Quantcast
X,Y Coordinates on Map - WoWInterface
Thread Tools Display Modes
09-04-15, 02:38 AM   #1
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
X,Y Coordinates on Map

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.
Attached Thumbnails
Click image for larger version

Name:	cPSNkUo.jpg
Views:	231
Size:	188.3 KB
ID:	8636  

Last edited by Lesteryoung : 09-04-15 at 02:40 AM.
  Reply With Quote
09-04-15, 05:34 AM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,702
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.
  Reply With Quote
09-04-15, 08:57 PM   #3
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
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.
  Reply With Quote
09-07-15, 01:07 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
09-07-15, 09:47 AM   #5
Vis
A Pyroguard Emberseer
 
Vis's Avatar
Join Date: Mar 2009
Posts: 1,821
An alternative is this one on Curse which is aptly named Coordinates
  Reply With Quote
09-07-15, 10:24 PM   #6
Nikita S. Doroshenko
A Cyclonian
 
Nikita S. Doroshenko's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2015
Posts: 44
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.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » X,Y Coordinates on Map

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off