From 24a0107c8257ec88a85ecdf259c7e78572d8435e Mon Sep 17 00:00:00 2001 From: Hokken Date: Fri, 23 Jan 2026 11:09:27 +0000 Subject: [PATCH 1/2] Save MultiBar position across sessions - Add position persistence for the main MultiBot UI (MultiBar) - Position is saved to MultiBotSave.MultiBarPosition on drag stop - Position is restored on PLAYER_ENTERING_WORLD event - Uses BOTTOMRIGHT anchor for consistent positioning - Properly calculates coordinates relative to UIParent Co-Authored-By: Claude Opus 4.5 --- Core/MultiBotInit.lua | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Core/MultiBotInit.lua b/Core/MultiBotInit.lua index a11d00f..b11f446 100644 --- a/Core/MultiBotInit.lua +++ b/Core/MultiBotInit.lua @@ -182,6 +182,22 @@ tMultiBar:SetMovable(true) -- Évite les micro-dépassements avec certains UI scale qui finissent par décaler Y tMultiBar:SetClampedToScreen(true) +-- Restore saved position after login/reload +do + local restoreFrame = CreateFrame("Frame") + restoreFrame:RegisterEvent("PLAYER_ENTERING_WORLD") + restoreFrame:SetScript("OnEvent", function(self, event) + if MultiBotSave and MultiBotSave.MultiBarPosition then + local pos = MultiBotSave.MultiBarPosition + if pos.x and pos.y then + tMultiBar:ClearAllPoints() + tMultiBar.setPoint(pos.x, pos.y) + end + end + self:UnregisterEvent("PLAYER_ENTERING_WORLD") + end) +end + -- LEFT -- local tLeft = tMultiBar.addFrame("Left", -76, 2, 32) @@ -1617,7 +1633,29 @@ tButton:SetScript("OnDragStart", function() MultiBot.frames["MultiBar"]:StartMoving() end) tButton:SetScript("OnDragStop", function() - MultiBot.frames["MultiBar"]:StopMovingOrSizing() + local frame = MultiBot.frames["MultiBar"] + frame:StopMovingOrSizing() + + -- Get frame position before re-anchoring + local frameRight = frame:GetRight() + local frameBottom = frame:GetBottom() + local parentRight = UIParent:GetRight() + + -- Calculate BOTTOMRIGHT coordinates (setPoint uses BOTTOMRIGHT anchor) + local x = frameRight - parentRight -- negative = left of right edge + local y = frameBottom -- positive = above bottom edge + + -- Re-anchor to BOTTOMRIGHT for consistency + frame:ClearAllPoints() + frame:SetPoint("BOTTOMRIGHT", x, y) + + -- Update frame's internal position tracking + frame.x = x + frame.y = y + + -- Save position to SavedVariables + MultiBotSave = MultiBotSave or {} + MultiBotSave.MultiBarPosition = { x = x, y = y } end) tButton.doLeft = function(pButton) MultiBot.ShowHideSwitch(pButton.parent.frames["Main"]) From de13878cf3d4217975e3d974514e1d9834e86877 Mon Sep 17 00:00:00 2001 From: Hokken Date: Sun, 25 Jan 2026 19:14:34 +0000 Subject: [PATCH 2/2] Refactor: Use existing save/restore mechanism for MultiBar position Instead of introducing a parallel persistence path, this update: 1. Uses existing MultiBot.toPoint() helper on drag stop 2. Saves to existing MultiBotSave["MultiBarPoint"] key 3. Removes duplicate PLAYER_ENTERING_WORLD handler (ADDON_LOADED in MultiBotHandler.lua already restores from this key) This ensures position is saved immediately on drag stop while staying consistent with the existing save/restore architecture. --- Core/MultiBotInit.lua | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/Core/MultiBotInit.lua b/Core/MultiBotInit.lua index b11f446..debc7c5 100644 --- a/Core/MultiBotInit.lua +++ b/Core/MultiBotInit.lua @@ -182,21 +182,7 @@ tMultiBar:SetMovable(true) -- Évite les micro-dépassements avec certains UI scale qui finissent par décaler Y tMultiBar:SetClampedToScreen(true) --- Restore saved position after login/reload -do - local restoreFrame = CreateFrame("Frame") - restoreFrame:RegisterEvent("PLAYER_ENTERING_WORLD") - restoreFrame:SetScript("OnEvent", function(self, event) - if MultiBotSave and MultiBotSave.MultiBarPosition then - local pos = MultiBotSave.MultiBarPosition - if pos.x and pos.y then - tMultiBar:ClearAllPoints() - tMultiBar.setPoint(pos.x, pos.y) - end - end - self:UnregisterEvent("PLAYER_ENTERING_WORLD") - end) -end +-- Position is restored via ADDON_LOADED in MultiBotHandler.lua using MultiBotSave["MultiBarPoint"] -- LEFT -- @@ -1636,26 +1622,9 @@ tButton:SetScript("OnDragStop", function() local frame = MultiBot.frames["MultiBar"] frame:StopMovingOrSizing() - -- Get frame position before re-anchoring - local frameRight = frame:GetRight() - local frameBottom = frame:GetBottom() - local parentRight = UIParent:GetRight() - - -- Calculate BOTTOMRIGHT coordinates (setPoint uses BOTTOMRIGHT anchor) - local x = frameRight - parentRight -- negative = left of right edge - local y = frameBottom -- positive = above bottom edge - - -- Re-anchor to BOTTOMRIGHT for consistency - frame:ClearAllPoints() - frame:SetPoint("BOTTOMRIGHT", x, y) - - -- Update frame's internal position tracking - frame.x = x - frame.y = y - - -- Save position to SavedVariables - MultiBotSave = MultiBotSave or {} - MultiBotSave.MultiBarPosition = { x = x, y = y } + -- Save position immediately using existing mechanism + local tX, tY = MultiBot.toPoint(frame) + MultiBotSave["MultiBarPoint"] = tX .. ", " .. tY end) tButton.doLeft = function(pButton) MultiBot.ShowHideSwitch(pButton.parent.frames["Main"])