Close the window when Escape is pressed

Register the main frame ("AmibisMainFrame") in UISpecialFrames so Escape
hides it and suppresses the game menu while it is open, matching the
default UI panels.

Move the stats-retry timer cleanup into the frame's OnHide script so the
close button, Escape, and /amibis all stop the timer.

Tests: the mock now registers named frames in _G and runs OnHide scripts.
The UI suite simulates FrameXML's CloseSpecialWindows() and asserts the
frame hides and the retry timer is cleared. 108 passing.
This commit is contained in:
dfj committed 2026-10-24 13:57:09 +02:00
1 parent cc3971fe93
commit d8fefc947e
6 files changed
+77 -9

No files matched your search

+1
View File
@@ -42,4 +42,5 @@ Amibis/
- Max 17 visible rows; rows are clickable (Shift+click = chat link, Ctrl+click = dress-up) - 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. - 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 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. - 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.
+1 -1
View File
@@ -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_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_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 <name>` parsing: override set/clear, case and multi-word normalization, `spec clear` not treated as a spec name | | `test_slash.lua` | `/amibis spec <name>` 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 ## Layout
+26
View File
@@ -53,4 +53,30 @@ describe("UI stat panel", function()
expect(holyTexts["+Healing"]).toBeTruthy() expect(holyTexts["+Healing"]).toBeTruthy()
expect(holyTexts["+Spell Damage"]).toBeFalsy() expect(holyTexts["+Spell Damage"]).toBeFalsy()
end) 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) end)
+26 -4
View File
@@ -71,7 +71,7 @@ local function makeChild()
end end
local function makeFrame() 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, { return setmetatable(frame, {
__index = function(self, key) __index = function(self, key)
if key == "CreateFontString" then if key == "CreateFontString" then
@@ -86,10 +86,28 @@ local function makeFrame()
table.insert(self.textures, tx) table.insert(self.textures, tx)
return tx return tx
end 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 elseif key == "Show" then
return function() self.shown = true; return self end return function()
self.shown = true
return self
end
elseif key == "Hide" then 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 elseif key == "IsShown" then
return function() return self.shown end return function() return self.shown end
elseif key == "SetSize" then elseif key == "SetSize" then
@@ -112,11 +130,15 @@ local function makeFrame()
end end
_G.MockFrames = {} _G.MockFrames = {}
function CreateFrame() function CreateFrame(frameType, name, parent, template)
local f = makeFrame() local f = makeFrame()
if name then
_G[name] = f
end
table.insert(_G.MockFrames, f) table.insert(_G.MockFrames, f)
return f return f
end end
_G.GameTooltip = makeFrame() _G.GameTooltip = makeFrame()
_G.SlashCmdList = {} _G.SlashCmdList = {}
_G.UISpecialFrames = { "GameMenuFrame", "StaticPopup1" }
+22 -4
View File
@@ -52,6 +52,27 @@ local function CreateMainFrame()
self:StopMovingOrSizing() self:StopMovingOrSizing()
Amibis:SaveFramePosition(self) Amibis:SaveFramePosition(self)
end) 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) frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
return frame return frame
@@ -584,11 +605,8 @@ function ns.UI.ToggleFrame()
end end
if MainFrame:IsShown() then if MainFrame:IsShown() then
-- Hiding runs the frame's OnHide script, which stops the stats retry timer.
MainFrame:Hide() MainFrame:Hide()
if Amibis._statsRetryTimer then
Amibis._statsRetryTimer:Hide()
Amibis._statsRetryTimer = nil
end
else else
MainFrame:Show() MainFrame:Show()
Amibis._statsRetryAttempts = nil Amibis._statsRetryAttempts = nil
+1
View File
@@ -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 - **Shift+Click** a row to link the BIS item in chat
- **Ctrl+Click** a row to open the dress-up preview - **Ctrl+Click** a row to open the dress-up preview
- **Hover** a row to see the item tooltip - **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 - **Click a phase segment** (T4 | T5 | T6 | ZA) to switch the comparison target
## Adding BIS Lists ## Adding BIS Lists