This repository has been archived by the owner on Jan 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Layout.lua
executable file
·1354 lines (1186 loc) · 38.9 KB
/
Layout.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
--[[--------------------------------------------------------------------
Grid
Compact party and raid unit frames.
Copyright (c) 2006-2009 Kyle Smith (Pastamancer)
Copyright (c) 2009-2018 Phanx <[email protected]>
All rights reserved. See the accompanying LICENSE file for details.
https://github.com/Phanx/Grid
https://www.curseforge.com/wow/addons/grid
https://www.wowinterface.com/downloads/info5747-Grid.html
----------------------------------------------------------------------]]
local GRID, Grid = ...
local L = Grid.L
local GridFrame
local GridRoster = Grid:GetModule("GridRoster")
local Media = LibStub("LibSharedMedia-3.0")
local GridLayout = Grid:NewModule("GridLayout", "AceBucket-3.0", "AceTimer-3.0")
GridLayout.LayoutList = {}
local floor, next, pairs, select, tinsert, tonumber, tostring = floor, next, pairs, select, tinsert, tonumber, tostring
local partyHandle
-- Mythic Raid IDs
-- http://wow.gamepedia.com/API_GetDifficultyInfo
local mythicIDS = {
[16] = true, -- 20-player Mythic
}
------------------------------------------------------------------------
CONFIGMODE_CALLBACKS = CONFIGMODE_CALLBACKS or {}
CONFIGMODE_CALLBACKS["Grid"] = function(action)
if action == "ON" then
GridLayout.config_mode = true
elseif action == "OFF" then
GridLayout.config_mode = nil
end
GridLayout:UpdateTabVisibility()
end
------------------------------------------------------------------------
GridLayout.prototype = {}
function GridLayout.prototype:Reset()
self:Hide()
self:SetAttribute("showPlayer", true)
self:SetAttribute("showSolo", true)
self:SetAttribute("showParty", true)
self:SetAttribute("showRaid", true)
self:SetAttribute("columnSpacing", nil)
self:SetAttribute("groupBy", nil)
self:SetAttribute("groupFilter", nil)
self:SetAttribute("groupingOrder", nil)
self:SetAttribute("maxColumns", nil)
self:SetAttribute("nameList", nil)
self:SetAttribute("roleFilter", nil)
self:SetAttribute("sortDir", nil)
self:SetAttribute("sortMethod", "INDEX")
self:SetAttribute("startingIndex", nil)
self:SetAttribute("strictFiltering", nil)
self:SetAttribute("xOffset", nil)
self:SetAttribute("yOffset", nil)
self:SetAttributeByProxy("columnAnchorPoint", nil)
self:SetAttributeByProxy("point", nil)
self:SetAttributeByProxy("unitsPerColumn", nil)
self:SetAttribute("gridGroupSpacing", nil) -- custom
self:SetAttribute("initialConfigFunction", GridLayout:GetInitialConfigSnippet())
end
function GridLayout.prototype:SetAttributeByProxy(name, value)
if name == "point" or name == "columnAnchorPoint" or name == "unitsPerColumn" then
GridLayout:Debug("SetAttributeByProxy", self:GetName(), name, tostring(value))
local count = 1
local frame = self:GetAttribute("child" .. count)
while frame do
-- GridLayout:Debug("ClearAllPoints", frame:GetName())
frame:ClearAllPoints()
count = count + 1
frame = self:GetAttribute("child" .. count)
end
end
self:SetAttribute(name, value)
end
-- nil or false for vertical
function GridLayout.prototype:SetOrientation(horizontal)
local p = GridLayout.db.profile
local groupAnchor = p.groupAnchor
local padding = p.unitSpacing
local xOffset, yOffset, point
if horizontal then
if groupAnchor == "TOPLEFT" or groupAnchor == "BOTTOMLEFT" then
xOffset = padding
yOffset = 0
point = "LEFT"
else
xOffset = -padding
yOffset = 0
point = "RIGHT"
end
else
if groupAnchor == "TOPLEFT" or groupAnchor == "TOPRIGHT" then
xOffset = 0
yOffset = -padding
point = "TOP"
else
xOffset = 0
yOffset = padding
point = "BOTTOM"
end
end
self:SetAttributeByProxy("point", point)
self:SetAttribute("xOffset", xOffset)
self:SetAttribute("yOffset", yOffset)
end
-- return the number of visible units belonging to the GroupHeader
function GridLayout.prototype:GetVisibleUnitCount()
local count = 0
while self:GetAttribute("child" .. count) do
count = count + 1
end
return count
end
function GridLayout.prototype:initialConfigFunction(...)
GridFrame:RegisterFrame(self[#self])
end
------------------------------------------------------------------------
local initialConfigSnippet = [[
RegisterUnitWatch(self)
self:SetAttribute("*type1", "target")
self:SetAttribute("toggleForVehicle", true)
local header = self:GetParent()
if header:GetAttribute("unitsuffix") == "pet" then
self:SetAttribute("useOwnerUnit", true)
self:SetAttribute("unitsuffix", "pet")
end
local click = header:GetFrameRef("clickcast_header")
if click then
click:SetAttribute("clickcast_button", self)
click:RunAttribute("clickcast_register")
end
header:CallMethod("initialConfigFunction")
]]
function GridLayout:GetInitialConfigSnippet()
return initialConfigSnippet .. GridFrame:GetInitialConfigSnippet()
end
function GridLayout:SetInitialConfigSnippet()
for i = 1, #self.layoutGroups do
self.layoutGroups[i]:SetAttribute("initialConfigFunction", GridLayout:GetInitialConfigSnippet())
end
for i = 1, #self.layoutPetGroups do
self.layoutGroups[i]:SetAttribute("initialConfigFunction", GridLayout:GetInitialConfigSnippet())
end
end
------------------------------------------------------------------------
local NUM_HEADERS = 0
function GridLayout:CreateHeader(isPetGroup)
--self:Debug("CreateHeader")
NUM_HEADERS = NUM_HEADERS + 1
local header = CreateFrame("Frame", "GridLayoutHeader" .. NUM_HEADERS, GridLayoutFrame, (isPetGroup and "SecureGroupPetHeaderTemplate" or "SecureGroupHeaderTemplate"))
for k, v in pairs(self.prototype) do
header[k] = v
end
if Clique then
header:SetAttribute("template", "ClickCastUnitTemplate,SecureUnitButtonTemplate")
SecureHandlerSetFrameRef(header, "clickcast_header", Clique.header)
else
header:SetAttribute("template", "SecureUnitButtonTemplate")
end
-- Fix for bug on the Blizz end when using SecureActionButtonTemplate with SecureGroupPetHeaderTemplate
-- http://forums.wowace.com/showpost.php?p=307869&postcount=3216
if isPetGroup then
header:SetAttribute("useOwnerUnit", true)
header:SetAttribute("unitsuffix", "pet")
end
header:SetAttribute("initialConfigFunction", GridLayout:GetInitialConfigSnippet())
header:Reset()
return header
end
------------------------------------------------------------------------
GridLayout.defaultDB = {
layouts = {
solo = "ByGroup",
party = "ByGroup",
raid = "ByRole",
arena = "ByGroup",
bg = "ByGroup",
},
lock = false,
horizontal = false,
showPets = false,
showOffline = false,
showWrongZone = "MYTHIC",
layoutPadding = 10,
unitSpacing = 1,
scale = 1,
backgroundColor = { r = 0.1, g = 0.1, b = 0.1, a = 0.65 },
backgroundTexture = "Blizzard Tooltip",
borderColor = { r = 0.5, g = 0.5, b = 0.5, a = 1 },
borderTexture = "Blizzard Tooltip",
borderSize = 16,
borderInset = 4,
anchor = "TOPLEFT",
groupAnchor = "TOPLEFT",
hideTab = false,
PosX = 500,
PosY = -400,
}
------------------------------------------------------------------------
GridLayout.options = {
name = L["Layout"],
disabled = InCombatLockdown,
order = 1,
type = "group",
get = function(info)
local k = info[#info]
local v = GridLayout.db.profile[k]
if type(v) == "table" and v.r and v.g and v.b then
return v.r, v.g, v.b, v.a
else
return v
end
end,
set = function(info, v)
local k = info[#info]
GridLayout.db.profile[k] = v
end,
args = {
lock = {
name = L["Frame lock"],
desc = L["Locks/unlocks the grid for movement."],
order = 2,
width = "double",
type = "toggle",
set = function(info, v)
GridLayout.db.profile.lock = v
GridLayout:UpdateTabVisibility()
end,
},
tab = {
name = L["Show tab"],
desc = L["Show a tab for dragging when Grid is unlocked."],
order = 4,
width = "double",
type = "toggle",
get = function()
return not GridLayout.db.profile.hideTab
end,
set = function(info, show)
GridLayout.db.profile.hideTab = not show
GridLayout:UpdateTabVisibility()
end,
},
clickThrough = {
name = L["Click through background"],
desc = L["Allow mouse clicks to pass through the background when Grid is locked."],
order = 6,
width = "double",
type = "toggle",
get = function()
return GridLayout.db.profile.clickThrough
end,
set = function(info, value)
GridLayout.db.profile.clickThrough = value
GridLayout:UpdateTabVisibility()
end,
},
horizontal = {
name = L["Horizontal groups"],
desc = L["Switch between horizontal/vertical groups."],
order = 8,
width = "double",
type = "toggle",
set = function(info, v)
GridLayout.db.profile.horizontal = v
GridLayout:ReloadLayout()
end,
},
--@debug@
splitGroups = {
name = COMPACT_UNIT_FRAME_PROFILE_KEEPGROUPSTOGETHER, -- L["Keep Groups Together"]
desc = L["Layouts added by plugins might not support this option."], -- TODO
order = 10,
width = "double",
type = "toggle",
set = function(info, v)
GridLayout.db.profile.splitGroups = v
GridLayout:GetModule("GridLayoutManager"):UpdateLayouts()
end,
},
--@end-debug@
showPets = {
name = COMPACT_UNIT_FRAME_PROFILE_DISPLAYPETS, -- L["Show Pets"]
desc = L["Layouts added by plugins might not support this option."], -- TODO
order = 12,
width = "double",
type = "toggle",
set = function(info, v)
GridLayout.db.profile.showPets = v
GridLayout:GetModule("GridLayoutManager"):UpdateLayouts()
end,
},
layouts = {
name = L["Layouts"],
order = 18,
type = "group",
dialogInline = true,
get = function(t)
return GridLayout.db.profile.layouts[t[#t]]
end,
set = function(t, v)
GridLayout.db.profile.layouts[t[#t]] = v
GridLayout:ReloadLayout()
end,
args = {
solo = {
name = L["Solo Layout"],
order = 2,
width = "double",
type = "select",
values = GridLayout.LayoutList,
},
party = {
name = L["Party Layout"],
order = 4,
width = "double",
type = "select",
values = GridLayout.LayoutList,
},
raid = {
name = L["Raid Layout"],
order = 6,
width = "double",
type = "select",
values = GridLayout.LayoutList,
},
arena = {
name = L["Arena Layout"],
order = 10,
width = "double",
type = "select",
values = GridLayout.LayoutList,
},
bg = {
name = L["Battleground Layout"],
order = 12,
width = "double",
type = "select",
values = GridLayout.LayoutList,
},
},
},
background = {
name = L["Layout Background"],
order = 20,
type = "group",
dialogInline = true,
args = {
backgroundColor = {
name = L["Background color"],
order = 21,
width = "double",
type = "color", hasAlpha = true,
set = function(info, r, g, b, a)
local color = GridLayout.db.profile.backgroundColor
color.r, color.g, color.b, color.a = r, g, b, a
GridLayout:UpdateColor()
end,
},
borderColor = {
name = L["Border color"],
order = 22,
width = "double",
type = "color", hasAlpha = true,
set = function(info, r, g, b, a)
local color = GridLayout.db.profile.borderColor
color.r, color.g, color.b, color.a = r, g, b, a
GridLayout:UpdateColor()
end,
},
backgroundTexture = {
name = L["Background Texture"],
order = 23,
width = "double",
type = "select",
dialogControl = "LSM30_Background",
values = Media:HashTable("background"),
set = function(info, v)
GridLayout.db.profile.backgroundTexture = v
GridLayout:UpdateColor()
end,
},
borderTexture = {
name = L["Border Texture"],
order = 24,
width = "double",
type = "select",
dialogControl = "LSM30_Border",
values = Media:HashTable("border"),
set = function(info, v)
GridLayout.db.profile.borderTexture = v
GridLayout:UpdateColor()
end,
},
borderSize = {
name = L["Border Size"],
order = 25,
width = "double",
type = "range", min = 1, max = 64, step = 1,
set = function(info, v)
GridLayout.db.profile.borderSize = v
GridLayout:UpdateColor()
end,
},
borderInset = {
name = L["Border Inset"],
order = 26,
width = "double",
type = "range", min = 0, max = 32, step = 1,
set = function(info, v)
GridLayout.db.profile.borderInset = v
GridLayout:UpdateColor()
end,
}
}
},
anchor = {
name = L["Layout Anchor"],
desc = L["Sets where Grid is anchored relative to the screen."],
order = 30,
width = "double",
type = "select",
values = {
CENTER = L["Center"],
TOP = L["Top"],
BOTTOM = L["Bottom"],
LEFT = L["Left"],
RIGHT = L["Right"],
TOPLEFT = L["Top Left"],
TOPRIGHT = L["Top Right"],
BOTTOMLEFT = L["Bottom Left"],
BOTTOMRIGHT = L["Bottom Right"],
},
set = function(info, v)
GridLayout.db.profile.anchor = v
GridLayout:SavePosition()
GridLayout:RestorePosition()
end,
},
groupAnchor = {
name = L["Group Anchor"],
desc = L["Sets where groups are anchored relative to the layout frame."],
order = 32,
width = "double",
type = "select",
values = {
TOPLEFT = L["Top Left"],
TOPRIGHT = L["Top Right"],
BOTTOMLEFT = L["Bottom Left"],
BOTTOMRIGHT = L["Bottom Right"],
},
set = function(info, v)
GridLayout.db.profile.groupAnchor = v
GridLayout:ReloadLayout()
end,
},
unitSpacing = {
name = L["Unit Spacing"],
desc = L["Adjust the spacing between the individual unit frames."],
order = 34,
width = "double",
type = "range", max = 20, min = 0, step = 1,
set = function(info, v)
GridLayout.db.profile.unitSpacing = v
GridLayout:ReloadLayout()
end,
},
layoutPadding = {
name = L["Layout Padding"],
desc = L["Adjust the extra spacing inside the layout frame, around the unit frames."],
order = 36,
width = "double",
type = "range", min = 0, max = 25, step = 1,
set = function(info, v)
GridLayout.db.profile.layoutPadding = v
GridLayout:ReloadLayout()
end,
},
scale = {
name = L["Scale"],
order = 38,
width = "double",
type = "range", min = 0.5, max = 2.0, step = 0.05, isPercent = true,
set = function(info, v)
GridLayout.db.profile.scale = v
GridLayout:Scale()
end,
},
reset = {
name = L["Reset Position"],
order = -1,
width = "double",
type = "execute",
func = function() GridLayout:ResetPosition() end,
},
groupOptions = {
name = L["ByGroup Layout Options"],
order = 20,
type = "group",
dialogInline = true,
args = {
showOffline = {
name = L["Show Offline"],
desc = L["Show groups with all players offline."],
order = 12,
width = "double",
type = "toggle",
set = function(info, v)
GridLayout.db.profile.showOffline = v
GridLayout:GetModule("GridLayoutManager"):UpdateLayouts()
end,
},
showWrongZone = {
name = L["Wrong Zone"],
desc = L["Show groups with all players in wrong zone."],
order = 12,
width = "double",
type = "select",
values = {
ALL = L["Show all groups"],
HIDE = L["Always hide wrong zone groups"],
RAIDINST = L["Hide when in raid instance"],
MYTHIC = L["Hide when in mythic raid instance"],
},
set = function(info, v)
GridLayout.db.profile.showWrongZone = v
GridLayout:GetModule("GridLayoutManager"):UpdateLayouts()
end,
},
}
},
},
}
------------------------------------------------------------------------
GridLayout.layoutSettings = {}
function GridLayout:PostInitialize()
--self:Debug("PostInitialize")
GridFrame = Grid:GetModule("GridFrame")
self.layoutGroups = {}
self.layoutPetGroups = {}
if not self.frame then
self:CreateFrames()
end
end
function GridLayout:PostEnable()
--self:Debug("PostEnable")
self:Debug("OnEnable")
self:UpdateTabVisibility()
self.forceRaid = true
self:ScheduleTimer(self.CombatFix, 1, self)
self:LoadLayout(self.db.profile.layout or self.db.profile.layouts["raid"])
-- position and scale frame
self:RestorePosition()
self:Scale()
self:RegisterMessage("Grid_ReloadLayout", "PartyTypeChanged")
self:RegisterMessage("Grid_PartyTransition", "PartyTypeChanged")
self:RegisterBucketMessage("Grid_UpdateLayoutSize", 0.2, "PartyMembersChanged")
self:RegisterMessage("Grid_RosterUpdated", "PartyMembersChanged")
self:RegisterEvent("GROUP_ROSTER_UPDATE", "PartyMembersChanged")
self:RegisterEvent("PLAYER_ENTERING_WORLD", "ZoneCheck")
self:RegisterMessage("Grid_EnteringCombat", "EnteringCombat")
self:RegisterMessage("Grid_LeavingCombat", "LeavingCombat")
end
function GridLayout:PostDisable()
--self:Debug("PostDisable")
self.frame:Hide()
end
function GridLayout:PostReset()
--self:Debug("PostReset")
self:ReloadLayout()
-- position and scale frame
self:RestorePosition()
self:Scale()
self:UpdateTabVisibility()
end
------------------------------------------------------------------------
local reloadLayoutQueued
local updateSizeQueued
function GridLayout:EnteringCombat()
-- Do not perform layout update checks in combat
if partyHandle then
partyHandle = self:CancelTimer(partyHandle) -- returns nil
end
--self:Debug("EnteringOrLeavingCombat")
if reloadLayoutQueued then return self:PartyTypeChanged() end
if updateSizeQueued then return self:PartyMembersChanged() end
end
function GridLayout:LeavingCombat()
--self:Debug("EnteringOrLeavingCombat")
-- When out of combat, check if the number of groups changed every 10 seconds
-- Basing this off events is not working, as it seems to take a variable amount of time for the new player
-- to show online
if not partyHandle then
partyHandle = self:ScheduleRepeatingTimer("Grid_CheckPartyMembersUpdate", 10)
end
if reloadLayoutQueued then return self:PartyTypeChanged() end
-- If we know the party size changed, definitely do an update
if updateSizeQueued then return self:PartyMembersChanged() end
-- Otherwise, check to see if the layout needs updating
self:Grid_CheckPartyMembersUpdate()
end
function GridLayout:CombatFix()
--self:Debug("CombatFix")
self:Debug("CombatFix")
self.forceRaid = false
return self:ReloadLayout()
end
function GridLayout:Grid_CheckPartyMembersUpdate()
local update_size
if InCombatLockdown() then
return
end
update_size = GridLayout:GetModule("GridLayoutManager"):UpdateLayouts()
if update_size then
self:PartyMembersChanged()
end
end
function GridLayout:PartyMembersChanged()
--self:Debug("PartyMembersChanged")
self:Debug("PartyMembersChanged")
if InCombatLockdown() then
updateSizeQueued = true
else
self:UpdateSize()
updateSizeQueued = false
end
end
function GridLayout:ShowWrongZone()
local showWrongZone = false
local name, instType, diffIndex = GetInstanceInfo()
-- Show groups in wrong zone
if self.db.profile.showWrongZone == "ALL" then
-- Always show groups in wrong zone
showWrongZone = true
elseif self.db.profile.showWrongZone == "MYTHIC" and not mythicIDS[diffIndex] then
-- Show groups in wrong zone when not in Mythic raid instance
showWrongZone = true
elseif self.db.profile.showWrongZone == "RAIDINST" and instType ~= "raid" then
-- Show groups in wrong zone when not in raid instance
showWrongZone = true
end
return showWrongZone
end
-- If we only show groups that are in the correct zone, then
-- update which groups are shown when the player changes zones
function GridLayout:ZoneCheck()
self:Debug("ZoneCheck")
if (self:ShowWrongZone()) then
return
elseif InCombatLockdown() then
updateSizeQueued = true
else
self:UpdateSize()
updateSizeQueued = false
end
end
function GridLayout:PartyTypeChanged()
--self:Debug("PartyTypeChanged")
self:Debug("PartyTypeChanged")
if InCombatLockdown() then
reloadLayoutQueued = true
else
self:ReloadLayout()
reloadLayoutQueued = false
updateSizeQueued = false
end
end
------------------------------------------------------------------------
function GridLayout:StartMoveFrame()
--self:Debug("StartMoveFrame")
if self.config_mode or not self.db.profile.lock then
self.frame:StartMoving()
self.frame.isMoving = true
end
end
function GridLayout:StopMoveFrame()
--self:Debug("StopMoveFrame")
if self.frame.isMoving then
self.frame:StopMovingOrSizing()
self:SavePosition()
self.frame.isMoving = false
if not InCombatLockdown() then
self:RestorePosition()
end
end
end
function GridLayout:UpdateTabVisibility()
local settings = self.db.profile
--print("UpdateTabVisibility", not settings.hideTab)
if not InCombatLockdown() then
if settings.lock and settings.clickThrough and not self.config_mode then
self.frame:EnableMouse(false)
else
self.frame:EnableMouse(true)
end
end
if settings.hideTab or (not self.config_mode and settings.lock) then
self.frame.tab:Hide()
else
self.frame.tab:Show()
end
end
local function GridLayout_OnMouseDown(frame, button)
if button == "LeftButton" then
if IsAltKeyDown() and frame == GridLayoutFrame.tab then
GridLayout.db.profile.hideTab = true
GridLayout:UpdateTabVisibility()
else
GridLayout:StartMoveFrame()
end
elseif button == "RightButton" and frame == GridLayoutFrame.tab and not InCombatLockdown() then
Grid:ToggleOptions()
end
end
local function GridLayout_OnMouseUp(frame)
GridLayout:StopMoveFrame()
end
local function GridLayout_OnEnter(frame)
local tip = GameTooltip
tip:SetOwner(frame, "ANCHOR_LEFT")
tip:SetText(L["Drag this tab to move Grid."])
tip:AddLine(L["Lock Grid to hide this tab."])
tip:AddLine(L["Alt-Click to permanantly hide this tab."])
tip:AddLine(L["Right-Click for more options."])
tip:Show()
end
local function GridLayout_OnLeave(frame)
GameTooltip:Hide()
end
function GridLayout:CreateFrames()
--self:Debug("CreateFrames")
-- create pet battle hider
local hider = CreateFrame("Frame", "GridPetBattleFrameHider", UIParent, "SecureHandlerStateTemplate")
hider:SetAllPoints(true)
RegisterStateDriver(hider, "visibility", "[petbattle] hide; show")
-- create main frame to hold all our gui elements
local f = CreateFrame("Frame", "GridLayoutFrame", hider)
f:SetPoint("CENTER")
f:SetMovable(true)
f:SetClampedToScreen(true)
f:SetScript("OnMouseDown", GridLayout_OnMouseDown)
f:SetScript("OnMouseUp", GridLayout_OnMouseUp)
f:SetScript("OnHide", GridLayout_OnMouseUp)
-- create backdrop
f.backdrop = CreateFrame("Frame", "$parentBackdrop", f)
f.backdrop:SetPoint("BOTTOMLEFT", -4, -4)
f.backdrop:SetPoint("TOPRIGHT", 4, 4)
f.backdrop:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground", tile = false, tileSize = 16,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4},
})
f:SetFrameLevel(f.backdrop:GetFrameLevel() + 2)
-- create drag handle
f.tab = CreateFrame("Frame", "$parentTab", f)
f.tab:SetWidth(48)
f.tab:SetHeight(28)
f.tab:EnableMouse(true)
f.tab:RegisterForDrag("LeftButton")
f.tab:SetPoint("BOTTOMLEFT", f.backdrop, "TOPLEFT", 2, -3)
f.tab:SetScript("OnMouseDown", GridLayout_OnMouseDown)
f.tab:SetScript("OnMouseUp", GridLayout_OnMouseUp)
f.tab:SetScript("OnEnter", GridLayout_OnEnter)
f.tab:SetScript("OnLeave", GridLayout_OnLeave)
-- Tab Background
f.tabBgLeft = f.tab:CreateTexture(nil, "BACKGROUND")
f.tabBgLeft:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
f.tabBgLeft:SetTexCoord(0, 0.25, 0, 1)
f.tabBgLeft:SetPoint("TOPLEFT", 0, 5)
f.tabBgLeft:SetPoint("BOTTOMLEFT", 0, 0)
f.tabBgLeft:SetWidth(16)
f.tabBgLeft:SetAlpha(0.9)
f.tabBgRight = f.tab:CreateTexture(nil, "BACKGROUND")
f.tabBgRight:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
f.tabBgRight:SetTexCoord(0.75, 1, 0, 1)
f.tabBgRight:SetPoint("TOPRIGHT", 0, 5)
f.tabBgRight:SetPoint("BOTTOMRIGHT", 0, 0)
f.tabBgRight:SetWidth(16)
f.tabBgRight:SetAlpha(0.9)
f.tabBgMiddle = f.tab:CreateTexture(nil, "BACKGROUND")
f.tabBgMiddle:SetTexture("Interface\\ChatFrame\\ChatFrameTab")
f.tabBgMiddle:SetTexCoord(0.25, 0.75, 0, 1)
f.tabBgMiddle:SetPoint("BOTTOMLEFT", f.tabBgLeft, "BOTTOMRIGHT", 0, 0)
f.tabBgMiddle:SetPoint("BOTTOMRIGHT", f.tabBgRight, "BOTTOMLEFT", 0, 0)
f.tabBgMiddle:SetPoint("TOP", f.tab, "TOP", 0, 5)
-- Tab Label
f.tabText = f.tab:CreateFontString(nil, "BACKGROUND", "GameFontNormalSmall")
f.tabText:SetText("Grid")
f.tabText:SetPoint("LEFT", 0, -3)
f.tabText:SetPoint("RIGHT", 0, -3)
self.frame = f
end
local function getRelativePoint(point, horizontal)
if point == "TOPLEFT" then
if horizontal then
return "BOTTOMLEFT", 1, -1
else
return "TOPRIGHT", 1, -1
end
elseif point == "TOPRIGHT" then
if horizontal then
return "BOTTOMRIGHT", -1, -1
else
return "TOPLEFT", -1, -1
end
elseif point == "BOTTOMLEFT" then
if horizontal then
return "TOPLEFT", 1, 1
else
return "BOTTOMRIGHT", 1, 1
end
elseif point == "BOTTOMRIGHT" then
if horizontal then
return "TOPRIGHT", -1, 1
else
return "BOTTOMLEFT", -1, 1
end
end
end
local previousGroup
function GridLayout:PlaceGroup(layoutGroup, groupNumber)
--self:Debug("PlaceGroup", groupNumber)
local frame = layoutGroup.frame
local settings = self.db.profile
local horizontal = settings.horizontal
local padding = settings.unitSpacing
local spacing = settings.layoutPadding
local groupAnchor = settings.groupAnchor
local relPoint, xMult, yMult = getRelativePoint(groupAnchor, horizontal)
layoutGroup:ClearAllPoints()
layoutGroup:SetParent(self.frame)
if groupNumber == 1 then
layoutGroup:SetPoint(groupAnchor, self.frame, groupAnchor, spacing * xMult, spacing * yMult)
else
local xPlus, yPlus = 0, 0
if horizontal then
xMult = 0
xPlus = tonumber(layoutGroup:GetAttribute("gridGroupSpacing")) or 0
else
yMult = 0
yPlus = tonumber(layoutGroup:GetAttribute("gridGroupSpacing")) or 0
end
layoutGroup:SetPoint(groupAnchor, previousGroup, relPoint, (padding * xMult) + xPlus, (padding * yMult) + yPlus)
end
self:Debug("Placing group", groupNumber, layoutGroup:GetName(), groupNumber == 1 and self.frame:GetName() or groupAnchor, previousGroup and previousGroup:GetName(), relPoint)
previousGroup = layoutGroup
end
function GridLayout:AddLayout(name, layout)
--self:Debug("AddLayout", layoutName)
self.layoutSettings[name] = layout
self.LayoutList[name] = layout.name or name -- for options
end
function GridLayout:ReloadLayout(event)
local party_type = GridRoster:GetPartyState()
self:Debug("ReloadLayout", event, party_type)
self:LoadLayout(self.db.profile.layouts[party_type])
end
local function getColumnAnchorPoint(point, horizontal)
if not horizontal then
if point == "TOPLEFT" or point == "BOTTOMLEFT" then
return "LEFT"
elseif point == "TOPRIGHT" or point == "BOTTOMRIGHT" then
return "RIGHT"
end
else
if point == "TOPLEFT" or point == "TOPRIGHT" then
return "TOP"
elseif point == "BOTTOMLEFT" or point == "BOTTOMRIGHT" then
return "BOTTOM"
end
end
return point
end
function GridLayout:LoadLayout(layoutName)
local p = self.db.profile
local layout = self.layoutSettings[layoutName]
self.db.profile.layout = layoutName
if InCombatLockdown() then
reloadLayoutQueued = true
return
end
self:Debug("LoadLayout", layoutName)
-- layout not ready yet
if type(layout) ~= "table" then