-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpanel.lua
5482 lines (4503 loc) · 176 KB
/
panel.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 detailsFramework = _G ["DetailsFramework"]
if (not detailsFramework or not DetailsFrameworkCanLoad) then
return
end
local _
--lua locals
local rawset = rawset --lua local
local rawget = rawget --lua local
local setmetatable = setmetatable --lua local
local unpack = table.unpack or unpack --lua local
local type = type --lua local
local floor = math.floor --lua local
local loadstring = loadstring --lua local
local CreateFrame = CreateFrame
-- TWW compatibility:
local GetSpellInfo = GetSpellInfo or function(spellID) if not spellID then return nil end local si = C_Spell.GetSpellInfo(spellID) if si then return si.name, nil, si.iconID, si.castTime, si.minRange, si.maxRange, si.spellID, si.originalIconID end end
local GetNumSpellTabs = GetNumSpellTabs or C_SpellBook.GetNumSpellBookSkillLines
local GetSpellTabInfo = GetSpellTabInfo or function(tabLine) local skillLine = C_SpellBook.GetSpellBookSkillLineInfo(tabLine) if skillLine then return skillLine.name, skillLine.iconID, skillLine.itemIndexOffset, skillLine.numSpellBookItems, skillLine.isGuild, skillLine.offSpecID end end
local SPELLBOOK_BANK_PLAYER = Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Player or "player"
local SpellBookItemTypeMap = Enum.SpellBookItemType and {[Enum.SpellBookItemType.Spell] = "SPELL", [Enum.SpellBookItemType.None] = "NONE", [Enum.SpellBookItemType.Flyout] = "FLYOUT", [Enum.SpellBookItemType.FutureSpell] = "FUTURESPELL", [Enum.SpellBookItemType.PetAction] = "PETACTION" } or {}
local GetSpellBookItemInfo = GetSpellBookItemInfo or function(...) local si = C_SpellBook.GetSpellBookItemInfo(...) if si then return SpellBookItemTypeMap[si.itemType] or "NONE", (si.itemType == Enum.SpellBookItemType.Flyout or si.itemType == Enum.SpellBookItemType.PetAction) and si.actionID or si.spellID or si.actionID, si end end
local GetSpellBookItemTexture = GetSpellBookItemTexture or function(...) return C_SpellBook.GetSpellBookItemTexture(...) end
local GetSpellTexture = GetSpellTexture or function(...) return C_Spell.GetSpellTexture(...) end
local IS_WOW_PROJECT_MAINLINE = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
local IS_WOW_PROJECT_NOT_MAINLINE = WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE
local IS_WOW_PROJECT_CLASSIC_ERA = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local CastInfo = detailsFramework.CastInfo
local PixelUtil = PixelUtil or DFPixelUtil
local UnitGroupRolesAssigned = detailsFramework.UnitGroupRolesAssigned
local cleanfunction = function() end
local APIFrameFunctions
do
local metaPrototype = {
WidgetType = "panel",
dversion = detailsFramework.dversion,
}
--check if there's a metaPrototype already existing
if (_G[detailsFramework.GlobalWidgetControlNames["panel"]]) then
--get the already existing metaPrototype
local oldMetaPrototype = _G[detailsFramework.GlobalWidgetControlNames ["panel"]]
--check if is older
if ( (not oldMetaPrototype.dversion) or (oldMetaPrototype.dversion < detailsFramework.dversion) ) then
--the version is older them the currently loading one
--copy the new values into the old metatable
for funcName, _ in pairs(metaPrototype) do
oldMetaPrototype[funcName] = metaPrototype[funcName]
end
end
else
--first time loading the framework
_G[detailsFramework.GlobalWidgetControlNames["panel"]] = metaPrototype
end
end
local PanelMetaFunctions = _G[detailsFramework.GlobalWidgetControlNames["panel"]]
detailsFramework:Mixin(PanelMetaFunctions, detailsFramework.ScriptHookMixin)
--default options for the frame layout
---@class df_framelayout_options : table
---@field amount_per_line number? 4
---@field start_x number? 2
---@field start_y number? -2
---@field is_vertical boolean? true if vertical, false if horizontal
---@field grow_right boolean? true to grow right, false to grow left
---@field grow_down boolean? true to grow down, false to grow up
---@field anchor_to_child boolean? true to anchor to the previous frame instead of coordinate
---@field anchor_point df_framelayout_point? "topleft"
---@field anchor_relative df_framelayout_point? "topleft"
---@field offset_x number? 100
---@field offset_y number? 20
---@field width number? 0
---@field min_width number? 0
---@field height number? 0
---@field break_if_hidden boolean? true to stop if encounters a hidden frame
---@field use__width boolean? if true it'll use the __width from the widget as the offset_x
local default_framelayout_options = {
amount_per_line = 4,
start_x = 2,
start_y = -2,
is_vertical = false,
grow_right = true, --on vertical (if not grow next line left)
grow_down = true, --on horizontal (if not grow next line up)
anchor_to_child = false, --if true set the point to the previous frame instead of coordinate
anchor_point = "topleft",
anchor_relative = "topleft",
offset_x = 100,
use__width = false, --__width from the widget
offset_y = 20,
width = 1,
min_width = 0,
height = 1,
break_if_hidden = true, --stop if encounters a hidden frame
}
---@alias df_framelayout_point
---| "top"
---| "bottom"
---| "left"
---| "right"
---@class df_framelayout : table
---@field AnchorTo fun(self:uiobject, anchor:uiobject, point:df_framelayout_point, x:number?, y:number?)
---@field ArrangeFrames fun(self:uiobject, frameList:table<uiobject>[], options:df_framelayout_options?)
--mixin for frame layout
detailsFramework.LayoutFrame = {
AnchorTo = function(self, anchor, point, x, y)
if (point == "top") then
self:ClearAllPoints()
self:SetPoint("bottom", anchor, "top", x or 0, y or 0)
elseif (point == "bottom") then
self:ClearAllPoints()
self:SetPoint("top", anchor, "bottom", x or 0, y or 0)
elseif (point == "left") then
self:ClearAllPoints()
self:SetPoint("right", anchor, "left", x or 0, y or 0)
elseif (point == "right") then
self:ClearAllPoints()
self:SetPoint("left", anchor, "right", x or 0, y or 0)
end
end,
ArrangeFrames = function(self, frameList, options)
if (not frameList) then
frameList = {self:GetChildren()}
end
options = options or {}
detailsFramework.table.deploy(options, default_framelayout_options)
local breakLine = options.amount_per_line + 1
local currentX, currentY = options.start_x, options.start_y
local offsetX, offsetY = options.offset_x, options.offset_y
local anchorPoint = options.anchor_point
local anchorAt = options.anchor_relative
local latestFrame = self
local firstRowFrame = frameList[1]
if (options.is_vertical) then
for i = 1, #frameList do
local thisFrame = frameList[i]
if (options.break_if_hidden and not thisFrame:IsShown()) then
break
end
thisFrame:ClearAllPoints()
if (options.anchor_to_child) then
if (i == breakLine) then
if (options.grow_right) then
thisFrame:SetPoint("topleft", firstRowFrame, "topright", offsetX, 0)
else
thisFrame:SetPoint("topright", firstRowFrame, "topleft", -offsetX, 0)
end
firstRowFrame = thisFrame
latestFrame = thisFrame
breakLine = breakLine + options.amount_per_line
else
thisFrame:SetPoint(anchorPoint, latestFrame, i == 1 and "topleft" or anchorAt, offsetX, i == 1 and 0 or offsetY)
latestFrame = thisFrame
end
else
if (i == breakLine) then
if (options.grow_right) then
currentX = currentX + offsetX
else
currentX = currentX - offsetX
end
currentY = options.start_y
firstRowFrame = thisFrame
breakLine = breakLine + options.amount_per_line
end
thisFrame:SetPoint(anchorPoint, self, anchorAt, currentX, currentY)
if (options.use__height) then --use the childframe.__width
currentY = currentY - thisFrame.__height
elseif (options.min_height) then
currentY = currentY - math.max(options.min_height, offsetY)
else
currentY = currentY - offsetY
end
end
end
else
for i = 1, #frameList do
local thisFrame = frameList[i]
if (options.break_if_hidden and not thisFrame:IsShown()) then
break
end
thisFrame:ClearAllPoints()
if (options.anchor_to_child) then
if (i == breakLine) then
if (options.grow_down) then
thisFrame:SetPoint("topleft", firstRowFrame, "bottomleft", 0, -offsetY)
else
thisFrame:SetPoint("bottomleft", firstRowFrame, "topleft", 0, offsetY)
end
firstRowFrame = thisFrame
latestFrame = thisFrame
breakLine = breakLine + options.amount_per_line
else
thisFrame:SetPoint(anchorPoint, latestFrame, i == 1 and "topleft" or anchorAt, i == 1 and 0 or offsetX, offsetY)
latestFrame = thisFrame
end
else
if (i == breakLine) then
if (options.grow_down) then
currentY = currentY - offsetY
else
currentY = currentY + offsetY
end
currentX = options.start_x
firstRowFrame = thisFrame
breakLine = breakLine + options.amount_per_line
end
thisFrame:SetPoint(anchorPoint, self, anchorAt, currentX, currentY)
if (options.use__width) then --use the childframe.__width
currentX = currentX + thisFrame.__width
elseif (options.min_width) then
currentX = currentX + math.max(options.min_width, offsetX)
else
currentX = currentX + offsetX
end
end
end
end
end
}
------------------------------------------------------------------------------------------------------------
--metatables
PanelMetaFunctions.__call = function(_table, value)
--nothing to do
return true
end
------------------------------------------------------------------------------------------------------------
--members
--tooltip
local gmember_tooltip = function(_object)
return _object:GetTooltip()
end
--shown
local gmember_shown = function(_object)
return _object:IsShown()
end
--backdrop color
local gmember_color = function(_object)
return _object.frame:GetBackdropColor()
end
--backdrop table
local gmember_backdrop = function(_object)
return _object.frame:GetBackdrop()
end
--frame width
local gmember_width = function(_object)
return _object.frame:GetWidth()
end
--frame height
local gmember_height = function(_object)
return _object.frame:GetHeight()
end
--locked
local gmember_locked = function(_object)
return rawget(_object, "is_locked")
end
PanelMetaFunctions.GetMembers = PanelMetaFunctions.GetMembers or {}
PanelMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip
PanelMetaFunctions.GetMembers ["shown"] = gmember_shown
PanelMetaFunctions.GetMembers ["color"] = gmember_color
PanelMetaFunctions.GetMembers ["backdrop"] = gmember_backdrop
PanelMetaFunctions.GetMembers ["width"] = gmember_width
PanelMetaFunctions.GetMembers ["height"] = gmember_height
PanelMetaFunctions.GetMembers ["locked"] = gmember_locked
PanelMetaFunctions.__index = function(object, key)
local func = PanelMetaFunctions.GetMembers[key]
if (func) then
return func(object, key)
end
local fromMe = rawget(object, key)
if (fromMe) then
return fromMe
end
return PanelMetaFunctions[key]
end
--tooltip
local smember_tooltip = function(_object, _value)
return _object:SetTooltip (_value)
end
--show
local smember_show = function(_object, _value)
if (_value) then
return _object:Show()
else
return _object:Hide()
end
end
--hide
local smember_hide = function(_object, _value)
if (not _value) then
return _object:Show()
else
return _object:Hide()
end
end
--backdrop color
local smember_color = function(_object, _value)
local _value1, _value2, _value3, _value4 = detailsFramework:ParseColors(_value)
return _object:SetBackdropColor(_value1, _value2, _value3, _value4)
end
--frame width
local smember_width = function(_object, _value)
return _object.frame:SetWidth(_value)
end
--frame height
local smember_height = function(_object, _value)
return _object.frame:SetHeight(_value)
end
--locked
local smember_locked = function(_object, _value)
if (_value) then
_object.frame:SetMovable(false)
return rawset(_object, "is_locked", true)
else
_object.frame:SetMovable(true)
rawset(_object, "is_locked", false)
return
end
end
--backdrop
local smember_backdrop = function(_object, _value)
return _object.frame:SetBackdrop(_value)
end
--close with right button
local smember_right_close = function(_object, _value)
return rawset(_object, "rightButtonClose", _value)
end
PanelMetaFunctions.SetMembers = PanelMetaFunctions.SetMembers or {}
PanelMetaFunctions.SetMembers["tooltip"] = smember_tooltip
PanelMetaFunctions.SetMembers["show"] = smember_show
PanelMetaFunctions.SetMembers["hide"] = smember_hide
PanelMetaFunctions.SetMembers["color"] = smember_color
PanelMetaFunctions.SetMembers["backdrop"] = smember_backdrop
PanelMetaFunctions.SetMembers["width"] = smember_width
PanelMetaFunctions.SetMembers["height"] = smember_height
PanelMetaFunctions.SetMembers["locked"] = smember_locked
PanelMetaFunctions.SetMembers["close_with_right"] = smember_right_close
PanelMetaFunctions.__newindex = function(_table, _key, _value)
local func = PanelMetaFunctions.SetMembers [_key]
if (func) then
return func (_table, _value)
else
return rawset(_table, _key, _value)
end
end
------------------------------------------------------------------------------------------------------------
--methods
--right click to close
function PanelMetaFunctions:CreateRightClickLabel(textType, width, height, showCloseText)
local text
width = width or 20
height = height or 20
if (showCloseText) then
text = showCloseText
else
if (textType) then
textType = string.lower(textType)
if (textType == "short") then
text = "close window"
elseif (textType == "medium") then
text = "close window"
elseif (textType == "large") then
text = "close window"
end
else
text = "close window"
end
end
return detailsFramework:NewLabel(self, _, "$parentRightMouseToClose", nil, "|TInterface\\TUTORIALFRAME\\UI-TUTORIAL-FRAME:" .. width .. ":" .. height .. ":0:1:512:512:8:70:328:409|t " .. text)
end
--show & hide
function PanelMetaFunctions:Show()
self.frame:Show()
end
function PanelMetaFunctions:Hide()
self.frame:Hide()
end
-- setpoint
function PanelMetaFunctions:SetPoint(v1, v2, v3, v4, v5)
v1, v2, v3, v4, v5 = detailsFramework:CheckPoints (v1, v2, v3, v4, v5, self)
if (not v1) then
print("Invalid parameter for SetPoint")
return
end
return self.widget:SetPoint(v1, v2, v3, v4, v5)
end
-- sizes
function PanelMetaFunctions:SetSize(w, h)
if (w) then
self.frame:SetWidth(w)
end
if (h) then
self.frame:SetHeight(h)
end
end
-- clear
function PanelMetaFunctions:HideWidgets()
for widgetName, widgetSelf in pairs(self) do
if (type(widgetSelf) == "table" and widgetSelf.dframework) then
widgetSelf:Hide()
end
end
end
-- backdrop
function PanelMetaFunctions:SetBackdrop(background, edge, tilesize, edgesize, tile, left, right, top, bottom)
if (type(background) == "boolean" and not background) then
return self.frame:SetBackdrop(nil)
elseif (type(background) == "table") then
self.frame:SetBackdrop(background)
else
local currentBackdrop = self.frame:GetBackdrop() or {edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border", bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", tile=true, tileSize=16, edgeSize=16, insets={left=1, right=0, top=0, bottom=0}}
currentBackdrop.bgFile = background or currentBackdrop.bgFile
currentBackdrop.edgeFile = edgeFile or currentBackdrop.edgeFile
currentBackdrop.tileSize = tilesize or currentBackdrop.tileSize
currentBackdrop.edgeSize = edgesize or currentBackdrop.edgeSize
currentBackdrop.tile = tile or currentBackdrop.tile
currentBackdrop.insets.left = left or currentBackdrop.insets.left
currentBackdrop.insets.right = left or currentBackdrop.insets.right
currentBackdrop.insets.top = left or currentBackdrop.insets.top
currentBackdrop.insets.bottom = left or currentBackdrop.insets.bottom
self.frame:SetBackdrop(currentBackdrop)
end
end
-- backdropcolor
function PanelMetaFunctions:SetBackdropColor(color, arg2, arg3, arg4)
if (arg2) then
self.frame:SetBackdropColor(color, arg2, arg3, arg4 or 1)
else
local _value1, _value2, _value3, _value4 = detailsFramework:ParseColors(color)
self.frame:SetBackdropColor(_value1, _value2, _value3, _value4)
end
end
-- border color
function PanelMetaFunctions:SetBackdropBorderColor(color, arg2, arg3, arg4)
if (arg2) then
return self.frame:SetBackdropBorderColor(color, arg2, arg3, arg4)
end
local _value1, _value2, _value3, _value4 = detailsFramework:ParseColors(color)
self.frame:SetBackdropBorderColor(_value1, _value2, _value3, _value4)
end
-- tooltip
function PanelMetaFunctions:SetTooltip (tooltip)
if (tooltip) then
return rawset(self, "have_tooltip", tooltip)
else
return rawset(self, "have_tooltip", nil)
end
end
function PanelMetaFunctions:GetTooltip()
return rawget(self, "have_tooltip")
end
-- frame levels
function PanelMetaFunctions:GetFrameLevel()
return self.widget:GetFrameLevel()
end
function PanelMetaFunctions:SetFrameLevel(level, frame)
if (not frame) then
return self.widget:SetFrameLevel(level)
else
local framelevel = frame:GetFrameLevel (frame) + level
return self.widget:SetFrameLevel(framelevel)
end
end
-- frame stratas
function PanelMetaFunctions:SetFrameStrata()
return self.widget:GetFrameStrata()
end
function PanelMetaFunctions:SetFrameStrata(strata)
if (type(strata) == "table") then
self.widget:SetFrameStrata(strata:GetFrameStrata())
else
self.widget:SetFrameStrata(strata)
end
end
------------------------------------------------------------------------------------------------------------
--scripts
local OnEnter = function(frame)
local capsule = frame.MyObject
local kill = capsule:RunHooksForWidget("OnEnter", frame, capsule)
if (kill) then
return
end
if (frame.MyObject.have_tooltip) then
GameCooltip2:Reset()
GameCooltip2:SetType ("tooltip")
GameCooltip2:SetColor ("main", "transparent")
GameCooltip2:AddLine(frame.MyObject.have_tooltip)
GameCooltip2:SetOwner(frame)
GameCooltip2:ShowCooltip()
end
end
local OnLeave = function(frame)
local capsule = frame.MyObject
local kill = capsule:RunHooksForWidget("OnLeave", frame, capsule)
if (kill) then
return
end
if (frame.MyObject.have_tooltip) then
GameCooltip2:ShowMe(false)
end
end
local OnHide = function(frame)
local capsule = frame.MyObject
local kill = capsule:RunHooksForWidget("OnHide", frame, capsule)
if (kill) then
return
end
end
local OnShow = function(frame)
local capsule = frame.MyObject
local kill = capsule:RunHooksForWidget("OnShow", frame, capsule)
if (kill) then
return
end
end
local OnMouseDown = function(frame, button)
local capsule = frame.MyObject
local kill = capsule:RunHooksForWidget("OnMouseDown", frame, button, capsule)
if (kill) then
return
end
if (frame.MyObject.container == UIParent) then
if (not frame.isLocked and frame:IsMovable()) then
frame.isMoving = true
frame:StartMoving()
end
elseif (not frame.MyObject.container.isLocked and frame.MyObject.container:IsMovable()) then
if (not frame.isLocked and frame:IsMovable()) then
frame.MyObject.container.isMoving = true
frame.MyObject.container:StartMoving()
end
end
end
local OnMouseUp = function(frame, button)
local capsule = frame.MyObject
local kill = capsule:RunHooksForWidget("OnMouseUp", frame, button, capsule)
if (kill) then
return
end
if (button == "RightButton" and frame.MyObject.rightButtonClose) then
frame.MyObject:Hide()
end
if (frame.MyObject.container == UIParent) then
if (frame.isMoving) then
frame:StopMovingOrSizing()
frame.isMoving = false
end
else
if (frame.MyObject.container.isMoving) then
frame.MyObject.container:StopMovingOrSizing()
frame.MyObject.container.isMoving = false
end
end
end
------------------------------------------------------------------------------------------------------------
--object constructor
function detailsFramework:CreatePanel (parent, w, h, backdrop, backdropcolor, bordercolor, member, name)
return detailsFramework:NewPanel(parent, parent, name, member, w, h, backdrop, backdropcolor, bordercolor)
end
function detailsFramework:NewPanel(parent, container, name, member, w, h, backdrop, backdropcolor, bordercolor)
if (not name) then
name = "DetailsFrameworkPanelNumber" .. detailsFramework.PanelCounter
detailsFramework.PanelCounter = detailsFramework.PanelCounter + 1
elseif (not parent) then
parent = UIParent
end
if (not container) then
container = parent
end
if (name:find("$parent")) then
name = name:gsub("$parent", parent:GetName())
end
local PanelObject = {type = "panel", dframework = true}
if (member) then
parent [member] = PanelObject
end
if (parent.dframework) then
parent = parent.widget
end
if (container.dframework) then
container = container.widget
end
--default members:
--misc
PanelObject.is_locked = true
PanelObject.container = container
PanelObject.rightButtonClose = false
PanelObject.frame = CreateFrame("frame", name, parent,"BackdropTemplate")
PanelObject.frame:SetSize(100, 100)
PanelObject.frame.Gradient = {
["OnEnter"] = {0.3, 0.3, 0.3, 0.5},
["OnLeave"] = {0.9, 0.7, 0.7, 1}
}
PanelObject.frame:SetBackdrop({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", edgeSize = 10, tileSize = 64, tile = true})
PanelObject.widget = PanelObject.frame
PanelObject.frame.MyObject = PanelObject
if (not APIFrameFunctions) then
APIFrameFunctions = {}
local idx = getmetatable(PanelObject.frame).__index
for funcName, funcAddress in pairs(idx) do
if (not PanelMetaFunctions [funcName]) then
PanelMetaFunctions [funcName] = function(object, ...)
local x = loadstring ( "return _G['"..object.frame:GetName().."']:"..funcName.."(...)")
return x (...)
end
end
end
end
PanelObject.frame:SetWidth(w or 100)
PanelObject.frame:SetHeight(h or 100)
PanelObject.HookList = {
OnEnter = {},
OnLeave = {},
OnHide = {},
OnShow = {},
OnMouseDown = {},
OnMouseUp = {},
}
--hooks
PanelObject.frame:SetScript("OnEnter", OnEnter)
PanelObject.frame:SetScript("OnLeave", OnLeave)
PanelObject.frame:SetScript("OnHide", OnHide)
PanelObject.frame:SetScript("OnShow", OnShow)
PanelObject.frame:SetScript("OnMouseDown", OnMouseDown)
PanelObject.frame:SetScript("OnMouseUp", OnMouseUp)
setmetatable(PanelObject, PanelMetaFunctions)
if (backdrop) then
PanelObject:SetBackdrop(backdrop)
elseif (type(backdrop) == "boolean") then
PanelObject.frame:SetBackdrop(nil)
end
if (backdropcolor) then
PanelObject:SetBackdropColor(backdropcolor)
end
if (bordercolor) then
PanelObject:SetBackdropBorderColor(bordercolor)
end
return PanelObject
end
------------fill panel
local button_on_enter = function(self)
self.MyObject._icon:SetBlendMode("ADD")
if (self.MyObject.onenter_func) then
pcall(self.MyObject.onenter_func, self.MyObject)
end
end
local button_on_leave = function(self)
self.MyObject._icon:SetBlendMode("BLEND")
if (self.MyObject.onleave_func) then
pcall(self.MyObject.onleave_func, self.MyObject)
end
end
local add_row = function(self, t, need_update)
local index = #self.rows+1
local thisrow = detailsFramework:NewPanel(self, self, "$parentHeader_" .. self._name .. index, nil, 1, 20)
thisrow.backdrop = {bgFile = [[Interface\Tooltips\UI-Tooltip-Background]]}
thisrow.color = {.3, .3, .3, .9}
thisrow.type = t.type
thisrow.func = t.func
thisrow.name = t.name
thisrow.notext = t.notext
thisrow.icon = t.icon
thisrow.iconalign = t.iconalign
thisrow.hidden = t.hidden or false
thisrow.onenter = t.onenter
thisrow.onleave = t.onleave
local text = detailsFramework:NewLabel(thisrow, nil, self._name .. "$parentLabel" .. index, "text")
text:SetPoint("left", thisrow, "left", 2, 0)
text:SetText(t.name)
table.insert(self._raw_rows, t)
table.insert(self.rows, thisrow)
if (need_update) then
self:AlignRows()
end
end
local align_rows = function(self)
local rows_shown = 0
for index, row in ipairs(self.rows) do
if (not row.hidden) then
rows_shown = rows_shown + 1
end
end
local cur_width = 1
local row_width = self._width / max(rows_shown, 0.0001)
local sindex = 1
wipe (self._anchors)
for index, row in ipairs(self.rows) do
if (not row.hidden) then
if (self._autowidth) then
if (self._raw_rows [index].width) then
row.width = self._raw_rows [index].width
else
row.width = row_width
end
row:SetPoint("topleft", self, "topleft", cur_width, -1)
table.insert(self._anchors, cur_width)
cur_width = cur_width + row_width + 1
else
row:SetPoint("topleft", self, "topleft", cur_width, -1)
row.width = self._raw_rows [index].width
table.insert(self._anchors, cur_width)
cur_width = cur_width + self._raw_rows [index].width + 1
end
row:Show()
local rowType = row.type
if (rowType == "text") then
for i = 1, #self.scrollframe.lines do
local line = self.scrollframe.lines [i]
local text = table.remove(line.text_available)
if (not text) then
self:CreateRowText (line)
text = table.remove(line.text_available)
end
table.insert(line.text_inuse, text)
text:SetPoint("left", line, "left", self._anchors [#self._anchors], 0)
text:SetWidth(row.width)
detailsFramework:SetFontSize(text, row.textsize or 10)
text:SetJustifyH(row.textalign or "left")
end
elseif (rowType == "entry") then
for i = 1, #self.scrollframe.lines do
local line = self.scrollframe.lines [i]
local entry = table.remove(line.entry_available)
if (not entry) then
self:CreateRowEntry (line)
entry = table.remove(line.entry_available)
end
table.insert(line.entry_inuse, entry)
entry:SetPoint("left", line, "left", self._anchors [#self._anchors], 0)
if (sindex == rows_shown) then
entry:SetWidth(row.width - 25)
else
entry:SetWidth(row.width)
end
entry.func = row.func
entry.onenter_func = nil
entry.onleave_func = nil
if (row.onenter) then
entry.onenter_func = row.onenter
end
if (row.onleave) then
entry.onleave_func = row.onleave
end
end
elseif (rowType == "checkbox") then
for i = 1, #self.scrollframe.lines do
local line = self.scrollframe.lines [i]
local checkbox = table.remove(line.checkbox_available)
if (not checkbox) then
self:CreateCheckbox (line)
checkbox = table.remove(line.checkbox_available)
end
table.insert(line.checkbox_inuse, checkbox)
checkbox:SetPoint("left", line, "left", self._anchors [#self._anchors] + ((row.width - 20) / 2), 0)
if (sindex == rows_shown) then
checkbox:SetWidth(20)
--checkbox:SetWidth(row.width - 25)
else
checkbox:SetWidth(20)
end
checkbox.onenter_func = nil
checkbox.onleave_func = nil
end
elseif (rowType == "button") then
for i = 1, #self.scrollframe.lines do
local line = self.scrollframe.lines [i]
local button = table.remove(line.button_available)
if (not button) then
self:CreateRowButton (line)
button = table.remove(line.button_available)
end
table.insert(line.button_inuse, button)
button:SetPoint("left", line, "left", self._anchors [#self._anchors], 0)
if (sindex == rows_shown) then
button:SetWidth(row.width - 25)
else
button:SetWidth(row.width)
end
if (row.icon) then
button._icon.texture = row.icon
button._icon:ClearAllPoints()
if (row.iconalign) then
if (row.iconalign == "center") then
button._icon:SetPoint("center", button, "center")
elseif (row.iconalign == "right") then
button._icon:SetPoint("right", button, "right")
end
else
button._icon:SetPoint("left", button, "left")
end
end
if (row.name and not row.notext) then
button._text:SetPoint("left", button._icon, "right", 2, 0)
button._text.text = row.name
end
button.onenter_func = nil
button.onleave_func = nil
if (row.onenter) then
button.onenter_func = row.onenter
end
if (row.onleave) then
button.onleave_func = row.onleave
end
end
elseif (rowType == "icon") then
for i = 1, #self.scrollframe.lines do
local line = self.scrollframe.lines [i]
local icon = table.remove(line.icon_available)
if (not icon) then
self:CreateRowIcon (line)
icon = table.remove(line.icon_available)
end
table.insert(line.icon_inuse, icon)
icon:SetPoint("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0)
icon.func = row.func
end
elseif (rowType == "texture") then
for i = 1, #self.scrollframe.lines do
local line = self.scrollframe.lines [i]
local texture = table.remove(line.texture_available)
if (not texture) then
self:CreateRowTexture (line)
texture = table.remove(line.texture_available)
end
table.insert(line.texture_inuse, texture)
texture:SetPoint("left", line, "left", self._anchors [#self._anchors] + ( ((row.width or 22) - 22) / 2), 0)
end
end
sindex = sindex + 1
else
row:Hide()
end
end
if (#self.rows > 0) then
if (self._autowidth) then
self.rows [#self.rows]:SetWidth(row_width - rows_shown + 1)
else
self.rows [#self.rows]:SetWidth(self._raw_rows [rows_shown].width - rows_shown + 1)
end
end
self.showing_amt = rows_shown
end
local update_rows = function(self, updated_rows)
for i = 1, #updated_rows do
local t = updated_rows [i]
local raw = self._raw_rows [i]
if (not raw) then
self:AddRow (t)
else
raw.name = t.name
raw.hidden = t.hidden or false
raw.textsize = t.textsize
raw.textalign = t.textalign
local widget = self.rows [i]
widget.name = t.name
widget.textsize = t.textsize
widget.textalign = t.textalign
widget.hidden = t.hidden or false