Quantcast WoWInterface - View Single Post - Coordinates for BfA
View Single Post
06-07-18, 09:14 AM   #12
Cogwerkz
A Deviate Faerie Dragon
 
Cogwerkz's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2017
Posts: 12
Well this is stupid simple and I didn't really test it, but I half way copy pasted the code I'm currently using for my minimap coordinates on the BfA beta.

Didn't want to necro any threads, just thought it might be nice for people to have as a reference or something to play around with while trying to make sense of the beta API changes.

Just remember I drycoded it in 2 minutes. Here there might be bugs! And dragons!

Lua Code:
  1. local coords = CreateFrame("Frame", nil, Minimap)
  2. coords:SetFrameLevel(Minimap:GetFrameLevel() + 5)
  3. coords:SetAllPoints()
  4. coords.elapsed = 0
  5.  
  6. coords.msg = coords:CreateFontString()
  7. coords.msg:SetDrawLayer("OVERLAY")
  8. coords.msg:SetFontObject(GameFontNormal)
  9. coords.msg:SetPoint("BOTTOM", 0, 20)
  10.  
  11. coords.onUpdate = function(self, elapsed)
  12.     self.elapsed = self.elapsed + elapsed
  13.     if self.elapsed < .1 then
  14.         return
  15.     end
  16.  
  17.     local x, y
  18.     local mapID = C_Map.GetBestMapForUnit("player")
  19.     if mapID then
  20.         -- you don't get coordinates in instances
  21.         local mapPosObject = C_Map.GetPlayerMapPosition(mapID, "player")
  22.         if mapPosObject then
  23.             x, y = mapPosObject:GetXY()
  24.         end
  25.     end
  26.  
  27.     -- just to avoid checking for nil entries and stuff
  28.     x = x or 0
  29.     y = y or 0
  30.  
  31.     -- hide it when there aren't any coordinates
  32.     self.msg:SetShown(x + y > 0)
  33.     self.msg:SetFormattedText("%.1f %.1f", x*100, y*100)
  34.  
  35.     self.elapsed = 0
  36. end
  37.  
  38. coords:SetScript("OnEvent", function(self)
  39.     self:SetScript("OnUpdate", self.onUpdate)
  40. end)
  41. coords:RegisterEvent("PLAYER_ENTERING_WORLD")
__________________
AzeriteUI
  Reply With Quote