|
Tercio@11
|
1
|
|
Tercio@11
|
2 local DF = _G ["DetailsFramework"]
|
|
Tercio@20
|
3 if (not DF or not DetailsFrameworkCanLoad) then
|
|
Tercio@20
|
4 return
|
|
Tercio@20
|
5 end
|
|
Tercio@20
|
6
|
|
Tercio@11
|
7 local _
|
|
Tercio@11
|
8 local _rawset = rawset --> lua local
|
|
Tercio@11
|
9 local _rawget = rawget --> lua local
|
|
Tercio@11
|
10 local _setmetatable = setmetatable --> lua local
|
|
Tercio@11
|
11 local _unpack = unpack --> lua local
|
|
Tercio@11
|
12 local _type = type --> lua local
|
|
Tercio@11
|
13 local _math_floor = math.floor --> lua local
|
|
Tercio@11
|
14 local loadstring = loadstring --> lua local
|
|
Tercio@11
|
15 local _string_len = string.len --> lua local
|
|
Tercio@11
|
16
|
|
Tercio@11
|
17 local cleanfunction = function() end
|
|
Tercio@11
|
18 local APITextEntryFunctions = false
|
|
Tercio@11
|
19 local TextEntryMetaFunctions = {}
|
|
Tercio@11
|
20
|
|
Tercio@11
|
21 DF.TextEntryCounter = 1
|
|
Tercio@11
|
22
|
|
Tercio@11
|
23 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
24 --> metatables
|
|
Tercio@11
|
25
|
|
Tercio@11
|
26 TextEntryMetaFunctions.__call = function (_table, value)
|
|
Tercio@11
|
27 --> unknow
|
|
Tercio@11
|
28 end
|
|
Tercio@11
|
29
|
|
Tercio@11
|
30 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
31 --> members
|
|
Tercio@11
|
32
|
|
Tercio@11
|
33 --> tooltip
|
|
Tercio@11
|
34 local gmember_tooltip = function (_object)
|
|
Tercio@11
|
35 return _object:GetTooltip()
|
|
Tercio@11
|
36 end
|
|
Tercio@11
|
37 --> shown
|
|
Tercio@11
|
38 local gmember_shown = function (_object)
|
|
Tercio@11
|
39 return _object:IsShown()
|
|
Tercio@11
|
40 end
|
|
Tercio@11
|
41 --> frame width
|
|
Tercio@11
|
42 local gmember_width = function (_object)
|
|
Tercio@11
|
43 return _object.editbox:GetWidth()
|
|
Tercio@11
|
44 end
|
|
Tercio@11
|
45 --> frame height
|
|
Tercio@11
|
46 local gmember_height = function (_object)
|
|
Tercio@11
|
47 return _object.editbox:GetHeight()
|
|
Tercio@11
|
48 end
|
|
Tercio@11
|
49 --> get text
|
|
Tercio@11
|
50 local gmember_text = function (_object)
|
|
Tercio@11
|
51 return _object.editbox:GetText()
|
|
Tercio@11
|
52 end
|
|
Tercio@11
|
53
|
|
Tercio@11
|
54 local get_members_function_index = {
|
|
Tercio@11
|
55 ["tooltip"] = gmember_tooltip,
|
|
Tercio@11
|
56 ["shown"] = gmember_shown,
|
|
Tercio@11
|
57 ["width"] = gmember_width,
|
|
Tercio@11
|
58 ["height"] = gmember_height,
|
|
Tercio@11
|
59 ["text"] = gmember_text,
|
|
Tercio@11
|
60 }
|
|
Tercio@11
|
61
|
|
Tercio@11
|
62 TextEntryMetaFunctions.__index = function (_table, _member_requested)
|
|
Tercio@11
|
63
|
|
Tercio@11
|
64 local func = get_members_function_index [_member_requested]
|
|
Tercio@11
|
65 if (func) then
|
|
Tercio@11
|
66 return func (_table, _member_requested)
|
|
Tercio@11
|
67 end
|
|
Tercio@11
|
68
|
|
Tercio@11
|
69 local fromMe = _rawget (_table, _member_requested)
|
|
Tercio@11
|
70 if (fromMe) then
|
|
Tercio@11
|
71 return fromMe
|
|
Tercio@11
|
72 end
|
|
Tercio@11
|
73
|
|
Tercio@11
|
74 return TextEntryMetaFunctions [_member_requested]
|
|
Tercio@11
|
75 end
|
|
Tercio@11
|
76
|
|
Tercio@11
|
77 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
78
|
|
Tercio@11
|
79 --> tooltip
|
|
Tercio@11
|
80 local smember_tooltip = function (_object, _value)
|
|
Tercio@11
|
81 return _object:SetTooltip (_value)
|
|
Tercio@11
|
82 end
|
|
Tercio@11
|
83 --> show
|
|
Tercio@11
|
84 local smember_show = function (_object, _value)
|
|
Tercio@11
|
85 if (_value) then
|
|
Tercio@11
|
86 return _object:Show()
|
|
Tercio@11
|
87 else
|
|
Tercio@11
|
88 return _object:Hide()
|
|
Tercio@11
|
89 end
|
|
Tercio@11
|
90 end
|
|
Tercio@11
|
91 --> hide
|
|
Tercio@11
|
92 local smember_hide = function (_object, _value)
|
|
Tercio@11
|
93 if (not _value) then
|
|
Tercio@11
|
94 return _object:Show()
|
|
Tercio@11
|
95 else
|
|
Tercio@11
|
96 return _object:Hide()
|
|
Tercio@11
|
97 end
|
|
Tercio@11
|
98 end
|
|
Tercio@11
|
99 --> frame width
|
|
Tercio@11
|
100 local smember_width = function (_object, _value)
|
|
Tercio@11
|
101 return _object.editbox:SetWidth (_value)
|
|
Tercio@11
|
102 end
|
|
Tercio@11
|
103 --> frame height
|
|
Tercio@11
|
104 local smember_height = function (_object, _value)
|
|
Tercio@11
|
105 return _object.editbox:SetHeight (_value)
|
|
Tercio@11
|
106 end
|
|
Tercio@11
|
107 --> set text
|
|
Tercio@11
|
108 local smember_text = function (_object, _value)
|
|
Tercio@11
|
109 return _object.editbox:SetText (_value)
|
|
Tercio@11
|
110 end
|
|
Tercio@11
|
111 --> set multiline
|
|
Tercio@11
|
112 local smember_multiline = function (_object, _value)
|
|
Tercio@11
|
113 if (_value) then
|
|
Tercio@11
|
114 return _object.editbox:SetMultiLine (true)
|
|
Tercio@11
|
115 else
|
|
Tercio@11
|
116 return _object.editbox:SetMultiLine (false)
|
|
Tercio@11
|
117 end
|
|
Tercio@11
|
118 end
|
|
Tercio@11
|
119 --> text horizontal pos
|
|
Tercio@11
|
120 local smember_horizontalpos = function (_object, _value)
|
|
Tercio@11
|
121 return _object.editbox:SetJustifyH (string.lower (_value))
|
|
Tercio@11
|
122 end
|
|
Tercio@11
|
123
|
|
Tercio@11
|
124 local set_members_function_index = {
|
|
Tercio@11
|
125 ["tooltip"] = smember_tooltip,
|
|
Tercio@11
|
126 ["show"] = smember_show,
|
|
Tercio@11
|
127 ["hide"] = smember_hide,
|
|
Tercio@11
|
128 ["width"] = smember_width,
|
|
Tercio@11
|
129 ["height"] = smember_height,
|
|
Tercio@11
|
130 ["text"] = smember_text,
|
|
Tercio@11
|
131 ["multiline"] = smember_multiline,
|
|
Tercio@11
|
132 ["align"] = smember_horizontalpos,
|
|
Tercio@11
|
133 }
|
|
Tercio@11
|
134
|
|
Tercio@11
|
135 TextEntryMetaFunctions.__newindex = function (_table, _key, _value)
|
|
Tercio@11
|
136 local func = set_members_function_index [_key]
|
|
Tercio@11
|
137 if (func) then
|
|
Tercio@11
|
138 return func (_table, _value)
|
|
Tercio@11
|
139 else
|
|
Tercio@11
|
140 return _rawset (_table, _key, _value)
|
|
Tercio@11
|
141 end
|
|
Tercio@11
|
142 end
|
|
Tercio@11
|
143
|
|
Tercio@11
|
144 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
145 --> methods
|
|
Tercio@11
|
146
|
|
Tercio@11
|
147 --> set point
|
|
Tercio@11
|
148 function TextEntryMetaFunctions:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y, Width)
|
|
Tercio@11
|
149
|
|
Tercio@11
|
150 if (type (MyAnchor) == "boolean" and MyAnchor and self.space) then
|
|
Tercio@11
|
151 local textWidth = self.label:GetStringWidth()+2
|
|
Tercio@11
|
152 self.editbox:SetWidth (self.space - textWidth - 15)
|
|
Tercio@11
|
153 return
|
|
Tercio@11
|
154
|
|
Tercio@11
|
155 elseif (type (MyAnchor) == "boolean" and MyAnchor and not self.space) then
|
|
Tercio@11
|
156 self.space = self.label:GetStringWidth()+2 + self.editbox:GetWidth()
|
|
Tercio@11
|
157 end
|
|
Tercio@11
|
158
|
|
Tercio@11
|
159 if (Width) then
|
|
Tercio@11
|
160 self.space = Width
|
|
Tercio@11
|
161 end
|
|
Tercio@11
|
162
|
|
Tercio@11
|
163 MyAnchor, SnapTo, HisAnchor, x, y = DF:CheckPoints (MyAnchor, SnapTo, HisAnchor, x, y, self)
|
|
Tercio@11
|
164 if (not MyAnchor) then
|
|
Tercio@11
|
165 print ("Invalid parameter for SetPoint")
|
|
Tercio@11
|
166 return
|
|
Tercio@11
|
167 end
|
|
Tercio@11
|
168
|
|
Tercio@11
|
169 if (self.space) then
|
|
Tercio@11
|
170 self.label:ClearAllPoints()
|
|
Tercio@11
|
171 self.editbox:ClearAllPoints()
|
|
Tercio@11
|
172
|
|
Tercio@11
|
173 self.label:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y)
|
|
Tercio@11
|
174 self.editbox:SetPoint ("left", self.label, "right", 2, 0)
|
|
Tercio@11
|
175
|
|
Tercio@11
|
176 local textWidth = self.label:GetStringWidth()+2
|
|
Tercio@11
|
177 self.editbox:SetWidth (self.space - textWidth - 15)
|
|
Tercio@11
|
178 else
|
|
Tercio@11
|
179 self.label:ClearAllPoints()
|
|
Tercio@11
|
180 self.editbox:ClearAllPoints()
|
|
Tercio@11
|
181 self.editbox:SetPoint (MyAnchor, SnapTo, HisAnchor, x, y)
|
|
Tercio@11
|
182 end
|
|
Tercio@11
|
183
|
|
Tercio@11
|
184 end
|
|
Tercio@11
|
185
|
|
Tercio@11
|
186 --> frame levels
|
|
Tercio@11
|
187 function TextEntryMetaFunctions:GetFrameLevel()
|
|
Tercio@11
|
188 return self.editbox:GetFrameLevel()
|
|
Tercio@11
|
189 end
|
|
Tercio@11
|
190 function TextEntryMetaFunctions:SetFrameLevel (level, frame)
|
|
Tercio@11
|
191 if (not frame) then
|
|
Tercio@11
|
192 return self.editbox:SetFrameLevel (level)
|
|
Tercio@11
|
193 else
|
|
Tercio@11
|
194 local framelevel = frame:GetFrameLevel (frame) + level
|
|
Tercio@11
|
195 return self.editbox:SetFrameLevel (framelevel)
|
|
Tercio@11
|
196 end
|
|
Tercio@11
|
197 end
|
|
Tercio@11
|
198
|
|
Tercio@11
|
199 --> select all text
|
|
Tercio@11
|
200 function TextEntryMetaFunctions:SelectAll()
|
|
Tercio@11
|
201 self.editbox:HighlightText()
|
|
Tercio@11
|
202 end
|
|
Tercio@11
|
203
|
|
Tercio@11
|
204 --> set labal description
|
|
Tercio@11
|
205 function TextEntryMetaFunctions:SetLabelText (text)
|
|
Tercio@11
|
206 if (text) then
|
|
Tercio@11
|
207 self.label:SetText (text)
|
|
Tercio@11
|
208 else
|
|
Tercio@11
|
209 self.label:SetText ("")
|
|
Tercio@11
|
210 end
|
|
Tercio@11
|
211 self:SetPoint (true) --> refresh
|
|
Tercio@11
|
212 end
|
|
Tercio@11
|
213
|
|
Tercio@11
|
214 --> set tab order
|
|
Tercio@11
|
215 function TextEntryMetaFunctions:SetNext (nextbox)
|
|
Tercio@11
|
216 self.next = nextbox
|
|
Tercio@11
|
217 end
|
|
Tercio@11
|
218
|
|
Tercio@11
|
219 --> blink
|
|
Tercio@11
|
220 function TextEntryMetaFunctions:Blink()
|
|
Tercio@11
|
221 self.label:SetTextColor (1, .2, .2, 1)
|
|
Tercio@11
|
222 end
|
|
Tercio@11
|
223
|
|
Tercio@11
|
224 --> show & hide
|
|
Tercio@11
|
225 function TextEntryMetaFunctions:IsShown()
|
|
Tercio@11
|
226 return self.editbox:IsShown()
|
|
Tercio@11
|
227 end
|
|
Tercio@11
|
228 function TextEntryMetaFunctions:Show()
|
|
Tercio@11
|
229 return self.editbox:Show()
|
|
Tercio@11
|
230 end
|
|
Tercio@11
|
231 function TextEntryMetaFunctions:Hide()
|
|
Tercio@11
|
232 return self.editbox:Hide()
|
|
Tercio@11
|
233 end
|
|
Tercio@11
|
234
|
|
Tercio@11
|
235 -- tooltip
|
|
Tercio@11
|
236 function TextEntryMetaFunctions:SetTooltip (tooltip)
|
|
Tercio@11
|
237 if (tooltip) then
|
|
Tercio@11
|
238 return _rawset (self, "have_tooltip", tooltip)
|
|
Tercio@11
|
239 else
|
|
Tercio@11
|
240 return _rawset (self, "have_tooltip", nil)
|
|
Tercio@11
|
241 end
|
|
Tercio@11
|
242 end
|
|
Tercio@11
|
243 function TextEntryMetaFunctions:GetTooltip()
|
|
Tercio@11
|
244 return _rawget (self, "have_tooltip")
|
|
Tercio@11
|
245 end
|
|
Tercio@11
|
246
|
|
Tercio@11
|
247 --> hooks
|
|
Tercio@11
|
248 function TextEntryMetaFunctions:SetHook (hookType, func)
|
|
Tercio@11
|
249 if (func) then
|
|
Tercio@11
|
250 _rawset (self, hookType.."Hook", func)
|
|
Tercio@11
|
251 else
|
|
Tercio@11
|
252 _rawset (self, hookType.."Hook", nil)
|
|
Tercio@11
|
253 end
|
|
Tercio@11
|
254 end
|
|
Tercio@11
|
255
|
|
Tercio@11
|
256 function TextEntryMetaFunctions:Enable()
|
|
Tercio@11
|
257 if (not self.editbox:IsEnabled()) then
|
|
Tercio@11
|
258 self.editbox:Enable()
|
|
Tercio@11
|
259 self.editbox:SetBackdropBorderColor (unpack (self.enabled_border_color))
|
|
Tercio@11
|
260 self.editbox:SetBackdropColor (unpack (self.enabled_backdrop_color))
|
|
Tercio@11
|
261 self.editbox:SetTextColor (unpack (self.enabled_text_color))
|
|
Tercio@22
|
262 if (self.editbox.borderframe) then
|
|
Tercio@22
|
263 self.editbox.borderframe:SetBackdropColor (unpack (self.editbox.borderframe.onleave_backdrop))
|
|
Tercio@22
|
264 end
|
|
Tercio@11
|
265 end
|
|
Tercio@11
|
266 end
|
|
Tercio@11
|
267
|
|
Tercio@11
|
268 function TextEntryMetaFunctions:Disable()
|
|
Tercio@11
|
269 if (self.editbox:IsEnabled()) then
|
|
Tercio@11
|
270 self.enabled_border_color = {self.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
271 self.enabled_backdrop_color = {self.editbox:GetBackdropColor()}
|
|
Tercio@11
|
272 self.enabled_text_color = {self.editbox:GetTextColor()}
|
|
Tercio@11
|
273
|
|
Tercio@11
|
274 self.editbox:Disable()
|
|
Tercio@11
|
275
|
|
Tercio@11
|
276 self.editbox:SetBackdropBorderColor (.5, .5, .5, .5)
|
|
Tercio@11
|
277 self.editbox:SetBackdropColor (.5, .5, .5, .5)
|
|
Tercio@11
|
278 self.editbox:SetTextColor (.5, .5, .5, .5)
|
|
Tercio@22
|
279
|
|
Tercio@22
|
280 if (self.editbox.borderframe) then
|
|
Tercio@22
|
281 self.editbox.borderframe:SetBackdropColor (.5, .5, .5, .5)
|
|
Tercio@22
|
282 end
|
|
Tercio@11
|
283 end
|
|
Tercio@11
|
284 end
|
|
Tercio@11
|
285
|
|
Tercio@11
|
286 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
287 --> scripts
|
|
Tercio@11
|
288 local OnEnter = function (textentry)
|
|
Tercio@11
|
289
|
|
Tercio@11
|
290 if (textentry.MyObject.OnEnterHook) then
|
|
Tercio@11
|
291 local interrupt = textentry.MyObject.OnEnterHook (textentry)
|
|
Tercio@11
|
292 if (interrupt) then
|
|
Tercio@11
|
293 return
|
|
Tercio@11
|
294 end
|
|
Tercio@11
|
295 end
|
|
Tercio@11
|
296
|
|
Tercio@11
|
297 if (textentry.MyObject.have_tooltip) then
|
|
Tercio@11
|
298 GameCooltip2:Preset (2)
|
|
Tercio@11
|
299 GameCooltip2:AddLine (textentry.MyObject.have_tooltip)
|
|
Tercio@11
|
300 GameCooltip2:ShowCooltip (textentry, "tooltip")
|
|
Tercio@11
|
301 end
|
|
Tercio@11
|
302
|
|
Tercio@11
|
303 textentry.mouse_over = true
|
|
Tercio@11
|
304
|
|
Tercio@11
|
305 if (textentry:IsEnabled()) then
|
|
Tercio@11
|
306 textentry.current_bordercolor = textentry.current_bordercolor or {textentry:GetBackdropBorderColor()}
|
|
Tercio@11
|
307 textentry:SetBackdropBorderColor (1, 1, 1, 1)
|
|
Tercio@11
|
308 end
|
|
Tercio@11
|
309
|
|
Tercio@11
|
310 end
|
|
Tercio@11
|
311
|
|
Tercio@11
|
312 local OnLeave = function (textentry)
|
|
Tercio@11
|
313 if (textentry.MyObject.OnLeaveHook) then
|
|
Tercio@11
|
314 local interrupt = textentry.MyObject.OnLeaveHook (textentry)
|
|
Tercio@11
|
315 if (interrupt) then
|
|
Tercio@11
|
316 return
|
|
Tercio@11
|
317 end
|
|
Tercio@11
|
318 end
|
|
Tercio@11
|
319
|
|
Tercio@11
|
320 if (textentry.MyObject.have_tooltip) then
|
|
Tercio@11
|
321 GameCooltip2:ShowMe (false)
|
|
Tercio@11
|
322 end
|
|
Tercio@11
|
323
|
|
Tercio@11
|
324 textentry.mouse_over = false
|
|
Tercio@11
|
325
|
|
Tercio@11
|
326 if (textentry:IsEnabled()) then
|
|
Tercio@11
|
327 textentry:SetBackdropBorderColor (unpack (textentry.current_bordercolor))
|
|
Tercio@11
|
328 end
|
|
Tercio@22
|
329
|
|
Tercio@11
|
330 end
|
|
Tercio@11
|
331
|
|
Tercio@11
|
332 local OnHide = function (textentry)
|
|
Tercio@11
|
333 if (textentry.MyObject.OnHideHook) then
|
|
Tercio@11
|
334 local interrupt = textentry.MyObject.OnHideHook (textentry)
|
|
Tercio@11
|
335 if (interrupt) then
|
|
Tercio@11
|
336 return
|
|
Tercio@11
|
337 end
|
|
Tercio@11
|
338 end
|
|
Tercio@11
|
339 end
|
|
Tercio@11
|
340
|
|
Tercio@11
|
341 local OnShow = function (textentry)
|
|
Tercio@11
|
342 if (textentry.MyObject.OnShowHook) then
|
|
Tercio@11
|
343 local interrupt = textentry.MyObject.OnShowHook (textentry)
|
|
Tercio@11
|
344 if (interrupt) then
|
|
Tercio@11
|
345 return
|
|
Tercio@11
|
346 end
|
|
Tercio@11
|
347 end
|
|
Tercio@11
|
348 end
|
|
Tercio@11
|
349
|
|
Tercio@11
|
350 local OnEnterPressed = function (textentry, byScript)
|
|
Tercio@11
|
351
|
|
Tercio@11
|
352 if (textentry.MyObject.OnEnterPressedHook) then
|
|
Tercio@11
|
353 local interrupt = textentry.MyObject.OnEnterPressedHook (textentry)
|
|
Tercio@11
|
354 if (interrupt) then
|
|
Tercio@11
|
355 return
|
|
Tercio@11
|
356 end
|
|
Tercio@11
|
357 end
|
|
Tercio@11
|
358
|
|
Tercio@11
|
359 local texto = DF:trim (textentry:GetText())
|
|
Tercio@11
|
360 if (_string_len (texto) > 0) then
|
|
Tercio@11
|
361 textentry.text = texto
|
|
Tercio@11
|
362 if (textentry.MyObject.func) then
|
|
Tercio@11
|
363 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, byScript or textentry)
|
|
Tercio@11
|
364 end
|
|
Tercio@11
|
365 else
|
|
Tercio@11
|
366 textentry:SetText ("")
|
|
Tercio@11
|
367 textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
368 end
|
|
Tercio@11
|
369 textentry.focuslost = true --> perdeu_focus isso aqui pra quando estiver editando e clicar em outra caixa
|
|
Tercio@11
|
370 textentry:ClearFocus()
|
|
Tercio@11
|
371
|
|
Tercio@11
|
372 if (textentry.MyObject.tab_on_enter and textentry.MyObject.next) then
|
|
Tercio@11
|
373 textentry.MyObject.next:SetFocus()
|
|
Tercio@11
|
374 end
|
|
Tercio@11
|
375 end
|
|
Tercio@11
|
376
|
|
Tercio@11
|
377 local OnEscapePressed = function (textentry)
|
|
Tercio@11
|
378
|
|
Tercio@11
|
379 if (textentry.MyObject.OnEscapePressedHook) then
|
|
Tercio@11
|
380 local interrupt = textentry.MyObject.OnEscapePressedHook (textentry)
|
|
Tercio@11
|
381 if (interrupt) then
|
|
Tercio@11
|
382 return
|
|
Tercio@11
|
383 end
|
|
Tercio@11
|
384 end
|
|
Tercio@11
|
385
|
|
Tercio@11
|
386 --textentry:SetText("")
|
|
Tercio@11
|
387 --textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
388 textentry.focuslost = true
|
|
Tercio@11
|
389 textentry:ClearFocus()
|
|
Tercio@11
|
390 end
|
|
Tercio@11
|
391
|
|
Tercio@11
|
392 local OnEditFocusLost = function (textentry)
|
|
Tercio@11
|
393
|
|
Tercio@11
|
394 if (textentry:IsShown()) then
|
|
Tercio@11
|
395
|
|
Tercio@11
|
396 if (textentry.MyObject.OnEditFocusLostHook) then
|
|
Tercio@11
|
397 local interrupt = textentry.MyObject.OnEditFocusLostHook (textentry)
|
|
Tercio@11
|
398 if (interrupt) then
|
|
Tercio@11
|
399 return
|
|
Tercio@11
|
400 end
|
|
Tercio@11
|
401 end
|
|
Tercio@11
|
402
|
|
Tercio@11
|
403 if (not textentry.focuslost) then
|
|
Tercio@11
|
404 local texto = DF:trim (textentry:GetText())
|
|
Tercio@11
|
405 if (_string_len (texto) > 0) then
|
|
Tercio@11
|
406 textentry.MyObject.currenttext = texto
|
|
Tercio@11
|
407 if (textentry.MyObject.func) then
|
|
Tercio@11
|
408 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, nil)
|
|
Tercio@11
|
409 end
|
|
Tercio@11
|
410 else
|
|
Tercio@11
|
411 textentry:SetText ("")
|
|
Tercio@11
|
412 textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
413 end
|
|
Tercio@11
|
414 else
|
|
Tercio@11
|
415 textentry.focuslost = false
|
|
Tercio@11
|
416 end
|
|
Tercio@11
|
417
|
|
Tercio@11
|
418 textentry.MyObject.label:SetTextColor (.8, .8, .8, 1)
|
|
Tercio@11
|
419
|
|
Tercio@11
|
420 end
|
|
Tercio@11
|
421 end
|
|
Tercio@11
|
422
|
|
Tercio@11
|
423 local OnEditFocusGained = function (textentry)
|
|
Tercio@11
|
424 if (textentry.MyObject.OnEditFocusGainedHook) then
|
|
Tercio@11
|
425 local interrupt = textentry.MyObject.OnEditFocusGainedHook (textentry)
|
|
Tercio@11
|
426 if (interrupt) then
|
|
Tercio@11
|
427 return
|
|
Tercio@11
|
428 end
|
|
Tercio@11
|
429 end
|
|
Tercio@11
|
430 textentry.MyObject.label:SetTextColor (1, 1, 1, 1)
|
|
Tercio@11
|
431 end
|
|
Tercio@11
|
432
|
|
Tercio@11
|
433 local OnChar = function (textentry, text)
|
|
Tercio@11
|
434 if (textentry.MyObject.OnCharHook) then
|
|
Tercio@11
|
435 local interrupt = textentry.MyObject.OnCharHook (textentry, text)
|
|
Tercio@11
|
436 if (interrupt) then
|
|
Tercio@11
|
437 return
|
|
Tercio@11
|
438 end
|
|
Tercio@11
|
439 end
|
|
Tercio@11
|
440 end
|
|
Tercio@11
|
441
|
|
Tercio@11
|
442 local OnTextChanged = function (textentry, byUser)
|
|
Tercio@11
|
443 if (textentry.MyObject.OnTextChangedHook) then
|
|
Tercio@11
|
444 local interrupt = textentry.MyObject.OnTextChangedHook (textentry, byUser)
|
|
Tercio@11
|
445 if (interrupt) then
|
|
Tercio@11
|
446 return
|
|
Tercio@11
|
447 end
|
|
Tercio@11
|
448 end
|
|
Tercio@11
|
449 end
|
|
Tercio@11
|
450
|
|
Tercio@11
|
451 local OnTabPressed = function (textentry)
|
|
Tercio@11
|
452 if (textentry.MyObject.OnTabPressedHook) then
|
|
Tercio@11
|
453 local interrupt = textentry.MyObject.OnTabPressedHook (textentry, byUser)
|
|
Tercio@11
|
454 if (interrupt) then
|
|
Tercio@11
|
455 return
|
|
Tercio@11
|
456 end
|
|
Tercio@11
|
457 end
|
|
Tercio@11
|
458
|
|
Tercio@11
|
459 if (textentry.MyObject.next) then
|
|
Tercio@11
|
460 OnEnterPressed (textentry, false)
|
|
Tercio@11
|
461 textentry.MyObject.next:SetFocus()
|
|
Tercio@11
|
462 end
|
|
Tercio@11
|
463 end
|
|
Tercio@11
|
464
|
|
Tercio@11
|
465 function TextEntryMetaFunctions:PressEnter (byScript)
|
|
Tercio@11
|
466 OnEnterPressed (self.editbox, byScript)
|
|
Tercio@11
|
467 end
|
|
Tercio@11
|
468
|
|
Tercio@11
|
469 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@22
|
470
|
|
Tercio@22
|
471 function TextEntryMetaFunctions:SetTemplate (template)
|
|
Tercio@22
|
472 if (template.width) then
|
|
Tercio@22
|
473 self:SetWidth (template.width)
|
|
Tercio@22
|
474 end
|
|
Tercio@22
|
475 if (template.height) then
|
|
Tercio@22
|
476 self:SetHeight (template.height)
|
|
Tercio@22
|
477 end
|
|
Tercio@22
|
478
|
|
Tercio@22
|
479 if (template.backdrop) then
|
|
Tercio@22
|
480 self:SetBackdrop (template.backdrop)
|
|
Tercio@22
|
481 end
|
|
Tercio@22
|
482 if (template.backdropcolor) then
|
|
Tercio@22
|
483 local r, g, b, a = DF:ParseColors (template.backdropcolor)
|
|
Tercio@22
|
484 self:SetBackdropColor (r, g, b, a)
|
|
Tercio@22
|
485 self.onleave_backdrop = {r, g, b, a}
|
|
Tercio@22
|
486 end
|
|
Tercio@22
|
487 if (template.backdropbordercolor) then
|
|
Tercio@22
|
488 local r, g, b, a = DF:ParseColors (template.backdropbordercolor)
|
|
Tercio@22
|
489 self:SetBackdropBorderColor (r, g, b, a)
|
|
Tercio@22
|
490 self.editbox.current_bordercolor[1] = r
|
|
Tercio@22
|
491 self.editbox.current_bordercolor[2] = g
|
|
Tercio@22
|
492 self.editbox.current_bordercolor[3] = b
|
|
Tercio@22
|
493 self.editbox.current_bordercolor[4] = a
|
|
Tercio@22
|
494 self.onleave_backdrop_border_color = {r, g, b, a}
|
|
Tercio@22
|
495 end
|
|
Tercio@22
|
496 end
|
|
Tercio@22
|
497
|
|
Tercio@22
|
498 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
499 --> object constructor
|
|
Tercio@11
|
500
|
|
Tercio@22
|
501 function DF:CreateTextEntry (parent, func, w, h, member, name, with_label, entry_template, label_template)
|
|
Tercio@22
|
502 return DF:NewTextEntry (parent, parent, name, member, w, h, func, nil, nil, nil, with_label, entry_template, label_template)
|
|
Tercio@11
|
503 end
|
|
Tercio@11
|
504
|
|
Tercio@22
|
505 function DF:NewTextEntry (parent, container, name, member, w, h, func, param1, param2, space, with_label, entry_template, label_template)
|
|
Tercio@11
|
506
|
|
Tercio@11
|
507 if (not name) then
|
|
Tercio@11
|
508 name = "DetailsFrameworkTextEntryNumber" .. DF.TextEntryCounter
|
|
Tercio@11
|
509 DF.TextEntryCounter = DF.TextEntryCounter + 1
|
|
Tercio@11
|
510
|
|
Tercio@11
|
511 elseif (not parent) then
|
|
Tercio@11
|
512 return nil
|
|
Tercio@11
|
513 end
|
|
Tercio@11
|
514
|
|
Tercio@11
|
515 if (not container) then
|
|
Tercio@11
|
516 container = parent
|
|
Tercio@11
|
517 end
|
|
Tercio@11
|
518
|
|
Tercio@11
|
519 if (name:find ("$parent")) then
|
|
Tercio@11
|
520 name = name:gsub ("$parent", parent:GetName())
|
|
Tercio@11
|
521 end
|
|
Tercio@11
|
522
|
|
Tercio@11
|
523 local TextEntryObject = {type = "textentry", dframework = true}
|
|
Tercio@11
|
524
|
|
Tercio@11
|
525 if (member) then
|
|
Tercio@11
|
526 parent [member] = TextEntryObject
|
|
Tercio@11
|
527 end
|
|
Tercio@11
|
528
|
|
Tercio@11
|
529 if (parent.dframework) then
|
|
Tercio@11
|
530 parent = parent.widget
|
|
Tercio@11
|
531 end
|
|
Tercio@11
|
532 if (container.dframework) then
|
|
Tercio@11
|
533 container = container.widget
|
|
Tercio@11
|
534 end
|
|
Tercio@11
|
535
|
|
Tercio@11
|
536 --> default members:
|
|
Tercio@11
|
537 --> hooks
|
|
Tercio@11
|
538 TextEntryObject.OnEnterHook = nil
|
|
Tercio@11
|
539 TextEntryObject.OnLeaveHook = nil
|
|
Tercio@11
|
540 TextEntryObject.OnHideHook = nil
|
|
Tercio@11
|
541 TextEntryObject.OnShowHook = nil
|
|
Tercio@11
|
542 TextEntryObject.OnEnterPressedHook = nil
|
|
Tercio@11
|
543 TextEntryObject.OnEscapePressedHook = nil
|
|
Tercio@11
|
544 TextEntryObject.OnEditFocusGainedHook = nil
|
|
Tercio@11
|
545 TextEntryObject.OnEditFocusLostHook = nil
|
|
Tercio@11
|
546 TextEntryObject.OnCharHook = nil
|
|
Tercio@11
|
547 TextEntryObject.OnTextChangedHook = nil
|
|
Tercio@11
|
548 TextEntryObject.OnTabPressedHook = nil
|
|
Tercio@11
|
549
|
|
Tercio@11
|
550 --> misc
|
|
Tercio@11
|
551 TextEntryObject.container = container
|
|
Tercio@11
|
552 TextEntryObject.have_tooltip = nil
|
|
Tercio@11
|
553
|
|
Tercio@11
|
554 TextEntryObject.editbox = CreateFrame ("EditBox", name, parent, "DetailsFrameworkEditBoxTemplate2")
|
|
Tercio@11
|
555 TextEntryObject.widget = TextEntryObject.editbox
|
|
Tercio@11
|
556
|
|
Tercio@11
|
557 TextEntryObject.editbox:SetTextInsets (3, 0, 0, -3)
|
|
Tercio@11
|
558
|
|
Tercio@11
|
559 if (not APITextEntryFunctions) then
|
|
Tercio@11
|
560 APITextEntryFunctions = true
|
|
Tercio@11
|
561 local idx = getmetatable (TextEntryObject.editbox).__index
|
|
Tercio@11
|
562 for funcName, funcAddress in pairs (idx) do
|
|
Tercio@11
|
563 if (not TextEntryMetaFunctions [funcName]) then
|
|
Tercio@11
|
564 TextEntryMetaFunctions [funcName] = function (object, ...)
|
|
Tercio@20
|
565 local x = loadstring ( "return _G['"..object.editbox:GetName().."']:"..funcName.."(...)")
|
|
Tercio@11
|
566 return x (...)
|
|
Tercio@11
|
567 end
|
|
Tercio@11
|
568 end
|
|
Tercio@11
|
569 end
|
|
Tercio@11
|
570 end
|
|
Tercio@11
|
571
|
|
Tercio@11
|
572 TextEntryObject.editbox.MyObject = TextEntryObject
|
|
Tercio@11
|
573
|
|
Tercio@11
|
574 if (not w and space) then
|
|
Tercio@11
|
575 w = space
|
|
Tercio@11
|
576 elseif (w and space) then
|
|
Tercio@11
|
577 if (DF.debug) then
|
|
Tercio@11
|
578 print ("warning: you are using width and space, try use only space for better results.")
|
|
Tercio@11
|
579 end
|
|
Tercio@11
|
580 end
|
|
Tercio@11
|
581
|
|
Tercio@11
|
582 TextEntryObject.editbox:SetWidth (w)
|
|
Tercio@11
|
583 TextEntryObject.editbox:SetHeight (h)
|
|
Tercio@11
|
584
|
|
Tercio@11
|
585 TextEntryObject.editbox:SetJustifyH ("center")
|
|
Tercio@11
|
586 TextEntryObject.editbox:EnableMouse (true)
|
|
Tercio@11
|
587 TextEntryObject.editbox:SetText ("")
|
|
Tercio@11
|
588
|
|
Tercio@11
|
589 TextEntryObject.editbox:SetAutoFocus (false)
|
|
Tercio@11
|
590 TextEntryObject.editbox:SetFontObject ("GameFontHighlightSmall")
|
|
Tercio@11
|
591
|
|
Tercio@11
|
592 TextEntryObject.editbox.current_bordercolor = {1, 1, 1, 0.7}
|
|
Tercio@11
|
593 TextEntryObject.editbox:SetBackdropBorderColor (1, 1, 1, 0.7)
|
|
Tercio@11
|
594 TextEntryObject.enabled_border_color = {TextEntryObject.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
595 TextEntryObject.enabled_backdrop_color = {TextEntryObject.editbox:GetBackdropColor()}
|
|
Tercio@11
|
596 TextEntryObject.enabled_text_color = {TextEntryObject.editbox:GetTextColor()}
|
|
Tercio@22
|
597 TextEntryObject.onleave_backdrop = {TextEntryObject.editbox:GetBackdropColor()}
|
|
Tercio@22
|
598 TextEntryObject.onleave_backdrop_border_color = {TextEntryObject.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
599
|
|
Tercio@11
|
600 TextEntryObject.func = func
|
|
Tercio@11
|
601 TextEntryObject.param1 = param1
|
|
Tercio@11
|
602 TextEntryObject.param2 = param2
|
|
Tercio@11
|
603 TextEntryObject.next = nil
|
|
Tercio@11
|
604 TextEntryObject.space = space
|
|
Tercio@11
|
605 TextEntryObject.tab_on_enter = false
|
|
Tercio@11
|
606
|
|
Tercio@11
|
607 TextEntryObject.label = _G [name .. "_Desc"]
|
|
Tercio@11
|
608
|
|
Tercio@11
|
609 TextEntryObject.editbox:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}})
|
|
Tercio@11
|
610
|
|
Tercio@11
|
611 --> hooks
|
|
Tercio@11
|
612 TextEntryObject.editbox:SetScript ("OnEnter", OnEnter)
|
|
Tercio@11
|
613 TextEntryObject.editbox:SetScript ("OnLeave", OnLeave)
|
|
Tercio@11
|
614 TextEntryObject.editbox:SetScript ("OnHide", OnHide)
|
|
Tercio@11
|
615 TextEntryObject.editbox:SetScript ("OnShow", OnShow)
|
|
Tercio@11
|
616
|
|
Tercio@11
|
617 TextEntryObject.editbox:SetScript ("OnEnterPressed", OnEnterPressed)
|
|
Tercio@11
|
618 TextEntryObject.editbox:SetScript ("OnEscapePressed", OnEscapePressed)
|
|
Tercio@11
|
619 TextEntryObject.editbox:SetScript ("OnEditFocusLost", OnEditFocusLost)
|
|
Tercio@11
|
620 TextEntryObject.editbox:SetScript ("OnEditFocusGained", OnEditFocusGained)
|
|
Tercio@11
|
621 TextEntryObject.editbox:SetScript ("OnChar", OnChar)
|
|
Tercio@11
|
622 TextEntryObject.editbox:SetScript ("OnTextChanged", OnTextChanged)
|
|
Tercio@11
|
623 TextEntryObject.editbox:SetScript ("OnTabPressed", OnTabPressed)
|
|
Tercio@11
|
624
|
|
Tercio@11
|
625 _setmetatable (TextEntryObject, TextEntryMetaFunctions)
|
|
Tercio@11
|
626
|
|
Tercio@22
|
627 if (with_label) then
|
|
Tercio@22
|
628 local label = DF:CreateLabel (TextEntryObject.editbox, with_label, nil, nil, nil, "label", nil, "overlay")
|
|
Tercio@22
|
629 label.text = with_label
|
|
Tercio@22
|
630 TextEntryObject.editbox:SetPoint ("left", label.widget, "right", 2, 0)
|
|
Tercio@22
|
631 if (label_template) then
|
|
Tercio@22
|
632 label:SetTemplate (label_template)
|
|
Tercio@22
|
633 end
|
|
Tercio@22
|
634 with_label = label
|
|
Tercio@22
|
635 end
|
|
Tercio@11
|
636
|
|
Tercio@22
|
637 if (entry_template) then
|
|
Tercio@22
|
638 TextEntryObject:SetTemplate (entry_template)
|
|
Tercio@22
|
639 end
|
|
Tercio@22
|
640
|
|
Tercio@22
|
641 return TextEntryObject, with_label
|
|
Tercio@22
|
642
|
|
Tercio@22
|
643 end
|
|
Tercio@22
|
644
|
|
Tercio@22
|
645 function DF:NewSpellEntry (parent, func, w, h, param1, param2, member, name)
|
|
Tercio@22
|
646 local editbox = DF:NewTextEntry (parent, parent, name, member, w, h, func, param1, param2)
|
|
Tercio@22
|
647
|
|
Tercio@22
|
648 editbox:SetHook ("OnEditFocusGained", SpellEntryOnEditFocusGained)
|
|
Tercio@22
|
649 editbox:SetHook ("OnTextChanged", SpellEntryOnTextChanged)
|
|
Tercio@22
|
650
|
|
Tercio@22
|
651 return editbox
|
|
Tercio@11
|
652 end
|
|
Tercio@11
|
653
|
|
Tercio@11
|
654 local function_gettext = function (self)
|
|
Tercio@11
|
655 return self.editbox:GetText()
|
|
Tercio@11
|
656 end
|
|
Tercio@11
|
657 local function_settext = function (self, text)
|
|
Tercio@11
|
658 return self.editbox:SetText (text)
|
|
Tercio@11
|
659 end
|
|
Tercio@11
|
660 local function_clearfocus = function (self)
|
|
Tercio@11
|
661 return self.editbox:ClearFocus()
|
|
Tercio@11
|
662 end
|
|
Tercio@11
|
663 local function_setfocus = function (self)
|
|
Tercio@11
|
664 return self.editbox:SetFocus (true)
|
|
Tercio@11
|
665 end
|
|
Tercio@11
|
666
|
|
Tercio@11
|
667 function DF:NewSpecialLuaEditorEntry (parent, w, h, member, name, nointent)
|
|
Tercio@11
|
668
|
|
Tercio@11
|
669 if (name:find ("$parent")) then
|
|
Tercio@11
|
670 name = name:gsub ("$parent", parent:GetName())
|
|
Tercio@11
|
671 end
|
|
Tercio@11
|
672
|
|
Tercio@11
|
673 local borderframe = CreateFrame ("Frame", name, parent)
|
|
Tercio@11
|
674 borderframe:SetSize (w, h)
|
|
Tercio@11
|
675
|
|
Tercio@11
|
676 if (member) then
|
|
Tercio@11
|
677 parent [member] = borderframe
|
|
Tercio@11
|
678 end
|
|
Tercio@11
|
679
|
|
Tercio@11
|
680 local scrollframe = CreateFrame ("ScrollFrame", name, borderframe, "DetailsFrameworkEditBoxMultiLineTemplate")
|
|
Tercio@11
|
681
|
|
Tercio@11
|
682 scrollframe:SetScript ("OnSizeChanged", function (self)
|
|
Tercio@11
|
683 scrollframe.editbox:SetSize (self:GetSize())
|
|
Tercio@11
|
684 end)
|
|
Tercio@11
|
685
|
|
Tercio@11
|
686 scrollframe:SetPoint ("topleft", borderframe, "topleft", 10, -10)
|
|
Tercio@11
|
687 scrollframe:SetPoint ("bottomright", borderframe, "bottomright", -30, 10)
|
|
Tercio@11
|
688
|
|
Tercio@11
|
689 scrollframe.editbox:SetMultiLine (true)
|
|
Tercio@11
|
690 scrollframe.editbox:SetJustifyH ("left")
|
|
Tercio@11
|
691 scrollframe.editbox:SetJustifyV ("top")
|
|
Tercio@11
|
692 scrollframe.editbox:SetMaxBytes (1024000)
|
|
Tercio@11
|
693 scrollframe.editbox:SetMaxLetters (128000)
|
|
Tercio@11
|
694
|
|
Tercio@11
|
695 borderframe.GetText = function_gettext
|
|
Tercio@11
|
696 borderframe.SetText = function_settext
|
|
Tercio@11
|
697 borderframe.ClearFocus = function_clearfocus
|
|
Tercio@11
|
698 borderframe.SetFocus = function_setfocus
|
|
Tercio@11
|
699
|
|
Tercio@22
|
700 borderframe.Enable = TextEntryMetaFunctions.Enable
|
|
Tercio@22
|
701 borderframe.Disable = TextEntryMetaFunctions.Disable
|
|
Tercio@22
|
702
|
|
Tercio@22
|
703 borderframe.SetTemplate = TextEntryMetaFunctions.SetTemplate
|
|
Tercio@22
|
704
|
|
Tercio@11
|
705 if (not nointent) then
|
|
Tercio@11
|
706 IndentationLib.enable (scrollframe.editbox, nil, 4)
|
|
Tercio@11
|
707 end
|
|
Tercio@11
|
708
|
|
Tercio@11
|
709 borderframe:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
|
|
Tercio@11
|
710 tile = 1, tileSize = 16, edgeSize = 16, insets = {left = 5, right = 5, top = 5, bottom = 5}})
|
|
Tercio@22
|
711
|
|
Tercio@22
|
712 scrollframe.editbox.current_bordercolor = {1, 1, 1, 0.7}
|
|
Tercio@22
|
713 borderframe:SetBackdropBorderColor (1, 1, 1, 0.7)
|
|
Tercio@11
|
714 borderframe:SetBackdropColor (0.090195, 0.090195, 0.188234, 1)
|
|
Tercio@22
|
715
|
|
Tercio@22
|
716 borderframe.enabled_border_color = {borderframe:GetBackdropBorderColor()}
|
|
Tercio@22
|
717 borderframe.enabled_backdrop_color = {borderframe:GetBackdropColor()}
|
|
Tercio@22
|
718 borderframe.enabled_text_color = {scrollframe.editbox:GetTextColor()}
|
|
Tercio@22
|
719
|
|
Tercio@22
|
720 borderframe.onleave_backdrop = {scrollframe.editbox:GetBackdropColor()}
|
|
Tercio@22
|
721 borderframe.onleave_backdrop_border_color = {scrollframe.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
722
|
|
Tercio@11
|
723 borderframe.scroll = scrollframe
|
|
Tercio@11
|
724 borderframe.editbox = scrollframe.editbox
|
|
Tercio@22
|
725 borderframe.editbox.borderframe = borderframe
|
|
Tercio@11
|
726
|
|
Tercio@11
|
727 return borderframe
|
|
Tercio@11
|
728 end |