From 0c41b4ad0ba9447838850086de478821b9b422ab Mon Sep 17 00:00:00 2001 From: Val Voronov Date: Sun, 7 May 2023 21:55:51 +0700 Subject: [PATCH] Add minimap coords --- ls_UI/core/defaults.lua | 6 +++ ls_UI/core/utils.lua | 34 +++++++++++++ ls_UI/locales/enUS.lua | 3 ++ ls_UI/locales/ruRU.lua | 3 ++ ls_UI/modules/minimap/minimap.lua | 58 ++++++++++++++++++++- ls_UI_Options/core.lua | 11 ++++ ls_UI_Options/minimap.lua | 84 +++++++++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 1 deletion(-) diff --git a/ls_UI/core/defaults.lua b/ls_UI/core/defaults.lua index 15f99104..e5b476e0 100644 --- a/ls_UI/core/defaults.lua +++ b/ls_UI/core/defaults.lua @@ -18,6 +18,7 @@ D.global = { blue = rgb(38, 125, 206), -- #267DCE (5PB 5/12) yellow = rgb(246, 196, 66), -- #F6C442 (2.5Y 8/10) gray = rgb(136, 137, 135), -- #888987 (N5) + light_gray = rgb(202, 202, 202), -- #CACACA (N8) dark_gray = rgb(59, 58, 58), -- #3B3A3A (N2) black = rgb(0, 0, 0), -- #000000 white = rgb(255, 255, 255), -- #FFFFFF @@ -1864,6 +1865,11 @@ D.profile = { color = { border = false, }, + coords = { + enabled = false, + background = true, + point = {"TOP", "Minimap", "BOTTOM", 0, -8}, + }, flag = { enabled = true, tooltip = false, diff --git a/ls_UI/core/utils.lua b/ls_UI/core/utils.lua index 738dc071..cdb21bb6 100644 --- a/ls_UI/core/utils.lua +++ b/ls_UI/core/utils.lua @@ -947,3 +947,37 @@ do E.FontStrings = module end + +---------- +-- MAPS -- +---------- + +-- credit: elcius@WoWInterface +do + local mapRects = {} + local tempVec2D = CreateVector2D(0, 0) + + function E:GetPlayerMapPosition() + tempVec2D.x, tempVec2D.y = UnitPosition("player") + if not tempVec2D.x then return end + + local mapID = C_Map.GetBestMapForUnit("player") + if not mapID then return end + + local mapRect = mapRects[mapID] + if not mapRect then + local _, pos1 = C_Map.GetWorldPosFromMapPos(mapID, CreateVector2D(0, 0)) + local _, pos2 = C_Map.GetWorldPosFromMapPos(mapID, CreateVector2D(1, 1)) + if not (pos1 and pos2) then return end + + mapRect = {pos1, pos2} + mapRect[2]:Subtract(mapRect[1]) + + mapRects[mapID] = mapRect + end + + tempVec2D:Subtract(mapRect[1]) + + return tempVec2D.y / mapRect[2].y * 100, tempVec2D.x / mapRect[2].x * 100 + end +end diff --git a/ls_UI/locales/enUS.lua b/ls_UI/locales/enUS.lua index bf380023..46029f68 100644 --- a/ls_UI/locales/enUS.lua +++ b/ls_UI/locales/enUS.lua @@ -17,6 +17,7 @@ L["ACCEPT"] = _G.ACCEPT L["ADD"] = _G.ADD L["ALT"] = _G.ALT_KEY_TEXT L["ARCANE_CHARGES"] = _G.POWER_TYPE_ARCANE_CHARGES +L["BACKGROUND"] = _G.BACKGROUND L["BACKPACK"] = _G.BACKPACK_TOOLTIP L["CALL_TO_ARMS_TOOLTIP"] = _G.LFG_CALL_TO_ARMS L["CANCEL"] = _G.CANCEL @@ -501,3 +502,5 @@ L["Y_OFFSET"] = "yOffset" L["YOUR_HEALING"] = "Your Healing" L["YOURS_FIRST"] = "Yours First" L["ZONE_ABILITY_BUTTON"] = "Zone Ability Button" + +L["COORDS"] = "Coordinates" diff --git a/ls_UI/locales/ruRU.lua b/ls_UI/locales/ruRU.lua index 474482c1..16fa773a 100644 --- a/ls_UI/locales/ruRU.lua +++ b/ls_UI/locales/ruRU.lua @@ -413,3 +413,6 @@ L["Y_OFFSET"] = "Смещение по Y" L["YOUR_HEALING"] = "Ваше исцеление" L["YOURS_FIRST"] = "Ваши в первую очередь" L["ZONE_ABILITY_BUTTON"] = "Кнопка доп. способности в зоне" + + +L["COORDS"] = "Координаты" diff --git a/ls_UI/modules/minimap/minimap.lua b/ls_UI/modules/minimap/minimap.lua index c7b519ce..bef51988 100644 --- a/ls_UI/modules/minimap/minimap.lua +++ b/ls_UI/modules/minimap/minimap.lua @@ -30,7 +30,7 @@ do if self._config.color.border then self.Border:SetVertexColor((C.db.global.colors.zone[zoneTypeToColor[GetZonePVPInfo() or "contested"]]):GetRGB()) else - self.Border:SetVertexColor(1, 1, 1) + self.Border:SetVertexColor(C.db.global.colors.light_gray:GetRGB()) end end @@ -166,6 +166,25 @@ do end end + + function minimap_proto:UpdateCoords() + if self._config.coords.enabled then + self.Coords:ClearAllPoints() + self.Coords:SetPoint(unpack(self._config.coords.point)) + self.Coords:Show() + + if self._config.coords.background then + self.Coords:SetBackdropColor(0, 0, 0, 0.6) + self.Coords:SetBackdropBorderColor(0, 0, 0, 0.6) + else + self.Coords:SetBackdropColor(0, 0, 0, 0) + self.Coords:SetBackdropBorderColor(0, 0, 0, 0) + end + else + self.Coords:Hide() + end + end + function cluster_proto:ResetSize(_, _, shouldIgnore) if not shouldIgnore then local scale = self._config.scale @@ -290,6 +309,29 @@ do end end +local coords_proto = {} + +do + local COORDS_FORMAT = "%.1f / %.1f" + local NO_COORDS = "n / a" + + function coords_proto:OnUpdate(elapsed) + self.elapsed = (self.elapsed or 0) - elapsed + if self.elapsed < 0 then + local x, y = E:GetPlayerMapPosition() + if x then + self.Text:SetFormattedText(COORDS_FORMAT, x, y) + + self.elapsed = 0.1 + else + self.Text:SetText(NO_COORDS) + + self.elapsed = 5 + end + end + end +end + function MODULE:IsInit() return isInit end @@ -396,6 +438,19 @@ function MODULE:Init() flagIcon:SetTexture("Interface\\AddOns\\ls_UI\\assets\\minimap-flags") difficultyFlag.Icon = flagIcon + local coords = Mixin(E:CreateBackdrop(textureParent), coords_proto) + coords:SetFrameLevel(Minimap:GetFrameLevel() + 2) + coords:SetScript("OnUpdate", coords.OnUpdate) + Minimap.Coords = coords + + local coordsText = coords:CreateFontString(nil, "ARTWORK", "GameFontNormal") + coordsText:SetPoint("CENTER", 0, 0) + coordsText:SetText("99.9 / 99.9") + coordsText:SetJustifyH("CENTER") + coords.Text = coordsText + + coords:SetSize(coordsText:GetUnboundedStringWidth() + 10, coordsText:GetStringHeight() + 8) + hooksecurefunc(MinimapCluster, "SetHeaderUnderneath", function() Minimap:UpdateConfig() Minimap:UpdateLayout() @@ -490,6 +545,7 @@ function MODULE:Update() Minimap:UpdateLayout() Minimap:UpdateBorderColor() Minimap:UpdateDifficultyFlag() + Minimap:UpdateCoords() MinimapCluster:UpdateFading() end end diff --git a/ls_UI_Options/core.lua b/ls_UI_Options/core.lua index 81c5e5f7..d32435a9 100644 --- a/ls_UI_Options/core.lua +++ b/ls_UI_Options/core.lua @@ -56,6 +56,17 @@ CONFIG.POINTS_EXT = { ["TOPRIGHT"] = "TOPRIGHT", } +CONFIG.POINTS_NO_CENTER = { + ["BOTTOM"] = "BOTTOM", + ["BOTTOMLEFT"] = "BOTTOMLEFT", + ["BOTTOMRIGHT"] = "BOTTOMRIGHT", + ["LEFT"] = "LEFT", + ["RIGHT"] = "RIGHT", + ["TOP"] = "TOP", + ["TOPLEFT"] = "TOPLEFT", + ["TOPRIGHT"] = "TOPRIGHT", +} + CONFIG.GROWTH_DIRS = { ["LEFT_DOWN"] = L["LEFT_DOWN"], ["LEFT_UP"] = L["LEFT_UP"], diff --git a/ls_UI_Options/minimap.lua b/ls_UI_Options/minimap.lua index 57b4695c..0c9c8c40 100644 --- a/ls_UI_Options/minimap.lua +++ b/ls_UI_Options/minimap.lua @@ -3,6 +3,7 @@ local _, CONFIG = ... -- Lua local _G = getfenv(0) local unpack = _G.unpack +local tonumber = _G.tonumber -- Mine local E, M, L, C, D, PrC, PrD, P, oUF = unpack(ls_UI) @@ -209,6 +210,89 @@ function CONFIG:CreateMinimapOptions(order) type = "description", name = " ", }, + coords = { + order = inc(1), + type = "group", + name = L["COORDS"], + inline = true, + get = function(info) + return C.db.profile.minimap.coords[info[#info]] + end, + set = function(info, value) + C.db.profile.minimap.coords[info[#info]] = value + + Minimap:UpdateConfig() + Minimap:UpdateCoords() + end, + disabled = isModuleDisabled, + args = { + enabled = { + order = reset(2), + type = "toggle", + name = L["ENABLE"], + }, + background = { + order = inc(2), + type = "toggle", + name = L["BACKGROUND"], + }, + spacer_1 = { + order = inc(2), + type = "description", + name = " ", + }, + point = { + order = inc(2), + type = "group", + name = "", + inline = true, + get = function(info) + return C.db.profile.minimap.coords.point[tonumber(info[#info])] + end, + set = function(info, value) + if C.db.profile.minimap.coords.point[tonumber(info[#info])] ~= value then + C.db.profile.minimap.coords.point[tonumber(info[#info])] = value + + Minimap:UpdateConfig() + Minimap:UpdateCoords() + end + end, + args = { + ["1"] = { + order = reset(2), + type = "select", + name = L["POINT"], + desc = L["POINT_DESC"], + values = CONFIG.POINTS_NO_CENTER, + }, + ["3"] = { + order = inc(2), + type = "select", + name = L["RELATIVE_POINT"], + desc = L["RELATIVE_POINT_DESC"], + values = CONFIG.POINTS_NO_CENTER, + }, + ["4"] = { + order = inc(2), + type = "range", + name = L["X_OFFSET"], + min = -128, max = 128, step = 1, + }, + ["5"] = { + order = inc(2), + type = "range", + name = L["Y_OFFSET"], + min = -128, max = 128, step = 1, + }, + }, + }, + }, + }, + spacer_8 = { + order = inc(1), + type = "description", + name = " ", + }, fading = { order = inc(1), type = "group",