vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local compost = AceLibrary("Compost-2.0") |
2 | local parser = ParserLib:GetInstance("1.1") |
||
3 | local roster = AceLibrary("RosterLib-2.0") |
||
4 | |||
5 | -- Link these after all files are loaded. |
||
6 | local defaultFormats |
||
7 | local defaultColors |
||
8 | local L |
||
9 | |||
10 | ------------------------ |
||
11 | -- Core -- |
||
12 | ------------------------ |
||
13 | |||
14 | SimpleCombatLog = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDebug-2.0") |
||
15 | |||
16 | -- Return a deep copy of the table. |
||
17 | function SimpleCombatLog.CopyTable(into, from) |
||
18 | for key, val in pairs(from) do |
||
19 | if( type(val) == "table" ) then |
||
20 | if not into[key] then into[key] = {} end |
||
21 | SimpleCombatLog.CopyTable(into[key], val) |
||
22 | else |
||
23 | into[key] = val |
||
24 | end |
||
25 | end |
||
26 | return into |
||
27 | end |
||
28 | |||
29 | --- SimpleCombatLog.modulePrototype.core = SimpleCombatLog |
||
30 | |||
31 | -- Hook the FCF_Tab_OnClick() to check for alt-rightclick. |
||
32 | function SimpleCombatLog:FCF_Tab_OnClick(button) |
||
33 | if IsAltKeyDown() and button == 'RightButton' then |
||
34 | self:LoadSettingMenu(this:GetID()) |
||
35 | else |
||
36 | self.old_FCF_Tab_OnClick(button) |
||
37 | end |
||
38 | end |
||
39 | |||
40 | -- Hook ChatFrame_OnEvent to suppress the default combat log. |
||
41 | function SimpleCombatLog:ChatFrame_OnEvent(event) |
||
42 | local id = this:GetID() |
||
43 | |||
44 | -- Note to self: must do ( self.events[event] == nil ) here, cannot do ( not self.events[event] ), since some events can be 'false' by default. |
||
45 | if self.events[event] == nil or not id or not self.settings[id] or not self.settings[id].suppress then |
||
46 | self.old_ChatFrame_OnEvent(event) |
||
47 | end |
||
48 | end |
||
49 | |||
50 | |||
51 | |||
52 | -- Interested events, the flag are also used as the default theme event settings. (So false has a different meaning to nil here) |
||
53 | SimpleCombatLog.events = { |
||
54 | ['CHAT_MSG_COMBAT_PET_HITS'] = true, |
||
55 | ['CHAT_MSG_COMBAT_PET_MISSES'] = true, |
||
56 | ['CHAT_MSG_COMBAT_SELF_HITS'] = true, |
||
57 | ['CHAT_MSG_COMBAT_SELF_MISSES'] = true, |
||
58 | ['CHAT_MSG_COMBAT_CREATURE_VS_CREATURE_HITS'] = true, |
||
59 | ['CHAT_MSG_COMBAT_CREATURE_VS_CREATURE_MISSES'] = true, |
||
60 | ['CHAT_MSG_COMBAT_CREATURE_VS_PARTY_HITS'] = true, |
||
61 | ['CHAT_MSG_COMBAT_CREATURE_VS_PARTY_MISSES'] = true, |
||
62 | ['CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS'] = true, |
||
63 | ['CHAT_MSG_COMBAT_CREATURE_VS_SELF_MISSES'] = true, |
||
64 | ['CHAT_MSG_COMBAT_FRIENDLYPLAYER_HITS'] = true, |
||
65 | ['CHAT_MSG_COMBAT_FRIENDLYPLAYER_MISSES'] = true, |
||
66 | ['CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS'] = true, |
||
67 | ['CHAT_MSG_COMBAT_HOSTILEPLAYER_MISSES'] = true, |
||
68 | ['CHAT_MSG_COMBAT_PARTY_HITS'] = true, |
||
69 | ['CHAT_MSG_COMBAT_PARTY_MISSES'] = true, |
||
70 | ['CHAT_MSG_SPELL_PET_BUFF'] = true, |
||
71 | ['CHAT_MSG_SPELL_PET_DAMAGE'] = true, |
||
72 | ['CHAT_MSG_SPELL_SELF_BUFF'] = true, |
||
73 | ['CHAT_MSG_SPELL_SELF_DAMAGE'] = true, |
||
74 | ['CHAT_MSG_SPELL_CREATURE_VS_CREATURE_BUFF'] = true, |
||
75 | ['CHAT_MSG_SPELL_CREATURE_VS_CREATURE_DAMAGE'] = true, |
||
76 | ['CHAT_MSG_SPELL_CREATURE_VS_PARTY_BUFF'] = true, |
||
77 | ['CHAT_MSG_SPELL_CREATURE_VS_PARTY_DAMAGE'] = true, |
||
78 | ['CHAT_MSG_SPELL_CREATURE_VS_SELF_BUFF'] = true, |
||
79 | ['CHAT_MSG_SPELL_CREATURE_VS_SELF_DAMAGE'] = true, |
||
80 | ['CHAT_MSG_SPELL_FRIENDLYPLAYER_BUFF'] = true, |
||
81 | ['CHAT_MSG_SPELL_FRIENDLYPLAYER_DAMAGE'] = true, |
||
82 | ['CHAT_MSG_SPELL_HOSTILEPLAYER_BUFF'] = true, |
||
83 | ['CHAT_MSG_SPELL_HOSTILEPLAYER_DAMAGE'] = true, |
||
84 | ['CHAT_MSG_SPELL_PARTY_BUFF'] = true, |
||
85 | ['CHAT_MSG_SPELL_PARTY_DAMAGE'] = true, |
||
86 | ['CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS'] = true, |
||
87 | ['CHAT_MSG_SPELL_PERIODIC_SELF_DAMAGE'] = true, |
||
88 | ['CHAT_MSG_SPELL_DAMAGESHIELDS_ON_OTHERS'] = true, |
||
89 | ['CHAT_MSG_SPELL_DAMAGESHIELDS_ON_SELF'] = true, |
||
90 | ['CHAT_MSG_SPELL_PERIODIC_CREATURE_BUFFS'] = true, |
||
91 | ['CHAT_MSG_SPELL_PERIODIC_CREATURE_DAMAGE'] = true, |
||
92 | ['CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS'] = true, |
||
93 | ['CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_DAMAGE'] = true, |
||
94 | ['CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_BUFFS'] = true, |
||
95 | ['CHAT_MSG_SPELL_PERIODIC_HOSTILEPLAYER_DAMAGE'] = true, |
||
96 | ['CHAT_MSG_SPELL_PERIODIC_PARTY_BUFFS'] = true, |
||
97 | ['CHAT_MSG_SPELL_PERIODIC_PARTY_DAMAGE'] = true, |
||
98 | ['CHAT_MSG_SPELL_AURA_GONE_OTHER'] = true, |
||
99 | ['CHAT_MSG_SPELL_AURA_GONE_SELF'] = true, |
||
100 | ['CHAT_MSG_SPELL_AURA_GONE_PARTY'] = true, |
||
101 | ['CHAT_MSG_SPELL_BREAK_AURA'] = true, |
||
102 | ['CHAT_MSG_COMBAT_FRIENDLY_DEATH'] = true, |
||
103 | ['CHAT_MSG_COMBAT_HOSTILE_DEATH'] = true, |
||
104 | ['CHAT_MSG_SPELL_ITEM_ENCHANTMENTS'] = true, |
||
105 | ['CHAT_MSG_COMBAT_XP_GAIN'] = true, |
||
106 | ['CHAT_MSG_COMBAT_HONOR_GAIN'] = true, |
||
107 | ['CHAT_MSG_COMBAT_FACTION_CHANGE'] = true, |
||
108 | ['CHAT_MSG_SPELL_TRADESKILLS'] = true, |
||
109 | ['CHAT_MSG_SPELL_FAILED_LOCALPLAYER'] = false, |
||
110 | } |
||
111 | |||
112 | SimpleCombatLog.defaultColors = { |
||
113 | |||
114 | player = "7f7fff", |
||
115 | pet = "7f4c26", |
||
116 | raid = "ff7133", |
||
117 | party = "a5ffa5", |
||
118 | target = "ff77ff", |
||
119 | targettarget = "994c99", |
||
120 | other = "ffffff", |
||
121 | |||
122 | physical = "ffffff", |
||
123 | holy = "ffff4c", |
||
124 | fire = "ff262d", |
||
125 | nature = "66ff66", |
||
126 | frost = "4c4ce5", |
||
127 | shadow = "ffb2ff", |
||
128 | arcane = "bfbfbf", |
||
129 | |||
130 | heal = "ffff4c", |
||
131 | miss = "ff7f7f", |
||
132 | buff = "33ff33", |
||
133 | debuff = "ff3333", |
||
134 | skill = "ffff66", |
||
135 | |||
136 | dirty = "eda55f", |
||
137 | } |
||
138 | |||
139 | |||
140 | function SimpleCombatLog:OnInitialize() |
||
141 | |||
142 | defaultFormats = self.loc.defaultFormats |
||
143 | defaultColors = self.defaultColors |
||
144 | L = self.loc.core |
||
145 | |||
146 | -- nil out the localization table, so that unused part will be GC'ed out. |
||
147 | self.loc = nil |
||
148 | |||
149 | self.old_FCF_Tab_OnClick = FCF_Tab_OnClick |
||
150 | FCF_Tab_OnClick = function(button) self:FCF_Tab_OnClick(button) end |
||
151 | |||
152 | self.old_ChatFrame_OnEvent = ChatFrame_OnEvent |
||
153 | ChatFrame_OnEvent = function(event) self:ChatFrame_OnEvent(event) end |
||
154 | |||
155 | -- index to Blizzard chat frames. |
||
156 | self.chatFrames = { ChatFrame1, ChatFrame2, ChatFrame3, ChatFrame4, ChatFrame5, ChatFrame6, ChatFrame7 } |
||
157 | |||
158 | self:RegisterChatCommand( { "/scl" }, { |
||
159 | type = 'group', |
||
160 | args = { |
||
161 | help = { |
||
162 | type = 'execute', |
||
163 | name = 'help', |
||
164 | desc = L["CmdHelpDesc"], |
||
165 | func = "ShowHelp", |
||
166 | }, |
||
167 | reset = { |
||
168 | type = 'execute', |
||
169 | name = 'reset', |
||
170 | desc = L["CmdResetDesc"], |
||
171 | func = "LoadInitialSettings", |
||
172 | }, |
||
173 | show = { |
||
174 | type = 'text', |
||
175 | name = 'show', |
||
176 | desc = L["CmdShowDesc"], |
||
177 | get = false, |
||
178 | set = function(id) self:LoadSettingMenu(tonumber(id)) end, |
||
179 | -- input = true, -- dunno why, this isn't working. |
||
180 | validate = { '1', '2', '3', '4', '5', '6', '7' }, |
||
181 | usage = "<ChatFrame ID>", |
||
182 | } |
||
183 | } |
||
184 | } ) |
||
185 | |||
186 | |||
187 | self:InitGlobalDB() |
||
188 | self:LoadThemes() |
||
189 | |||
190 | self.settings = {} |
||
191 | |||
192 | self:InitPerCharDB() |
||
193 | self:LoadSettings() |
||
194 | |||
195 | if self.firstLoad then |
||
196 | self:LoadInitialSettings() |
||
197 | self:ShowHelp() |
||
198 | end |
||
199 | |||
200 | |||
201 | end |
||
202 | |||
203 | function SimpleCombatLog:InitGlobalDB() |
||
204 | |||
205 | if not SimpleCombatLogDB or not SimpleCombatLogDB.version then |
||
206 | self:Print("SCL version changed, resetting global data.") |
||
207 | SimpleCombatLogDB = { |
||
208 | version = self.version, |
||
209 | themes = {} |
||
210 | } |
||
211 | end |
||
212 | |||
213 | self.themeDB = SimpleCombatLogDB.themes |
||
214 | end |
||
215 | |||
216 | function SimpleCombatLog:InitPerCharDB() |
||
217 | |||
218 | if not SimpleCombatLogDBPerChar or not SimpleCombatLogDBPerChar.version then |
||
219 | self:Print("SCL version changed, resetting per-char data.") |
||
220 | self.firstLoad = true |
||
221 | SimpleCombatLogDBPerChar = { |
||
222 | version = self.version, |
||
223 | settings = {} |
||
224 | } |
||
225 | end |
||
226 | |||
227 | self.settingDB = SimpleCombatLogDBPerChar.settings |
||
228 | end |
||
229 | |||
230 | -- Load themes into |
||
231 | function SimpleCombatLog:LoadThemes() |
||
232 | for i, theme in pairs(self.themeDB) do |
||
233 | self.themes[i] = theme |
||
234 | end |
||
235 | end |
||
236 | |||
237 | function SimpleCombatLog:SetTheme(id, themeName) |
||
238 | local themeTable |
||
239 | |||
240 | if self.themes[themeName] then |
||
241 | self.settingDB[id] = themeName |
||
242 | self.settings[id] = self.themes[themeName] |
||
243 | end |
||
244 | |||
245 | self:RefreshSettings() |
||
246 | end |
||
247 | |||
248 | function SimpleCombatLog:LoadSettings() |
||
249 | for id, setting in pairs(self.settingDB) do |
||
250 | if type(setting) == 'string' then -- this is a theme. |
||
251 | self:SetTheme(id, setting) |
||
252 | -- self.settings[id] = self.themes[setting] |
||
253 | else |
||
254 | self.settings[id] = setting |
||
255 | end |
||
256 | end |
||
257 | end |
||
258 | |||
259 | function SimpleCombatLog:ShowHelp() |
||
260 | for i, msg in ipairs(L["Welcome"]) do |
||
261 | self:Print(msg) |
||
262 | end |
||
263 | end |
||
264 | |||
265 | function SimpleCombatLog:OnEnable() |
||
266 | self:RefreshSettings() |
||
267 | end |
||
268 | |||
269 | function SimpleCombatLog:OnDisable() |
||
270 | parser:UnregisterAllEvents("SimpleCombatLog") |
||
271 | end |
||
272 | |||
273 | |||
274 | function SimpleCombatLog:OnCombatEvent(event, info) |
||
275 | self:Debug("OnCombatEvent", event, arg1, info.type) |
||
276 | |||
277 | -- Parse for the message type. |
||
278 | local infoType = info.type |
||
279 | local msgType |
||
280 | if infoType == 'hit' then |
||
281 | if info.isCrit then |
||
282 | msgType = 'hitCrit' |
||
283 | elseif info.isDOT then |
||
284 | msgType = 'hitDOT' |
||
285 | else |
||
286 | msgType = 'hit' |
||
287 | end |
||
288 | elseif infoType == 'heal' then |
||
289 | if info.isCrit then |
||
290 | msgType = 'healCrit' |
||
291 | elseif info.isDOT then |
||
292 | msgType = 'healDOT' |
||
293 | else |
||
294 | msgType = 'heal' |
||
295 | end |
||
296 | elseif infoType == 'dispel' then |
||
297 | if info.isFailed then |
||
298 | msgType = 'dispelFailed' |
||
299 | else |
||
300 | msgType = 'dispel' |
||
301 | end |
||
302 | elseif infoType == 'cast' then |
||
303 | if info.isBegin then |
||
304 | msgType = 'castBegin' |
||
305 | elseif info.victim then |
||
306 | msgType = 'castTargeted' |
||
307 | else |
||
308 | msgType = 'cast' |
||
309 | end |
||
310 | elseif infoType == 'honor' then |
||
311 | if not info.amount then |
||
312 | msgType = 'dishonor' |
||
313 | elseif info.source then |
||
314 | msgType = 'honorKill' |
||
315 | else |
||
316 | msgType = 'honor' |
||
317 | end |
||
318 | elseif info.type == 'reputation' then |
||
319 | if info.rank then |
||
320 | msgType = 'reputationRank' |
||
321 | elseif info.isNegative then |
||
322 | msgType = 'reputationMinus' |
||
323 | else |
||
324 | msgType = 'reputation' |
||
325 | end |
||
326 | elseif info.type == 'death' then |
||
327 | if info.source then |
||
328 | msgType = 'deathSource' |
||
329 | elseif info.skill then |
||
330 | msgType = 'deathSkill' |
||
331 | else |
||
332 | msgType = 'death' |
||
333 | end |
||
334 | elseif info.type == 'unknown' then |
||
335 | ChatFrame1:AddMessage(string.format("%s: %s", event, info.message),1,0,0) |
||
336 | return |
||
337 | else |
||
338 | msgType = infoType |
||
339 | end |
||
340 | |||
341 | -- Get necessary fields out of info table. |
||
342 | local tokens = compost:Acquire() |
||
343 | local fields = defaultFormats[msgType][2] |
||
344 | for i, v in pairs(fields) do |
||
345 | tokens[v] = info[v] |
||
346 | end |
||
347 | |||
348 | -- Common conversion for all chat frames. |
||
349 | if tokens.skill == ParserLib_MELEE then tokens.skill = L["Melee"] end |
||
350 | if tokens.skill == ParserLib_DAMAGESHIELD then tokens.skill = L["Damage Shields"] end |
||
351 | |||
352 | if infoType == 'hit' then |
||
353 | if not info.element then |
||
354 | tokens.element = 'physical' |
||
355 | else |
||
356 | tokens.element = self:GetElementType(info.element) |
||
357 | end |
||
358 | elseif infoType == 'heal' then |
||
359 | tokens.element = 'heal' |
||
360 | elseif infoType == 'buff' or infoType == 'debuff' then |
||
361 | if info.amountRank then |
||
362 | tokens.skill = string.format("%s(%d)", tokens.skill, info.amountRank) |
||
363 | end |
||
364 | tokens.element = infoType |
||
365 | elseif infoType == 'durability' then |
||
366 | if not tokens.item then tokens.item = L["All Items"] end |
||
367 | elseif infoType == 'miss' then |
||
368 | tokens.missType = L.missType[tokens.missType] |
||
369 | elseif infoType == 'environment' then |
||
370 | tokens.damageType = L.damageType[tokens.damageType] |
||
371 | end |
||
372 | |||
373 | for id, settings in pairs(self.settings) do |
||
374 | if settings.events and settings.events[event] and self:FilterCheck(id, info) then |
||
375 | if infoType == 'hit' or infoType == 'environment' then |
||
376 | tokens.trailers = self:GetTrailerString(id, info) |
||
377 | elseif info.type == 'experience' then |
||
378 | tokens.trailers = self:GetExpTrailerString(id, info) |
||
379 | end |
||
380 | self:ParseInfo(id, msgType, tokens) |
||
381 | end |
||
382 | end |
||
383 | |||
384 | compost:Reclaim(tokens) |
||
385 | |||
386 | end |
||
387 | |||
388 | function SimpleCombatLog:ParseInfo(id, msgType, tokens) |
||
389 | self:Debug("ParseInfo", id, msgType) |
||
390 | |||
391 | local settings = self.settings[id] |
||
392 | |||
393 | local myTokens = compost:Acquire() |
||
394 | for i, v in pairs(tokens) do |
||
395 | myTokens[i] = v |
||
396 | end |
||
397 | |||
398 | if myTokens.source then |
||
399 | if myTokens.source == ParserLib_SELF then |
||
400 | myTokens.source = self:Colorize(L["You"], self:GetColorHex(id, 'player' ) ) |
||
401 | else |
||
402 | myTokens.source = self:Colorize(myTokens.source, self:GetColorHex(id, self:GetUnitType(myTokens.source, true) ) ) |
||
403 | end |
||
404 | end |
||
405 | if myTokens.victim then |
||
406 | if myTokens.victim == ParserLib_SELF then |
||
407 | myTokens.victim = self:Colorize(L["You"], self:GetColorHex(id, 'player' ) ) |
||
408 | else |
||
409 | myTokens.victim = self:Colorize(myTokens.victim, self:GetColorHex(id, self:GetUnitType(myTokens.victim, true) ) ) |
||
410 | end |
||
411 | end |
||
412 | if myTokens.sourceGained then |
||
413 | if myTokens.sourceGained == ParserLib_SELF then |
||
414 | myTokens.sourceGained = self:Colorize(L["You"], self:GetColorHex(id, 'player' ) ) |
||
415 | else |
||
416 | myTokens.sourceGained = self:Colorize(myTokens.sourceGained, self:GetColorHex(id, self:GetUnitType(myTokens.sourceGained, true) ) ) |
||
417 | end |
||
418 | end |
||
419 | |||
420 | if myTokens.skill then |
||
421 | if settings.colorspell and myTokens.element then |
||
422 | myTokens.skill = self:Colorize(myTokens.skill, self:GetColorHex(id, myTokens.element) ) |
||
423 | else |
||
424 | myTokens.skill = self:Colorize(myTokens.skill, self:GetColorHex(id, "skill") ) |
||
425 | end |
||
426 | end |
||
427 | |||
428 | if myTokens.amount and myTokens.element then |
||
429 | myTokens.amount = self:Colorize(myTokens.amount, self:GetColorHex(id, myTokens.element) ) |
||
430 | end |
||
431 | |||
432 | local fields = defaultFormats[msgType][2] |
||
433 | local fieldCount = table.getn(fields) |
||
434 | |||
435 | local outputString |
||
436 | if fieldCount == 0 then |
||
437 | outputString = self:GetFormat(id, msgType) |
||
438 | elseif fieldCount == 1 then |
||
439 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ] ) |
||
440 | elseif fieldCount == 2 then |
||
441 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ] ) |
||
442 | elseif fieldCount == 3 then |
||
443 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ], myTokens[fields[3] ] ) |
||
444 | elseif fieldCount == 4 then |
||
445 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ], myTokens[fields[3] ], myTokens[fields[4] ] ) |
||
446 | elseif fieldCount == 5 then |
||
447 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ], myTokens[fields[3] ], myTokens[fields[4] ], myTokens[fields[5] ] ) |
||
448 | elseif fieldCount == 6 then |
||
449 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ], myTokens[fields[3] ], myTokens[fields[4] ], myTokens[fields[5] ], myTokens[fields[6] ] ) |
||
450 | elseif fieldCount == 7 then |
||
451 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ], myTokens[fields[3] ], myTokens[fields[4] ], myTokens[fields[5] ], myTokens[fields[6] ], myTokens[fields[7] ] ) |
||
452 | elseif fieldCount == 8 then |
||
453 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ], myTokens[fields[3] ], myTokens[fields[4] ], myTokens[fields[5] ], myTokens[fields[6] ], myTokens[fields[7] ], myTokens[fields[8] ] ) |
||
454 | elseif fieldCount == 9 then |
||
455 | outputString = string.format( self:GetFormat(id, msgType), myTokens[fields[1] ], myTokens[fields[2] ], myTokens[fields[3] ], myTokens[fields[4] ], myTokens[fields[5] ], myTokens[fields[6] ], myTokens[fields[7] ], myTokens[fields[8] ], myTokens[fields[9] ] ) |
||
456 | end |
||
457 | |||
458 | |||
459 | -- Get the ChatFrame to display. |
||
460 | |||
461 | local chatframe |
||
462 | if type(id) == 'number' then -- this is a default chat frame. |
||
463 | chatframe = getglobal("ChatFrame" .. id) |
||
464 | elseif type(id) == 'string' then -- this is a custom chat frame. |
||
465 | chatframe = getglobal(id) |
||
466 | end |
||
467 | |||
468 | if chatframe then |
||
469 | if settings.colorEvent then |
||
470 | local e = string.sub(event, 10) |
||
471 | local info = ChatTypeInfo[e] |
||
472 | chatframe:AddMessage(outputString, info.r, info.g, info.b) |
||
473 | else |
||
474 | chatframe:AddMessage(outputString) |
||
475 | end |
||
476 | end |
||
477 | |||
478 | compost:Reclaim(myTokens) |
||
479 | |||
480 | |||
481 | end |
||
482 | |||
483 | function SimpleCombatLog:Colorize(text, hexColor) |
||
484 | return string.format('|cff%s%s|r', hexColor, text) |
||
485 | end |
||
486 | |||
487 | |||
488 | function SimpleCombatLog:GetValue(id, field) |
||
489 | if not self.settings[id] then |
||
490 | return false |
||
491 | else |
||
492 | return self.settings[id][field] |
||
493 | end |
||
494 | end |
||
495 | |||
496 | |||
497 | function SimpleCombatLog:GetEvent(id, event) |
||
498 | local db = self.settings[id] |
||
499 | if not db or not db.events or not db.events[event] then |
||
500 | return false |
||
501 | else |
||
502 | return db.events[event] |
||
503 | end |
||
504 | end |
||
505 | |||
506 | |||
507 | SimpleCombatLog.filterFlags = { |
||
508 | { |
||
509 | player = 1, |
||
510 | pet = 2, |
||
511 | party = 3, |
||
512 | raid = 4, |
||
513 | target = 5, |
||
514 | targettarget = 6, |
||
515 | other = 7 |
||
516 | }, |
||
517 | { |
||
518 | player = 8, |
||
519 | pet = 9, |
||
520 | party = 10, |
||
521 | raid = 11, |
||
522 | target = 12, |
||
523 | targettarget = 13, |
||
524 | other = 14 |
||
525 | } |
||
526 | } |
||
527 | |||
528 | function SimpleCombatLog:GetFilter(id, filterType, nameFilter, isSource) |
||
529 | local db = self.settings[id] |
||
530 | if not db or not db.filters or not db.filters[filterType] then |
||
531 | return false |
||
532 | else |
||
533 | local source |
||
534 | if isSource then source = 1 else source = 2 end |
||
535 | local flag = self.filterFlags[source][nameFilter] |
||
536 | return db.filters[filterType][flag] |
||
537 | end |
||
538 | end |
||
539 | |||
540 | |||
541 | |||
542 | |||
543 | -- Return values: hex, isDefault |
||
544 | function SimpleCombatLog:GetColorHex(id, colorType) |
||
545 | assert( id and colorType ) |
||
546 | local hex, isDefault |
||
547 | if not self.settings[id] or not self.settings[id].colors or not self.settings[id].colors[colorType] then |
||
548 | hex = defaultColors[colorType] |
||
549 | isDefault = true |
||
550 | else |
||
551 | hex = self.settings[id].colors[colorType] |
||
552 | isDefault = false |
||
553 | end |
||
554 | return hex, isDefault |
||
555 | end |
||
556 | |||
557 | |||
558 | |||
559 | |||
560 | function SimpleCombatLog:GetFormat(id, msgType) |
||
561 | assert( id and msgType ) |
||
562 | local db = self.settings[id] |
||
563 | if not db or not db.formats or not db.formats[msgType] then |
||
564 | return defaultFormats[msgType][1], true |
||
565 | else |
||
566 | return db.formats[msgType], false |
||
567 | end |
||
568 | end |
||
569 | |||
570 | |||
571 | function SimpleCombatLog:GetWatchList(id, watchType) |
||
572 | local db = self.settings[id] |
||
573 | if db and db.watchList and db.watchList[watchType] then |
||
574 | return db.watchList[watchType] |
||
575 | end |
||
576 | end |
||
577 | |||
578 | |||
579 | function SimpleCombatLog:RefreshSettings() |
||
580 | |||
581 | local usedEvents = {} |
||
582 | |||
583 | for event in pairs(self.events) do |
||
584 | for j in pairs(self.settings) do |
||
585 | if self:GetEvent(j, event) then |
||
586 | usedEvents[event] = true |
||
587 | if not parser:IsEventRegistered("SimpleCombatLog", event) then |
||
588 | parser:RegisterEvent("SimpleCombatLog", event, function(event, info) self:OnCombatEvent(event, info) end) |
||
589 | end |
||
590 | end |
||
591 | |||
592 | end |
||
593 | end |
||
594 | |||
595 | |||
596 | -- Unregister non-used events from ParserLib. |
||
597 | for event in pairs(self.events) do |
||
598 | if not usedEvents[event] and parser:IsEventRegistered("SimpleCombatLog", event) then |
||
599 | parser:UnregisterEvent("SimpleCombatLog", event) |
||
600 | end |
||
601 | end |
||
602 | |||
603 | |||
604 | for id, setting in self.settings do |
||
605 | local chatframe = getglobal("ChatFrame" .. id) |
||
606 | if chatframe then |
||
607 | if setting.resize then |
||
608 | chatframe:SetMaxResize(1000, 700) |
||
609 | chatframe:SetMinResize(40, 40) |
||
610 | else |
||
611 | chatframe:SetMaxResize(608, 400) |
||
612 | chatframe:SetMinResize(296, 75) |
||
613 | end |
||
614 | end |
||
615 | end |
||
616 | |||
617 | |||
618 | |||
619 | end |
||
620 | |||
621 | -- Get constant element string from localized element string. |
||
622 | function SimpleCombatLog:GetElementType(element) |
||
623 | for elementType, keyword in self.fixCombatLog do |
||
624 | if element == keyword then |
||
625 | return elementType |
||
626 | end |
||
627 | end |
||
628 | |||
629 | --[[ |
||
630 | if element == SPELL_SCHOOL0_CAP then return 'physical' |
||
631 | elseif element == SPELL_SCHOOL1_CAP then return 'holy' |
||
632 | elseif element == SPELL_SCHOOL2_CAP then return 'fire' |
||
633 | elseif element == SPELL_SCHOOL3_CAP then return 'nature' |
||
634 | elseif element == SPELL_SCHOOL4_CAP then return 'frost' |
||
635 | elseif element == SPELL_SCHOOL5_CAP then return 'shadow' |
||
636 | elseif element == SPELL_SCHOOL6_CAP then return 'arcane' |
||
637 | end |
||
638 | ]] |
||
639 | self:Debug("Unknown element:", element) |
||
640 | return 'physical' |
||
641 | end |
||
642 | |||
643 | -- Get trailer string by parsing info. |
||
644 | function SimpleCombatLog:GetTrailerString(id, info) |
||
645 | local trailer = '' |
||
646 | if info.isCrushing then trailer = trailer .. self:GetFormat(id, 'crushing')end |
||
647 | if info.isGlancing then trailer = trailer .. self:GetFormat(id, 'glancing')end |
||
648 | if info.amountAbsorb then trailer = trailer .. format(self:GetFormat(id, 'absorb'), info.amountAbsorb) end |
||
649 | if info.amountResist then trailer = trailer .. format(self:GetFormat(id, 'resist'), info.amountResist) end |
||
650 | if info.amountBlock then trailer = trailer .. format(self:GetFormat(id, 'block'), info.amountBlock) end |
||
651 | if info.amountVulnerable then trailer = trailer .. format(self:GetFormat(id, 'vulnerable'), info.amountVulnerable) end |
||
652 | return trailer |
||
653 | end |
||
654 | |||
655 | function SimpleCombatLog:GetExpTrailerString(id, info) |
||
656 | local trailer = '' |
||
657 | if info.source then trailer = trailer .. format(self:GetFormat(id, 'expSource'), info.source) end |
||
658 | if info.bonusAmount then |
||
659 | trailer = trailer .. format(self:GetFormat(id, 'expBonus'), info.bonusType, info.bonusAmount) |
||
660 | elseif info.penaltyAmount then |
||
661 | trailer = trailer .. format(self:GetFormat(id, 'expBonus'), info.penaltyType, info.penaltyAmount) |
||
662 | end |
||
663 | if info.amountGroupBonus then |
||
664 | trailer = trailer .. format(self:GetFormat(id, 'expGroup'), info.amountGroupBonus) |
||
665 | elseif info.amountRaidPenalty then |
||
666 | trailer = trailer .. format(self:GetFormat(id, 'expRaid'), info.amountGroupBonus) |
||
667 | end |
||
668 | return trailer |
||
669 | end |
||
670 | |||
671 | -- Check for the filter settings, return true if this message can be shown, false if the message is filtered. |
||
672 | function SimpleCombatLog:FilterCheck(id, info) |
||
673 | |||
674 | -- These message ignore name filters. |
||
675 | if info.type == 'experience' |
||
676 | or info.type == 'honor' |
||
677 | or info.type == 'reputation' |
||
678 | or info.type == 'fail' then |
||
679 | return true |
||
680 | end |
||
681 | |||
682 | if not self.settings[id] then |
||
683 | return true |
||
684 | end |
||
685 | |||
686 | local watch = self:GetWatchList(id, 'skill') |
||
687 | |||
688 | -- Custom skill watch? |
||
689 | if watch and info.skill and watch[info.skill] then |
||
690 | return true |
||
691 | end |
||
692 | |||
693 | |||
694 | -- Checking names |
||
695 | if not info.source and not info.victim then return true end |
||
696 | |||
697 | if info.source then |
||
698 | local name = info.source |
||
699 | |||
700 | -- Custom name watch. |
||
701 | watch = self:GetWatchList(id, 'source') |
||
702 | if watch and watch[name] then return true end |
||
703 | |||
704 | if self:GetFilter(id, info.type, self:GetUnitType(name), true) then |
||
705 | return true |
||
706 | end |
||
707 | if self:IsTarget(name) and self:GetFilter(id, info.type, 'target', true) then |
||
708 | return true |
||
709 | end |
||
710 | if self:IsTargetTarget(name) and self:GetFilter(id, info.type, 'targettarget', true) then |
||
711 | return true |
||
712 | end |
||
713 | end |
||
714 | |||
715 | if info.victim then |
||
716 | local name = info.victim |
||
717 | |||
718 | -- Custom name watch. |
||
719 | watch = self:GetWatchList(id, 'victim') |
||
720 | if watch and watch[name] then return true end |
||
721 | |||
722 | if self:GetFilter(id, info.type, self:GetUnitType(name)) then |
||
723 | return true |
||
724 | end |
||
725 | if self:IsTarget(name) and self:GetFilter(id, info.type, 'target') then |
||
726 | return true |
||
727 | end |
||
728 | if self:IsTargetTarget(name) and self:GetFilter(id, info.type, 'targettarget') then |
||
729 | return true |
||
730 | end |
||
731 | end |
||
732 | |||
733 | -- The message does not match any filter setting, block. |
||
734 | return false |
||
735 | |||
736 | end |
||
737 | |||
738 | function SimpleCombatLog:IsTarget(name) |
||
739 | return name == UnitName("target") |
||
740 | end |
||
741 | |||
742 | function SimpleCombatLog:IsTargetTarget(name) |
||
743 | return name == UnitName("targettarget") |
||
744 | end |
||
745 | |||
746 | |||
747 | -- Get what is this name : player, pet, party, raid, or others. |
||
748 | function SimpleCombatLog:GetUnitType(name, checkTarget) |
||
749 | if not name then return end |
||
750 | |||
751 | if checkTarget then |
||
752 | if name == UnitName('target') then return 'target' end |
||
753 | if name == UnitName('targettarget') then return 'targettarget' end |
||
754 | end |
||
755 | |||
756 | if name == ParserLib_SELF then return 'player' end |
||
757 | |||
758 | -- This is NOT player, but someone which has an identical name to player ( most likely a pet name). |
||
759 | if name == UnitName('player') then return 'other' end |
||
760 | |||
761 | local unit = roster:GetUnitIDFromName(name) |
||
762 | |||
763 | if not unit then return 'other' end |
||
764 | |||
765 | if unit == 'pet' then return 'pet' end |
||
766 | |||
767 | if string.find(unit, 'party', 1, true) then return 'party' end |
||
768 | |||
769 | return 'raid' |
||
770 | |||
771 | end |
||
772 | |||
773 | |||
774 | function SimpleCombatLog:LoadInitialSettings() |
||
775 | SimpleCombatLogDB = nil |
||
776 | SimpleCombatLogDBPerChar = nil |
||
777 | self:InitGlobalDB() |
||
778 | self:InitPerCharDB() |
||
779 | self.settings = {} |
||
780 | self:SetTheme(2, 'default') |
||
781 | self:Print("Loaded default settings (custom themes will exist until next login).") |
||
782 | end |
||
783 | |||
784 | function SimpleCombatLog:LoadSettingMenu(id) |
||
785 | if not self.ShowSettingMenu then |
||
786 | self:Print("Dropdown menu component is not loaded.") |
||
787 | else |
||
788 | self:ShowSettingMenu(id) |
||
789 | end |
||
790 | end |
||
791 | |||
792 | |||
793 | -- Save the table as base locales if there isn't one, update the current locales if there is one. |
||
794 | function SimpleCombatLog:UpdateLocales(loc) |
||
795 | if not self.loc then |
||
796 | self.loc = loc |
||
797 | else |
||
798 | self.CopyTable(self.loc, loc) |
||
799 | end |
||
800 | end |