diff --git a/.luacheckrc b/.luacheckrc index a3e0607..9549edb 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -18,16 +18,16 @@ globals = { -- WoW API the addon reads. Keep this list explicit: an unexpected global is usually a typo. read_globals = { -- Lua extensions in the WoW client - "date", + "date", "wipe", -- Namespaces - "C_AddOns", "C_CVar", "C_DamageMeter", "C_EditMode", "C_InputInterfaceStyle", "C_Timer", "C_UI", "Settings", "EventRegistry", + "C_AddOns", "C_CVar", "C_DamageMeter", "C_EditMode", "C_EventUtils", "C_InputInterfaceStyle", "C_Timer", "C_UI", "Settings", "Enum", "EventRegistry", -- Frames and UI (AutoSetupReloadPopup* are named in FrameXML/AutoSetup_ReloadPopup.xml) "CreateFrame", "UIParent", "EditModeManagerFrame", "InterfaceOptionsFrame", "InterfaceOptionsFrame_OpenToCategory", "InterfaceOptions_AddCategory", "AutoSetupReloadPopup", "AutoSetupReloadPopupMessage", -- Addons - "DisableAddOn", "EnableAddOn", "GetAddOnInfo", "GetNumAddOns", "LoadAddOn", + "DisableAddOn", "EnableAddOn", "GetAddOnInfo", "GetNumAddOns", -- Client - "CallErrorHandler", "CopyTable", "GetBuildInfo", "GetCVar", "SetCVar", "GetPhysicalScreenSize", + "CallErrorHandler", "CopyTable", "GetCVar", "SetCVar", "GetPhysicalScreenSize", "InCombatLockdown", "ReloadUI", "UnitAffectingCombat", "UnitExists", } diff --git a/AutoSetup.lua b/AutoSetup.lua index a56979b..5dd078a 100644 --- a/AutoSetup.lua +++ b/AutoSetup.lua @@ -9,16 +9,6 @@ local addonName, AutoSetup = ... AutoSetup = AutoSetup or {} _G.AutoSetup = AutoSetup -- expose to XML / scripts, which only see globals --- WoW flavor detection (same pattern used in AutoPotion's Core/Constants.lua). --- WOW_PROJECT_ID has no documented constant for WoW Forever yet (confirmed in-game via --- /dump WOW_PROJECT_ID, which currently reports 1/WOW_PROJECT_MAINLINE on the Forever beta --- client, since Forever runs on the Mainline client codebase). Detect it via interface number --- instead: interface numbers are 5 digits (e.g. 16001 for client 1.60.1); the 16000-19999 range --- is reserved for Forever ahead of BCC's 20000+, matching the detection used by DBM and --- Details-Framework/Plater. -local _, _, _, tocVersion = GetBuildInfo() -AutoSetup.isForever = (tocVersion and tocVersion >= 16000 and tocVersion < 20000) or false - local debugLog = {} -- rolling in‑memory log for /autosetup debug local lastResolution = nil -- last resolution string we evaluated local initDone = false -- the one verbose evaluation per login/reload has run (see RunInitialEvaluation) @@ -32,8 +22,8 @@ local controllerSupportChangedThisSession = false -- true once our SetCVar took local CONTROLLER_SUPPORT_CVAR = "InputDeviceInterfaceStyle" -- Native controller support needs the game's controller interface: on Forever, not on Retail. --- Checked by capability, not flavor, so a client that adds it later gets the option too; isForever --- is only for what depends on game content. The C_InputInterfaceStyle namespace alone isn't enough: +-- Checked by capability, not flavor, so a client that adds it later gets the option too. The +-- C_InputInterfaceStyle namespace alone isn't enough: -- Retail 12.1.7 ships it without the interface. Like Blizzard's InputUtil.IsGamepadUISupported(), -- also require the CVar to exist. AutoSetup.hasControllerInterface = C_InputInterfaceStyle ~= nil and GetCVar(CONTROLLER_SUPPORT_CVAR) ~= nil @@ -139,7 +129,8 @@ local function MigrateDB(db, version) end -- Run once, at ADDON_LOADED. Data from a newer AutoSetup, or data that fails to migrate, is left as it --- is: no migration runs on it and nothing resets it. +-- is: no migration runs on it and nothing resets it. A newer file's profiles still apply, from a copy, +-- so nothing this version does can write its shape into the file. local function LoadDB() if AutoSetupDB == nil then AutoSetupDB = { version = DB_VERSION, profiles = {} } @@ -156,9 +147,13 @@ local function LoadDB() end local db = AutoSetupDB - if type(db) == "table" and type(db.version) == "number" and db.version >= DB_VERSION - and type(db.profiles) == "table" then + if type(db) == "table" and db.version == DB_VERSION and type(db.profiles) == "table" then profiles = db.profiles + elseif type(db) == "table" and type(db.version) == "number" and db.version > DB_VERSION + and type(db.profiles) == "table" then + profiles = CopyTable(db.profiles) + Print("These saved profiles are from a newer AutoSetup. They apply, but profile changes " + .. "made this session won't be saved.") else Print("Couldn't read the saved profiles. They are kept as they were, " .. "and profile changes made this session won't be saved.") @@ -213,14 +208,15 @@ local function GetAddOnNameAndTitle(index) return GetAddOnInfo(index) end -local function GetEnabledState(name, index) +-- Without a character the state covers all characters, like EnableAddOn and DisableAddOn below. +-- "Some" (enabled on other characters only, say) matches neither wish, so it gets changed. +local function IsInDesiredState(name, index, desired) if C_AddOns and C_AddOns.GetAddOnEnableState then - -- Retail-style API: first argument is the addon name or index - return C_AddOns.GetAddOnEnableState(name or index) > 0 - else - local _, _, _, enabled = GetAddOnInfo(name or index) - return not not enabled + local state = C_AddOns.GetAddOnEnableState(name or index) + return state == (desired and Enum.AddOnEnableState.All or Enum.AddOnEnableState.None) end + local _, _, _, enabled = GetAddOnInfo(name or index) + return (not not enabled) == desired end local function EnableAddon(name, index) @@ -250,6 +246,20 @@ AutoSetup.GetAddOnNameAndTitle = GetAddOnNameAndTitle -- switching to a layout that's no longer wanted. local layoutRequest = 0 +-- Raw layout name -> CleanString result, so target changes don't rebuild the same strings. Wiped by +-- every full evaluation (CacheProfileLayouts), which keeps it to the layouts of this session. +local cleanedLayoutNames = {} + +local function CleanLayoutListName(name) + if not name then return "" end + local clean = cleanedLayoutNames[name] + if not clean then + clean = CleanString(name) + cleanedLayoutNames[name] = clean + end + return clean +end + local function ApplyEditLayoutInternal(targetNameClean, attemptsLeft, verbose, request) if request ~= layoutRequest then return end @@ -268,15 +278,16 @@ local function ApplyEditLayoutInternal(targetNameClean, attemptsLeft, verbose, r -- unsaved changes. The EditMode.Exit callback applies the profile's layout afterwards. if manager and manager:IsEditModeActive() then return end + local ready = manager and manager:IsInitialized() local foundIndex, foundName - if manager and manager:IsInitialized() then + if ready then local activeInfo = manager:GetActiveLayoutInfo() - if activeInfo and CleanString(activeInfo.layoutName) == targetNameClean then + if activeInfo and CleanLayoutListName(activeInfo.layoutName) == targetNameClean then return end for i, layoutInfo in ipairs(manager:GetLayouts()) do - if CleanString(layoutInfo.layoutName) == targetNameClean then + if CleanLayoutListName(layoutInfo.layoutName) == targetNameClean then foundIndex = i foundName = layoutInfo.layoutName break @@ -292,7 +303,8 @@ local function ApplyEditLayoutInternal(targetNameClean, attemptsLeft, verbose, r Debug("Switched to Edit Mode layout '" .. foundName .. "' (index " .. foundIndex .. ")") Print("Switched to layout '" .. foundName .. "'.") end - elseif attemptsLeft > 0 then + elseif attemptsLeft > 0 and not ready then + -- Only the layouts arriving late is worth a retry; a name missing from a loaded list stays missing. C_Timer.After(1.0, function() ApplyEditLayoutInternal(targetNameClean, attemptsLeft - 1, verbose, request) end) @@ -327,10 +339,10 @@ function AutoSetup.ExecuteReload() end Debug("Executing UI reload...") - if ReloadUI then - ReloadUI() - elseif C_UI and C_UI.Reload then + if C_UI and C_UI.Reload then C_UI.Reload() + elseif ReloadUI then + ReloadUI() else Debug("ERROR: No reload function available!") Print("ERROR: No reload function available for reload") @@ -388,21 +400,23 @@ local function ApplyAddonSet(profile, verbose) desired = true end - local currentlyEnabled = GetEnabledState(name, i) - if desired and not currentlyEnabled then - EnableAddon(name, i) - changed = true - if verbose then Debug("Enabling addon: " .. name) end - elseif not desired and currentlyEnabled then - DisableAddon(name, i) + if not IsInDesiredState(name, i, desired) then + if desired then + EnableAddon(name, i) + if verbose then Debug("Enabling addon: " .. name) end + else + DisableAddon(name, i) + if verbose then Debug("Disabling addon: " .. name) end + end changed = true - if verbose then Debug("Disabling addon: " .. name) end end end end end if changed then + -- Unsaved changes are lost when the game's AddOn list closes without saving (ResetAddOns). + if C_AddOns and C_AddOns.SaveAddOns then C_AddOns.SaveAddOns() end Debug("AddOn changes detected: Showing reload popup") -- Show popup instead of auto-reload ShowReloadPopup("addonset", "AddOn configuration changed for '" .. (profile.name or "this profile") .. "'.") @@ -427,7 +441,7 @@ end -- Addons that let AutoSetup switch their features: addon folder name -> name of the global API -- table. The API provides IsFeatureEnabled(feature) (nil for an unknown feature) and --- SetFeatureEnabled(feature, enabled). +-- SetFeatureEnabled(feature, enabled) (false when the feature couldn't be set). AutoSetup.FeatureProviders = { QoL = "QoLAPI", } @@ -475,7 +489,10 @@ local function ApplyFeatureSet(profile, verbose) if ok and enabled == nil then if verbose then Print("Unknown feature '" .. feature .. "' for " .. provider .. " in this profile.") end elseif ok and enabled ~= desired then - if AutoSetup.CallFeatureProvider(api.SetFeatureEnabled, feature, desired) then + local called, applied = AutoSetup.CallFeatureProvider(api.SetFeatureEnabled, feature, desired) + if called and applied == false then + Debug("Feature " .. key .. " could not be set.") + elseif called then Debug("Feature " .. key .. " set to " .. tostring(desired)) end end @@ -611,6 +628,7 @@ end -- client manages it. Only relevant on clients with the controller interface -- elsewhere a stale -- nativeControllerSupport value is ignored. local function CacheProfileLayouts(profile) + wipe(cleanedLayoutNames) layoutProfile = profile if not profile or (AutoSetup.hasControllerInterface and profile.nativeControllerSupport) then baseLayoutClean, targetLayoutClean = nil, nil @@ -639,12 +657,21 @@ end local eventFrame = CreateFrame("Frame") --- Only needed to switch to the target layout. Combat end (PLAYER_REGEN_ENABLED) isn't among them: --- it stays registered for the catch-up after an evaluation that ran in combat, and to leave the --- target layout (or switch to it, if combat start couldn't) once combat ends. It fires once per combat. -local TARGET_EVENTS = { "PLAYER_TARGET_CHANGED", "PLAYER_SOFT_ENEMY_CHANGED", "PLAYER_REGEN_DISABLED" } +-- Only needed to switch to the target layout, along with combat start. Combat end +-- (PLAYER_REGEN_ENABLED) isn't among them: it stays registered for the catch-up after an evaluation +-- that ran in combat, and to leave the target layout (or switch to it, if combat start couldn't) +-- once combat ends. It fires once per combat. +local TARGET_CHANGE_EVENTS = { "PLAYER_TARGET_CHANGED", "PLAYER_SOFT_ENEMY_CHANGED" } local targetEventsRegistered = nil -- nil until the first evaluation, so that one always logs the state +-- Layouts can't change in combat and combat end looks at the target anyway, so these two are also +-- dropped for the length of a fight. +local function SetTargetChangeEvents(registered) + for _, event in ipairs(TARGET_CHANGE_EVENTS) do + if registered then eventFrame:RegisterEvent(event) else eventFrame:UnregisterEvent(event) end + end +end + -- Listen to the target events only while a target layout applies, so without one AutoSetup does -- next to nothing during play. Recomputed on every full evaluation, after CacheProfileLayouts and -- ApplyControllerSupport (an unsettled input mode leaves Edit Mode alone until the next reload). @@ -652,8 +679,11 @@ local function UpdateTargetEventRegistration() local wanted = targetLayoutClean ~= nil and not IsInputModeUnsettled(layoutProfile) if wanted == targetEventsRegistered then return end targetEventsRegistered = wanted - for _, event in ipairs(TARGET_EVENTS) do - if wanted then eventFrame:RegisterEvent(event) else eventFrame:UnregisterEvent(event) end + SetTargetChangeEvents(wanted) + if wanted then + eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED") + else + eventFrame:UnregisterEvent("PLAYER_REGEN_DISABLED") end Debug(wanted and "Target layout applies: target and combat-start events registered." or "No target layout applies: target and combat-start events unregistered.") @@ -714,6 +744,14 @@ local function UpdateCurrentLayout() UpdateLayout(false) end +-- The player switched the controller interface in the game's options, which works without a reload. +-- That can settle the input mode (or unsettle it), and only a full evaluation would notice otherwise. +local function OnInputModeChanged() + if not initDone then return end + UpdateTargetEventRegistration() + UpdateCurrentLayout() +end + ------------------------------------------------------------------------------- -- Resolution monitoring (observe‑only) -- We never change the user's resolution; we only respond to changes. @@ -743,13 +781,16 @@ end -- Events ------------------------------------------------------------------------------- --- The target events (TARGET_EVENTS) are registered by UpdateTargetEventRegistration. +-- The target events are registered by UpdateTargetEventRegistration. eventFrame:RegisterEvent("ADDON_LOADED") eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD") eventFrame:RegisterEvent("EDIT_MODE_LAYOUTS_UPDATED") eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED") eventFrame:RegisterEvent("DISPLAY_SIZE_CHANGED") eventFrame:RegisterEvent("UI_SCALE_CHANGED") +if AutoSetup.hasControllerInterface and C_EventUtils.IsEventValid("INPUT_DEVICE_INTERFACE_TRANSITION") then + eventFrame:RegisterEvent("INPUT_DEVICE_INTERFACE_TRANSITION") +end eventFrame:SetScript("OnEvent", function(self, event, arg1) if event == "ADDON_LOADED" then @@ -776,13 +817,21 @@ eventFrame:SetScript("OnEvent", function(self, event, arg1) end elseif event == "EDIT_MODE_LAYOUTS_UPDATED" then RunInitialEvaluation() - elseif event == "PLAYER_REGEN_ENABLED" and applyAfterCombat then - EvaluateProfileState(false) - elseif event == "PLAYER_TARGET_CHANGED" - or event == "PLAYER_SOFT_ENEMY_CHANGED" - or event == "PLAYER_REGEN_DISABLED" - or event == "PLAYER_REGEN_ENABLED" then + elseif event == "PLAYER_REGEN_ENABLED" then + if targetEventsRegistered then SetTargetChangeEvents(true) end + if applyAfterCombat then + EvaluateProfileState(false) + else + UpdateCurrentLayout() + end + elseif event == "PLAYER_REGEN_DISABLED" then + UpdateCurrentLayout() + SetTargetChangeEvents(false) + elseif event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_SOFT_ENEMY_CHANGED" then UpdateCurrentLayout() + elseif event == "INPUT_DEVICE_INTERFACE_TRANSITION" then + -- Fires synchronously, possibly from inside our own SetCVar; look once it has finished. + C_Timer.After(0, OnInputModeChanged) end end) diff --git a/FrameXML/AutoSetup_Options.lua b/FrameXML/AutoSetup_Options.lua index b7870f6..b2831b5 100644 --- a/FrameXML/AutoSetup_Options.lua +++ b/FrameXML/AutoSetup_Options.lua @@ -137,21 +137,25 @@ local function ValidateFeatures(features) end end --- Retrieve available Edit Mode layouts (names) -local function GetLayoutNames() - if not C_EditMode or not C_EditMode.GetLayouts then - if C_AddOns and C_AddOns.LoadAddOn then - pcall(C_AddOns.LoadAddOn, "Blizzard_EditMode") - else - pcall(LoadAddOn, "Blizzard_EditMode") - end - end +-- Blizzard's own layout dropdown hides the presets of the other interface (keyboard and mouse or +-- controller) too. +local function IsOtherInterfacePreset(layoutInfo) + if layoutInfo.layoutType ~= Enum.EditModeLayoutType.Preset or layoutInfo.interfaceStyle == nil then + return false + end + local style = C_InputInterfaceStyle and C_InputInterfaceStyle.GetCurrentStyle + and C_InputInterfaceStyle.GetCurrentStyle() + return style ~= nil and style ~= layoutInfo.interfaceStyle +end +-- The names of the layouts a profile can use: the same list ApplyEditLayoutInternal searches, so +-- presets are included (C_EditMode.GetLayouts has only the saved ones). +local function GetLayoutNames() local names = {} - local layouts = C_EditMode and C_EditMode.GetLayouts and C_EditMode.GetLayouts() - if layouts and layouts.layouts then - for _, layoutInfo in pairs(layouts.layouts) do - if layoutInfo.layoutName then + local manager = EditModeManagerFrame + if manager and manager:IsInitialized() then + for _, layoutInfo in ipairs(manager:GetLayouts()) do + if layoutInfo.layoutName and not IsOtherInterfacePreset(layoutInfo) then table.insert(names, layoutInfo.layoutName) end end @@ -250,6 +254,13 @@ local function SetDamageMeterState(panel, state) panel.damageMeterButton:SetText("Damage Meter: " .. stateText) end +-- nil leaves the UI scale alone; the slider only matters with the box ticked. +local function SetScaleOverride(panel, scale) + panel.scaleCheck:SetChecked(scale ~= nil) + panel.scaleSlider:SetEnabled(scale ~= nil) + panel.scaleSlider:SetValue(scale or tonumber(GetCVar("uiScale")) or 1.0) +end + local function RefreshProfileList(panel) if not panel or not panel.listContent then return end @@ -304,7 +315,7 @@ local function RefreshProfileList(panel) local displayName = data.name or "Profile" local targetText = data.editLayoutTarget and (" -> " .. data.editLayoutTarget) or "" local hasAddons = (data.addonSet or data.featureSet) and "|cff00ff00Addons|r" or "|cffff0000No Addons|r" - local scaleText = data.scale and tostring(data.scale) or "default" + local scaleText = data.scale and tostring(data.scale) or "unchanged" local controllerText = (AutoSetup.hasControllerInterface and data.nativeControllerSupport) and " | |cff00ff00Controller|r" or "" local damageMeterText = "" @@ -332,7 +343,7 @@ local function RefreshProfileList(panel) panel.resInput:SetText(res) panel.baseLayoutInput:SetText(data.editLayoutBase or "") panel.targetLayoutInput:SetText(data.editLayoutTarget or "") - panel.scaleSlider:SetValue(data.scale or (tonumber(GetCVar("uiScale")) or 1.0)) + SetScaleOverride(panel, data.scale) if panel.controllerCheck then panel.controllerCheck:SetChecked(data.nativeControllerSupport or false) end SetDamageMeterState(panel, data.damageMeter) panel.addonsInput:SetText(BuildAddonsString(data.addonSet or {}, data.featureSet or {})) @@ -370,6 +381,9 @@ local function RefreshProfileList(panel) row:SetPoint("TOPLEFT", 0, 0) row:Show() end + + -- The scroll range follows the child's height; without this, rows past it can't be reached. + panel.listContent:SetHeight(math.max(-yOffset, 40)) end function AutoSetup_OpenOptionsPanel() @@ -395,8 +409,9 @@ function AutoSetup_OptionsPanel_OnLoad(panel) panel.baseLayoutInput = _G[baseName .. "BaseLayoutInput"] panel.baseLayoutLabel = _G[baseName .. "BaseLayoutLabel"] panel.targetLayoutInput = _G[baseName .. "TargetLayoutInput"] + panel.scaleCheck = _G[baseName .. "ScaleCheck"] panel.scaleSlider = _G[baseName .. "ScaleSlider"] - panel.scaleSliderText = _G[baseName .. "ScaleSliderText"] + panel.scaleSliderText = _G[baseName .. "ScaleSliderText"] -- the slider template's $parentText panel.controllerCheck = _G[baseName .. "ControllerCheck"] panel.damageMeterButton = _G[baseName .. "DamageMeterButton"] panel.addonsInput = _G[baseName .. "AddonsInput"] @@ -475,7 +490,8 @@ function AutoSetup_OptionsPanel_OnLoad(panel) local res = panel.resInput:GetText() or "" local baseLayout = panel.baseLayoutInput:GetText() or "" local targetLayout = panel.targetLayoutInput:GetText() or "" - local scale = tonumber(string.format("%.2f", panel.scaleSlider:GetValue())) + local scale = panel.scaleCheck:GetChecked() + and tonumber(string.format("%.2f", panel.scaleSlider:GetValue())) or nil -- Without the controller interface the checkbox is hidden but Edit still sets it from the -- stored value; store false so a stale true neither survives the save nor allows a blank base. local controllerSupport = AutoSetup.hasControllerInterface and panel.controllerCheck @@ -517,7 +533,7 @@ function AutoSetup_OptionsPanel_OnLoad(panel) panel.resInput:SetText("") panel.baseLayoutInput:SetText("") panel.targetLayoutInput:SetText("") - panel.scaleSlider:SetValue(tonumber(GetCVar("uiScale")) or 1.0) + SetScaleOverride(panel, nil) if panel.controllerCheck then panel.controllerCheck:SetChecked(false) end SetDamageMeterState(panel, nil) panel.addonsInput:SetText("") @@ -528,10 +544,14 @@ function AutoSetup_OptionsPanel_OnLoad(panel) panel.scaleSlider:SetMinMaxValues(0.65, 1.15) panel.scaleSlider:SetValueStep(0.01) panel.scaleSlider:SetObeyStepOnDrag(true) - panel.scaleSlider:SetValue(tonumber(GetCVar("uiScale")) or 1.0) panel.scaleSlider:SetScript("OnValueChanged", function(self, value) panel.scaleSliderText:SetText(string.format("UI Scale: %.2f", value)) end) + if panel.scaleCheck.Text then panel.scaleCheck.Text:SetText("Set UI scale") end + panel.scaleCheck:HookScript("OnClick", function(self) + panel.scaleSlider:SetEnabled(self:GetChecked()) + end) + SetScaleOverride(panel, nil) panel.scaleSliderText:SetText(string.format("UI Scale: %.2f", panel.scaleSlider:GetValue())) end @@ -552,4 +572,6 @@ function AutoSetup_OptionsPanel_OnLoad(panel) -- Built when shown, so it's current every time and costs nothing until the panel is opened. -- Save and delete refresh it while it's open. panel:HookScript("OnShow", AutoSetup.RefreshOptionsList) + -- The popup hangs off UIParent, so it wouldn't close with the settings by itself. + panel:HookScript("OnHide", HideLayoutPopup) end diff --git a/FrameXML/AutoSetup_Options.xml b/FrameXML/AutoSetup_Options.xml index 9f7efd6..ff8f446 100644 --- a/FrameXML/AutoSetup_Options.xml +++ b/FrameXML/AutoSetup_Options.xml @@ -193,6 +193,17 @@ + + + + + + + + + + + @@ -205,19 +216,6 @@ - - - - - - - - - - - - - diff --git a/FrameXML/AutoSetup_ReloadPopup.xml b/FrameXML/AutoSetup_ReloadPopup.xml index 60baee6..55e5560 100644 --- a/FrameXML/AutoSetup_ReloadPopup.xml +++ b/FrameXML/AutoSetup_ReloadPopup.xml @@ -3,7 +3,7 @@ ..\FrameXML\UI.xsd"> - + @@ -87,16 +87,7 @@ - -- Go through AutoSetup.ExecuteReload() so the combat-lockdown - -- guard applies here too; fall back to a direct call only if - -- the AutoSetup table is somehow unavailable. - if AutoSetup and AutoSetup.ExecuteReload then - AutoSetup.ExecuteReload() - elseif ReloadUI then - ReloadUI() - elseif C_UI and C_UI.Reload then - C_UI.Reload() - end + AutoSetup.ExecuteReload() @@ -121,14 +112,22 @@ - -- Hide the OKAY button inherited from DialogBoxFrame; our own buttons replace it. local inherited = _G[(self:GetName() or "") .. "Button"] if inherited then inherited:Hide() end + self:RegisterForDrag("LeftButton") - + + + self:StartMoving() + + + + self:StopMovingOrSizing() + + -- Bring to front when shown self:Raise(); diff --git a/README.md b/README.md index 8d96f25..999e757 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ In the options panel: - Optional alternate layout used while in combat or when you have a target. - Leave blank if you only want one layout for this resolution, or if this profile has native controller support enabled (same reason as above). 5. **UI Scale** - - Adjust the slider if you want a per‑profile UI scale override. + - Tick **Set UI scale** and adjust the slider for a per‑profile UI scale. Unticked leaves the scale alone. 6. **Damage Meter** - Click the button to step through `Damage Meter: Leave alone`, `On` and `Off`. - On and Off apply whenever the profile is applied. In combat the change waits until combat ends. diff --git a/docs/TESTING.md b/docs/TESTING.md deleted file mode 100644 index 00d7281..0000000 --- a/docs/TESTING.md +++ /dev/null @@ -1,275 +0,0 @@ -# In-game test checklist - -AutoSetup has no automated tests. Before a release, run this checklist on Retail and on WoW Forever. -Items marked **Retail only** or **Forever only** run on that flavor alone. Every check looks only at what the player sees or -what the game reports: the active layout, chat lines, errors, the saved variables file, the debug log -and the profiler. `docs/` is in `.pkgmeta`'s ignore list, so this file isn't in the release. - -## Tools - -- **`/as`** (or `/autosetup`): opens the options panel (profile list and form). -- **`/autosetup debug`**: prints the current resolution and the debug log (the last 50 lines, in - memory only, cleared by a reload). -- **`/autosetup testreload`**: runs the real reload path (`AutoSetup.ExecuteReload`). -- **Errors**: BugSack (with BugGrabber), or without it `/console scriptErrors 1` so Lua errors show - in the game's error frame. Turn one of them on before every run. -- **Saved variables file**: `WTF/Account//SavedVariables/AutoSetup.lua` inside the game - folder (`_retail_` for Retail, `_classic_beta_` for Forever). The client reads it at login and - overwrites it at logout or reload, so edit it only with the game closed, and look at it after - logging out. Back it up before items 1 to 3 and put it back afterwards. -- **Event registration**: the event frame is local, so read it from the debug log. Every full - evaluation (login, reload, resolution change, saving a profile, deleting the current - resolution's) whose result differs from the last one logs one of: - - `Target layout applies: target and combat-start events registered.` - - `No target layout applies: target and combat-start events unregistered.` - - The first evaluation after login always logs one. The events are `PLAYER_TARGET_CHANGED`, - `PLAYER_SOFT_ENEMY_CHANGED` and `PLAYER_REGEN_DISABLED`; `PLAYER_REGEN_ENABLED` stays registered. -- **Profiler** (CPU time, ms per frame, averaged over recent frames): - - ``` - /dump C_AddOnProfiler.GetAddOnMetric("AutoSetup", Enum.AddOnProfilerMetric.RecentAverageTime) - ``` - - Read it after about 10 seconds of the activity being measured. -- **Layouts**: you need at least two saved Edit Mode layouts (e.g. `Base` and `Target`), made in - Edit Mode, so a switch is visible: make them clearly different (move the player frame). - -## Setup files - -### Upgrade test file (item 2) - -The unversioned shape before saved-data version 2: profiles at the top level, with the old -`autoReload` flag and `suppressChat`. Replace the resolutions with your own (`/autosetup debug` -prints it) so one profile applies, and the layout names with yours: - -```lua -AutoSetupDB = { - ["1920x1080"] = { - ["name"] = "Desk", - ["editLayoutBase"] = "Base", - ["editLayoutTarget"] = "Target", - ["scale"] = 0.8, - ["nativeControllerSupport"] = false, - ["suppressChat"] = true, - ["autoReload"] = true, - ["addonSet"] = { - ["QoL"] = true, - }, - ["featureSet"] = { - ["ForeverQoL:viewport"] = true, - }, - }, - ["2560x1440"] = { - ["name"] = "Collision", - ["editLayoutBase"] = "Base", - ["featureSet"] = { - ["ForeverQoL:viewport"] = false, - ["QoL:viewport"] = true, - }, - }, -} -``` - -### Broken feature provider (item 11) - -Needs Quality of Life (folder `QoL`, API global `QoLAPI`) loaded and a profile with a `QoL:viewport` -entry in its AddOns box. These lines break QoL's API for the session only; `/reload` restores it. - -``` -/run QoLAPI.SetFeatureEnabled = function() error("AutoSetup test: SetFeatureEnabled") end -/run QoLAPI.IsFeatureEnabled = function() error("AutoSetup test: IsFeatureEnabled") end -``` - -## Checklist - -### 1. Fresh install - -Setup: game closed, move `AutoSetup.lua` out of `SavedVariables`. - -1. Log in. No errors. -2. Log out. The file reads `AutoSetupDB = { ["version"] = 2, ["profiles"] = {} }` (formatting aside). - -### 2. Upgrade from unversioned saved data - -Setup: game closed, put the [upgrade test file](#upgrade-test-file-item-2) in place. - -1. Log in. No errors. `/autosetup debug` shows `Saved data migrated from version 1 to 2.` `/as` - lists both profiles, and **Edit** on each fills the form with every setting (name, layouts, - scale, AddOns box with `QoL:viewport` or `!QoL:viewport`). -2. Log out. In the file: `version` is 2, both profiles are under `profiles`, neither has - `suppressChat` or `autoReload`, the first has `QoL:viewport = true` and no `ForeverQoL:` key, and - `Collision` has only `QoL:viewport = true` (the `QoL:` value won). -3. Log in and out again. The file is the same as after step 2 and the debug log has no migration line. - -### 3. Saved data from a newer AutoSetup - -Setup: game closed, take the file from item 2 and change `["version"] = 2` to `["version"] = 3`. -Keep a copy. - -1. Log in. No errors, no migration line in the debug log, the profiles are listed in `/as`. -2. Log out without saving or deleting a profile. The file matches the copy (key order aside). - -### 4. Base and target layout switching - -Setup: a profile for the current resolution with base `Base` and target `Target`. Stand near mobs. - -1. Target a mob: the `Target` layout applies. -2. Clear the target (Escape): the `Base` layout applies. -3. Get into combat without a target (let a mob hit you, then clear the target): `Target` applies. -4. Leave combat: `Base` applies. -5. None of these switches prints "layout applied" (or any other line) in chat. No errors. - -### 5. Picking a layout by hand - -1. Open Edit Mode and pick another layout from its dropdown. -2. Blizzard's "layout applied" line shows in chat, as it does without AutoSetup. - -### 6. Edit Mode open - -Setup: the profile from item 4. - -1. Open Edit Mode, then target a mob or clear the target. The layout doesn't change while it is open. -2. Close Edit Mode (keep or discard the changes). The layout for the current target state applies. - -### 7. Target change in combat - -Setup: the profile from item 4. - -1. Target a mob and pull it, so combat starts with the `Target` layout. -2. In combat, clear the target and target it again a few times: no switch, no "action blocked" - error or `ADDON_ACTION_BLOCKED` in BugSack. -3. Leave combat: the layout for the current target state applies, without errors. -4. Switches AutoSetup couldn't make before combat are caught up after it: open `/as` before a pull - and keep it open, then in combat change the profile's target layout to another saved layout - and save. No switch while in combat; - once combat ends, the new target layout (or the base layout, without a target) applies. - -### 8. Target events only while a target layout applies - -1. With a profile that has no target layout (or no profile for this resolution), `/reload`, then - `/autosetup debug`: it shows `No target layout applies: ... unregistered.` Turn on action - targeting (or use soft targeting), walk through a group of mobs for about 10 seconds and read the - profiler: close to zero. -2. In `/as`, give the profile a target layout and save. `/autosetup debug` shows - `Target layout applies: ... registered.` Targeting a mob switches layouts, without a reload. Read - the profiler again while soft-targeting through mobs, for comparison. -3. Remove the target layout and save. The debug log shows `... unregistered.` again and targeting - no longer switches layouts. - -### 9. Forever only: controller support on - -Setup: a profile with native controller support on and a target layout, applied (accept the reload -prompts until the controller interface is on). - -1. `/autosetup debug` after the last reload shows `No target layout applies: ... unregistered.` -2. Targeting mobs and entering combat don't change the Edit Mode layout. -3. Log in at a resolution whose profile wants the other controller mode. If BugSack shows - `ADDON_ACTION_BLOCKED` for `SetCVar` (it doesn't happen every time), the popup says the game - blocked it and to reload to try again or change it in Options > Controller, not that it was just - set, and the debug log shows `Setting InputDeviceInterfaceStyle was blocked.` Without the block, - the popup says it was just set. - -### 10. Window resizing - -Setup: windowed mode (Options > Graphics > Display Mode). - -1. Drag the window edge for a few seconds, then `/autosetup debug`. Each burst of resizing shows one - `Resolution check after size/scale change.` line, not one per event. -2. Make profiles for two window sizes (each with a different base layout), resize from one to the - other (or move the window to a monitor with another resolution): once the size settles, the - debug log shows `Resolution changed from ... to ...` and that size's profile applies. - -### 11. Broken feature provider - -Setup: QoL loaded, a profile for this resolution with base layout, scale and a QoL feature in the -AddOns box set to the opposite of QoL's current setting, so AutoSetup has to switch it -(`QoL:viewport` turns it on, `!QoL:viewport` off), plus another AddOns entry. - -1. Run the `SetFeatureEnabled` line from [Broken feature provider](#broken-feature-provider-item-11), - then save the profile in `/as` (which applies it). The error shows once in BugSack or the error - frame. The layout and scale are applied and the save message, list refresh and AddOns entry are - unaffected. -2. `/reload`, run the `IsFeatureEnabled` line, then save the profile with `QoL:viewport` again. The - error shows (from the save's check and from the apply). `Saved AutoSetup profile for .` - prints, the list shows the saved profile and the rest of the profile is applied. -3. `/reload` to restore QoL. - -### 12. Retail only: chat in restricted states - -1. In a dungeon or raid encounter (or in the open world with the secret-value test CVars from the - Warcraft Wiki's "Secret values" page turned on), with a target layout profile, let party, raid - and system lines arrive while targeting switches layouts. -2. Every line reaches chat. AutoSetup raises no errors. - -### 13. Options panel - -1. Log in and open `/as` straight away: the profile list shows every profile. -2. There is no "Suppress chat" checkbox. -3. On clients with the controller interface (Forever) the native controller support checkbox shows - and the base layout label says `(blank = controller default)`. On clients without it (Retail - 12.1.7 today) the checkbox is hidden and the label is plain `Base Edit Mode Layout Name`. -4. Save a new profile and delete one: the list updates each time while the panel is open. Close and - reopen the panel: the list is still correct. - -### 14. Reload popup - -1. Save a profile for this resolution whose AddOns box changes an addon's state (e.g. `!SomeAddon` - for an enabled addon). The popup lists the reason; with a controller change pending too (Forever), - it lists both. -2. Click **Reload UI**: the UI reloads. Outside combat, `/autosetup testreload` reloads too; in - combat it prints `Cannot reload UI in combat. Reload skipped.` - -### 15. Retail only: controller support saved before the capability fix - -Setup: with the game closed, set `["nativeControllerSupport"] = true` on the current resolution's -profile in `WTF/Account//SavedVariables/AutoSetup.lua`; the profile has a base and a -target layout. - -1. Log in: the base layout applies and no reload popup appears. `/autosetup debug` shows - `Target layout applies: ... registered.` and targeting a mob switches to the target layout. -2. The profile list in `/as` doesn't show `Controller` for that profile. -3. Click the profile's Edit button and save it. After logout the file shows - `["nativeControllerSupport"] = false`. -4. Clear the base layout and save: `Please enter a base Edit Mode layout name.` prints and nothing - is saved. - -### 16. Damage Meter setting - -Setup: a profile for this resolution with a base layout, and a second resolution you can switch to -(window sizes work, see item 10) with its own profile. Read the state with -`/dump GetCVar("damageMeterEnabled")` and by whether the Damage Meter shows. - -1. In `/as` press the `Damage Meter:` button repeatedly: `Leave alone`, `On`, `Off`, `Leave alone`. - On Forever, repeat with the controller interface on, then close the settings: no freeze. The - button doesn't overlap anything, with the controller checkbox shown (Forever) and hidden (Retail). -2. Set `On` with the CVar at 0 and save: the Damage Meter shows, no reload, the debug log shows - `Damage Meter turned on.` and the list shows `Meter On`. Set `Off` and save: it goes away, the log - shows `Damage Meter turned off.` and the list shows `Meter Off`. Save `Off` again: no new log line. - The `Meter` text doesn't run under the **Edit** button with long layout names. -3. **Edit** on that profile shows `Damage Meter: Off`. **Clear Form** shows `Leave alone`. Saving with - no base layout still prints the base layout message and saves nothing, whichever state is set. -4. With the profile on `Off`, turn the Damage Meter on in the game's advanced options, then `/reload`: - it is off. Do the same again and log out and in: it is off. Repeat with the profile on `On`, - turning it off by hand: it is on after the reload and after the login. -5. With this profile on `Off` and the second resolution's on `On`, change between them: each change - sets the CVar to that profile's value, no reload. -6. Set the profile to `Leave alone`, save, then `/reload` with the CVar at 1 and again with it at 0: - it stays as it was, and the list row has no `Meter` text. Change to this resolution from the - other one with the CVar at the opposite of that profile's value: it stays as it was. -7. With a profile on `Off`, delete it, and with no profile for this resolution `/reload`: the Damage - Meter stays as it was. With the current profile on `Off` and the CVar turned on by hand, delete - the second resolution's profile: the CVar stays at 1 (recreate that profile for later steps). -8. Open `/as` before a pull with the profile on `Off` and the CVar at 1. In combat, save it: the - Damage Meter stays. When combat ends it goes away with nothing to do. -9. With a profile that has a target layout, targeting mobs and entering combat log no Damage Meter - line: only a full evaluation applies the setting. -10. Save a profile with `Off`, then with `On`: Edit Mode's Damage Meter checkbox keeps its own setting - (with `Off` it is greyed out, which is expected). -11. Log out. In the file, `On` is `["damageMeter"] = true`, `Off` is `false`, Leave alone has no - `damageMeter` key, and `version` is still 2. A profile saved before this feature has no key, - behaves as step 6 and lists as before. -12. No errors in any step. - -A client without `C_DamageMeter` can't be run here; there the setting does nothing and the rest of the -profile applies.