local _, P = ... local frame = CreateFrame("Frame") local ticker local function say(s) print("|cff60d5ffRuen UI:|r " .. P.Translate(s)) end local function init() RuenUIDB = RuenUIDB or {original = {}, reports = {}} RuenUIDB.original = RuenUIDB.original or {} RuenUIDB.reports = RuenUIDB.reports or {} RuenUICharacter = RuenUICharacter or {original = {}} RuenUICharacter.original = RuenUICharacter.original or {} end -- Merge the narration profile once, preserving unrelated settings and live AceDB references. local function mergePreferences(target, values) local changed = false for key, value in pairs(values) do if type(value) == "table" then if type(target[key]) ~= "table" then target[key] = {}; changed = true end if mergePreferences(target[key], value) then changed = true end elseif target[key] ~= value then target[key] = value; changed = true end end return changed end local function applyAddonPresets() if not P.addonPresets then return false end local changed = false RuenUIDB.addonPresetVersions = RuenUIDB.addonPresetVersions or {} RuenUIDB.addonOriginal = RuenUIDB.addonOriginal or {} for addon, preset in pairs(P.addonPresets) do if C_AddOns.IsAddOnLoaded(addon) and RuenUIDB.addonPresetVersions[addon] ~= P.addonPresetVersion then local db = _G[preset.variable] or {} if RuenUIDB.addonOriginal[preset.variable] == nil then RuenUIDB.addonOriginal[preset.variable] = CopyTable(db) end for key, value in pairs(preset.values) do if db[key] ~= value then db[key] = value; changed = true end end if preset.profile then db.profiles = db.profiles or {} db.profiles["Ruen Narration"] = db.profiles["Ruen Narration"] or {} for _, profile in pairs(db.profiles) do if mergePreferences(profile, preset.profile) then changed = true end end db.global = db.global or {} if mergePreferences(db.global, preset.global or {}) then changed = true end end if addon == "VoiceQuest" then -- Voice IDs belong to the destination PC. Let VoiceQuest choose locally. for _, key in ipairs({"maleVoice", "femaleVoice", "narratorVoice"}) do if db[key] ~= nil then db[key] = nil; changed = true end end end _G[preset.variable] = db RuenUIDB.addonPresetVersions[addon] = P.addonPresetVersion end end if C_AddOns.IsAddOnLoaded("VoiceQuest") and not RuenUICharacter.voiceQuestProfileSeeded then VoiceQuestCharDB = VoiceQuestCharDB or {} RuenUICharacter.oldVoiceQuestCharDB = CopyTable(VoiceQuestCharDB) if VoiceQuestCharDB.useOwn then VoiceQuestCharDB.useOwn = false; changed = true end RuenUICharacter.voiceQuestProfileSeeded = true end return changed end local function watchBlockedActions() local lastNotice local diagnostic = CreateFrame("Frame") diagnostic:RegisterEvent("ADDON_ACTION_BLOCKED") diagnostic:RegisterEvent("ADDON_ACTION_FORBIDDEN") for _, event in ipairs({"VOICE_CHAT_TTS_PLAYBACK_STARTED", "VOICE_CHAT_TTS_PLAYBACK_FINISHED", "VOICE_CHAT_TTS_PLAYBACK_FAILED"}) do pcall(diagnostic.RegisterEvent, diagnostic, event) end diagnostic:SetScript("OnEvent", function(_, event, addon, operation) init() if event:find("^VOICE_CHAT_TTS_") then RuenUICharacter.ttsPlayback = RuenUICharacter.ttsPlayback or {} RuenUICharacter.ttsPlayback[event] = time() return end local records = RuenUICharacter.blockedActions or {} RuenUICharacter.blockedActions = records records[#records + 1] = {time = time(), event = event, addon = addon, operation = operation, stack = debugstack and debugstack(2, 24, 0) or ""} while #records > 12 do table.remove(records, 1) end if not lastNotice or time() - lastNotice >= 10 then lastNotice = time() say("Blocked action: " .. tostring(addon) .. " / " .. tostring(operation)) end end) end watchBlockedActions() local function saveCVar(key) local value = C_CVar.GetCVar(key) if value == nil then return nil end if RuenUIDB.original[key] == nil then RuenUIDB.original[key] = value end if RuenUICharacter.original[key] == nil then RuenUICharacter.original[key] = value end return value end local function put(key, value, validate) if saveCVar(key) == nil then RuenUIDB.results[key] = "unavailable" return end if validate and IsGraphicsSettingValueSupported then local reason = IsGraphicsSettingValueSupported(key, tonumber(value), false) -- Blizzard uses a nil error label for supported settings (normally result 0). if reason and reason ~= 0 then RuenUIDB.results[key] = "unsupported: " .. tostring(reason) return end end local ok, err = pcall(C_CVar.SetCVar, key, tostring(value)) RuenUIDB.results[key] = ok and C_CVar.GetCVar(key) or ("error: " .. tostring(err)) end local function applyList(list) for _, entry in ipairs(list) do put(entry[1], entry[2], entry[1]:match("^graphics") ~= nil) end end local function changeSetting(system, setting, value) if not setting then return end for _, item in ipairs(system.settings) do if item.setting == setting then item.value = value; return end end table.insert(system.settings, {setting = setting, value = value}) end local function anchor(system, point, relativePoint, x, y) system.anchorInfo = {point = point, relativeTo = "UIParent", relativePoint = relativePoint, offsetX = x, offsetY = y} system.isInDefaultPosition = false end local function setupThirdTarget() if RuenTargetTargetTarget then RegisterUnitWatch(RuenTargetTargetTarget); return end if not TargetFrameToT then return end local f = CreateFrame("Button", "RuenTargetTargetTarget", UIParent, "SecureUnitButtonTemplate") f:SetSize(150, 28) f:SetPoint("TOPRIGHT", TargetFrameToT, "BOTTOMRIGHT", 0, -4) f:SetAttribute("unit", "targettargettarget") f:SetAttribute("type1", "target") f:RegisterForClicks("AnyUp") local bg = f:CreateTexture(nil, "BACKGROUND") bg:SetAllPoints(); bg:SetColorTexture(0.03, 0.03, 0.04, 0.85) local label = f:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") label:SetPoint("TOPLEFT", 4, -3); label:SetText("ToToT") f.nameText = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") f.nameText:SetPoint("TOPLEFT", 42, -3); f.nameText:SetWidth(104); f.nameText:SetJustifyH("LEFT") f.health = CreateFrame("StatusBar", nil, f) f.health:SetPoint("BOTTOMLEFT", 4, 3); f.health:SetSize(142, 6) f.health:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar") f.health:SetStatusBarColor(0.25, 0.7, 0.4) local function refresh() local unit = "targettargettarget" if UnitExists(unit) then f.nameText:SetText(UnitName(unit)) f.health:SetMinMaxValues(0, UnitHealthMax(unit)) f.health:SetValue(UnitHealth(unit)) end end f:SetScript("OnShow", refresh) f:SetScript("OnEvent", function(_,event,unit) -- UNIT_TARGET also fires for every raid/nameplate unit. Only the two -- links feeding this display can change its target. if event=="UNIT_TARGET" and unit~="target" and unit~="targettarget" then return end refresh() end) f:RegisterEvent("PLAYER_TARGET_CHANGED") f:RegisterEvent("UNIT_TARGET") f:RegisterUnitEvent("UNIT_HEALTH", "targettargettarget") f:RegisterUnitEvent("UNIT_MAXHEALTH", "targettargettarget") -- Five inexpensive refreshes/second only while this small frame is visible; -- secure unit watching handles visibility, including target changes in combat. local elapsedTime = 0 f:SetScript("OnUpdate", function(_, elapsed) elapsedTime = elapsedTime + elapsed if elapsedTime >= 0.2 then elapsedTime = 0; refresh() end end) RegisterUnitWatch(f) end local function applyCombatBindings() if InCombatLockdown() then error("leave combat before applying bindings") end RuenUICharacter.bindingChanges = RuenUICharacter.bindingChanges or {} local changes = RuenUICharacter.bindingChanges local function bind(key, action) local previous = GetBindingAction(key) if not changes[key] then changes[key] = {before = previous, applied = action or ""} end if not SetBinding(key, action) then error("could not bind " .. key) end changes[key].applied = action or "" end local base = {"Q", "W", "R", "T", "A", "G", "H", "Z", "X", "C", "V", "B"} -- Remove paging, not class/form/vehicle behavior. All action assignments stay put. for _, action in ipairs({"ACTIONPAGE1", "ACTIONPAGE2", "ACTIONPAGE3", "ACTIONPAGE4", "ACTIONPAGE5", "ACTIONPAGE6", "NEXTACTIONPAGE", "PREVACTIONPAGE"}) do local keys = {GetBindingKey(action)} for _, key in ipairs(keys) do bind(key, nil) end end for key, action in pairs(RuenUICharacter.addedBindings or {}) do if GetBindingAction(key) == action then bind(key, nil) end end -- Make the new keys the displayed shortcuts, and preserve every old key for undo. for _, prefix in ipairs({"ACTIONBUTTON", "MULTIACTIONBAR1BUTTON", "MULTIACTIONBAR2BUTTON", "MULTIACTIONBAR3BUTTON", "MULTIACTIONBAR4BUTTON"}) do for i = 1, 12 do local keys = {GetBindingKey(prefix .. i)} for _, key in ipairs(keys) do bind(key, nil) end end end for i = 1, 12 do bind(base[i], "ACTIONBUTTON" .. i) bind("SHIFT-" .. base[i], "MULTIACTIONBAR1BUTTON" .. i) bind("CTRL-" .. base[i], "MULTIACTIONBAR2BUTTON" .. i) end -- Remove obsolete modified movement keys from the earlier RDFG setup. for _, key in ipairs({"CTRL-SHIFT-R", "CTRL-SHIFT-G"}) do local old = GetBindingAction(key) if old == "MOVEFORWARD" or old == "STRAFERIGHT" then bind(key, nil) end end -- ESDF movement remains available while holding either combat-row modifier. for _, prefix in ipairs({"", "SHIFT-", "CTRL-", "CTRL-SHIFT-"}) do bind(prefix .. "E", "MOVEFORWARD"); bind(prefix .. "D", "MOVEBACKWARD") bind(prefix .. "S", "STRAFELEFT"); bind(prefix .. "F", "STRAFERIGHT") end bind("U", "INTERACTTARGET"); bind("ALT-U", "TOGGLEPINGLISTENER") bind("SHIFT-U", "ASSISTTARGET") if RuenTargetTargetTarget then bind("CTRL-SHIFT-U", "CLICK RuenTargetTargetTarget:LeftButton") end bind("I", "OPENALLBAGS"); bind("K", "TOGGLECHARACTER0") bind("J", "TOGGLEQUESTLOG"); bind("N", "NAMEPLATES") bind("SHIFT-N", "ALLNAMEPLATES") bind("CTRL-I", "SITORSTAND"); bind("SHIFT-I", "TOGGLESHEATH") SaveBindings(GetCurrentBindingSet()) RuenUICharacter.bindingsVersion = 2 P.ApplyUtilityBindings(true) end local function restoreCombatBindings() for key, change in pairs(RuenUICharacter.bindingChanges or {}) do if GetBindingAction(key) == change.applied then SetBinding(key, change.before ~= "" and change.before or nil) end end if RuenTargetTargetTarget then UnregisterUnitWatch(RuenTargetTargetTarget) RuenTargetTargetTarget:Hide() end end local layoutHelpersInstalled = false local function ownsLayout() if not RuenUIDB or RuenUIDB.disabled then return false end local manager = EditModeManagerFrame local active = manager and manager:GetActiveLayoutInfo() return manager and not manager.overrideLayoutInfo and P.IsOurLayout(active) end local function setSlotsLocked(locked) if InCombatLockdown() then say(P.Localized("Change the bar lock after combat.", "Измените блокировку панелей после боя.")); return end RuenUIDB.results = RuenUIDB.results or {} put("lockActionBars", locked and 1 or 0) -- Pet dragging reads the Settings value, not merely the raw CVar. if Settings.GetSetting and Settings.GetSetting("lockActionBars") then Settings.SetValue("lockActionBars", locked) end RuenUIDB.unlockedSlotsVersion = 1 say(locked and P.Localized("Action and pet buttons locked. Shift-drag temporarily overrides the lock.", "Кнопки и панель питомца заблокированы. Shift позволяет временно перемещать кнопки.") or P.Localized("Action and pet buttons unlocked: drag to rearrange outside combat.", "Кнопки и панель питомца разблокированы: перемещайте их вне боя.")) P.MigrateExtraBars(true) end local function uiRatio(f) return f:GetEffectiveScale() / UIParent:GetEffectiveScale() end local function frameEdge(f, method) if f and f.IsForbidden and f:IsForbidden() then return end local value = f and f[method] and f[method](f) -- Target/focus aura layouts publish secret coordinates, even out of combat. -- Never perform arithmetic on these; overlays reserve a fixed public area. if issecretvalue and issecretvalue(value) then return end return value and value * uiRatio(f) end local function placeRelative(f, point, relative, relativePoint, x, y) if not f or not relative then return end -- Measure the neighbor, but anchor to UIParent. Never link protected action -- frames into Blizzard's unprotected panel containers or mutate systemInfo. local function axis(which, low, high) if relativePoint:find(low) then return frameEdge(relative, which == "x" and "GetLeft" or "GetBottom") end if relativePoint:find(high) then return frameEdge(relative, which == "x" and "GetRight" or "GetTop") end local first = frameEdge(relative, which == "x" and "GetLeft" or "GetBottom") local last = frameEdge(relative, which == "x" and "GetRight" or "GetTop") return first and last and (first + last) / 2 end local rx, ry = axis("x", "LEFT", "RIGHT"), axis("y", "BOTTOM", "TOP") if not rx or not ry then return end local scale = uiRatio(f) if f.GetPoint and (not f.GetNumPoints or f:GetNumPoints()==1) then local p,r,rp,px,py=f:GetPoint(1) if p==point and r==UIParent and rp=="BOTTOMLEFT" and px and py and math.abs(px-(rx+x)/scale)<.01 and math.abs(py-(ry+y)/scale)<.01 then return end end -- These original methods avoid Edit Mode's shared snap/anchor bookkeeping. local clear = f.ClearAllPointsBase or f.ClearAllPoints local set = f.SetPointBase or f.SetPoint clear(f) set(f, point, UIParent, "BOTTOMLEFT", (rx + x) / scale, (ry + y) / scale) end local chatBaseWidth,chatAppliedWidth local function fitChat() local chat=ChatFrame1 if not chat or not MainActionBar then return end local current=chat:GetWidth() if not chatBaseWidth or (chatAppliedWidth and math.abs(current-chatAppliedWidth)>.5) then chatBaseWidth=current end local left=frameEdge(chat,"GetLeft") or 20 local right=frameEdge(MainActionBar,"GetLeft") if not right then return end local width=math.min(chatBaseWidth,math.max(240,(right-left-16)/uiRatio(chat))) if math.abs(current-width)>.5 then chat:SetWidth(width) end chatAppliedWidth=width end local trackerBaseWidth,trackerAppliedWidth local function fitTracker() if not ObjectiveTrackerFrame or not ownsLayout() or InCombatLockdown() or EditModeManagerFrame:IsShown() then return end local current=ObjectiveTrackerFrame:GetWidth() if not trackerBaseWidth or (trackerAppliedWidth and math.abs(current-trackerAppliedWidth)>.5) then trackerBaseWidth=current end local width=math.min(trackerBaseWidth,math.max(220,UIParent:GetWidth()-1134)/uiRatio(ObjectiveTrackerFrame)) if math.abs(current-width)>.5 then ObjectiveTrackerFrame:SetWidth(width) end trackerAppliedWidth=width local top = frameEdge(ObjectiveTrackerFrame, "GetTop") local clickTop = frameEdge(P.UtilityTop(), "GetTop") if top and clickTop then local available = math.max(80, (top - clickTop - 24) / uiRatio(ObjectiveTrackerFrame)) local height = math.min(400, available) if math.abs(ObjectiveTrackerFrame:GetHeight() - height) > 0.5 then ObjectiveTrackerFrame:SetHeight(height) end end end -- Match the short menu row to the bags using the original frame method. -- Avoid Edit Mode's SetScale override and never mutate shared systemInfo. local function alignCornerWidths() if not BagsBar or not MicroMenuContainer then return end local target = BagsBar:GetWidth() * uiRatio(BagsBar) local menu = MicroMenuContainer local current = menu:GetWidth() * uiRatio(menu) local right, bottom = frameEdge(menu, "GetRight"), frameEdge(menu, "GetBottom") if current > 0 and target > 0 and right and bottom and math.abs(current - target) > 0.1 then local setScale = menu.SetScaleBase or menu.SetScale setScale(menu, menu:GetScale() * target / current) placeRelative(menu, "BOTTOMRIGHT", UIParent, "BOTTOMLEFT", right, bottom) end end -- Inventory opens inward of the quest column and above the action rows. All -- anchors use measured UIParent coordinates, never protected action-bar parents. local bagBaseScale, bagAppliedScale local bagPlacing=false local function positionCombinedBags() local bag = ContainerFrameCombinedBags if not ownsLayout() or InCombatLockdown() or EditModeManagerFrame:IsShown() then return end if not bag or not bag:IsShown() or bag:GetParent() ~= UIParent then return end local currentScale=bag:GetScale() if not bagBaseScale or (bagAppliedScale and math.abs(currentScale-bagAppliedScale)>.001) then bagBaseScale=currentScale end local screenWidth = UIParent:GetWidth() local right = (frameEdge(MultiBarLeft, "GetLeft") or screenWidth - 280) - 20 if ObjectiveTrackerFrame and ObjectiveTrackerFrame:IsShown() then right = math.min(right, (frameEdge(ObjectiveTrackerFrame, "GetLeft") or right + 20) - 20) end local bottom = math.max(frameEdge(P.UtilityTop(), "GetTop") or 180, frameEdge(MultiBar5 or MultiBarBottomRight, "GetTop") or 180) + 22 local ratio = uiRatio(bag)*bagBaseScale/currentScale local width, height = bag:GetWidth()*ratio, bag:GetHeight()*ratio if width<=0 or height<=0 then return end local target,fit=P.FindBagPosition(width,height,right-width,bottom) P.bagUnplaced=not target if not target then return end local moved=math.abs((frameEdge(bag,"GetLeft") or -1)-target.left)>.5 or math.abs((frameEdge(bag,"GetBottom") or -1)-target.bottom)>.5 or math.abs(currentScale-bagBaseScale*fit)>.001 bagPlacing=true bagAppliedScale=bagBaseScale*fit if math.abs(currentScale-bagAppliedScale)>.001 then bag:SetScale(bagAppliedScale) end placeRelative(bag,"BOTTOMLEFT",UIParent,"BOTTOMLEFT",target.left,target.bottom) bag:SetClampedToScreen(true) bagPlacing=false if moved then P.overlayRevision=(P.overlayRevision or 0)+1 end end local bagQueued=false local function queueCombinedBags() if bagQueued or bagPlacing then return end bagQueued=true -- Never run Blizzard's bag manager from addon context. In particular bank -- OnShow opens the backpack before its protected first-tab initialization. -- Leave that native call stack alone; move only our visible bag afterward. C_Timer.After(0,function() bagQueued=false positionCombinedBags() P.PositionOverlayFrames() end) end local function refreshUILayout() P.RefreshPetExtras() if not ownsLayout() or InCombatLockdown() or EditModeManagerFrame:IsShown() then return end P.MigrateExtraBars() P.MigrateClassLayout() placeRelative(MultiBarBottomLeft, "BOTTOMLEFT", MainActionBar, "TOPLEFT", 0, 4) placeRelative(MultiBarBottomRight, "BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 0, 4) alignCornerWidths() placeRelative(BagsBar, "BOTTOMRIGHT", MicroMenuContainer, "TOPRIGHT", 0, 10) placeRelative(MultiBarLeft, "BOTTOMRIGHT", BagsBar, "TOPRIGHT", 0, 14) P.PositionExtraBars(placeRelative, frameEdge) fitChat() P.RefreshClassLayout(placeRelative, frameEdge, uiRatio) P.PositionLeftBars(placeRelative, frameEdge) P.PositionEncounterWidgets(placeRelative,frameEdge) placeRelative(ObjectiveTrackerFrame, "TOPRIGHT", MinimapCluster, "BOTTOMRIGHT", 0, -24) fitTracker() P.PositionGroupFrames(placeRelative, frameEdge) P.RefreshClassAssist() P.RefreshDamageMeters() queueCombinedBags() P.PositionOverlayFrames() end local function anchorTooltip(tooltip,settled) if not ownsLayout() or EditModeManagerFrame:IsShown() or not MultiBarLeft then return end P.PositionTooltip(tooltip,settled) end local function installUILayoutHelpers() if layoutHelpersInstalled then return end layoutHelpersInstalled = true P.InitializeOverlayLayout(placeRelative,frameEdge,function() return ownsLayout() and not EditModeManagerFrame:IsShown() end) P.InitializeClassAssist(ownsLayout, placeRelative, frameEdge, put) P.InitializeDamageMeters(ownsLayout, placeRelative, frameEdge, put) local listener = CreateFrame("Frame") local queued = false local function queue() if queued then return end queued = true C_Timer.After(0.3, function() queued = false if InCombatLockdown() then listener:RegisterEvent("PLAYER_REGEN_ENABLED"); return end listener:UnregisterEvent("PLAYER_REGEN_ENABLED") refreshUILayout() end) end if UpdateContainerFrameAnchors then hooksecurefunc("UpdateContainerFrameAnchors", function() if InCombatLockdown() then listener:RegisterEvent("PLAYER_REGEN_ENABLED") else queueCombinedBags() end end) end local watchedBag local function watchBag() local bag=ContainerFrameCombinedBags if not bag or watchedBag==bag then return end watchedBag=bag local function changed() if bagPlacing then return end P.overlayRevision=(P.overlayRevision or 0)+1 if not bag:IsShown() then P.bagUnplaced=nil end queueCombinedBags() end for _,script in ipairs({"OnShow","OnHide","OnSizeChanged"}) do bag:HookScript(script,changed) end hooksecurefunc(bag,"SetPoint",queueCombinedBags) end watchBag() local hookedClassFrames = {} local function watchClassFrames() for _, name in ipairs(P.classFrameNames) do local f = _G[name] if f and not hookedClassFrames[f] then hookedClassFrames[f] = true f:HookScript("OnShow", queue) f:HookScript("OnSizeChanged", queue) end end end watchClassFrames() -- Repair late native restores of the left shelf outside combat, including -- reloads, layout changes, and bars becoming visible after a class change. for _,name in ipairs({"MultiBar6","MultiBar7"}) do local f=_G[name] if f then f:HookScript("OnShow",queue) f:HookScript("OnSizeChanged",queue) if f.OnUpdateSystem then hooksecurefunc(f,"OnUpdateSystem",queue) end end end listener:RegisterEvent("EDIT_MODE_LAYOUTS_UPDATED") for _, event in ipairs({"ADDON_LOADED", "PLAYER_ENTERING_WORLD", "UPDATE_SHAPESHIFT_FORMS", "UPDATE_SHAPESHIFT_FORM", "UPDATE_MULTI_CAST_ACTIONBAR", "SPELLS_CHANGED", "UNIT_PET", "GROUP_ROSTER_UPDATE"}) do pcall(listener.RegisterEvent, listener, event) end if EditModeManagerFrame.UpdateBottomActionBarPositions then hooksecurefunc(EditModeManagerFrame, "UpdateBottomActionBarPositions", queue) end listener:RegisterEvent("DISPLAY_SIZE_CHANGED") listener:RegisterEvent("UI_SCALE_CHANGED") listener:RegisterEvent("PLAYER_TARGET_CHANGED") listener:RegisterEvent("PLAYER_FOCUS_CHANGED") listener:SetScript("OnEvent", function(_, event, unit) if event == "UNIT_PET" and unit ~= "player" then return end if event=="PLAYER_TARGET_CHANGED" or event=="PLAYER_FOCUS_CHANGED" then P.overlayRevision=(P.overlayRevision or 0)+1 if InCombatLockdown() then listener:RegisterEvent("PLAYER_REGEN_ENABLED") else queueCombinedBags() end return end if event == "ADDON_LOADED" then watchClassFrames();watchBag() end queue() end) UIParent:HookScript("OnSizeChanged", queue) EditModeManagerFrame:HookScript("OnHide", queue) hooksecurefunc(EditModeManagerFrame, "UpdateSystems", queue) hooksecurefunc(ObjectiveTrackerFrame, "UpdateHeight", function() if InCombatLockdown() then listener:RegisterEvent("PLAYER_REGEN_ENABLED") else fitTracker() end end) local defaultTooltipOwner local tooltipPlacing=false local function managesTooltip(tooltip) local owner = tooltip:GetOwner() if not owner then return false end if owner==defaultTooltipOwner or owner==UIParent or owner==WorldFrame then return true end -- Bag/menu tooltips can use their own anchor instead of the default one. for _ = 1, 8 do if not owner then break end if owner == BagsBar or owner == ContainerFrameCombinedBags or owner == MicroMenuContainer or owner == MainActionBar or owner == MultiBarBottomLeft or owner == MultiBarBottomRight or owner == MultiBarLeft or owner == MultiBarRight or owner == MultiBar5 or owner == MultiBar6 or owner == MultiBar7 or owner == PetActionBar or owner == StanceBar or owner == MultiCastActionBarFrame or owner == PossessActionBar then return true end owner = owner:GetParent() end return false end local function restoreTooltipAnchor(tooltip,settled) if tooltipPlacing or not managesTooltip(tooltip) then return end tooltipPlacing=true anchorTooltip(tooltip,settled) tooltipPlacing=false end local tooltipQueued=false local function queueTooltip(tooltip) if tooltipQueued or tooltipPlacing then return end tooltipQueued=true C_Timer.After(0,function() tooltipQueued=false if not tooltip:IsShown() then P.ResetTooltipPosition(tooltip) defaultTooltipOwner=nil else restoreTooltipAnchor(tooltip,true) end end) end hooksecurefunc("GameTooltip_SetDefaultAnchor", function(tooltip,owner) defaultTooltipOwner=owner or tooltip:GetOwner() restoreTooltipAnchor(tooltip,false) queueTooltip(tooltip) end) -- The native bag calculator runs on every item-tooltip refresh, after -- SetOwner. Reclaim its anchor in the same call, before the next paint. if ContainerFrameItemButton_CalculateItemTooltipAnchors then hooksecurefunc("ContainerFrameItemButton_CalculateItemTooltipAnchors",function(_,tooltip) if tooltip==GameTooltip then restoreTooltipAnchor(tooltip,false);queueTooltip(tooltip) end end) end GameTooltip:HookScript("OnShow",function(tooltip) if managesTooltip(tooltip) then restoreTooltipAnchor(tooltip,false);queueTooltip(tooltip) end end) GameTooltip:HookScript("OnSizeChanged",queueTooltip) -- SetOwner may hide/show during a refresh. Reset only if it remains hidden -- after that native call, not on the intermediate OnHide event. GameTooltip:HookScript("OnHide",queueTooltip) hooksecurefunc(GameTooltip,"SetPoint",function() -- A deferred repair alone can show the native position for a frame. -- Restore only the cached anchor here; defer measuring rebuilt text. restoreTooltipAnchor(GameTooltip,false) queueTooltip(GameTooltip) end) for _,name in ipairs({"ShoppingTooltip1","ShoppingTooltip2"}) do local comparison=_G[name] if comparison then for _,script in ipairs({"OnShow","OnHide","OnSizeChanged"}) do comparison:HookScript(script,function() queueTooltip(GameTooltip) end) end end end if GameTooltip_ShowCompareItem then hooksecurefunc("GameTooltip_ShowCompareItem",function(tooltip) if not tooltip or tooltip==GameTooltip then restoreTooltipAnchor(GameTooltip,true) queueTooltip(GameTooltip) end end) end queue() end local function seedClickBar() if RuenUICharacter.clickBarSeeded or InCombatLockdown() or GetCursorInfo() then return end local pickup = C_Item and C_Item.PickupItem or PickupItem if not pickup or not C_Item or not C_Item.GetItemInfoInstant then return end local items, seen, empty = {}, {}, {} local function add(id, hearth) if not id or seen[id] then return end local _, _, _, _, _, class, subclass = C_Item.GetItemInfoInstant(id) if hearth or (class == 0 and subclass == 5) then seen[id] = true; items[#items + 1] = id end end local count = C_Item.GetItemCount or GetItemCount for i = 1, 12 do local button = _G["MultiBarLeftButton" .. i] if button and button.action then local kind, id = GetActionInfo(button.action) if not kind then empty[#empty + 1] = button.action elseif kind == "item" then seen[id] = true end end end if count and count(6948) > 0 then add(6948, true) end if C_Container then for bag = 0, 4 do for slot = 1, C_Container.GetContainerNumSlots(bag) do add(C_Container.GetContainerItemID(bag, slot)) end end end RuenUICharacter.seededClickSlots = RuenUICharacter.seededClickSlots or {} local slotIndex = 1 for _, id in ipairs(items) do local destination = empty[slotIndex] if not destination then break end -- Recheck both cursor and destination; never replace another assignment. if GetCursorInfo() or GetActionInfo(destination) then return end pickup(id) local kind, cursorID = GetCursorInfo() if kind == "item" and cursorID == id then PlaceAction(destination) local placedKind, placedID = GetActionInfo(destination) if placedKind == "item" and placedID == id then RuenUICharacter.seededClickSlots[destination] = id slotIndex = slotIndex + 1 end end ClearCursor() end RuenUICharacter.clickBarSeeded = true end local function restoreClickBar() if GetCursorInfo() then return end for slot, id in pairs(RuenUICharacter.seededClickSlots or {}) do local kind, currentID = GetActionInfo(slot) if kind == "item" and currentID == id then PickupAction(slot); ClearCursor() end end end local function configureLayout() local manager = EditModeManagerFrame if not manager or not manager.layoutInfo or not EditModePresetLayoutManager then error("Edit Mode is not ready; use /ruen apply after loading") end if RuenUICharacter.oldLayout == nil then RuenUICharacter.oldLayout = manager.layoutInfo.activeLayout end for i, layout in ipairs(manager:GetLayouts()) do if P.IsOurLayout(layout) then C_EditMode.SetActiveLayout(i) RuenUIDB.layoutExport = C_EditMode.ConvertLayoutInfoToString(layout) return end end if manager:AreLayoutsOfTypeMaxed(Enum.EditModeLayoutType.Account) then error("account Edit Mode layouts are full; none removed") end local layout = CopyTable(EditModePresetLayoutManager:GetCopyOfPresetLayouts()[1]) local E, A, U = Enum.EditModeSystem, Enum.EditModeActionBarSetting, Enum.EditModeUnitFrameSystemIndices for _, system in ipairs(layout.systems) do local index = system.systemIndex if system.system == E.ActionBar and index and index <= 5 then changeSetting(system, A.NumIcons, 12) changeSetting(system, A.IconPadding, 2) changeSetting(system, A.VisibleSetting, Enum.ActionBarVisibleSetting.Always) changeSetting(system, A.Orientation, Enum.ActionBarOrientation.Horizontal) if index <= 3 then changeSetting(system, A.AlwaysShowButtons, 1) changeSetting(system, A.NumRows, 1) changeSetting(system, A.IconSize, 4) -- 90%, encoded (90-50)/10 anchor(system, "BOTTOM", "BOTTOM", 0, 48 + (index - 1) * 42) else changeSetting(system, A.AlwaysShowButtons, 1) -- visible, unbound click slots changeSetting(system, A.NumRows, 2) -- six columns, two rows changeSetting(system, A.IconSize, 4) -- 90%, comfortable mouse targets anchor(system, "BOTTOMRIGHT", "BOTTOMRIGHT", -22, 100) end if index == 1 then changeSetting(system, A.HideBarArt, 1) changeSetting(system, A.HideBarScrolling, 1) end elseif system.system == E.ActionBar and index == Enum.EditModeActionBarSystemIndices.PetActionBar then changeSetting(system, A.IconSize, P.petIconSize) anchor(system, "BOTTOM", "BOTTOM", 0, 185) elseif system.system == E.ActionBar and index == Enum.EditModeActionBarSystemIndices.StanceBar then changeSetting(system, A.IconSize, 3) anchor(system, "BOTTOMRIGHT", "BOTTOM", -250, 185) elseif system.system == E.MainActionBarEndCap then changeSetting(system, Enum.EditModeMainActionBarEndCapSetting.Hidden, 1) elseif system.system == E.UnitFrame then if index == U.Player then anchor(system, "BOTTOMRIGHT", "BOTTOM", -110, 258) elseif index == U.Target then anchor(system, "BOTTOMLEFT", "BOTTOM", 110, 258) elseif index == U.Focus then anchor(system, "BOTTOMLEFT", "BOTTOM", 110, 340) elseif index == U.Party then changeSetting(system, Enum.EditModeUnitFrameSetting.UseRaidStylePartyFrames, 1) anchor(system, "LEFT", "LEFT", 25, 25) end elseif system.system == E.CastBar then anchor(system, "BOTTOM", "BOTTOM", 0, 228) elseif system.system == E.StatusTrackingBar then changeSetting(system, Enum.EditModeStatusTrackingBarSetting.Size, 0) -- native minimum 50% anchor(system, "BOTTOM", "BOTTOM", 0, (index == 1) and 5 or 24) elseif system.system == E.MicroMenu then changeSetting(system, Enum.EditModeMicroMenuSetting.Size, 2) -- 80% anchor(system, "BOTTOMRIGHT", "BOTTOMRIGHT", -22, 8) elseif system.system == E.Bags then changeSetting(system, Enum.EditModeBagsSetting.Size, 1) -- 80% anchor(system, "BOTTOMRIGHT", "BOTTOMRIGHT", -22, 50) elseif system.system == E.ObjectiveTracker then changeSetting(system, Enum.EditModeObjectiveTrackerSetting.Height, 0) -- native minimum, 400 UI units anchor(system, "TOPRIGHT", "TOPRIGHT", -22, -322) elseif system.system == E.Minimap then changeSetting(system, Enum.EditModeMinimapSetting.Size, 4) -- 90% anchor(system, "TOPRIGHT", "TOPRIGHT", -22, -40) elseif system.system == E.ChatFrame then changeSetting(system, Enum.EditModeChatFrameSetting.WidthHundreds, 3) changeSetting(system, Enum.EditModeChatFrameSetting.WidthTensAndOnes, 80) changeSetting(system, Enum.EditModeChatFrameSetting.HeightHundreds, 1) changeSetting(system, Enum.EditModeChatFrameSetting.HeightTensAndOnes, 50) anchor(system, "BOTTOMLEFT", "BOTTOMLEFT", 20, 45) end end P.ConfigureClassSystems(layout) P.ConfigureClassAssistSystems(layout) P.ConfigureExtraBars(layout) manager:CreateLayoutTbls() manager:MakeNewLayout(layout, Enum.EditModeLayoutType.Account, P.layoutName, false) for i, saved in ipairs(manager:GetLayouts()) do if P.IsOurLayout(saved) then C_EditMode.SetActiveLayout(i) RuenUIDB.layoutExport = C_EditMode.ConvertLayoutInfoToString(saved) return end end error("Edit Mode did not save the new layout") end local function setBarVisibility(bars) -- The Blizzard Settings proxy owns the cached value AND the refresh callback. -- Raw SetActionBarToggles alone changes server state without updating frames. for i = 1, 7 do local key = "PROXY_SHOW_ACTIONBAR_" .. (i + 1) assert(Settings.GetSetting(key), "Action bar settings not ready") Settings.SetValue(key, bars[i] and true or false) end MultiActionBar_Update() end local function recordLayoutStatus(announce) local status = {bars = {}, time = time(), verified = true, release=P.release, uiWidth=UIParent:GetWidth(),uiHeight=UIParent:GetHeight(),uiScale=UIParent:GetEffectiveScale()} status.cooldowns={} for _,name in ipairs({"EssentialCooldownViewer","UtilityCooldownViewer","BuffIconCooldownViewer","BuffBarCooldownViewer"}) do local f=_G[name] if f then status.cooldowns[name]={shown=f:IsShown(),visibleSetting=f.visibleSetting, systemIndex=f.systemIndex,settings=f.systemInfo and CopyTable(f.systemInfo.settings), left=frameEdge(f,"GetLeft"),bottom=frameEdge(f,"GetBottom"),width=f:GetWidth(),height=f:GetHeight()} end end for _, name in ipairs({"MainActionBar", "MultiBarBottomLeft", "MultiBarBottomRight", "MultiBar5", "MultiBarLeft", "MultiBarRight", "MultiBar6", "MultiBar7"}) do local bar = _G[name] local shown = bar and bar:IsShown() or false local info = {shown = shown} if bar then info.width, info.height = bar:GetSize() info.left, info.bottom = bar:GetLeft(), bar:GetBottom() end status.bars[name] = info if not shown then status.verified = false end end local manager = EditModeManagerFrame local active = manager and manager:GetActiveLayoutInfo() status.movement = {E = GetBindingAction("E"), S = GetBindingAction("S"), D = GetBindingAction("D"), F = GetBindingAction("F")} status.controlsVersion = (GetCurrentBindingSet() == 1 and RuenUIDB or RuenUICharacter).controlsVersion status.utilityBindings = {} for _, key in ipairs({"`", "BUTTON3", "BUTTON4", "BUTTON5", "SPACE", "N", "M", "I", "L", "P", "F8"}) do status.utilityBindings[key] = GetBindingAction(key) end if ContainerFrameCombinedBags and ContainerFrameCombinedBags:IsShown() then status.bagWindow = {left = frameEdge(ContainerFrameCombinedBags, "GetLeft"), right = frameEdge(ContainerFrameCombinedBags, "GetRight"), bottom = frameEdge(ContainerFrameCombinedBags, "GetBottom"), top = frameEdge(ContainerFrameCombinedBags, "GetTop")} end status.thirdTargetShown = RuenTargetTargetTarget and RuenTargetTargetTarget:IsShown() or false status.layout = active and active.layoutName or "unknown" if status.layout ~= P.layoutName then status.verified = false end status.frames, status.overlaps = {}, {} for _, name in ipairs({"MainActionBar", "MultiBarBottomLeft", "MultiBarBottomRight", "MultiBar5", "MultiBarLeft", "MultiBarRight", "MultiBar6", "MultiBar7", "ChatFrame1", "BagsBar", "MicroMenuContainer", "MinimapCluster", "ObjectiveTrackerFrame", "ContainerFrameCombinedBags", "GameTooltip", "ShoppingTooltip1", "ShoppingTooltip2"}) do local f = _G[name] if f then status.frames[name] = {shown=f:IsShown(), left = frameEdge(f, "GetLeft"), right = frameEdge(f, "GetRight"), bottom = frameEdge(f, "GetBottom"), top = frameEdge(f, "GetTop")} end end for _, pair in ipairs({{"BagsBar", "MicroMenuContainer"}, {"MultiBarLeft", "BagsBar"}, {"MinimapCluster", "ObjectiveTrackerFrame"}, {"ObjectiveTrackerFrame", "MultiBarLeft"}, {"MultiBarBottomLeft", "MainActionBar"}, {"MultiBarBottomRight", "MultiBarBottomLeft"}}) do local upper, lower = status.frames[pair[1]], status.frames[pair[2]] if upper and lower and upper.bottom and lower.top and upper.bottom < lower.top - 1 then status.overlaps[#status.overlaps + 1] = pair[1] .. "/" .. pair[2] status.verified = false end end status.classLayoutVersion = RuenUIDB.classLayoutVersion status.intentionalOverlaps={} if P.bagOverHUD and ContainerFrameCombinedBags and ContainerFrameCombinedBags:IsShown() then status.intentionalOverlaps[#status.intentionalOverlaps+1]="Oversized inventory temporarily covers HUD information; action/chat/quest controls remain clear" end if P.tooltipOverInventory then status.intentionalOverlaps[#status.intentionalOverlaps+1]="Comparison tooltips over other inventory slots (hovered item kept clear)" end if P.tooltipOverSocial then status.intentionalOverlaps[#status.intentionalOverlaps+1]="Large tooltip over chat/social space because no fully clear position fits" end for alert in pairs(P.overlayOverChat or {}) do status.intentionalOverlaps[#status.intentionalOverlaps+1]=(alert:GetName() or "Alert").." temporarily over chat in a crowded layout" end for alert in pairs(P.overlayOverOptional or {}) do status.intentionalOverlaps[#status.intentionalOverlaps+1]=(alert:GetName() or "Alert").." temporarily over optional cooldown/meter area in a crowded layout" end status.attachments=P.AttachedHUDRegions() status.classFrames = {} local combatNames = {"MainActionBar", "MultiBarBottomLeft", "MultiBarBottomRight", "MultiBar5", "MultiBarLeft", "MultiBarRight", "MultiBar6", "MultiBar7", "BagsBar", "MicroMenuContainer"} for _, name in ipairs(P.classFrameNames) do local f = _G[name] if f then status.classFrames[name] = {shown = f:IsShown(), left = frameEdge(f, "GetLeft"), right = frameEdge(f, "GetRight"), bottom = frameEdge(f, "GetBottom"), top = frameEdge(f, "GetTop")} end end for _,issue in ipairs(P.OverlayAudit()) do status.overlaps[#status.overlaps+1]=issue status.verified=false end local function intersects(a, b) return a and b and a.left and a.right and a.bottom and a.top and b.left and b.right and b.bottom and b.top and math.min(a.right, b.right) - math.max(a.left, b.left) > 1 and math.min(a.top, b.top) - math.max(a.bottom, b.bottom) > 1 end for name, rect in pairs(status.classFrames) do if rect.shown then for _, other in ipairs(combatNames) do local f = _G[other] if f and f:IsShown() and intersects(rect, status.frames[other]) then status.overlaps[#status.overlaps + 1] = name .. "/" .. other status.verified = false end end end end status.graphics = {} for _, entry in ipairs(P.graphics) do status.graphics[entry[1]] = C_CVar.GetCVar(entry[1]) end for _, key in ipairs({"GxApi", "GxFullscreenResolution", "useUiScale", "uiScale", "shadowTextureSize", "shadowNumCascades", "farclip", "groundEffectDist", "gxTripleBuffer", "graphicsOutlineMode", "textureFilteringMode", "ffxGlow"}) do status.graphics[key] = C_CVar.GetCVar(key) end if GetFramerate then status.fps = GetFramerate() end if C_VoiceChat and C_VoiceChat.GetTtsVoices then local ok, voices = pcall(C_VoiceChat.GetTtsVoices) if ok then status.ttsVoices = voices end end RuenUICharacter.verification = status if announce then say("Ruen UI "..P.release.."; UI "..math.floor(status.uiWidth).." x "..math.floor(status.uiHeight)..". Cooldowns: "..(RuenUIDB.cooldownsMode or "auto")..".") for _,note in ipairs(status.intentionalOverlaps) do say(note) end if status.verified then say("ESDF ready: Q W R T / A G H / Z X C V B. Rows bottom to top: base, Shift, Ctrl, Alt. Utility bars are above bags and chat. /ruen bars lists shortcuts; /ruen lock or unlock controls dragging.") else say("Layout needs a spacing check: " .. table.concat(status.overlaps, ", ") .. ". /ruen status checks again.") end end end local function mask(key, enum, names) if not enum or saveCVar(key) == nil then return end local value = tonumber(C_CVar.GetCVar(key)) or 0 for _, name in ipairs(names) do local flag = enum[name] if flag and flag > 0 then value = bit.bor(value, bit.lshift(1, flag - 1)) end end put(key, value) end local function apply() if InCombatLockdown() then say("Wait until combat ends, then /ruen apply."); return end P.InitializeGunAudio() RuenUIDB.results = RuenUIDB.results or {} if RuenUIDB.graphicsVersion ~= (P.graphicsVersion or P.version) then applyList(P.graphics) RuenUIDB.graphicsVersion = P.graphicsVersion or P.version end applyList(P.gameplay) put("softTargetInteract", Enum.SoftTargetEnableFlags.Any) mask("nameplateStackingTypes", Enum.NamePlateStackType, {"Enemy"}) mask("nameplateThreatDisplay", Enum.NamePlateThreatDisplay, {"Progressive", "HealthBarColor"}) if C_Minimap and MinimapUtil and Enum.MinimapTrackingFilter then local filter = Enum.MinimapTrackingFilter.TrivialQuests local index = MinimapUtil.GetFilterIndexForFilterID(filter) if index then if RuenUICharacter.oldTrivial == nil then RuenUICharacter.oldTrivial = not C_Minimap.IsFilteredOut(filter) end C_Minimap.SetTracking(index, true) end end if not RuenUICharacter.oldBars then RuenUICharacter.oldBars = {GetActionBarToggles()} end local bars = {GetActionBarToggles()} for i=1,7 do bars[i]=true end -- Retain existing extra bars and refresh Blizzard's cached visibility settings. setBarVisibility(bars) setupThirdTarget() applyCombatBindings() P.ApplyExtraBindings(true) local ok, err = pcall(configureLayout) RuenUICharacter.layoutStatus = ok and "saved" or tostring(err) if not ok then say("Bars enabled; layout needs attention: " .. tostring(err)); return end RuenUICharacter.version = P.version C_Timer.After(1, function() refreshUILayout() local seeded, seedError = pcall(seedClickBar) if not seeded then say("Click bar is ready; drag items into its empty slots. " .. tostring(seedError)) end recordLayoutStatus(true) say("Settings saved. Type /reload once to finish native frame setup.") end) end local function restore() if InCombatLockdown() then say("Leave combat before restoring."); return end if RuenUIDB.optimizer then P.OptimizerCommand("restore") end P.StopGunAudio() P.StopSwingTimers() P.StopDamageMeters() P.RestoreClassAssist() for key, value in pairs(RuenUIDB.original) do pcall(C_CVar.SetCVar, key, value) end for key, value in pairs(RuenUICharacter.original) do pcall(C_CVar.SetCVar, key, value) end if Settings.GetSetting("lockActionBars") then Settings.SetValue("lockActionBars",C_CVar.GetCVar("lockActionBars")=="1") end if RuenUICharacter.oldBars then setBarVisibility(RuenUICharacter.oldBars) end if RuenUICharacter.oldLayout then pcall(C_EditMode.SetActiveLayout, RuenUICharacter.oldLayout) end if RuenUICharacter.oldTrivial ~= nil then local index = MinimapUtil.GetFilterIndexForFilterID(Enum.MinimapTrackingFilter.TrivialQuests) if index then C_Minimap.SetTracking(index, RuenUICharacter.oldTrivial) end end restoreClickBar() restoreCombatBindings() if RuenUIDB.oldSelfCast and SetModifiedClick then if Settings.GetSetting("SELFCAST") then Settings.SetValue("SELFCAST",RuenUIDB.oldSelfCast) else SetModifiedClick("SELFCAST",RuenUIDB.oldSelfCast) end end for key, action in pairs(RuenUICharacter.addedBindings or {}) do if GetBindingAction(key) == action then SetBinding(key) end end SaveBindings(GetCurrentBindingSet()) RuenUIDB.disabled = true P.RefreshPetExtras() local addonRestore = false for variable, original in pairs(RuenUIDB.addonOriginal or {}) do _G[variable] = CopyTable(original) addonRestore = true end if RuenUICharacter.oldVoiceQuestCharDB then VoiceQuestCharDB = CopyTable(RuenUICharacter.oldVoiceQuestCharDB) addonRestore = true end say("Original settings restored for this character; automatic setup disabled account-wide. The extra saved layout is retained for reuse.") if addonRestore then say("Type /reload once to finish restoring addon preferences.") end end local function bench() if ticker then say("An FPS sample is already running."); return end local samples, total, below = {}, 0, 0 say("Sampling FPS once per second for 3 minutes. Play normally and keep WoW focused.") ticker = C_Timer.NewTicker(1, function() local fps = GetFramerate() samples[#samples + 1] = fps; total = total + fps if fps < 30 then below = below + 1 end if #samples == 180 then ticker:Cancel(); ticker = nil table.sort(samples) local r = {time = time(), count = 180, mean = total / 180, minimum = samples[1], p10 = samples[18], below30 = below, note = "1-second FPS readings, not a per-frame 1% low"} local reports = RuenUIDB.reports reports[#reports + 1] = r while #reports > 5 do table.remove(reports, 1) end say(string.format("FPS sample: avg %.1f, minimum %.1f, 10th percentile %.1f; %d/180 readings below 30. Saved on logout/reload.", r.mean, r.minimum, r.p10, below)) end end) end SLASH_RUENUI1 = "/ruen" SLASH_RUENUI2 = "/ruenui" SlashCmdList.RUENUI = function(message) init() message = message:lower():match("^%s*(.-)%s*$") local command, argument = message:match("^(%S+)%s*(.-)$") if message == "unlock" or message == "lock" then setSlotsLocked(message == "lock"); return elseif message == "bars" then say(P.BarHelp()); return elseif command == "cooldowns" or command == "mouseover" then say(P.ClassAssistCommand(command,argument)); return elseif command == "guns" then local reply = P.GunAudioCommand(argument) if reply then say(reply) end return elseif command == "meters" then say(P.DamageMeterCommand(argument)); return elseif command == "optimize" then P.OptimizerCommand(argument); return elseif message == "swing" or message:match("^swing%s") then say(P.SwingCommand(message:match("^swing%s+(%S+)") or "status")); return end if message == "" or message == "help" then P.Help(); return elseif command == "language" or command == "lang" then if argument == "" then P.LanguageStatus() else P.SetLanguage(argument, false) end return elseif command == "voice" then if argument == "" then P.LanguageStatus() else P.SetLanguage(argument, true) end return elseif message == "bindings" then if InCombatLockdown() then say("Reapply bindings after combat.") else P.ApplyUtilityBindings(true); P.ApplyExtraBindings(true) end return elseif message == "pet auto" then if P.ResetPetExtras() then say(P.Localized("Extra pet buttons use automatic overflow again.","Дополнительные кнопки питомца снова выбираются автоматически.")) else say(P.Localized("Change pet buttons after combat.","Измените кнопки питомца после боя.")) end return elseif message == "bags" then if InCombatLockdown() then say("Reposition bags after combat.") else queueCombinedBags() end return end if message == "apply" then RuenUIDB.disabled = nil; apply() elseif message == "restore" then restore() elseif message == "bench" then bench() elseif message == "status" then recordLayoutStatus(true) elseif message == "balanced" or message == "performance" then if InCombatLockdown() then say("Leave combat before changing graphics."); return end P.StopOptimizer() RuenUIDB.results = RuenUIDB.results or {} applyList(P.graphics) if message == "performance" then applyList(P.performance) end say(message .. " graphics applied at 100% render scale; use /ruen bench to measure.") elseif message == "export" then local manager = EditModeManagerFrame if manager and manager:GetActiveLayoutInfo() then local text = C_EditMode.ConvertLayoutInfoToString(manager:GetActiveLayoutInfo()) RuenUIDB.layoutExport = text if CopyToClipboard then CopyToClipboard(text) end say("Current native layout copied; also available through Edit Mode > Share > Copy to Clipboard.") end else say("/ruen apply | status | balanced | performance | bench | export | restore. Setup runs once per character. The small third-target display refreshes only while visible.") end end frame:RegisterEvent("PLAYER_ENTERING_WORLD") local function setupAfterLogin() if InCombatLockdown() then frame:RegisterEvent("PLAYER_REGEN_ENABLED"); return end frame:UnregisterEvent("PLAYER_REGEN_ENABLED") init() P.InitializeGunAudio() if RuenUIDB.disabled then return end local ok, err = pcall(function() P.MigrateBrand() setupThirdTarget() P.InitializeSwingTimers(function() return ownsLayout() and not EditModeManagerFrame:IsShown() end) if RuenUIDB.unlockedSlotsVersion ~= 1 then setSlotsLocked(false) end P.InitializePetExtras(function() return ownsLayout() and not EditModeManagerFrame:IsShown() end) installUILayoutHelpers() P.InitializeOptimizer() if RuenUIDB.graphicsVersion ~= P.graphicsVersion then RuenUIDB.results = RuenUIDB.results or {} applyList(P.graphics) RuenUIDB.graphicsVersion = P.graphicsVersion say("Long-session graphics applied: 60 FPS cap, lighter effects/distance, 100% render scale.") end -- Apply the chat preference to existing installs without resetting the -- UI profile. Preserve the old value for /ruen restore and honor later -- manual changes after this one-time upgrade. if RuenUIDB.chatFilterVersion ~= 1 then RuenUIDB.results = RuenUIDB.results or {} put("profanityFilter", 0) if C_CVar.GetCVar("profanityFilter") == "0" then RuenUIDB.chatFilterVersion = 1 end end local changed = applyAddonPresets() P.InitializeLanguage() P.ApplyUtilityBindings(false) P.ApplyExtraBindings(false) if RuenUICharacter.version ~= P.version then apply() else C_Timer.After(1, function() refreshUILayout() local seeded, seedError = pcall(seedClickBar) if not seeded then say("Click bar: " .. tostring(seedError)) end recordLayoutStatus(false) end) end if changed then say("Addon preferences saved. Type /reload once to finish setup.") end end) if not ok then say("Setup paused: " .. tostring(err) .. ". /ruen apply retries native UI setup.") end end frame:SetScript("OnEvent", function(self, event) self:UnregisterEvent(event) if event == "PLAYER_ENTERING_WORLD" then C_Timer.After(3, setupAfterLogin) else setupAfterLogin() end end)