|
Tercio@11
|
1
|
|
Tercio@11
|
2
|
|
Tercio@11
|
3
|
|
Tercio@11
|
4 local DF = _G ["DetailsFramework"]
|
|
Tercio@11
|
5 local _
|
|
Tercio@11
|
6
|
|
Tercio@11
|
7 local _rawset = rawset --> lua local
|
|
Tercio@11
|
8 local _rawget = rawget --> lua local
|
|
Tercio@11
|
9 local _setmetatable = setmetatable --> lua local
|
|
Tercio@11
|
10 local _unpack = unpack --> lua local
|
|
Tercio@11
|
11 local _type = type --> lua local
|
|
Tercio@11
|
12 local _math_floor = math.floor --> lua local
|
|
Tercio@11
|
13 local loadstring = loadstring --> lua local
|
|
Tercio@11
|
14
|
|
Tercio@11
|
15 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
|
|
Tercio@11
|
16
|
|
Tercio@11
|
17 local cleanfunction = function() end
|
|
Tercio@11
|
18 local APISliderFunctions = false
|
|
Tercio@11
|
19 local SliderMetaFunctions = {}
|
|
Tercio@11
|
20 local NameLessSlider = 1
|
|
Tercio@11
|
21
|
|
Tercio@11
|
22 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
23 --> metatables
|
|
Tercio@11
|
24
|
|
Tercio@11
|
25 SliderMetaFunctions.__call = function (_table, value)
|
|
Tercio@11
|
26 if (not value) then
|
|
Tercio@11
|
27 if (_table.isSwitch) then
|
|
Tercio@11
|
28
|
|
Tercio@11
|
29 if (type (value) == "boolean") then --> false
|
|
Tercio@11
|
30 return _table.slider:SetValue (1)
|
|
Tercio@11
|
31 end
|
|
Tercio@11
|
32
|
|
Tercio@11
|
33 if (_table.slider:GetValue() == 1) then
|
|
Tercio@11
|
34 return false
|
|
Tercio@11
|
35 else
|
|
Tercio@11
|
36 return true
|
|
Tercio@11
|
37 end
|
|
Tercio@11
|
38 end
|
|
Tercio@11
|
39 return _table.slider:GetValue()
|
|
Tercio@11
|
40 else
|
|
Tercio@11
|
41 if (_table.isSwitch) then
|
|
Tercio@11
|
42 if (type (value) == "boolean") then
|
|
Tercio@11
|
43 if (value) then
|
|
Tercio@11
|
44 _table.slider:SetValue (2)
|
|
Tercio@11
|
45 else
|
|
Tercio@11
|
46 _table.slider:SetValue (1)
|
|
Tercio@11
|
47 end
|
|
Tercio@11
|
48 else
|
|
Tercio@11
|
49 _table.slider:SetValue (value)
|
|
Tercio@11
|
50 end
|
|
Tercio@11
|
51 return
|
|
Tercio@11
|
52 end
|
|
Tercio@11
|
53
|
|
Tercio@11
|
54 return _table.slider:SetValue (value)
|
|
Tercio@11
|
55 end
|
|
Tercio@11
|
56 end
|
|
Tercio@11
|
57
|
|
Tercio@11
|
58 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
59 --> members
|
|
Tercio@11
|
60
|
|
Tercio@11
|
61 --> tooltip
|
|
Tercio@11
|
62 local gmember_tooltip = function (_object)
|
|
Tercio@11
|
63 return _object:GetTooltip()
|
|
Tercio@11
|
64 end
|
|
Tercio@11
|
65 --> shown
|
|
Tercio@11
|
66 local gmember_shown = function (_object)
|
|
Tercio@11
|
67 return _object:IsShown()
|
|
Tercio@11
|
68 end
|
|
Tercio@11
|
69 --> frame width
|
|
Tercio@11
|
70 local gmember_width = function (_object)
|
|
Tercio@11
|
71 return _object.slider:GetWidth()
|
|
Tercio@11
|
72 end
|
|
Tercio@11
|
73 --> frame height
|
|
Tercio@11
|
74 local gmember_height = function (_object)
|
|
Tercio@11
|
75 return _object.slider:GetHeight()
|
|
Tercio@11
|
76 end
|
|
Tercio@11
|
77 --> locked
|
|
Tercio@11
|
78 local gmember_locked = function (_object)
|
|
Tercio@11
|
79 return _rawget (_object, "lockdown")
|
|
Tercio@11
|
80 end
|
|
Tercio@11
|
81 --> fractional
|
|
Tercio@11
|
82 local gmember_fractional = function (_object)
|
|
Tercio@11
|
83 return _rawget (_object, "useDecimals")
|
|
Tercio@11
|
84 end
|
|
Tercio@11
|
85 --> value
|
|
Tercio@11
|
86 local gmember_value = function (_object)
|
|
Tercio@11
|
87 return _object()
|
|
Tercio@11
|
88 end
|
|
Tercio@11
|
89
|
|
Tercio@11
|
90 local get_members_function_index = {
|
|
Tercio@11
|
91 ["tooltip"] = gmember_tooltip,
|
|
Tercio@11
|
92 ["shown"] = gmember_shown,
|
|
Tercio@11
|
93 ["width"] = gmember_width,
|
|
Tercio@11
|
94 ["height"] = gmember_height,
|
|
Tercio@11
|
95 ["locked"] = gmember_locked,
|
|
Tercio@11
|
96 ["fractional"] = gmember_fractional,
|
|
Tercio@11
|
97 ["value"] = gmember_value,
|
|
Tercio@11
|
98 }
|
|
Tercio@11
|
99
|
|
Tercio@11
|
100 SliderMetaFunctions.__index = function (_table, _member_requested)
|
|
Tercio@11
|
101
|
|
Tercio@11
|
102 local func = get_members_function_index [_member_requested]
|
|
Tercio@11
|
103 if (func) then
|
|
Tercio@11
|
104 return func (_table, _member_requested)
|
|
Tercio@11
|
105 end
|
|
Tercio@11
|
106
|
|
Tercio@11
|
107 local fromMe = _rawget (_table, _member_requested)
|
|
Tercio@11
|
108 if (fromMe) then
|
|
Tercio@11
|
109 return fromMe
|
|
Tercio@11
|
110 end
|
|
Tercio@11
|
111
|
|
Tercio@11
|
112 return SliderMetaFunctions [_member_requested]
|
|
Tercio@11
|
113 end
|
|
Tercio@11
|
114
|
|
Tercio@11
|
115 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
116
|
|
Tercio@11
|
117 --> tooltip
|
|
Tercio@11
|
118 local smember_tooltip = function (_object, _value)
|
|
Tercio@11
|
119 return _object:SetTooltip (_value)
|
|
Tercio@11
|
120 end
|
|
Tercio@11
|
121 --> show
|
|
Tercio@11
|
122 local smember_show = function (_object, _value)
|
|
Tercio@11
|
123 if (_value) then
|
|
Tercio@11
|
124 return _object:Show()
|
|
Tercio@11
|
125 else
|
|
Tercio@11
|
126 return _object:Hide()
|
|
Tercio@11
|
127 end
|
|
Tercio@11
|
128 end
|
|
Tercio@11
|
129 --> hide
|
|
Tercio@11
|
130 local smember_hide = function (_object, _value)
|
|
Tercio@11
|
131 if (not _value) then
|
|
Tercio@11
|
132 return _object:Show()
|
|
Tercio@11
|
133 else
|
|
Tercio@11
|
134 return _object:Hide()
|
|
Tercio@11
|
135 end
|
|
Tercio@11
|
136 end
|
|
Tercio@11
|
137 --> frame width
|
|
Tercio@11
|
138 local smember_width = function (_object, _value)
|
|
Tercio@11
|
139 return _object.slider:SetWidth (_value)
|
|
Tercio@11
|
140 end
|
|
Tercio@11
|
141 --> frame height
|
|
Tercio@11
|
142 local smember_height = function (_object, _value)
|
|
Tercio@11
|
143 return _object.slider:SetHeight (_value)
|
|
Tercio@11
|
144 end
|
|
Tercio@11
|
145 --> locked
|
|
Tercio@11
|
146 local smember_locked = function (_object, _value)
|
|
Tercio@11
|
147 if (_value) then
|
|
Tercio@11
|
148 return self:Disable()
|
|
Tercio@11
|
149 else
|
|
Tercio@11
|
150 return self:Enable()
|
|
Tercio@11
|
151 end
|
|
Tercio@11
|
152 end
|
|
Tercio@11
|
153 --> backdrop
|
|
Tercio@11
|
154 local smember_backdrop = function (_object, _value)
|
|
Tercio@11
|
155 return _object.slider:SetBackdrop (_value)
|
|
Tercio@11
|
156 end
|
|
Tercio@11
|
157 --> fractional
|
|
Tercio@11
|
158 local smember_fractional = function (_object, _value)
|
|
Tercio@11
|
159 return _rawset (_object, "useDecimals", _value)
|
|
Tercio@11
|
160 end
|
|
Tercio@11
|
161 --> value
|
|
Tercio@11
|
162 local smember_value = function (_object, _value)
|
|
Tercio@11
|
163 _object (_value)
|
|
Tercio@11
|
164 end
|
|
Tercio@11
|
165
|
|
Tercio@11
|
166 local set_members_function_index = {
|
|
Tercio@11
|
167 ["tooltip"] = smember_tooltip,
|
|
Tercio@11
|
168 ["show"] = smember_show,
|
|
Tercio@11
|
169 ["hide"] = smember_hide,
|
|
Tercio@11
|
170 ["backdrop"] = smember_backdrop,
|
|
Tercio@11
|
171 ["width"] = smember_width,
|
|
Tercio@11
|
172 ["height"] = smember_height,
|
|
Tercio@11
|
173 ["locked"] = smember_locked,
|
|
Tercio@11
|
174 ["fractional"] = smember_fractional,
|
|
Tercio@11
|
175 ["value"] = smember_value,
|
|
Tercio@11
|
176 }
|
|
Tercio@11
|
177
|
|
Tercio@11
|
178 SliderMetaFunctions.__newindex = function (_table, _key, _value)
|
|
Tercio@11
|
179 local func = set_members_function_index [_key]
|
|
Tercio@11
|
180 if (func) then
|
|
Tercio@11
|
181 return func (_table, _value)
|
|
Tercio@11
|
182 else
|
|
Tercio@11
|
183 return _rawset (_table, _key, _value)
|
|
Tercio@11
|
184 end
|
|
Tercio@11
|
185 end
|
|
Tercio@11
|
186
|
|
Tercio@11
|
187 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
188 --> methods
|
|
Tercio@11
|
189
|
|
Tercio@11
|
190 --> show & hide
|
|
Tercio@11
|
191 function SliderMetaFunctions:IsShown()
|
|
Tercio@11
|
192 return self.slider:IsShown()
|
|
Tercio@11
|
193 end
|
|
Tercio@11
|
194 function SliderMetaFunctions:Show()
|
|
Tercio@11
|
195 return self.slider:Show()
|
|
Tercio@11
|
196 end
|
|
Tercio@11
|
197 function SliderMetaFunctions:Hide()
|
|
Tercio@11
|
198 return self.slider:Hide()
|
|
Tercio@11
|
199 end
|
|
Tercio@11
|
200
|
|
Tercio@11
|
201 --> fixed value
|
|
Tercio@11
|
202 function SliderMetaFunctions:SetFixedParameter (value)
|
|
Tercio@11
|
203 _rawset (self, "FixedValue", value)
|
|
Tercio@11
|
204 end
|
|
Tercio@11
|
205
|
|
Tercio@11
|
206 --> set value
|
|
Tercio@11
|
207 function SliderMetaFunctions:SetValue (value)
|
|
Tercio@11
|
208 return self (value)
|
|
Tercio@11
|
209 end
|
|
Tercio@11
|
210
|
|
Tercio@11
|
211 -- thumb size
|
|
Tercio@11
|
212 function SliderMetaFunctions:SetThumbSize (w, h)
|
|
Tercio@11
|
213 if (not w) then
|
|
Tercio@11
|
214 w = self.thumb:GetWidth()
|
|
Tercio@11
|
215 end
|
|
Tercio@11
|
216 if (not h) then
|
|
Tercio@11
|
217 h = self.thumb:GetHeight()
|
|
Tercio@11
|
218 end
|
|
Tercio@11
|
219 return self.thumb:SetSize (w, h)
|
|
Tercio@11
|
220 end
|
|
Tercio@11
|
221
|
|
Tercio@11
|
222
|
|
Tercio@11
|
223 -- setpoint
|
|
Tercio@11
|
224 function SliderMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
225 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
|
|
Tercio@11
|
226 if (not v1) then
|
|
Tercio@11
|
227 print ("Invalid parameter for SetPoint")
|
|
Tercio@11
|
228 return
|
|
Tercio@11
|
229 end
|
|
Tercio@11
|
230 return self.widget:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
231 end
|
|
Tercio@11
|
232
|
|
Tercio@11
|
233 -- sizes
|
|
Tercio@11
|
234 function SliderMetaFunctions:SetSize (w, h)
|
|
Tercio@11
|
235 if (w) then
|
|
Tercio@11
|
236 self.slider:SetWidth (w)
|
|
Tercio@11
|
237 end
|
|
Tercio@11
|
238 if (h) then
|
|
Tercio@11
|
239 return self.slider:SetHeight (h)
|
|
Tercio@11
|
240 end
|
|
Tercio@11
|
241 end
|
|
Tercio@11
|
242
|
|
Tercio@11
|
243 -- tooltip
|
|
Tercio@11
|
244 function SliderMetaFunctions:SetTooltip (tooltip)
|
|
Tercio@11
|
245 if (tooltip) then
|
|
Tercio@11
|
246 return _rawset (self, "have_tooltip", tooltip)
|
|
Tercio@11
|
247 else
|
|
Tercio@11
|
248 return _rawset (self, "have_tooltip", nil)
|
|
Tercio@11
|
249 end
|
|
Tercio@11
|
250 end
|
|
Tercio@11
|
251 function SliderMetaFunctions:GetTooltip()
|
|
Tercio@11
|
252 return _rawget (self, "have_tooltip")
|
|
Tercio@11
|
253 end
|
|
Tercio@11
|
254
|
|
Tercio@11
|
255 -- frame levels
|
|
Tercio@11
|
256 function SliderMetaFunctions:GetFrameLevel()
|
|
Tercio@11
|
257 return self.slider:GetFrameLevel()
|
|
Tercio@11
|
258 end
|
|
Tercio@11
|
259 function SliderMetaFunctions:SetFrameLevel (level, frame)
|
|
Tercio@11
|
260 if (not frame) then
|
|
Tercio@11
|
261 return self.slider:SetFrameLevel (level)
|
|
Tercio@11
|
262 else
|
|
Tercio@11
|
263 local framelevel = frame:GetFrameLevel (frame) + level
|
|
Tercio@11
|
264 return self.slider:SetFrameLevel (framelevel)
|
|
Tercio@11
|
265 end
|
|
Tercio@11
|
266 end
|
|
Tercio@11
|
267
|
|
Tercio@11
|
268 -- frame stratas
|
|
Tercio@11
|
269 function SliderMetaFunctions:SetFrameStrata()
|
|
Tercio@11
|
270 return self.slider:GetFrameStrata()
|
|
Tercio@11
|
271 end
|
|
Tercio@11
|
272 function SliderMetaFunctions:SetFrameStrata (strata)
|
|
Tercio@11
|
273 if (_type (strata) == "table") then
|
|
Tercio@11
|
274 self.slider:SetFrameStrata (strata:GetFrameStrata())
|
|
Tercio@11
|
275 else
|
|
Tercio@11
|
276 self.slider:SetFrameStrata (strata)
|
|
Tercio@11
|
277 end
|
|
Tercio@11
|
278 end
|
|
Tercio@11
|
279
|
|
Tercio@11
|
280 -- enabled
|
|
Tercio@11
|
281 function SliderMetaFunctions:IsEnabled()
|
|
Tercio@11
|
282 return not _rawget (self, "lockdown")
|
|
Tercio@11
|
283 end
|
|
Tercio@11
|
284 function SliderMetaFunctions:Enable()
|
|
Tercio@11
|
285 self.slider:Enable()
|
|
Tercio@11
|
286 if (not self.lock_texture) then
|
|
Tercio@11
|
287 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
|
|
Tercio@11
|
288 self.lock_texture:SetDesaturated (true)
|
|
Tercio@11
|
289 self.lock_texture:SetPoint ("center", self.amt, "center")
|
|
Tercio@11
|
290 end
|
|
Tercio@11
|
291 self.lock_texture:Hide()
|
|
Tercio@11
|
292 self.slider.amt:Show()
|
|
Tercio@11
|
293 self:SetAlpha (1)
|
|
Tercio@11
|
294 return _rawset (self, "lockdown", false)
|
|
Tercio@11
|
295 end
|
|
Tercio@11
|
296
|
|
Tercio@11
|
297 function SliderMetaFunctions:Disable()
|
|
Tercio@11
|
298
|
|
Tercio@11
|
299 self.slider:Disable()
|
|
Tercio@11
|
300 self.slider.amt:Hide()
|
|
Tercio@11
|
301 self:SetAlpha (.4)
|
|
Tercio@11
|
302
|
|
Tercio@11
|
303 if (not self.lock_texture) then
|
|
Tercio@11
|
304 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
|
|
Tercio@11
|
305 self.lock_texture:SetDesaturated (true)
|
|
Tercio@11
|
306 self.lock_texture:SetPoint ("center", self.amt, "center")
|
|
Tercio@11
|
307 end
|
|
Tercio@11
|
308 self.lock_texture:Show()
|
|
Tercio@11
|
309
|
|
Tercio@11
|
310 return _rawset (self, "lockdown", true)
|
|
Tercio@11
|
311 end
|
|
Tercio@11
|
312
|
|
Tercio@11
|
313 --> hooks
|
|
Tercio@11
|
314 function SliderMetaFunctions:SetHook (hookType, func)
|
|
Tercio@11
|
315 if (func) then
|
|
Tercio@11
|
316 _rawset (self, hookType.."Hook", func)
|
|
Tercio@11
|
317 else
|
|
Tercio@11
|
318 _rawset (self, hookType.."Hook", nil)
|
|
Tercio@11
|
319 end
|
|
Tercio@11
|
320 end
|
|
Tercio@11
|
321
|
|
Tercio@11
|
322 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
323 --> scripts
|
|
Tercio@11
|
324
|
|
Tercio@11
|
325 local OnEnter = function (slider)
|
|
Tercio@11
|
326
|
|
Tercio@11
|
327 if (_rawget (slider.MyObject, "lockdown")) then
|
|
Tercio@11
|
328 return
|
|
Tercio@11
|
329 end
|
|
Tercio@11
|
330
|
|
Tercio@11
|
331 DetailsFrameworkSliderButtons1:ShowMe (slider)
|
|
Tercio@11
|
332
|
|
Tercio@11
|
333 if (slider.MyObject.OnEnterHook) then
|
|
Tercio@11
|
334 local interrupt = slider.MyObject.OnEnterHook (slider)
|
|
Tercio@11
|
335 if (interrupt) then
|
|
Tercio@11
|
336 return
|
|
Tercio@11
|
337 end
|
|
Tercio@11
|
338 end
|
|
Tercio@11
|
339
|
|
Tercio@11
|
340 slider.thumb:SetAlpha (1)
|
|
Tercio@11
|
341
|
|
Tercio@11
|
342 if (slider.MyObject.have_tooltip and slider.MyObject.have_tooltip ~= "Right Click to Type the Value") then
|
|
Tercio@11
|
343 GameCooltip2:Preset (2)
|
|
Tercio@11
|
344 GameCooltip2:AddLine (slider.MyObject.have_tooltip)
|
|
Tercio@11
|
345 GameCooltip2:ShowCooltip (slider, "tooltip")
|
|
Tercio@11
|
346 else
|
|
Tercio@11
|
347 GameCooltip2:Preset (1)
|
|
Tercio@11
|
348 GameCooltip2:AddLine ("Right Click to Type the Value")
|
|
Tercio@11
|
349 GameCooltip2:AddIcon ([[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]], 1, 1, 16, 16, 0.015625, 0.15671875, 0.640625, 0.798828125)
|
|
Tercio@11
|
350 GameCooltip2:ShowCooltip (slider, "tooltip")
|
|
Tercio@11
|
351 end
|
|
Tercio@11
|
352
|
|
Tercio@11
|
353 local parent = slider:GetParent().MyObject
|
|
Tercio@11
|
354 if (parent and parent.type == "panel") then
|
|
Tercio@11
|
355 if (parent.GradientEnabled) then
|
|
Tercio@11
|
356 parent:RunGradient()
|
|
Tercio@11
|
357 end
|
|
Tercio@11
|
358 end
|
|
Tercio@11
|
359
|
|
Tercio@11
|
360 end
|
|
Tercio@11
|
361
|
|
Tercio@11
|
362 local OnLeave = function (slider)
|
|
Tercio@11
|
363
|
|
Tercio@11
|
364 if (_rawget (slider.MyObject, "lockdown")) then
|
|
Tercio@11
|
365 return
|
|
Tercio@11
|
366 end
|
|
Tercio@11
|
367
|
|
Tercio@11
|
368 DetailsFrameworkSliderButtons1:PrepareToHide()
|
|
Tercio@11
|
369
|
|
Tercio@11
|
370 if (slider.MyObject.OnLeaveHook) then
|
|
Tercio@11
|
371 local interrupt = slider.MyObject.OnLeaveHook (slider)
|
|
Tercio@11
|
372 if (interrupt) then
|
|
Tercio@11
|
373 return
|
|
Tercio@11
|
374 end
|
|
Tercio@11
|
375 end
|
|
Tercio@11
|
376
|
|
Tercio@11
|
377 slider.thumb:SetAlpha (.7)
|
|
Tercio@11
|
378
|
|
Tercio@11
|
379 if (slider.MyObject.have_tooltip) then
|
|
Tercio@11
|
380 GameCooltip2:ShowMe (false)
|
|
Tercio@11
|
381 end
|
|
Tercio@11
|
382
|
|
Tercio@11
|
383 local parent = slider:GetParent().MyObject
|
|
Tercio@11
|
384 if (parent and parent.type == "panel") then
|
|
Tercio@11
|
385 if (parent.GradientEnabled) then
|
|
Tercio@11
|
386 parent:RunGradient (false)
|
|
Tercio@11
|
387 end
|
|
Tercio@11
|
388 end
|
|
Tercio@11
|
389
|
|
Tercio@11
|
390 end
|
|
Tercio@11
|
391
|
|
Tercio@11
|
392
|
|
Tercio@11
|
393 local f = CreateFrame ("frame", "DetailsFrameworkSliderButtons1", UIParent)
|
|
Tercio@11
|
394 f:Hide()
|
|
Tercio@11
|
395 --f:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], tile = true, tileSize = 5})
|
|
Tercio@11
|
396 f:SetHeight (18)
|
|
Tercio@11
|
397
|
|
Tercio@11
|
398 local t = 0
|
|
Tercio@11
|
399 f.is_going_hide = false
|
|
Tercio@11
|
400 local going_hide = function (self, elapsed)
|
|
Tercio@11
|
401 t = t + elapsed
|
|
Tercio@11
|
402 if (t > 0.3) then
|
|
Tercio@11
|
403 f:Hide()
|
|
Tercio@11
|
404 f:SetScript ("OnUpdate", nil)
|
|
Tercio@11
|
405 f.is_going_hide = false
|
|
Tercio@11
|
406 end
|
|
Tercio@11
|
407 end
|
|
Tercio@11
|
408
|
|
Tercio@11
|
409 function f:ShowMe (host)
|
|
Tercio@11
|
410 f:SetPoint ("bottomleft", host, "topleft", -3, -5)
|
|
Tercio@11
|
411 f:SetPoint ("bottomright", host, "topright", 3, -5)
|
|
Tercio@11
|
412 f:SetFrameStrata (host:GetFrameStrata())
|
|
Tercio@11
|
413 f:SetFrameLevel (host:GetFrameLevel())
|
|
Tercio@11
|
414 f:Show()
|
|
Tercio@11
|
415 if (f.is_going_hide) then
|
|
Tercio@11
|
416 f:SetScript ("OnUpdate", nil)
|
|
Tercio@11
|
417 f.is_going_hide = false
|
|
Tercio@11
|
418 end
|
|
Tercio@11
|
419
|
|
Tercio@11
|
420 f.host = host.MyObject
|
|
Tercio@11
|
421 end
|
|
Tercio@11
|
422
|
|
Tercio@11
|
423 function f:PrepareToHide()
|
|
Tercio@11
|
424 f.is_going_hide = true
|
|
Tercio@11
|
425 t = 0
|
|
Tercio@11
|
426 f:SetScript ("OnUpdate", going_hide)
|
|
Tercio@11
|
427 end
|
|
Tercio@11
|
428
|
|
Tercio@11
|
429 local button_plus = CreateFrame ("button", "DetailsFrameworkSliderButtonsPlusButton", f)
|
|
Tercio@11
|
430 local button_minor = CreateFrame ("button", "DetailsFrameworkSliderButtonsMinorButton", f)
|
|
Tercio@11
|
431
|
|
Tercio@11
|
432 button_plus:SetScript ("OnEnter", function (self)
|
|
Tercio@11
|
433 if (f.is_going_hide) then
|
|
Tercio@11
|
434 f:SetScript ("OnUpdate", nil)
|
|
Tercio@11
|
435 f.is_going_hide = false
|
|
Tercio@11
|
436 end
|
|
Tercio@11
|
437 end)
|
|
Tercio@11
|
438 button_minor:SetScript ("OnEnter", function (self)
|
|
Tercio@11
|
439 if (f.is_going_hide) then
|
|
Tercio@11
|
440 f:SetScript ("OnUpdate", nil)
|
|
Tercio@11
|
441 f.is_going_hide = false
|
|
Tercio@11
|
442 end
|
|
Tercio@11
|
443 end)
|
|
Tercio@11
|
444
|
|
Tercio@11
|
445 button_plus:SetScript ("OnLeave", function (self)
|
|
Tercio@11
|
446 f:PrepareToHide()
|
|
Tercio@11
|
447 end)
|
|
Tercio@11
|
448 button_minor:SetScript ("OnLeave", function (self)
|
|
Tercio@11
|
449 f:PrepareToHide()
|
|
Tercio@11
|
450 end)
|
|
Tercio@11
|
451
|
|
Tercio@11
|
452 button_plus:SetNormalTexture ([[Interface\Buttons\UI-PlusButton-Up]])
|
|
Tercio@11
|
453 button_minor:SetNormalTexture ([[Interface\Buttons\UI-MinusButton-Up]])
|
|
Tercio@11
|
454
|
|
Tercio@11
|
455 button_plus:SetPushedTexture ([[Interface\Buttons\UI-PlusButton-Down]])
|
|
Tercio@11
|
456 button_minor:SetPushedTexture ([[Interface\Buttons\UI-MinusButton-Down]])
|
|
Tercio@11
|
457
|
|
Tercio@11
|
458 button_plus:SetDisabledTexture ([[Interface\Buttons\UI-PlusButton-Disabled]])
|
|
Tercio@11
|
459 button_minor:SetDisabledTexture ([[Interface\Buttons\UI-MinusButton-Disabled]])
|
|
Tercio@11
|
460
|
|
Tercio@11
|
461 button_plus:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]])
|
|
Tercio@11
|
462 button_minor:SetHighlightTexture ([[Interface\Buttons\UI-PlusButton-Hilight]])
|
|
Tercio@11
|
463
|
|
Tercio@11
|
464 --button_minor:SetPoint ("bottomleft", f, "bottomleft", -6, -13)
|
|
Tercio@11
|
465 --button_plus:SetPoint ("bottomright", f, "bottomright", 6, -13)
|
|
Tercio@11
|
466
|
|
Tercio@11
|
467 button_minor:SetPoint ("bottomright", f, "bottomright", 13, -13)
|
|
Tercio@11
|
468 button_plus:SetPoint ("left", button_minor, "right", -2, 0)
|
|
Tercio@11
|
469
|
|
Tercio@11
|
470 button_plus:SetSize (16, 16)
|
|
Tercio@11
|
471 button_minor:SetSize (16, 16)
|
|
Tercio@11
|
472
|
|
Tercio@11
|
473 local timer = 0
|
|
Tercio@11
|
474 local change_timer = 0
|
|
Tercio@11
|
475
|
|
Tercio@11
|
476 -- -- --
|
|
Tercio@11
|
477
|
|
Tercio@11
|
478 local plus_button_script = function()
|
|
Tercio@11
|
479
|
|
Tercio@11
|
480 local current = f.host.value
|
|
Tercio@11
|
481 local editbox = SliderMetaFunctions.editbox_typevalue
|
|
Tercio@11
|
482
|
|
Tercio@11
|
483 if (f.host.fine_tuning) then
|
|
Tercio@11
|
484 f.host:SetValue (current + f.host.fine_tuning)
|
|
Tercio@11
|
485 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
|
|
Tercio@11
|
486 SliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current + f.host.fine_tuning)))
|
|
Tercio@11
|
487 end
|
|
Tercio@11
|
488 else
|
|
Tercio@11
|
489 if (f.host.useDecimals) then
|
|
Tercio@11
|
490 f.host:SetValue (current + 0.1)
|
|
Tercio@11
|
491 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
|
|
Tercio@11
|
492 SliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current + 0.1))
|
|
Tercio@11
|
493 end
|
|
Tercio@11
|
494 else
|
|
Tercio@11
|
495 f.host:SetValue (current + 1)
|
|
Tercio@11
|
496 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
|
|
Tercio@11
|
497 SliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current + 1)))
|
|
Tercio@11
|
498 end
|
|
Tercio@11
|
499 end
|
|
Tercio@11
|
500 end
|
|
Tercio@11
|
501
|
|
Tercio@11
|
502 end
|
|
Tercio@11
|
503
|
|
Tercio@11
|
504 button_plus:SetScript ("OnMouseUp", function (self)
|
|
Tercio@11
|
505 if (not button_plus.got_click) then
|
|
Tercio@11
|
506 plus_button_script()
|
|
Tercio@11
|
507 end
|
|
Tercio@11
|
508 button_plus.got_click = false
|
|
Tercio@11
|
509 self:SetScript ("OnUpdate", nil)
|
|
Tercio@11
|
510 end)
|
|
Tercio@11
|
511
|
|
Tercio@11
|
512 local on_update = function (self, elapsed)
|
|
Tercio@11
|
513 timer = timer + elapsed
|
|
Tercio@11
|
514 if (timer > 0.4) then
|
|
Tercio@11
|
515 change_timer = change_timer + elapsed
|
|
Tercio@11
|
516 if (change_timer > 0.1) then
|
|
Tercio@11
|
517 change_timer = 0
|
|
Tercio@11
|
518 plus_button_script()
|
|
Tercio@11
|
519 button_plus.got_click = true
|
|
Tercio@11
|
520 end
|
|
Tercio@11
|
521 end
|
|
Tercio@11
|
522 end
|
|
Tercio@11
|
523 button_plus:SetScript ("OnMouseDown", function (self)
|
|
Tercio@11
|
524 timer = 0
|
|
Tercio@11
|
525 change_timer = 0
|
|
Tercio@11
|
526 self:SetScript ("OnUpdate", on_update)
|
|
Tercio@11
|
527 end)
|
|
Tercio@11
|
528
|
|
Tercio@11
|
529 -- -- --
|
|
Tercio@11
|
530
|
|
Tercio@11
|
531 local minor_button_script = function()
|
|
Tercio@11
|
532 local current = f.host.value
|
|
Tercio@11
|
533 local editbox = SliderMetaFunctions.editbox_typevalue
|
|
Tercio@11
|
534
|
|
Tercio@11
|
535 if (f.host.fine_tuning) then
|
|
Tercio@11
|
536 f.host:SetValue (current - f.host.fine_tuning)
|
|
Tercio@11
|
537 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
|
|
Tercio@11
|
538 SliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.2f", current - f.host.fine_tuning)))
|
|
Tercio@11
|
539 end
|
|
Tercio@11
|
540 else
|
|
Tercio@11
|
541 if (f.host.useDecimals) then
|
|
Tercio@11
|
542 f.host:SetValue (current - 0.1)
|
|
Tercio@11
|
543 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
|
|
Tercio@11
|
544 SliderMetaFunctions.editbox_typevalue:SetText (string.format ("%.2f", current - 0.1))
|
|
Tercio@11
|
545 end
|
|
Tercio@11
|
546 else
|
|
Tercio@11
|
547 f.host:SetValue (current - 1)
|
|
Tercio@11
|
548 if (editbox and SliderMetaFunctions.editbox_typevalue:IsShown()) then
|
|
Tercio@11
|
549 SliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (current - 1)))
|
|
Tercio@11
|
550 end
|
|
Tercio@11
|
551 end
|
|
Tercio@11
|
552 end
|
|
Tercio@11
|
553 end
|
|
Tercio@11
|
554
|
|
Tercio@11
|
555 button_minor:SetScript ("OnMouseUp", function (self)
|
|
Tercio@11
|
556 if (not button_minor.got_click) then
|
|
Tercio@11
|
557 minor_button_script()
|
|
Tercio@11
|
558 end
|
|
Tercio@11
|
559 button_minor.got_click = false
|
|
Tercio@11
|
560 self:SetScript ("OnUpdate", nil)
|
|
Tercio@11
|
561 end)
|
|
Tercio@11
|
562
|
|
Tercio@11
|
563 local on_update = function (self, elapsed)
|
|
Tercio@11
|
564 timer = timer + elapsed
|
|
Tercio@11
|
565 if (timer > 0.4) then
|
|
Tercio@11
|
566 change_timer = change_timer + elapsed
|
|
Tercio@11
|
567 if (change_timer > 0.1) then
|
|
Tercio@11
|
568 change_timer = 0
|
|
Tercio@11
|
569 minor_button_script()
|
|
Tercio@11
|
570 button_minor.got_click = true
|
|
Tercio@11
|
571 end
|
|
Tercio@11
|
572 end
|
|
Tercio@11
|
573 end
|
|
Tercio@11
|
574 button_minor:SetScript ("OnMouseDown", function (self)
|
|
Tercio@11
|
575 timer = 0
|
|
Tercio@11
|
576 change_timer = 0
|
|
Tercio@11
|
577 self:SetScript ("OnUpdate", on_update)
|
|
Tercio@11
|
578 end)
|
|
Tercio@11
|
579
|
|
Tercio@11
|
580 function SliderMetaFunctions:TypeValue()
|
|
Tercio@11
|
581 if (not self.isSwitch) then
|
|
Tercio@11
|
582
|
|
Tercio@11
|
583 if (not SliderMetaFunctions.editbox_typevalue) then
|
|
Tercio@11
|
584
|
|
Tercio@11
|
585 local editbox = CreateFrame ("EditBox", "DetailsFrameworkSliderEditBox", UIParent)
|
|
Tercio@11
|
586
|
|
Tercio@11
|
587 editbox:SetSize (40, 20)
|
|
Tercio@11
|
588 editbox:SetJustifyH ("center")
|
|
Tercio@11
|
589 editbox:SetBackdrop ({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]],
|
|
Tercio@11
|
590 edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", --edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
|
|
Tercio@11
|
591 tile = true, edgeSize = 8, tileSize = 5})
|
|
Tercio@11
|
592 editbox:SetFontObject ("GameFontHighlightSmall")
|
|
Tercio@11
|
593
|
|
Tercio@11
|
594 editbox:SetScript ("OnEnterPressed", function()
|
|
Tercio@11
|
595 editbox:ClearFocus()
|
|
Tercio@11
|
596 editbox:Hide()
|
|
Tercio@11
|
597 editbox:GetParent().MyObject.typing_value = false
|
|
Tercio@11
|
598 editbox:GetParent().MyObject.value = tonumber (editbox:GetText())
|
|
Tercio@11
|
599 end)
|
|
Tercio@11
|
600
|
|
Tercio@11
|
601 editbox:SetScript ("OnEscapePressed", function()
|
|
Tercio@11
|
602 editbox:ClearFocus()
|
|
Tercio@11
|
603 editbox:Hide()
|
|
Tercio@11
|
604 editbox:GetParent().MyObject.typing_value = false
|
|
Tercio@11
|
605 editbox:GetParent().MyObject.value = tonumber (self.typing_value_started)
|
|
Tercio@11
|
606 end)
|
|
Tercio@11
|
607
|
|
Tercio@11
|
608 editbox:SetScript ("OnTextChanged", function()
|
|
Tercio@11
|
609 editbox:GetParent().MyObject.typing_can_change = true
|
|
Tercio@11
|
610 editbox:GetParent().MyObject.value = tonumber (editbox:GetText())
|
|
Tercio@11
|
611 editbox:GetParent().MyObject.typing_can_change = false
|
|
Tercio@11
|
612
|
|
Tercio@11
|
613 -- esse self fica como o primeiro a ser alterado
|
|
Tercio@11
|
614 --print ("text changed", self:GetName())
|
|
Tercio@11
|
615 --print ()
|
|
Tercio@11
|
616 end)
|
|
Tercio@11
|
617
|
|
Tercio@11
|
618 SliderMetaFunctions.editbox_typevalue = editbox
|
|
Tercio@11
|
619 end
|
|
Tercio@11
|
620
|
|
Tercio@11
|
621 local pvalue = self.previous_value [2]
|
|
Tercio@11
|
622 self:SetValue (pvalue)
|
|
Tercio@11
|
623
|
|
Tercio@11
|
624 self.typing_value = true
|
|
Tercio@11
|
625 self.typing_value_started = pvalue
|
|
Tercio@11
|
626
|
|
Tercio@11
|
627 SliderMetaFunctions.editbox_typevalue:SetSize (self.width, self.height)
|
|
Tercio@11
|
628 SliderMetaFunctions.editbox_typevalue:SetPoint ("center", self.widget, "center")
|
|
Tercio@11
|
629 SliderMetaFunctions.editbox_typevalue:SetFocus()
|
|
Tercio@11
|
630 SliderMetaFunctions.editbox_typevalue:SetParent (self.widget)
|
|
Tercio@11
|
631 SliderMetaFunctions.editbox_typevalue:SetFrameLevel (self.widget:GetFrameLevel()+1)
|
|
Tercio@11
|
632
|
|
Tercio@11
|
633 if (self.useDecimals) then
|
|
Tercio@11
|
634 SliderMetaFunctions.editbox_typevalue:SetText (tostring (string.format ("%.1f", self.value)))
|
|
Tercio@11
|
635 else
|
|
Tercio@11
|
636 SliderMetaFunctions.editbox_typevalue:SetText (tostring (math.floor (self.value)))
|
|
Tercio@11
|
637 end
|
|
Tercio@11
|
638
|
|
Tercio@11
|
639 SliderMetaFunctions.editbox_typevalue:HighlightText()
|
|
Tercio@11
|
640
|
|
Tercio@11
|
641 SliderMetaFunctions.editbox_typevalue:Show()
|
|
Tercio@11
|
642 end
|
|
Tercio@11
|
643 end
|
|
Tercio@11
|
644
|
|
Tercio@11
|
645 local OnMouseDown = function (slider, button)
|
|
Tercio@11
|
646 if (button == "RightButton") then
|
|
Tercio@11
|
647 slider.MyObject:TypeValue()
|
|
Tercio@11
|
648 end
|
|
Tercio@11
|
649 end
|
|
Tercio@11
|
650
|
|
Tercio@11
|
651 local OnMouseUp = function (slider, button)
|
|
Tercio@11
|
652 --if (button == "RightButton") then
|
|
Tercio@11
|
653 -- if (slider.MyObject.typing_value) then
|
|
Tercio@11
|
654 -- slider.MyObject:SetValue (slider.MyObject.previous_value [2])
|
|
Tercio@11
|
655 -- end
|
|
Tercio@11
|
656 --end
|
|
Tercio@11
|
657 end
|
|
Tercio@11
|
658
|
|
Tercio@11
|
659 local OnHide = function (slider)
|
|
Tercio@11
|
660 if (slider.MyObject.OnHideHook) then
|
|
Tercio@11
|
661 local interrupt = slider.MyObject.OnHideHook (slider)
|
|
Tercio@11
|
662 if (interrupt) then
|
|
Tercio@11
|
663 return
|
|
Tercio@11
|
664 end
|
|
Tercio@11
|
665 end
|
|
Tercio@11
|
666
|
|
Tercio@11
|
667 if (slider.MyObject.typing_value) then
|
|
Tercio@11
|
668 SliderMetaFunctions.editbox_typevalue:ClearFocus()
|
|
Tercio@11
|
669 SliderMetaFunctions.editbox_typevalue:SetText ("")
|
|
Tercio@11
|
670 slider.MyObject.typing_valu = false
|
|
Tercio@11
|
671 end
|
|
Tercio@11
|
672 end
|
|
Tercio@11
|
673
|
|
Tercio@11
|
674 local OnShow = function (slider)
|
|
Tercio@11
|
675 if (slider.MyObject.OnShowHook) then
|
|
Tercio@11
|
676 local interrupt = slider.MyObject.OnShowHook (slider)
|
|
Tercio@11
|
677 if (interrupt) then
|
|
Tercio@11
|
678 return
|
|
Tercio@11
|
679 end
|
|
Tercio@11
|
680 end
|
|
Tercio@11
|
681 end
|
|
Tercio@11
|
682
|
|
Tercio@11
|
683 local table_insert = table.insert
|
|
Tercio@11
|
684 local table_remove = table.remove
|
|
Tercio@11
|
685
|
|
Tercio@11
|
686 local OnValueChanged = function (slider)
|
|
Tercio@11
|
687
|
|
Tercio@11
|
688 local amt = slider:GetValue()
|
|
Tercio@11
|
689
|
|
Tercio@11
|
690 if (slider.MyObject.typing_value and not slider.MyObject.typing_can_change) then
|
|
Tercio@11
|
691 slider.MyObject:SetValue (slider.MyObject.typing_value_started)
|
|
Tercio@11
|
692 return
|
|
Tercio@11
|
693 end
|
|
Tercio@11
|
694
|
|
Tercio@11
|
695 table_insert (slider.MyObject.previous_value, 1, amt)
|
|
Tercio@11
|
696 table_remove (slider.MyObject.previous_value, 4)
|
|
Tercio@11
|
697
|
|
Tercio@11
|
698 if (slider.MyObject.OnValueChangeHook) then
|
|
Tercio@11
|
699 local interrupt = slider.MyObject.OnValueChangeHook (slider, slider.MyObject.FixedValue, amt)
|
|
Tercio@11
|
700 if (interrupt) then
|
|
Tercio@11
|
701 return
|
|
Tercio@11
|
702 end
|
|
Tercio@11
|
703 end
|
|
Tercio@11
|
704
|
|
Tercio@11
|
705 if (slider.MyObject.OnValueChanged) then
|
|
Tercio@11
|
706 slider.MyObject.OnValueChanged (slider, slider.MyObject.FixedValue, amt)
|
|
Tercio@11
|
707 end
|
|
Tercio@11
|
708
|
|
Tercio@11
|
709 if (amt < 10 and amt >= 1) then
|
|
Tercio@11
|
710 amt = "0"..amt
|
|
Tercio@11
|
711 end
|
|
Tercio@11
|
712
|
|
Tercio@11
|
713 if (slider.MyObject.useDecimals) then
|
|
Tercio@11
|
714 slider.amt:SetText (string.format ("%.2f", amt))
|
|
Tercio@11
|
715 else
|
|
Tercio@11
|
716 slider.amt:SetText (math.floor (amt))
|
|
Tercio@11
|
717 end
|
|
Tercio@11
|
718 slider.MyObject.ivalue = amt
|
|
Tercio@11
|
719 end
|
|
Tercio@11
|
720
|
|
Tercio@11
|
721 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
722 --> object constructor
|
|
Tercio@11
|
723
|
|
Tercio@11
|
724 local SwitchOnClick = function (self, button, forced_value, value)
|
|
Tercio@11
|
725
|
|
Tercio@11
|
726 local slider = self.MyObject
|
|
Tercio@11
|
727
|
|
Tercio@11
|
728 if (_rawget (slider, "lockdown")) then
|
|
Tercio@11
|
729 return
|
|
Tercio@11
|
730 end
|
|
Tercio@11
|
731
|
|
Tercio@11
|
732 if (forced_value) then
|
|
Tercio@11
|
733 _rawset (slider, "value", not value)
|
|
Tercio@11
|
734 end
|
|
Tercio@11
|
735
|
|
Tercio@11
|
736 if (_rawget (slider, "value")) then --actived
|
|
Tercio@11
|
737
|
|
Tercio@11
|
738 _rawset (slider, "value", false)
|
|
Tercio@11
|
739 slider._text:SetText (slider._ltext)
|
|
Tercio@11
|
740 slider._thumb:ClearAllPoints()
|
|
Tercio@11
|
741
|
|
Tercio@11
|
742 slider:SetBackdropColor (1, 0, 0, 0.4)
|
|
Tercio@11
|
743 slider._thumb:SetPoint ("left", slider.widget, "left")
|
|
Tercio@11
|
744
|
|
Tercio@11
|
745 else
|
|
Tercio@11
|
746
|
|
Tercio@11
|
747 _rawset (slider, "value", true)
|
|
Tercio@11
|
748 slider._text:SetText (slider._rtext)
|
|
Tercio@11
|
749 slider._thumb:ClearAllPoints()
|
|
Tercio@11
|
750
|
|
Tercio@11
|
751 slider:SetBackdropColor (0, 0, 1, 0.4)
|
|
Tercio@11
|
752 slider._thumb:SetPoint ("right", slider.widget, "right")
|
|
Tercio@11
|
753
|
|
Tercio@11
|
754 end
|
|
Tercio@11
|
755
|
|
Tercio@11
|
756 if (slider.OnSwitch and not forced_value) then
|
|
Tercio@11
|
757 local value = _rawget (slider, "value")
|
|
Tercio@11
|
758 if (slider.return_func) then
|
|
Tercio@11
|
759 value = slider:return_func (value)
|
|
Tercio@11
|
760 end
|
|
Tercio@11
|
761 slider.OnSwitch (slider, slider.FixedValue, value)
|
|
Tercio@11
|
762 end
|
|
Tercio@11
|
763
|
|
Tercio@11
|
764 end
|
|
Tercio@11
|
765
|
|
Tercio@11
|
766 local default_switch_func = function (self, passed_value)
|
|
Tercio@11
|
767 if (self.value) then
|
|
Tercio@11
|
768 return false
|
|
Tercio@11
|
769 else
|
|
Tercio@11
|
770 return true
|
|
Tercio@11
|
771 end
|
|
Tercio@11
|
772 end
|
|
Tercio@11
|
773
|
|
Tercio@11
|
774 local switch_get_value = function (self)
|
|
Tercio@11
|
775 return self.value
|
|
Tercio@11
|
776 end
|
|
Tercio@11
|
777
|
|
Tercio@11
|
778 local switch_set_value = function (self, value)
|
|
Tercio@11
|
779 if (self.switch_func) then
|
|
Tercio@11
|
780 value = self:switch_func (value)
|
|
Tercio@11
|
781 end
|
|
Tercio@11
|
782
|
|
Tercio@11
|
783 SwitchOnClick (self.widget, nil, true, value)
|
|
Tercio@11
|
784 end
|
|
Tercio@11
|
785
|
|
Tercio@11
|
786 local switch_set_fixparameter = function (self, value)
|
|
Tercio@11
|
787 _rawset (self, "FixedValue", value)
|
|
Tercio@11
|
788 end
|
|
Tercio@11
|
789
|
|
Tercio@11
|
790 local switch_disable = function (self)
|
|
Tercio@11
|
791 if (not self.lock_texture) then
|
|
Tercio@11
|
792 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
|
|
Tercio@11
|
793 self.lock_texture:SetDesaturated (true)
|
|
Tercio@11
|
794 self.lock_texture:SetPoint ("center", self._thumb, "center")
|
|
Tercio@11
|
795 end
|
|
Tercio@11
|
796
|
|
Tercio@11
|
797 self.lock_texture:Show()
|
|
Tercio@11
|
798 self._text:Hide()
|
|
Tercio@11
|
799 self:SetAlpha (.4)
|
|
Tercio@11
|
800 _rawset (self, "lockdown", true)
|
|
Tercio@11
|
801 end
|
|
Tercio@11
|
802 local switch_enable = function (self)
|
|
Tercio@11
|
803 if (not self.lock_texture) then
|
|
Tercio@11
|
804 DF:NewImage (self, [[Interface\PetBattles\PetBattle-LockIcon]], 12, 12, "overlay", {0.0546875, 0.9453125, 0.0703125, 0.9453125}, "lock_texture", "$parentLockTexture")
|
|
Tercio@11
|
805 self.lock_texture:SetDesaturated (true)
|
|
Tercio@11
|
806 self.lock_texture:SetPoint ("center", self._thumb, "center")
|
|
Tercio@11
|
807 end
|
|
Tercio@11
|
808
|
|
Tercio@11
|
809 self.lock_texture:Hide()
|
|
Tercio@11
|
810 self._text:Show()
|
|
Tercio@11
|
811 self:SetAlpha (1)
|
|
Tercio@11
|
812 return _rawset (self, "lockdown", false)
|
|
Tercio@11
|
813 end
|
|
Tercio@11
|
814
|
|
Tercio@11
|
815 function DF:CreateSwitch (parent, on_switch, default_value, w, h, ltext, rtext, member, name, color_inverted, switch_func, return_func, with_label)
|
|
Tercio@11
|
816 local switch, label = DF:NewSwitch (parent, parent, name, member, w or 60, h or 20, ltext, rtext, default_value, color_inverted, switch_func, return_func, with_label)
|
|
Tercio@11
|
817 if (on_switch) then
|
|
Tercio@11
|
818 switch.OnSwitch = on_switch
|
|
Tercio@11
|
819 end
|
|
Tercio@11
|
820 return switch, label
|
|
Tercio@11
|
821 end
|
|
Tercio@11
|
822
|
|
Tercio@11
|
823 function DF:NewSwitch (parent, container, name, member, w, h, ltext, rtext, default_value, color_inverted, switch_func, return_func, with_label)
|
|
Tercio@11
|
824
|
|
Tercio@11
|
825 --> early checks
|
|
Tercio@11
|
826 if (not name) then
|
|
Tercio@11
|
827 name = "DetailsFrameWorkSlider" .. NameLessSlider
|
|
Tercio@11
|
828 NameLessSlider = NameLessSlider + 1
|
|
Tercio@11
|
829 elseif (not parent) then
|
|
Tercio@11
|
830 return nil
|
|
Tercio@11
|
831 end
|
|
Tercio@11
|
832 if (not container) then
|
|
Tercio@11
|
833 container = parent
|
|
Tercio@11
|
834 end
|
|
Tercio@11
|
835
|
|
Tercio@11
|
836 --> defaults
|
|
Tercio@11
|
837 ltext = ltext or "OFF"
|
|
Tercio@11
|
838 rtext = rtext or "ON"
|
|
Tercio@11
|
839
|
|
Tercio@11
|
840 --> build frames
|
|
Tercio@11
|
841
|
|
Tercio@11
|
842 w = w or 60
|
|
Tercio@11
|
843 h = h or 20
|
|
Tercio@11
|
844
|
|
Tercio@11
|
845 local slider = DF:NewButton (parent, container, name, member, w, h)
|
|
Tercio@11
|
846
|
|
Tercio@11
|
847 slider.switch_func = switch_func
|
|
Tercio@11
|
848 slider.return_func = return_func
|
|
Tercio@11
|
849 slider.SetValue = switch_set_value
|
|
Tercio@11
|
850 slider.GetValue = switch_get_value
|
|
Tercio@11
|
851 slider.SetFixedParameter = switch_set_fixparameter
|
|
Tercio@11
|
852 slider.Disable = switch_disable
|
|
Tercio@11
|
853 slider.Enable = switch_enable
|
|
Tercio@11
|
854
|
|
Tercio@11
|
855 if (member) then
|
|
Tercio@11
|
856 parent [member] = slider
|
|
Tercio@11
|
857 end
|
|
Tercio@11
|
858
|
|
Tercio@11
|
859 slider:SetBackdrop ({edgeFile = [[Interface\Buttons\UI-SliderBar-Border]], edgeSize = 8,
|
|
Tercio@11
|
860 bgFile = [[Interface\AddOns\Details\images\background]], insets = {left = 3, right = 3, top = 5, bottom = 5}})
|
|
Tercio@11
|
861
|
|
Tercio@11
|
862 local thumb = slider:CreateTexture (nil, "artwork")
|
|
Tercio@11
|
863 thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob")
|
|
Tercio@11
|
864 thumb:SetSize (34+(h*0.2), h*1.2)
|
|
Tercio@11
|
865 thumb:SetAlpha (0.7)
|
|
Tercio@11
|
866 thumb:SetPoint ("left", slider.widget, "left")
|
|
Tercio@11
|
867
|
|
Tercio@11
|
868 local text = slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
|
|
Tercio@11
|
869 text:SetTextColor (.8, .8, .8, 1)
|
|
Tercio@11
|
870 text:SetPoint ("center", thumb, "center")
|
|
Tercio@11
|
871
|
|
Tercio@11
|
872 slider._text = text
|
|
Tercio@11
|
873 slider._thumb = thumb
|
|
Tercio@11
|
874 slider._ltext = ltext
|
|
Tercio@11
|
875 slider._rtext = rtext
|
|
Tercio@11
|
876 slider.thumb = thumb
|
|
Tercio@11
|
877
|
|
Tercio@11
|
878 slider.invert_colors = color_inverted
|
|
Tercio@11
|
879
|
|
Tercio@11
|
880 slider:SetScript ("OnClick", SwitchOnClick)
|
|
Tercio@11
|
881
|
|
Tercio@11
|
882 slider:SetValue (default_value)
|
|
Tercio@11
|
883
|
|
Tercio@11
|
884 slider.isSwitch = true
|
|
Tercio@11
|
885
|
|
Tercio@11
|
886 if (with_label) then
|
|
Tercio@11
|
887 local label = DF:CreateLabel (slider.widget, with_label, nil, nil, nil, "label", nil, "overlay")
|
|
Tercio@11
|
888 label.text = with_label
|
|
Tercio@11
|
889 slider.widget:SetPoint ("left", label.widget, "right", 2, 0)
|
|
Tercio@11
|
890 with_label = label
|
|
Tercio@11
|
891 end
|
|
Tercio@11
|
892
|
|
Tercio@11
|
893 return slider, with_label
|
|
Tercio@11
|
894 end
|
|
Tercio@11
|
895
|
|
Tercio@11
|
896 function DF:CreateSlider (parent, w, h, min, max, step, defaultv, isDecemal, member, name, with_label)
|
|
Tercio@11
|
897 local slider, label = DF:NewSlider (parent, parent, name, member, w, h, min, max, step, defaultv, isDecemal, false, with_label)
|
|
Tercio@11
|
898 return slider, label
|
|
Tercio@11
|
899 end
|
|
Tercio@11
|
900
|
|
Tercio@11
|
901 function DF:NewSlider (parent, container, name, member, w, h, min, max, step, defaultv, isDecemal, isSwitch, with_label)
|
|
Tercio@11
|
902
|
|
Tercio@11
|
903 --> early checks
|
|
Tercio@11
|
904 if (not name) then
|
|
Tercio@11
|
905 name = "DetailsFrameworkSlider" .. DF.SliderCounter
|
|
Tercio@11
|
906 DF.SliderCounter = DF.SliderCounter + 1
|
|
Tercio@11
|
907 end
|
|
Tercio@11
|
908 if (not parent) then
|
|
Tercio@11
|
909 return nil
|
|
Tercio@11
|
910 end
|
|
Tercio@11
|
911 if (not container) then
|
|
Tercio@11
|
912 container = parent
|
|
Tercio@11
|
913 end
|
|
Tercio@11
|
914
|
|
Tercio@11
|
915 if (name:find ("$parent")) then
|
|
Tercio@11
|
916 name = name:gsub ("$parent", parent:GetName())
|
|
Tercio@11
|
917 end
|
|
Tercio@11
|
918
|
|
Tercio@11
|
919 local SliderObject = {type = "slider", dframework = true}
|
|
Tercio@11
|
920
|
|
Tercio@11
|
921 if (member) then
|
|
Tercio@11
|
922 parent [member] = SliderObject
|
|
Tercio@11
|
923 end
|
|
Tercio@11
|
924
|
|
Tercio@11
|
925 if (parent.dframework) then
|
|
Tercio@11
|
926 parent = parent.widget
|
|
Tercio@11
|
927 end
|
|
Tercio@11
|
928 if (container.dframework) then
|
|
Tercio@11
|
929 container = container.widget
|
|
Tercio@11
|
930 end
|
|
Tercio@11
|
931
|
|
Tercio@11
|
932 --> defaults
|
|
Tercio@11
|
933 min = min or 1
|
|
Tercio@11
|
934 max = max or 2
|
|
Tercio@11
|
935 step = step or 1
|
|
Tercio@11
|
936 defaultv = defaultv or min
|
|
Tercio@11
|
937
|
|
Tercio@11
|
938 w = w or 130
|
|
Tercio@11
|
939 h = h or 19
|
|
Tercio@11
|
940
|
|
Tercio@11
|
941 --> default members:
|
|
Tercio@11
|
942 --> hooks
|
|
Tercio@11
|
943 SliderObject.OnEnterHook = nil
|
|
Tercio@11
|
944 SliderObject.OnLeaveHook = nil
|
|
Tercio@11
|
945 SliderObject.OnHideHook = nil
|
|
Tercio@11
|
946 SliderObject.OnShowHook = nil
|
|
Tercio@11
|
947 SliderObject.OnValueChangeHook = nil
|
|
Tercio@11
|
948 --> misc
|
|
Tercio@11
|
949 SliderObject.lockdown = false
|
|
Tercio@11
|
950 SliderObject.container = container
|
|
Tercio@11
|
951 SliderObject.have_tooltip = nil
|
|
Tercio@11
|
952 SliderObject.FixedValue = nil
|
|
Tercio@11
|
953 SliderObject.useDecimals = isDecemal or false
|
|
Tercio@11
|
954
|
|
Tercio@11
|
955 SliderObject.slider = CreateFrame ("slider", name, parent)
|
|
Tercio@11
|
956 SliderObject.widget = SliderObject.slider
|
|
Tercio@11
|
957
|
|
Tercio@11
|
958 if (not APISliderFunctions) then
|
|
Tercio@11
|
959 APISliderFunctions = true
|
|
Tercio@11
|
960 local idx = getmetatable (SliderObject.slider).__index
|
|
Tercio@11
|
961 for funcName, funcAddress in pairs (idx) do
|
|
Tercio@11
|
962 if (not SliderMetaFunctions [funcName]) then
|
|
Tercio@11
|
963 SliderMetaFunctions [funcName] = function (object, ...)
|
|
Tercio@11
|
964 local x = loadstring ( "return _G."..object.slider:GetName()..":"..funcName.."(...)")
|
|
Tercio@11
|
965 return x (...)
|
|
Tercio@11
|
966 end
|
|
Tercio@11
|
967 end
|
|
Tercio@11
|
968 end
|
|
Tercio@11
|
969 end
|
|
Tercio@11
|
970
|
|
Tercio@11
|
971 SliderObject.slider.MyObject = SliderObject
|
|
Tercio@11
|
972 SliderObject.slider:SetWidth (w)
|
|
Tercio@11
|
973 SliderObject.slider:SetHeight (h)
|
|
Tercio@11
|
974 SliderObject.slider:SetOrientation ("horizontal")
|
|
Tercio@11
|
975 SliderObject.slider:SetMinMaxValues (min, max)
|
|
Tercio@11
|
976 SliderObject.slider:SetValueStep (step)
|
|
Tercio@11
|
977 SliderObject.slider:SetValue (defaultv)
|
|
Tercio@11
|
978 SliderObject.ivalue = defaultv
|
|
Tercio@11
|
979
|
|
Tercio@11
|
980 SliderObject.slider:SetBackdrop ({edgeFile = "Interface\\Buttons\\UI-SliderBar-Border", edgeSize = 8})
|
|
Tercio@11
|
981 SliderObject.slider:SetBackdropColor (0.9, 0.7, 0.7, 1.0)
|
|
Tercio@11
|
982
|
|
Tercio@11
|
983 SliderObject.thumb = SliderObject.slider:CreateTexture (nil, "artwork")
|
|
Tercio@11
|
984 SliderObject.thumb:SetTexture ("Interface\\Buttons\\UI-ScrollBar-Knob")
|
|
Tercio@11
|
985 SliderObject.thumb:SetSize (30+(h*0.2), h*1.2)
|
|
Tercio@11
|
986 SliderObject.thumb:SetAlpha (0.7)
|
|
Tercio@11
|
987 SliderObject.slider:SetThumbTexture (SliderObject.thumb)
|
|
Tercio@11
|
988 SliderObject.slider.thumb = SliderObject.thumb
|
|
Tercio@11
|
989
|
|
Tercio@11
|
990 if (not isSwitch) then
|
|
Tercio@11
|
991 SliderObject.have_tooltip = "Right Click to Type the Value"
|
|
Tercio@11
|
992 end
|
|
Tercio@11
|
993
|
|
Tercio@11
|
994 SliderObject.amt = SliderObject.slider:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
|
|
Tercio@11
|
995
|
|
Tercio@11
|
996 local amt = defaultv
|
|
Tercio@11
|
997 if (amt < 10 and amt >= 1) then
|
|
Tercio@11
|
998 amt = "0"..amt
|
|
Tercio@11
|
999 end
|
|
Tercio@11
|
1000
|
|
Tercio@11
|
1001 if (SliderObject.useDecimals) then
|
|
Tercio@11
|
1002 SliderObject.amt:SetText (string.format ("%.2f", amt))
|
|
Tercio@11
|
1003 else
|
|
Tercio@11
|
1004 SliderObject.amt:SetText (math.floor (amt))
|
|
Tercio@11
|
1005 end
|
|
Tercio@11
|
1006
|
|
Tercio@11
|
1007 SliderObject.amt:SetTextColor (.8, .8, .8, 1)
|
|
Tercio@11
|
1008 SliderObject.amt:SetPoint ("center", SliderObject.thumb, "center")
|
|
Tercio@11
|
1009 SliderObject.slider.amt = SliderObject.amt
|
|
Tercio@11
|
1010
|
|
Tercio@11
|
1011 SliderObject.previous_value = {defaultv or 0, 0, 0}
|
|
Tercio@11
|
1012
|
|
Tercio@11
|
1013 --> hooks
|
|
Tercio@11
|
1014 SliderObject.slider:SetScript ("OnEnter", OnEnter)
|
|
Tercio@11
|
1015 SliderObject.slider:SetScript ("OnLeave", OnLeave)
|
|
Tercio@11
|
1016 SliderObject.slider:SetScript ("OnHide", OnHide)
|
|
Tercio@11
|
1017 SliderObject.slider:SetScript ("OnShow", OnShow)
|
|
Tercio@11
|
1018 SliderObject.slider:SetScript ("OnValueChanged", OnValueChanged)
|
|
Tercio@11
|
1019 SliderObject.slider:SetScript ("OnMouseDown", OnMouseDown)
|
|
Tercio@11
|
1020 SliderObject.slider:SetScript ("OnMouseUp", OnMouseUp)
|
|
Tercio@11
|
1021
|
|
Tercio@11
|
1022
|
|
Tercio@11
|
1023 _setmetatable (SliderObject, SliderMetaFunctions)
|
|
Tercio@11
|
1024
|
|
Tercio@11
|
1025 if (with_label) then
|
|
Tercio@11
|
1026 local label = DF:CreateLabel (SliderObject.slider, with_label, nil, nil, nil, "label", nil, "overlay")
|
|
Tercio@11
|
1027 label.text = with_label
|
|
Tercio@11
|
1028 SliderObject.slider:SetPoint ("left", label.widget, "right", 2, 0)
|
|
Tercio@11
|
1029 with_label = label
|
|
Tercio@11
|
1030 end
|
|
Tercio@11
|
1031
|
|
Tercio@11
|
1032 return SliderObject, with_label
|
|
Tercio@11
|
1033
|
|
Tercio@11
|
1034 end |