Skip to content

Fix(Unlock Mode): keep cascade-moved elements out of the screen center - #2098

Open
JuJuFX-dev wants to merge 1 commit into
EllesmereGaming:mainfrom
JuJuFX-dev:fix/unlock-anchor-pending-center
Open

JuJuFX-dev wants to merge 1 commit into
EllesmereGaming:mainfrom
JuJuFX-dev:fix/unlock-anchor-pending-center

Conversation

@JuJuFX-dev

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes an element jumping to the middle of the screen after its anchor link is removed. In unlock mode, when an element is repositioned by the anchor cascade (because the element it is anchored to was moved or resized), ApplyAnchorPosition records the new position for the eventual save. That record was being written with no coordinates: the local variables holding the computed center were declared inside the if/else branch that computes them, while the write sits after that block has already ended, so Lua read two globals that are never set and stored x = nil, y = nil instead. On Save & Exit that nil pair is converted to 0, 0, which is the exact center of the screen.

Nothing looked wrong while the anchor was still in place, because an anchored element has its position recomputed from its target on every apply, and the saved coordinates are never used. Removing the anchor is the moment the saved position starts to matter, and the element then snapped to the screen center instead of staying where the user had left it. Elements with their own grow direction (Cooldown Manager bars and action bars) were never affected: those take a separate path that stores a marker instead of coordinates, and the marker path resolves the position from the element's live bounds at save time.

The fix hoists the two declarations to function scope, so the save record now carries exactly the coordinates the element was positioned at. No behavior changes anywhere else: the placement math, the pixel snapping and the idempotent skip guard are untouched, and the grow-direction path is unchanged.

How was it tested?

Tested in-game on live. The scoping defect was also reproduced outside the game with a small Lua 5.1 harness that slices the real tail of ApplyAnchorPosition out of the file and runs it against stub frames: before the fix it shows the saved record holding nil coordinates while the element was positioned elsewhere, plus the two undeclared globals being read; after the fix the record matches the placement, and the grow-direction path still stores its marker.

Checklist

  • New settings default OFF (no behavior change without opt-in) - N/A, no new settings
  • Zero cost while disabled: no events registered, no polling, no hooks doing work, no frames built - N/A, no new feature
  • Cheap while enabled: event-driven (no polling, no timer-based logic, no per-frame allocations) - unchanged, the fix moves two declarations
  • No writes onto Blizzard-owned frames (weak-table pattern used); HookScript/hooksecurefunc only, never SetScript on Blizzard frames - N/A
  • Tested in-game on live; no version gates or pre-Midnight APIs added

ApplyAnchorPosition declared bCenterX/bCenterY inside the CENTER branch of
the placement if/else, but the pendingPositions write near the end of the
function sits outside that block. Lua read two never-set globals there, so an
element the anchor cascade moved during unlock mode stored { point = "CENTER",
x = nil, y = nil }. CommitPositions passes that straight to SaveBarPosition,
ConvertToCenterPos short-circuits CENTER/CENTER to "x or 0, y or 0", and the
saved position becomes the screen center. Invisible while the anchor stands
(the position is recomputed every apply), but the element jumps to the middle
of the screen once the anchor is removed.

Hoist the declaration to function scope so the write reads the values that
were actually SetPoint'd. Elements with their own grow direction are
unaffected: those take the growSkip path above and store { _anchored = true }.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant