ProjectAzilroka

ProjectAzilroka

512k Downloads

Square Minimap Buttons does not pick up on new minimap buttons

Emielvr opened this issue ยท 6 comments

commented

Picture showing button not being picked up on:
image

Some addons don't immediately add their minimap button to the minimap frame upon loading the game. In VuhDo's case for example, the addon takes a second to initialize before LDBIcon is called. As a result the minimap button is not present on the minimap frame the first time SMB:GrabMinimapButtons() is called.

Looking at the code of SMB:GrabMinimapButtons() I imagine SMB.ButtonCounts is being used to test whether new frames are present or not? Since the buttons are being moved from the minimap to the SMB bar, they disappear from the minimap frame. So after the first call to SMB:GrabMinimapButtons() most of the minimap buttons have been moved and the minimap frame will have less children than before. That means that if NumChildren > (SMB.ButtonCounts[Frame] or 0) will never succeed anymore unless you add at least as many buttons as have been removed by the previous SMB bar update.

In any case if I remove the if-statement which checks whether NumChildren is larger than the previous amount it will pick up on the new minimap button being added. But then there'd be no "caching" and it would loop through the frames every single time. Maybe you can cache them by name or something similar? Or update ButtonCounts to reflect the new frame counts after calling SMB:Update() to move the minimap buttons?

commented

It does indeed keep calling the function but it never makes it past the "NumChildren > (SMB.ButtonCounts[Frame] or 0)" if-statement after the first call (see second paragraph OP). Essentially, SMB.ButtonCounts holds an old, incorrect value value of the number of children of the minimap Minimap frame because SMB:Update() has moved them to the SMB bar without updating the count in SMB.ButtonCounts.

commented

I wait 6 seconds to grab minimap buttons after PEW. And every 6 seconds after that it tries to grab again. It is on a repeat cycle.

commented

What about updating the frame counts in SMB.ButtonCounts after calling SMB:Update()? That's only 1-2 extra iterations per login in the majority of cases.

commented

Caching by name wont work because frames do not have to have a name, and as Im thinking through this, Im not sure how we could solve this, as every solution I can think of requires iterating through every frame every update, which would not be ideal at all.

commented

To summarize:

Addon 1 adds minimap button, NumChrilden = 1
Addon 2 adds minimap button, NumChildren = 2
SMB:GrabMinimapButtons() is called
NumChildren (2) > SMB.ButtonCounts[Minimap] (0)
SMB.ButtonCounts[Minimap] gets assigned value of NumChildren(2)
SMB:Update() is called, buttons are moved to SMB bar, NumChildren = 0
Addon 3 adds minimap button, NumChildren = 1
SMB:GrabMinimapButtons() is called
NumChildren (1) not larger than SMB.ButtonCounts[Minimap] (2)
SMB:Update() is not called

commented

If its only being called every 6 seconds we can probably just drop ButtonCounts and iterate everything every time.