vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Titan Plugin For DamageMeters 4.1.3
3 Author: SeraphTC, with additions by Dandelion
4  
5 Code Changes By Dandelion (15/05/2006)
6  
7 TitanDamageMeters.Lua Changes:
8 Changed the way Titan is detected to avoid falsely detecting it when Bhaldie Infobar is loaded.
9  
10 Code Change By SeraphTC (28/01/2006)
11  
12 TitanDamageMeters.Lua Changes:
13 Moved the call for TitanPanelButton_OnLoad(); inside the 'if damagemeters loaded' statement to prevent errors when titan panel was not loaded.
14 Changed the titan menu category from a non-existant TMSP variable (oops! missed that last time!) to 'Information' where it belongs.
15 Improved the feedback from IsDMLoaded() and prevent it being called twice (no need to call it from the right-side button when it will have already
16 been called from the left-side button).
17 Removed TITAN_DAMAGEMETERS_TPLOADED as we dont use it!
18 Renamed TITAN_DAMAGEMETERS_LOADED to TITAN_AND_DAMAGEMETERS_LOADED as it contains the status of both titan and damagemeters
19 Moved the 'Glue' functions to the end of the file above the 'Utility' functions to help keep things tidy :)
20 (makes sense to have the dedicated plugin code all together and called functions together at the end).
21  
22 Code Tidied By SeraphTC (23/01/2006)
23  
24 TitanDamageMeters.Lua Changes:
25 Added TITAN_DAMAGEMETERS_TPLOADED variable to check for loaded status of Titan Panel
26 Changed value of TITAN_DAMAGEMETERSRIGHT_MENU_TEXT from "Damage Meters" to "Damage Meters (Right)"
27 Removed the TITAN_DAMAGEMETERS_VERSION variable and use DamageMeters_VERSIONSTRING instead (no point in duplicating values)
28 Removed LeftTag and RightTag variables as completely unused.
29 Removed Add/Ignore a Prefix on the menu/tooltip text depending on the availability of catagories,
30 as we dont check for this here!
31 Renamed GetStatus() function to IsDMLoaded() to prevent possible conflicts with TMSP
32 Removed IsAddonLoaded line from IsDMLoaded() as we dont use it!
33 Removed Titan existance checking from onload statement and incorporated it with IsDMLoaded(). This way we have one function
34 that handles both checks, will print error messages to the chat pane and will return 1 of 4 values for
35 future internal debugging.
36 (GetAddonInfo provides a more reliable result with its "enabled" value)
37 Removed the old refs to TitanPanelDamageMetersButton_xxxx function calls - may as well use the internal DamageMeters functions
38 and save duplication!
39 Added tests to see if damage meters and titan are loaded to most functions before any code is called - this should prevent WoW from returning
40 nil value errors if either mod is not loaded.
41 Added a TitanDMPrintD() - a stripped out version of DMPrintD from damagemeters, so that we can easily print to the chatchannel if damagemeters
42 is not running. (This will only be called from IsDMLoaded() but is a very quick way to prevent errors).
43 (Dand) Added checks before calling TitanPanel base functions in two places that check that Titan is loaded.
44 TitanDamageMeters.xml Changes:
45 Removed reference to TitanDamageMetersFunctions.lua as we dont use it.
46  
47 File Structure Changes:
48 Removed TitanDamageMetersFunctions.lua as not used.
49  
50  
51  
52 ]]--
53  
54 -- Set Labels and ID
55 TITAN_DAMAGEMETERS_ID = "DamageMeters";
56 TITAN_DAMAGEMETERSRIGHT_ID = "DamageMetersRight";
57 TITAN_DAMAGEMETERS_MENU_TEXT = "Damage Meters";
58 TITAN_DAMAGEMETERSRIGHT_MENU_TEXT = "Damage Meters (Right)";
59 TITAN_DAMAGEMETERS_BUTTON_LABEL = "Damage Meters";
60 TITAN_DAMAGEMETERS_TOOLTIP = "Show Damage Meters";
61 TITAN_DAMAGEMETERS_ICONPATH = "Interface\\Addons\\DamageMeters\\Artwork\\TitanDamageMeters"
62 TITAN_AND_DAMAGEMETERS_LOADED = nil;
63  
64 -- OnLoad Statement
65  
66 function TitanPanelDamageMetersButton_OnLoad()
67  
68 TITAN_AND_DAMAGEMETERS_LOADED = IsDMLoaded();
69 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then -- Only continue if DamageMeters AND Titan Panel are loaded
70 this.registry = {
71 id = TITAN_DAMAGEMETERS_ID,
72 category = "Information",
73 version = DamageMeters_VERSIONSTRING,
74 menuText = TITAN_DAMAGEMETERS_MENU_TEXT,
75 buttonTextFunction = "TitanPanelDamageMetersButton_GetButtonText",
76 tooltipTitle = TITAN_DAMAGEMETERS_TOOLTIP,
77 tooltipTextFunction = "TitanPanelDamageMetersButton_GetTooltipText",
78 icon = TITAN_DAMAGEMETERS_ICONPATH,
79 iconWidth = 16,
80 frequency = 1, -- PC: Added.
81 savedVariables = {
82 ShowIcon = 1,
83 ShowLabelText = 1,
84 shownRanks = {},
85 shownLeaders = {},
86 shownValues = {}
87 }
88 };
89  
90 TitanPanelButton_OnLoad(); -- Dand: added. TitanPanelButton_OnLoad not defined if Titan not loaded.
91 -- SeraphTC - moved this here instead of in its own 'If' statement - no point in doing 2x checks for the same thing in one function ;)
92 end
93 end
94  
95 -- OnLoad Statement For Right Side Icon
96 -- No ButtonTextFunction is required here, as Right Side menu's use the Icon Template and have no button text
97  
98 function TitanPanelDamageMetersRightButton_OnLoad()
99  
100 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
101 this.registry = {
102 id = TITAN_DAMAGEMETERSRIGHT_ID,
103 category = "Information",
104 version = DamageMeters_VERSIONSTRING,
105 menuText = TITAN_DAMAGEMETERSRIGHT_MENU_TEXT,
106 tooltipTitle = TITAN_DAMAGEMETERS_TOOLTIP,
107 tooltipTextFunction = "TitanPanelDamageMetersButton_GetTooltipText",
108 icon = TITAN_DAMAGEMETERS_ICONPATH,
109 iconWidth = 16,
110 savedVariables = {
111 ShowIcon = 1,
112 }
113 };
114  
115 TitanPanelButton_OnLoad(); -- Dand: added. TitanPanelButton_OnLoad not defined if Titan not loaded.
116 -- SeraphTC - moved this here instead of in its own 'If' statement - no point in doing 2x checks for the same thing in one function ;)
117 end
118 end
119  
120  
121 -- Update Button OnEvent
122  
123 function TitanPanelDamageMetersButton_OnEvent()
124 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
125 TitanPanelButton_UpdateButton(TITAN_DAMAGEMETERS_ID);
126 end
127 end
128  
129 function TitanPanelDamageMetersButton_OnClick(button)
130 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
131 if (button == "LeftButton") then
132 DamageMeters_ToggleShow();
133 end
134 end
135 end
136  
137 -- Get Button Text
138  
139 function TitanPanelDamageMetersButton_GetButtonText(id)
140 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
141 local button, id = TitanUtils_GetButton(id, true);
142 local retstr = "";
143  
144 -- supports turning off labels
145 if (TitanGetVar(TITAN_DAMAGEMETERS_ID, "ShowLabelText")) then
146 retstr = "";
147  
148 local quant;
149  
150 -- Values.
151 local shownValues = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownValues");
152 for quant = 1, DamageMeters_Quantity_MAX do
153 if (shownValues[quant]) then
154 --local quantColorCode = DamageMeters_quantityColorCodeDefault[quant];
155 local quantColorCode = "|cFFFFD040";
156 retstr = string.format("%s "..quantColorCode.."%s=|cFFFFFFFF%s"..FONT_COLOR_CODE_CLOSE, retstr, DM_QUANTDEFS[quant].titanAbbrev, TitanPanelDamageMeters_GetValue(quant));
157 end
158 end
159  
160 -- Ranks.
161 local playerRanks = DamageMeters_rankTables[DMT_ACTIVE][UnitName("Player")];
162 if (nil ~= playerRanks and table.getn(playerRanks) > 0) then
163 local shownRanks = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownRanks");
164 for quant = 1, DamageMeters_Quantity_MAX do
165 if (shownRanks[quant]) then
166 local rank = playerRanks[quant];
167 if (nil == rank) then
168 rank = "-";
169 else
170 rank = tostring(rank);
171 end
172 --Dand: These colors don't all look good: using the regular text color instead.
173 --local quantColorCode = DamageMeters_quantityColorCodeDefault[quant];
174 local quantColorCode = "|cFFFFD040";
175 retstr = string.format("%s "..quantColorCode.."%s#=|cFFFFFFFF%s"..FONT_COLOR_CODE_CLOSE, retstr, DM_QUANTDEFS[quant].titanAbbrev, rank);
176 end
177 end
178 end
179  
180 -- Leaders.
181 local shownLeaders = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownLeaders");
182 for quant = 1, DamageMeters_Quantity_MAX do
183 if (shownLeaders[quant]) then
184 --local quantColorCode = DamageMeters_quantityColorCodeDefault[quant];
185 local quantColorCode = "|cFFFFD040";
186 retstr = string.format("%s "..quantColorCode.."%sL=|cFFFFFFFF%s"..FONT_COLOR_CODE_CLOSE, retstr, DM_QUANTDEFS[quant].titanAbbrev, TitanPanelDamageMeters_GetLeaderName(quant));
187 end
188 end
189  
190 if (retstr == "") then
191 retstr = TITAN_DAMAGEMETERS_BUTTON_LABEL;
192 end
193 end
194  
195 return retstr
196 end
197 end
198  
199  
200 -- Get Tooltip Text
201 -- NB: You can use XML to format the text in the str, eg:
202 -- \n = New Line
203 -- \t = Tab space
204 -- Others may work but I have not tested them yet.
205  
206 function TitanPanelDamageMetersButton_GetTooltipText()
207 return "Toggle Frame\tLeft-Click"
208 end
209  
210 -- Setup Right Click Menu
211  
212 function TitanPanelRightClickMenu_PrepareDamageMetersMenu()
213 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
214 if ( UIDROPDOWNMENU_MENU_LEVEL == 2 ) then
215 if (UIDROPDOWNMENU_MENU_VALUE == "Values") then
216 local quant;
217 for quant = 1, DamageMeters_Quantity_MAX do
218 info = {};
219 info.text = DamageMeters_GetQuantityString(quant, true);
220 info.value = quant;
221 info.func = TitanPanelDamageMeters_SetValueOption;
222 info.checked = TitanPanelDamageMeters_IsValueShown(quant);
223 info.keepShownOnClick = 1;
224 UIDropDownMenu_AddButton(info,UIDROPDOWNMENU_MENU_LEVEL);
225 end
226 end
227  
228 if (UIDROPDOWNMENU_MENU_VALUE == "Ranks") then
229 local quant;
230 for quant = 1, DamageMeters_Quantity_MAX do
231 info = {};
232 info.text = DamageMeters_GetQuantityString(quant, true);
233 info.value = quant;
234 info.func = TitanPanelDamageMeters_SetRankOption;
235 info.checked = TitanPanelDamageMeters_IsRankShown(quant);
236 info.keepShownOnClick = 1;
237 UIDropDownMenu_AddButton(info,UIDROPDOWNMENU_MENU_LEVEL);
238 end
239 end
240  
241 if (UIDROPDOWNMENU_MENU_VALUE == "Leaders") then
242 local quant;
243 for quant = 1, DamageMeters_Quantity_MAX do
244 info = {};
245 info.text = DamageMeters_GetQuantityString(quant, true);
246 info.value = quant;
247 info.func = TitanPanelDamageMeters_SetLeaderOption;
248 info.checked = TitanPanelDamageMeters_IsLeaderShown(quant);
249 info.keepShownOnClick = 1;
250 UIDropDownMenu_AddButton(info,UIDROPDOWNMENU_MENU_LEVEL);
251 end
252 end
253 else
254 -- Menu title
255 TitanPanelRightClickMenu_AddTitle(TITAN_DAMAGEMETERS_MENU_TEXT);
256 TitanPanelRightClickMenu_AddCommand("Reset Window Position",TITAN_DAMAGEMETERS_ID, "DamageMeters_ResetPos");
257 TitanPanelRightClickMenu_AddCommand("Clear List",TITAN_DAMAGEMETERS_ID, "DamageMeters_Clear");
258  
259 -- A blank line in the menu
260 TitanPanelRightClickMenu_AddSpacer();
261  
262 -- Generic function to toggle icon
263 TitanPanelRightClickMenu_AddToggleIcon(TITAN_DAMAGEMETERS_ID);
264 -- Generic function to toggle label text
265 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_DAMAGEMETERS_ID);
266  
267 -- A blank line in the menu
268 TitanPanelRightClickMenu_AddSpacer();
269  
270 -- Value menu
271 info = {};
272 info.text = "Values";
273 info.hasArrow = 1;
274 UIDropDownMenu_AddButton(info);
275  
276 -- Rank menu
277 info = {};
278 info.text = "Ranks";
279 info.hasArrow = 1;
280 UIDropDownMenu_AddButton(info);
281  
282 -- Leaders menu
283 info = {};
284 info.text = "Leaders";
285 info.hasArrow = 1;
286 UIDropDownMenu_AddButton(info);
287  
288 -- A blank line in the menu
289 TitanPanelRightClickMenu_AddSpacer();
290  
291 -- Generic function to hide the plugin
292 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_DAMAGEMETERS_ID, TITAN_PANEL_MENU_FUNC_HIDE);
293 end
294 end
295 end
296  
297 -- Setup Right Click Menu For Right Side Button
298  
299 function TitanPanelRightClickMenu_PrepareDamageMetersRightMenu()
300 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
301 TitanPanelRightClickMenu_AddTitle(TITAN_DAMAGEMETERSRIGHT_MENU_TEXT);
302  
303 TitanPanelRightClickMenu_AddCommand("Reset Window Position",TITAN_DAMAGEMETERS_ID, "DamageMeters_ResetPos");
304 TitanPanelRightClickMenu_AddCommand("Clear List",TITAN_DAMAGEMETERS_ID, "DamageMeters_Clear");
305  
306 -- Generic function to hide the plugin
307 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_DAMAGEMETERSRIGHT_ID, TITAN_PANEL_MENU_FUNC_HIDE);
308 end
309 end
310  
311  
312 -- Glue
313  
314 function TitanDMPrintD(msg)
315 DEFAULT_CHAT_FRAME:AddMessage(msg,0.50,0.50,1.00);
316 end
317  
318 function IsDMLoaded() -- Renamed from GetStatus() to prevent possible conflicts with Titan Mod Support Project Core Functions
319  
320 local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo("DamageMeters")
321 local _, _, _, titanEnabled, _, _, _ = GetAddOnInfo("Titan")
322  
323 -- Dand: Some mod called Bhaldie Infobar actually defines this function. :|
324 -- Seems generally better to use the GetAddOnInfo function anyway.
325 --if not TitanPanelButton_UpdateButton then -- If Titan is not running
326 if not titanEnabled then -- If Titan is not running
327 if not (enabled == 1) then -- If DamageMeters is not running
328 TitanDMPrintD("DamageMeters: DamageMeters Not Loaded."); -- Print in the chat channel
329 TitanDMPrintD("DamageMeters: Titan Not Loaded."); -- for both mods
330 return 0; -- Return 0
331 else
332 TitanDMPrintD("DamageMeters: Titan Not Loaded."); -- Otherwise just let us know that Titan is not running
333 TitanDMPrintD("DamageMeters: Titan Plugin Not Available"); -- the plugin will not be available
334 TitanDMPrintD("DamageMeters: DamageMeters Loaded OK."); -- but that DamageMeters loaded ok,
335 return 1; -- and return 1
336 end
337  
338 elseif (enabled == 1) then -- Otherwise Titan is running, so check DamageMeters
339 TitanDMPrintD("DamageMeters: Titan Loaded OK."); -- and if its running print in the chat channel
340 TitanDMPrintD("DamageMeters: Titan Plugin Available"); -- for the plugin
341 TitanDMPrintD("DamageMeters: DamageMeters Loaded OK."); -- and for both mods
342 return 2; -- return 2
343 else -- otherwise Titan is running but DamageMeters is not
344 TitanDMPrintD("DamageMeters: DamageMetersNot Loaded."); -- so let us know
345 return 3; -- and return 3
346 end
347 end
348  
349 -- Utility functions
350  
351 function TitanPanelDamageMeters_SetValueOption()
352 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
353 shownValues = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownValues");
354 if (shownValues) then
355 if (nil ~= shownValues[this.value]) then
356 shownValues[this.value] = not shownValues[this.value];
357 else
358 shownValues[this.value] = true;
359 end
360 end
361 end
362 end
363  
364 function TitanPanelDamageMeters_SetRankOption()
365 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
366 shownRanks = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownRanks");
367 if (shownRanks) then
368 if (nil ~= shownRanks[this.value]) then
369 shownRanks[this.value] = not shownRanks[this.value];
370 else
371 shownRanks[this.value] = true;
372 end
373 end
374 end
375 end
376  
377 function TitanPanelDamageMeters_SetLeaderOption()
378 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
379 shownLeaders = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownLeaders");
380 if (shownLeaders) then
381 if (nil ~= shownLeaders[this.value]) then
382 shownLeaders[this.value] = not shownLeaders[this.value];
383 else
384 shownLeaders[this.value] = true;
385 end
386 end
387 end
388 end
389  
390 function TitanPanelDamageMeters_IsValueShown(quant)
391 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
392 shownValues = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownValues");
393 if (shownValues) then
394 if (shownValues[quant]) then
395 return shownValues[quant];
396 end
397 end
398  
399 return false;
400 end
401 end
402  
403 function TitanPanelDamageMeters_IsRankShown(quant)
404 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
405 shownRanks = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownRanks");
406 if (shownRanks) then
407 if (shownRanks[quant]) then
408 return shownRanks[quant];
409 end
410 end
411  
412 return false;
413 end
414 end
415  
416 function TitanPanelDamageMeters_IsLeaderShown(quant)
417 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
418 shownLeaders = TitanGetVar(TITAN_DAMAGEMETERS_ID, "shownLeaders");
419 if (shownLeaders) then
420 if (shownLeaders[quant]) then
421 return shownLeaders[quant];
422 end
423 end
424  
425 return false;
426 end
427 end
428  
429 function TitanPanelDamageMeters_GetValue(quantity)
430 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
431 return DamageMeters_GetQuantityValueString(quantity, UnitName("Player"));
432 end
433 end
434  
435 function TitanPanelDamageMeters_GetLeaderName(quant)
436 if (TITAN_AND_DAMAGEMETERS_LOADED == 2) then
437 for player, struct in DamageMeters_rankTables[DMT_ACTIVE] do
438 if (struct[quant] == 1) then
439 return player;
440 end
441 end
442  
443 return "-";
444 end
445 end