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