-
Notifications
You must be signed in to change notification settings - Fork 7
/
slider.lua
1692 lines (1384 loc) · 52.4 KB
/
slider.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
--[=[
SLIDER:
When the value of the slider is changed, it'll call self.OnValueChanged if the value exists.
slider.OnValueChanged = function(self, FixedValue, value) end
All hooks set for "OnValueChanged" will also be called, example: slider:SetHook("OnValueChanged", function(self, FixedValue, value) end)
SWITCH:
When the value of the switch is changed, it'll call self.OnSwitch if the key exists.
switch.OnSwitch = function(self, FixedValue, value) end
All hooks set for "OnSwitch" will also be called, example: switch:SetHook("OnSwitch", function(self, FixedValue, value) end)
--]=]
---@type detailsframework
local DF = _G["DetailsFramework"]
if (not DF or not DetailsFrameworkCanLoad) then
return
end
local _
local APISliderFunctions = false
do
local metaPrototype = {
WidgetType = "slider",
dversion = DF.dversion
}
--check if there's a metaPrototype already existing
if (_G[DF.GlobalWidgetControlNames["slider"]]) then
--get the already existing metaPrototype
local oldMetaPrototype = _G[DF.GlobalWidgetControlNames["slider"]]
--check if is older
if ( (not oldMetaPrototype.dversion) or (oldMetaPrototype.dversion < DF.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[DF.GlobalWidgetControlNames["slider"]] = metaPrototype
end
end
local DFSliderMetaFunctions = _G[DF.GlobalWidgetControlNames["slider"]]
DF:Mixin(DFSliderMetaFunctions, DF.SetPointMixin)
DF:Mixin(DFSliderMetaFunctions, DF.FrameMixin)
DF:Mixin(DFSliderMetaFunctions, DF.TooltipHandlerMixin)
DF:Mixin(DFSliderMetaFunctions, DF.ScriptHookMixin)
------------------------------------------------------------------------------------------------------------
--metatables
DFSliderMetaFunctions.__call = function(object, value)
if (not value) then
if (object.isSwitch) then
if (type(value) == "boolean") then
object.slider:SetValue(1)
return
end
if (object.slider:GetValue() == 1) then
return false
else
return true
end
end
return object.slider:GetValue()
else
if (object.isSwitch) then
if (type(value) == "boolean") then
if (value) then
object.slider:SetValue(2)
else
object.slider:SetValue(1)
end
else
object.slider:SetValue(value)
end
return
end
return object.slider:SetValue(value)
end
end
------------------------------------------------------------------------------------------------------------
--members
--tooltip
local gmember_tooltip = function(object)
return object:GetTooltip()
end
--shown
local gmember_shown = function(object)
return object:IsShown()
end
--frame width
local gmember_width = function(object)
return object.slider:GetWidth()
end
--frame height
local gmember_height = function(object)
return object.slider:GetHeight()
end
--locked
local gmember_locked = function(object)
return rawget(object, "lockdown")
end
--fractional
local gmember_fractional = function(object)
return rawget(object, "useDecimals")
end
--value
local gmember_value = function(object)
return object()
end
DFSliderMetaFunctions.GetMembers = DFSliderMetaFunctions.GetMembers or {}
DFSliderMetaFunctions.GetMembers["tooltip"] = gmember_tooltip
DFSliderMetaFunctions.GetMembers["shown"] = gmember_shown
DFSliderMetaFunctions.GetMembers["width"] = gmember_width
DFSliderMetaFunctions.GetMembers["height"] = gmember_height
DFSliderMetaFunctions.GetMembers["locked"] = gmember_locked
DFSliderMetaFunctions.GetMembers["fractional"] = gmember_fractional
DFSliderMetaFunctions.GetMembers["value"] = gmember_value
DFSliderMetaFunctions.__index = function(object, key)
local func = DFSliderMetaFunctions.GetMembers[key]
if (func) then
return func(object, key)
end
local alreadyHaveKey = rawget(object, key)
if (alreadyHaveKey) then
return alreadyHaveKey
end
return DFSliderMetaFunctions[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
--frame width
local smember_width = function(object, value)
return object.slider:SetWidth(value)
end
--frame height
local smember_height = function(object, value)
return object.slider:SetHeight(value)
end
--locked
local smember_locked = function(object, value)
if (value) then
return object:Disable()
else
return object:Enable()
end
end
--backdrop
local smember_backdrop = function(object, value)
return object.slider:SetBackdrop(value)
end
--fractional
local smember_fractional = function(object, value)
return rawset(object, "useDecimals", value)
end
--value
local smember_value = function(object, value)
object(value)
end
DFSliderMetaFunctions.SetMembers = DFSliderMetaFunctions.SetMembers or {}
DFSliderMetaFunctions.SetMembers["tooltip"] = smember_tooltip
DFSliderMetaFunctions.SetMembers["show"] = smember_show
DFSliderMetaFunctions.SetMembers["hide"] = smember_hide
DFSliderMetaFunctions.SetMembers["backdrop"] = smember_backdrop
DFSliderMetaFunctions.SetMembers["width"] = smember_width
DFSliderMetaFunctions.SetMembers["height"] = smember_height
DFSliderMetaFunctions.SetMembers["locked"] = smember_locked
DFSliderMetaFunctions.SetMembers["fractional"] = smember_fractional
DFSliderMetaFunctions.SetMembers["value"] = smember_value
DFSliderMetaFunctions.__newindex = function(object, key, value)
local func = DFSliderMetaFunctions.SetMembers[key]
if (func) then
return func(object, value)
else
return rawset(object, key, value)
end
end
------------------------------------------------------------------------------------------------------------
--methods
--fixed value
function DFSliderMetaFunctions:SetFixedParameter(value)
rawset(self, "FixedValue", value)
end
function DFSliderMetaFunctions:GetFixedParameter()
return rawget(self, "FixedValue")
end
function DFSliderMetaFunctions:SetValueChangedFunction(newFunction)
self.OnValueChanged = newFunction
end
--set value
function DFSliderMetaFunctions:SetValue(value)
return self(value)
end
function DFSliderMetaFunctions:SetValueNoCallback(value)
self.NoCallback = true
self.slider:SetValue(value)
end
-- thumb size
function DFSliderMetaFunctions:SetThumbSize(width, height)
if (not width) then
width = self.thumb:GetWidth()
end
if (not height) then
height = self.thumb:GetHeight()
end
return self.thumb:SetSize(width, height)
end
--clear focus
function DFSliderMetaFunctions:ClearFocus()
local editbox = DFSliderMetaFunctions.editbox_typevalue
if editbox and self.typing_value then
editbox:ClearFocus()
editbox:Hide()
editbox:GetParent().MyObject.typing_value = false
editbox:GetParent().MyObject.value = self.typing_value_started
end
end
--enabled
function DFSliderMetaFunctions:IsEnabled()
return not rawget(self, "lockdown")
end
function DFSliderMetaFunctions:Enable()
self.slider:Enable()
if (not self.is_checkbox) then
if (not self.lock_texture) then
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self.amt, "center")
end
self.lock_texture:Hide()
end
self.slider.amt:Show()
self:SetAlpha(1)
if (self.is_checkbox) then
self.checked_texture:Show()
end
return rawset(self, "lockdown", false)
end
function DFSliderMetaFunctions:Disable()
self:ClearFocus()
self.slider:Disable()
self.slider.amt:Hide()
self:SetAlpha(.4)
if (not self.is_checkbox) then
if (not self.lock_texture) then
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self.amt, "center")
end
self.lock_texture:Show()
end
if (self.is_checkbox) then
self.checked_texture:Show()
end
return rawset(self, "lockdown", true)
end
------------------------------------------------------------------------------------------------------------
--scripts
local OnEnter = function(slider)
local object = slider.MyObject
if (rawget(object, "lockdown")) then
return
end
DetailsFrameworkSliderButtons1:ShowMe(slider, object.bAttachButtonsToLeft)
local kill = object:RunHooksForWidget("OnEnter", slider, object)
if (kill) then
return
end
slider.thumb:SetAlpha(1)
if (object.onenter_backdrop_border_color) then
slider:SetBackdropBorderColor(unpack(object.onenter_backdrop_border_color))
end
object:ShowTooltip()
end
local OnLeave = function(slider)
local object = slider.MyObject
if (rawget(object, "lockdown")) then
return
end
DetailsFrameworkSliderButtons1:PrepareToHide()
local kill = object:RunHooksForWidget("OnLeave", slider, object)
if (kill) then
return
end
slider.thumb:SetAlpha(.7)
if (object.onleave_backdrop_border_color) then
slider:SetBackdropBorderColor(unpack(object.onleave_backdrop_border_color))
end
object:HideTooltip()
end
--parent frame for the plus and minus buttons which shows when the slider is hovered over
local sliderButtonsParentFrame = DetailsFrameworkSliderButtons1 or CreateFrame("frame", "DetailsFrameworkSliderButtons1", UIParent, "BackdropTemplate")
sliderButtonsParentFrame:Hide()
sliderButtonsParentFrame:SetHeight(18) --width is set by setpoint
C_Timer.After(0, function()
if (not sliderButtonsParentFrame.__background) then
DetailsFramework:ApplyStandardBackdrop(sliderButtonsParentFrame) --ApplyStandardBackdrop loads after this file
end
sliderButtonsParentFrame:SetBackdropBorderColor(0, 0, 0, 0)
sliderButtonsParentFrame:SetBackdropColor(.05, .05, .05, .9)
end)
sliderButtonsParentFrame.isGoingToHide = false
local timeToHide = 0
local onUpdateTimeToHide = function(self, elapsed)
timeToHide = timeToHide + elapsed
if (timeToHide > 0.3) then
sliderButtonsParentFrame:Hide()
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
end
end
function sliderButtonsParentFrame:ShowMe(sliderFrame, bAnchorToLeft)
sliderButtonsParentFrame.bAnchorToLeft = bAnchorToLeft
sliderButtonsParentFrame:SetParent(sliderFrame)
sliderButtonsParentFrame:ClearAllPoints()
sliderButtonsParentFrame.buttonMinor:ClearAllPoints()
sliderButtonsParentFrame.buttonPlus:ClearAllPoints()
sliderButtonsParentFrame:SetWidth(35)
if (sliderButtonsParentFrame.bAnchorToLeft) then
sliderButtonsParentFrame:SetPoint("topright", sliderFrame, "topleft", 0, 0)
sliderButtonsParentFrame:SetPoint("bottomright", sliderFrame, "bottomleft", 0, 0)
sliderButtonsParentFrame.buttonPlus:SetPoint("right", sliderButtonsParentFrame, "right", -2, 0)
sliderButtonsParentFrame.buttonMinor:SetPoint("right", sliderButtonsParentFrame.buttonPlus, "left", 0, 0)
else
sliderButtonsParentFrame:SetPoint("topleft", sliderFrame, "topright", 2, 0)
sliderButtonsParentFrame:SetPoint("bottomleft", sliderFrame, "bottomright", 2, 0)
sliderButtonsParentFrame.buttonMinor:SetPoint("left", sliderButtonsParentFrame, "left", 2, 0)
sliderButtonsParentFrame.buttonPlus:SetPoint("left", sliderButtonsParentFrame.buttonMinor, "right", 0, 0)
end
sliderButtonsParentFrame:SetFrameStrata("FULLSCREEN")
sliderButtonsParentFrame:SetFrameLevel(sliderFrame:GetFrameLevel() + 1000)
sliderButtonsParentFrame:Show()
if (sliderButtonsParentFrame.isGoingToHide) then
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
end
sliderButtonsParentFrame.host = sliderFrame.MyObject
end
function sliderButtonsParentFrame:PrepareToHide()
sliderButtonsParentFrame.isGoingToHide = true
timeToHide = 0
sliderButtonsParentFrame:SetScript("OnUpdate", onUpdateTimeToHide)
end
local buttonPlus = DetailsFrameworkSliderButtonsPlusButton or CreateFrame("button", "DetailsFrameworkSliderButtonsPlusButton", sliderButtonsParentFrame, "BackdropTemplate")
local buttonMinor = DetailsFrameworkSliderButtonsMinorButton or CreateFrame("button", "DetailsFrameworkSliderButtonsMinorButton", sliderButtonsParentFrame, "BackdropTemplate")
buttonPlus:SetFrameStrata(sliderButtonsParentFrame:GetFrameStrata())
buttonMinor:SetFrameStrata(sliderButtonsParentFrame:GetFrameStrata())
sliderButtonsParentFrame.buttonPlus = buttonPlus
sliderButtonsParentFrame.buttonMinor = buttonMinor
buttonPlus:SetScript("OnEnter", function(self)
if (sliderButtonsParentFrame.isGoingToHide) then
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
end
end)
buttonMinor:SetScript("OnEnter", function(self)
if (sliderButtonsParentFrame.isGoingToHide) then
sliderButtonsParentFrame:SetScript("OnUpdate", nil)
sliderButtonsParentFrame.isGoingToHide = false
end
end)
buttonPlus:SetScript("OnLeave", function(self)
sliderButtonsParentFrame:PrepareToHide()
end)
buttonMinor:SetScript("OnLeave", function(self)
sliderButtonsParentFrame:PrepareToHide()
end)
buttonPlus:SetNormalTexture([[Interface\Buttons\UI-PlusButton-Up]])
buttonMinor:SetNormalTexture([[Interface\Buttons\UI-MinusButton-Up]])
buttonPlus:SetPushedTexture([[Interface\Buttons\UI-PlusButton-Down]])
buttonMinor:SetPushedTexture([[Interface\Buttons\UI-MinusButton-Down]])
buttonPlus:SetDisabledTexture([[Interface\Buttons\UI-PlusButton-Disabled]])
buttonMinor:SetDisabledTexture([[Interface\Buttons\UI-MinusButton-Disabled]])
buttonPlus:SetHighlightTexture([[Interface\Buttons\UI-PlusButton-Hilight]])
buttonMinor:SetHighlightTexture([[Interface\Buttons\UI-PlusButton-Hilight]])
C_Timer.After(0, function()
DF:SetButtonTexture(buttonPlus, "AlliedRace-UnlockingFrame-ZoomIn")
DF:SetButtonTexture(buttonMinor, "AlliedRace-UnlockingFrame-ZoomOut")
end)
buttonMinor:ClearAllPoints()
buttonPlus:ClearAllPoints()
buttonMinor:SetPoint("bottomright", sliderButtonsParentFrame, "bottomright", 13, -13)
buttonPlus:SetPoint("left", buttonMinor, "right", -2, 0)
buttonPlus:SetSize(16, 16)
buttonMinor:SetSize(16, 16)
buttonPlus:SetAlpha(0.834)
buttonMinor:SetAlpha(0.834)
--increate the value on pressing the button or holding the button pressed
local buttonPlusOnClick = function()
local sliderObject = sliderButtonsParentFrame.host
local currentValueOnSlider = sliderObject.value
local editboxShowingValue = DFSliderMetaFunctions.editbox_typevalue
if (sliderObject.fine_tuning) then
sliderObject:SetValue(currentValueOnSlider + sliderObject.fine_tuning)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(string.format("%.2f", currentValueOnSlider + sliderObject.fine_tuning)))
end
else
if (sliderObject.useDecimals) then
sliderObject:SetValue(currentValueOnSlider + 0.1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(string.format("%.2f", currentValueOnSlider + 0.1))
end
else
sliderObject:SetValue(currentValueOnSlider + 1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(math.floor(currentValueOnSlider + 1)))
end
end
end
end
buttonPlus:SetScript("OnMouseUp", function(self)
if (not buttonPlus.got_click) then
buttonPlusOnClick()
end
buttonPlus.got_click = false
self:SetScript("OnUpdate", nil)
end)
--hold the plus or minus button for x amount of time before start changing the value
local delayBeforeStartSimulatingClicks = 0
--after the delay been passed, trigger a click each x seconds
local simulateClickTimer = 0
local buttonPlusOnUpdate = function(self, deltaTime)
delayBeforeStartSimulatingClicks = delayBeforeStartSimulatingClicks + deltaTime
if (delayBeforeStartSimulatingClicks > 0.4) then
simulateClickTimer = simulateClickTimer + deltaTime
if (simulateClickTimer > 0.1) then
simulateClickTimer = 0
buttonPlusOnClick()
buttonPlus.got_click = true
end
end
end
buttonPlus:SetScript("OnMouseDown", function(self)
delayBeforeStartSimulatingClicks = 0
simulateClickTimer = 0
self:SetScript("OnUpdate", buttonPlusOnUpdate)
end)
-- -- --
--increate the value on pressing the button or holding the button pressed
local buttonMinusOnClick = function()
local sliderObject = sliderButtonsParentFrame.host
local currentValueOnSlider = sliderObject.value
local editboxShowingValue = DFSliderMetaFunctions.editbox_typevalue
if (sliderObject.fine_tuning) then
sliderObject:SetValue(currentValueOnSlider - sliderObject.fine_tuning)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(string.format("%.2f", currentValueOnSlider - sliderObject.fine_tuning)))
end
else
if (sliderObject.useDecimals) then
sliderObject:SetValue(currentValueOnSlider - 0.1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(string.format("%.2f", currentValueOnSlider - 0.1))
end
else
sliderObject:SetValue(currentValueOnSlider - 1)
if (editboxShowingValue and DFSliderMetaFunctions.editbox_typevalue:IsShown()) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(math.floor(currentValueOnSlider - 1)))
end
end
end
end
buttonMinor:SetScript("OnMouseUp", function(self)
if (not buttonMinor.got_click) then
buttonMinusOnClick()
end
buttonMinor.got_click = false
self:SetScript("OnUpdate", nil)
end)
local buttonMinusOnUpdate = function(self, elapsed)
delayBeforeStartSimulatingClicks = delayBeforeStartSimulatingClicks + elapsed
if (delayBeforeStartSimulatingClicks > 0.4) then
simulateClickTimer = simulateClickTimer + elapsed
if (simulateClickTimer > 0.1) then
simulateClickTimer = 0
buttonMinusOnClick()
buttonMinor.got_click = true
end
end
end
buttonMinor:SetScript("OnMouseDown", function(self)
delayBeforeStartSimulatingClicks = 0
simulateClickTimer = 0
self:SetScript("OnUpdate", buttonMinusOnUpdate)
end)
local do_precision = function(text)
if (type(text) == "string" and text:find("%.")) then
local left, right = strsplit(".", text)
left = tonumber(left)
right = tonumber(right)
if (left and right) then
local newString = tostring(left) .. "." .. tostring(right)
local newNumber = tonumber(newString)
if (newNumber) then
return newNumber
end
end
end
return tonumber(text)
end
DF.TextToFloor = do_precision
function DFSliderMetaFunctions:TypeValue()
if (not self.isSwitch) then
if (not DFSliderMetaFunctions.editbox_typevalue) then
local editbox = CreateFrame("EditBox", "DetailsFrameworkSliderEditBox", UIParent, "BackdropTemplate")
editbox:SetSize(40, 20)
editbox:SetJustifyH("center")
DF:ApplyStandardBackdrop(editbox)
editbox:SetFontObject("GameFontHighlightSmall")
editbox:SetScript("OnEnterPressed", function()
editbox:ClearFocus()
editbox:Hide()
editbox:GetParent().MyObject.typing_value = false
editbox:GetParent().MyObject.value = tonumber(editbox:GetText()) --do_precision (editbox:GetText())
end)
editbox:SetScript("OnEscapePressed", function()
editbox:ClearFocus()
editbox:Hide()
editbox:GetParent().MyObject.typing_value = false
editbox:GetParent().MyObject.value = self.typing_value_started --do_precision (self.typing_value_started)
end)
editbox:SetScript("OnTextChanged", function()
editbox:GetParent().MyObject.typing_can_change = true
editbox:GetParent().MyObject.value = tonumber(editbox:GetText()) --do_precision
editbox:GetParent().MyObject.typing_can_change = false
end)
DFSliderMetaFunctions.editbox_typevalue = editbox
end
local pvalue = self.previous_value[2]
self:SetValue(pvalue)
self.typing_value = true
self.typing_value_started = pvalue
DFSliderMetaFunctions.editbox_typevalue:SetSize(self.width, self.height)
DFSliderMetaFunctions.editbox_typevalue:SetPoint("center", self.widget, "center")
DFSliderMetaFunctions.editbox_typevalue:SetFocus()
DFSliderMetaFunctions.editbox_typevalue:SetParent(self.widget)
DFSliderMetaFunctions.editbox_typevalue:SetFrameLevel(self.widget:GetFrameLevel()+1)
if (self.useDecimals) then
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(string.format("%.1f", self.value)))
else
DFSliderMetaFunctions.editbox_typevalue:SetText(tostring(math.floor(self.value)))
end
DFSliderMetaFunctions.editbox_typevalue:HighlightText()
DFSliderMetaFunctions.editbox_typevalue:Show()
end
end
local OnMouseDown = function(slider, button)
local object = slider.MyObject
object.IsValueChanging = true
local kill = object:RunHooksForWidget("OnMouseDown", slider, button, object)
if (kill) then
return
end
if (button == "RightButton") then
object:TypeValue()
end
end
local OnMouseUp = function(slider, button)
local object = slider.MyObject
object.IsValueChanging = nil
local kill = object:RunHooksForWidget("OnMouseUp", slider, button, object)
if (kill) then
return
end
end
local OnHide = function(slider)
local object = slider.MyObject
local kill = object:RunHooksForWidget("OnHide", slider, object)
if (kill) then
return
end
if (object.typing_value) then
DFSliderMetaFunctions.editbox_typevalue:ClearFocus()
DFSliderMetaFunctions.editbox_typevalue:SetText("")
object.typing_valu = false
end
end
local OnShow = function(slider)
local object = slider.MyObject
local kill = object:RunHooksForWidget("OnShow", slider, object)
if (kill) then
return
end
end
local OnValueChanged = function(slider)
local object = slider.MyObject
local amt
if (object.useDecimals) then
amt = slider:GetValue()
else
amt = do_precision(slider:GetValue())
end
if (object.typing_value and not object.typing_can_change) then
object:SetValue(object.typing_value_started)
return
end
table.insert(object.previous_value, 1, amt)
table.remove(object.previous_value, 4)
if (object.useDecimals) then
slider.amt:SetText(string.format("%.2f", amt))
else
slider.amt:SetText(math.floor(amt))
end
object.ivalue = amt
if (object.NoCallback) then
object.NoCallback = false
return
end
--some plugins registered OnValueChanged and others with OnValueChange
local kill = object:RunHooksForWidget("OnValueChanged", slider, object.FixedValue, amt, object)
if (kill) then
return
end
local kill = object:RunHooksForWidget("OnValueChange", slider, object.FixedValue, amt, object)
if (kill) then
return
end
if (object.OnValueChanged) then
object.OnValueChanged(slider, object.FixedValue, amt)
end
end
------------------------------------------------------------------------------------------------------------
--object constructor
local SwitchOnClick = function(self, button, forced_value, value)
local object = self.MyObject
if (rawget(object, "lockdown")) then
return
end
if (forced_value) then
rawset(object, "value", not value)
end
if (rawget(object, "value")) then --actived
rawset(object, "value", false)
if (object.backdrop_disabledcolor) then
object:SetBackdropColor(unpack(object.backdrop_disabledcolor))
else
object:SetBackdropColor(1, 0, 0, 0.4)
end
if (object.is_checkbox) then
object.checked_texture:Hide()
else
object._text:SetText(object._ltext)
object._thumb:ClearAllPoints()
object._thumb:SetPoint("left", object.widget, "left")
end
else
rawset(object, "value", true)
if (object.backdrop_enabledcolor) then
object:SetBackdropColor(unpack(object.backdrop_enabledcolor))
else
object:SetBackdropColor(0, 0, 1, 0.4)
end
if (object.is_checkbox) then
object.checked_texture:Show()
else
object._text:SetText(object._rtext)
object._thumb:ClearAllPoints()
object._thumb:SetPoint("right", object.widget, "right")
end
end
if (object.OnSwitch and not forced_value) then
local value = rawget(object, "value")
if (object.return_func) then
value = object:return_func (value)
end
local success, errorText = xpcall(object.OnSwitch, geterrorhandler(), object, object.FixedValue, value)
if (not success) then
return
end
--trigger hooks
object:RunHooksForWidget("OnSwitch", object, object.FixedValue, value)
end
end
local switch_get_value = function(self)
return self.value
end
local switch_set_value = function(self, value, forcedState)
if (self.switch_func) then
value = self:switch_func(value)
end
local bForceValue = true
if (forcedState == "RUN_CALLBACK") then
bForceValue = false
end
SwitchOnClick (self.widget, nil, bForceValue, value)
end
local switch_set_fixparameter = function(self, value)
rawset(self, "FixedValue", value)
end
local switch_get_fixparameter = function(self)
return rawget(self, "FixedValue")
end
local switch_disable = function(self)
if (self.is_checkbox) then
self.checked_texture:Hide()
else
self._text:Hide()
if (not self.lock_texture) then
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self._thumb, "center")
end
self.lock_texture:Show()
end
self:SetAlpha(.4)
rawset(self, "lockdown", true)
end
local switch_enable = function(self)
if (self.is_checkbox) then
if (rawget(self, "value")) then
self.checked_texture:Show()
else
self.checked_texture:Hide()
end
else
if (not self.lock_texture) then
DF:NewImage(self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
self.lock_texture:SetDesaturated(true)
self.lock_texture:SetPoint("center", self._thumb, "center")
end
self.lock_texture:Hide()
self._text:Show()
end
self:SetAlpha(1)
return rawset(self, "lockdown", false)
end
local set_switch_func = function(self, newFunction)
self.OnSwitch = newFunction
end
local get_switch_func = function(self)
return self.OnSwitch
end
local setCheckedTexture = function(self, texture, xOffSet, yOffSet, sizePercent, color)
if (texture) then
self.checked_texture:SetTexture(texture, "CLAMP", "CLAMP", "TRILINEAR")
end
if (xOffSet or yOffSet) then
self.checked_texture:SetPoint("center", self.button, "center", xOffSet or -1, yOffSet or -1)
else
self.checked_texture:SetPoint("center", self.button, "center", -1, -1)
end
if (sizePercent and type(sizePercent) == "number") then
local width = self:GetWidth() * sizePercent
self.checked_texture:SetSize(width, width)
end
if (color) then
local r, g, b, a = DF:ParseColors(color)
self.checked_texture:SetVertexColor(r, g, b, a)
end
end
local set_as_checkbok = function(self)
if self.is_checkbox and self.checked_texture then return end
local checked = self:CreateTexture(self:GetName() .. "CheckTexture", "overlay")
checked:SetTexture([[Interface\Buttons\UI-CheckBox-Check]])
checked:SetPoint("center", self.button, "center", -1, -1)
local size_pct = self:GetWidth()/32
checked:SetSize(32 * size_pct, 32 * size_pct)
self.checked_texture = checked
self.SetCheckedTexture = setCheckedTexture
self.SetChecked = switch_set_value
self.GetChecked = switch_get_value
self._thumb:Hide()
self._text:Hide()
self.is_checkbox = true
if (rawget(self, "value")) then
self.checked_texture:Show()
if (self.backdrop_enabledcolor) then
self:SetBackdropColor(unpack(self.backdrop_enabledcolor))
else
self:SetBackdropColor(0, 0, 1, 0.4)
end
else
self.checked_texture:Hide()
if (self.backdrop_disabledcolor) then
self:SetBackdropColor(unpack(self.backdrop_disabledcolor))
else
self:SetBackdropColor(0, 0, 1, 0.4)
end
end
end
local createExtraSpaceToClick = function(self, label, widgetWidth, highlight)
--self = self.widget or self
label = label.widget or label
widgetWidth = widgetWidth or 140
local extraSpaceFrame = CreateFrame("button", nil, self.widget)
extraSpaceFrame:EnableMouse(true)
extraSpaceFrame:SetFrameLevel(self:GetFrameLevel()-1)
PixelUtil.SetSize(extraSpaceFrame, widgetWidth, self:GetHeight() + 1)
PixelUtil.SetPoint(extraSpaceFrame, "topleft", self.widget, "topleft", 0, 0)
local highlightTexture
if (highlight) then
highlightTexture = extraSpaceFrame:CreateTexture(nil, "highlight")
if (type(highlight) ~= "boolean") then
highlightTexture:SetTexture(highlight)
else
highlightTexture:SetColorTexture(1, 1, 1, 0.1)
end
PixelUtil.SetPoint(highlightTexture, "topleft", extraSpaceFrame, "topleft", 0, 0)
PixelUtil.SetPoint(highlightTexture, "bottomright", extraSpaceFrame, "bottomright", 0, 0)
end
extraSpaceFrame:SetScript("OnClick", function()
local bNewState = not self:GetValue()
self.OnSwitch(self, nil, bNewState)
if (bNewState) then
self:SetValue(true, "RUN_CALLBACK")
else
self:SetValue(false, "RUN_CALLBACK")