vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 ****************************************************************
3 Scrolling Combat Text - Damage 2.0
4  
5 Author: Grayhoof
6 ****************************************************************
7  
8 Official Site:
9 http://grayhoof.wowinterface.com
10  
11 ****************************************************************]]
12 --embedded libs
13 local parser = ParserLib:GetInstance("1.1")
14  
15 --global name
16 SCTD = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceConsole-2.0", "AceHook-2.0");
17  
18 --Add new frame to SCT
19 SCT.FRAME3 = 3;
20 local arrAniData3 = {};
21 tinsert(SCT.ArrayAniData, arrAniData3);
22  
23 local MSG_Y_OFFSET = 0;
24 local arrMsgData = {
25 ["MSGTEXT1"] = {size=1, xoffset=0, yoffset=0, align="CENTER", height=5, duration=1},
26 }
27  
28 local default_config = {
29 ["SCTD_VERSION"] = SCTD.Version,
30 ["SCTD_ENABLED"] = 1,
31 ["SCTD_SHOWMELEE"] = 1,
32 ["SCTD_SHOWPERIODIC"] = 1,
33 ["SCTD_SHOWSPELL"] = 1,
34 ["SCTD_SHOWPET"] = 1,
35 ["SCTD_SHOWCOLORCRIT"] = false,
36 ["SCTD_FLAGDMG"] = false,
37 ["SCTD_SHOWDMGTYPE"] = false,
38 ["SCTD_SHOWSPELLNAME"] = 1,
39 ["SCTD_SHOWRESIST"] = 1,
40 ["SCTD_SHOWTARGETS"] = false,
41 ["SCTD_DMGFONT"] = 1,
42 ["SCTD_TARGET"] = false,
43 ["SCTD_PVPDMG"] = false,
44 ["SCTD_USESCT"] = 1,
45 ["SCTD_STICKYCRIT"] = 1,
46 ["SCTD_SPELLCOLOR"] = false
47 };
48  
49 local default_config_colors = {
50 ["SCTD_SHOWMELEE"] = {r = 1.0, g = 1.0, b = 1.0},
51 ["SCTD_SHOWPERIODIC"] = {r = 1.0, g =1.0, b = 0.0},
52 ["SCTD_SHOWSPELL"] = {r = 1.0, g = 1.0, b = 0.0},
53 ["SCTD_SHOWPET"] = {r = 0.6, g = 0.6, b = 0.0},
54 ["SCTD_SHOWCOLORCRIT"] = {r = 0.2, g = 0.4, b = 0.6}
55 }
56  
57 local default_frame_config = {
58 ["FONT"] = 1,
59 ["FONTSHADOW"] = 2,
60 ["ALPHA"] = 100,
61 ["ANITYPE"] = 1,
62 ["ANISIDETYPE"] = 1,
63 ["XOFFSET"] = 0,
64 ["YOFFSET"] = 210,
65 ["DIRECTION"] = false,
66 ["TEXTSIZE"] = 24,
67 ["FADE"] = 1.5
68 }
69  
70 local arrShadowOutline = {
71 [1] = "",
72 [2] = "OUTLINE",
73 [3] = "THICKOUTLINE"
74 }
75  
76 ----------------------
77 --Called on login
78 function SCTD:OnEnable()
79 --check SCT version
80 if (not SCT) or (tonumber(SCT.db.profile["VERSION"]) < 5) then
81 StaticPopupDialogs["SCTD_VERSION"] = {
82 text = SCTD.LOCALS.Version_Warning,
83 button1 = TEXT(OKAY) ,
84 timeout = 0,
85 whileDead = 1,
86 hideOnEscape = 1,
87 showAlert = 1
88 };
89 StaticPopup_Show("SCTD_VERSION");
90 if (SCTOptionsFrame_Misc103) then
91 SCTOptionsFrame_Misc103:Hide();
92 end
93 self:OnDisable();
94 return;
95 end
96 self:RegisterSelfEvents();
97 end
98  
99 ----------------------
100 -- Disable all events, not using AceDB, but may as well name it right.
101 function SCTD:OnDisable()
102 -- no more events to handle
103 parser:UnregisterAllEvents("sctd")
104 self:UnregisterAllEvents()
105 end
106  
107 ----------------------
108 --Called when addon loaded
109 function SCTD:OnInitialize()
110  
111 --slash commands
112 local main = {
113 type="group",
114 args = {
115 menu = {
116 name = "Menu", type = 'execute',
117 desc = "Display SCT Option Menu",
118 func = function()
119 self:ShowSCTDMenu();
120 end
121 },
122 }
123 }
124 local menu = {
125 type = 'execute',
126 desc = "Display SCTD Option Menu",
127 func = function()
128 self:ShowSCTDMenu();
129 end
130 }
131  
132 self:RegisterChatCommand({"/sctd"}, main);
133 self:RegisterChatCommand({"/sctdmenu"}, menu);
134  
135 --register with other mods
136 self:RegisterOtherMods();
137  
138 --Hook SCT show menu
139 self:Hook(SCT, "ShowMenu")
140  
141 --update old values
142 self:UpdateValues();
143  
144 --setup msgs
145 self:MsgInit();
146  
147 end
148  
149 ----------------------
150 -- Show the Option Menu
151 function SCTD:ShowSCTDMenu()
152 local loaded, message = LoadAddOn("sct_options");
153 if (loaded) then
154 --if options page exsists (not disabled)
155 if (SCTDOptions) then
156 PlaySound("igMainMenuOpen");
157 --Hook SCT ShowExample
158 if (not SCTD:IsHooked(SCT, "ShowExample")) then
159 SCTD:Hook(SCT, "ShowExample");
160 end
161 --show options
162 SCTDOptions:Show();
163 --update animation options
164 SCTD:UpdateAnimationOptions()
165 else
166 PlaySound("TellMessage");
167 SCTD:Print(SCTD.LOCALS.Load_Error);
168 end
169 else
170 PlaySound("TellMessage");
171 SCTD:Print(SCT.LOCALS.Load_Error.." "..message);
172 end;
173 end
174  
175 ----------------------
176 --Reset everything to default for SCTD
177 function SCTD:ShowMenu()
178 SCTD:UpdateValues();
179 --open sct menu
180 self.hooks[SCT].ShowMenu.orig();
181 --Hook SCT ShowExample
182 if (not self:IsHooked(SCT, "ShowExample") and SCT.ShowExample) then
183 self:Hook(SCT, "ShowExample");
184 end
185 --if window is showing, reload it
186 if (SCTDOptions) and (SCTDOptions:IsVisible()) then
187 SCTDOptions:Hide();
188 SCTDOptions:Show();
189 end
190 end
191  
192 ----------------------
193 -- display ddl or chxbox based on type
194 function SCTD:UpdateAnimationOptions()
195 --get scroll down checkbox
196 local chkbox = getglobal("SCTOptionsFrame_CheckButton113");
197 --get anime type dropdown
198 local ddl1 = getglobal("SCTOptionsFrame_Selection103");
199 --get animside type dropdown
200 local ddl2 = getglobal("SCTOptionsFrame_Selection104");
201 --get item
202 local id = UIDropDownMenu_GetSelectedID(ddl1)
203 if (id == 1 or id == 6) then
204 chkbox:Show();
205 ddl2:Hide();
206 else
207 chkbox:Hide();
208 ddl2:Show();
209 end
210 end
211  
212 ----------------------
213 --Hide the Option Menu
214 function SCTD:HideMenu()
215 PlaySound("igMainMenuClose");
216 SCTDOptions:Hide();
217 SCTD_EXAMPLEMSG:Hide();
218 end
219  
220 ---------------------
221 --Show SCT Example
222 function SCTD:ShowExample()
223 self.hooks[SCT].ShowExample.orig();
224 self:MsgInit()
225 self:SetDamageFlags();
226  
227 --animated example for options that may need it
228 local option = this.SCTVar or "SCTD_SHOWMELEE";
229 if (string.find(option,"SCTD_SHOW")) then
230 self:DisplayText(option, self.LOCALS.EXAMPLE);
231 end
232  
233 --show msg frame
234 SCTD_EXAMPLEMSG:Show();
235  
236 --show example FRAME3
237 --get object
238 example = getglobal("SCTDMsgExample1");
239 --set text size
240 SCT:SetFontSize(example,
241 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["FONT"],
242 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["TEXTSIZE"],
243 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["FONTSHADOW"]);
244 --set the color
245 example:SetTextColor(1, 1, 1);
246 --set alpha
247 example:SetAlpha(SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["ALPHA"]/100);
248 --Position
249 example:SetPoint("CENTER", "UIParent", "CENTER",
250 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["XOFFSET"],
251 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["YOFFSET"]);
252 --Set the text to display
253 example:SetText(self.LOCALS.EXAMPLE);
254  
255 --update animation options
256 self:UpdateAnimationOptions()
257 end
258  
259 ----------------------
260 --Update old values for new versions
261 function SCTD:UpdateValues()
262 local i, var;
263 --set defaults
264 for i in default_config do
265 if(SCT.db.profile[i] == nil) then
266 SCT.db.profile[i] = default_config[i];
267 end
268 end
269 --set colors
270 for i in default_config_colors do
271 var = SCT.db.profile[SCT.COLORS_TABLE][i] or default_config_colors[i];
272 SCT.db.profile[SCT.COLORS_TABLE][i] = var;
273 end
274 --set frame data
275 if (not SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]) then
276 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3] = {};
277 end
278 for i in default_frame_config do
279 if (SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3][i] == nil) then
280 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3][i] = default_frame_config[i];
281 end
282 end
283 end
284  
285 ----------------------
286 -- Event Handler
287 function SCTD:OnEvent()
288 --Player PvP status changed
289 SCTD:SetDamageFlags();
290 end
291  
292 ----------------------
293 --Determine if its a "melee" ranged evet
294 function SCTD:IsMeleeRanged(skill)
295 if (skill == ParserLib_MELEE or
296 skill == self.LOCALS.AUTO_SHOT or
297 --skill == self.LOCALS.SHOOT or
298 skill == self.LOCALS.SHOOT_BOW or
299 skill == self.LOCALS.SHOOT_CROSSBOW or
300 skill == self.LOCALS.SHOOT_GUN) then
301 return true;
302 else
303 return false;
304 end
305 end
306  
307 ----------------------
308 -- Parses all combat events using paserlib
309 function SCTD:ParseCombat(info)
310 --self doesn't work here because of the call from ParserLib
311 local self = SCTD;
312  
313 --exit if not enabled
314 if (not SCT.db.profile["SCTD_ENABLED"]) then
315 return;
316 end
317  
318 --Hits (melee, spell, etc..)
319 if (info.type == "hit") then
320 if (info.source == ParserLib_SELF) then
321 if (self:IsMeleeRanged(info.skill)) then
322 self:DisplayText("SCTD_SHOWMELEE", info.amount, info.isCrit, nil, nil, info.victim);
323 else
324 if (info.isDOT) then
325 self:DisplayText("SCTD_SHOWPERIODIC", info.amount, nil, info.element, info.amountResist, info.victim, info.skill);
326 else
327 self:DisplayText("SCTD_SHOWSPELL", info.amount, info.isCrit, info.element, info.amountResist, info.victim, info.skill);
328 end
329 end
330 elseif (SCT:GetTargetUnit(info.source) == "pet") then
331 if (info.skill == ParserLib_MELEE) then
332 self:DisplayText("SCTD_SHOWPET", info.amount, info.isCrit, info.element, info.amountResist, info.victim, PET);
333 else
334 self:DisplayText("SCTD_SHOWPET", info.amount, info.isCrit, info.element, info.amountResist, info.victim, info.skill);
335 end
336 end
337  
338 --Miss Events
339 elseif (info.type == "miss") then
340 local source;
341 --if its self, player, else see if its pet
342 if (info.source == ParserLib_SELF) then
343 source = "player";
344 else
345 source = SCT:GetTargetUnit(info.source);
346 end;
347 --remove skill if melee or ranged non-skill
348 if (self:IsMeleeRanged(info.skill)) then
349 info.skill = nil;
350 end
351 --if pet or player
352 if (source == "player") or (source == "pet")then
353 local type = "SCTD_SHOWMELEE";
354 if (info.skill) then
355 type="SCTD_SHOWSPELL";
356 end
357 if (source == "pet") then
358 type="SCTD_SHOWPET";
359 end
360 if (info.missType == "miss") then
361 self:DisplayText(type, MISS, nil, nil, nil, info.victim, info.skill);
362 elseif (info.missType == "dodge") then
363 self:DisplayText(type, DODGE, nil, nil, nil, info.victim, info.skill);
364 elseif (info.missType == "block") then
365 self:DisplayText(type, BLOCK, nil, nil, nil, info.victim, info.skill);
366 elseif (info.missType == "deflect") then
367 self:DisplayText(type, DEFLECT, nil, nil, nil, info.victim, info.skill);
368 elseif (info.missType == "immune") then
369 self:DisplayText(type, IMMUNE, nil, nil, nil, info.victim, info.skill);
370 elseif (info.missType == "evade") then
371 self:DisplayText(type, EVADE, nil, nil, nil, info.victim, info.skill);
372 elseif (info.missType == "parry") then
373 self:DisplayText(type, PARRY, nil, nil, nil, info.victim, info.skill);
374 elseif (info.missType == "resist") then
375 self:DisplayText(type, RESIST, nil, nil, nil, info.victim, info.skill);
376 elseif (info.missType == "reflect") then
377 self:DisplayText(type, REFLECT, nil, nil, nil, info.victim, info.skill);
378 elseif (info.missType == "absorb") then
379 self:DisplayText(type, ABSORB, nil, nil, nil, info.victim, info.skill);
380 end
381 end
382 end
383 end
384  
385  
386 ----------------------
387 --Display for mainly combat events
388 --Mainly used for short messages
389 function SCTD:DisplayText(option, msg1, crit, damagetype, resisted, target, spell)
390 local rbgcolor, showcrit, showmsg, adat;
391 --if option is on
392 if (SCT.db.profile[option]) then
393 --if show only target
394 if (SCT.db.profile["SCTD_TARGET"]) then
395 if (target ~= UnitName("target")) then
396 return;
397 end
398 end
399 --get options
400 rbgcolor = SCT.db.profile[SCT.COLORS_TABLE][option];
401 --if damage type
402 if ((damagetype) and (SCT.db.profile["SCTD_SHOWDMGTYPE"])) then
403 msg1 = msg1.." "..damagetype.."";
404 end
405 --if spell color
406 if ((damagetype) and (SCT.db.profile["SCTD_SPELLCOLOR"])) then
407 rbgcolor = SCT.SpellColors[damagetype] or rbgcolor;
408 end
409 --if resisted
410 if ((resisted) and (SCT.db.profile["SCTD_SHOWRESIST"])) then
411 msg1 = msg1.." {"..resisted.."}";
412 end
413 --if target label
414 if ((target) and (SCT.db.profile["SCTD_SHOWTARGETS"])) then
415 msg1 = target..": "..msg1;
416 end
417 --if spell
418 if ((spell) and (SCT.db.profile["SCTD_SHOWSPELLNAME"])) then
419 msg1 = msg1.." ("..spell..")";
420 end
421 --if flag
422 if (SCT.db.profile["SCTD_FLAGDMG"]) then
423 msg1 = self.LOCALS.SelfFlag..msg1..self.LOCALS.SelfFlag;
424 end
425 --if crit
426 if (crit) then
427 if (SCT.db.profile["SCTD_SHOWCOLORCRIT"]) then
428 rbgcolor = SCT.db.profile[SCT.COLORS_TABLE]["SCTD_SHOWCOLORCRIT"];
429 end
430 self:Display_Crit_Damage( msg1, rbgcolor );
431 else
432 self:Display_Damage( msg1, rbgcolor );
433 end
434  
435 end
436 end
437  
438  
439 ----------------------
440 --Displays a message at the top of the screen
441 function SCTD:Display_Damage(msg, color)
442 if (SCT.db.profile["SCTD_USESCT"]) then
443 SCT:DisplayText(msg, color, nil, "damage", SCT.FRAME3);
444 else
445 SCTD_MSGTEXT1:SetPoint("CENTER", "UIParent", "CENTER",
446 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["XOFFSET"],
447 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["YOFFSET"] + MSG_Y_OFFSET);
448 SCTD_MSGTEXT1:SetTimeVisible(SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["FADE"]);
449 SCTD_MSGTEXT1:AddMessage(msg, color.r, color.g, color.b, 1);
450 end
451 end
452  
453 ----------------------
454 --Displays a message at the top of the screen
455 function SCTD:Display_Crit_Damage(msg, color)
456 if (SCT.db.profile["SCTD_STICKYCRIT"]) then
457 SCT:DisplayText(msg, color, 1, "damage", SCT.FRAME3);
458 elseif (SCT.db.profile["SCTD_USESCT"]) then
459 SCT:DisplayText("+"..msg.."+", color, nil, "damage", SCT.FRAME3);
460 else
461 SCTD_MSGTEXT1:SetPoint("CENTER", "UIParent", "CENTER",
462 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["XOFFSET"],
463 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["YOFFSET"] + MSG_Y_OFFSET);
464 SCTD_MSGTEXT1:SetTimeVisible(SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["FADE"] or 1.5);
465 SCTD_MSGTEXT1:AddMessage("+"..msg.."+", color.r, color.g, color.b, 1);
466 end
467 end
468  
469 ------------------------
470 --Setup msg arrays
471 function SCTD:MsgInit()
472 for key, value in arrMsgData do
473 value.FObject = getglobal("SCTD_"..key);
474 self:SetMsgFont(value.FObject);
475 end
476 self:SetDamageFlags()
477 end
478  
479 ------------------------
480 --Setup Damage Flags based on Options
481 function SCTD:SetDamageFlags()
482 --set WoW Damage Flags
483 if (SCT.db.profile["SCTD_DMGFONT"]) then
484 SetCVar("CombatDamage", 0);
485 self:SetPvPDamageFlags();
486 else
487 SetCVar("CombatDamage", 1);
488 end
489 end
490  
491 ------------------------
492 --Setup Damage Flags based on Options and PvP status
493 function SCTD:SetPvPDamageFlags()
494 --set WoW Damage Flags
495 if (SCT.db.profile["SCTD_PVPDMG"]) then
496 if (UnitIsPVP("player")) then
497 SetCVar("CombatDamage", 1);
498 SCT.db.profile["SCTD_ENABLED"] = false;
499 else
500 SetCVar("CombatDamage", 0);
501 SCT.db.profile["SCTD_ENABLED"] = 1;
502 end
503 end
504 end
505  
506 -------------------------
507 --Set the font of an object using msg vars
508 function SCTD:SetMsgFont(object)
509 --set font
510 object:SetFont(SCT.LOCALS.FONTS[SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["FONT"]].path,
511 SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["TEXTSIZE"],
512 arrShadowOutline[SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["FONTSHADOW"]]);
513 --reset size of allow 5 messages
514 object:SetHeight(SCT.db.profile[SCT.FRAMES_DATA_TABLE][SCT.FRAME3]["TEXTSIZE"] * 6)
515 --Set Fade Duration
516 object:SetFadeDuration(1);
517 --set offset to center
518 MSG_Y_OFFSET = object:GetHeight()/2;
519 end
520  
521 ----------------------
522 --Register All Events
523 function SCTD:RegisterSelfEvents()
524 --core events
525 self:RegisterEvent("UNIT_FACTION", "OnEvent");
526 self:RegisterEvent("PLAYER_ENTERING_WORLD", "OnEvent");
527  
528 --core chat events for Parserlib
529 parser:RegisterEvent("sctd", "CHAT_MSG_COMBAT_SELF_HITS", SCTD.ParseCombat) ;
530 parser:RegisterEvent("sctd", "CHAT_MSG_COMBAT_SELF_MISSES", SCTD.ParseCombat) ;
531 parser:RegisterEvent("sctd", "CHAT_MSG_SPELL_SELF_DAMAGE", SCTD.ParseCombat) ;
532 parser:RegisterEvent("sctd", "CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE", SCTD.ParseCombat) ;
533 parser:RegisterEvent("sctd", "CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_DAMAGE", SCTD.ParseCombat) ;
534 parser:RegisterEvent("sctd", "CHAT_MSG_COMBAT_PET_HITS", SCTD.ParseCombat) ;
535 parser:RegisterEvent("sctd", "CHAT_MSG_COMBAT_PET_MISSES", SCTD.ParseCombat) ;
536 parser:RegisterEvent("sctd", "CHAT_MSG_SPELL_PET_DAMAGE", SCTD.ParseCombat) ;
537 end
538  
539 -------------------------
540 --Regsiter SCTD with other mods
541 function SCTD:RegisterOtherMods()
542 -- myAddOns support
543 if(myAddOnsFrame_Register) then
544 local SCTDDetails = {
545 name = "sctd",
546 version = SCTD.Version,
547 optionsframe = "SCTDOptions",
548 category = MYADDONS_CATEGORY_COMBAT
549 };
550 myAddOnsFrame_Register(SCTDDetails);
551 end
552  
553 --Cosmos support
554 if ( EarthFeature_AddButton ) then
555 EarthFeature_AddButton(
556 {
557 id="SCT";
558 name=self.LOCALS.CB_NAME;
559 text=self.LOCALS.CB_NAME;
560 subtext=self.LOCALS.CB_SHORT_DESC;
561 helptext=self.LOCALS.CB_LONG_DESC;
562 icon=self.LOCALS.CB_ICON;
563 callback=SCTD.ShowSCTDMenu;
564 }
565 );
566 elseif (Cosmos_RegisterButton) then
567 Cosmos_RegisterButton (
568 self.LOCALS.CB_NAME,
569 self.LOCALS.CB_SHORT_DESC,
570 self.LOCALS.CB_LONG_DESC,
571 self.LOCALS.CB_ICON,
572 SCTD.ShowSCTDMenu,
573 function()
574 return true;
575 end
576 );
577 default_config.ENABLED = 0;
578 end
579  
580 -- Add to CTMod Control panel if available
581 if ( CT_RegisterMod ) then
582 CT_RegisterMod(self.LOCALS.CB_NAME, nil, 5, self.LOCALS.CB_ICON, self.LOCALS.CB_LONG_DESC, "switch", nil, SCTD.ShowSCTDMenu);
583 end
584 end