-
Notifications
You must be signed in to change notification settings - Fork 1
/
LibDropdown-1.0.lua
executable file
·1203 lines (1085 loc) · 30.2 KB
/
LibDropdown-1.0.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- This library has been modified and so I've changed the major name to use an MC suffix. Changes are:
-- * Added support for a color parameter on items to tint the text
-- * Added an optional cleanup function to menus so their owner can be notified if they're released
-- * Added support for items with an icon
local MAJOR = "LibDropdownMC-1.0"
local MINOR = 2
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then return end
local assert = assert
local ipairs = ipairs
local math = math
local max = max
local min = min
local next = next
local pairs = pairs
local select = select
local table = table
local setmetatable = setmetatable
local tinsert = tinsert
local tostring = tostring
local tremove = tremove
local type = type
local wipe = wipe
local CreateFrame = CreateFrame
local PlaySound = PlaySound
local ShowUIPanel = ShowUIPanel
local GetMouseFocus = GetMouseFocus
local UISpecialFrames = UISpecialFrames
local ChatFrame1 = ChatFrame1
local ColorPickerFrame = ColorPickerFrame
local GameTooltip = GameTooltip
local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor
local HIGHLIGHT_FONT_COLOR = HIGHLIGHT_FONT_COLOR
local NORMAL_FONT_COLOR = NORMAL_FONT_COLOR
local framePool = lib.framePool or {}
lib.framePool = framePool
local buttonPool = lib.buttonPool or {}
lib.buttonPool = buttonPool
local inputPool = lib.inputPool or {}
lib.inputPool = inputPool
local frameHideQueue = lib.frameHideQueue or {}
lib.frameHideQueue = frameHideQueue
local sliderPool = lib.sliderPool or {}
lib.sliderPool = sliderPool
local AddButton, Refresh, GetRoot, SetChecked, HideRecursive, ShowGroup, HideGroup, SetGroup, NewDropdownFrame, NewDropdownButton, ReleaseFrame, AcquireButton, ReleaseButton, AcquireFrame
local UIParent = _G.UIParent
local openMenu
local noop = lib.noop or function() end
lib.noop = noop
local new, newHash, newSet, del
if not lib.new then
local list = setmetatable({}, {__mode='k'})
function new(...)
local t = next(list)
if t then
list[t] = nil
for i = 1, select('#', ...) do
t[i] = select(i, ...)
end
return t
else
return {...}
end
end
function del(t)
setmetatable(t, nil)
for k in pairs(t) do
t[k] = nil
end
t[''] = true
t[''] = nil
list[t] = true
return nil
end
lib.new, lib.del = new, del
end
-- Make the frame match the tooltip
local function InitializeFrame(frame)
local backdrop = GameTooltip:GetBackdrop()
frame:SetBackdrop(backdrop)
if backdrop then
frame:SetBackdropColor(GameTooltip:GetBackdropColor())
frame:SetBackdropBorderColor(GameTooltip:GetBackdropBorderColor())
end
frame:SetScale(GameTooltip:GetScale())
end
local editBoxCount = 1
local function AcquireInput()
local frame = tremove(inputPool)
if frame then
frame.released = false
return frame
end
frame = CreateFrame("EditBox", "LibDropDownEditBox"..editBoxCount, UIParent, "InputBoxTemplate")
frame:SetAutoFocus(false)
editBoxCount = editBoxCount + 1
frame:SetScript("OnEscapePressed", function(self)
self:ClearFocus()
self:GetParent():GetRoot():Refresh()
end)
frame:SetScript("OnEnterPressed", function(self)
if self.ValueChanged then
self:ValueChanged(self:GetText())
end
end)
frame.refresh = noop
return frame
end
local function AcquireSlider()
local frame = tremove(sliderPool)
if frame then
frame.released = false
return frame
end
local frame = CreateFrame("Slider", nil, UIParent)
frame:SetWidth(10)
frame:SetHeight(150)
frame:SetOrientation("VERTICAL")
frame:SetBackdrop({
bgFile = [[Interface\Buttons\UI-SliderBar-Background]],
edgeFile = [[Interface\Buttons\UI-SliderBar-Border]],
tile = true,
tileSize = 8,
edgeSize = 8,
insets = {left = 3, right = 3, top = 6, bottom = 6}
})
frame:SetThumbTexture([[Interface\Buttons\UI-SliderBar-Button-Vertical]])
frame:EnableMouseWheel()
frame:Show()
local text = frame:CreateFontString(nil, nil, "GameFontNormalSmall")
text:SetPoint("TOP", frame, "BOTTOM")
text:SetTextColor(1, 1, 1, 1)
frame.text = text
frame:SetScript("OnMouseWheel", function(self, direction, ...)
if not direction then return end -- huh?
local mn, mx = self:GetMinMaxValues()
local nv = min(mx, max(mn, self:GetValue() + ((self.step or 1) * direction * -1)))
self:SetValue(nv)
end)
frame:SetScript("OnValueChanged", function(self)
local mn, mx = self:GetMinMaxValues()
local nv = min(mx, max(mn, self:GetValue()))
if nv ~= self:GetValue() then
self:SetValue(nv)
return
end
local n, x = self:GetMinMaxValues()
local ev = x - nv
frame.text:SetText(ev)
if self.ValueChanged then
self:ValueChanged(self:GetValue())
end
end)
frame.refresh = noop
return frame
end
local function ReleaseSlider(slider)
if slider.released then return end
slider.released = true
slider:Hide()
slider:SetParent(UIParent)
tinsert(sliderPool, slider)
return nil
end
local function ReleaseInput(input)
if input.released then return end
input.released = true
input:Hide()
input:SetParent(UIParent)
tinsert(inputPool, input)
return nil
end
local function MouseOver(frame)
local f = GetMouseFocus()
while f and f ~= UIParent do
if f == frame then return true end
f = f:GetParent()
end
return false
end
-- Frame methods
function AddButton(self, b)
b:ClearAllPoints()
b:SetParent(self)
b:Show()
if #self.buttons == 0 then
b:SetPoint("TOPLEFT", self, "TOPLEFT", 0, -4)
b:SetPoint("TOPRIGHT", self, "TOPRIGHT", 0, -4)
else
b:SetPoint("TOPLEFT", self.buttons[#self.buttons], "BOTTOMLEFT")
b:SetPoint("TOPRIGHT", self.buttons[#self.buttons], "BOTTOMRIGHT")
end
tinsert(self.buttons, b)
self:SetHeight(#self.buttons * b:GetHeight() + 8)
end
function Refresh(self)
if not self:IsVisible() then return end
local maxWidth = 1
for i = 1, #self.buttons do
self.buttons[i]:refresh()
maxWidth = math.max(maxWidth, self.buttons[i].text:GetStringWidth() + 60)
end
self:SetWidth(maxWidth)
end
function GetRoot(self)
local parent = self:GetParent()
if parent and parent.GetRoot then
return parent:GetRoot()
else
return self
end
end
-- Button methods
function ShowGroup(self)
if not self.enabled then return end
if not self.groupFrame then
self.groupFrame = self:AcquireFrame()
end
if not self.handled then
self.handler(lib, self.group, self.groupFrame)
self.handled = true
end
self.groupFrame:SetPoint("TOPLEFT", self, "TOPRIGHT", 0, 4)
self.groupFrame:Show()
self.groupFrame:Refresh()
self:LockHighlight()
self:enter()
if self.groupFrame.Showing then
self.groupFrame:Showing()
end
end
function HideGroup(self)
if not self then return end
if MouseOver(self) then return end
if self.groupFrame then
self.groupFrame:Hide()
end
self:UnlockHighlight()
self:leave()
if self.groupFrame.Hiding then
self.groupFrame:Hiding()
end
end
function SetChecked(self, val)
self.checked = val
if val then
self.check:Show()
self.check:SetDesaturated(false)
elseif val == false or not self.tristate then
self.check:Hide()
elseif val == nil then
self.check:Show()
self.check:SetDesaturated(true)
end
end
function HideRecursive(self)
HideGroup(self:GetParent())
end
function SetGroup(self, t, handler)
if t then
self.expand:Show()
self:SetScript("OnEnter", ShowGroup)
self:SetScript("OnLeave", HideGroup)
self.group = t
self.handler = handler
else
self.expand:Hide()
self:SetScript("OnEnter", nil)
self:SetScript("OnLeave", nil)
self.group = nil
self.handler = nil
end
self.clickable = t == nil
end
-- Pool methods
local frameCount = 0
function NewDropdownFrame()
local frame = CreateFrame("Frame", "LibDropdownFrame" .. frameCount, UIParent)
frameCount = frameCount + 1
frame:SetPoint("CENTER", UIParent, "CENTER")
frame:SetWidth(10)
frame:SetHeight(24)
frame:EnableMouse(true)
frame.AddButton = AddButton
frame.Refresh = Refresh
frame.GetRoot = GetRoot
frame.isDropdownFrame = true
frame.Release = ReleaseFrame
frame.AcquireButton = AcquireButton
-- make it close on escape
tinsert(UISpecialFrames, frame:GetName())
return frame
end
do
local function enterButton(self)
GameTooltip_SetDefaultAnchor(GameTooltip, self)
GameTooltip:ClearLines()
GameTooltip:AddLine(self.text:GetText())
if self.desc then
GameTooltip:AddLine("|cffffffff" .. self.desc .. "|r")
end
GameTooltip:Show()
end
local function leaveButton(self)
GameTooltip:Hide()
local p = self:GetParent()
if p then
local f = p:GetScript("OnLeave")
if f then
f(p)
end
end
end
local function pushText(self)
if not self.clickable then return end
self.text:SetPoint("TOP", self, "TOP", 0, -2)
self.text:SetPoint("LEFT", self.check, "RIGHT", 6, 0)
end
local function unpushText(self)
if not self.clickable then return end
self.text:SetPoint("TOP", self, "TOP", 0, 0)
self.text:SetPoint("LEFT", self.check, "RIGHT", 4, 0)
end
local function click(self)
if self.OnClick and self.clickable then
self.OnClick(self)
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
self:GetParent():GetRoot():Refresh()
end
end
local function settext(self, t)
self.text:SetText(t)
end
local function disable(self)
self.enabled = false
self:SetScript("OnMouseDown", nil)
self:SetScript("OnMouseUp", nil)
self.text:SetTextColor(0.5, 0.5, 0.5, 1)
self.check:SetDesaturated(true)
self.expand:SetDesaturated(true)
self:oldDisable()
end
local function enable(self)
self.enabled = true
self:SetScript("OnMouseDown", pushText)
self:SetScript("OnMouseUp", unpushText)
self.text:SetTextColor(1, 1, 1, 1)
-- self.text:SetTextColor(self:GetTextColor()) -- Removed in 3.0
self.check:SetDesaturated(false)
self.expand:SetDesaturated(false)
self:oldEnable()
end
local function revert()
--ColorPickerFrame.previousValues.frame
end
local function setColor()
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = ColorPickerFrame.opacity or 1
local f = ColorPickerFrame.previousValues.frame
f:GetNormalTexture():SetVertexColor(r, g, b, a)
if f:GetParent().OnClick then
f:GetParent():OnClick(r, g, b, a)
end
end
local function revert()
local p = ColorPickerFrame.previousValues
ColorPickerFrame:SetColorRGB(p.r, p.g, p.b)
ColorPickerFrame.opacity = p.opacity
setColor()
end
local function openColorPicker(self)
local p = self:GetParent()
p.r, p.g, p.b, p.a = self:GetNormalTexture():GetVertexColor()
ColorPickerFrame.hasOpacity = p.hasOpacity
ColorPickerFrame.opacityFunc = p.opacityFunc
ColorPickerFrame.opacity = p.a
ColorPickerFrame:SetColorRGB(p.r, p.g, p.b)
ColorPickerFrame.previousValues = ColorPickerFrame.previousValues or {}
ColorPickerFrame.previousValues.r = p.r
ColorPickerFrame.previousValues.g = p.g
ColorPickerFrame.previousValues.b = p.b
ColorPickerFrame.previousValues.opacity = p.a
ColorPickerFrame.previousValues.frame = self
ColorPickerFrame.cancelFunc = revert
ColorPickerFrame.func = setColor
ShowUIPanel(ColorPickerFrame)
end
local function highlightSwatch(self)
self.tex:SetTexture(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
end
local function unhighlightSwatch(self)
self.tex:SetTexture(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
end
local function makeTitle(self, t)
-- self.text:SetJustifyH("CENTER")
self.text:ClearAllPoints()
self.text:SetPoint("LEFT", self, "LEFT", 16, 0)
self.text:SetPoint("RIGHT", self, "RIGHT", -16, 0)
self.text:SetTextColor(1, 0.8, 0, 1)
self.clickable = false
if t then self.text:SetText(t) end
end
local function makeButton(self, t)
local text, frame, check, expand = self.text, self, self.check, self.expand
text:ClearAllPoints()
text:SetPoint("TOP", frame, "TOP")
text:SetPoint("LEFT", check, "RIGHT", 4, 0)
text:SetPoint("BOTTOM", frame, "BOTTOM")
text:SetPoint("RIGHT", expand, "LEFT", -4, 0)
text:SetJustifyH("LEFT")
self.text:SetTextColor(1, 1, 1, 1)
self.clickable = true
if t then text:SetText(t) end
end
function NewDropdownButton(f)
local frame = f or CreateFrame("Button", nil, UIParent)
frame:SetHighlightTexture([[Interface\QuestFrame\UI-QuestTitleHighlight]])
frame:GetHighlightTexture():SetBlendMode("ADD")
-- frame:SetDisabledTextColor(0.5, 0.5, 0.5, 1) -- Removed in 3.0
frame:SetPushedTextOffset(3,-3)
frame:SetHeight(18)
local check = frame.check or frame:CreateTexture()
check:SetTexture([[Interface\Buttons\UI-CheckBox-Check]])
check:SetWidth(18)
check:SetHeight(18)
check:SetPoint("LEFT", frame, "LEFT", 4, 0)
check:Hide()
frame.check = check
local expand = frame.expand or frame:CreateTexture()
expand:SetTexture([[Interface\ChatFrame\ChatFrameExpandArrow]])
expand:SetWidth(16)
expand:SetHeight(16)
expand:SetPoint("RIGHT", frame, "RIGHT", -4, 0)
expand:Hide()
frame.expand = expand
local text = frame.text or frame:CreateFontString(nil, nil, "GameFontHighlightSmall")
frame.text = text
frame.SetText = settext
frame.MakeButton = makeButton
frame.MakeTitle = makeTitle
frame:MakeButton("<not set>")
local swatch = frame.swatch or CreateFrame("Button", nil, frame)
swatch:SetWidth(18)
swatch:SetHeight(18)
swatch.tex = swatch.text or swatch:CreateTexture(nil, "BACKGROUND")
swatch.tex:SetPoint("CENTER", swatch, "CENTER")
swatch.tex:SetWidth(swatch:GetWidth()-2)
swatch.tex:SetHeight(swatch:GetHeight()-2)
-- swatch.tex:SetTexture([[Interface\ChatFrame\ChatFrameColorSwatch]])
swatch:SetNormalTexture([[Interface\ChatFrame\ChatFrameColorSwatch]])
swatch:SetPoint("RIGHT", frame, "RIGHT", -4, 0)
swatch:SetScript("OnClick", openColorPicker)
swatch:SetFrameLevel(frame:GetFrameLevel() + 100)
swatch:SetScript("OnEnter", highlightSwatch)
swatch:SetScript("OnLeave", unhighlightSwatch)
swatch:Hide()
frame.swatch = swatch
unhighlightSwatch(swatch)
frame:SetScript("OnEnter", enterButton)
frame:SetScript("OnLeave", leaveButton)
frame.enter, frame.leave = enterButton, leaveButton
frame:SetScript("OnMouseDown", pushText)
frame:SetScript("OnMouseUp", unpushText)
frame:SetScript("OnClick", click)
frame.SetGroup = SetGroup
frame.SetChecked = SetChecked
frame.AcquireFrame = AcquireFrame
frame.GetRoot = GetRoot
frame.oldDisable, frame.Disable = frame.Disable, disable
frame.oldEnable, frame.Enable = frame.Enable, enable
frame.Release = ReleaseButton
frame.clickable = true
frame.enabled = true
frame:Enable()
return frame
end
end
function ReleaseFrame(f)
if f.rootMenu then
openMenu = nil
end
if f.released then return end
if f.cleanup then
f.cleanup()
end
f.released = true
f.data = nil
f.dataname = nil
f.rootMenu = nil
f:Hide()
f:SetParent(UIParent)
f:ClearAllPoints()
tinsert(framePool, f)
for i = 1, #f.buttons do
local button = tremove(f.buttons)
button:Release()
end
return nil
end
function AcquireButton(p)
local b = NewDropdownButton(tremove(buttonPool))
b.released = false
b:EnableMouse(true)
b:Show()
p:AddButton(b)
return b
end
function ReleaseButton(b)
if b.released then return end
tinsert(buttonPool, b)
b.desc = nil
b.released = true
b.Enable = b.oldEnable
b.Disable = b.oldDisable
b.handled = false
b:SetParent(UIParent)
b:Hide()
if b.slider then
b.slider = ReleaseSlider(b.slider)
end
if b.input then
b.input = ReleaseInput(b.input)
end
b:ClearAllPoints()
b:MakeButton("(released)")
if b.groupFrame then
b.groupFrame.Showing = nil
b.groupFrame = b.groupFrame:Release()
end
end
local function frameReleaseOnHide(self)
self:SetScript("OnHide", nil)
self:Release()
end
function AcquireFrame(parent, toplevel)
local f = tremove(framePool) or NewDropdownFrame()
InitializeFrame(f) -- set the look of the frame
f.released = false
f.buttons = f.buttons or {}
f:SetParent(parent or UIParent)
if parent then
f:SetScript("OnLeave", HideRecursive)
else
f:SetScript("OnLeave", nil)
end
if toplevel then
f:SetScript("OnHide", frameReleaseOnHide)
else
f:SetScript("OnHide", nil)
end
f:ClearAllPoints()
f:Show()
return f
end
----------------------------------------------------------------------
----------------------------------------------------------------------
do
local Ace3 = {}
local grefresh
local info = {}
local options
local currentOptionData
local function setup(k, v, parent)
local b = parent:AcquireButton()
b.data = v
b.option = v
b.dataname = k
b.refresh = grefresh
-- Tint with a color (mundocani)
if v.color then
b.text:SetTextColor(v.color.r, v.color.g, v.color.b, v.color.a)
end
return b
end
local function setInfoOptions()
local option = options
for _, key in ipairs(info) do
if option.args and option.args[key] then
option = option.args[key]
else
return
end
end
info.option = option
info.type = option.type
end
local function initInfo(type)
info.options = options
info.appName = options.name
info.type = type
info.uiType = "dropdown"
info.uiName = "LibDropdown-1.0"
end
local function wipeInfo()
local type = info.type
wipe(info)
initInfo(type)
end
local function runHandler(button, handler, ...)
info.handler = handler
info.option = button.data
if not button.rootMenu then
tinsert(info, 1, button.dataname)
end
local v = button.data
if v and v[handler] then
local ht = type(v[handler])
if ht == "function" then
setInfoOptions()
local ret, r1, r2, r3 = v[handler](info, ...)
wipeInfo()
return ret, r1, r2, r3
elseif ht == "table" then
return v[handler]
elseif ht == "string" then
local t = runHandler(button, "handler", ...)
if type(t) == "table" then
setInfoOptions()
local ret, r1, r2, r3 = t[v[handler]](t, info, ...)
wipeInfo()
return ret, r1, r2, r3
end
end
elseif v and v[handler] == false then
return nil -- Is this right?
else
if button.GetParent then
local pp = button:GetParent() and button:GetParent():GetParent()
if not pp or not pp.data then
pp = button:GetParent()
end
if pp and pp.data then
return runHandler(pp, handler, ...)
end
end
end
wipeInfo()
return nil
end
function grefresh(self)
local isDisabled = false
self:SetText(self.data.name)
self.desc = self.data.desc
if type(self.data.disabled) == "function" then
if self.data.disabled() then
self:Disable()
isDisabled = true
else
self:Enable()
end
elseif type(self.data.disabled) == "boolean" then
if self.data.disabled then
self:Disable()
isDisabled = true
else
self:Enable()
end
end
if self.data.icon then
self.swatch:Show()
self.swatch.tex:Hide()
self.swatch:SetNormalTexture(self.data.icon)
else
self.swatch:Hide()
self.swatch.tex:Show()
self.swatch:SetNormalTexture([[Interface\ChatFrame\ChatFrameColorSwatch]])
end
return isDisabled
end
-- group
do
local function refresh(self)
grefresh(self)
if not self.groupFrame or self.groupFrame == self:GetParent() then return end
self.groupFrame:Refresh()
end
function Ace3.group(k, v, parent)
local b = setup(k, v, parent)
if v.inline then
-- TODO: Add heading
local b2 = parent:AcquireButton()
b:MakeTitle(k)
b2.refresh = noop
lib:OpenAce3Menu(v.args, parent)
else
b:SetGroup(v.args, lib.OpenAce3Menu)
end
b.refresh = refresh
end
end
-- execute
function Ace3.execute(k, v, parent)
local b = setup(k, v, parent)
b:SetText(v.name)
b.desc = v.desc
b.OnClick = function(self)
initInfo('execute')
runHandler(self, "func")
self:GetRoot():Refresh()
end
end
-- input
do
local function refresh(self)
grefresh(self)
self.input:SetText(runHandler(self, "get") or "")
end
local function inputValueChanged(self, val)
initInfo('input')
runHandler(self:GetParent():GetParent(), "set", val)
self:GetParent():GetRoot():Refresh()
end
function Ace3.input(k, v, parent)
local b = setup(k, v, parent)
b:SetGroup(v, lib.Ace3InputShow)
b.input = AcquireInput()
b.refresh = refresh
end
local function showInput(frame)
local data = frame.data
local input = frame:GetParent().input
input:SetParent(frame)
input:ClearAllPoints()
input:SetPoint("LEFT", frame, "LEFT", 10, 0)
frame:SetWidth(185)
input:SetWidth(170)
input:SetHeight(34)
frame:SetHeight(34)
input.ValueChanged = inputValueChanged
input:Show()
refresh(frame:GetParent())
end
function lib:Ace3InputShow(t, parent)
parent.data = t
parent.Showing = showInput
end
end
-- toggle
do
local function refresh(self)
local disabled = grefresh(self)
initInfo('toggle')
local actual = runHandler(self, "get")
if disabled then
self:SetChecked(false)
else
self:SetChecked(actual)
end
end
local function onClick(self)
initInfo('toggle')
if self.data.tristate then
local val = runHandler(self, "get")
local sv
if val == nil then sv = true
elseif val == true then sv = false
else sv = nil end
runHandler(self, "set", sv)
else
local val = not runHandler(self, "get")
runHandler(self, "set", val)
end
self:GetRoot():Refresh()
end
function Ace3.toggle(k, v, parent)
local b = setup(k, v, parent)
b.OnClick = onClick
b.tristate = v.tristate
b.refresh = refresh
end
end
-- header
do
local function refresh(self)
grefresh(self)
end
function Ace3.header(k, v, parent)
local b = setup(k, v, parent)
b:MakeTitle(k)
b:EnableMouse(false)
b.tristate = nil
b.refresh = refresh
end
end
-- color
do
local function refresh(self)
grefresh(self)
initInfo('color')
self.swatch:GetNormalTexture():SetVertexColor(runHandler(self, "get"))
end
function Ace3.color(k, v, parent)
local b = setup(k, v, parent)
b.swatch:Show()
b.clickable = false
b.refresh = refresh
b.OnClick = function(self, r, g, b, a)
runHandler(self, "set", r, g, b, a)
self:GetRoot():Refresh()
end
end
end
-- select
do
local function refresh(self)
grefresh(self)
if self.groupFrame then
self.groupFrame:Refresh()
end
end
function Ace3.select(k, v, parent)
local b = setup(k, v, parent)
b.parentTree = v
b:SetGroup(v.values, lib.Ace3MenuSelect)
b.refresh = refresh
end
local function buttonRefresh(self)
initInfo('select')
self:SetChecked( runHandler(self:GetParent():GetParent(), "get") == self.value )
end
function lib:Ace3MenuSelect(t, parent)
initInfo('select')
if type(t) == "string" or type(t) == "function" then
t = runHandler(parent, "values")
end
if type(t) == "table" then
for k, v in pairs(t) do
local b = parent:AcquireButton()
b:SetText(v)
b.value = k
b.OnClick = function(self)
initInfo('select')
runHandler(self:GetParent():GetParent(), "set", self.value)
self:GetParent():GetRoot():Refresh()
end
b.refresh = buttonRefresh
end
end
end
end
-- range
-- Some extra tricksery for mousewheel on the containing frame. A bit more user friendly.
do
local function refresh(self)
grefresh(self)
initInfo('range')
self.slider:SetValue(runHandler(self, "get") or self.slider:GetMinMaxValues())
initInfo('range')
self.slider.text:SetText(runHandler(self, "get"))
end
function Ace3.range(k, v, parent)
local b = setup(k, v, parent)
b:SetGroup(v, lib.Ace3SliderShow)
b.slider = AcquireSlider()
b.refresh = refresh
end
local function onWheel(f)
f:GetParent().slider:GetScript("OnMouseWheel")(f:GetParent().slider)
end
local function removeMousewheelFuncs(f)
tremove(f.buttons)
f:EnableMouseWheel(false)
f:SetScript("OnMouseWheel", nil)
f.Hiding = nil
end
local function sliderValueChanged(self, val)
initInfo('range')
runHandler(self:GetParent():GetParent(), "set", val)
self:GetParent():GetRoot():Refresh()
end
local function showSlider(frame)
local data = frame.data
local slider = frame:GetParent().slider
slider:SetParent(frame)
slider:ClearAllPoints()
slider:SetPoint("CENTER", frame, "CENTER")
slider:SetPoint("TOP", frame, "TOP", 0, -8)
slider:SetHeight(150)
slider.text:ClearAllPoints()
slider.text:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, 8)
slider.text:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 8)
slider.text:SetText(data.max)
frame:SetWidth(max(60, slider.text:GetStringWidth() + 10))
slider.step = data.bigStep
slider:SetMinMaxValues(data.min or 0, data.max or 100)
slider:SetValueStep(data.bigStep or data.step or 1)
slider.ValueChanged = sliderValueChanged
frame:EnableMouseWheel(true)
frame:SetScript("OnMouseWheel", onWheel)
frame.Hiding = removeMousewheelFuncs
frame:SetHeight(180)