From 18af4ed07ec8f04cda776431d236bc6f2e90f526 Mon Sep 17 00:00:00 2001 From: shagu Date: Tue, 24 Aug 2021 17:19:33 +0200 Subject: [PATCH] worldmap-coordinates: show coordinates on worldmap --- mods/worldmap-coordinates.lua | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 mods/worldmap-coordinates.lua diff --git a/mods/worldmap-coordinates.lua b/mods/worldmap-coordinates.lua new file mode 100644 index 0000000..70ebe98 --- /dev/null +++ b/mods/worldmap-coordinates.lua @@ -0,0 +1,45 @@ +local _G = _G or getfenv(0) +local GetExpansion = ShaguTweaks.GetExpansion + +local module = ShaguTweaks:register({ + title = "Show World Map Coordinates", + description = "Adds Coordinates to the bottom of the World Map", + enabled = nil, +}) + +module.enable = function(self) + 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 + + -- coordinates + if not WorldMapButton.coords then + WorldMapButton.coords = CreateFrame("Frame", "pfWorldMapButtonCoords", WorldMapButton) + WorldMapButton.coords.text = WorldMapButton.coords:CreateFontString(nil, "OVERLAY") + WorldMapButton.coords.text:SetPoint("BOTTOMLEFT", WorldMapButton, "BOTTOMLEFT", 3, -21) + WorldMapButton.coords.text:SetFontObject(GameFontWhite) + WorldMapButton.coords.text:SetTextColor(1, 1, 1) + WorldMapButton.coords.text:SetJustifyH("RIGHT") + + WorldMapButton.coords:SetScript("OnUpdate", function() + local width = WorldMapButton:GetWidth() + local height = WorldMapButton:GetHeight() + local mx, my = WorldMapButton:GetCenter() + local scale = WorldMapButton:GetEffectiveScale() + local x, y = GetCursorPosition() + + mx = (( x / scale ) - ( mx - width / 2)) / width * 100 + my = (( my + height / 2 ) - ( y / scale )) / height * 100 + + if MouseIsOver(WorldMapButton) then + WorldMapButton.coords.text:SetText(string.format('|cffffcc00Coordinates: |r%.1f / %.1f', mx, my)) + else + WorldMapButton.coords.text:SetText("") + end + end) + end + end) +end