WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   X,Y Coordinates on Map (https://www.wowinterface.com/forums/showthread.php?t=52695)

Lesteryoung 09-04-15 02:38 AM

X,Y Coordinates on Map
 
1 Attachment(s)
Could someone make a simple coordinates lua that displays x,y for cursor and the player on the map?

Preferably to hook onto the part I circled in the picture, written as "Player: X,Y Cursor: X,Y" or something to that effect. No decimals necessary.

I know there are a bunch of coordinates addons but all of them that I've found have extra features that I don't want.

There's one on this site that does similar to what I want but it doesn't display when the map isn't full screen.

The addon that does similiar to what I want is called riffCoords, but it's at the bottom of the map, and only displays when you're full screen.

p3lim 09-04-15 05:34 AM

Lua Code:
  1. local CoordText = WorldMapFrameCloseButton:CreateFontString(nil, nil, 'GameFontNormal')
  2. CoordText:SetPoint('RIGHT', WorldMapFrameCloseButton, 'LEFT', -30, 0)
  3.  
  4. local totalElapsed = 0
  5. WorldMapDetailFrame:HookScript('OnUpdate', function(self, elapsed)
  6.     if(totalElapsed > 0.1) then
  7.         if(WorldMapScrollFrame:IsMouseOver()) then
  8.             local scale = self:GetEffectiveScale()
  9.             local centerX, centerY = self:GetCenter()
  10.             local width, height = self:GetSize()
  11.             local x, y = GetCursorPosition()
  12.  
  13.             x = ((x / scale) - (centerX - (width / 2))) / width
  14.             y = (centerY + (height / 2) - (y / scale)) / height
  15.  
  16.             CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
  17.             CoordText:SetTextColor(0, 1, 0)
  18.         else
  19.             local x, y = GetPlayerMapPosition('player')
  20.             CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
  21.             CoordText:SetTextColor(1, 1, 0)
  22.         end
  23.  
  24.         totalElapsed = 0
  25.     else
  26.         totalElapsed = totalElapsed + elapsed
  27.     end
  28. end)

What I use, this adds player (or mouse when hovering the map) position to the left of the close button.

Lesteryoung 09-04-15 08:57 PM

Hey, thanks man! This is almost exactly what I'm looking for! The adjustment I would want to make is to just move the frame to the center where I circled in the picture and get rid of the "Map and Quest" text. Other than that it's perfect. I like how it shows player position when not hovering instead of making two coordinates for each, that's actually clever.

Phanx 09-07-15 01:07 AM

Just have it reuse the existing title fontstring instead of creating a new one. Replace the first two lines with this one:

Code:

local CoordText = WorldMapFrame.BorderFrame.TitleText

Vis 09-07-15 09:47 AM

An alternative is this one on Curse which is aptly named Coordinates

Nikita S. Doroshenko 09-07-15 10:24 PM

I'm new in programming, so I might be wrong and my code can be too massy, but i tried to replace OnUpdate with C_Timer.After(0.2seconds,function). And on my PC i got 30% less CPU usage of this feature with 30 FPS capped (i used ChocolateBar+libQtip+BrokerCPU to track performance). i think for players with 60+ FPS the difference in performance will be more significant.

Lua Code:
  1. local CoordText = WorldMapFrame.BorderFrame.TitleText
  2. local update, frame
  3.  
  4. local function WorldMapDetailFrameUpdate_OnHide()
  5.     update = false
  6. end
  7. local function WorldMapDetailFrameUpdate_OnShow()
  8.     update = true
  9. end
  10.  
  11. function WorldMapDetailFrameUpdate(self)
  12.     if not frame then
  13.         frame = self
  14.     end
  15.     if(WorldMapScrollFrame:IsMouseOver()) then
  16.         local scale = frame:GetEffectiveScale()
  17.         local centerX, centerY = frame:GetCenter()
  18.         local width, height = frame:GetSize()
  19.         local x, y = GetCursorPosition()
  20.  
  21.         x = ((x / scale) - (centerX - (width / 2))) / width
  22.         y = (centerY + (height / 2) - (y / scale)) / height
  23.  
  24.         CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
  25.         CoordText:SetTextColor(0, 1, 0)
  26.     else
  27.         local x, y = GetPlayerMapPosition('player')
  28.         CoordText:SetFormattedText('%.2f, %.2f', x * 100, y * 100)
  29.         CoordText:SetTextColor(1, 1, 0)
  30.     end
  31.     if update then
  32.         C_Timer.After(0.2, WorldMapDetailFrameUpdate );
  33.     end
  34. end
  35.  
  36. WorldMapFrame:HookScript('OnShow', WorldMapDetailFrameUpdate_OnShow)
  37. WorldMapFrame:HookScript('OnHide', WorldMapDetailFrameUpdate_OnHide)
  38. WorldMapFrame:HookScript('OnShow', WorldMapDetailFrameUpdate)

If you can make my code even run faster and looks better, and point on my mistakes, i will very appreciate it.


All times are GMT -6. The time now is 04:53 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI