diff --git a/AGENTS.md b/AGENTS.md index 631cde9..bca05e4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -42,4 +42,5 @@ Amibis/ - Max 17 visible rows; rows are clickable (Shift+click = chat link, Ctrl+click = dress-up) - Stats panel is **per-spec**: `SPEC_STAT_PROFILES` in `Amibis.lua` defines an ordered `{ stat, weight }` list for every class/spec (casters see spell damage/hit/crit/haste, melee see strength/AP/hit/expertise/armor pen, tanks see stamina/defense/dodge/parry/block, healers see healing/spirit/mp5). The same weights rank top upgrades, score completion, and pick which two gains are shown in the upgrade line. Keep profiles to 8 rows so the panel fits the frame. - The phase-progress bar always measures the **latest** phase, independent of the selected phase: stats-based once item data is cached, slot-based (prefixed `~`) until then. It refreshes on talent and equipment changes. +- The main frame is registered in `UISpecialFrames`, so Escape closes it (and suppresses the game menu while it is open). `MainFrame`'s `OnHide` clears the stats retry timer, so both the close button and Escape clean up. - Stat values are read via `STAT_MAP` (WoW `GetItemStats` keys → internal stat names); TBC's per-school hit/crit/haste keys are all mapped to one internal stat. diff --git a/Amibis/Tests/README.md b/Amibis/Tests/README.md index a92bc39..8cd658d 100644 --- a/Amibis/Tests/README.md +++ b/Amibis/Tests/README.md @@ -27,7 +27,7 @@ apt-get download lua5.4 && dpkg -x lua5.4_*.deb /tmp/lua && /tmp/lua/usr/bin/lua | `test_stats.lua` | `ScanItemStats`: MAX aggregation across alias keys (spell damage schools, healing, haste/crit/mp5 ratings), single-mapping pass-through, unmapped key filtering, nil handling | | `test_compare.lua` | `CompareGear`: BIS counting, weighted upgrade ranking, positive-diffs-only scoring, per-spec stat profiles (Shadow counts spell damage, Holy counts healing, Warrior counts strength/AP, tank mitigation stats), `GetStatKeysForSpec`, `GetCompletionRatio` | | `test_slash.lua` | `/amibis spec ` parsing: override set/clear, case and multi-word normalization, `spec clear` not treated as a spec name | -| `test_ui.lua` | UI smoke test with mocked frames: the stats panel rebuilds when switching Shadow → Holy (regression: old rows were hidden via a missing `label` field, which errored and left the Shadow rows on screen) | +| `test_ui.lua` | UI smoke tests with mocked frames: the stats panel rebuilds when switching Shadow → Holy (regression: old rows were hidden via a missing `label` field, which errored and left the Shadow rows on screen), and the main frame is registered in `UISpecialFrames` so Escape closes it | ## Layout diff --git a/Amibis/Tests/test_ui.lua b/Amibis/Tests/test_ui.lua index 091da40..850c3d3 100644 --- a/Amibis/Tests/test_ui.lua +++ b/Amibis/Tests/test_ui.lua @@ -53,4 +53,30 @@ describe("UI stat panel", function() expect(holyTexts["+Healing"]).toBeTruthy() expect(holyTexts["+Spell Damage"]).toBeFalsy() end) + + it("closes the window when Escape is pressed", function() + ns.UI.Initialize() + if not ns.UI.IsShown() then + ns.UI.ToggleFrame() + end + expect(ns.UI.IsShown()).toBeTruthy() + + local registered = false + for _, name in ipairs(UISpecialFrames) do + if name == "AmibisMainFrame" then registered = true end + end + expect(registered).toBeTruthy() + + -- Simulate an in-flight stats retry so the OnHide cleanup is exercised. + ns.Amibis._statsRetryTimer = CreateFrame("Frame") + + -- Mirrors FrameXML's CloseSpecialWindows(): hide every shown special frame. + for _, name in ipairs(UISpecialFrames) do + local frame = _G[name] + if frame and frame:IsShown() then frame:Hide() end + end + + expect(ns.UI.IsShown()).toBeFalsy() + expect(ns.Amibis._statsRetryTimer).toBeNil() + end) end) diff --git a/Amibis/Tests/wow_mocks.lua b/Amibis/Tests/wow_mocks.lua index e319303..43baa5b 100644 --- a/Amibis/Tests/wow_mocks.lua +++ b/Amibis/Tests/wow_mocks.lua @@ -71,7 +71,7 @@ local function makeChild() end local function makeFrame() - local frame = { fonts = {}, textures = {}, shown = true, width = 0, height = 0 } + local frame = { fonts = {}, textures = {}, shown = true, width = 0, height = 0, scripts = {} } return setmetatable(frame, { __index = function(self, key) if key == "CreateFontString" then @@ -86,10 +86,28 @@ local function makeFrame() table.insert(self.textures, tx) return tx end + elseif key == "SetScript" then + return function(_, event, handler) + self.scripts[event] = handler + return self + end + elseif key == "GetScript" then + return function(_, event) + return self.scripts[event] + end elseif key == "Show" then - return function() self.shown = true; return self end + return function() + self.shown = true + return self + end elseif key == "Hide" then - return function() self.shown = false; return self end + return function() + local wasShown = self.shown + self.shown = false + local handler = self.scripts["OnHide"] + if wasShown and handler then handler(self) end + return self + end elseif key == "IsShown" then return function() return self.shown end elseif key == "SetSize" then @@ -112,11 +130,15 @@ local function makeFrame() end _G.MockFrames = {} -function CreateFrame() +function CreateFrame(frameType, name, parent, template) local f = makeFrame() + if name then + _G[name] = f + end table.insert(_G.MockFrames, f) return f end _G.GameTooltip = makeFrame() _G.SlashCmdList = {} +_G.UISpecialFrames = { "GameMenuFrame", "StaticPopup1" } diff --git a/Amibis/UI/ComparisonFrame.lua b/Amibis/UI/ComparisonFrame.lua index 8c175be..62397a0 100644 --- a/Amibis/UI/ComparisonFrame.lua +++ b/Amibis/UI/ComparisonFrame.lua @@ -52,6 +52,27 @@ local function CreateMainFrame() self:StopMovingOrSizing() Amibis:SaveFramePosition(self) end) + frame:SetScript("OnHide", function() + if Amibis._statsRetryTimer then + Amibis._statsRetryTimer:Hide() + Amibis._statsRetryTimer = nil + end + end) + + -- Registering with UISpecialFrames makes the Escape key close the window + -- (and suppresses the game menu, like the default UI panels). + if UISpecialFrames then + local registered = false + for _, name in ipairs(UISpecialFrames) do + if name == "AmibisMainFrame" then + registered = true + break + end + end + if not registered then + table.insert(UISpecialFrames, "AmibisMainFrame") + end + end frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0) return frame @@ -584,11 +605,8 @@ function ns.UI.ToggleFrame() end if MainFrame:IsShown() then + -- Hiding runs the frame's OnHide script, which stops the stats retry timer. MainFrame:Hide() - if Amibis._statsRetryTimer then - Amibis._statsRetryTimer:Hide() - Amibis._statsRetryTimer = nil - end else MainFrame:Show() Amibis._statsRetryAttempts = nil diff --git a/README.md b/README.md index 3380c19..7e3e4a1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ A World of Warcraft: The Burning Crusade Classic addon that compares your equipp - **Shift+Click** a row to link the BIS item in chat - **Ctrl+Click** a row to open the dress-up preview - **Hover** a row to see the item tooltip +- **Press Escape** to close the window (registered in `UISpecialFrames`) - **Click a phase segment** (T4 | T5 | T6 | ZA) to switch the comparison target ## Adding BIS Lists