-
Notifications
You must be signed in to change notification settings - Fork 16
/
GroupHeader.lua
executable file
·2018 lines (1780 loc) · 62.5 KB
/
GroupHeader.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
local _G = _G
local PitBull4 = _G.PitBull4
-- luacheck: globals oRA3 ClickCastHeader SecureButton_GetModifiedUnit RAID_CLASS_COLORS
local DEBUG = PitBull4.DEBUG
local expect = PitBull4.expect
local deep_copy = PitBull4.Utils.deep_copy
local frames_to_anchor = PitBull4.frames_to_anchor
local MAX_PARTY_MEMBERS = _G.MAX_PARTY_MEMBERS
local MAX_PARTY_MEMBERS_WITH_PLAYER = MAX_PARTY_MEMBERS + 1
local MAX_RAID_MEMBERS = _G.MAX_RAID_MEMBERS
local MAX_BOSS_FRAMES = _G.MAX_BOSS_FRAMES
local MEMBERS_PER_RAID_GROUP = _G.MEMBERS_PER_RAID_GROUP
local NUM_RAID_GROUPS = _G.NUM_RAID_GROUPS
local NUM_CLASSES = #CLASS_SORT_ORDER
local MINIMUM_EXAMPLE_GROUP = 2
local GROUP_ROLES = {
TANK = TANK,
HEALER = HEALER,
DAMAGER = DAMAGER,
NONE = NONE,
}
-- lock to prevent the SecureGroupHeader_Update for doing unnecessary
-- work when running ForceShow
local in_force_show = false
--- Make a group header.
-- @param group the name for the group. Also acts as a unique identifier.
-- @usage local header = PitBull4:MakeGroupHeader("Monkey")
function PitBull4:MakeGroupHeader(group)
if DEBUG then
expect(group, 'typeof', 'string')
end
local group_db = PitBull4.db.profile.groups[group]
local pet_based = group_db.unit_group:match("pet") and true
local group_based = group_db.unit_group:match("^party") or group_db.unit_group:match("^raid")
local use_pet_header = pet_based and group_db.use_pet_header
local header_name
if not group_based then
header_name = "PitBull4_EnemyGroups_"..group
elseif use_pet_header then
header_name = "PitBull4_PetGroups_" .. group
else
header_name = "PitBull4_Groups_" .. group
end
local header = _G[header_name]
if not header then
local template
if group_based then
if use_pet_header then
template = "SecureGroupPetHeaderTemplate"
else
template = "SecureGroupHeaderTemplate"
end
else
template = "SecureFrameTemplate"
end
header = CreateFrame("Frame", header_name, UIParent, template)
header:Hide() -- it will be shown later and attributes being set won't cause lag
header.name = group
header.group_db = group_db
header.group_based = group_based
self:ConvertIntoGroupHeader(header)
elseif header.group_db ~= group_db then
-- If the frame already exists and the group_db doesn't already match the one
-- we expect it to be then it's a recreated frame from one we've previously
-- deleted so we need to set the group_db and force an update.
header.group_db = group_db
header:RefreshGroup()
end
header:UpdateShownState()
for frame, relative_to in pairs(frames_to_anchor) do
local relative_frame = PitBull4.Utils.GetRelativeFrame(relative_to)
if relative_frame == header then
frame:RefixSizeAndPosition()
end
end
end
PitBull4.MakeGroupHeader = PitBull4:OutOfCombatWrapper(PitBull4.MakeGroupHeader)
--- Swap the group from a Normal and Pet Group Header.
-- @param group the name for the group.
-- @usage PitBull4:SwapGroupTemplate("Monkey")
-- Note that the use_pet_header setting for the group_db is expected to already
-- be set to the value you're going to.
function PitBull4:SwapGroupTemplate(group)
if DEBUG then
expect(group, 'typeof', 'string')
end
local old_header = self.name_to_header[group]
local group_db = PitBull4.db.profile.groups[group]
local group_based = group_db.unit_group:match("^party") or group_db.unit_group:match("^raid")
if not group_db.enabled then
return
end
old_header.group_db = deep_copy(group_db)
old_header.group_db.enabled = false
old_header:RefreshGroup()
old_header:UpdateShownState()
old_header:RecheckConfigMode()
local pet_based = not not group_db.unit_group:match("pet") -- this feels dirty
local use_pet_header = pet_based and group_db.use_pet_header
local new_name
if not group_based then
new_name = "PitBull4_EnemyGroups_"..group
elseif use_pet_header then
new_name = "PitBull4_PetGroups_"..group
else
new_name = "PitBull4_Groups_"..group
end
local new_header = _G[new_name]
if not new_header then
-- Doesn't exist so make it.
self:MakeGroupHeader(group)
new_header = _G[new_name]
else
-- already exists so jump through the hoops to reactive it.
self.name_to_header[group] = new_header
new_header.group_db = group_db
new_header:RefreshGroup()
new_header:UpdateShownState()
end
new_header:RecheckConfigMode()
end
PitBull4.SwapGroupTemplate = PitBull4:OutOfCombatWrapper(PitBull4.SwapGroupTemplate)
local GroupHeader = {}
PitBull4.GroupHeader = GroupHeader
local GroupHeader__scripts = {}
PitBull4.GroupHeader__scripts = GroupHeader__scripts
local MemberUnitFrame = PitBull4.MemberUnitFrame
local MemberUnitFrame__scripts = PitBull4.MemberUnitFrame__scripts
--- Force an update on the group header.
-- This is just a wrapper for SecureGroupHeader_Update.
-- @param force the update to happen now
-- @usage header:Update()
function GroupHeader:Update(force)
local shown = self:IsShown()
-- We can't directly call SecureGroupHeader_Update so we just
-- set an attribute back to iself. Calling SecureGroupHeader_Update
-- directly taints the entire template system and is very bad.
if not shown and force then
self:Show()
end
self:SetAttribute("maxColumns",self:GetAttribute("maxColumns"))
if not shown and force then
self:Hide()
end
end
GroupHeader.Update = PitBull4:OutOfCombatWrapper(GroupHeader.Update)
--- Send :Update to all member frames.
-- @args ... the arguments to send along with :Update
-- @usage header:UpdateMembers(true, true)
function GroupHeader:UpdateMembers(...)
for _, frame in self:IterateMembers() do
frame:Update(...)
end
end
function GroupHeader:ProxySetAttribute(key, value)
if self:GetAttribute(key) ~= value then
self:SetAttribute(key, value)
return not not self:IsVisible()
end
end
function GroupHeader:UpdateShownState()
local group_db = self.group_db
if not group_db or not group_db.enabled then
PitBull4:RemoveGroupFromStateHeader(self)
else
PitBull4:AddGroupToStateHeader(self)
end
end
GroupHeader.UpdateShownState = PitBull4:OutOfCombatWrapper(GroupHeader.UpdateShownState)
local DIRECTION_TO_POINT = {
down_right = "TOP",
down_left = "TOP",
up_right = "BOTTOM",
up_left = "BOTTOM",
right_down = "LEFT",
right_up = "LEFT",
left_down = "RIGHT",
left_up = "RIGHT",
}
local DIRECTION_TO_GROUP_ANCHOR_POINT = {
down_right = "TOPLEFT",
down_left = "TOPRIGHT",
up_right = "BOTTOMLEFT",
up_left = "BOTTOMRIGHT",
right_down = "TOPLEFT",
right_up = "BOTTOMLEFT",
left_down = "TOPRIGHT",
left_up = "BOTTOMRIGHT",
}
local DIRECTION_TO_COLUMN_ANCHOR_POINT = {
down_right = "LEFT",
down_left = "RIGHT",
up_right = "LEFT",
up_left = "RIGHT",
right_down = "TOP",
right_up = "BOTTOM",
left_down = "TOP",
left_up = "BOTTOM",
}
local DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER = {
down_right = 1,
down_left = -1,
up_right = 1,
up_left = -1,
right_down = 1,
right_up = 1,
left_down = -1,
left_up = -1,
}
local DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER = {
down_right = -1,
down_left = -1,
up_right = 1,
up_left = 1,
right_down = -1,
right_up = 1,
left_down = -1,
left_up = 1,
}
local POINT_TO_HORIZONTAL_MULTIPLIER = {
TOP = 0,
BOTTOM = 0,
LEFT = 1,
RIGHT = -1,
TOPLEFT = 1,
TOPRIGHT = -1,
BOTTOMLEFT = 1,
BOTTOMRIGHT = -1,
CENTER = 0,
}
local POINT_TO_VERTICAL_MULTIPLIER = {
TOP = -1,
BOTTOM = 1,
LEFT = 0,
RIGHT = 0,
TOPLEFT = -1,
TOPRIGHT = -1,
BOTTOMLEFT = 1,
BOTTOMRIGHT = 1,
CENTER = 0,
}
local GROUPING_ORDER = {}
do
local t = {}
for i = 1, NUM_RAID_GROUPS do
t[i] = i..""
end
GROUPING_ORDER.GROUP = table.concat(t, ",")
end
GROUPING_ORDER.CLASS = function()
return table.concat(PitBull4.ClassOrder, ",")
end
GROUPING_ORDER.ASSIGNEDROLE = function()
return table.concat(PitBull4.RoleOrder, ",")
end
local function position_label(self, label)
label:ClearAllPoints()
local group_db = self.group_db
if group_db.direction:match("down") then
label:SetPoint("BOTTOM", self, "TOP", 0, group_db.vertical_spacing)
else
label:SetPoint("TOP", self, "BOTTOM", 0, -group_db.vertical_spacing)
end
end
-- Offsets used to be stored between the center of the screen and the center
-- of the group frame, while the frames anchor point varied based on the
-- growth direction of the frame. So the offset from the actual anchor point
-- was calculated as needed. Now we store the the actual offsets and only
-- recalculate if the anchor point is being determined by the growth direction.
-- This function converts the existing offsets to the new format.
function PitBull4:MigrateGroupAnchorToNewFormat(group_db, layout_db)
local scale = layout_db.scale * group_db.scale / UIParent:GetEffectiveScale()
local direction = group_db.direction
local unit_width = layout_db.size_x * group_db.size_x
local unit_height = layout_db.size_y * group_db.size_y
local x_diff = unit_width / 2 * -DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER[direction]
local y_diff = unit_height / 2 * -DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER[direction]
group_db.position_x = (group_db.position_x / scale + x_diff) * scale
group_db.position_y = (group_db.position_y / scale + y_diff) * scale
end
-- Handles adjusting the offsets for when the growth direction changes.
function PitBull4:AdjustGroupAnchorForDirectionChange(group_db, new_direction)
-- If the anchor is set explicitly then changing the direction does not require
-- a recalculation of the anchor offsets.
if group_db.anchor ~= "" then return end
local old_direction = group_db.direction
local layout_db = self.db.profile.layouts[group_db.layout]
local scale = layout_db.scale * group_db.scale
local unit_width = layout_db.size_x * group_db.size_x
local unit_height = layout_db.size_y * group_db.size_y
-- Calculate the difference from the current anchor point to the center
local x_diff = unit_width / 2 * DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER[old_direction]
local y_diff = unit_height / 2 * DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER[old_direction]
-- Calculate the difference from the center to the new anchor point
x_diff = x_diff + unit_width / 2 * -DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER[new_direction]
y_diff = y_diff + unit_height / 2 * -DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER[new_direction]
-- Adjust the offset to the new anchor point
group_db.position_x = (group_db.position_x / scale + x_diff) * scale
group_db.position_y = (group_db.position_y / scale + y_diff) * scale
end
-- Anchors a frame to the first frame within the group. The first frame probably will
-- not exist when we need to do the anchoring. So we need to calculate where the frame
-- would exist and adjust our offsets accordingly so we can simulate anchoring to the frame
-- even though we're really anchoring to the group header itself.
function GroupHeader:AnchorFrameToFirstUnit(frame, anchor, rel_point, x, y)
local growth_point = self:GetAttribute("point")
if rel_point:find(growth_point, 1, false) then
-- The relative point is on the edge we're growing away from so we
-- do not need to calculate the offset.
frame:SetPoint(anchor, self, rel_point, x, y)
else
-- The relative point is not on the edge we're growing away from
-- so we must calculate the offset to the other edge of the unit frame
local group_db = self.group_db
local layout = group_db.layout
local layout_db = PitBull4.db.profile.layouts[layout]
local scale = self:GetEffectiveScale() / UIParent:GetEffectiveScale()
local unit_width = layout_db.size_x * group_db.size_x / scale
local unit_height = layout_db.size_y * group_db.size_y / scale
local direction = group_db.direction
if growth_point == "TOP" or growth_point == "BOTTOM" then
if rel_point:find("LEFT", 1, false) then
x = x - (unit_width / 2)
if rel_point == "LEFT" then
y = y + (unit_height/ 2 * DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER[direction])
end
elseif rel_point:find("RIGHT", 1, false) then
x = x + (unit_width / 2)
if rel_point == "RIGHT" then
y = y + (unit_height / 2 * DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER[direction])
end
end
elseif growth_point == "LEFT" or growth_point == "RIGHT" then
if rel_point:find("TOP", 1, false) then
y = y + (unit_height / 2)
if rel_point == "TOP" then
x = x + (unit_width / 2 * DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER[direction])
end
elseif rel_point:find("BOTTOM", 1, false) then
y = y - (unit_height / 2)
if rel_point == "BOTTOM" then
x = x + (unit_width / 2 * DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER[direction])
end
end
end
if growth_point == "TOP" and rel_point:find("BOTTOM", 1, false) then
y = y - unit_height
elseif growth_point == "BOTTOM" and rel_point:find("TOP", 1, false) then
y = y + unit_height
elseif growth_point == "LEFT" and rel_point:find("RIGHT", 1, false) then
x = x + unit_width
elseif growth_point == "RIGHT" and rel_point:find("LEFT", 1, false) then
x = x - unit_width
end
if rel_point == "CENTER" then
if growth_point == "BOTTOM" or growth_point == "TOP" then
y = y + (unit_height / 2 * DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER[direction])
else -- growth_point == "LEFT" or growth_point == "RIGHT"
x = x + (unit_width / 2 * DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER[direction])
end
end
frame:SetPoint(anchor, self, growth_point, x, y)
end
end
--- Reset the size and position of the group header. More accurately,
-- the scale and the position since size is set dynamically.
-- @usage header:RefixSizeAndPosition()
function GroupHeader:RefixSizeAndPosition()
local group_db = self.group_db
local layout = group_db.layout
local layout_db = PitBull4.db.profile.layouts[layout]
local updated = false
self:SetScale(layout_db.scale * group_db.scale)
self:SetFrameStrata(layout_db.strata)
self:SetFrameLevel(layout_db.level - 1) -- 1 less than what the unit frame will be at
-- Calculate the width and height of the group when the number of units
-- returned from GetMaxUnits() exist. Use this to cause config mode to
-- behave this way.
local unit_width = layout_db.size_x * group_db.size_x
local unit_height = layout_db.size_y * group_db.size_y
local max = self:GetMaxUnits()
local super_unit_group = self.super_unit_group
local config_mode = PitBull4.config_mode
updated = self:ProxySetAttribute('unitWidth',unit_width) or updated
updated = self:ProxySetAttribute('unitHeight',unit_height) or updated
updated = self:ProxySetAttribute('clickThrough',group_db.click_through) or updated
-- Limit the number of frames to the config mode for raid
if config_mode and config_mode:sub(1,4) == "raid" and super_unit_group == "raid" then
if config_mode == "raid" then
if max > MEMBERS_PER_RAID_GROUP then
max = MEMBERS_PER_RAID_GROUP
end
elseif config_mode:sub(1,4) == "raid" then
local num = config_mode:sub(5)+0 -- raid10, raid25, raid40 => 10, 25, 40
if num < max then
max = num
end
end
end
local units_per_column = group_db.units_per_column
local num_columns
if units_per_column and max > units_per_column then
num_columns = math.ceil(max / units_per_column)
else
units_per_column = max
num_columns = 1
end
local point = self:GetAttribute("point") or "TOP"
local x_offset_mult = POINT_TO_HORIZONTAL_MULTIPLIER[point]
local y_offset_mult = POINT_TO_VERTICAL_MULTIPLIER[point]
local x_mult, y_mult = math.abs(x_offset_mult), math.abs(y_offset_mult)
local x_offset = self:GetAttribute("xOffset") or 0
local y_offset = self:GetAttribute("yOffset") or 0
local column_spacing = self:GetAttribute("columnSpacing") or 0
local col_point = self:GetAttribute("columnAnchorPoint")
local col_x_mult = POINT_TO_HORIZONTAL_MULTIPLIER[col_point]
local col_y_mult = POINT_TO_VERTICAL_MULTIPLIER[col_point]
local width = x_mult * (units_per_column - 1) * unit_width + ((units_per_column - 1) * (x_offset * x_offset_mult)) + unit_width
local height = y_mult * (units_per_column - 1) * unit_height + ((units_per_column - 1) * (y_offset * y_offset_mult)) + unit_height
if num_columns > 1 then
width = width + ((num_columns - 1) * math.abs(col_x_mult) * (width + column_spacing))
height = height + ((num_columns - 1) * math.abs(col_y_mult) * (height + column_spacing))
end
-- Set minimum width and height. If we don't do this then
-- SecureTemplates will calculate the size dynamically and these
-- dimensions will end up being set to 0.1 if there are no units to
-- display. This causes the positioning of the group header to move
-- and results in group frames that jump when someone joins the group
-- from where they were in config mode. It also will make the frames
-- that are anchored to the entire group to behave differently in config
-- mode from actual use.
updated = self:ProxySetAttribute("minWidth",math.max(width,0.1)) or updated
updated = self:ProxySetAttribute("minHeight",math.max(height,0.1)) or updated
if not updated then
-- Update absolutely must be called at least once to ensure the GroupHeader
-- frame size is recalculated.
self:Update(true)
end
if not self.group_based then
self:ConfigureChildren()
end
-- Check if the frame we will be anchoring to exists and if not
-- delaying setting the anchor until it does.
local rel_to = group_db.relative_to
local rel_frame, rel_type = PitBull4.Utils.GetRelativeFrame(rel_to)
if not rel_frame then
frames_to_anchor[self] = rel_to
if rel_type == "~" then
PitBull4.anchor_timer:Show()
end
return
else
frames_to_anchor[self] = nil
end
local scale = self:GetEffectiveScale() / UIParent:GetEffectiveScale()
local anchor = group_db.anchor
if anchor == "" then
anchor = DIRECTION_TO_GROUP_ANCHOR_POINT[group_db.direction]
end
self:ClearAllPoints()
if rel_type == "f" then
rel_frame:AnchorFrameToFirstUnit(self, anchor, group_db.relative_point, group_db.position_x / scale, group_db.position_y / scale)
else
self:SetPoint(anchor, rel_frame, group_db.relative_point, group_db.position_x / scale, group_db.position_y / scale)
end
end
--- Recheck the group-based settings of the group header, including sorting, position, what units are shown.
-- @param dont_refresh_children don't call :RefreshLayout on the child frames
-- @usage header:RefreshGroup()
function GroupHeader:RefreshGroup(dont_refresh_children)
local group_db = self.group_db
local layout = group_db.layout
self.layout = layout
local layout_db = PitBull4.db.profile.layouts[layout]
self.layout_db = layout_db
self.dont_update = true
for _, frame in self:IterateMembers() do
frame.dont_update = true
end
local is_shown = self:IsShown()
self:Hide()
local force_show = self.force_show
self:UnforceShow()
-- Wipe all the points on the member frames before doing
-- the work below. SecureGroupHeader's code does not
-- do this for us as it should so if you change directions
-- the frames can break since they'll end up with conflicting
-- anchors.
for _, member in self:IterateMembers() do
member:ClearAllPoints()
end
local enabled = group_db.enabled
local unit_group = group_db.unit_group
local party_based = unit_group:sub(1, 5) == "party"
local group_based = party_based or unit_group:sub(1, 4) == "raid"
local include_player = party_based and group_db.include_player
local show_when = group_db.show_when
local show_solo = show_when.solo
if group_based then
show_solo = include_player and show_solo
end
local group_filter = group_based and group_db.group_filter or nil
local sort_direction = group_db.sort_direction
local sort_method = group_db.sort_method
local group_by = group_db.group_by
local name_list = nil
-- If using oRA3, override the MAINTANK groupFilter and use oRA3's tanks (even if empty)
if group_filter == "MAINTANK" and oRA3 then
local main_tanks = oRA3:GetSortedTanks()
name_list = table.concat(main_tanks, ",")
end
local changed_units = self.unit_group ~= unit_group or self.include_player ~= include_player or self.show_solo ~= show_solo or self.group_filter ~= group_filter or self.sort_direction ~= sort_direction or self.sort_method ~= sort_method or self.group_by ~= group_by or self.name_list ~= name_list or self.group_based ~= group_based
if changed_units then
local old_unit_group = self.unit_group
local old_super_unit_group = self.super_unit_group
self.unit_group = unit_group
self.group_based = group_based
self.include_player = include_player
self.show_solo = show_solo
self.group_filter = group_filter
self.sort_direction = sort_direction
self.sort_method = sort_method
self.group_by = group_db.group_by
self.name_list = name_list
if DEBUG then
expect(unit_group, 'typeof', 'string')
end
if party_based then
self.super_unit_group = "party"
self.unitsuffix = unit_group:sub(6)
self:SetAttribute("showRaid", nil)
self:SetAttribute("showParty", true)
self:SetAttribute("showPlayer", include_player and true or nil)
self:SetAttribute("showSolo", show_solo and true or nil)
self:SetAttribute("groupFilter", nil)
if group_filter then
local first = (","):split(group_filter)
if GROUP_ROLES[first] then
self:SetAttribute("groupFilter", group_filter)
end
end
elseif not group_based then
self:UnregisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT")
self:UnregisterEvent("UPDATE_BATTLEFIELD_STATUS")
if unit_group:sub(1, 4) == "boss" then
self.super_unit_group = "boss"
self.unitsuffix = unit_group:sub(5)
self:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT")
elseif unit_group:sub(1, 5) == "arena" then
self.super_unit_group = "arena"
self.unitsuffix = unit_group:sub(6)
self:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
end
else
self.super_unit_group = "raid"
self.unitsuffix = unit_group:sub(5)
self:SetAttribute("showParty", nil)
self:SetAttribute("showPlayer", nil)
self:SetAttribute("showSolo", nil)
self:SetAttribute("showRaid", true)
if name_list then
self:SetAttribute("groupFilter", nil)
self:SetAttribute("nameList", name_list)
else
self:SetAttribute("groupFilter", group_filter)
self:SetAttribute("nameList", nil)
end
end
if self.unitsuffix == "" then
self.unitsuffix = nil
end
self:SetAttribute("unitsuffix", self.unitsuffix)
local is_wacky = PitBull4.Utils.IsWackyUnitGroup(unit_group)
self.is_wacky = is_wacky
if old_unit_group then
PitBull4.unit_group_to_headers[old_unit_group][self] = nil
PitBull4.super_unit_group_to_headers[old_super_unit_group][self] = nil
end
for _, frame in self:IterateMembers() do
frame:SetAttribute("unitsuffix", self.unitsuffix)
frame.is_wacky = is_wacky
end
PitBull4.unit_group_to_headers[unit_group][self] = true
PitBull4.super_unit_group_to_headers[self.super_unit_group][self] = true
end
local direction = group_db.direction
local point = DIRECTION_TO_POINT[direction]
self:SetAttribute("point", point)
if point == "LEFT" or point == "RIGHT" then
self:SetAttribute("xOffset", group_db.horizontal_spacing * DIRECTION_TO_HORIZONTAL_SPACING_MULTIPLIER[direction])
self:SetAttribute("yOffset", 0)
self:SetAttribute("columnSpacing", group_db.vertical_spacing)
else
self:SetAttribute("xOffset", 0)
self:SetAttribute("yOffset", group_db.vertical_spacing * DIRECTION_TO_VERTICAL_SPACING_MULTIPLIER[direction])
self:SetAttribute("columnSpacing", group_db.horizontal_spacing)
end
if self.label then
position_label(self, self.label)
end
self:SetAttribute("sortMethod", sort_method)
self:SetAttribute("sortDir", sort_direction)
self:SetAttribute("template", ClickCastHeader and "ClickCastUnitTemplate,PitBull4_UnitTemplate" or "PitBull4_UnitTemplate")
self:SetAttribute("templateType", "Button")
self:SetAttribute("groupBy", group_by)
local order = GROUPING_ORDER[group_db.group_by]
if type(order) == "function" then
order = order()
end
self:SetAttribute("groupingOrder", order)
self:SetAttribute("unitsPerColumn", group_db.units_per_column)
self:SetAttribute("maxColumns", self:GetMaxUnits())
self:SetAttribute("startingIndex", 1)
self:SetAttribute("columnAnchorPoint", DIRECTION_TO_COLUMN_ANCHOR_POINT[direction])
self:SetAttribute("useOwnerUnit", 1)
-- Set the attributes for the StateHeader to know when to show and hide this
-- group
for k,v in pairs(show_when) do
local value = enabled and v
if group_based then
if k == "solo" then
value = enabled and show_solo and party_based
elseif k == "party" then
value = value and party_based
end
end
self:SetAttribute(k, value)
end
self:RefixSizeAndPosition()
if is_shown then
self:Show()
end
if force_show then
self:ForceShow()
end
for _, frame in self:IterateMembers() do
frame.dont_update = nil
end
self.dont_update = nil
if changed_units and not dont_refresh_children then
for _, frame in self:IterateMembers() do
frame:RefreshLayout()
end
end
end
GroupHeader.RefreshGroup = PitBull4:OutOfCombatWrapper(GroupHeader.RefreshGroup)
--- Recheck the layout of the group header, refreshing the layout of all members.
-- @param dont_refresh_children don't call :RefreshLayout on the child frames
-- @usage header:RefreshLayout()
function GroupHeader:RefreshLayout(dont_refresh_children)
self:RefixSizeAndPosition()
self:UpdateConfigAnchorLine()
if not dont_refresh_children then
for _, frame in self:IterateMembers() do
frame:RefreshLayout()
end
end
end
GroupHeader.RefreshLayout = PitBull4:OutOfCombatWrapper(GroupHeader.RefreshLayout)
--- Initialize a member frame. This should be called once per member frame immediately following the frame's creation.
-- @usage header:InitializeConfigFunction()
function GroupHeader:InitialConfigFunction()
-- Since Cataclysm, the frame is not passed into us but the new
-- GroupHeader does set the 1..n array slots to the frames.
-- Since this function is only called on the creation of a new
-- frame the newest frame will always be the last array slot
local frame = self[#self]
frame.header = self
frame.is_singleton = false
frame.classification = self.name
frame.classification_db = self.group_db
frame.is_wacky = self.is_wacky
local layout = self.group_db.layout
frame.layout = layout
PitBull4:ConvertIntoUnitFrame(frame)
if frame:CanChangeAttribute() then
if self.unitsuffix then
frame:ProxySetAttribute("unitsuffix", self.unitsuffix)
end
local layout_db = PitBull4.db.profile.layouts[layout]
frame.layout_db = layout_db
frame:ProxySetAttribute("initial-width", layout_db.size_x * self.group_db.size_x)
frame:ProxySetAttribute("initial-height", layout_db.size_y * self.group_db.size_y)
frame:ProxySetAttribute("initial-unitWatch", true)
end
frame:_RefreshLayout() -- Normally protected by an OutOfCombatWrapper
end
local function should_show_header(config_mode, header)
if not config_mode then
return false
end
if config_mode == "solo" then
return header.show_solo
end
if header.group_based and config_mode == "party" and header.super_unit_group ~= "party" then
return false
end
return true
end
function GroupHeader:RecheckConfigMode()
if self.group_db.enabled and should_show_header(PitBull4.config_mode, self) then
self:ForceShow()
else
self:UnforceShow()
end
self:UpdateConfigAnchorLine()
end
--- Force unit frames to be created on the group header, even if those units don't exist.
-- @usage header:ForceUnitFrameCreation()
function GroupHeader:ForceUnitFrameCreation()
local num = self:GetMaxUnits()
if self[num] then
return
end
local rehide = false
local maxColumns = self:GetAttribute("maxColumns")
local unitsPerColumn = self:GetAttribute("unitsPerColumn")
local startingIndex = self:GetAttribute("startingIndex")
if unitsPerColumn and num > unitsPerColumn then
self:ProxySetAttribute("maxColumns", num / unitsPerColumn)
else
self:ProxySetAttribute("maxColumns", 1)
self:ProxySetAttribute("unitsPerColumn", num)
end
if not self:IsShown() then
self:Show()
rehide = true
end
self:SetAttribute("startingIndex", -num + 1) -- Not proxied to ensure an Update happens
self:ProxySetAttribute("maxColumns", maxColumns)
self:ProxySetAttribute("unitsPerColumn", unitsPerColumn)
self:SetAttribute("startingIndex", startingIndex) -- Not proxied to ensure an Update happens
if rehide then
self:Hide()
end
-- this is done because the previous hack can mess up some unit references
for _, frame in self:IterateMembers() do
local unit = SecureButton_GetModifiedUnit(frame, "LeftButton")
if unit ~= frame.unit then
frame.unit = unit
frame:Update()
end
end
end
GroupHeader.ForceUnitFrameCreation = PitBull4:OutOfCombatWrapper(GroupHeader.ForceUnitFrameCreation)
local function hook_SecureGroupHeader_Update()
hook_SecureGroupHeader_Update = nil
local function hook(self)
if not PitBull4.all_headers[self] then
return
end
if not self.force_show then
return
end
if not in_force_show then
self:RecheckConfigMode()
end
PitBull4:ScheduleTimer(self.ApplyConfigModeState, 0, self)
end
hooksecurefunc("SecureGroupHeader_Update", hook)
hooksecurefunc("SecureGroupPetHeader_Update", hook)
end
-- utility function for ApplyConfigModeState
local function fill_table(tbl, ...)
for i = 1, select('#', ...), 1 do
local key = select(i, ...)
key = tonumber(key) or strtrim(key)
tbl[key] = i
end
end
-- utility function for ApplyConfigModeState
local function double_fill_table(tbl, ...)
fill_table(tbl, ...)
for i = 1, select('#', ...), 1 do
local key = select(i, ...)
tbl[i] = strtrim(key)
end
end
-- utility function for ApplyConfigModeState, it doctors
-- up some data so don't reuse this elsewhere
local function get_group_roster_info(super_unit_group, index)
local _, unit, name, subgroup, class_name, role, server, assigned_role
if super_unit_group == "raid" then
unit = "raid"..index
name, _, subgroup, _, _, class_name, _, _, _, role, _, assigned_role = GetRaidRosterInfo(index)
elseif super_unit_group == "boss" then
unit = "boss"..index
if UnitExists(unit) then
name = UnitName(unit)
class_name = UnitClassBase(unit)
subgroup = 1
end
elseif super_unit_group == "arena" then
unit = "arena"..index
if UnitExists(unit) then
name, server = UnitName(unit)
if server and server ~= "" then
name = name.."-"..server
end
class_name = UnitClassBase(unit)
subgroup = 1
end
else
if index > 0 then
unit = "party"..index
else
unit = "player"
end
if UnitExists(unit) then
name, server = UnitName(unit)
if server and server ~= "" then
name = name.."-"..server
end
class_name = UnitClassBase(unit)
-- The UnitInParty and UnitInRaid checks are an ugly workaround for thee
-- You are not in a party bug that Blizzard created.
if not PitBull4.leaving_world and (UnitInParty(unit) or UnitInRaid(unit)) then
if GetPartyAssignment("MAINTANK", unit) then
role = "MAINTANK"
elseif GetPartyAssignment("MAINASSIST", unit) then
role = "MAINASSIST"
end
end
assigned_role = UnitGroupRolesAssigned(unit)
subgroup = 1
end
end
-- return some bogus data to get our fake unit ids to sort where we want.
if not name then
name = string.format("~%02d",index)
subgroup = 0
class_name = '!'
end
return unit, name, subgroup, class_name, role, assigned_role
end
-- utility function for ApplyConfigModeState
-- Give a point return the opposite point and which axes the point
-- depends on.
local function get_relative_point_anchor(point)
point = point:upper()
if point == "TOP" then
return "BOTTOM", 0, -1
elseif point == "BOTTOM" then
return "TOP", 0, 1
elseif point == "LEFT" then
return "RIGHT", 1, 0
elseif point =="RIGHT" then
return "LEFT", -1, 0
elseif point == "TOPLEFT" then
return "BOTTOMRIGHT", 1, -1
elseif point == "TOPRIGHT" then
return "BOTTOMLEFT", -1, -1
elseif point == "BOTTOMLEFT" then
return "TOPRIGHT", 1, 1
elseif point == "BOTTOMRIGHT" then
return "TOPLEFT", -1, 1
else
return "CENTER", 0, 0
end
end
-- Tables used by ApplyConfigModeState
local sorting_table = {}
local token_table = {}
local grouping_table = {}
local temp_table = {}
-- utility function for ApplyConfigModeState
local function sort_on_group_with_names(a, b)
local order1 = token_table[ grouping_table[a] ]
local order2 = token_table[ grouping_table[b] ]
if order1 then
if not order2 then
return true
else
if order1 == order2 then
return sorting_table[a] < sorting_table[b]
else
return order1 < order2
end
end
else
if order2 then
return false
else
return sorting_table[a] < sorting_table[b]
end
end
end
-- utility function for ApplyConfigModeState
local function sort_on_group_with_ids(a, b)