vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 
2 --[[ KLH Threatmeter KLHTM_RaidGui.lua
3  
4 Lukon Mod 2: Part of the replacement for Gui.lua and Tables.lua.
5 Controls the GUI for the raid threat section of KLH ThreatMeter.
6 See also KTM_Gui.xml, KTM_Gui.lua.
7 --]]
8  
9 local mod = klhtm
10 local me = { }
11 mod.guiraid = me
12  
13  
14 -- The number of rows defined in New_Frame.xml
15 local Max_Rows = 20;
16 KLHTM_MaxRaidRows = Max_Rows;
17  
18 -- If the top threat value is greater than 150% of aggro gain when no master target is set
19 -- then the threat100 reference value is set to the top threat value. This prevents very
20 -- large %threat values when mobs use secondary targetting abilities.
21 local Max_Aggro_Ratio = 1.5
22  
23 -- Local references to some Gui variables
24 local options = KLHTM_GuiOptions;
25 local gui = KLHTM_Gui;
26 local sizes = KLHTM_GuiSizes;
27 local state = KLHTM_GuiState;
28 local heights = KLHTM_GuiHeights;
29  
30  
31  
32 ------------------------------------------------------------------------------
33 -- Sets up the instance variable "gui.raid". It contains data on the GUI
34 -- components in the raid threat frame.
35 ------------------------------------------------------------------------------
36 function KLHTM_CreateRaidTable()
37  
38 gui.raid = {
39 ["frame"] = KLHTM_RaidFrame,
40 ["line"] = KLHTM_RaidFrameLine, -- dividing line between title bar and frame
41 ["head"] = { -- column headers
42 ["name"] = {
43 ["frame"] = KLHTM_RaidFrameHeaderName,
44 ["text"] = KLHTM_RaidFrameHeaderNameText,
45 ["width"] = 90,
46 ["colour"] = {["r"] = 1.0, ["g"] = 1.0, ["b"] = 1.0},
47 ["vis"] = function() return (options.raid.columnVis.name) end,
48 },
49 ["threat"] = {
50 ["frame"] = KLHTM_RaidFrameHeaderThreat,
51 ["text"] = KLHTM_RaidFrameHeaderThreatText,
52 ["width"] = 45,
53 ["colour"] = {["r"] = 1.0, ["g"] = 1.0, ["b"] = 1.0},
54 ["vis"] = function() return (options.raid.columnVis.threat) end,
55 },
56 ["pc"] = {
57 ["frame"] = KLHTM_RaidFrameHeaderPercentThreat,
58 ["text"] = KLHTM_RaidFrameHeaderPercentThreatText,
59 ["width"] = 40,
60 ["colour"] = {["r"] = 1.0, ["g"] = 1.0, ["b"] = 1.0},
61 ["vis"] = function() return (options.raid.columnVis.pc) end,
62 },
63 },
64 ["rows"] = {},
65 ["bottom"] = { -- bottom bar
66 ["frame"] = KLHTM_RaidFrameBottom,
67 ["line"] = KLHTM_RaidFrameBottomLine, -- dividing line between frame and bottom bar
68 ["tdef"] = {
69 ["frame"] = KLHTM_RaidFrameBottomThreatDefecit,
70 ["text"] = KLHTM_RaidFrameBottomThreatDefecitText,
71 ["width"] = 40,
72 },
73 ["targ"] = {
74 ["frame"] = KLHTM_RaidFrameBottomMasterTarget,
75 ["text"] = KLHTM_RaidFrameBottomMasterTargetText,
76 --["width"] = 50,
77 -- should take up whatever remaining space there is
78 },
79 },
80 };
81  
82 for x = 1 , Max_Rows do
83 gui.raid.rows[x] = {
84 ["frame"] = getglobal("KLHTM_RaidFrameRow" .. x),
85 ["name"] = {
86 ["frame"] = getglobal("KLHTM_RaidFrameRow" .. x .. "Name"),
87 ["text"] = getglobal("KLHTM_RaidFrameRow" .. x .. "NameText"),
88 },
89 ["threat"] = {
90 ["frame"] = getglobal("KLHTM_RaidFrameRow" .. x .. "Threat"),
91 ["text"] = getglobal("KLHTM_RaidFrameRow" .. x .. "ThreatText"),
92 },
93 ["pc"] = {
94 ["frame"] = getglobal("KLHTM_RaidFrameRow" .. x .. "PercentThreat"),
95 ["text"] = getglobal("KLHTM_RaidFrameRow" .. x .. "PercentThreatText"),
96 },
97 ["bar"] = getglobal("KLHTM_RaidFrameRow" .. x .. "Bar"),
98 };
99 end
100 end
101  
102  
103 ------------------------------------------------------------------------------
104 -- Applies Gui component properties that are not specified in the XML
105 ------------------------------------------------------------------------------
106 function KLHTM_SetupRaidGui()
107  
108 -- headers
109 for index, header in gui.raid.head do
110 header.text:SetText(mod.string.get("gui", "raid", "head", index));
111 header.frame:SetHeight(heights.header);
112 KLHTM_AddOutline(header.text);
113 KLHTM_LocaliseStringWidth(header);
114  
115 for _, row in gui.raid.rows do
116 row[index].text:SetTextColor(header.colour.r, header.colour.g, header.colour.b);
117 row[index].frame:SetHeight(heights.data);
118 KLHTM_AddOutline(row[index].text);
119 end
120 end
121  
122 -- rows
123 for _, row in gui.raid.rows do
124 row.frame:SetHeight(heights.data);
125 end
126  
127 -- botton bar
128 gui.raid.bottom.frame:SetHeight(heights.data);
129 gui.raid.bottom.tdef.frame:SetHeight(heights.data);
130 gui.raid.bottom.targ.frame:SetHeight(heights.data);
131 end
132  
133  
134 ------------------------------------------------------------------------------
135 -- Sets the default options for displaying the main window and title bar strings
136 -- when the raid view is selected.
137 ------------------------------------------------------------------------------
138 function KLHTM_SetDefaultRaidOptions()
139  
140 options.raid = {
141 -- column visibility
142 ["columnVis"] = {
143 ["name"] = true,
144 ["threat"] = true,
145 ["pc"] = true,
146 },
147 -- title bar string visibility
148 ["stringVis"] = {
149 ["rank"] = false,
150 ["pc"] = false,
151 ["tdef"] = false,
152 },
153 -- max number of rows to show
154 ["rows"] = 10,
155 -- if true, rows with 0 threat are not shown
156 ["hideZeroRows"] = true,
157 -- if true, the raid window will shrink if there are fewer data rows
158 -- than the specified in ["rows"]. Otherwise empty rows will be shown.
159 ["resize"] = false,
160 -- if true, numbers 10,000 or greater are abbreviated with "k"
161 ["abbreviate"] = false,
162 -- if true, a virtual player "aggro gain" is shown
163 ["showAggroGain"] = true,
164 -- if true, the bottom bar will not be shown
165 ["hideBottomBar"] = false,
166 };
167 end
168  
169  
170 ------------------------------------------------------------------------------
171 -- Updates the visibility of columns the raid table and the bottom bar. The
172 -- contents are not rendered here. The frame width is stored in sizes.self.x.
173 -- Should be called:
174 --
175 -- a) when the column visibility changes
176 -- b) when the number of rows to be drawn changes
177 ------------------------------------------------------------------------------
178 function KLHTM_UpdateRaidFrame()
179  
180 sizes.raid.x = 0;
181  
182 for column, header in gui.raid.head do
183 -- header
184 if (header.vis()) then
185 header.frame:SetWidth(header.width);
186 sizes.raid.x = sizes.raid.x + header.width;
187 header.frame:Show();
188 else
189 header.frame:Hide();
190 header.frame:SetWidth(0.1);
191 end
192 -- rows
193 for index, row in gui.raid.rows do
194 if (header.vis()) then
195 row[column].frame:SetWidth(header.width);
196 row[column].frame:Show();
197 else
198 row[column].frame:Hide();
199 row[column].frame:SetWidth(0.1);
200 end
201 end
202 end
203  
204 for _, row in gui.raid.rows do
205 row.frame:SetWidth(sizes.raid.x);
206 end
207  
208 -- bottom bar
209 gui.raid.bottom.tdef.frame:SetWidth(gui.raid.bottom.tdef.width);
210 -- do we need this now that we have dual anchors?
211 gui.raid.bottom.targ.text:SetWidth(gui.raid.bottom.targ.frame:GetWidth());
212  
213 if (options.raid.hideBottomBar) then
214 gui.raid.bottom.frame:Hide();
215 else
216 gui.raid.bottom.frame:Show();
217 end
218 end
219  
220  
221 ------------------------------------------------------------------------------
222 -- Draws the minimised title bar strings present in the raid view.
223 ------------------------------------------------------------------------------
224 function KLHTM_DrawRaidStrings(raidData, playerCount, threat100)
225  
226 -- update title bar strings
227 local userThreat = mod.table.raiddata[UnitName("player")];
228 if userThreat == nil then
229 userThreat = 0
230 end
231  
232 -- threat defecit (todo: colours?)
233 local defecit = threat100 - userThreat;
234 if (options.raid.abbreviate) then
235 defecit = KLHTM_Abbreviate(defecit);
236 end
237  
238 -- threat rank
239 local userRank = 1;
240 for _, data in raidData do
241 if (data.threat > userThreat) then
242 userRank = userRank + 1;
243 end
244 end
245  
246 if (threat100 == 0) then
247 gui.title.string.tdef.text:SetText("0");
248 gui.title.string.pc.text:SetText("0%");
249 gui.title.string.rank.text:SetText("-/" .. playerCount);
250 else
251 gui.title.string.tdef.text:SetText(defecit);
252 gui.title.string.pc.text:SetText(math.floor(userThreat * 100 / threat100 + 0.5) .. "%");
253 gui.title.string.rank.text:SetText(userRank .. "/" .. playerCount);
254 end
255 end
256  
257  
258 ------------------------------------------------------------------------------
259 -- Draws raid the bottom bar strings
260 --
261 -- [data] - the sorted threat data
262 -- [threat100] - ??
263  
264 -- help i am broken.
265 ------------------------------------------------------------------------------
266 function KLHTM_DrawRaidBottom(data, threat100, playerCount, userThreat)
267  
268 -- master target
269 if (mod.boss.mastertarget ~= nil) then
270 gui.raid.bottom.targ.text:SetText(mod.boss.mastertarget);
271 else
272 gui.raid.bottom.targ.text:SetText("");
273 end
274  
275 -- new threat defecit ... maybe...
276 if (false) then
277 if ((mod.boss.mastertarget ~= nil) and (mod.boss.mttruetarget ~= nil) and
278 (mod.tables.raiddata[mod.boss.mttruetarget] ~= nil)) then
279 -- there is an active, valid master target and targettarget
280  
281 if (mod.boss.mttruetarget == UnitName("player")) then
282 -- we are the MT. either someone above us, or below us
283 end
284 end
285 end
286  
287  
288  
289 -- threat defecit. Several options here. (a) we are MT, show distance to no2.
290 -- (b) we are dps, show defecit from MT \ aggro gain. (c) all zero.
291 -- How do we know what threat100 is referring to?
292  
293 local defecit = threat100 - userThreat;
294 if (defecit == 0) then
295 defecit = "";
296 elseif (options.raid.abbreviate) then
297 defecit = KLHTM_Abbreviate(defecit);
298 end
299 gui.raid.bottom.tdef.text:SetText(defecit);
300  
301  
302  
303 end
304  
305  
306 -- used by GetRaidData(). Defined at the class level to reduce memory use.
307 local GetRaidData_data;
308 ------------------------------------------------------------------------------
309 -- Makes a copy of the raid threat data from KLHTM_RaidData for use by
310 -- KLHTM_DrawRaidFrame and performs some processing.
311 --
312 -- returns:
313 -- [data] - the sorted threat data (with zero-pruning only),
314 -- [playerCount] - the number of preporting players (virtual and real),
315 -- [threat100] - the reference value for %max threat calculations
316 ------------------------------------------------------------------------------
317 function KLHTM_GetRaidData()
318  
319 local data = GetRaidData_data;
320  
321 if (data == nil) then
322 data = {};
323 -- 50: 40 players + room for "virtual players" eg aggro gain
324 for x = 1, 50 do
325 data[x] = {["name"] = "", ["threat"] = 0, ["pc"] = 0,};
326 end
327  
328 GetRaidData_data = data
329 end
330  
331 -- check for aggro gain
332 if (options.raid.showAggroGain) then
333 mod.boss.updateaggrogain()
334 else
335 mod.table.raiddata[mod.string.get("misc", "aggrogain")] = nil;
336 end
337  
338 -- copy data over
339 local rowCount = 0; -- the number of rows to be rendered
340 local playerCount = 0; -- the number of players found
341  
342 for player, threat in mod.table.raiddata do
343 playerCount = playerCount + 1;
344  
345 -- omit "zero rows" if necessary
346 if (not(options.raid.hideZeroRows and (threat == 0))) then
347 rowCount = rowCount + 1;
348 data[rowCount].name = player;
349 data[rowCount].threat = threat;
350 end
351 end
352 table.setn(data, rowCount);
353  
354 table.sort(data, function(a,b) return a.threat > b.threat; end);
355  
356 -- determine the %threat reference value
357 -- this part is highly suspect. Need the updated boss module, then a recode
358 -- of the threat100 and related calculations.
359 local threat100; local aggro;
360  
361 if (rowCount == 0) then
362 -- there is no data availible
363 threat100 = 0;
364 else
365 if (options.raid.showAggroGain == false) then
366 -- ignore aggro gain. Wrong!
367 threat100 = data[1].threat;
368 else
369 -- use MT if possible, or targettarget
370 if (mod.boss.mastertarget == nil) then
371 aggro = mod.table.raiddata[mod.string.get("misc", "aggrogain")];
372 else
373 aggro = mod.table.raiddata[mod.boss.mttruetarget];
374 end
375 -- ignore unreasonable threat100 values
376 if ((aggro == nil) or (aggro * Max_Aggro_Ratio < data[1].threat)) then
377 threat100 = data[1].threat;
378 else
379 threat100 = aggro;
380 end
381 end
382 end
383  
384 return data, playerCount, threat100;
385 end
386  
387  
388 ------------------------------------------------------------------------------
389 -- Updates the raid threat window (if maximised) and title bar raid strings.
390 -- Updates the raid threat data. A copy of KLHTM_RaidData is made, and processed.
391 -- If minimised, KLHTM_DrawRaidStrings is called. Otherwise all the strings in
392 -- the raid frame are redrawn.
393 ------------------------------------------------------------------------------
394 function KLHTM_DrawRaidFrame()
395  
396 local data, playerCount, threat100 = KLHTM_GetRaidData();
397  
398 if (state.min) then
399 KLHTM_DrawRaidStrings(data, playerCount, threat100);
400 return;
401 end
402  
403 local userThreat = mod.table.raiddata[UnitName("player")];
404 if (userThreat == nil) then
405 -- seems to happen at initialisation
406 userThreat = 0;
407 end
408  
409 -- make sure the user is visible (user may not show up with 0 threat)
410 if (table.getn(data) > options.raid.rows) then
411 if (userThreat < data[options.raid.rows].threat) then
412 data[options.raid.rows].name = UnitName("player");
413 data[options.raid.rows].threat = userThreat;
414 end
415  
416 -- ignore rows that won't be drawn from here on
417 table.setn(data, options.raid.rows);
418 end
419  
420 -- calculate % threat
421 for x = 1, table.getn(data) do
422 if (threat100 == 0) then
423 data[x].pc = 0;
424 else
425 data[x].pc = math.floor(data[x].threat / threat100 * 100);
426 end
427 end
428  
429 -- bar reference width (max threat)
430 local barRef;
431 if ((data[1] ~= nil) and (data[1].threat ~= 0)) then
432 barRef = sizes.raid.x / data[1].threat;
433 end
434  
435 -- render the rows
436 for row = 1, table.getn(data) do
437 for index, value in data[row] do
438 if (options.raid.abbreviate) then
439 gui.raid.rows[row][index].text:SetText(KLHTM_Abbreviate(value));
440 else
441 gui.raid.rows[row][index].text:SetText(value);
442 end
443 end
444 -- bars
445 if ((barRef == nil) or (data[row].threat == 0)) then
446 gui.raid.rows[row].bar:Hide();
447 else
448 local colours = KLHTM_GetClassColours(data[row].name);
449 gui.raid.rows[row].bar:SetWidth(data[row].threat * barRef);
450 gui.raid.rows[row].bar:SetVertexColor(colours.r, colours.g, colours.b);
451 gui.raid.rows[row].bar:Show();
452 end
453 gui.raid.rows[row].frame:Show();
454 end
455  
456 -- bottom bar
457 if (options.raid.hideBottomBar ~= true) then
458 KLHTM_DrawRaidBottom(data, threat100, playerCount, userThreat);
459 end
460  
461 -- hide empty rows
462 for row = table.getn(data) + 1, Max_Rows do
463 gui.raid.rows[row].frame:Hide();
464 end
465  
466 -- resize frame
467 if (options.raid.resize) then
468 sizes.raid.y = heights.header + heights.data * table.getn(data);
469 else
470 sizes.raid.y = heights.header + heights.data * options.raid.rows;
471 end
472  
473 if (options.raid.hideBottomBar ~= true) then
474 sizes.raid.y = sizes.raid.y + heights.data + 2;
475 end
476  
477 -- 14: (5 + 1) * 2 for the insets plus a gap.
478 -- Then 2 each for the title-header, header-data and (optional) data-bottom gaps.
479 sizes.frame.y = sizes.raid.y + sizes.title.y + 14;
480 gui.frame:SetHeight(sizes.frame.y);
481 end
482  
483  
484 -- used to unlocalise class names
485 local _classes = {"warrior", "druid", "priest", "shaman", "mage", "warlock", "rogue", "hunter", "paladin"}
486  
487 ------------------------------------------------------------------------------
488 -- Returns the class colours of the specified player
489 --
490 -- [return]: A table with .r, .g, .b values from 0 to 1.
491 ------------------------------------------------------------------------------
492 function KLHTM_GetClassColours(playerName)
493  
494 local className;
495  
496 -- apply pre-defined colours
497 if (playerName == UnitName("player")) then
498 return {["r"] = 1.0, ["g"] = 0, ["b"] = 0};
499 end
500  
501 if (playerName == mod.string.get("misc", "aggrogain")) then
502 return {["r"] = 0, ["g"] = 0, ["b"] = 1.0};
503 end
504  
505 className = mod.table.raidclasses[playerName];
506  
507 if (className == nil) then
508 -- the player's class isnt stored in our table, rebuild it.
509 if mod.out.checktrace("info", me, "raidcolours") then
510 mod.out.printtrace(string.format("Updating class entry for %s.", playerName));
511 end
512  
513 mod.table.redoraidclasses();
514 className = mod.table.raidclasses[playerName];
515 end
516  
517 if (className == nil) then
518 -- class name could not be found. Seems to be due to people who have left
519 -- the raid group?
520 if mod.out.checktrace("warning", me, "raidcolours") then
521 mod.out.printtrace(string.format("Updating class entry for %s.", playerName))
522 end
523  
524 mod.table.raidclasses[playerName] = "";
525 className = "";
526 end
527  
528 className = string.upper(className)
529  
530 if (className == "") then
531 return {["r"] = 0.5, ["g"] = 0.5, ["b"] = 0.5};
532 else
533 return RAID_CLASS_COLORS[className];
534 end
535 end
536  
537  
538 ------------------------------------------------------------------------------
539 -- Called when the user mouses over a raid string
540 ------------------------------------------------------------------------------
541 function KLHTM_RaidString_OnEnter(name)
542  
543 if (name == "targ") then
544 if (mod.boss.mastertarget ~= nil) then
545  
546 local text = string.format(mod.string.get("gui", "raid", "stringlong", name),
547 mod.boss.mastertarget);
548  
549 text = string.format("|cffffc900%s\n|r%s",
550 mod.string.get("gui", "raid", "stringshort", name), text);
551  
552 GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT", -100, 0);
553 GameTooltip:SetText(text, 1.0, 1.0, 1.0, 1, 1);
554 GameTooltip:Show();
555 gui.raid.bottom[name].text:SetTextColor(1.0, 0.82, 0);
556 end
557 end
558  
559 -- threat defecit text disabled for the moment
560 end
561  
562 function KLHTM_RaidString_OnLeave(name)
563 gui.raid.bottom[name].text:SetTextColor(1.0, 1.0, 1.0);
564 GameTooltip:Hide();
565 end