/Tukui/modules/datatext/battleground.lua

http://github.com/Asphyxia/Tukui · Lua · 123 lines · 111 code · 10 blank · 2 comment · 32 complexity · a39940e26941201eb319b08f1556a58b MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. local twinpeaks = select(1, GetBattlegroundInfo(2))
  3. local gilneas = select(1, GetBattlegroundInfo(3))
  4. local warsong = select(1, GetBattlegroundInfo(4))
  5. local arathi = select(1, GetBattlegroundInfo(5))
  6. local eos = select(1, GetBattlegroundInfo(6))
  7. local alterac = select(1, GetBattlegroundInfo(7))
  8. local sota = select(1, GetBattlegroundInfo(8))
  9. local conquest = select(1, GetBattlegroundInfo(9))
  10. if not C["datatext"].battleground then return end
  11. local bgframe = TukuiInfoLeftBattleGround
  12. bgframe:SetScript("OnEnter", function(self)
  13. local numScores = GetNumBattlefieldScores()
  14. for i=1, numScores do
  15. local name, killingBlows, honorableKills, deaths, honorGained, faction, race, class, classToken, damageDone, healingDone, bgRating, ratingChange = GetBattlefieldScore(i)
  16. if ( name ) then
  17. if ( name == UnitName("player") ) then
  18. GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT", 0, T.Scale(4))
  19. GameTooltip:ClearLines()
  20. GameTooltip:Point("BOTTOM", self, "TOP", 0, 1)
  21. GameTooltip:ClearLines()
  22. GameTooltip:AddLine(L.datatext_ttstatsfor.."[|cffCC0033"..name.."|r]")
  23. GameTooltip:AddLine' '
  24. GameTooltip:AddDoubleLine(L.datatext_ttkillingblows, killingBlows,1,1,1)
  25. GameTooltip:AddDoubleLine(L.datatext_tthonorkills, honorableKills,1,1,1)
  26. GameTooltip:AddDoubleLine(L.datatext_ttdeaths, deaths,1,1,1)
  27. GameTooltip:AddDoubleLine(L.datatext_tthonorgain, format('%d', honorGained),1,1,1)
  28. GameTooltip:AddDoubleLine(L.datatext_ttdmgdone, damageDone,1,1,1)
  29. GameTooltip:AddDoubleLine(L.datatext_tthealdone, healingDone,1,1,1)
  30. --Add extra statistics to watch based on what BG you are in.
  31. if GetRealZoneText() == arathi or GetRealZoneText() == gilneas then
  32. GameTooltip:AddDoubleLine(L.datatext_basesassaulted,GetBattlefieldStatData(i, 1),1,1,1)
  33. GameTooltip:AddDoubleLine(L.datatext_basesdefended,GetBattlefieldStatData(i, 2),1,1,1)
  34. elseif GetRealZoneText() == warsong or GetRealZoneText() == twinpeaks then
  35. GameTooltip:AddDoubleLine(L.datatext_flagscaptured,GetBattlefieldStatData(i, 1),1,1,1)
  36. GameTooltip:AddDoubleLine(L.datatext_flagsreturned,GetBattlefieldStatData(i, 2),1,1,1)
  37. elseif GetRealZoneText() == eos then
  38. GameTooltip:AddDoubleLine(L.datatext_flagscaptured,GetBattlefieldStatData(i, 1),1,1,1)
  39. elseif GetRealZoneText() == alterac then
  40. GameTooltip:AddDoubleLine(L.datatext_graveyardsassaulted,GetBattlefieldStatData(i, 1),1,1,1)
  41. GameTooltip:AddDoubleLine(L.datatext_graveyardsdefended,GetBattlefieldStatData(i, 2),1,1,1)
  42. GameTooltip:AddDoubleLine(L.datatext_towersassaulted,GetBattlefieldStatData(i, 3),1,1,1)
  43. GameTooltip:AddDoubleLine(L.datatext_towersdefended,GetBattlefieldStatData(i, 4),1,1,1)
  44. elseif GetRealZoneText() == sota then
  45. GameTooltip:AddDoubleLine(L.datatext_demolishersdestroyed,GetBattlefieldStatData(i, 1),1,1,1)
  46. GameTooltip:AddDoubleLine(L.datatext_gatesdestroyed,GetBattlefieldStatData(i, 2),1,1,1)
  47. elseif GetRealZoneText() == conquest then
  48. GameTooltip:AddDoubleLine(L.datatext_basesassaulted,GetBattlefieldStatData(i, 1),1,1,1)
  49. GameTooltip:AddDoubleLine(L.datatext_basesdefended,GetBattlefieldStatData(i, 2),1,1,1)
  50. end
  51. GameTooltip:Show()
  52. end
  53. end
  54. end
  55. end)
  56. bgframe:SetScript("OnLeave", function(self) GameTooltip:Hide() end)
  57. local Stat = CreateFrame("Frame")
  58. Stat:EnableMouse(true)
  59. local Text1 = TukuiInfoLeftBattleGround:CreateFontString(nil, "OVERLAY")
  60. Text1:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  61. Text1:SetPoint("LEFT", TukuiInfoLeftBattleGround, 30, 0.5)
  62. Text1:SetHeight(TukuiInfoLeft:GetHeight())
  63. local Text2 = TukuiInfoLeftBattleGround:CreateFontString(nil, "OVERLAY")
  64. Text2:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  65. Text2:SetPoint("CENTER", TukuiInfoLeftBattleGround, 0, 0.5)
  66. Text2:SetHeight(TukuiInfoLeft:GetHeight())
  67. local Text3 = TukuiInfoLeftBattleGround:CreateFontString(nil, "OVERLAY")
  68. Text3:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  69. Text3:SetPoint("RIGHT", TukuiInfoLeftBattleGround, -30, 0.5)
  70. Text3:SetHeight(TukuiInfoLeft:GetHeight())
  71. local int = 2
  72. local function Update(self, t)
  73. int = int - t
  74. if int < 0 then
  75. local dmgtxt
  76. RequestBattlefieldScoreData()
  77. local numScores = GetNumBattlefieldScores()
  78. for i=1, numScores do
  79. local name, killingBlows, honorableKills, deaths, honorGained, faction, race, class, classToken, damageDone, healingDone, bgRating, ratingChange = GetBattlefieldScore(i)
  80. if healingDone > damageDone then
  81. dmgtxt = (L.datatext_healing..T.datacolor..healingDone)
  82. else
  83. dmgtxt = (L.datatext_damage..T.datacolor..damageDone)
  84. end
  85. if ( name ) then
  86. if ( name == T.myname ) then
  87. Text2:SetText(L.datatext_honor..T.datacolor..format('%d', honorGained)..T.datacolor)
  88. Text1:SetText(dmgtxt)
  89. Text3:SetText(L.datatext_killingblows..T.datacolor..killingBlows..T.datacolor)
  90. end
  91. end
  92. end
  93. int = 2
  94. end
  95. end
  96. --hide text when not in an bg
  97. local function OnEvent(self, event)
  98. if event == "PLAYER_ENTERING_WORLD" then
  99. local inInstance, instanceType = IsInInstance()
  100. if inInstance and (instanceType == "pvp") then
  101. bgframe:Show()
  102. else
  103. Text1:SetText("")
  104. Text2:SetText("")
  105. Text3:SetText("")
  106. bgframe:Hide()
  107. end
  108. end
  109. end
  110. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  111. Stat:SetScript("OnEvent", OnEvent)
  112. Stat:SetScript("OnUpdate", Update)
  113. Update(Stat, 2)