Files
ShagaTweaks/mods/worldmap-window.lua
T
shagu 6c26bc6190 core: don't rely on sane global environment
some addons like to provide a broken _G variable to
the global environment breaking every other addon that
relies on it if existing. With this commit, make ShaguTweaks
no longer re-use the global _G, even if existing.
2022-11-19 16:59:12 +01:00

73 lines
2.1 KiB
Lua

local _G = ShaguTweaks.GetGlobalEnv()
local HookScript = ShaguTweaks.HookScript
local module = ShaguTweaks:register({
title = "WorldMap Window",
description = "Turns the world map into a movable window. The map can be scaled with <Ctrl> + Mousewheel.",
expansions = { ["vanilla"] = true, ["tbc"] = true },
category = "World & MiniMap",
enabled = true,
})
module.enable = function(self)
table.insert(UISpecialFrames, "WorldMapFrame")
function _G.ToggleWorldMap()
if WorldMapFrame:IsShown() then
WorldMapFrame:Hide()
else
WorldMapFrame:Show()
end
end
local delay = CreateFrame("Frame")
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
UIPanelWindows["WorldMapFrame"] = { area = "center" }
-- make sure the hooks get only applied once
if not this.hooked then
this.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)
end
end)
HookScript(WorldMapFrame, "OnMouseDown",function()
WorldMapFrame:StartMoving()
end)
HookScript(WorldMapFrame, "OnMouseUp",function()
WorldMapFrame:StopMovingOrSizing()
end)
end
WorldMapFrame:SetMovable(true)
WorldMapFrame:EnableMouse(true)
WorldMapFrame:SetScale(.85)
WorldMapFrame:ClearAllPoints()
WorldMapFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 30)
WorldMapFrame:SetWidth(WorldMapButton:GetWidth() + 15)
WorldMapFrame:SetHeight(WorldMapButton:GetHeight() + 55)
BlackoutWorld:Hide()
end)
end