/Tukui/modules/maps/location_panel.lua

http://github.com/Asphyxia/Tukui · Lua · 92 lines · 82 code · 9 blank · 1 comment · 14 complexity · 24f96c1a3a96005000e5e6969eee0566 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. if not C.map.location_panel then return end
  3. local font, fsize, fstyle = C.media.pixelfont, C.datatext.fontsize, "MONOCHROMEOUTLINE"
  4. local locpanel = CreateFrame("Frame", "TukuiLocationPanel", UIParent)
  5. locpanel:CreatePanel("Default", 70, 23, "TOP", UIParent, "TOP", 0, -8)
  6. locpanel:CreateShadow("Default")
  7. locpanel:CreateOverlay(locpanel)
  8. locpanel:SetFrameLevel(4)
  9. locpanel:EnableMouse(true)
  10. local xcoords = CreateFrame("Frame", "TukuiXCoordsPanel", locpanel)
  11. xcoords:CreatePanel("Default", 35, 19, "RIGHT", locpanel, "LEFT", 1, 0)
  12. xcoords:CreateShadow("Default")
  13. xcoords:CreateOverlay(xcoords)
  14. xcoords:SetFrameLevel(2)
  15. local ycoords = CreateFrame("Frame", "TukuiYCoordsPanel", locpanel)
  16. ycoords:CreatePanel("Default", 35, 19, "LEFT", locpanel, "RIGHT", -1, 0)
  17. ycoords:CreateShadow("Default")
  18. ycoords:CreateOverlay(ycoords)
  19. ycoords:SetFrameLevel(2)
  20. -- Set font
  21. local locFS = locpanel:CreateFontString(nil, "OVERLAY")
  22. locFS:SetFont(font, fsize, fstyle)
  23. local xFS = xcoords:CreateFontString(nil, "OVERLAY")
  24. xFS:SetFont(font, fsize, fstyle)
  25. local yFS = ycoords:CreateFontString(nil, "OVERLAY")
  26. yFS:SetFont(font, fsize, fstyle)
  27. local function SetLocColor(frame, pvpT)
  28. if (pvpT == "arena" or pvpT == "combat") then
  29. frame:SetTextColor(1, 0, 0)
  30. elseif pvpT == "friendly" then
  31. frame:SetTextColor(0, 1, 0)
  32. elseif pvpT == "contested" then
  33. frame:SetTextColor(1, 1, 0)
  34. elseif pvpT == "hostile" then
  35. frame:SetTextColor(1, 0, 0)
  36. elseif pvpT == "sanctuary" then
  37. frame:SetTextColor(0, .9, .9)
  38. else
  39. frame:SetTextColor(0, 1, 0)
  40. end
  41. end
  42. local function OnEvent()
  43. location = GetMinimapZoneText()
  44. pvpType = GetZonePVPInfo();
  45. locFS:SetText(location)
  46. locpanel:SetWidth(locFS:GetStringWidth() + 40)
  47. SetLocColor(locFS, pvpType)
  48. locFS:SetPoint("CENTER", locpanel, "CENTER", 1, 1)
  49. locFS:SetJustifyH("CENTER")
  50. end
  51. local function xUpdate()
  52. posX, posY = GetPlayerMapPosition("player");
  53. posX = math.floor(100 * posX)
  54. xFS:SetText(T.datacolor..posX)
  55. xFS:SetPoint("CENTER", xcoords, "CENTER", 1, 1)
  56. end
  57. local function yUpdate()
  58. posX, posY = GetPlayerMapPosition("player");
  59. posY = math.floor(100 * posY)
  60. yFS:SetText(T.datacolor..posY)
  61. yFS:SetPoint("CENTER", ycoords, "CENTER", 1, 1)
  62. end
  63. locpanel:SetScript("OnMouseDown", function()
  64. if WorldMapFrame:IsShown() then
  65. WorldMapFrame:Hide()
  66. else
  67. WorldMapFrame:Show()
  68. end
  69. end)
  70. locpanel:SetScript("OnEnter", function()
  71. locFS:SetTextColor(1, 1, 1)
  72. end)
  73. locpanel:SetScript("OnLeave", function()
  74. pvpType = GetZonePVPInfo();
  75. SetLocColor(locFS, pvpType)
  76. end)
  77. locpanel:RegisterEvent("ZONE_CHANGED")
  78. locpanel:RegisterEvent("PLAYER_ENTERING_WORLD")
  79. locpanel:RegisterEvent("ZONE_CHANGED_INDOORS")
  80. locpanel:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  81. locpanel:SetScript("OnEvent", OnEvent)
  82. xcoords:SetScript("OnUpdate", xUpdate)
  83. ycoords:SetScript("OnUpdate", yUpdate)