Files
Xurkon 8ee8c2516c 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.
2026-06-01 18:35:39 -05:00

85 lines
2.8 KiB
Lua

---@class WorldMapButton
---@field Initialize function
local WorldMapButton = QuestieLoader:CreateModule("WorldMapButton")
---@type l10n
local l10n = QuestieLoader:ImportModule("l10n")
---@type QuestieLib
local QuestieLib = QuestieLoader:ImportModule("QuestieLib")
---@type QuestieQuest
local QuestieQuest = QuestieLoader:ImportModule("QuestieQuest")
---@type QuestieMenu
local QuestieMenu = QuestieLoader:ImportModule("QuestieMenu")
local KButtons = QuestieCompat.KButtons or LibStub("Krowi_WorldMapButtons-1.4")
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()
mapButton = KButtons:Add("QuestieWorldMapButtonTemplate", "BUTTON")
_RefreshMapButtonVisibility()
WorldMapFrame:HookScript("OnShow", _RefreshMapButtonVisibility)
WorldMapFrame:HookScript("OnHide", _RefreshMapButtonVisibility)
Questie.WorldMap = {
Button = mapButton
}
end
---@param shouldShow boolean
function WorldMapButton.Toggle(shouldShow)
Questie.db.profile.mapShowHideEnabled = shouldShow
_RefreshMapButtonVisibility()
end
QuestieWorldMapButtonMixin = {
OnLoad = function() end,
OnHide = function() end,
OnMouseDown = function(_, button)
if button == "LeftButton" then
Questie.db.profile.enabled = (not Questie.db.profile.enabled)
QuestieQuest:ToggleNotes(Questie.db.profile.enabled)
elseif button == "RightButton" then
QuestieMenu:Show()
end
end,
OnMouseUp = function() end,
OnEnter = function(self)
local GameTooltip = QuestieCompat.SetupTooltip(self)
GameTooltip:SetOwner(self, "ANCHOR_NONE");
GameTooltip:SetPoint("TOPRIGHT", self, "BOTTOMRIGHT", 0, 0);
GameTooltip:AddLine("Questie ".. QuestieLib:GetAddonVersionString(), 1, 1, 1)
GameTooltip:AddLine(Questie:Colorize(l10n('Left Click') , 'gray') .. ": ".. l10n('Toggle Questie'))
GameTooltip:AddLine(Questie:Colorize(l10n('Right Click') , 'gray') .. ": ".. l10n('Toggle Menu'))
GameTooltip:Show()
end,
OnLeave = function() end,
OnClick = function() end, -- Only fires on left click
Refresh = function() end,
}