I use AceTimer-3.0 for updating my coords frame:
Lua Code:
local CORE, LIBS = LybrialUI:GetCore();
local LOCALE = LIBS.LOCALE;
local Texts = LybrialMiniMap:NewModule("Texts", "AceTimer-3.0");
Texts.displayName = LOCALE["TEXTS"];
Texts.desc = LOCALE["TEXTS_DESC"];
Texts.zone = nil;
Texts.coords = nil;
Texts.date = nil;
Texts.clock = nil;
local _G = _G;
local C_Map = C_Map;
local CreateFrame = CreateFrame;
local CreateVector2D = CreateVector2D;
local GetMinimapZoneText = GetMinimapZoneText;
local Minimap = Minimap;
local UnitPosition = UnitPosition;
local strsub = strsub;
local unpack = unpack;
function Texts:OnEnableCoords()
if (not self.coords) then
self.coords = CreateFrame("Frame", "LybrialUITextsCoords", Minimap);
self.coords.text = self.coords:CreateFontString(nil, "OVERLAY");
self.coords.MapRects = {};
self.coords:SetScript("OnEvent", function(self)
self.mapId = C_Map.GetBestMapForUnit("player");
end);
self.coords:RegisterEvent("PLAYER_ENTERING_WORLD");
self.coords:RegisterEvent("ZONE_CHANGED");
self.coords:RegisterEvent("ZONE_CHANGED_INDOORS");
self.coords:RegisterEvent("ZONE_CHANGED_NEW_AREA");
self:ScheduleRepeatingTimer(self.UpdatePlayerMapPosition, 1);
end
end
function Texts:OnUpdateCoords()
local show = self.db.profile.texts.coords.show;
local anchor = self.db.profile.texts.coords.position.anchor;
local offsetX = self.db.profile.texts.coords.position.offset.x;
local offsetY = self.db.profile.texts.coords.position.offset.y;
local font = self.db.profile.texts.coords.font.font;
local fontSize = self.db.profile.texts.coords.font.size;
local fontOutline = self.db.profile.texts.coords.font.outline;
local fontColor = self.db.profile.texts.coords.font.color;
self.coords:SetSize(120, 30);
self.coords:ClearAllPoints();
self.coords:SetPoint(anchor, Minimap, anchor, offsetX, offsetY);
self.coords.text:ClearAllPoints();
self.coords.text:SetPoint("CENTER");
self.coords.text:SetFont(LIBS.LSM:Fetch("font", font), fontSize, fontOutline);
self.coords.text:SetTextColor(unpack(fontColor));
if (show) then
self.coords:Show();
else
self.coords:Hide();
end
end
function Texts:UpdatePlayerMapPosition()
local coords = Texts.coords;
if (not coords:IsShown()) then
return ;
end
if (not coords.mapId) then
return ;
end
local rects = coords.MapRects[coords.mapId];
if (not rects) then
rects = {};
local _, topLeft = C_Map.GetWorldPosFromMapPos(coords.mapId, CreateVector2D(0, 0));
local _, bottomRight = C_Map.GetWorldPosFromMapPos(coords.mapId, CreateVector2D(1, 1));
bottomRight:Subtract(topLeft);
rects = { topLeft.x, topLeft.y, bottomRight.x, bottomRight.y };
coords.MapRects[coords.mapId] = rects;
end
local x, y = UnitPosition("player");
if (x) then
x = x - rects[1];
y = y - rects[2];
x = x / rects[3];
y = y / rects[4];
y = y * 100;
x = x * 100;
coords.text:SetFormattedText("%.1f, %.1f", y, x);
end
end