Skip to content

Commit

Permalink
Add minimap coords
Browse files Browse the repository at this point in the history
  • Loading branch information
ls- committed May 7, 2023
1 parent 65cdffa commit 0c41b4a
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ls_UI/core/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions ls_UI/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions ls_UI/locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
3 changes: 3 additions & 0 deletions ls_UI/locales/ruRU.lua
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,6 @@ L["Y_OFFSET"] = "Смещение по Y"
L["YOUR_HEALING"] = "Ваше исцеление"
L["YOURS_FIRST"] = "Ваши в первую очередь"
L["ZONE_ABILITY_BUTTON"] = "Кнопка доп. способности в зоне"


L["COORDS"] = "Координаты"
58 changes: 57 additions & 1 deletion ls_UI/modules/minimap/minimap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -490,6 +545,7 @@ function MODULE:Update()
Minimap:UpdateLayout()
Minimap:UpdateBorderColor()
Minimap:UpdateDifficultyFlag()
Minimap:UpdateCoords()
MinimapCluster:UpdateFading()
end
end
Expand Down
11 changes: 11 additions & 0 deletions ls_UI_Options/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
84 changes: 84 additions & 0 deletions ls_UI_Options/minimap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 0c41b4a

Please sign in to comment.