forked from Macblack131/Mac_RogueComboPointBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMac_MinimalSlider.lua
More file actions
150 lines (123 loc) · 4.36 KB
/
Mac_MinimalSlider.lua
File metadata and controls
150 lines (123 loc) · 4.36 KB
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
Mac_MinimalSliderWithInputBoxMixin = CreateFromMixins(CallbackRegistryMixin)
Mac_MinimalSliderWithInputBoxMixin:GenerateCallbackEvents(
{
"OnValueChanged",
"OnInteractStart",
"OnInteractEnd",
}
);
local interactionFlags = {
Hover = 1,
Click = 2,
};
function Mac_MinimalSliderWithInputBoxMixin:OnLoad()
CallbackRegistryMixin.OnLoad(self);
self.InteractionFlags = CreateFromMixins(FlagsMixin);
self.InteractionFlags:OnLoad();
local forward = false;
self.Back:SetScript("OnClick", GenerateClosure(self.OnStepperClicked, self, forward));
local backward = true;
self.Forward:SetScript("OnClick", GenerateClosure(self.OnStepperClicked, self, backward));
local function OnMouseDown(slider)
if slider:IsEnabled() then
self:SetInteractionFlag(interactionFlags.Click);
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
end
end
self.Slider:SetScript("OnMouseDown", OnMouseDown);
local function OnMouseUp(slider)
if slider:IsEnabled() then
self:ClearInteractionFlag(interactionFlags.Click);
end
end
self.Slider:SetScript("OnMouseUp", OnMouseUp);
local function OnEnter(slider)
if slider:IsEnabled() then
self:SetInteractionFlag(interactionFlags.Hover);
end
end
self.Slider:SetScript("OnEnter", OnEnter);
local function OnLeave(slider)
if slider:IsEnabled() then
self:ClearInteractionFlag(interactionFlags.Hover);
end
end
self.Slider:SetScript("OnLeave", OnLeave);
end
function Mac_MinimalSliderWithInputBoxMixin:OnStepperClicked(forward)
local value = self.Slider:GetValue();
local step = self.Slider.buttonStep
if forward then
self.Slider:SetValue(value + step);
else
self.Slider:SetValue(value - step);
end
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
end
function Mac_MinimalSliderWithInputBoxMixin:Init(value, minValue, maxValue, steps, buttonStep)
self.Slider:SetMinMaxValues(minValue, maxValue)
self.Slider:SetValueStep((maxValue - minValue) / steps)
self.Slider:SetValue(value)
self.Slider.buttonStep = buttonStep or 1
self.EditBox:SetJustifyH("CENTER")
self.EditBox:SetText(math.floor(value * 10 + 0.5) / 10)
self.EditBox.currentValue = math.floor(value * 10 + 0.5) / 10
local function OnValueChanged(slider, value)
self.EditBox:SetText(math.floor(value * 10 + 0.5) / 10)
self.EditBox.currentValue = math.floor(value * 10 + 0.5) / 10
self:TriggerEvent(Mac_MinimalSliderWithInputBoxMixin.Event.OnValueChanged, value);
end
self.Slider:SetScript("OnValueChanged", OnValueChanged);
local function OnEnterPressed()
local value = tonumber(self.EditBox:GetText())
if value == nil then
return
else
OnValueChanged(nil , math.floor(value * 10 + 0.5) / 10)
end
self.EditBox:ClearFocus()
end
self.EditBox:SetScript("OnEnterPressed", OnEnterPressed)
local function OnEditFocusGained()
self.EditBox:HighlightText(0,0)
end
self.EditBox:SetScript("OnEditFocusGained", OnEditFocusGained)
local function OnEscapePressed()
self.EditBox:SetText(self.EditBox.currentValue)
self.EditBox:ClearFocus()
end
self.EditBox:SetScript("OnEscapePressed", OnEscapePressed)
end
function Mac_MinimalSliderWithInputBoxMixin:SetInteractionFlag(flag)
local wasAnySet = self.InteractionFlags:IsAnySet();
self.InteractionFlags:Set(flag);
if not wasAnySet then
self:TriggerEvent(Mac_MinimalSliderWithInputBoxMixin.Event.OnInteractStart);
end
end
function Mac_MinimalSliderWithInputBoxMixin:ClearInteractionFlag(flag)
local wasAnySet = self.InteractionFlags:IsAnySet();
self.InteractionFlags:Clear(flag);
if wasAnySet and not self.InteractionFlags:IsAnySet() then
self:TriggerEvent(Mac_MinimalSliderWithInputBoxMixin.Event.OnInteractEnd);
end
end
local function ConfigureSlider(self, color, alpha)
self.Slider.Thumb:SetAlpha(alpha);
end
function Mac_MinimalSliderWithInputBoxMixin:SetEnabled(enabled)
if enabled then
ConfigureSlider(self, NORMAL_FONT_COLOR, 1.0);
else
ConfigureSlider(self, GRAY_FONT_COLOR, .7);
end
self.Slider:SetEnabled(enabled);
self.Back:SetEnabled(enabled);
self.Forward:SetEnabled(enabled);
end
function Mac_MinimalSliderWithInputBoxMixin:SetValue(value)
self.Slider:SetValue(value)
end
function Mac_MinimalSliderWithInputBoxMixin:Release()
self.Slider:Release();
end