vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 ----------------------------
2 -- Variables + Constants
3 ----------------------------
4 -- Keeps track of player class and level for the session.
5 local playerList = {};
6  
7 -- Winner?
8 local TITAN_HONORPLUS_BGWINNER = nil;
9  
10 -- Time until accepting battlegrounds invite
11 local TITAN_HONORPLUS_BGCONFIRM = 0;
12  
13 -- Last known bonus from battlegrounds
14 local TITAN_HONORPLUS_CURRENTBONUS = 0;
15  
16 -- Time of last PvP damage
17 local TITAN_HONORPLUS_PVPDMG = 0;
18  
19 -- Interval to send API BG Data requests, in seconds.
20 local TITAN_HONORPLUS_BGAPI_INTERVAL = 5;
21  
22 -- The line last used to set tooltip honor info
23 local TITAN_HONORPLUS_TOOLTIPLINE = nil;
24  
25 -- Next time to check.
26 local TITAN_HONORPLUS_BGAPI_NEXT = 0;
27  
28 -- Gives standard class colour
29 TITAN_HONORPLUS_CLASSCOLORINDEX = {
30 [1] = "|cffff7d0a",
31 [2] = "|cffaad2aa",
32 [3] = "|cff69cdf0",
33 [4] = "|cfff58cb9",
34 [5] = "|cffffffff",
35 [6] = "|cfffff569",
36 [7] = "|cfff58cb9",
37 [8] = "|cffc88296",
38 [9] = "|cffc89b6e",
39 }
40  
41 -- Default saved values.
42 TITAN_HONORPLUS_DEFAULTS = {
43 ['todayd'] = 0,
44 ['todayb'] = 0,
45 ['todaydk'] = 0,
46 ['todayhk'] = 0,
47 ['todaycp'] = 0,
48 ['todaycp2'] = 0,
49 ['yesterday'] = 0,
50 ['lastweek'] = 0,
51 ['weekdk'] = 0,
52 ['log'] = {},
53 };
54  
55 -- Titan ID
56 local TITAN_HONORPLUS_ID = "HonorPlus";
57  
58 -- PvP Icon Directory
59 local TITAN_HONORPLUS_ICON_PATH = "Interface\\PvPRankBadges\\PvPRank";
60  
61 -- Converting honor-gain string format to double-format.
62 local TITAN_HONORPLUS_SEARCH = string.gsub(COMBATLOG_HONORGAIN,'%(','%%(');
63 local TITAN_HONORPLUS_SEARCH = string.gsub(TITAN_HONORPLUS_SEARCH,'%)','%%)');
64 local TITAN_HONORPLUS_SEARCH = string.gsub(TITAN_HONORPLUS_SEARCH,'%%s','(.+)');
65 local TITAN_HONORPLUS_SEARCH = string.gsub(TITAN_HONORPLUS_SEARCH,'%%d','(%%d+)');
66  
67 -- Set when loaded
68 local vLoaded = nil;
69 local vVar = nil;
70  
71 -- Playername|Realmname
72 local vC = nil;
73  
74 ----------------------------
75 -- Function Hooks
76 ----------------------------
77 local old_WorldStateScoreFrame_Update; -- Battlegrounds score sheet. Display update.
78 local old_GameTooltip_OnHide; -- Tooltip is hidden, remove custom honor line.
79 local old_WorldStateScoreFrame_Resize; -- When we add a new column to the scoreboard we need to resize it differently.
80 local old_StaticPopup_OnHide; -- Detects when you click 'hide' on BG invite request.
81  
82 ----------------------------
83 -- On Load
84 ----------------------------
85 function TitanPanelHonorPlusButton_OnLoad()
86  
87 -- Register for TitanPanel
88 TitanPanelHonorPlus_Register();
89  
90 -- ** Events **
91 -- For initialisation
92 this:RegisterEvent("VARIABLES_LOADED");
93 -- For registering deaths by Players.
94 this:RegisterEvent("PLAYER_DEAD"); -- And auto-release
95 this:RegisterEvent("CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS");
96 this:RegisterEvent("CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE");
97 -- For getting honor bonus data
98 this:RegisterEvent("UPDATE_BATTLEFIELD_SCORE");
99 this:RegisterEvent("UPDATE_WORLD_STATES");
100 -- Tooltip modifications
101 this:RegisterEvent("UPDATE_MOUSEOVER_UNIT");
102 -- Updating titan button/tooltip
103 this:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN");
104 this:RegisterEvent("PLAYER_PVP_KILLS_CHANGED");
105 this:RegisterEvent("PLAYER_PVP_RANK_CHANGED");
106 -- For checking BG queue status
107 this:RegisterEvent("UPDATE_BATTLEFIELD_STATUS");
108  
109 -- Get LeftClick Event
110 this:RegisterForClicks("LeftButtonUp");
111  
112 -- ** Function hooks **
113 -- Update of BG scoreboard
114 old_WorldStateScoreFrame_Update = WorldStateScoreFrame_Update;
115 WorldStateScoreFrame_Update = TitanHonorPlus_WorldStateScoreFrame_Update;
116 -- Resizing the BG scoreboard
117 old_WorldStateScoreFrame_Resize = WorldStateScoreFrame_Resize;
118 WorldStateScoreFrame_Resize = TitanHonorPlus_WorldStateScoreFrame_Resize
119 -- Tooltip is hidden
120 old_GameTooltip_OnHide = GameTooltip_OnHide;
121 GameTooltip_OnHide = TitanHonorPlus_GameTooltip_OnHide;
122 -- Dynamic query dialog is hidden
123 old_StaticPopup_OnHide = StaticPopup_OnHide;
124 StaticPopup_OnHide = TitanHonorPlus_StaticPopup_OnHide;
125  
126 -- Kill List.
127 SlashCmdList["TITANHONORPLUS"] = TitanHonorPlus_PrintKills;
128 SLASH_TITANHONORPLUS1 = "/titanhonorplus";
129 SLASH_TITANHONORPLUS2 = "/thp";
130 end
131  
132 -- Setup Titan Registry
133 function TitanPanelHonorPlus_Register()
134 this.registry = {
135 id = TITAN_HONORPLUS_ID,
136 builtIn = 1,
137 version = "10.1700",
138 menuText = TITAN_HONORPLUS_MENU_TEXT,
139 buttonTextFunction = "TitanPanelHonorPlusButton_GetButtonText",
140 tooltipTitle = TITAN_HONORPLUS_TOOLTIP,
141 tooltipTextFunction = "TitanPanelHonorPlusButton_GetTooltipText",
142 frequency = 1,
143 savedVariables = {
144 ShowIcon = 1,
145 ShowLabelText = 1,
146  
147 AlternateDisplay = 0,
148 SortByHonor = 0,
149 SortByKills = 1,
150  
151 UseCalculatedToday = 0,
152 SCT = 1,
153  
154 Print_Bonus = 1,
155  
156 ScoreBoard_Kills = 1,
157 ScoreBoard_Opium = 1,
158 ScoreBoard_ClassColorSymbol = 0,
159 ScoreBoard_ClassColorList = 1,
160  
161 Tooltip = 1,
162  
163 AutoRelease = 1,
164 AutoJoinBG = 1,
165 }
166 };
167 end
168  
169 ----------------------------
170 -- Initialization
171 ----------------------------
172 function TitanHonorPlus_Initialize()
173 if (vVar) then
174 local iName, xName;
175 if (TITAN_HONORPLUS == nil) then TITAN_HONORPLUS = { }; end
176 vC = UnitName("player").."|"..GetCVar("realmName");
177 if (TITAN_HONORPLUS[vC] == nil) then TITAN_HONORPLUS[vC] = { }; end
178 for iName, xName in TITAN_HONORPLUS_DEFAULTS do
179 if (TITAN_HONORPLUS[vC][iName] == nil) then TITAN_HONORPLUS[vC][iName] = xName; end
180 end
181 for iName, xName in TITAN_HONORPLUS[vC]['log'] do
182 if (type(xName) == "number") then TITAN_HONORPLUS[vC]['log'][iName] = { ['k'] = xName, ['h'] = 0, ['r'] = "Unknown Rank" }; end
183 end
184 info = TITAN_HONORPLUS_CHATINFO["Default"];
185 if (TITAN_HONORPLUS_CHATINFO[UnitName("Player")]) then info = TITAN_HONORPLUS_CHATINFO[UnitName("Player")]; end
186 ChatTypeInfo["HONORPLUS"] = info;
187  
188 if (type(TipBuddy_TargetName_Text) == "table") and (type(TipBuddy_Main_Frame) == "table") then
189 TitanHonorPlus_TipBuddy_Main_Frame:Show();
190 TitanHonorPlus_TipBuddy_TargetName_Text:ClearAllPoints();
191 TitanHonorPlus_TipBuddy_TargetName_Text:SetPoint("BOTTOMLEFT", "TipBuddy_Main_Frame", "TOPLEFT", 0, 0);
192 end
193 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
194 TitanPanelButton_UpdateTooltip();
195 vLoaded = true;
196 end
197 end
198  
199 ----------------------------
200 -- Slash Commands
201 ----------------------------
202 -- The one and only slash command prints all of todays kills
203 function TitanHonorPlus_PrintKills()
204 local rankName, rankNumber, todayHK, todayDK, todayCP, todayB, ydayHK, ydayDK, ydayCP,
205 weekHK, weekDK, weekCP, lastweekHK, lastweekDK, lastweekCP, lastweekRank,
206 lifetimeHK, lifetimeDK, highestRankName, highestRankNumber = TitanPanelHonorPlusGetPVPData("Slashcommand");
207 DEFAULT_CHAT_FRAME:AddMessage("Todays Kills:");
208 local s;
209 if (TitanGetVar(TITAN_HONORPLUS_ID, "SortByKills") == 1) then s = "k"; else s = "h"; end
210 local done = {};
211 local a, b, x, y, i, c, high, text;
212 local c1, c2 = "", "";
213 i = 0;
214 for a, b in TITAN_HONORPLUS[vC]['log'] do
215 text, high = "", nil;
216 for x, y in TITAN_HONORPLUS[vC]['log'] do
217 if (not done[x]) then
218 if (high == nil) then high = x; end
219 if (y[s] > TITAN_HONORPLUS[vC]['log'][high][s]) then high = x; end
220 end
221 end
222 done[high] = 1;
223 c = "|cffd0d0ff";
224 if (TITAN_HONORPLUS[vC]['log'][high]['k'] > 3) then c = "|cffffd0d0"; end
225 if (TITAN_HONORPLUS[vC]['log'][high]['c']) then local oclass = TITAN_HONORPLUS[vC]['log'][high]['c']; c1 = TITAN_HONORPLUS_CLASSCOLORINDEX[oclass]; c2 = "|r"; end
226 text = text..c..TITAN_HONORPLUS[vC]['log'][high]['k'].." "..c1..high..c2.."|r"..
227 "|cffd0d0d0".." (";
228 if (TITAN_HONORPLUS[vC]['log'][high]['l']) then text = text.."L"..TITAN_HONORPLUS[vC]['log'][high]['l'].." "; end
229 text = text..TITAN_HONORPLUS[vC]['log'][high]['r']..")".."|r".." "..
230 "|cffdacda1"..TitanPanelHonorPlusRound(TITAN_HONORPLUS[vC]['log'][high]['h']).." "..HONOR_CONTRIBUTION_POINTS;
231 i = i+1;
232 DEFAULT_CHAT_FRAME:AddMessage(text);
233 end
234 if (i == 0) then DEFAULT_CHAT_FRAME:AddMessage("|cffffa0a0".."No Kills.".."|r"); end
235 end
236  
237 ----------------------------
238 -- On Event
239 ----------------------------
240 function TitanPanelHonorPlusButton_OnEvent()
241  
242 if (event == "VARIABLES_LOADED") then
243 vVar = true;
244 TitanHonorPlus_Initialize();
245 ---------------------------------------
246  
247 elseif (event == "CHAT_MSG_COMBAT_HONOR_GAIN") then
248 local x, p, h, s ,e, f, k;
249 local s, e, name, rank, honor = string.find(arg1, TITAN_HONORPLUS_SEARCH);
250 if (name) and (rank) and (honor) then
251  
252 if (TITAN_HONORPLUS[vC]['log'][name] == nil) then TITAN_HONORPLUS[vC]['log'][name] = { ['h'] = 0, ['k'] = 0, }; end
253 TITAN_HONORPLUS[vC]['todayhk'] = TITAN_HONORPLUS[vC]['todayhk'] +1;
254 TITAN_HONORPLUS[vC]['log'][name]['k'] = TITAN_HONORPLUS[vC]['log'][name]['k'] +1;
255 x = TITAN_HONORPLUS[vC]['log'][name]['k'];
256 if (x == 1) then p = 1;
257 elseif (x == 2) then p = 0.75;
258 elseif (x == 3) then p = 0.5;
259 elseif (x == 4) then p = 0.25;
260 else p = 0; end
261 h = honor * p;
262 TITAN_HONORPLUS[vC]['todaycp'] = TITAN_HONORPLUS[vC]['todaycp'] + h;
263 TITAN_HONORPLUS[vC]['todaycp2'] = TITAN_HONORPLUS[vC]['todaycp2'] + honor;
264 local hround = TitanPanelHonorPlusRound(h);
265 local text = string.format(TITAN_HONORPLUS_ESTIMATED,name, x, rank, hround);
266 TitanPanelHonorPlusButton_PrintMsg(text);
267  
268 TITAN_HONORPLUS[vC]['log'][name]['h'] = TITAN_HONORPLUS[vC]['log'][name]['h'] + h;
269 TITAN_HONORPLUS[vC]['log'][name]['r'] = rank;
270 local oclass, olevel;
271 if (playerList[name]) then
272 if (playerList[name]['l']) then olevel = playerList[name]['l']; end
273 if (playerList[name]['c']) then oclass = playerList[name]['c']; end
274 end
275 if ((not oclass) or (not olevel)) and (type(Opium_TimeToString) == "function") and (type(OpiumData) == "table") then
276 local playerData = OpiumData["playerLinks"][GetCVar("realmName")][string.lower(name)];
277 if playerData then
278 olevel = playerData[OPIUM_INDEX_LEVEL];
279 oclass = playerData[OPIUM_INDEX_CLASS];
280 end
281 end
282 if (olevel) then
283 TITAN_HONORPLUS[vC]['log'][name]['l'] = olevel;
284 end
285 if (oclass) then
286 TITAN_HONORPLUS[vC]['log'][name]['c'] = oclass;
287 end
288 if (hround > 0) and (type(SCT_OnLoad) == "function") and (TitanGetVar(TITAN_HONORPLUS_ID, "SCT") == 1) then
289 currentcolor = SCT_GetColor(16);
290 text = "+"..hround.." "..HONOR_CONTRIBUTION_POINTS;
291 if (SCT_Get("SHOWHONOR") == 1) then text = text.."*"; end
292 if (SCT_Get("SHOWASMESSAGE") == 1) then
293 SCT_Display_Message(text, currentcolor);
294 else
295 SCT_Display(text, currentcolor);
296 end
297 end
298 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
299 TitanPanelButton_UpdateTooltip();
300 end
301 ---------------------------------------
302  
303 elseif (event == "UPDATE_MOUSEOVER_UNIT") then
304 TitanHonorPlus_ClearHonorLine();
305  
306 if (UnitExists("mouseover")) and (TitanGetVar(TITAN_HONORPLUS_ID, "Tooltip") == 1) and -- Longest ever if statement? lol
307 (not UnitIsFriend("player", "mouseover")) and (UnitIsPlayer("mouseover")) and
308 (GetDifficultyColor(UnitLevel("mouseover")) ~= QuestDifficultyColor["trivial"]) then
309  
310 local oclass, olevel = TITAN_HONORPLUS_CLASSINDEX[UnitClass("mouseover")], UnitLevel("mouseover");
311 playerList[UnitName("mouseover")] = { ['c'] = oclass, ['l'] = olevel }
312 local i;
313 local z = TITAN_HONORPLUS[vC]['log'][UnitName("mouseover")];
314 if (z) then
315 TITAN_HONORPLUS[vC]['log'][UnitName("mouseover")]['c'] = oclass;
316 TITAN_HONORPLUS[vC]['log'][UnitName("mouseover")]['l'] = olevel;
317 i = z['k'];
318 end
319 local text, color;
320 if (type(i) ~= "number") then i = 0; end
321 if (i > 3) then text = "0% ";
322 elseif (i == 3) then text = "25% ";
323 elseif (i == 2) then text = "50% ";
324 elseif (i == 1) then text = "75% ";
325 else text = "100%"; end
326 text = text.." "..HONOR_CONTRIBUTION_POINTS;
327 color = TitanHonorPlus_SmoothColor(i);
328 if (type(TipBuddy_TargetName_Text) == "table") and (type(TipBuddy_Main_Frame) == "table") then
329 TitanHonorPlus_TipBuddy_Main_Frame:SetParent(TipBuddy_Main_Frame);
330 TitanHonorPlus_TipBuddy_TargetName_Text:Show();
331 TitanHonorPlus_TipBuddy_TargetName_Text:SetWidth(TipBuddy_Main_Frame:GetWidth());
332 TitanHonorPlus_TipBuddy_TargetName_Text:SetText(text);
333 TitanHonorPlus_TipBuddy_TargetName_Text:SetTextColor(color);
334 end
335 if (GameTooltip:IsVisible()) and (type(GameTooltipTextLeft1:GetText()) == "string") and (string.find(GameTooltipTextLeft1:GetText(), UnitName("mouseover"))) then
336 local j, left, right;
337 for j=3,20 do
338 left = getglobal("GameTooltipTextLeft"..j);
339 right = getglobal("GameTooltipTextRight"..j);
340 if ((left:GetText() == nil) or (left:GetText() == "")) and ((right:GetText() == nil) or (right:GetText() == "")) then
341 left:SetText(text);
342 left:SetTextColor(color);
343 left:Show();
344 TITAN_HONORPLUS_TOOLTIPLINE = j;
345 GameTooltip:SetHeight(GameTooltip:GetHeight() +18);
346 break;
347 end
348 end
349 end
350 else
351 TitanHonorPlus_TipBuddy_TargetName_Text:SetText("");
352 end
353 ---------------------------------------
354  
355 elseif (event == "UPDATE_BATTLEFIELD_STATUS") then
356 TitanHonorPlus_CheckBGConfirm();
357 ---------------------------------------
358  
359 -- I've seen other implementations of gathering battleground player data, and it all looked very messy, using function hooks, and the dreadful OnUpdate, ARGH!
360 -- Well, I found a far easier way of doing that with simple events =]
361 elseif (event == "UPDATE_BATTLEFIELD_SCORE") or (event == "UPDATE_WORLD_STATES") then
362 TitanHonorPlus_CheckBonusHonor();
363 ---------------------------------------
364  
365 elseif (event == "CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS") or (event == "CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE") then
366 TITAN_HONORPLUS_PVPDMG = GetTime();
367 ---------------------------------------
368  
369 elseif (event == "PLAYER_DEAD") then
370 -- Auto-Release upon death. But not when soulstoned, and only in battlegrounds.
371 local status, _, _ = GetBattlefieldStatus();
372 if (status == "active") and (not HasSoulstone()) and (TitanGetVar(TITAN_HONORPLUS_ID, "AutoRelease") == 1) then
373 RepopMe();
374 end
375 local x = GetTime() -15;
376 if (x <= TITAN_HONORPLUS_PVPDMG) then TITAN_HONORPLUS[vC]['todayd'] = TITAN_HONORPLUS[vC]['todayd'] +1; end
377 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
378 TitanPanelButton_UpdateTooltip();
379 ---------------------------------------
380 TitanHonorPlus_RequestBattlefieldData();
381 end
382 ------------------------------------------------------------------------------------------------------------------------------------------------------------
383  
384 end
385  
386 function TitanHonorPlus_RequestBattlefieldData(f)
387 if (f) or (GetTime() > TITAN_HONORPLUS_BGAPI_NEXT) then
388 TITAN_HONORPLUS_BGAPI_NEXT = GetTime() + TITAN_HONORPLUS_BGAPI_INTERVAL;
389 RequestBattlefieldScoreData();
390 end
391 end
392  
393 -- Clear the tooltip of the previously added honor info
394 function TitanHonorPlus_ClearHonorLine()
395 if (TITAN_HONORPLUS_TOOLTIPLINE) then
396 local lastleft = getglobal("GameTooltipTextLeft"..TITAN_HONORPLUS_TOOLTIPLINE);
397 if (type(lastleft:GetText()) == "string") and (string.find(lastleft:GetText(), HONOR_CONTRIBUTION_POINTS)) then
398 lastleft:SetText("");
399 lastleft:Hide();
400 end
401 TITAN_HONORPLUS_TOOLTIPLINE = nil;
402 end
403 end
404  
405 -- Call TitanHonorPlus_ClearHonorLine() when the tooltip is hidden
406 function TitanHonorPlus_GameTooltip_OnHide()
407 old_GameTooltip_OnHide();
408 TitanHonorPlus_ClearHonorLine();
409 end
410  
411 function TitanHonorPlus_CheckBonusHonor()
412 local i, j;
413 j = GetNumBattlefieldScores();
414 for i = 1, j do
415 local name, killingBlows, honorableKills, deaths, honorGained, faction, rank, race, class = GetBattlefieldScore(i);
416 if (name) then
417 if (faction == 1) then faction = "Alliance"; else faction = "Horde"; end
418 if (UnitFactionGroup("player") ~= faction) and (name) and (not playerList[name]) then
419 local oclass = TITAN_HONORPLUS_CLASSINDEX[class];
420 playerList[name] = { ['c'] = oclass };
421 if (TITAN_HONORPLUS[vC]['log'][name]) then TITAN_HONORPLUS[vC]['log'][name]['c'] = oclass; end
422 end
423 if (name == UnitName("player")) then
424 if (honorGained ~= nil) and (honorGained ~= TITAN_HONORPLUS_CURRENTBONUS) then
425 diff = honorGained - TITAN_HONORPLUS_CURRENTBONUS;
426 TITAN_HONORPLUS_CURRENTBONUS = honorGained;
427 if (diff > 0) then
428 TitanPanelHonorPlusButton_PrintMsg(string.format(TITAN_HONORPLUS_BONUSHONORGAINED, diff));
429 TITAN_HONORPLUS[vC]['todayb'] = TITAN_HONORPLUS[vC]['todayb'] + diff;
430 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
431 TitanPanelButton_UpdateTooltip();
432 end
433 end
434 break;
435 end
436 end
437 end
438 end
439  
440 ----------------------------
441 -- Auto-join Battlegrounds
442 ----------------------------
443 function TitanHonorPlus_CheckBGConfirm()
444 local status;
445  
446 for i=1,MAX_BATTLEFIELD_QUEUES do
447 status,_,_ = GetBattlefieldStatus(i);
448 if(status == "confirm") then
449 break
450 end
451 end
452  
453  
454 if (status == "confirm") then
455 if (StaticPopup_Visible("CONFIRM_BATTLEFIELD_ENTRY")) then
456 if (TITAN_HONORPLUS_BGCONFIRM == 0) then
457 DEFAULT_CHAT_FRAME:AddMessage(NORMAL_FONT_COLOR_CODE..TITAN_HONORPLUS_AUTOJOINBG..FONT_COLOR_CODE_CLOSE);
458 TITAN_HONORPLUS_BGCONFIRM = GetTime() +10;
459 elseif (GetTime() > TITAN_HONORPLUS_BGCONFIRM) then
460 TITAN_HONORPLUS_BGCONFIRM = 0;
461 DEFAULT_CHAT_FRAME:AddMessage(NORMAL_FONT_COLOR_CODE..TITAN_HONORPLUS_AUTOJOINBG_DONE..FONT_COLOR_CODE_CLOSE);
462 BattlefieldFrame_EnterBattlefield();
463 StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY");
464 end
465 end
466 end
467 end
468  
469 -- If the "Hide" button is clicked when ready to enter BG.
470 -- It means the user doesn't want to join, so we disable auto-join.
471 function TitanHonorPlus_StaticPopup_OnHide()
472 old_StaticPopup_OnHide();
473 if (this.which == "CONFIRM_BATTLEFIELD_ENTRY") and (TITAN_HONORPLUS_BGCONFIRM ~= 0) then
474 TITAN_HONORPLUS_BGCONFIRM = 0;
475 DEFAULT_CHAT_FRAME:AddMessage(NORMAL_FONT_COLOR_CODE..TITAN_HONORPLUS_AUTOJOINBG_CANCEL..FONT_COLOR_CODE_CLOSE);
476 end
477 end
478  
479  
480  
481 ----------------------------
482 -- Return Button text
483 ----------------------------
484 function TitanPanelHonorPlusButton_GetButtonText(id)
485 if (not vLoaded) then return "Loading.."; end
486 TitanHonorPlus_CheckBGConfirm();
487 TitanHonorPlus_RequestBattlefieldData();
488 local rankName, rankNumber, todayHK, todayDK, todayCP, todayB, ydayHK, ydayDK, ydayCP,
489 weekHK, weekDK, weekCP, lastweekHK, lastweekDK, lastweekCP, lastweekRank,
490 lifetimeHK, lifetimeDK, highestRankName, highestRankNumber = TitanPanelHonorPlusGetPVPData("Button");
491  
492 if (TitanGetVar(TITAN_HONORPLUS_ID, "AlternateDisplay") == 1) then
493  
494  
495 local todayD = TITAN_HONORPLUS[vC]['todayd'];
496 return ""..
497 HONOR_CONTRIBUTION_POINTS..": ", TitanUtils_GetHighlightText(todayCP + todayB),
498 TITAN_HONORPLUS_KILLS..": ", TitanUtils_GetGreenText(todayHK),
499 TITAN_HONORPLUS_DEATHS..": ", TitanUtils_GetRedText(todayD);
500 else
501 return ""..
502 TITAN_HONORPLUS_BUTTON_LABEL_RANK, TitanUtils_GetHighlightText(rankNumber),
503 TITAN_HONORPLUS_BUTTON_LABEL_HK, TitanUtils_GetGreenText(todayHK),
504 TITAN_HONORPLUS_BUTTON_LABEL_DK, TitanUtils_GetRedText(todayDK);
505 end
506 end
507  
508 ----------------------------
509 -- Return all PvP data
510 ----------------------------
511 function TitanPanelHonorPlusGetPVPData(msg)
512 -- Current rank
513 local rankName, rankNumber = GetPVPRankInfo(UnitPVPRank("player"));
514 if (not rankName) then
515 rankName = NONE;
516 end
517  
518 -- This session's values
519 local todayHK, todayDK = GetPVPSessionStats();
520  
521 local todayB = TITAN_HONORPLUS[vC]['todayb'];
522  
523 -- Yesterday's values
524 local ydayHK, ydayDK, ydayCP = GetPVPYesterdayStats();
525  
526 -- This Week's values
527 local weekHK, weekCP = GetPVPThisWeekStats();
528  
529 -- Last Week's values
530 local lastweekHK, lastweekDK, lastweekCP, lastweekRank = GetPVPLastWeekStats();
531  
532 -- Lifetime stats
533 local lifetimeHK, lifetimeDK, highestRank = GetPVPLifetimeStats();
534 local highestRankName, highestRankNumber = GetPVPRankInfo(highestRank);
535 if ( not highestRankName ) then
536 highestRankName = NONE;
537 end
538  
539 if (ydayCP ~= TITAN_HONORPLUS[vC]['yesterday']) and (not ((ydayCP == 0) and (lifetimeHK == 0))) then
540 -- Yesterday has been updated.
541 TITAN_HONORPLUS[vC]['yesterday'] = ydayCP;
542 TITAN_HONORPLUS[vC]['weekdk'] = TITAN_HONORPLUS[vC]['weekdk'] + ydayDK;
543 TITAN_HONORPLUS[vC]['log'] = { };
544 TITAN_HONORPLUS[vC]['todayhk'] = 0;
545 TITAN_HONORPLUS[vC]['todaydk'] = 0;
546 TITAN_HONORPLUS[vC]['todaycp'] = 0;
547 TITAN_HONORPLUS[vC]['todayb'] = 0;
548 TITAN_HONORPLUS[vC]['todayd'] = 0;
549 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
550 TitanPanelButton_UpdateTooltip();
551 end
552 if (TitanGetVar(TITAN_HONORPLUS_ID, "UseCalculatedToday") == 1) then todayHK = TITAN_HONORPLUS[vC]['todayhk']; end
553 local todayCP = TitanPanelHonorPlusRound(TITAN_HONORPLUS[vC]['todaycp']);
554  
555 -- reset if new week
556 if (lastweekCP ~= TITAN_HONORPLUS[vC]['lastweek']) then
557 TITAN_HONORPLUS[vC]['lastweek'] = lastweekCP;
558 TITAN_HONORPLUS[vC]['weekcp'] = 0;
559 TITAN_HONORPLUS[vC]['weekdk'] = 0;
560 TitanPanelButton_UpdateTooltip();
561 end
562 local weekDK = TITAN_HONORPLUS[vC]['weekdk'];
563  
564 return rankName, rankNumber, todayHK, todayDK, todayCP, todayB, ydayHK, ydayDK, ydayCP,
565 weekHK, weekDK, weekCP, lastweekHK, lastweekDK, lastweekCP, lastweekRank,
566 lifetimeHK, lifetimeDK, highestRankName, highestRankNumber;
567 end
568  
569 function TitanPanelHonorPlusButton_OnClick()
570 if (arg1 == "LeftButton") then
571 TitanPanelHonorPlus_ToggleVar_AlternateDisplay();
572 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
573 TitanPanelButton_UpdateTooltip();
574  
575 else
576 TitanPanelButton_OnClick(arg1);
577 end
578 end
579  
580 ----------------------------
581 -- Return Tooltip text
582 ----------------------------
583 function TitanPanelHonorPlusButton_GetTooltipText()
584 if (not vLoaded) then return "Loading.."; end
585  
586 local rankName, rankNumber, todayHK, todayDK, todayCP, todayB, ydayHK, ydayDK, ydayCP,
587 weekHK, weekDK, weekCP, lastweekHK, lastweekDK, lastweekCP, lastweekRank,
588 lifetimeHK, lifetimeDK, highestRankName, highestRankNumber = TitanPanelHonorPlusGetPVPData("Tooltip");
589  
590 local todaycp2 = TitanPanelHonorPlusRound(TITAN_HONORPLUS[vC]['todaycp2']);
591 local progress = TitanPanelHonorPlusRound(GetPVPRankProgress() *100);
592 local todayD = TITAN_HONORPLUS[vC]['todayd'];
593 local s;
594 if (TitanGetVar(TITAN_HONORPLUS_ID, "SortByKills") == 1) then s = "k"; else s = "h"; end
595 local done = {};
596 local high;
597  
598 if (TitanGetVar(TITAN_HONORPLUS_ID, "AlternateDisplay") == 1) then
599  
600 local text = ""..
601 RANK..": "..TitanUtils_GetHighlightText(rankName.." ("..RANK.." "..rankNumber..")").."\n"..
602 TITAN_HONORPLUS_PROGRESS..": "..TitanUtils_GetHighlightText(progress.."%").."\n"..
603 "\n"..
604 TitanUtils_GetHighlightText(TITAN_HONORPLUS_PVPSTATS).."\n"..
605 TITAN_HONORPLUS_KILLS..": \t"..TitanUtils_GetGreenText(todayHK).."\n"..
606 TITAN_HONORPLUS_DEATHS..": \t"..TitanUtils_GetRedText(todayD).."\n"..
607 "\n"..
608 TitanUtils_GetHighlightText(HONOR_CONTRIBUTION_POINTS).."\n"..
609 TITAN_HONORPLUS_KILLS..": \t"..TitanUtils_GetHighlightText(todayCP).."\n"..
610 TITAN_HONORPLUS_BONUS..": \t"..TitanUtils_GetHighlightText(todayB).."\n"..
611 TITAN_HONORPLUS_TOTAL..": \t"..TitanUtils_GetHighlightText(todayCP + todayB).."\n"..
612 "\n"..
613 TitanUtils_GetHighlightText(TITAN_HONORPLUS_TOP15);
614  
615 local a, b, x, y, i, c;
616 local c1 = "|cffd0d0d0";
617 i = 0;
618 for a, b in TITAN_HONORPLUS[vC]['log'] do
619 high = nil;
620 for x, y in TITAN_HONORPLUS[vC]['log'] do
621 if (not done[x]) then
622 if (high == nil) then high = x; end
623 if (y[s] > TITAN_HONORPLUS[vC]['log'][high][s]) then high = x; end
624 end
625 end
626 done[high] = 1;
627 c = "|cffd0d0ff";
628 if (TITAN_HONORPLUS[vC]['log'][high]['k'] > 3) then c = "|cffffd0d0"; end
629 if (TITAN_HONORPLUS[vC]['log'][high]['c']) then local oclass = TITAN_HONORPLUS[vC]['log'][high]['c']; c1 = TITAN_HONORPLUS_CLASSCOLORINDEX[oclass]; end
630 text = text.."\n"..c..TITAN_HONORPLUS[vC]['log'][high]['k'].." "..c1..high.."|r"..
631 "|cffd0d0d0".." (";
632 if (TITAN_HONORPLUS[vC]['log'][high]['l']) then text = text.."L"..TITAN_HONORPLUS[vC]['log'][high]['l'].." "; end
633 text = text..TITAN_HONORPLUS[vC]['log'][high]['r']..")".."|r".."\t"..
634 "|cffdacda1"..TitanPanelHonorPlusRound(TITAN_HONORPLUS[vC]['log'][high]['h']).." "..HONOR_CONTRIBUTION_POINTS;
635 i = i+1;
636 if (i == 15) then break; end
637 end
638 if (i == 0) then text = text.."\n"..TITAN_HONORPLUS_NOKILLS; end
639 return text;
640 else
641  
642 return ""..
643 RANK..": "..TitanUtils_GetHighlightText(rankName.." ("..RANK.." "..rankNumber..")").."\n"..
644 TITAN_HONORPLUS_PROGRESS..": "..TitanUtils_GetHighlightText(progress.."%").."\n"..
645 "\n"..
646 TitanUtils_GetHighlightText(HONOR_THIS_SESSION).." ".."|cffa0a0a0"..TITAN_HONORPLUS_HINT_TOOLTIP.."|r".."\n"..
647 HONORABLE_KILLS..": \t"..TitanUtils_GetGreenText(todayHK).."\n"..
648 DISHONORABLE_KILLS..": \t"..TitanUtils_GetRedText(todayDK).."\n"..
649 TITAN_HONORPLUS_BONUS..": \t".."|cffa0a0ff"..todayB.."|r".."\n"..
650 HONOR_CONTRIBUTION_POINTS..": \t"..TitanUtils_GetHighlightText(todayCP + todayB).."\n"..
651 "\n"..
652 TitanUtils_GetHighlightText(HONOR_YESTERDAY).."\n"..
653 HONORABLE_KILLS..": \t"..TitanUtils_GetGreenText(ydayHK).."\n"..
654 DISHONORABLE_KILLS..": \t"..TitanUtils_GetRedText(ydayDK).."\n"..
655 HONOR_CONTRIBUTION_POINTS..": \t"..TitanUtils_GetHighlightText(ydayCP).."\n"..
656 "\n"..
657 TitanUtils_GetHighlightText(HONOR_THISWEEK).."\n"..
658 HONORABLE_KILLS..": \t"..TitanUtils_GetGreenText(weekHK).."\n"..
659 DISHONORABLE_KILLS..": \t"..TitanUtils_GetRedText(weekDK).."\n"..
660 HONOR_CONTRIBUTION_POINTS..": \t"..TitanUtils_GetHighlightText(weekCP).."\n"..
661 "\n"..
662 TitanUtils_GetHighlightText(HONOR_LASTWEEK).."\n"..
663 HONORABLE_KILLS..": \t"..TitanUtils_GetGreenText(lastweekHK).."\n"..
664 DISHONORABLE_KILLS..": \t"..TitanUtils_GetRedText(lastweekDK).."\n"..
665 HONOR_CONTRIBUTION_POINTS..": \t"..TitanUtils_GetHighlightText(lastweekCP).."\n"..
666 HONOR_STANDING..": \t"..TitanUtils_GetHighlightText(lastweekRank).."\n"..
667 "\n"..
668 TitanUtils_GetHighlightText(HONOR_LIFETIME).."\n"..
669 HONORABLE_KILLS..": \t"..TitanUtils_GetGreenText(lifetimeHK).."\n"..
670 DISHONORABLE_KILLS..": \t"..TitanUtils_GetRedText(lifetimeDK).."\n"..
671 HONOR_HIGHEST_RANK..": \t"..TitanUtils_GetHighlightText(highestRankName);
672  
673 end
674 end
675  
676 ----------------------------
677 -- PvP Icon
678 ----------------------------
679 function TitanPanelHonorPlusButton_OnShow()
680 TitanPanelHonorPlusButton_SetPVPHonorIcon();
681 end
682  
683 function TitanPanelHonorPlusButton_SetPVPHonorIcon()
684 local rankName, rankNumber = GetPVPRankInfo(UnitPVPRank("player"));
685 if (rankNumber > 0) then
686 TitanPanelHonorPlusButtonIcon:SetTexture(format("%s%02d", TITAN_HONORPLUS_ICON_PATH, rankNumber));
687 TitanPanelHonorPlusButtonIcon:SetWidth(16);
688 end
689 end
690  
691 ----------------------------
692 -- TitanVar Toggles
693 ----------------------------
694 function TitanPanelHonorPlus_ToggleVar_UseCalculatedToday()
695 TitanToggleVar(TITAN_HONORPLUS_ID, "UseCalculatedToday");
696 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
697 end
698 function TitanPanelHonorPlus_ToggleVar_Print_Bonus()
699 TitanToggleVar(TITAN_HONORPLUS_ID, "Print_Bonus");
700 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
701 end
702 function TitanPanelHonorPlus_ToggleVar_SCT()
703 TitanToggleVar(TITAN_HONORPLUS_ID, "SCT");
704 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
705 end
706 function TitanPanelHonorPlus_ToggleVar_ScoreBoard_Opium()
707 TitanToggleVar(TITAN_HONORPLUS_ID, "ScoreBoard_Opium");
708 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
709 end
710 function TitanPanelHonorPlus_ToggleVar_ScoreBoard_ClassColorSymbol()
711 TitanToggleVar(TITAN_HONORPLUS_ID, "ScoreBoard_ClassColorSymbol");
712 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
713 end
714 function TitanPanelHonorPlus_ToggleVar_ScoreBoard_ClassColorList()
715 TitanToggleVar(TITAN_HONORPLUS_ID, "ScoreBoard_ClassColorList");
716 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
717 end
718 function TitanPanelHonorPlus_ToggleVar_Tooltip()
719 TitanToggleVar(TITAN_HONORPLUS_ID, "Tooltip");
720 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
721 end
722 function TitanPanelHonorPlus_ToggleVar_ScoreBoard_Kills()
723 TitanToggleVar(TITAN_HONORPLUS_ID, "ScoreBoard_Kills");
724 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
725 WorldStateScoreFrame_Update();
726 WorldStateScoreFrame_Resize();
727 end
728 function TitanPanelHonorPlus_ToggleVar_AlternateDisplay()
729 TitanToggleVar(TITAN_HONORPLUS_ID, "AlternateDisplay");
730 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
731 end
732 function TitanPanelHonorPlus_ToggleVar_Sorting()
733 TitanToggleVar(TITAN_HONORPLUS_ID, "SortByKills");
734 TitanToggleVar(TITAN_HONORPLUS_ID, "SortByHonor");
735 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
736 end
737 function TitanPanelHonorPlus_ToggleVar_AutoRelease()
738 TitanToggleVar(TITAN_HONORPLUS_ID, "AutoRelease");
739 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
740 end
741  
742 function TitanPanelHonorPlus_ToggleVar_AutoJoinBG()
743 TitanToggleVar(TITAN_HONORPLUS_ID, "AutoJoinBG");
744 TitanPanelButton_UpdateButton(TITAN_HONORPLUS_ID);
745 end
746  
747 ----------------------------
748 -- Rightclick Menu
749 ----------------------------
750 function TitanPanelRightClickMenu_PrepareHonorPlusMenu()
751 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_HONORPLUS_ID].menuText);
752 TitanPanelRightClickMenu_AddToggleIcon(TITAN_HONORPLUS_ID);
753 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_HONORPLUS_ID);
754 TitanPanelRightClickMenu_AddSpacer();
755  
756  
757 TitanPanelRightClickMenu_AddTitle("General Options");
758 info = {};
759 info.text = TITAN_HONORPLUS_MENU_TOOLTIP;
760 info.func = TitanPanelHonorPlus_ToggleVar_Tooltip;
761 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "Tooltip");
762 UIDropDownMenu_AddButton(info);
763  
764 -- Add toggle for calculating today's values.
765 info = {};
766 info.text = TITAN_HONORPLUS_MENU_CALCTODAY;
767 info.func = TitanPanelHonorPlus_ToggleVar_UseCalculatedToday;
768 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "UseCalculatedToday");
769 UIDropDownMenu_AddButton(info);
770  
771 info = {};
772 info.text = TITAN_HONORPLUS_MENU_PRINTBONUS;
773 info.func = TitanPanelHonorPlus_ToggleVar_Print_Bonus;
774 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "Print_Bonus");
775 UIDropDownMenu_AddButton(info);
776  
777 -- Add toggle for Scrolling Combat Text support.
778 if (type(SCT_OnLoad) == "function") then
779 info = {};
780 info.text = TITAN_HONORPLUS_MENU_SCT;
781 info.func = TitanPanelHonorPlus_ToggleVar_SCT;
782 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "SCT");
783 UIDropDownMenu_AddButton(info);
784 end
785  
786 TitanPanelRightClickMenu_AddSpacer();
787 TitanPanelRightClickMenu_AddTitle("Scoreboard Options");
788  
789 info = {};
790 info.text = TITAN_HONORPLUS_MENU_SCOREBOARDCLASSCOLORSYMBOL;
791 info.func = TitanPanelHonorPlus_ToggleVar_ScoreBoard_ClassColorSymbol;
792 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_ClassColorSymbol");
793 UIDropDownMenu_AddButton(info);
794 info = {};
795 info.text = TITAN_HONORPLUS_MENU_SCOREBOARDCLASSCOLORLIST;
796 info.func = TitanPanelHonorPlus_ToggleVar_ScoreBoard_ClassColorList;
797 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_ClassColorList");
798 UIDropDownMenu_AddButton(info);
799 info = {};
800 info.text = TITAN_HONORPLUS_MENU_SCOREBOARDKILLS;
801 info.func = TitanPanelHonorPlus_ToggleVar_ScoreBoard_Kills;
802 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_Kills");
803 UIDropDownMenu_AddButton(info);
804 if (type(Opium_TimeToString) == "function") and (type(OpiumData) == "table") then
805 info = {};
806 info.text = TITAN_HONORPLUS_MENU_OPIUM;
807 info.func = TitanPanelHonorPlus_ToggleVar_ScoreBoard_Opium;
808 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_Opium");
809 UIDropDownMenu_AddButton(info);
810 end
811  
812 TitanPanelRightClickMenu_AddSpacer();
813 TitanPanelRightClickMenu_AddTitle("Battlegrounds");
814  
815 info = {};
816 info.text = TITAN_HONORPLUS_MENU_AUTORELEASE;
817 info.func = TitanPanelHonorPlus_ToggleVar_AutoRelease;
818 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "AutoRelease");
819 UIDropDownMenu_AddButton(info);
820 info = {};
821 info.text = TITAN_HONORPLUS_MENU_AUTOJOINBG;
822 info.func = TitanPanelHonorPlus_ToggleVar_AutoJoinBG;
823 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "AutoJoinBG");
824 UIDropDownMenu_AddButton(info);
825  
826 if (TitanGetVar(TITAN_HONORPLUS_ID, "AlternateDisplay") == 1) then
827 TitanPanelRightClickMenu_AddSpacer();
828 TitanPanelRightClickMenu_AddTitle("Sorting");
829  
830 info = {};
831 info.text = TITAN_HONORPLUS_MENU_SORTBYKILLS;
832 info.func = TitanPanelHonorPlus_ToggleVar_Sorting;
833 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "SortByKills");
834 UIDropDownMenu_AddButton(info);
835  
836 info = {};
837 info.text = TITAN_HONORPLUS_MENU_SORTBYHONOR;
838 info.func = TitanPanelHonorPlus_ToggleVar_Sorting;
839 info.checked = TitanGetVar(TITAN_HONORPLUS_ID, "SortByHonor");
840 UIDropDownMenu_AddButton(info);
841 end
842 TitanPanelRightClickMenu_AddSpacer();
843 TitanPanelRightClickMenu_AddTitle(TITAN_HONORPLUS_HINT);
844 TitanPanelRightClickMenu_AddSpacer();
845 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_HONORPLUS_ID, TITAN_PANEL_MENU_FUNC_HIDE);
846 end
847  
848 ----------------------------
849 -- Simple Round Function
850 ----------------------------
851 function TitanPanelHonorPlusRound(x)
852 if(x - math.floor(x) > 0.5) then
853 x = x + 0.5;
854 end
855 return math.floor(x);
856 end
857  
858 ----------------------------
859 -- Hooked Scoreboard Function
860 ----------------------------
861 function TitanHonorPlus_WorldStateScoreFrame_Update()
862 old_WorldStateScoreFrame_Update();
863 TitanHonorPlus_CheckBonusHonor();
864  
865 local TitanHonorPlusColumn;
866 if (TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_Kills")) then
867 local text, icon, tooltip, columnButton;
868 local numStatColumns = GetNumBattlefieldStats();
869 local columnButton, columnButtonText, columnTextButton, columnIcon;
870 local honorGainedAnchorFrame = "WorldStateScoreFrameHK";
871 local i = numStatColumns+1;
872 if (i <= MAX_NUM_STAT_COLUMNS) then
873 TitanHonorPlusColumn = i;
874 text, icon, tooltip = TITAN_HONORPLUS_KILLEDTODAY, "", TITAN_HONORPLUS_TOOLTIP_TODAYSKILLS;
875 columnButton = getglobal("WorldStateScoreColumn"..i);
876 columnButtonText = getglobal("WorldStateScoreColumn"..i.."Text");
877 columnButtonText:SetText(text);
878 columnButton.icon = icon;
879 columnButton.tooltip = tooltip;
880  
881 columnTextButton = getglobal("WorldStateScoreButton1Column"..i.."Text");
882 columnTextButton:SetPoint("CENTER", "WorldStateScoreColumn"..i, "CENTER", -1, -33);
883  
884 honorGainedAnchorFrame = "WorldStateScoreColumn"..i;
885 WorldStateScoreFrameHonorGained:SetPoint("CENTER", honorGainedAnchorFrame, "CENTER", 88, 0);
886  
887 getglobal("WorldStateScoreColumn"..i):Show();
888 end
889 end
890 local i;
891 local numScores = GetNumBattlefieldScores();
892 local name, faction, index, buttonName, log, kills, color, text;
893 local buttonName, nameButton, todayColumn;
894  
895 for i=1, MAX_WORLDSTATE_SCORE_BUTTONS do
896 -- Need to create an index adjusted by the scrollframe offset
897 index = FauxScrollFrame_GetOffset(WorldStateScoreScrollFrame) + i;
898 if ( index <= numScores ) then
899 buttonName = getglobal("WorldStateScoreButton"..i.."NameButtonName");
900 nameButton = getglobal("WorldStateScoreButton"..i.."NameButton");
901 if (TitanHonorPlusColumn) then todayColumn = getglobal("WorldStateScoreButton"..i.."Column"..TitanHonorPlusColumn.."Text"); end
902 local name, killingBlows, honorableKills, deaths, honorGained, faction, rank, race, class = GetBattlefieldScore(index);
903 if (name) then
904 text = name;
905 if (TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_Opium")) and (type(Opium_TimeToString) == "function") and (type(OpiumData) == "table") then
906 local myfaction = OPIUM_FACTIONINDEX[UnitFactionGroup("player")];
907 local oname, oline;
908 local playerData = OpiumData["playerLinks"][GetCVar("realmName")][string.lower(name)];
909 if playerData then
910 local olevel, oclass, orace, ofaction, oguild, olastseen = playerData[OPIUM_INDEX_LEVEL], playerData[OPIUM_INDEX_CLASS], playerData[OPIUM_INDEX_RACE], playerData[OPIUM_INDEX_FACTION], playerData[OPIUM_INDEX_GUILD], playerData[OPIUM_INDEX_LASTSEEN];
911 if (olevel == -1) then olevel = "??"; end
912 olastseen = Opium_TimeToString(time() - OPIUM_TIMEOFFSET - olastseen);
913 if (ofaction ~= myfaction) then oname = "|cffff5050"..name.."|r"; else oname = "|cff50ff50"..name.."|r"; end
914 oline = oname.."\n"..HIGHLIGHT_FONT_COLOR_CODE..OPIUM_TEXT_LEVEL.." "..olevel.."|r".." "..OPIUM_RACEINDEX[orace].." "..TITAN_HONORPLUS_CLASSCOLORINDEX[oclass]..OPIUM_CLASSINDEX[oclass].."|r";
915 if (oguild) then oline = oline.."\n".."|cff30ff30".."<"..oguild..">".."|r"; end
916 oline = oline.."\nLast Seen: ".."|cffffa0a0"..olastseen.."|r";
917 nameButton.tooltip = oline;
918 end
919 end
920 if (faction == 1) then faction = "Alliance"; else faction = "Horde"; end
921 local i = TITAN_HONORPLUS_CLASSINDEX[class];
922 if (WorldStateScoreFrame.selectedTab == 1) then
923 if (TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_ClassColorSymbol")) then text = text..TITAN_HONORPLUS_CLASSCOLORINDEX[i].."+".."|r"; end
924 else
925 if (TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_ClassColorList")) then text = TITAN_HONORPLUS_CLASSCOLORINDEX[i]..text.."|r"; end
926 end
927 buttonName:SetText(text);
928 --(TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_Kills"))
929 if (todayColumn) and (TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_Kills")) and (faction ~= UnitFactionGroup("player")) then
930 local log = TITAN_HONORPLUS[vC]['log'][name];
931 if (log) then log = log['k']; end
932 if (type(log) ~= "number") then log = 0; end
933 todayColumn:SetText(TitanHonorPlus_SmoothColor(log, 1)..log.."|r");
934 --todayColumn:SetTextColor(TitanHonorPlus_SmoothColor(log));
935 todayColumn:Show();
936 end
937 end
938 end
939 end
940 end
941  
942 -- Returns color based on number of kills, green to red. Red if more than 3 kills.
943 function TitanHonorPlus_SmoothColor(k, t)
944 if (k > 4) then k = 4; end
945 p = 1-(k/4);
946 local r,g,b = 1, 1, 0;
947 if (p > 0.75) then r = 4*(1- p);
948 else g = 1.33* p; end
949 if (not t) then return r, g, b; end
950 r, g, b = TitanHonorPlus_base10to16(255*r), TitanHonorPlus_base10to16(255*g), TitanHonorPlus_base10to16(255*b);
951 return "|cff"..r..g..b;
952 end
953  
954 local TITAN_HONORPLUS_BASE16 = { [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9, [10] = "a", [11] = "b", [12] = "c", [13] = "d", [14] = "e", [15] = "f" };
955  
956 function TitanHonorPlus_base10to16(n)
957 if (type(n) ~= "number") then return; end
958 n = math.floor(n);
959 local r, d, x = nil, 0, "";
960 while true do
961 d = math.floor(n / 16);
962 r = n - (d*16);
963 n = d;
964 x = TITAN_HONORPLUS_BASE16[r]..x;
965 if (d == 0) then break; end
966 end
967 while (strlen(x) < 2) do x = "0"..x; end
968 return x;
969 end
970  
971 -- So we can grow the size of the BG scoreboard when we add the new column
972 function TitanHonorPlus_WorldStateScoreFrame_Resize(width)
973 old_WorldStateScoreFrame_Resize();
974 TitanHonorPlus_WorldStateScoreFrame_Resize_func();
975 end
976  
977 function TitanHonorPlus_WorldStateScoreFrame_Resize_func()
978 if (TitanGetVar(TITAN_HONORPLUS_ID, "ScoreBoard_Kills")) then
979 local numColumns = GetNumBattlefieldStats() +1;
980 if ( WorldStateScoreScrollFrame:IsVisible() ) then
981 width = WORLDSTATESCOREFRAME_BASE_WIDTH + 37 + numColumns *WORLDSTATESCOREFRAME_COLUMN_SPACING;
982 else
983 width = WORLDSTATESCOREFRAME_BASE_WIDTH + numColumns *WORLDSTATESCOREFRAME_COLUMN_SPACING;
984 end
985 WorldStateScoreFrame:SetWidth(width);
986 WorldStateScoreFrameTopBackground:SetWidth(WorldStateScoreFrame:GetWidth()-129);
987 WorldStateScoreFrameTopBackground:SetTexCoord(0, WorldStateScoreFrameTopBackground:GetWidth()/256, 0, 1.0);
988 WorldStateScoreFrame.scrollBarButtonWidth = WorldStateScoreFrame:GetWidth() - 165;
989 WorldStateScoreFrame.buttonWidth = WorldStateScoreFrame:GetWidth() - 137;
990 WorldStateScoreScrollFrame:SetWidth(WorldStateScoreFrame.scrollBarButtonWidth);
991 end
992 end
993  
994 ----------------------------
995 -- Chat Options
996 ----------------------------
997 CHAT_MSG_HONORPLUS = "Honor+";
998 ChatTypeGroup["HONORPLUS"] = {
999 "CHAT_MSG_HONORPLUS"
1000 };
1001 ChatTypeInfo["HONORPLUS"] = { sticky = 0 };
1002 tinsert(OtherMenuChatTypeGroups, "HONORPLUS");
1003 CHAT_HONORPLUS_GET = "";
1004 TITAN_HONORPLUS_CHATINFO = {
1005 ["Default"] = {
1006 ["r"] = 0.878,
1007 ["g"] = 0.792,
1008 ["b"] = 0.039,
1009 ["show"] = {
1010 "ChatFrame1"
1011 }
1012 }
1013 };
1014 function TitanPanelHonorPlusButton_PrintMsg(msg)
1015 event = "CHAT_MSG_HONORPLUS";
1016 arg1 = msg;
1017 arg2, arg3, arg4, arg6 = "", "", "", "";
1018 local info = TITAN_HONORPLUS_CHATINFO["Default"];
1019 if ( TITAN_HONORPLUS_CHATINFO[UnitName("player")] ) then
1020 info = TITAN_HONORPLUS_CHATINFO[UnitName("player")];
1021 end
1022 for i = 1, 7, 1 do
1023 for k, v in info["show"] do
1024 if ( v == "ChatFrame" .. i ) then
1025 this = getglobal("ChatFrame" .. i);
1026 ChatFrame_OnEvent(event);
1027 end
1028 end
1029 end
1030 end
1031  
1032 TitanPanelHonorPlusButton_oldFCF_Tab_OnClick = FCF_Tab_OnClick;
1033 function TitanPanelHonorPlusButton_newFCF_Tab_OnClick(button)
1034 TitanPanelHonorPlusButton_oldFCF_Tab_OnClick(button);
1035 if ( button == "RightButton" ) then
1036 local frame = getglobal("ChatFrame" .. this:GetID());
1037 local info = TITAN_HONORPLUS_CHATINFO["Default"];
1038 if ( TITAN_HONORPLUS_CHATINFO[UnitName("player")] ) then
1039 info = TITAN_HONORPLUS_CHATINFO[UnitName("player")];
1040 end
1041 for k, v in info["show"] do
1042 if ( v == "ChatFrame" .. this:GetID() ) then
1043 local y = 1;
1044 while ( frame.messageTypeList[y] ) do
1045 y = y + 1;
1046 end
1047 frame.messageTypeList[y] = "HONORPLUS";
1048 end
1049 end
1050 end
1051 end
1052 FCF_Tab_OnClick = TitanPanelHonorPlusButton_newFCF_Tab_OnClick;
1053  
1054 TitanPanelHonorPlusButton_oldFCF_SetChatTypeColor = FCF_SetChatTypeColor;
1055 function TitanPanelHonorPlusButton_newFCF_SetChatTypeColor()
1056 TitanPanelHonorPlusButton_oldFCF_SetChatTypeColor();
1057 if ( UIDROPDOWNMENU_MENU_VALUE == "HONORPLUS" ) then
1058 local r,g,b = ColorPickerFrame:GetColorRGB();
1059 if ( not TITAN_HONORPLUS_CHATINFO[UnitName("player")] ) then
1060 TITAN_HONORPLUS_CHATINFO[UnitName("player")] = TITAN_HONORPLUS_CHATINFO["Default"];
1061 end
1062 TITAN_HONORPLUS_CHATINFO[UnitName("player")].r = r;
1063 TITAN_HONORPLUS_CHATINFO[UnitName("player")].g = g;
1064 TITAN_HONORPLUS_CHATINFO[UnitName("player")].b = b;
1065 ChatTypeInfo["HONORPLUS"].r = r;
1066 ChatTypeInfo["HONORPLUS"].g = g;
1067 ChatTypeInfo["HONORPLUS"].b = b;
1068 end
1069 end
1070 FCF_SetChatTypeColor = TitanPanelHonorPlusButton_newFCF_SetChatTypeColor;
1071  
1072 TitanPanelHonorPlusButton_oldFCF_CancelFontColorSettings = FCF_CancelFontColorSettings;
1073 function TitanPanelHonorPlusButton_newFCF_CancelFontColorSettings(prev)
1074 TitanPanelHonorPlusButton_oldFCF_CancelFontColorSettings(prev);
1075 if ( prev.r and UIDROPDOWNMENU_MENU_VALUE == "HONORPLUS" ) then
1076 if ( not TITAN_HONORPLUS_CHATINFO[UnitName("player")] ) then
1077 TITAN_HONORPLUS_CHATINFO[UnitName("player")] = TITAN_HONORPLUS_CHATINFO["Default"];
1078 end
1079 TITAN_HONORPLUS_CHATINFO[UnitName("player")].r = prev.r;
1080 TITAN_HONORPLUS_CHATINFO[UnitName("player")].g = prev.g;
1081 TITAN_HONORPLUS_CHATINFO[UnitName("player")].b = prev.b;
1082 ChatTypeInfo["HONORPLUS"].r = prev.r;
1083 ChatTypeInfo["HONORPLUS"].g = prev.g;
1084 ChatTypeInfo["HONORPLUS"].b = prev.b;
1085 end
1086 end
1087 FCF_CancelFontColorSettings = TitanPanelHonorPlusButton_newFCF_CancelFontColorSettings;
1088  
1089 TitanPanelHonorPlusButton_oldFCFMessageTypeDropDown_OnClick = FCFMessageTypeDropDown_OnClick;
1090 function TitanPanelHonorPlusButton_newFCFMessageTypeDropDown_OnClick()
1091 TitanPanelHonorPlusButton_oldFCFMessageTypeDropDown_OnClick();
1092 if ( not TITAN_HONORPLUS_CHATINFO[UnitName("player")] ) then
1093 TITAN_HONORPLUS_CHATINFO[UnitName("player")] = TITAN_HONORPLUS_CHATINFO["Default"];
1094 end
1095 if ( this.value == "HONORPLUS" ) then
1096 if ( UIDropDownMenuButton_GetChecked() ) then
1097 for k, v in TITAN_HONORPLUS_CHATINFO[UnitName("player")]["show"] do
1098 if ( v == FCF_GetCurrentChatFrame():GetName() ) then
1099 TITAN_HONORPLUS_CHATINFO[UnitName("player")]["show"][k] = nil;
1100 break;
1101 end
1102 end
1103 else
1104 tinsert(TITAN_HONORPLUS_CHATINFO[UnitName("player")]["show"], FCF_GetCurrentChatFrame():GetName());
1105 end
1106 end
1107 end
1108 FCFMessageTypeDropDown_OnClick = TitanPanelHonorPlusButton_newFCFMessageTypeDropDown_OnClick;