-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBuffReminder.lua
More file actions
743 lines (699 loc) · 28.9 KB
/
Copy pathBuffReminder.lua
File metadata and controls
743 lines (699 loc) · 28.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
-- BuffReminder.lua
-- Author : mcrane
BuffReminder = {
["hide_all"] = false,
["button_space"] = 2,
["all_buffs"] = {}, -- all buffs even if not monitored, key is icon
["current_buffs"] = {}, -- only contains buffs that we monitor, key is name
["new_buffs"] = {},
["watched_buffs"] = {},
["missing_buffs"] = {},
["missing_groups"] = {},
["icons"] = {},
["enchants"] = {},
["player_status"] = {
["dead"] = false,
["instance"] = false,
["raid_inst"] = false,
["pvp_inst"] = false,
["party"] = false,
["raid"] = false,
["resting"] = true,
["taxi"] = true,
["combat"] = false,
["mounted"] = false,
},
["update_time"] = 0,
["delay"] = 1,
["scripts"] = {},
["script_res"] = {},
["default"] = { ["script_res"] = false},
["status_updated"] = false,
}
BRVars = {}
BRVars.BuffGroups = {}
BRVars.Options = {}
BuffReminder.dbg = false
BuffReminder.DefaultOptions = {
["version"] = "1.2",
["warnsound"] = nil,
["size"] = 30,
["warntime"] = 60,
["warncharges"] = 5,
["alpha"] = 1.0,
["script"] = "",
["enchants"] = {
["main"] = false,
["off"] = false,
},
["conditions"] = {
["always"] = 0,
["dead"] = 1,
["instance"] = 0,
["party"] = 0,
["raid"] = 0,
["resting"] = 1,
["taxi"] = 1,
["combat"] = 0,
["mounted"] = 1,
},
}
-- util functions
local function getArgs(m)
local _, count = string.gsub(m, [["]], "")
if math.mod(count, 2) ~= 0 then
DEFAULT_CHAT_FRAME:AddMessage("Unfinished quote in command.")
return nil, 0
end
for i in string.gfind(m, '(".-")') do
m = string.gsub(m, i, string.gsub(string.gsub(i, "%s", "%%%%space%%%%"), '"', ""))
end
local args = {}
local largs = {}
local r
local argc = 0
for v in string.gfind(m, "(%S+)") do
r, _ = string.gsub(v, "%%space%%", " ")
table.insert(args, r)
table.insert(largs, string.lower(r))
argc = argc + 1
end
return args, largs, argc
end
local function tableLen(t)
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
local function toNum(n)
local n = tonumber(n)
if n == nil then DEFAULT_CHAT_FRAME:AddMessage("Invalid number given.") end
return n
end
-------------------------------------------------------------------------------
function BuffReminder.MakeIcon(index, texture)
BuffReminder.icons[index] = CreateFrame("Frame", nil, BuffReminderFrame)
BuffReminder.icons[index]:SetFrameStrata("BACKGROUND")
BuffReminder.icons[index]:SetWidth(BRVars.Options.size)
BuffReminder.icons[index]:SetHeight(BRVars.Options.size)
tex = BuffReminder.icons[index]:CreateTexture(nil, "ARTWORK")
tex:SetTexture(texture)
tex:SetAlpha(BRVars.Options.alpha)
tex:SetAllPoints(BuffReminder.icons[index])
BuffReminder.icons[index].texture = tex
end
function BuffReminder.MakeIcons()
for i in BuffReminder.icons do
BuffReminder.icons[i]:Hide()
end
local index = 1
for i in BuffReminder.missing_groups do
local skipIcon = false
for k, v in pairs(BuffReminder.player_status) do
if (BRVars.BuffGroups[i].conditions.always ~= 2) and ((BRVars.BuffGroups[i].conditions.always == 1) or (v and
(BRVars.BuffGroups[i].conditions[k] == 1)) or (not v and BRVars.BuffGroups[i].conditions[k] == 2)) then
skipIcon = true
break
end
end
if not skipIcon and not BuffReminder.script_res[i] then
BuffReminder.MakeIcon(index, BuffReminder.missing_groups[i])
index = index + 1
end
end
skipIcon = false
for k, v in pairs(BuffReminder.player_status) do
if (BRVars.Options.conditions.always ~= 2) and ((BRVars.Options.conditions.always == 1) or (v and
(BRVars.Options.conditions[k] == 1)) or (not v and BRVars.Options.conditions[k] == 2)) then
skipIcon = true
break
end
end
if not skipIcon and not BuffReminder.default.script_res then
if BRVars.Options.enchants.main and (not BuffReminder.enchants.main) then
local t = GetInventoryItemTexture("player", 16)
if t ~= nil then
BuffReminder.MakeIcon(index, t)
index = index + 1
end
end
if BRVars.Options.enchants.off and (not BuffReminder.enchants.off) then
local t = GetInventoryItemTexture("player", 17)
if t ~= nil then
BuffReminder.MakeIcon(index, t)
index = index + 1
end
end
end
local count = index - 1
local pitch = BRVars.Options.size + BuffReminder.button_space * 2
local c = (pitch * (count - 1)) / 2
for i = count, 1, -1 do
BuffReminder.icons[i]:SetPoint("CENTER", c, 0)
BuffReminder.icons[i]:Show()
c = c - pitch
end
end
-- search groups for matching buff name
function BuffReminder.FindBuffGroupByName(buff)
for i in BRVars.BuffGroups do
if BRVars.BuffGroups[i].buffs[buff] ~= nil then
return i
end
end
return nil
end
-- search groups for matching buff icon (icon, buff button number)
function BuffReminder.FindGroupByIcon(icon, n)
for i in BRVars.BuffGroups do
for k, v in pairs(BRVars.BuffGroups[i].buffs) do
-- if this buff has no icon cache then cache it if matched
if BRVars.BuffGroups[i].buffs[k] == "" then
local name = BuffReminder.GetPlayerBuffName(n)
if name == k then
v = icon
return i, k
end
elseif v == icon then
return i, k
end
end
end
return nil
end
-- check if buffs have changd since last update
function BuffReminder.BuffsUpdated(buffs)
for i in BuffReminder.current_buffs do
if buffs[i] == nil then -- lost a buff
return true
end
end
for i in buffs do
if BuffReminder.current_buffs[i] == nil then -- gained a buff
return true
end
end
return false
end
-- creates a list of current buffs which are also watched buffs
function BuffReminder.GetBuffs()
BuffReminder.new_buffs = {}
if BuffReminder.dbg then
for i = 0, 29 do
local texture = GetPlayerBuffTexture(i)
local tl = GetPlayerBuffTimeLeft(i)
if texture == nil then break end
DEFAULT_CHAT_FRAME:AddMessage("Icon: " .. tostring(texture) .. ", time: " .. tostring(tl))
end
end
BuffReminder.all_buffs = {}
for i = 0, 29 do
local icon = GetPlayerBuffTexture(i)
if icon == nil then break end
local time = GetPlayerBuffTimeLeft(i)
BuffReminder.all_buffs[icon] = time
local group, name = BuffReminder.FindGroupByIcon(icon, i)
-- if the buff isn't found in the buff groups or time is low then don't add it
if group ~= nil and (time > BRVars.BuffGroups[group].warntime or time == 0) then
BuffReminder.new_buffs[name] = icon
BRVars.BuffGroups[group].icon = icon
end
end
BuffReminder.status_updated = BuffReminder.status_updated or BuffReminder.BuffsUpdated(BuffReminder.new_buffs)
BuffReminder.current_buffs = BuffReminder.new_buffs
-- see if we're mounted by checking speed increased buff
local speed
for i = 0, 31 do
local buffIndex, untilCancelled = GetPlayerBuff(i, "HELPFUL|PASSIVE")
if buffIndex < 0 then break end
if untilCancelled == 1 then
TooltipScanner:ClearLines()
TooltipScanner:SetPlayerBuff(buffIndex)
if (TooltipScannerTextLeft2:IsShown()) then
text = TooltipScannerTextLeft2:GetText()
if (text) then
_, _, speed = string.find(text, BUFFREMINDER_SPEED_INCREASED)
end
end
end
end
local mounted = BuffReminder.player_status.mounted
if speed then
BuffReminder.player_status.mounted = true
else
BuffReminder.player_status.mounted = false
end
if mounted ~= BuffReminder.player_status.mounted then BuffReminder.status_updated = true end
end
function BuffReminder.GetMissinGroups()
BuffReminder.missing_groups = {}
-- first add all groups then remove any not found
for i in BRVars.BuffGroups do
BuffReminder.missing_groups[i] = BRVars.BuffGroups[i].icon
end
for i in BuffReminder.watched_buffs do
if BuffReminder.current_buffs[i] ~= nil then
local group = BuffReminder.FindBuffGroupByName(i)
BuffReminder.missing_groups[group] = nil
end
end
end
-- get a table of all watched buffs
function BuffReminder.GetWatchedBuffs()
BuffReminder.watched_buffs = {}
for k, v in BRVars.BuffGroups do
for j in v.buffs do
BuffReminder.watched_buffs[j] = v.buffs[j]
end
end
end
-- try to get the buff name from the buff icon tooltip
function BuffReminder.GetPlayerBuffName(n)
TooltipScanner:ClearLines()
TooltipScanner:SetPlayerBuff(n)
if (TooltipScannerTextLeft1:IsShown()) then
return TooltipScannerTextLeft1:GetText()
else
return nil
end
end
function BuffReminder.GetEnchants()
local changed = false
if BRVars.Options.enchants.main or BRVars.Options.enchants.off then
local hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges = GetWeaponEnchantInfo();
if (BuffReminder.enchants.main ~= hasMainHandEnchant) or (hasOffHandEnchant ~= BuffReminder.enchants.off) then
changed = true
end
BuffReminder.enchants.main = (hasMainHandEnchant == 1) and (mainHandExpiration > BRVars.Options.warntime * 1000) and ((mainHandCharges == 0) or (mainHandCharges > BRVars.Options.warncharges))
BuffReminder.enchants.off = (hasOffHandEnchant == 1) and (offHandExpiration > BRVars.Options.warntime * 1000) and ((offHandCharges == 0) or (offHandCharges > BRVars.Options.warncharges))
end
return changed
end
function BuffReminder.GetScriptResults()
local res
local changed = false
for k, v in pairs(BuffReminder.scripts) do
res = v.script()
if BuffReminder.script_res[k] ~= res then
BuffReminder.script_res[k] = res
changed = true
end
end
if BuffReminder.default.script ~= nil then
res = BuffReminder.default.script()
if BuffReminder.default.script_res ~= res then
BuffReminder.default.script_res = res
changed = true
end
end
return changed
end
-- debug helpers ----------------------------------------------------------------------------
function BuffReminder.list_current()
for k, v in BuffReminder.current_buffs do
DEFAULT_CHAT_FRAME:AddMessage(k .. " --> " .. v)
end
end
function BuffReminder.list_missing()
for k, v in BuffReminder.missing_buffs do
DEFAULT_CHAT_FRAME:AddMessage(k .. " --> " .. v)
end
end
-- slash command functions ------------------------------------------------------------------
-- reset the icons to unknown state
function BuffReminder.ClearIcons()
for k, v in pairs(BRVars.BuffGroups) do
v.icon = "Interface\\Icons\\INV_Misc_QuestionMark" -- set group icon to ?
for j in v.buffs do
v.buffs[j] = "" -- erase cached buff icon
end
end
BuffReminder.Update()
end
-- check for existence of a group
function BuffReminder.GroupExists(group)
if BRVars.BuffGroups[group] == nil then
DEFAULT_CHAT_FRAME:AddMessage('\124cffffff00\124hGroup "' .. tostring(group) .. '" does not exist.')
DEFAULT_CHAT_FRAME:AddMessage('\124cffffff00\124hYour groups are:')
for i in BRVars.BuffGroups do
DEFAULT_CHAT_FRAME:AddMessage('\124cffffff00\124h ' .. i)
end
return false
end
return true
end
-- print a list of groups and buffs
function BuffReminder.PrintBuffs()
for i in BRVars.BuffGroups do
DEFAULT_CHAT_FRAME:AddMessage('\124cffffff00\124hGroup: ' .. tostring(i))
for j in BRVars.BuffGroups[i].buffs do
DEFAULT_CHAT_FRAME:AddMessage("\124cffffff00\124h " .. j)
end
end
end
function BuffReminder.PrintAllGroups()
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h** buff groups **")
for i in BRVars.BuffGroups do
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h " .. i)
local t = BRVars.BuffGroups[i].buffs
end
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h** end of buff groups **")
end
function BuffReminder.PrintGroup(group)
DEFAULT_CHAT_FRAME:AddMessage('\124cffffff00\124hGroup: ' .. tostring(group))
for i in BRVars.BuffGroups[group].buffs do
DEFAULT_CHAT_FRAME:AddMessage("\124cffffff00\124h " .. i)
end
DEFAULT_CHAT_FRAME:AddMessage("\124cffffff00\124h ---")
for i in BRVars.BuffGroups[group].conditions do
DEFAULT_CHAT_FRAME:AddMessage("\124cffffff00\124h hide condition " .. i .. ": \124cff80ff00\124h" .. tostring(BRVars.BuffGroups[group].conditions[i]))
end
DEFAULT_CHAT_FRAME:AddMessage("\124cffffff00\124h early warning time: \124cff80ff00\124h" .. tostring(BRVars.BuffGroups[group].warntime))
end
function BuffReminder.AddBuffToGroup(grp, name, print)
if BRVars.BuffGroups[grp] == nil then
BRVars.BuffGroups[grp] = {["conditions"] = {}, ["warntime"] = BRVars.Options.warntime, ["icon"] = "Interface\\Icons\\INV_Misc_QuestionMark", ["script"] = "", ["buffs"] = {}}
for i in BRVars.Options.conditions do
BRVars.BuffGroups[grp].conditions[i] = BRVars.Options.conditions[i]
end
end
if name ~= nil then
BRVars.BuffGroups[grp].buffs[name] = ""
end
if print then BuffReminder.PrintGroup(grp) end
BuffReminder.Update()
end
function BuffReminder.ShowHelp()
DEFAULT_CHAT_FRAME:AddMessage("\124cfff4f9a7\124h ***** BuffReminder Help ***** ")
DEFAULT_CHAT_FRAME:AddMessage("\124cfff4f9a7\124hBuffs you want to monitor must be added to buff groups.")
DEFAULT_CHAT_FRAME:AddMessage("\124cfff4f9a7\124hMutually exclusive buffs should go into common groups.")
DEFAULT_CHAT_FRAME:AddMessage("\124cfff4f9a7\124hUntil a buff is seen by the addon it will have a '?' icon.")
DEFAULT_CHAT_FRAME:AddMessage("\124cfff4f9a7\124hGroup commands:")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br group <groupname> add <buffname>")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h Adds a buff to a group. If the group doesn't exist it will be created.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br group <groupname> remove")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h Removes the buff group.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br group <groupname> disable")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h Prevents the group's icon from being displayed when one of it's buffs are missing.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br group <groupname> enable")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h Allows the group's icon to be displayed when one of it's buffs are missing.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br group <number>")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h Sets the early warning timer for the group.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br group [dead|instance|party|raid|resting|taxi]")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h Toggles the given conditional for the group.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br group")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h Prints a listing of your buff groups.")
DEFAULT_CHAT_FRAME:AddMessage("\124cfff4f9a7\124hBuff commands:")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br buff <buffname> remove")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h removes a buff from being monitored.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br buff <buffname>")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h prints the group info of the group a buff belongs to.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h /br buff")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h prints a list of your watched buffs.")
DEFAULT_CHAT_FRAME:AddMessage("\124cfff4f9a7\124hGeneral options:")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br alpha <number> \124cffabb7ff\- changes the icon transparency (min 0.0, max 1.0).")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br config \124cffabb7ff\- opens the configuration dialog.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br [lock|unlock] \124cffabb7ff\- locks or unlocks the icon frame for user placement.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br NUKE \124cffabb7ff\- clears all of your settings.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br reseticons \124cffabb7ff\- clears the icon cache.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br size <number> \124cffabb7ff\- changes the icon size (min 10, max 400).")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br sound [sound name]\124cffabb7ff\- sets the warning sound or turns it off if no name given. ex: /br sound RaidWarning")
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124h/br time <number> \124cffabb7ff\- sets the default early warning time setting for new buff groups.")
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124h ***** End of BuffReminder Help *****\124h\124r")
end
-- end slash command functions --------------------------------------------------------------
SLASH_BuffReminder1 = "/br"
SLASH_BuffReminder2 = "/buffreminder"
function SlashCmdList.BuffReminder(msg)
local handled = false
local args, largs, argc = getArgs(msg)
if argc == 0 or largs[1] == "help" then
BuffReminder.ShowHelp()
return
end
-- group command and subcommands
if largs[1] == "group" then
if argc == 1 then
BuffReminder.PrintAllGroups()
else
if largs[3] == "add" then
BuffReminder.AddBuffToGroup(args[2], args[4], true)
else
if not BuffReminder.GroupExists(args[2]) then return end
if argc >= 3 then
if largs[3] == "disable" then
BRVars.BuffGroups[args[2]].conditions.always = true
elseif largs[3] == "enable" then
BRVars.BuffGroups[args[2]].conditions.always = false
elseif BRVars.BuffGroups[args[2]].conditions[args[3]] ~= nil then
BRVars.BuffGroups[args[2]].conditions[args[3]] = not BRVars.BuffGroups[args[2]].conditions[args[3]]
elseif largs[3] == "remove" then
BRVars.BuffGroups[args[2]] = nil
else
local n = toNum(args[3])
if n ~= nil then
BRVars.BuffGroups[args[2]].warntime = n
end
end
end
end
BuffReminder.PrintGroup(args[2])
end
handled = true
-- buff command and subcommands
elseif largs[1] == "buff" then
if argc == 1 then
BuffReminder.PrintBuffs()
elseif argc == 2 then
local g = BuffReminder.FindBuffGroup(args[2])
if g == nil then
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124hBuff " .. args[2] .. " does not exist in any buff groups.")
else
BuffReminder.PrintGroup(g)
end
elseif largs[3] == "remove" then
for i in BRVars.BuffGroups do
BRVars.BuffGroups[i].buffs[args[2]] = nil
end
DEFAULT_CHAT_FRAME:AddMessage("\124cffabb7ff\124hRemoved " .. args[2] .. " from all buff groups.")
end
handled = true
else
if largs[1] == "unlock" then
BuffReminderFrame:EnableMouse(true)
brtexture:SetTexture("Interface\\AddOns\\BuffReminder\\Media\\cross")
handled = true
elseif largs[1] == "lock" then
BuffReminderFrame:EnableMouse(false)
brtexture:SetTexture(nil)
handled = true
elseif args[1] == "NUKE" then
BRVars.BuffGroups = {}
BRVars.Options = BuffReminder.DefaultOptions
handled = true
elseif largs[1] == "sound" then
if argc == 1 then
BRVars.Options.warnsound = nil
else
BRVars.Options.warnsound = args[2]
PlaySound(tostring(BRVars.Options.warnsound), "master")
end
handled = true
elseif largs[1] == "size" then
local n = toNum(args[2])
if n ~= nil and (n >= 10 and n <= 400) then
BRVars.Options.size = n
handled = true
end
elseif largs[1] == "alpha" then
local n = toNum(args[2])
if n ~= nil and (n >= 0 and n <= 1.0) then
BRVars.Options.alpha = n
handled = true
end
elseif largs[1] == "time" then
local n = toNum(args[2])
if n ~= nil then
BRVars.Options.warntime = n
handled = true
end
elseif largs[1] == "reseticons" then
BuffReminder.ClearIcons()
handled = true
elseif largs[1] == "config" then
BRConfigFrame:Show()
handled = true
end
end
BuffReminder.Update()
if not handled then
DEFAULT_CHAT_FRAME:AddMessage("\124cffcbeb1c\124hBuffReminder command error. Try /br help.")
end
end
--------------------------------------------------------------------------------------------------
function BuffReminder_OnLoad()
this:RegisterForDrag("LeftButton")
this:EnableMouse(false)
-- this:RegisterEvent("PLAYER_ALIVE")
this:RegisterEvent("PLAYER_DEAD")
this:RegisterEvent("PLAYER_UNGHOST")
this:RegisterEvent("PLAYER_AURAS_CHANGED")
this:RegisterEvent("PLAYER_ENTERING_WORLD")
this:RegisterEvent("UNIT_FLAGS")
this:RegisterEvent("PLAYER_UPDATE_RESTING")
this:RegisterEvent("PLAYER_ENTERING_WORLD")
this:RegisterEvent("PARTY_MEMBERS_CHANGED")
this:RegisterEvent("RAID_ROSTER_UPDATE")
this:RegisterEvent("UNIT_INVENTORY_CHANGED")
this:RegisterEvent("PLAYER_REGEN_ENABLED")
this:RegisterEvent("PLAYER_REGEN_DISABLED")
this:RegisterEvent("ADDON_LOADED")
-- this:RegisterAllEvents()
-- tooltip frame for getting spell name
lbrTooltipFrame = CreateFrame('GameTooltip', 'BrTooltip', UIParent, 'GameTooltipTemplate')
lbrTooltipFrame:SetOwner(UIParent, 'ANCHOR_NONE')
if (DEFAULT_CHAT_FRAME) then
DEFAULT_CHAT_FRAME:AddMessage("BuffReminder AddOn loaded. Type '/br help' for config commands.")
end
UIErrorsFrame:AddMessage("BuffReminder AddOn loaded", 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME)
end
--------------------------------------------------------------------------------------------------
function BuffReminder_OnUpdate(elapsed)
BuffReminder.update_time = BuffReminder.update_time + elapsed
if BuffReminder.update_time >= BuffReminder.delay then
BuffReminder.update_time = 0
local resChanged = BuffReminder.GetScriptResults()
BuffReminder.GetBuffs()
local enchantsChanged = BuffReminder.GetEnchants()
if resChanged or enchantsChanged or BuffReminder.status_updated then
BuffReminder.Update()
end
end
end
function BuffReminder.Update()
if BuffReminder.hide_all then return end
BuffReminder.GetWatchedBuffs()
BuffReminder.GetMissinGroups()
BuffReminder.MakeIcons()
end
function BuffReminder_OnEvent(event, arg1)
if event == "UNIT_FLAGS" and arg1 == "player" then
if UnitOnTaxi("player") == 1 then
BuffReminder.player_status.taxi = true
else
BuffReminder.player_status.taxi = false
end
-- elseif event == "PLAYER_AURAS_CHANGED" then
-- BuffReminder.Update()
elseif event == "PARTY_MEMBERS_CHANGED" then
BuffReminder.player_status.party = (GetNumPartyMembers() > 0)
elseif event == "RAID_ROSTER_UPDATE" then
BuffReminder.player_status.raid = (GetNumRaidMembers() > 0)
elseif event == "PLAYER_DEAD" then
BuffReminder.player_status.dead = true
elseif event == "PLAYER_UNGHOST" then
BuffReminder.player_status.dead = false
elseif event == "PLAYER_UPDATE_RESTING" then
BuffReminder.player_status.resting = (IsResting() == 1)
elseif event == "PLAYER_REGEN_ENABLED" then
BuffReminder.player_status.combat = false
elseif event == "PLAYER_REGEN_DISABLED" then
BuffReminder.player_status.combat = true
elseif event == "PLAYER_ENTERING_WORLD" then
BuffReminder.player_status.resting = (IsResting() == 1)
BuffReminder.player_status.dead = (UnitIsDeadOrGhost("player") == 1)
BuffReminder.player_status.taxi = (UnitOnTaxi("player") == 1)
BuffReminder.player_status.party = (GetNumPartyMembers() > 0)
BuffReminder.player_status.raid = (GetNumRaidMembers() > 0)
BuffReminder.player_status.combat = false
local isInstance, instanceType = IsInInstance()
BuffReminder.player_status.instance = (instanceType == "party")
BuffReminder.player_status.raid_inst = (instanceType == "raid")
BuffReminder.player_status.pvp_inst = (instanceType == "pvp")
DEFAULT_CHAT_FRAME:AddMessage(tostring(instanceType))
elseif event == "ADDON_LOADED" then
if arg1 == "BuffReminder" then
if BRVars.Options.version == nil or BRVars.Options.version ~= BuffReminder.DefaultOptions.version then
BRVars.Options = BuffReminder.DefaultOptions
else
BuffReminder.SanityCheck()
end
BuffReminderFrame:SetWidth(BRVars.Options.size)
BuffReminderFrame:SetHeight(BRVars.Options.size)
for k, v in pairs(BRVars.BuffGroups) do
if v.script ~= "" then
BuffReminder.scripts[k] = {}
BuffReminder.scripts[k].script = loadstring(v.script)
end
BuffReminder.script_res[k] = false
end
if BRVars.Options.script ~= "" then
BuffReminder.default.script = loadstring(BRVars.Options.script)
end
end
end
BuffReminder.Update() -- force icon update
end
--------------------------------------------------------------------------------------------------
local function printOptions(opts)
for k, v in pairs(opts) do
if type(v) ~= "table" then
DEFAULT_CHAT_FRAME:AddMessage(k .. " = " .. v)
else
DEFAULT_CHAT_FRAME:AddMessage(k .. " = ")
for k2, v2 in pairs(v) do
DEFAULT_CHAT_FRAME:AddMessage(" " .. k2 .. " = " .. tostring(v2))
end
end
end
end
-- copy missing or mistyped options from defaults
function BuffReminder.CopyOptions(cpy)
for k1, v1 in pairs(BuffReminder.DefaultOptions) do
if type(v1) ~= "table" then
if cpy[k1] == nil or type(cpy[k1]) ~= type(v1) then
cpy[k1] = v1
end
else
if type(cpy[k1]) ~= "table" then
DEFAULT_CHAT_FRAME:AddMessage(k1 .. " type is " .. type(cpy[k1]))
cpy[k1] = {}
end
for k2, v2 in pairs(v1) do
if cpy[k1][k2] == nil or type(cpy[k1][k2]) ~= type(v2) then
cpy[k1][k2] = v2
end
end
end
end
end
-- remove unused options
function BuffReminder.CleanOptions(opts)
for k1, v1 in pairs(opts) do
if BuffReminder.DefaultOptions[k1] == nil then
opts[k1] = nil
elseif type(v1) == "table" then
for k2, v2 in pairs(v1) do
if BuffReminder.DefaultOptions[k1][k2] == nil then opts[k1][k2] = nil end
end
end
end
end
function BuffReminder.SanityCheck()
BuffReminder.CopyOptions(BRVars.Options)
BuffReminder.CleanOptions(BRVars.Options)
for i in BRVars.BuffGroups do
if BRVars.BuffGroups[i].conditions == nil then BRVars.BuffGroups[i].conditions = {} end
for j in BuffReminder.DefaultOptions.conditions do
if BRVars.BuffGroups[i].conditions[j] == nil then BRVars.BuffGroups[i].conditions[j] = BuffReminder.DefaultOptions.conditions[j] end
end
if BRVars.BuffGroups[i].script == nil then BRVars.BuffGroups[i].script = "" end
-- fixup old config for new buff/icon key/value
for j in BRVars.BuffGroups[i].buffs do
if type(BRVars.BuffGroups[i].buffs[j]) == "table" then
BRVars.BuffGroups[i].buffs[j] = ""
end
end
end
BRVars.Options.version = BuffReminder.DefaultOptions.version
end