-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDcr_DebuffsFrame.lua
1876 lines (1428 loc) · 70.3 KB
/
Dcr_DebuffsFrame.lua
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
--[[
This file is part of Decursive.
Decursive (v @project-version@) add-on for World of Warcraft UI
Copyright (C) 2006-2025 John Wellesz (Decursive AT 2072productions.com) ( http://www.2072productions.com/to/decursive.php )
Decursive is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Decursive is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Decursive. If not, see <https://www.gnu.org/licenses/>.
Decursive is inspired from the original "Decursive v1.9.4" by Patrick Bohnet (Quu).
The original "Decursive 1.9.4" is in public domain ( www.quutar.com )
Decursive is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
This file was last updated on @file-date-iso@
--]]
-------------------------------------------------------------------------------
local addonName, T = ...;
-- big ugly scary fatal error message display function {{{
if not T._FatalError then
-- the beautiful error popup : {{{ -
StaticPopupDialogs["DECURSIVE_ERROR_FRAME"] = {
text = "|cFFFF0000Decursive Error:|r\n%s",
button1 = "OK",
OnAccept = function()
return false;
end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1,
preferredIndex = 3,
}; -- }}}
T._FatalError = function (TheError) StaticPopup_Show ("DECURSIVE_ERROR_FRAME", TheError); end
end
-- }}}
if not T._LoadedFiles or not T._LoadedFiles["Dcr_lists.xml"] or not T._LoadedFiles["Dcr_lists.lua"] then -- XML are loaded even if LUA syntax errors exixts
if not DecursiveInstallCorrupted then T._FatalError("Decursive installation is corrupted! (Dcr_lists.xml or Dcr_lists.lua not loaded)"); end;
DecursiveInstallCorrupted = true;
return;
end
T._LoadedFiles["Dcr_DebuffsFrame.lua"] = false;
local D = T.Dcr;
local L = D.L;
local LC = D.LC;
local DC = T._C;
local _G = _G;
local setmetatable = _G.setmetatable;
local unpack = _G.unpack;
local select = _G.select;
local pairs = _G.pairs;
local ipairs = _G.ipairs;
local bit = _G.bit;
local GetTime = _G.GetTime;
local IsControlKeyDown = _G.IsControlKeyDown;
local IsAltKeyDown = _G.IsAltKeyDown;
local IsShiftKeyDown = _G.IsShiftKeyDown;
local floor = _G.math.floor;
local table = _G.table;
local t_insert = _G.table.insert;
local UnitExists = _G.UnitExists;
local UnitClass = _G.UnitClass;
local fmod = _G.math.fmod;
local UnitIsUnit = _G.UnitIsUnit;
local InCombatLockdown = _G.InCombatLockdown;
local GetRaidTargetIndex= _G.GetRaidTargetIndex;
local CreateFrame = _G.CreateFrame;
-- NS def
D.MicroUnitF = {};
-- create a shortcut
local MicroUnitF = D.MicroUnitF;
MicroUnitF.prototype = {};
MicroUnitF.metatable ={ __index = MicroUnitF.prototype };
function MicroUnitF:new(...)
local instance = setmetatable({}, self.metatable);
instance:init(...);
return instance;
end
-- Init object factory defaults
--MicroUnitF.ExistingPerID = {};
MicroUnitF.ExistingPerUNIT = {};
MicroUnitF.UnitToMUF = {};
MicroUnitF.Number = 0;
MicroUnitF.UnitShown = 0;
MicroUnitF.UnitsDebuffedInRange = 0;
MicroUnitF.DraggingHandle = false;
D.ForLLDebuffedUnitsNum = 0;
-- using power 2 values just to OR them but only CHARMED_STATUS is ORed (it's a C style bitfield)
local NORMAL = DC.NORMAL;
local ABSENT = DC.ABSENT;
local FAR = DC.FAR;
local STEALTHED = DC.STEALTHED;
local BLACKLISTED = DC.BLACKLISTED;
local AFFLICTED = DC.AFFLICTED;
local AFFLICTED_NIR = DC.AFFLICTED_NIR;
local CHARMED_STATUS = DC.CHARMED_STATUS;
local AFFLICTED_AND_CHARMED = DC.AFFLICTED_AND_CHARMED;
local EMPTY_TABLE = DC.EMPTY_TABLE;
-- Those are the different colors used for the MUFs main texture
local MF_colors = { };
DC.MouseButtonsReadable = { -- {{{
["*%s1"] = L["HLP_LEFTCLICK"], -- left mouse button
["*%s2"] = L["HLP_RIGHTCLICK"], -- right mouse button
["*%s3"] = L["HLP_MIDDLECLICK"], -- middle mouse button
["*%s4"] = L["HLP_MOUSE4"], -- 4th mouse button
["*%s5"] = L["HLP_MOUSE5"], -- 5th mouse button
["ctrl-%s1"] = L["CTRL"] .. "-" .. L["HLP_LEFTCLICK"],
["ctrl-%s2"] = L["CTRL"] .. "-" .. L["HLP_RIGHTCLICK"],
["ctrl-%s3"] = L["CTRL"] .. "-" .. L["HLP_MIDDLECLICK"],
["ctrl-%s4"] = L["CTRL"] .. "-" .. L["HLP_MOUSE4"],
["ctrl-%s5"] = L["CTRL"] .. "-" .. L["HLP_MOUSE5"],
["shift-%s1"] = L["SHIFT"] .. "-" .. L["HLP_LEFTCLICK"],
["shift-%s2"] = L["SHIFT"] .. "-" .. L["HLP_RIGHTCLICK"],
["shift-%s3"] = L["SHIFT"] .. "-" .. L["HLP_MIDDLECLICK"],
["shift-%s4"] = L["SHIFT"] .. "-" .. L["HLP_MOUSE4"],
["shift-%s5"] = L["SHIFT"] .. "-" .. L["HLP_MOUSE5"],
["alt-%s1"] = L["ALT"] .. "-" .. L["HLP_LEFTCLICK"],
["alt-%s2"] = L["ALT"] .. "-" .. L["HLP_RIGHTCLICK"],
["alt-%s3"] = L["ALT"] .. "-" .. L["HLP_MIDDLECLICK"],
["alt-%s4"] = L["ALT"] .. "-" .. L["HLP_MOUSE4"],
["alt-%s5"] = L["ALT"] .. "-" .. L["HLP_MOUSE5"],
}; -- }}}
-- modifier for the macro
local AvailableModifier = { -- {{{
"shift","ctrl","alt",
} -- }}}
-- MicroUnitF STATIC methods {{{
function MicroUnitF:Show()
-- change handle position here depending on reverse display option or in INIT?
D.MFContainer:SetScale(D.profile.DebuffsFrameElemScale);
self:Place (); -- not strickly necessary but avoid glitches when switching between profiles where the scale is different...
D.MFContainer:Show();
D.profile.ShowDebuffsFrame = true;
self:ResetAllPositions();
end
-- Updates the color table
function MicroUnitF:RegisterMUFcolors ()
-- MF_colors = D.profile.MF_colors; -- this should be enough but is not because D.profile can change at unexpected times....
D:tcopy(MF_colors, D.profile.MF_colors);
end
function MicroUnitF:GetFarthestVerticalMUF()
-- "Everything pushes me further away..."
if D.profile.DebuffsFrameVerticalDisplay then
if self.UnitShown > D.profile.DebuffsFramePerline then
return D.profile.DebuffsFramePerline;
else
return self.UnitShown;
end
else
if self.UnitShown > D.profile.DebuffsFramePerline then
return floor( self.UnitShown / D.profile.DebuffsFramePerline ) * D.profile.DebuffsFramePerline
+ ((self.UnitShown % D.profile.DebuffsFramePerline ~= 0) and 1 or - D.profile.DebuffsFramePerline + 1);
else
return 1;
end
end
end
-- defines what is printed when the object is read as a string
function MicroUnitF:ToString() -- {{{
return "Decursive Micro Unit Frame Object";
end -- }}}
-- The Factory for MicroUnitF objects
function MicroUnitF:Create(Unit, ID) -- {{{
if InCombatLockdown() then
-- if we are fighting, postpone the call
D:AddDelayedFunctionCall (
"Create"..Unit, self.Create,
Unit, ID);
return false;
end
if self.ExistingPerUNIT[Unit] then
return false;
end
-- create a new MUF object
self.ExistingPerUNIT[Unit] = self:new(D.MFContainer, Unit, self.Number + 1, ID);
self.Number = self.Number + 1;
return self.ExistingPerUNIT[Unit];
end -- }}}
-- return the number MUFs we can use
function MicroUnitF:MFUsableNumber () -- {{{
return ((self.MaxUnit > D.Status.UnitNum) and D.Status.UnitNum or self.MaxUnit);
end -- }}}
-- this is used when a setting influencing MUF's position is changed
function MicroUnitF:ResetAllPositions () -- {{{
-- Lua is great...
D:ScheduleDelayedCall("Dcr_MicroUnitF_ResetAllPositions", function()
if InCombatLockdown() then
D:AddDelayedFunctionCall (
"ResetAllPositions", self.ResetAllPositions,
self);
return false;
end
if self:MFsDisplay_Update () == false then
D:Debug("ResetAllPositions(): |cFFFFAA33We are not ready, let's call ourself back later...|r"); -- LOL
self:ResetAllPositions();
return false;
end
local Unit_Array = D.Status.Unit_Array;
D:Debug("Resetting all MF position", 'perRow:', D.profile.DebuffsFramePerline, '#Unit_Array:', #Unit_Array);
for i=1, #Unit_Array do
local MF = self.ExistingPerUNIT[ Unit_Array[i] ]
if MF then
MF.Frame:SetPoint(unpack(self:GetMUFAnchor(i)));
end
end
self:Place();
return true;
end, 0.5);
end -- }}}
-- return the anchor of a given MUF depending on its creation ID
do
local Anchor = { "BOTTOMLEFT", 0, 0, "BOTTOMLEFT" };
function MicroUnitF:GetMUFAnchor (ID) -- {{{
local RowNum, NumOnRow
if not D.profile.DebuffsFrameVerticalDisplay then
RowNum = floor( (ID - 1) / D.profile.DebuffsFramePerline);
NumOnRow = fmod( (ID - 1), D.profile.DebuffsFramePerline);
else
RowNum = fmod( (ID - 1), D.profile.DebuffsFramePerline );
NumOnRow = floor( (ID - 1) / D.profile.DebuffsFramePerline );
end
local x = NumOnRow * (DC.MFSIZE + D.profile.DebuffsFrameXSpacing);
local y = (D.profile.DebuffsFrameGrowToTop and 1 or -1) * RowNum * (D.profile.DebuffsFrameYSpacing + DC.MFSIZE);
Anchor[2] = x; Anchor[3] = y;
return Anchor;
end
function MicroUnitF:GetHelperAnchor (atBottom)
if atBottom then
-- set Anchor table
self:GetMUFAnchor(D.profile.DebuffsFrameGrowToTop and 1 or self:GetFarthestVerticalMUF());
Anchor[3] = Anchor[3] - (D.profile.DebuffsFrameYSpacing + DC.MFSIZE);
return "TOPLEFT", self.Frame, Anchor[2], Anchor[3], "BOTTOMLEFT";
else
-- set Anchor table
self:GetMUFAnchor(D.profile.DebuffsFrameGrowToTop and self:GetFarthestVerticalMUF() or 1);
Anchor[3] = Anchor[3] + (D.profile.DebuffsFrameYSpacing + DC.MFSIZE);
return "BOTTOMLEFT", self.Frame, Anchor[2], Anchor[3], "BOTTOMLEFT";
end
end
end-- }}}
function MicroUnitF:Delayed_MFsDisplay_Update ()
if D.profile.ShowDebuffsFrame then
D:ScheduleDelayedCall("Dcr_Delayed_MFsDisplay_Update", self.MFsDisplay_Update, 1.5, self);
end
end
-- This update the MUFs display, show and hide MUFs as necessary
function MicroUnitF:MFsDisplay_Update () -- {{{
if (not D.profile.ShowDebuffsFrame) then
return;
end
-- This function cannot do anything if we are fighting
if InCombatLockdown() then
-- if we are fighting, postpone the call
D:AddDelayedFunctionCall (
"UpdateMicroUnitFrameDisplay", self.MFsDisplay_Update,
self);
return false;
end
-- Get an up to date unit array if necessary
D:GetUnitArray(); -- this is the only place where GetUnitArray() is called directly
-- =======
-- Begin
-- =======
-- get the number of MUFs we should display
local NumToShow = self:MFUsableNumber();
-- if we don't have all the MUFs needed then return, we are not ready
if (self.Number < NumToShow) then
self:Delayed_MFsDisplay_Update ();
return false;
end
local MF = false;
local i = 1;
local Old_UnitShown = self.UnitShown;
D:Debug("Update required: NumToShow = ", NumToShow);
local Unit_Array_UnitToGUID = D.Status.Unit_Array_UnitToGUID;
local Unit_Array = D.Status.Unit_Array;
-- Scan unit array in display order and show the maximum until NumToShow is reached
-- The ID is set for all MUFs present in our unit array
local Updated = 0;
for i, Unit in ipairs(Unit_Array) do
MF = self.ExistingPerUNIT[Unit];
if MF then
MF.ID = i;
if not MF.Shown and i <= NumToShow then -- we got this unit in our group but it's hidden
MF.Shown = true;
self.UnitShown = self.UnitShown + 1;
MF.ToPlace = true;
Updated = Updated + 1;
D:ScheduleDelayedCall("Dcr_Update"..MF.CurrUnit, MF.UpdateWithCS, D.db.global.DebuffsFrameRefreshRate * (0.9 + Updated / D.db.global.DebuffsFramePerUPdate), MF);
--D:Debug("|cFF88AA00Show schedule for MUF", Unit, "UnitShown:", self.UnitShown);
end
else
--D:errln("showhide: no muf for", Unit); -- call delay display up
self:Delayed_MFsDisplay_Update ();
end
end
-- hide remaining units
if self.UnitShown > NumToShow then
for Unit, MF in pairs(self.ExistingPerUNIT) do -- see all the MUF we ever created and show or hide them if there corresponding unit exists
-- hide
if MF.Shown and (not Unit_Array_UnitToGUID[Unit] or MF.ID > NumToShow ) then -- we don't have this unit but its MUF is shown
-- clear debuff before hiding to avoid leaving 'ghosts' behind... that would reappear briefly when the unit comes back
if D.UnitDebuffed[MF.CurrUnit] then
D.UnitDebuffed[MF.CurrUnit] = false; -- used by the live-list only
D.ForLLDebuffedUnitsNum = D.ForLLDebuffedUnitsNum - 1;
end
MF.Debuffs = EMPTY_TABLE;
MF.Debuff1Prio = false;
MF.PrevDebuff1Prio = false;
D.Stealthed_Units[MF.CurrUnit] = false;
MF.Shown = false;
self.UnitShown = self.UnitShown - 1;
--D:Debug("|cFF88AA00Hiding %d (%s), scheduling update in %f|r", i, MF.CurrUnit, D.db.global.DebuffsFrameRefreshRate * i);
Updated = Updated + 1;
D:ScheduleDelayedCall("Dcr_Update"..MF.CurrUnit, MF.Update, D.db.global.DebuffsFrameRefreshRate * (0.9 + Updated / D.db.global.DebuffsFramePerUPdate), MF);
MF.Frame:Hide();
end
end
end
-- manage to get what we show in the screen
if self.UnitShown > 0 and Old_UnitShown ~= self.UnitShown then
MicroUnitF:Place();
end
return true;
end -- }}}
function MicroUnitF:Delayed_Force_FullUpdate ()
if (D.profile.ShowDebuffsFrame) then
D:ScheduleDelayedCall("Dcr_Force_FullUpdate", self.Force_FullUpdate, 0.3, self);
end
end
function MicroUnitF:Force_FullUpdate () -- {{{
if (not D.profile.ShowDebuffsFrame) then
return false;
end
-- This function cannot do anything if we are fighting
if InCombatLockdown() then
-- if we are fighting, postpone the call
D:AddDelayedFunctionCall (
"Force_FullUpdate", self.Force_FullUpdate,
self);
return false;
end
D.Status.SpellsChanged = GetTime(); -- will force an update of all MUFs attributes
D.MicroUnitF.UnitsDebuffedInRange = 0; -- reset this now since we are no longer able to maintain it.
local i = 1;
for Unit, MF in pairs(self.ExistingPerUNIT) do
--if not MF.Debuffs[1] then
MF.UnitStatus = 0; -- reset status to force SetColor to update
--end
MF.CenterFontString:SetTextColor(unpack(MF_colors["COLORCHRONOS"]));
MF.InnerTexture:SetColorTexture(unpack(MF_colors[CHARMED_STATUS]));
D:ScheduleDelayedCall("Dcr_Update"..MF.CurrUnit, MF.UpdateWithCS, D.db.global.DebuffsFrameRefreshRate * (0.9 + i / D.db.global.DebuffsFramePerUPdate), MF);
i = i + 1;
end
return true
end -- }}}
-- Those set the scalling of the MUF container
-- SACALING FUNCTIONS (MicroUnitF Children) {{{
do
local UIScale = 0;
local FrameScale = 0;
local function TestMUFCorner(x, y, margin) -- {{{
-- if the MUF is not horizontaly outside of the screen
if not (x < 0 or x + margin > DC.ScreenWidth) then
x = nil;
end
-- if the MUF is not vertically outside of the screen
if not (y < 0 or y + margin > DC.ScreenHeight) then
y = nil;
end
return x, y;
end -- }}}
function MicroUnitF.prototype:IsOnScreen(xDelta, yDelta) -- {{{
-- frame relative position
local left, bottom, width, height = self.Frame:GetRect();
-- we need to check just one corner (MUFs are fix-sized squares)
return TestMUFCorner(left * FrameScale - xDelta, bottom * FrameScale - yDelta, width * FrameScale);
end -- }}}
-- Place the MUFs container according to its scale
function MicroUnitF:Place () -- {{{
if self.UnitShown == 0 or self.DraggingHandle then return end
if InCombatLockdown() then
-- if we are fighting, postpone the call
D:AddDelayedFunctionCall (
"MicroUnitFPlace", self.Place,
self);
return false;
end
local UIParent = UIParent;
UIScale = UIParent:GetEffectiveScale()
FrameScale = self.Frame:GetEffectiveScale();
DC.ScreenWidth = UIParent:GetWidth() * UIScale;
DC.ScreenHeight = UIParent:GetHeight() * UIScale;
local saved_x, saved_y = D.profile.DebuffsFrameContainer_x, D.profile.DebuffsFrameContainer_y;
local current_x, current_y = self.Frame:GetRect();
current_x = current_x * FrameScale;
current_y = current_y * FrameScale;
-- If executed for the very first time, then put it in the top right corner of the screen
if (not saved_x or not saved_y) then
saved_x = (UIParent:GetWidth() * UIScale) - (UIParent:GetWidth() * UIScale) / 4;
saved_y = (UIParent:GetHeight() * UIScale) - (UIParent:GetWidth() * UIScale) / 5;
D.profile.DebuffsFrameContainer_x = saved_x;
D.profile.DebuffsFrameContainer_y = saved_y;
end
-- test and fix handle's position if some MUFs are out of the screen
local Handle_x_offset = 0;
local Handle_y_offset = 0;
local StickToRightOffest = 0;
local Unit_Array = D.Status.Unit_Array;
local x_out_arrays = {};
local y_out_arrays = {};
if D.profile.DebuffsFrameStickToRight then -- {{{
local FirstLineNum = 0;
-- get the number of max unit per line/row
if not D.profile.DebuffsFrameVerticalDisplay then
if self.UnitShown > D.profile.DebuffsFramePerline then
FirstLineNum = D.profile.DebuffsFramePerline;
else FirstLineNum = self.UnitShown; end
else
if self.UnitShown > D.profile.DebuffsFramePerline then
FirstLineNum = floor( (self.UnitShown ) / D.profile.DebuffsFramePerline ) + ((self.UnitShown % D.profile.DebuffsFramePerline ~= 0) and 1 or 0);
else FirstLineNum = 1; end
end
-- get the offset of the handle we need to apply in order to align the MUFs on the right
StickToRightOffest = FrameScale * (FirstLineNum * (DC.MFSIZE + D.profile.DebuffsFrameXSpacing) - D.profile.DebuffsFrameXSpacing );
end -- }}}
-- get a list of all MUFs which position is *saved* outside of the screen (hence the current_y - saved_y)
for i=1, self.UnitShown do
local MF = self.ExistingPerUNIT[ Unit_Array[i] ];
if MF then
x_out_arrays[#x_out_arrays + 1], y_out_arrays[#y_out_arrays + 1] = MF:IsOnScreen(current_x - saved_x + StickToRightOffest, current_y - saved_y)
end
end
-- sort those lists to find the extrems
if #x_out_arrays then table.sort(x_out_arrays) end
if #y_out_arrays then table.sort(y_out_arrays) end
-- test if there is no solution -- XXX cannot work
if (x_out_arrays[1] and x_out_arrays[1] < 0 and (x_out_arrays[#x_out_arrays] > DC.ScreenWidth))
or (y_out_arrays[1] and y_out_arrays[1] < 0 and (y_out_arrays[#y_out_arrays] > DC.ScreenHeight)) then
D:Print(D:ColorText("WARNING: Your Micro-Unit-Frames' window is too big to fit entirely on your screen, you should change MUFs display settings (scale and/or disposition)! (Type /Decursive)", "FFFF0000"));
end
--D:Debug("MicroUnitF:Place(), outliers:", x_out_arrays[1], x_out_arrays[#x_out_arrays], y_out_arrays[1], y_out_arrays[#x_out_arrays]);
-- x
if x_out_arrays[1] then
if x_out_arrays[1] < 0 then
Handle_x_offset = - x_out_arrays[1];
else
Handle_x_offset = - (x_out_arrays[#x_out_arrays] + DC.MFSIZE * FrameScale - DC.ScreenWidth)
end
end
-- y
if y_out_arrays[1] then
if y_out_arrays[1] < 0 then
Handle_y_offset = - y_out_arrays[1];
else
Handle_y_offset = - (y_out_arrays[#y_out_arrays] + DC.MFSIZE * FrameScale - DC.ScreenHeight)
end
end
--D:Debug("MicroUnitF:Place(), handle offset:", Handle_x_offset, Handle_y_offset);
saved_x = saved_x + Handle_x_offset - StickToRightOffest;
saved_y = saved_y + Handle_y_offset;
-- set to the scaled position
self.Frame:ClearAllPoints();
self.Frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", saved_x/FrameScale , saved_y/FrameScale);
D:Debug("MUF Window position set");
D.MFContainerHandle:ClearAllPoints();
D.MFContainerHandle:SetPoint(self:GetHelperAnchor());
-- if the handle is at the top of the screen it means it's overlaping the MUF, let's move the handle somewhere else.
if floor(D.MFContainerHandle:GetTop() * FrameScale + 0.5) == floor(UIParent:GetTop() * UIScale + 0.5) then -- if at top
D.MFContainerHandle:ClearAllPoints();
D.MFContainerHandle:SetPoint(self:GetHelperAnchor(true));
D:Debug("|cff00ff00Handle moved|r");
end
return true
end -- }}}
-- Save the position of the frame without its scale
function MicroUnitF:SavePos () -- {{{
if self.UnitShown == 0 then return end
if self.Frame:IsVisible() then
-- We save the unscalled position (no problem if the sacale is changed behind our back)
D.profile.DebuffsFrameContainer_x = self.Frame:GetEffectiveScale() * self.Frame:GetLeft();
D.profile.DebuffsFrameContainer_y = self.Frame:GetEffectiveScale() * self.Frame:GetBottom();
D:Debug("MUF pos:", D.profile.DebuffsFrameContainer_x, D.profile.DebuffsFrameContainer_y);
-- if we choosed to align the MUF to the right then we have to add the
-- width of the first line to get the original position of the handle
if D.profile.DebuffsFrameStickToRight then -- {{{
local FirstLineNum;
if not D.profile.DebuffsFrameVerticalDisplay then
if self.UnitShown > D.profile.DebuffsFramePerline then
FirstLineNum = D.profile.DebuffsFramePerline;
else
FirstLineNum = self.UnitShown;
end
else
if self.UnitShown > D.profile.DebuffsFramePerline then
FirstLineNum = floor( self.UnitShown / D.profile.DebuffsFramePerline ) + ((self.UnitShown % D.profile.DebuffsFramePerline ~= 0) and 1 or 0);
else
FirstLineNum = 1;
end
end
D.profile.DebuffsFrameContainer_x = D.profile.DebuffsFrameContainer_x + self.Frame:GetEffectiveScale() * (FirstLineNum * (DC.MFSIZE + D.profile.DebuffsFrameXSpacing) - D.profile.DebuffsFrameXSpacing);
end -- }}}
-- D:Debug("Frame position saved");
D:Debug("MUF pos saved:", D.profile.DebuffsFrameContainer_x, D.profile.DebuffsFrameContainer_y);
end
end -- }}}
end
-- set the scaling of the MUFs container according to the user settings
function MicroUnitF:SetScale (NewScale) -- {{{
-- Setting the new scale
self.Frame:SetScale(NewScale);
-- Place the frame adapting its position to the news cale
self:Place ();
end -- }}}
-- }}}
-- Update the MUF of a given unitid
function MicroUnitF:UpdateMUFUnit(Unitid, CheckStealth, o_auraUpdateInfo)
if not D.profile.ShowDebuffsFrame then
return;
end
local unit = false;
if (D.Status.Unit_Array_UnitToGUID[Unitid]) then
unit = Unitid;
else
D:Debug("Unit", Unitid, "not in raid or party!" );
return;
end
-- get the MUF object
local MF = self.UnitToMUF[unit];
if (MF and MF.Shown) then
-- The MUF will be updated only every DebuffsFrameRefreshRate seconds at most
-- but we don't miss any event XXX note this can be the cause of slowdown if 25 or 40 players got debuffed at the same instant, DebuffUpdateRequest is here to prevent that since 2008-02-17
if (not D:DelayedCallExixts("Dcr_Update"..unit)) then
D.DebuffUpdateRequest = D.DebuffUpdateRequest + 1;
D:ScheduleDelayedCall("Dcr_Update"..unit
, CheckStealth and MF.UpdateWithCS or MF.Update
, D.db.global.DebuffsFrameRefreshRate * (0.9 + D.DebuffUpdateRequest / D.db.global.DebuffsFramePerUPdate)
, MF --, o_auraUpdateInfo
);
D:Debug("Update scheduled for, ", unit, MF.ID);
return true; -- return value used to aknowledge that the function actually did something
end
else
D:Debug("No MUF found for ", unit, Unitid);
end
end
-- Event management functions
-- MUF EVENTS (MicroUnitF children) (OnEnter, OnLeave, OnLoad, OnPreClick) {{{
do
local UnitGUID = _G.UnitGUID;
local GetSpellInfo = _G.C_Spell and _G.C_Spell.GetSpellInfo or _G.GetSpellInfo;
local GetSpellName = _G.C_Spell and _G.C_Spell.GetSpellName or function (spellId) return (GetSpellInfo(spellId)) end;
local ttHelpLines = {}; -- help tooltip text
local TooltipUpdate = 0; -- help tooltip change update check
T._CatchAllErrors = 'LibQTip';
local LibQTip = LibStub('LibQTip-1.0');
T._CatchAllErrors = false;
local MUFtoolTip = nil;
-- This function is responsible for showing the tooltip when the mouse pointer is over a MUF
-- it also handles Unstable Affliction detection and warning.
function MicroUnitF:OnEnter(frame) -- {{{
D.Status.MouseOveringMUF = true;
local MF = frame.Object;
local Status;
local Unit = MF.CurrUnit; -- shortcut
local TooltipText = "";
local GUIDwasFixed = false;
local unitguid = UnitGUID(Unit);
if unitguid ~= D.Status.Unit_Array_UnitToGUID[Unit] or Unit ~= D.Status.Unit_Array_GUIDToUnit[unitguid] then
if unitguid then
D.Status.Unit_Array_UnitToGUID[Unit] = unitguid;
D.Status.Unit_Array_GUIDToUnit[unitguid] = Unit;
GUIDwasFixed = true;
end
end
MF:Update(false, false, true); -- will reset the color early and set the current status of the MUF
MF:SetClassBorder(); -- set the border if it wasn't possible at the time the unit was discovered
if not Unit then
return; -- If the user overs the MUF before it's completely initialized
end
--Test for unstable affliction like spells
if MF.Debuffs[1] then
for i, Debuff in ipairs(MF.Debuffs) do
if Debuff.Type then
-- Create a warning if an Unstable Affliction like spell is detected XXX will be integrated along with the filtering system comming 'soon'(tm)
if DC.IS_HARMFULL_DEBUFF[Debuff.Name] then
-- if Debuff.Name == DC.DS["Unstable Affliction"] or Debuff.Name == DC.DS["Vampiric Touch"] then
D:Println("|cFFFF0000 ==> %s !!|r (%s)", Debuff.Name, D:MakePlayerName((D:PetUnitName( Unit, true ))));
D:SafePlaySoundFile(DC.DeadlyDebuffAlert);
end
end
end
-- TODO: scan here for fluidity buff/debuff and alert
-- http://www.wowhead.com/search?q=Ionization#npc-abilities
-- http://www.wowhead.com/search?q=+Fluidity#spells
end
if D.profile.AfflictionTooltips then
MUFtoolTip = LibQTip:Acquire("DecursiveMUFToolTip", 1, "LEFT");
MUFtoolTip:SetAutoHideDelay(.3, frame, function() MUFtoolTip = nil end)
MUFtoolTip:Clear()
-- removes the CHARMED_STATUS bit from Status, we don't need it
Status = bit.band(MF.UnitStatus, bit.bnot(CHARMED_STATUS));
-- First, write the name of the unit in its class color
if UnitExists(MF.CurrUnit) then
MUFtoolTip:AddLine(
((DC.RAID_ICON_LIST[GetRaidTargetIndex(Unit)]) and (DC.RAID_ICON_LIST[GetRaidTargetIndex(Unit)] .. "0:0:0:0|t ") or "")
-- Colored unit name
.. D:ColorTextNA((D:PetUnitName(Unit, true)), ((UnitClass(Unit)) and DC.HexClassColor[ (select(2, UnitClass(Unit))) ] or "AAAAAA"))
.. " |cFF3F3F3F(".. Unit .. ")|r"
);
else
MUFtoolTip:AddLine(MF.CurrUnit);
end
-- set UnitStatus text
local StatusText = "";
-- set the status text, just translate the bitfield to readable text
if Status == NORMAL then
StatusText = L["NORMAL"];
elseif Status == ABSENT then
StatusText = L["ABSENT"]:format(Unit);
elseif Status == FAR then
StatusText = L["TOOFAR"];
elseif Status == BLACKLISTED then
StatusText = L["BLACKLISTED"];
elseif MF.Debuffs[1] and (Status == AFFLICTED or Status == AFFLICTED_NIR) then
local DebuffType = MF.Debuffs[1].Type;
StatusText = L["AFFLICTEDBY"]:format(D:ColorTextNA( L[DC.TypeNames[DebuffType]:upper()], D.profile.TypeColors[DebuffType]) );
elseif Status == STEALTHED then
StatusText = L["STEALTHED"];
end
-- Unit Status
MUFtoolTip:AddLine(StatusText);
-- list the debuff(s) names
if MF.Debuffs[1] then
for i, Debuff in ipairs(MF.Debuffs) do
if Debuff.Type then
local DebuffApps = Debuff.Applications;
MUFtoolTip:AddLine(D:ColorTextNA(Debuff.Name, D.profile.TypeColors[Debuff.Type]) .. (DebuffApps > 0 and (" (%d)"):format(DebuffApps) or ""));
end
end
end
-- Display the tooltip
MUFtoolTip:ClearAllPoints();
MUFtoolTip:SetClampedToScreen(true)
MUFtoolTip:SetPoint(self:GetHelperAnchor());
MUFtoolTip:Show();
-- if the tooltip is at the top of the screen it means it's overlaping the MUF, let's move the tooltip beneath the first MUF.
if floor(MUFtoolTip:GetTop() + 0.5) >= floor(UIParent:GetTop() + 0.5) then -- if at top -- XXX attempt to perform arithmetic on a nil value, reported on 2018-08-16 and 2020-01-29
MUFtoolTip:ClearAllPoints();
MUFtoolTip:SetPoint(self:GetHelperAnchor(true));
end
end
-- show a help text in the Game default tooltip
if D.profile.DebuffsFrameShowHelp then
-- if necessary we will update the help tooltip text
if (D.Status.SpellsChanged ~= TooltipUpdate and not D.Status.Combat) then
ttHelpLines = {};
local MouseButtons = D.db.global.MouseButtons;
for Spell, Prio in pairs(D.Status.CuringSpellsPrio) do
ttHelpLines[Prio] = {[D:ColorText(DC.MouseButtonsReadable[MouseButtons[Prio]], D:NumToHexColor(MF_colors[Prio]))] =
("%s%s"):format(GetSpellName(Spell) or Spell, (D.Status.FoundSpells[Spell] and D.Status.FoundSpells[Spell][5]) and "|cFFFF0000*|r" or "")}
end
t_insert(ttHelpLines, {[DC.MouseButtonsReadable[MouseButtons[#MouseButtons - 1]]] = ("%s"):format(L["TARGETUNIT"])});
t_insert(ttHelpLines, {[DC.MouseButtonsReadable[MouseButtons[#MouseButtons ]]] = ("%s"):format(L["FOCUSUNIT"])});
TooltipUpdate = D.Status.SpellsChanged;
end
D:DisplayLQTGameTooltip(ttHelpLines, frame)
end
end -- }}}
function MicroUnitF:OnLeave(frame) -- {{{
D.Status.MouseOveringMUF = false;
end -- }}}
local keyTemplate = "|cFF11FF11%s|r-|cFF11FF11%s|r";
local keyHelp;
function D.MicroUnitF:OnCornerLeave(frame)
end
function D.MicroUnitF:OnCornerEnter(frame)
if MUFtoolTip then
MUFtoolTip:Release();
MUFtoolTip = nil;
end
if not keyHelp then
keyHelp = {
{[keyTemplate:format(D.L["ALT"], D.L["HLP_LEFTCLICK"]) ] = D.L["HANDLEHELP"]},
{[-1] = -1},
{[keyTemplate:format(D.L["ALT"], D.L["HLP_RIGHTCLICK"])] = D.L["BINDING_NAME_DCRSHOWOPTION"]},
{[-1] = -1},
{[keyTemplate:format(D.L["CTRL"], D.L["HLP_LEFTCLICK"]) ] = D.L["BINDING_NAME_DCRPRSHOW"] },
{[keyTemplate:format(D.L["SHIFT"], D.L["HLP_LEFTCLICK"]) ] = D.L["BINDING_NAME_DCRSKSHOW"] },
{[-1] = -1},
{[keyTemplate:format(D.L["SHIFT"], D.L["HLP_RIGHTCLICK"])] = D.L["BINDING_NAME_DCRSHOW"] },
}
end
if D.profile.DebuffsFrameShowHelp then
D:DisplayLQTGameTooltip(keyHelp, frame);
end;
end
end
function MicroUnitF:OnLoad(frame) -- {{{
frame:SetScript("PreClick", self.OnPreClick);
frame:SetScript("PostClick", self.OnPostClick);
end
-- }}}
function MicroUnitF.OnPreClick(frame, Button) -- {{{
D:Debug("Micro unit Preclicked: ", Button);
local RequestedPrio;
local ButtonsString = "";
local modifier;
if IsControlKeyDown() then
modifier = "ctrl-";
elseif IsAltKeyDown() then
modifier = "alt-";
elseif IsShiftKeyDown() then
modifier = "shift-";
end
if Button == "LeftButton" then
ButtonsString = "*%s1";
elseif Button == "RightButton" then
ButtonsString = "*%s2";
elseif Button == "MiddleButton" then
ButtonsString = "*%s3";
elseif Button == "Button4" then
ButtonsString = "*%s4";
elseif Button == "Button5" then
ButtonsString = "*%s5";
else
D:Debug("unknown button", Button);
return;
end
RequestedPrio = D:tGiveValueIndex(D.db.global.MouseButtons, modifier and (modifier .. ButtonsString:sub(-3)) or ButtonsString);
D:Debug("RequestedPrio:", RequestedPrio);
if frame.Object.UnitStatus == NORMAL and D:tcheckforval(D.Status.CuringSpellsPrio, RequestedPrio) then
D:Println(L["HLP_NOTHINGTOCURE"]);
elseif (frame.Object.UnitStatus == AFFLICTED and frame.Object.Debuffs[1]) then
local NeededPrio = D:GiveSpellPrioNum(frame.Object.Debuffs[1].Type);
local Unit = frame.Object.CurrUnit; -- shortcut
-- there is no spell for the requested prio ? (no spell registered to this modifier+mousebutton)
if modifier and RequestedPrio and not D:tcheckforval(D.Status.CuringSpellsPrio, RequestedPrio) then
D:Debug("No spell registered for", RequestedPrio);
-- Get the priority that would have been requested without modifiers
local RequestedPrioNoMod = D:tGiveValueIndex(D.db.global.MouseButtons, ButtonsString);
-- Get the spell bond to this priority
local NoModSpell = D:tGiveValueIndex(D.Status.CuringSpellsPrio, RequestedPrioNoMod)
-- If there is one and it's a user customized macro
if NoModSpell and D.Status.FoundSpells[NoModSpell][5] then
D:Debug("But spell used by", ButtonsString, "is a user nacro");
-- let the user use the modifiers he want without yelling at him
RequestedPrio = RequestedPrioNoMod;
end
end