PageRenderTime 184ms CodeModel.GetById 101ms app.highlight 9ms RepoModel.GetById 71ms app.codeStats 0ms

/Tukui/modules/datatext/battleground.lua

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