fix(worldmap): persist button toggle; hook OnShow/OnHide; Mapster offset
- Refactor button positioning and visibility into _PositionMapButton and
_RefreshMapButtonVisibility helpers. Single source of truth for both.
- WorldMapButton.Initialize now hooks OnShow/OnHide on WorldMapFrame so
the button self-updates when the user opens/closes the world map.
No more manual show/hide calls required from elsewhere in the code.
- Toggle(shouldShow) now persists to Questie.db.profile.mapShowHideEnabled
and calls _RefreshMapButtonVisibility, so the user's choice survives
/reload and is consistent with the world map's current visibility.
- Special-case Mapster offset: -50, -72.3 vs default -50, -40. Without
this, the button overlapped Mapster's UI elements when both addons
were loaded.
- Frame level set to 99 to ensure the button draws above other map
elements.
All helpers are no-op-safe when mapButton is nil. IsAddOnLoaded
('Mapster') is optional — falls through to default offset if Mapster
is not loaded.
This commit is contained in:
@@ -15,8 +15,36 @@ local KButtons = QuestieCompat.KButtons or LibStub("Krowi_WorldMapButtons-1.4")
|
|||||||
|
|
||||||
local mapButton
|
local mapButton
|
||||||
|
|
||||||
|
local function _PositionMapButton()
|
||||||
|
if not mapButton then return end
|
||||||
|
|
||||||
|
local anchor = WorldMapDetailFrame or WorldMapButton or WorldMapFrame
|
||||||
|
mapButton:SetParent(anchor)
|
||||||
|
mapButton:ClearAllPoints()
|
||||||
|
if IsAddOnLoaded and IsAddOnLoaded("Mapster") then
|
||||||
|
mapButton:SetPoint("TOPRIGHT", anchor, "TOPRIGHT", -50, -72.3)
|
||||||
|
else
|
||||||
|
mapButton:SetPoint("TOPRIGHT", anchor, "TOPRIGHT", -50, -40)
|
||||||
|
end
|
||||||
|
mapButton:SetFrameLevel(99)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function _RefreshMapButtonVisibility()
|
||||||
|
if not mapButton then return end
|
||||||
|
|
||||||
|
_PositionMapButton()
|
||||||
|
if Questie.db.profile.mapShowHideEnabled and WorldMapFrame:IsVisible() then
|
||||||
|
mapButton:Show()
|
||||||
|
else
|
||||||
|
mapButton:Hide()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function WorldMapButton.Initialize()
|
function WorldMapButton.Initialize()
|
||||||
mapButton = KButtons:Add("QuestieWorldMapButtonTemplate", "BUTTON")
|
mapButton = KButtons:Add("QuestieWorldMapButtonTemplate", "BUTTON")
|
||||||
|
_RefreshMapButtonVisibility()
|
||||||
|
WorldMapFrame:HookScript("OnShow", _RefreshMapButtonVisibility)
|
||||||
|
WorldMapFrame:HookScript("OnHide", _RefreshMapButtonVisibility)
|
||||||
|
|
||||||
Questie.WorldMap = {
|
Questie.WorldMap = {
|
||||||
Button = mapButton
|
Button = mapButton
|
||||||
@@ -25,11 +53,8 @@ end
|
|||||||
|
|
||||||
---@param shouldShow boolean
|
---@param shouldShow boolean
|
||||||
function WorldMapButton.Toggle(shouldShow)
|
function WorldMapButton.Toggle(shouldShow)
|
||||||
if shouldShow then
|
Questie.db.profile.mapShowHideEnabled = shouldShow
|
||||||
mapButton:Show()
|
_RefreshMapButtonVisibility()
|
||||||
else
|
|
||||||
mapButton:Hide()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
QuestieWorldMapButtonMixin = {
|
QuestieWorldMapButtonMixin = {
|
||||||
|
|||||||
Reference in New Issue
Block a user