Harden world map window initialization

This commit is contained in:
Dusk-92
2026-08-26 15:28:41 +02:00
parent f75201172f
commit 5aed263978
+46 -23
View File
@@ -1,5 +1,6 @@
local _G = ShaguTweaks.GetGlobalEnv()
local T = ShaguTweaks.T
local API = ShaguTweaks.API
local HookScript = ShaguTweaks.HookScript
local module = ShaguTweaks:register({
@@ -10,52 +11,69 @@ local module = ShaguTweaks:register({
enabled = true,
})
module.enable = function(self)
table.insert(UISpecialFrames, "WorldMapFrame")
local function AddSpecialFrame(name)
for i = 1, table.getn(UISpecialFrames) do
if UISpecialFrames[i] == name then return end
end
table.insert(UISpecialFrames, name)
end
function _G.ToggleWorldMap()
if WorldMapFrame:IsShown() then
WorldMapFrame:Hide()
else
WorldMapFrame:Show()
module.enable = function(self)
AddSpecialFrame("WorldMapFrame")
-- Window mode requires a direct Show/Hide toggle instead of the stock
-- full-screen panel toggle. Install it once when this module is enabled.
if not self.toggleInstalled then
self.toggleInstalled = true
function _G.ToggleWorldMap()
if WorldMapFrame:IsShown() then
WorldMapFrame:Hide()
else
WorldMapFrame:Show()
end
end
end
local delay = CreateFrame("Frame")
-- Reuse one initialization frame so repeated enable() calls cannot stack
-- PLAYER_ENTERING_WORLD handlers or duplicate WorldMapFrame hooks.
if not self.delay then
self.delay = CreateFrame("Frame")
end
local delay = self.delay
delay:RegisterEvent("PLAYER_ENTERING_WORLD")
delay:SetScript("OnEvent", function()
-- do not load if other map addon is loaded
if Cartographer then return end
if METAMAP_TITLE then return end
-- Do not interfere with dedicated map addons.
if Cartographer or METAMAP_TITLE then
this:UnregisterAllEvents()
this:Hide()
return
end
UIPanelWindows["WorldMapFrame"] = { area = "center" }
-- make sure the hooks get only applied once
if not this.hooked then
this.hooked = true
if not self.hooked then
self.hooked = true
HookScript(WorldMapFrame, "OnShow", function()
-- customize
this:EnableKeyboard(false)
this:EnableMouseWheel(1)
-- set back to default scale
WorldMapFrame:SetScale(.85)
end)
HookScript(WorldMapFrame, "OnMouseWheel", function()
if IsShiftKeyDown() then
WorldMapFrame:SetAlpha(WorldMapFrame:GetAlpha() + arg1/10)
elseif IsControlKeyDown() then
WorldMapFrame:SetScale(WorldMapFrame:GetScale() + arg1/10)
if API.IsShiftKeyDown() then
WorldMapFrame:SetAlpha(WorldMapFrame:GetAlpha() + arg1 / 10)
elseif API.IsControlKeyDown() then
WorldMapFrame:SetScale(WorldMapFrame:GetScale() + arg1 / 10)
end
end)
HookScript(WorldMapFrame, "OnMouseDown",function()
HookScript(WorldMapFrame, "OnMouseDown", function()
WorldMapFrame:StartMoving()
end)
HookScript(WorldMapFrame, "OnMouseUp",function()
HookScript(WorldMapFrame, "OnMouseUp", function()
WorldMapFrame:StopMovingOrSizing()
end)
end
@@ -69,5 +87,10 @@ module.enable = function(self)
WorldMapFrame:SetWidth(WorldMapButton:GetWidth() + 15)
WorldMapFrame:SetHeight(WorldMapButton:GetHeight() + 55)
BlackoutWorld:Hide()
-- Initialization is complete. Keeping this event registered would repeat
-- the full layout work on every loading screen and reset a moved window.
this:UnregisterAllEvents()
this:Hide()
end)
end