Skip to content

Commit 095b340

Browse files
committed
fixed for MOP
1 parent 23765a0 commit 095b340

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

.context/patterns.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,3 +801,101 @@ end
801801
- When debugging issues where state "randomly" appears or disappears
802802
- During code review of features that modify pooled object properties
803803
- When implementing new visual indicators or state tracking on existing pooled types
804+
805+
## WindowGrouping Integration
806+
807+
### Pattern: Frame-like Objects Must Implement Show/Hide/IsShown and Fade Animations
808+
**Problem**: Custom UI objects added to WindowGrouping (via `windowGrouping:AddWindow()`) fail with "Frame must have fadeIn and fadeOut animations" or cause errors when methods like `Hide()` or `IsShown()` are called.
809+
810+
**Why**: The WindowGrouping system expects all registered frames to behave like standard WoW frames with:
811+
1. **Standard frame methods**: `Show()`, `Hide()`, `IsShown()`
812+
2. **Fade animation groups**: `fadeIn`, `fadeOut` properties
813+
3. **Callback support**: `Hide(callback)` must support optional callback parameter for chained animations
814+
815+
When these requirements aren't met, the window grouping system can't properly coordinate showing/hiding multiple windows with fade animations.
816+
817+
**Solution Pattern**:
818+
1. **Implement Show/Hide/IsShown methods** that delegate to the actual UI frame
819+
2. **Attach fade animations** using `animations:AttachFadeGroup()` on the frame
820+
3. **Support optional callback in Hide()** for animation chaining
821+
4. **Store fadeIn/fadeOut** as properties on the object itself
822+
823+
**Example** (from frames/classic/currency.lua fix):
824+
```lua
825+
-- At module level, import animations
826+
---@class Animations: AceModule
827+
local animations = addon:GetModule('Animations')
828+
829+
-- Define the frame-like class with animation properties
830+
---@class CurrencyIconGrid
831+
---@field iconGrid Grid
832+
---@field fadeIn AnimationGroup
833+
---@field fadeOut AnimationGroup
834+
local CurrencyIconGrid = {}
835+
836+
-- Implement Show/Hide/IsShown methods
837+
function CurrencyIconGrid:Show()
838+
self.iconGrid.frame:Show()
839+
end
840+
841+
function CurrencyIconGrid:Hide(callback)
842+
-- Support optional callback parameter used by windowGrouping
843+
if callback then
844+
self.fadeOut.callback = callback
845+
self.fadeOut:Play()
846+
else
847+
self.iconGrid.frame:Hide()
848+
end
849+
end
850+
851+
function CurrencyIconGrid:IsShown()
852+
return self.iconGrid.frame:IsShown()
853+
end
854+
855+
-- In the constructor, attach fade animations
856+
function currency:CreateIconGrid(parent)
857+
local b = {}
858+
setmetatable(b, {__index = CurrencyIconGrid})
859+
860+
-- Create the grid frame
861+
local g = grid:Create(parent)
862+
-- ... configure grid ...
863+
b.iconGrid = g
864+
865+
-- Attach fade animations for windowGrouping compatibility
866+
b.fadeIn, b.fadeOut = animations:AttachFadeGroup(g:GetContainer())
867+
868+
return b
869+
end
870+
871+
-- Now safe to add to window grouping
872+
b.windowGrouping:AddWindow('currencyConfig', b.currencyFrame)
873+
```
874+
875+
**Reference Implementation** (frames/themeconfig.lua:98):
876+
```lua
877+
-- ThemeConfig frame with proper windowGrouping integration
878+
tc.fadeIn, tc.fadeOut = animations:AttachFadeAndSlideLeft(tc.frame)
879+
-- Methods are inherited from the frame itself
880+
```
881+
882+
**When to Apply**:
883+
- Any custom UI object added to WindowGrouping via `AddWindow()`
884+
- Objects that wrap or encapsulate WoW frames but don't expose frame methods directly
885+
- When seeing errors: "Frame must have fadeIn and fadeOut animations"
886+
- When seeing errors about missing `Hide()`, `Show()`, or `IsShown()` methods
887+
- Before registering a new window type with the window grouping system
888+
889+
**Critical Requirements Checklist**:
890+
-`Show()` method exists and shows the frame
891+
-`Hide()` method exists with optional callback parameter
892+
-`Hide(callback)` plays fadeOut animation and triggers callback when provided
893+
-`IsShown()` method exists and returns boolean
894+
-`fadeIn` property contains AnimationGroup from AttachFadeGroup
895+
-`fadeOut` property contains AnimationGroup from AttachFadeGroup
896+
897+
**Related Files**:
898+
- `util/windowgroup.lua:16` - Assertion that checks for fadeIn/fadeOut
899+
- `util/windowgroup.lua:21,28,33,34,41` - Calls to IsShown(), Hide(), Show()
900+
- `frames/classic/currency.lua:65-81,168` - Example implementation
901+
- `frames/themeconfig.lua:98` - Reference implementation with AttachFadeAndSlideLeft

frames/classic/currency.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ local const = addon:GetModule('Constants')
1616
---@class Events: AceModule
1717
local events = addon:GetModule('Events')
1818

19+
---@class Animations: AceModule
20+
local animations = addon:GetModule('Animations')
21+
1922
---@class CurrencyItem: Item
2023
---@field frame Frame
2124
---@field icon Texture
@@ -55,8 +58,28 @@ end
5558
---@class CurrencyIconGrid
5659
---@field iconGrid Grid
5760
---@field private iconIndex CurrencyItem[]
61+
---@field fadeIn AnimationGroup
62+
---@field fadeOut AnimationGroup
5863
local CurrencyIconGrid = {}
5964

65+
function CurrencyIconGrid:Show()
66+
self.iconGrid.frame:Show()
67+
end
68+
69+
function CurrencyIconGrid:Hide(callback)
70+
-- Support optional callback parameter used by windowGrouping
71+
if callback then
72+
self.fadeOut.callback = callback
73+
self.fadeOut:Play()
74+
else
75+
self.iconGrid.frame:Hide()
76+
end
77+
end
78+
79+
function CurrencyIconGrid:IsShown()
80+
return self.iconGrid.frame:IsShown()
81+
end
82+
6083
function CurrencyIconGrid:Update()
6184
for _, cell in pairs(self.iconGrid.cells) do
6285
---@cast cell CurrencyItem
@@ -141,6 +164,9 @@ function currency:CreateIconGrid(parent)
141164
g.maxCellWidth = 7
142165
b.iconGrid = g
143166

167+
-- Attach fade animations for windowGrouping compatibility
168+
b.fadeIn, b.fadeOut = animations:AttachFadeGroup(g:GetContainer())
169+
144170
b:Update()
145171
events:RegisterEvent('CURRENCY_DISPLAY_UPDATE', function()
146172
b:Update()

0 commit comments

Comments
 (0)