-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPerfectRaid_Buffs.lua
More file actions
1351 lines (1184 loc) · 39.6 KB
/
PerfectRaid_Buffs.lua
File metadata and controls
1351 lines (1184 loc) · 39.6 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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[-------------------------------------------------------------------------
Copyright (c) 2006, Jim Whitehead II <cladhaire@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of PerfectRaid nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------]]
local Buffs = PerfectRaid:NewModule("PerfectRaid-Buffs")
local L = PerfectRaidLocals
local utils, frames
local timerFrame
-- Speed up this module as much as possible
local genv = _G
local PerfectRaid = genv.PerfectRaid
local setmetatable = genv.setmetatable
local pairs = genv.pairs
local table = genv.table
local ipairs = genv.ipairs
local select = genv.select
local UnitClass = genv.UnitClass
local UnitRaid = genv.UnitRace
local GetNumGroupMembers = genv.GetNumGroupMembers
local CreateFrame = genv.CreateFrame
local UIParent = genv.UIParent
local GetRaidRosterInfo = genv.GetRaidRosterInfo
local string = genv.string
local rawset = genv.rawset
local UnitBuff = genv.UnitBuff
local UnitDebuff = genv.UnitDebuff
local unpack = genv.unpack
local GetTime = genv.GetTime
local strjoin = genv.strjoin
function Buffs:Initialize()
PerfectRaid.defaults.profile.buffs = {}
frames = PerfectRaid.frames
utils = PerfectRaid.utils
self:RegisterMessage("DONGLE_PROFILE_CREATED")
self:RegisterMessage("PERFECTRAID_TAB_CHANGED")
end
function Buffs:Enable()
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
if GetNumGroupMembers() > 0 then
self:GROUP_ROSTER_UPDATE()
end
self:UpdateBuffTable()
for unit in pairs(frames) do
self:UNIT_AURA(nil, unit)
end
-- Create a simple OnUpdate timer that triggers an update every second
local updateInterval = 1.0 -- How often the OnUpdate code will run (in seconds)
local elapsedCount = 0
timerFrame = CreateFrame("Frame", "PraidBuffTimerFrame", UIParent);
timerFrame:SetScript("OnUpdate", function(frame, elapsed)
elapsedCount = elapsedCount + elapsed
if elapsedCount > updateInterval then
self:FullUpdate()
timerFrame.TimeSinceLastUpdate = elapsedCount - updateInterval;
end
end)
end
function Buffs:FullUpdate()
for unit in pairs(frames) do
self:UNIT_AURA(nil, unit)
end
end
function Buffs:DONGLE_PROFILE_CREATED(event, db, addon, svname, profileKey)
if svname ~= "PerfectRaidDB" then return end
self:PrintF(L["Adding default buffs to new profile \"%s\""], profileKey)
local buffs = db.profile.buffs
for k,v in ipairs(self.defaults) do
if not v.disabled then
self:AddDefaultBuff(buffs, v)
end
end
end
function Buffs:PERFECTRAID_TAB_CHANGED(old,new)
if PROptions_Buffs_Edit and PROptions_Buffs_Edit:IsVisible() then
self.options:FadeOut(PROptions_Buffs_Edit)
end
end
local raidLookup = {}
for i=1,40 do
raidLookup[i] = "raid"..i
end
function Buffs:GROUP_ROSTER_UPDATE()
if GetNumGroupMembers() > 0 then
for i=1,GetNumGroupMembers() do
local group = select(3, GetRaidRosterInfo(i))
local unit = raidLookup[i]
if UnitIsUnit(unit, "player") then raidLookup.player = group end
raidLookup[unit] = group
end
end
end
function Buffs:ConfigureButton(button)
local font = button:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
button.aura = font
end
function Buffs:UpdateButtonLayout(button, options)
button.aura:ClearAllPoints()
if options.alignright then
button.aura:SetPoint("RIGHT", button.leftbox, "RIGHT", -2, 0)
else
button.aura:SetPoint("LEFT", button.rightbox, "LEFT", 2, 0)
end
end
function Buffs:ShowButton(button)
local unit = button:GetAttribute("unit")
self:UNIT_AURA(nil, unit)
end
local band = bit.band
local buffs = {}
local buffcache = {}
local mybuffs = {}
local mymask = {}
local buffexpiry = {}
local buffstacks = {}
local mystacks = {}
local BIT_CURSE = 1
local BIT_MAGIC = 2
local BIT_POISON = 4
local BIT_DISEASE = 8
local debuffstatus = setmetatable({}, {__index=function(t,k) rawset(t,k,0); return 0 end})
local work = {}
local patterns = setmetatable({}, {__index=function(t,k)
local str = string.rep("%s ", k):sub(1,-2)
rawset(t,k,str)
return str
end})
function Buffs:UNIT_AURA(event, unit)
if not frames[unit] then return end
for k,v in pairs(buffcache) do buffcache[k] = nil end
for k,v in pairs(buffstacks) do buffstacks[k] = nil end
for k,v in pairs(mybuffs) do mybuffs[k] = nil end
for k,v in pairs(mystacks) do mystacks[k] = nil end
for k,v in pairs(buffexpiry) do buffexpiry[k] = nil end
for i=1,40 do
local name,texture,count,dispelType,duration,expires,caster,stealable = UnitBuff(unit, i)
if not name then break end
if caster == "player" then
mybuffs[name] = true
mystacks[name] = (mystacks[name] or 0) + count
buffexpiry[name] = expires
end
buffcache[name] = (buffcache[name] or 0) + 1
buffstacks[name] = (buffstacks[name] or 0) + count
end
local debuffType
for i=1,40 do
local name,texture,count,dispelType,duration,expires,caster = UnitDebuff(unit, i)
if not name and not dispelType then break end
buffcache[name] = (buffcache[name] or 0) + 1
buffstacks[name] = (buffstacks[name] or 0) + count
buffexpiry[name] = expires
if dispelType and name ~= dispelType then
buffcache[dispelType] = (buffcache[dispelType] or 0) + 1
buffstacks[dispelType] = (buffstacks[dispelType] or 0) + count
debuffType = dispelType
end
end
-- Raise any relevant debuff gained/lost messages
local status = debuffstatus[unit]
-- Disease
if buffcache.Disease and band(status, BIT_DISEASE) == 0 then
status = status + BIT_DISEASE
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Disease")
elseif not buffcache.Disease and band(status, BIT_DISEASE) > 0 then
status = status - BIT_DISEASE
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Disease")
end
if buffcache.Poison and band(status, BIT_POISON) == 0 then
status = status + BIT_POISON
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Poison")
elseif not buffcache.Poison and band(status, BIT_POISON) > 0 then
status = status - BIT_POISON
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Poison")
end
if buffcache.Magic and band(status, BIT_MAGIC) == 0 then
status = status + BIT_MAGIC
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Magic")
elseif not buffcache.Magic and band(status, BIT_MAGIC) > 0 then
status = status - BIT_MAGIC
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Magic")
end
if buffcache.Curse and band(status, BIT_CURSE) == 0 then
status = status + BIT_CURSE
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Curse")
elseif not buffcache.Curse and band(status, BIT_CURSE) > 0 then
status = status - BIT_CURSE
self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Curse")
end
-- Update the status
debuffstatus[unit] = status
for k,v in pairs(work) do work[k] = nil end
for i,entry in ipairs(buffs) do
local checkcond = false
-- Determine which spell name we matched
local buffname
if buffcache[entry.buffname] then
buffname = entry.buffname
elseif buffcache[entry.groupname or "nil"] then
buffname = entry.groupname
elseif buffcache[entry.groupname2 or "nil"] then
buffname = entry.groupname2
elseif buffcache[entry.groupname3 or "nil"] then
buffname = entry.groupname3
elseif buffcache[entry.groupname4 or "nil"] then
buffname = entry.groupname4
end
-- How many stacks are there?
local class = select(2, UnitClass(unit))
local conds = self.conditions
local group = raidLookup[unit]
local mine = mybuffs[buffname]
if entry.missing then
if not buffname then
checkcond = true
end
else
if buffname then
if (entry.mine and mine) or not entry.mine then
checkcond = true
end
end
end
-- Handle the condition checking for the buff, taking strictness into account
if checkcond then
if entry.strict then
-- Set up a boolean value so we can trip it if a filter fails
local pass = true
for i,name in pairs(entry.cond) do
if conds[name] and not conds[name](unit, class, group, mine) then
pass = false
end
end
if pass then
self:CreateBuffEntry(buffname, entry)
end
else
-- Simply iterate each of the conditions, and break when we match
for i,name in pairs(entry.cond) do
if conds[name] and conds[name](unit, class, group, mine) then
self:CreateBuffEntry(buffname, entry)
break
end
end
end
end
end
for frame in pairs(frames[unit]) do
frame.aura:SetFormattedText(patterns[#work], unpack(work))
end
end
function Buffs:CreateBuffEntry(buffname, entry)
local expires = buffexpiry[buffname]
local num = buffcache[buffname]
local stacks = buffstacks[buffname]
local mine = mybuffs[buffname]
-- show only my stacks
if entry.onlymine then
stacks = mystacks[buffname]
end
if ( ( num and num > 1 ) or ( stacks and stacks > 1 ) ) and not entry.onlymine then
local num = num
-- If the buff is mine, and it should be masked
-- A buff is masked when there is a "mine" filter set for it
if mine and not mymask[buffname] then
num = num - 1
end
if (expires and entry.showexpiry) and (stacks > 1 and entry.showstacks) then
work[#work + 1] = string.format("%s(%d,%d)", entry.colortext, stacks, -1 * (GetTime()-expires) )
elseif (stacks and stacks > 1 and entry.showstacks) then
work[#work + 1] = string.format("%s(%d)", entry.colortext, stacks )
elseif ( num and expires and entry.showexpiry) then
work[#work + 1] = string.format("%s(%d,%d)", entry.colortext, num, -1 * (GetTime() - expires))
elseif ( num and num > 1 ) then
work[#work + 1] = string.format("%s(%d)", entry.colortext, num)
else
work[#work + 1] = string.format("%s", entry.colortext)
end
else
if (entry.onlymine and not mine) or (not entry.onlymine and mymask[buffname]) then
-- Don't show
else
if (expires and entry.showexpiry) and (stacks > 1 and entry.showstacks) then
work[#work + 1] = string.format("%s(%d,%d)", entry.colortext, stacks, -1 * (GetTime()-expires) )
elseif (stacks and stacks > 1 and entry.showstacks) then
work[#work + 1] = string.format("%s(%d)", entry.colortext, stacks )
elseif (expires and entry.showexpiry) then
work[#work + 1] = string.format("%s(%d)", entry.colortext, -1 * (GetTime()-expires))
else
work[#work + 1] = entry.colortext
end
end
end
end
function Buffs:CreateOptions(opt)
self.options = opt
local options = CreateFrame("Frame", "PROptions_Buffs", PROptions)
opt:AddOptionsTab(L["Buffs/Debuffs"], options)
local num_entries = 19
local scrollframe = opt:CreateListFrame(options, num_entries)
-- Set up double-click handlers
local function OnDoubleClick(button)
button:Click()
self:EditEntry()
end
for i=1,num_entries do
local button = scrollframe.entries[i]
button:SetScript("OnDoubleClick", OnDoubleClick)
end
local update = function()
local list = PerfectRaid.db.profile.buffs
local idx,button
local offset = FauxScrollFrame_GetOffset(scrollframe)
FauxScrollFrame_Update(scrollframe, #list, num_entries, 20)
for i=1,num_entries do
idx = offset + i
local button = scrollframe.entries[i]
if idx <= #list then
local entry = list[idx]
local display = entry.buffname
if entry.groupname then
display = display .. "/"..entry.groupname
end
display = display .. " (|cFF"..entry.color..entry.disptext.."|r)"
if entry.disabled then
display = display .. L[" *** DISABLED ***"]
end
button.line1:SetText(display)
button:Show()
if options.selected == idx then
button:SetChecked(true)
else
button:SetChecked(false)
end
else
button:Hide()
end
end
end
scrollframe.update = update
scrollframe:SetScript("OnVerticalScroll", function(frame, value)
FauxScrollFrame_OnVerticalScroll(frame, value, 20, update)
self:EnableButtons()
end)
scrollframe:SetScript("OnShow", function()
scrollframe.update()
self:EnableButtons()
end)
local postClick = function()
self:EnableButtons()
end
for i,frame in ipairs(scrollframe.entries) do
frame:SetScript("PostClick", postClick)
end
local delete = CreateFrame("Button", "PRBuffs_Delete", options, "PRButtonTemplate")
delete:SetText(L["Delete"])
delete:SetPoint("BOTTOMRIGHT", 0, 5)
delete:SetScript("OnClick", function() self:DeleteEntry() end)
delete:Show()
local edit = CreateFrame("Button", "PRBuffs_Edit", options, "PRButtonTemplate")
edit:SetText(L["Edit"])
edit:SetPoint("BOTTOMRIGHT", delete, "BOTTOMLEFT", -10, 0)
edit:SetScript("OnClick", function() self:EditEntry() end)
edit:Show()
local add = CreateFrame("Button", "PRBuffs_Add", options, "PRButtonTemplate")
add:SetText(L["Add"])
add:SetPoint("BOTTOMRIGHT", edit, "BOTTOMLEFT", -10, 0)
add:SetScript("OnClick", function() self:AddEntry() end)
add:Show()
local disable = CreateFrame("Button", "PRBuffs_Disable", options, "PRButtonTemplate")
disable:SetText(L["Disable"])
disable:SetPoint("BOTTOMRIGHT", add, "BOTTOMLEFT", -10, 0)
disable:SetScript("OnClick", function() self:DisableEntry() end)
disable:Show()
local up = CreateFrame("Button", "PRBuffs_Up", options, "PRButtonTemplate")
up:SetWidth(70)
up:SetText(L["Up"])
up:SetPoint("BOTTOMRIGHT", disable, "BOTTOMLEFT", -10, 0)
up:SetScript("OnClick", function() self:MoveEntry("UP") end)
up:Show()
local down = CreateFrame("Button", "PRBuffs_Down", options, "PRButtonTemplate")
down:SetWidth(70)
down:SetText(L["Down"])
down:SetPoint("BOTTOMRIGHT", up, "BOTTOMLEFT", -10, 0)
down:SetScript("OnClick", function() self:MoveEntry("DOWN") end)
down:Show()
self:CreateEditFrame(options)
end
function Buffs:CreateEditFrame(parent)
local frame = CreateFrame("Frame", "PROptions_Buffs_Edit", PROptions)
local name = "PROptions_Buffs_Edit"
-- frame:SetPoint("TOPLEFT", 15, -25)
-- frame:SetPoint("BOTTOMRIGHT", -15, 15)
frame:SetAllPoints(PROptions_Buffs)
frame:SetFrameLevel(frame:GetFrameLevel() + 1)
frame:Hide()
local buffname = CreateFrame("EditBox", name.."BuffName", frame, "InputBoxTemplate")
local font = buffname:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
font:SetText(L["Buff Name:"])
font:SetPoint("BOTTOMLEFT", buffname, "TOPLEFT", 0, 3)
buffname:SetPoint("TOPLEFT", 0, -10)
buffname:SetAutoFocus(nil)
buffname:SetWidth(180)
buffname:SetHeight(20)
buffname:Show()
frame.buffname = buffname
local groupname1 = CreateFrame("EditBox", name.."GroupName", frame, "InputBoxTemplate")
local groupname2 = CreateFrame("EditBox", name.."GroupName2", frame, "InputBoxTemplate")
local groupname3 = CreateFrame("EditBox", name.."GroupName3", frame, "InputBoxTemplate")
local groupname4 = CreateFrame("EditBox", name.."GroupName4", frame, "InputBoxTemplate")
local font = groupname1:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
-- label
font:SetText(L["Buffs that share the same effect:"])
font:SetPoint("BOTTOMLEFT", groupname1, "TOPLEFT", 0, 3)
-- share/group name 1
groupname1:SetPoint("TOPLEFT", 230, -10)
groupname1:SetAutoFocus(nil)
groupname1:SetWidth(200)
groupname1:SetHeight(20)
groupname1:Show()
frame.groupname1 = groupname1
-- share/group name 2
groupname2:SetPoint("TOPLEFT", groupname1, "BOTTOMLEFT", 0, -2)
groupname2:SetAutoFocus(nil)
groupname2:SetWidth(200)
groupname2:SetHeight(20)
groupname2:Show()
frame.groupname2 = groupname2
-- share/group name 3
groupname3:SetPoint("TOPLEFT", groupname2, "BOTTOMLEFT", 0, -2)
groupname3:SetAutoFocus(nil)
groupname3:SetWidth(200)
groupname3:SetHeight(20)
groupname3:Show()
frame.groupname3 = groupname3
-- share/group name 4
groupname4:SetPoint("TOPLEFT", groupname3, "BOTTOMLEFT", 0, -2)
groupname4:SetAutoFocus(nil)
groupname4:SetWidth(200)
groupname4:SetHeight(20)
groupname4:Show()
frame.groupname4 = groupname4
local disptext = CreateFrame("EditBox", name.."DispText", frame, "InputBoxTemplate")
local font = disptext:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
font:SetText(L["Display Text:"])
font:SetPoint("BOTTOMLEFT", disptext, "TOPLEFT", 0, 3)
disptext:SetPoint("TOPLEFT", 0, -54)
disptext:SetAutoFocus(nil)
disptext:SetWidth(180)
disptext:SetHeight(20)
disptext:Show()
frame.disptext = disptext
-- Color Swatch
local function colorSwatchCancel()
local self = ColorPickerFrame.object;
local r, g, b = self.r, self.g, self.b;
self.normalTexture:SetVertexColor(r, g, b);
end
local function colorSwatchColor()
local self = ColorPickerFrame.object;
local r, g, b = ColorPickerFrame:GetColorRGB();
self.normalTexture:SetVertexColor(r, g, b);
self.color[1] = r
self.color[2] = g
self.color[3] = b
disptext:SetTextColor(r,g,b)
end
local function colorSwatchOpacity()
local self = ColorPickerFrame.object;
local a = OpacitySliderFrame:GetValue();
end
local function colorSwatchShow(self)
local r, g, b, a;
self.color = self.color or {1,1,1}
local color = self.color;
if ( color ) then
r, g, b, a = unpack(color);
end
self.r, self.g, self.b = r, g, b
self.opacityFunc = colorSwatchOpacity;
self.swatchFunc = colorSwatchColor;
self.cancelFunc = colorSwatchCancel;
ColorPickerFrame.object = self;
UIDropDownMenuButton_OpenColorPicker(self);
ColorPickerFrame:SetFrameStrata("TOOLTIP");
ColorPickerFrame:Raise();
end
local function colorSwatchOnClick(self)
CloseMenus();
colorSwatchShow(self);
end
local function colorSwatchOnEnter(self)
self.bg:SetVertexColor(1, 0.82, 0);
end
local function colorSwatchOnLeave(self)
self.bg:SetVertexColor(1, 1, 1);
end
local swatch = CreateFrame("Button", "PRColorSelect", frame);
swatch:SetHeight(20) swatch:SetWidth(20)
swatch:SetPoint("LEFT", disptext, "RIGHT", 5, 0)
local bg = swatch:CreateTexture(nil, "BACKGROUND");
local normalTexture = swatch:CreateTexture(nil, "ARTWORK");
frame.color = swatch
normalTexture:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch");
normalTexture:SetAllPoints(swatch);
swatch:SetNormalTexture(normalTexture);
bg:SetTexture(.2,.2,.2);
bg:SetPoint("TOPLEFT", swatch, 1, -1);
bg:SetPoint("BOTTOMRIGHT", swatch, 0, 1);
normalTexture:SetVertexColor(1,1,1)
swatch.bg, swatch.normalTexture = bg, normalTexture;
swatch.object, swatch.hasAlpha = self, 1
swatch:SetScript("OnLeave", colorSwatchOnLeave);
swatch:SetScript("OnEnter", colorSwatchOnEnter);
swatch:SetScript("OnClick", colorSwatchOnClick);
buffname:SetScript("OnTabPressed", function() if IsShiftKeyDown() then disptext:SetFocus() else groupname1:SetFocus() end end)
groupname1:SetScript("OnTabPressed", function() if IsShiftKeyDown() then buffname:SetFocus() else groupname2:SetFocus() end end)
groupname2:SetScript("OnTabPressed", function() if IsShiftKeyDown() then groupname1:SetFocus() else groupname3:SetFocus() end end)
groupname3:SetScript("OnTabPressed", function() if IsShiftKeyDown() then groupname2:SetFocus() else groupname4:SetFocus() end end)
groupname4:SetScript("OnTabPressed", function() if IsShiftKeyDown() then groupname3:SetFocus() else disptext:SetFocus() end end)
disptext:SetScript("OnTabPressed", function() if IsShiftKeyDown() then groupname4:SetFocus() else buffname:SetFocus() end end)
local function makeCheck(value)
local button = CreateFrame("CheckButton", "PRBuffCond_"..value, PROptions_Buffs_Edit, "PRCheckTemplate")
button.Label:SetText(value)
button.value = value
return button
end
PROptions_Buffs_Edit.checks = {}
local checks = PROptions_Buffs_Edit.checks
-- Build condition checkboxes
checks[1] = makeCheck(self.conditions[1])
checks[1]:SetPoint("TOPLEFT", disptext, "BOTTOMLEFT", 0, -40)
checks[1]:Show()
for i=2,6 do
checks[i] = makeCheck(self.conditions[i])
checks[i]:SetPoint("TOPLEFT", checks[i-1], "TOPRIGHT", 75, 0)
checks[i]:Show()
end
checks[7] = makeCheck(self.conditions[7])
checks[7]:SetPoint("TOPLEFT", checks[1], "BOTTOMLEFT", 0, -5)
checks[7]:Show()
for i=8,12 do
checks[i] = makeCheck(self.conditions[i])
checks[i]:SetPoint("TOPLEFT", checks[i-1], "TOPRIGHT", 75, 0)
checks[i]:Show()
end
checks[13] = makeCheck(self.conditions[13])
checks[13]:SetPoint("TOPLEFT", checks[7], "BOTTOMLEFT", 0, -5)
checks[13]:Show()
for i=14,18 do
checks[i] = makeCheck(self.conditions[i])
checks[i]:SetPoint("TOPLEFT", checks[i-1], "TOPRIGHT", 75, 0)
checks[i]:Show()
end
checks[19] = makeCheck(self.conditions[19])
checks[19]:SetPoint("TOPLEFT", checks[13], "BOTTOMLEFT", 0, -5)
checks[19]:Show()
for i=20,22 do
checks[i] = makeCheck(self.conditions[i])
checks[i]:SetPoint("TOPLEFT", checks[i-1], "TOPRIGHT", 75, 0)
checks[i]:Show()
end
local cancel = CreateFrame("Button", "PRBuffs_EditCancel", PROptions_Buffs_Edit, "PRButtonTemplate")
cancel:SetText(L["Cancel"])
cancel:SetPoint("BOTTOMRIGHT", 0, 5)
cancel:SetScript("OnClick", function() self:CancelEntry() end)
cancel:Show()
local save = CreateFrame("Button", "PRBuffs_EditSave", PROptions_Buffs_Edit, "PRButtonTemplate")
save:SetText(L["Save"])
save:SetPoint("BOTTOMRIGHT", cancel, "BOTTOMLEFT", -10, 0)
save:SetScript("OnClick", function() self:SaveEntry() end)
save:Show()
local missing = CreateFrame("CheckButton", "PRBuffs_Missing", PROptions_Buffs_Edit, "PRCheckTemplate")
missing.Label:SetText(L["Only show if this buff is missing"])
missing:SetPoint("BOTTOMLEFT", 0, 10)
missing:Show()
frame.missing = missing
local strict = CreateFrame("CheckButton", "PRBuffs_Strict", PROptions_Buffs_Edit, "PRCheckTemplate")
strict.Label:SetText(L["Make filters strict"])
strict:SetPoint("BOTTOMLEFT", missing, "TOPLEFT", 0, 0)
strict:Show()
frame.strict = strict
local disabled = CreateFrame("CheckButton", "PRBuffs_Disabled", PROptions_Buffs_Edit, "PRCheckTemplate")
disabled.Label:SetText(L["Do not check this buff (Disable)"])
disabled:SetPoint("BOTTOMLEFT", strict, "TOPLEFT", 0, 0)
disabled:Show()
frame.disabled = disabled
local onlymine = CreateFrame("CheckButton", "PRBuffs_OnlyMine", PROptions_Buffs_Edit, "PRCheckTemplate")
onlymine.Label:SetText(L["Only show my buffs"])
onlymine:SetPoint("TOPLEFT", disabled, "TOPRIGHT", 200, 0)
onlymine:Show()
frame.onlymine = onlymine
local showexpiry = CreateFrame("CheckButton", "PRBuffs_ShowExpiry", PROptions_Buffs_Edit, "PRCheckTemplate")
showexpiry.Label:SetText(L["Show expiry"])
showexpiry:SetPoint("TOPLEFT", strict, "TOPRIGHT", 200, 0)
showexpiry:Show()
frame.showexpiry = showexpiry
local showstacks = CreateFrame("CheckButton", "PRBuffs_ShowStacks", PROptions_Buffs_Edit, "PRCheckTemplate")
showstacks.Label:SetText(L["Show stacks"])
showstacks:SetPoint("TOPLEFT", missing, "TOPRIGHT", 200, 0)
showstacks:Show()
frame.showstacks = showstacks
local dropdown = CreateFrame("Frame", "PRBuffs_Dropdown", PROptions_Buffs_Edit, "UIDropDownMenuTemplate")
dropdown:SetID(1)
dropdown:SetPoint("BOTTOMRIGHT", -115, 80)
dropdown:SetScript("OnShow", function() self:DropDown_OnShow() end)
PRBuffs_DropdownButton:SetScript("OnClick", function() ToggleDropDownMenu(nil, nil, PRBuffs_Dropdown, "cursor") end)
UIDropDownMenu_SetText(dropdown, L["Auto-fill Default"])
end
function Buffs:FillEntry(entry)
local options = PROptions_Buffs_Edit
options.buffname:SetText(entry.buffname)
options.groupname1:SetText(entry.groupname or "")
options.groupname2:SetText(entry.groupname2 or "")
options.groupname3:SetText(entry.groupname3 or "")
options.groupname4:SetText(entry.groupname4 or "")
options.disptext:SetText(entry.disptext)
options.disptext:SetTextColor(utils.HexToRGBPerc(entry.color))
PRColorSelect.normalTexture:SetVertexColor(utils.HexToRGBPerc(entry.color))
local cond = {string.split(",", entry.conds)}
for k,v in ipairs(cond) do
cond[v] = true
end
for idx,button in ipairs(PROptions_Buffs_Edit.checks) do
if cond[button.value] then
button:SetChecked(true)
else
button:SetChecked(false)
end
end
options.missing:SetChecked(entry.missing)
options.disabled:SetChecked(entry.disabled)
options.strict:SetChecked(entry.strict)
options.onlymine:SetChecked(entry.onlymine)
options.showstacks:SetChecked(entry.showstacks)
options.showexpiry:SetChecked(entry.showexpiry)
end
function Buffs:EditEntry()
local scrollframe = PROptions_BuffsScrollFrame
local offset = FauxScrollFrame_GetOffset(scrollframe)
local selected = PROptions_Buffs.selected
local entry = PerfectRaid.db.profile.buffs[selected]
local options = PROptions_Buffs_Edit
options.editEntry = entry
self.options:FadeOut(PROptions_Buffs)
self.options:FadeIn(options)
self:FillEntry(entry)
end
function Buffs:MoveEntry(direction)
local selected = PROptions_Buffs.selected
local destination
if direction == "UP" then
destination = selected - 1
else
destination = selected + 1
end
local tmp = PerfectRaid.db.profile.buffs[destination]
PerfectRaid.db.profile.buffs[destination] = PerfectRaid.db.profile.buffs[selected]
PerfectRaid.db.profile.buffs[selected] = tmp
PROptions_Buffs.selected = destination
PROptions_BuffsScrollFrame.update()
self:EnableButtons()
self:UpdateBuffTable()
end
function Buffs:DisableEntry()
local scrollframe = PROptions_BuffsScrollFrame
local offset = FauxScrollFrame_GetOffset(scrollframe)
local selected = PROptions_Buffs.selected
local entry = PerfectRaid.db.profile.buffs[selected]
entry.disabled = not entry.disabled
scrollframe.update()
self:EnableButtons()
self:UpdateBuffTable()
end
function Buffs:AddEntry()
local options = PROptions_Buffs_Edit
self.options:FadeOut(PROptions_Buffs)
self.options:FadeIn(options)
options.buffname:SetText("")
options.groupname1:SetText("")
options.groupname2:SetText("")
options.groupname3:SetText("")
options.groupname4:SetText("")
options.disptext:SetText("")
options.disptext:SetTextColor(1,1,1)
PRColorSelect.normalTexture:SetVertexColor(1,1,1)
for idx,button in ipairs(PROptions_Buffs_Edit.checks) do
button:SetChecked(false)
end
options.missing:SetChecked(false)
options.disabled:SetChecked(false)
options.strict:SetChecked(false)
options.onlymine:SetChecked(false)
options.showstacks:SetChecked(false)
options.showexpiry:SetChecked(false)
options.buffname:SetFocus()
end
function Buffs:DeleteEntry()
local scrollframe = PROptions_BuffsScrollFrame
local offset = FauxScrollFrame_GetOffset(scrollframe)
local selected = PROptions_Buffs.selected
table.remove(PerfectRaid.db.profile.buffs, selected)
PROptions_Buffs.selected = nil
scrollframe.update()
self:EnableButtons()
self:UpdateBuffTable()
end
function Buffs:UpdateBuffTable()
for k,v in pairs(buffs) do buffs[k] = nil end
for k,v in pairs(mymask) do mymask[k] = nil end
for idx,entry in ipairs(PerfectRaid.db.profile.buffs) do
if not entry.disabled then
local tbl = {}
tbl.buffname = entry.buffname
tbl.groupname = entry.groupname
tbl.groupname2 = entry.groupname2
tbl.groupname3 = entry.groupname3
tbl.groupname4 = entry.groupname4
tbl.colortext = "|cFF"..entry.color..tostring(entry.disptext).."|r"
tbl.missing = entry.missing
tbl.strict = entry.strict
tbl.cond = {string.split(",", entry.conds)}
tbl.onlymine = entry.onlymine
tbl.showstacks = entry.showstacks
tbl.showexpiry = entry.showexpiry
if tbl.onlymine then
mymask[tbl.buffname] = true
if entry.groupname then
mymask[tbl.groupname] = true
end
end
table.insert(buffs, tbl)
end
end
for unit in pairs(frames) do
self:UNIT_AURA(nil, unit)
end
end
function Buffs:SaveEntry()
local frame = PROptions_Buffs_Edit
local buffname = frame.buffname:GetText()
local groupname1 = frame.groupname1:GetText()
local groupname2 = frame.groupname2:GetText()
local groupname3 = frame.groupname3:GetText()
local groupname4 = frame.groupname4:GetText()
local disptext = frame.disptext:GetText()
local err
if buffname == "" then
err = "You must supply a buff name"
elseif disptext == "" then
err = "You must supply a display text"
end
if err then
StaticPopupDialogs["PR_BUFF_SAVE_ERROR"].text = err
StaticPopup_Show("PR_BUFF_SAVE_ERROR")
return
end
if groupname1 == "" then groupname1 = nil end
if groupname2 == "" then groupname2 = nil end
if groupname3 == "" then groupname3 = nil end
if groupname4 == "" then groupname4 = nil end
local options = PROptions_Buffs_Edit
local entry = options.editEntry or {}
entry.buffname = buffname
entry.groupname = groupname1
entry.groupname2 = groupname2
entry.groupname3 = groupname3
entry.groupname4 = groupname4
entry.disptext = disptext
local work = {}
for idx,button in ipairs(PROptions_Buffs_Edit.checks) do
if button:GetChecked() then
table.insert(work, button.value)
end
end
local conds = strjoin(",", unpack(work))
entry.conds = conds
entry.missing = frame.missing:GetChecked()
entry.disabled = frame.disabled:GetChecked()
entry.strict = frame.strict:GetChecked()
entry.onlymine = frame.onlymine:GetChecked()
entry.showstacks = frame.showstacks:GetChecked()
entry.showexpiry = frame.showexpiry:GetChecked()
local color = utils.RGBPercToHex(frame.disptext:GetTextColor())
entry.color = color
if not options.editEntry then
table.insert(PerfectRaid.db.profile.buffs, entry)
end
options.editEntry = nil
self:CancelEntry()
PROptions_BuffsScrollFrame.update()
self:UpdateBuffTable()
end
function Buffs:CancelEntry()
local options = PROptions_Buffs_Edit
self.options:FadeOut(options)
options.editEntry = nil
self.options:FadeIn(PROptions_Buffs)
end
function Buffs:EnableButtons()
local selected = PROptions_Buffs.selected
if selected then
PRBuffs_Edit:Enable()
PRBuffs_Delete:Enable()
PRBuffs_Disable:Enable()
PRBuffs_Up:Enable()
PRBuffs_Down:Enable()
-- Change enable/disable
local scrollframe = PROptions_BuffsScrollFrame
local offset = FauxScrollFrame_GetOffset(scrollframe)
local selected = PROptions_Buffs.selected
local entry = PerfectRaid.db.profile.buffs[selected]
if selected == 1 then
PRBuffs_Up:Disable()
end
if selected == #PerfectRaid.db.profile.buffs then
PRBuffs_Down:Disable()
end
if entry.disabled then
PRBuffs_Disable:SetText(L["Enable"])
else
PRBuffs_Disable:SetText(L["Disable"])