local _, P = ... -- Explicit recovery only: no recurring work and no edits to live systemInfo. -- Cover every native system, including ones this class has not displayed yet. function P.ResetNativeLayoutPositions(layout) local manager = EditModePresetLayoutManager local defaults = manager and manager:GetCopyOfPresetLayouts() assert(defaults and defaults[1], "Native layout defaults are not ready") local index = {} for _, system in ipairs(defaults[1].systems or {}) do local key = system.system .. ":" .. tostring(system.systemIndex or 0) index[key] = system end local report = {native = 0, unavailable = {}, companions = {}} for _, system in ipairs(layout.systems or {}) do local key = system.system .. ":" .. tostring(system.systemIndex or 0) local preset = index[key] local position = preset and preset.anchorInfo if not position and manager.GetDefaultSystemAnchorInfo then local ok, result = pcall(manager.GetDefaultSystemAnchorInfo, manager, system.system, system.systemIndex) if ok then position = result end end if position then system.anchorInfo = CopyTable(position) system.anchorInfo2 = nil -- discard secondary snap anchors too system.isInDefaultPosition = true report.native = report.native + 1 else report.unavailable[#report.unavailable + 1] = "native system " .. key end end return report end local function attempt(report, label, fn) local ok, result = pcall(fn) if not ok or result == false then report.unavailable[#report.unavailable + 1] = label else report.companions[#report.companions + 1] = label end end function P.ResetCompanionPositions(report) local spoken = SpokenEnv if spoken and spoken.Options and spoken.Options.ResetPositions then -- Upstream's position-only reset preserves narration, volume and style. attempt(report, "Spoken narration", function() spoken.Options:ResetPositions() end) end local compendium = SpokenCompendium and SpokenCompendium.window if compendium then attempt(report, "Compendium", function() compendium:ClearAllPoints() compendium:SetPoint("CENTER", UIParent, "CENTER", 0, 0) if compendium.SetUserPlaced then compendium:SetUserPlaced(false) end end) end if C_AddOns and C_AddOns.IsAddOnLoaded("Leatrix_Maps") then -- Leatrix keeps a private live copy of its DB and overwrites saved -- values at logout. Use its own position-only reset, not a DB write -- that appears to work and is then silently undone. The pinned build -- exposes this button on its main panel; tiptext is locale-independent. attempt(report, "Leatrix Maps", function() for _, name in ipairs(UISpecialFrames or {}) do local panel = _G[name] if panel and panel.GetChildren and not (panel.IsForbidden and panel:IsForbidden()) then for _, child in ipairs({panel:GetChildren()}) do if not (child.IsForbidden and child:IsForbidden()) and child.tiptext == "Click to reset the map position and scale to the game default." then local click = child:GetScript("OnClick") if not click or (child.IsEnabled and not child:IsEnabled()) then return false end click(child, "LeftButton") return true end end end end return false end) end end function P.ResetNativePanelPositions(report) -- Hand ordinary windows (bank, professions, spellbook, merchant, etc.) -- back to Blizzard's panel manager. Never replace protected handlers or -- write UIPanelWindows/UIPanelLayout attributes from addon code. if not UpdateUIPanelPositions then return end attempt(report, "Native panels", function() for name in pairs(UIPanelWindows or {}) do local panel = _G[name] if panel and panel.SetUserPlaced and not (panel.IsForbidden and panel:IsForbidden()) then panel:SetUserPlaced(false) end end UpdateUIPanelPositions() end) end