|
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
|
|
Tercioo@29
|
186 function TextEntryMetaFunctions:SetText (text)
|
|
Tercioo@29
|
187 self.editbox:SetText (text)
|
|
Tercioo@29
|
188 end
|
|
Tercioo@29
|
189 function TextEntryMetaFunctions:GetText()
|
|
Tercioo@29
|
190 return self.editbox:GetText()
|
|
Tercioo@29
|
191 end
|
|
Tercioo@29
|
192
|
|
Tercio@11
|
193 --> frame levels
|
|
Tercio@11
|
194 function TextEntryMetaFunctions:GetFrameLevel()
|
|
Tercio@11
|
195 return self.editbox:GetFrameLevel()
|
|
Tercio@11
|
196 end
|
|
Tercio@11
|
197 function TextEntryMetaFunctions:SetFrameLevel (level, frame)
|
|
Tercio@11
|
198 if (not frame) then
|
|
Tercio@11
|
199 return self.editbox:SetFrameLevel (level)
|
|
Tercio@11
|
200 else
|
|
Tercio@11
|
201 local framelevel = frame:GetFrameLevel (frame) + level
|
|
Tercio@11
|
202 return self.editbox:SetFrameLevel (framelevel)
|
|
Tercio@11
|
203 end
|
|
Tercio@11
|
204 end
|
|
Tercio@11
|
205
|
|
Tercio@11
|
206 --> select all text
|
|
Tercio@11
|
207 function TextEntryMetaFunctions:SelectAll()
|
|
Tercio@11
|
208 self.editbox:HighlightText()
|
|
Tercio@11
|
209 end
|
|
Tercio@11
|
210
|
|
Tercio@11
|
211 --> set labal description
|
|
Tercio@11
|
212 function TextEntryMetaFunctions:SetLabelText (text)
|
|
Tercio@11
|
213 if (text) then
|
|
Tercio@11
|
214 self.label:SetText (text)
|
|
Tercio@11
|
215 else
|
|
Tercio@11
|
216 self.label:SetText ("")
|
|
Tercio@11
|
217 end
|
|
Tercio@11
|
218 self:SetPoint (true) --> refresh
|
|
Tercio@11
|
219 end
|
|
Tercio@11
|
220
|
|
Tercio@11
|
221 --> set tab order
|
|
Tercio@11
|
222 function TextEntryMetaFunctions:SetNext (nextbox)
|
|
Tercio@11
|
223 self.next = nextbox
|
|
Tercio@11
|
224 end
|
|
Tercio@11
|
225
|
|
Tercio@11
|
226 --> blink
|
|
Tercio@11
|
227 function TextEntryMetaFunctions:Blink()
|
|
Tercio@11
|
228 self.label:SetTextColor (1, .2, .2, 1)
|
|
Tercio@11
|
229 end
|
|
Tercio@11
|
230
|
|
Tercio@11
|
231 --> show & hide
|
|
Tercio@11
|
232 function TextEntryMetaFunctions:IsShown()
|
|
Tercio@11
|
233 return self.editbox:IsShown()
|
|
Tercio@11
|
234 end
|
|
Tercio@11
|
235 function TextEntryMetaFunctions:Show()
|
|
Tercio@11
|
236 return self.editbox:Show()
|
|
Tercio@11
|
237 end
|
|
Tercio@11
|
238 function TextEntryMetaFunctions:Hide()
|
|
Tercio@11
|
239 return self.editbox:Hide()
|
|
Tercio@11
|
240 end
|
|
Tercio@11
|
241
|
|
Tercio@11
|
242 -- tooltip
|
|
Tercio@11
|
243 function TextEntryMetaFunctions:SetTooltip (tooltip)
|
|
Tercio@11
|
244 if (tooltip) then
|
|
Tercio@11
|
245 return _rawset (self, "have_tooltip", tooltip)
|
|
Tercio@11
|
246 else
|
|
Tercio@11
|
247 return _rawset (self, "have_tooltip", nil)
|
|
Tercio@11
|
248 end
|
|
Tercio@11
|
249 end
|
|
Tercio@11
|
250 function TextEntryMetaFunctions:GetTooltip()
|
|
Tercio@11
|
251 return _rawget (self, "have_tooltip")
|
|
Tercio@11
|
252 end
|
|
Tercio@11
|
253
|
|
Tercio@11
|
254 --> hooks
|
|
Tercio@11
|
255 function TextEntryMetaFunctions:SetHook (hookType, func)
|
|
Tercio@11
|
256 if (func) then
|
|
Tercio@11
|
257 _rawset (self, hookType.."Hook", func)
|
|
Tercio@11
|
258 else
|
|
Tercio@11
|
259 _rawset (self, hookType.."Hook", nil)
|
|
Tercio@11
|
260 end
|
|
Tercio@11
|
261 end
|
|
Tercio@11
|
262
|
|
Tercio@11
|
263 function TextEntryMetaFunctions:Enable()
|
|
Tercio@11
|
264 if (not self.editbox:IsEnabled()) then
|
|
Tercio@11
|
265 self.editbox:Enable()
|
|
Tercio@11
|
266 self.editbox:SetBackdropBorderColor (unpack (self.enabled_border_color))
|
|
Tercio@11
|
267 self.editbox:SetBackdropColor (unpack (self.enabled_backdrop_color))
|
|
Tercio@11
|
268 self.editbox:SetTextColor (unpack (self.enabled_text_color))
|
|
Tercio@22
|
269 if (self.editbox.borderframe) then
|
|
Tercio@22
|
270 self.editbox.borderframe:SetBackdropColor (unpack (self.editbox.borderframe.onleave_backdrop))
|
|
Tercio@22
|
271 end
|
|
Tercio@11
|
272 end
|
|
Tercio@11
|
273 end
|
|
Tercio@11
|
274
|
|
Tercio@11
|
275 function TextEntryMetaFunctions:Disable()
|
|
Tercio@11
|
276 if (self.editbox:IsEnabled()) then
|
|
Tercio@11
|
277 self.enabled_border_color = {self.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
278 self.enabled_backdrop_color = {self.editbox:GetBackdropColor()}
|
|
Tercio@11
|
279 self.enabled_text_color = {self.editbox:GetTextColor()}
|
|
Tercio@11
|
280
|
|
Tercio@11
|
281 self.editbox:Disable()
|
|
Tercio@11
|
282
|
|
Tercio@11
|
283 self.editbox:SetBackdropBorderColor (.5, .5, .5, .5)
|
|
Tercio@11
|
284 self.editbox:SetBackdropColor (.5, .5, .5, .5)
|
|
Tercio@11
|
285 self.editbox:SetTextColor (.5, .5, .5, .5)
|
|
Tercio@22
|
286
|
|
Tercio@22
|
287 if (self.editbox.borderframe) then
|
|
Tercio@22
|
288 self.editbox.borderframe:SetBackdropColor (.5, .5, .5, .5)
|
|
Tercio@22
|
289 end
|
|
Tercio@11
|
290 end
|
|
Tercio@11
|
291 end
|
|
Tercio@11
|
292
|
|
Tercio@11
|
293 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
294 --> scripts
|
|
Tercio@11
|
295 local OnEnter = function (textentry)
|
|
Tercio@11
|
296
|
|
Tercio@11
|
297 if (textentry.MyObject.OnEnterHook) then
|
|
Tercio@11
|
298 local interrupt = textentry.MyObject.OnEnterHook (textentry)
|
|
Tercio@11
|
299 if (interrupt) then
|
|
Tercio@11
|
300 return
|
|
Tercio@11
|
301 end
|
|
Tercio@11
|
302 end
|
|
Tercio@11
|
303
|
|
Tercio@11
|
304 if (textentry.MyObject.have_tooltip) then
|
|
Tercio@11
|
305 GameCooltip2:Preset (2)
|
|
Tercio@11
|
306 GameCooltip2:AddLine (textentry.MyObject.have_tooltip)
|
|
Tercio@11
|
307 GameCooltip2:ShowCooltip (textentry, "tooltip")
|
|
Tercio@11
|
308 end
|
|
Tercio@11
|
309
|
|
Tercio@11
|
310 textentry.mouse_over = true
|
|
Tercio@11
|
311
|
|
Tercio@11
|
312 if (textentry:IsEnabled()) then
|
|
Tercio@11
|
313 textentry.current_bordercolor = textentry.current_bordercolor or {textentry:GetBackdropBorderColor()}
|
|
Tercio@11
|
314 textentry:SetBackdropBorderColor (1, 1, 1, 1)
|
|
Tercio@11
|
315 end
|
|
Tercio@11
|
316
|
|
Tercio@11
|
317 end
|
|
Tercio@11
|
318
|
|
Tercio@11
|
319 local OnLeave = function (textentry)
|
|
Tercio@11
|
320 if (textentry.MyObject.OnLeaveHook) then
|
|
Tercio@11
|
321 local interrupt = textentry.MyObject.OnLeaveHook (textentry)
|
|
Tercio@11
|
322 if (interrupt) then
|
|
Tercio@11
|
323 return
|
|
Tercio@11
|
324 end
|
|
Tercio@11
|
325 end
|
|
Tercio@11
|
326
|
|
Tercio@11
|
327 if (textentry.MyObject.have_tooltip) then
|
|
Tercio@11
|
328 GameCooltip2:ShowMe (false)
|
|
Tercio@11
|
329 end
|
|
Tercio@11
|
330
|
|
Tercio@11
|
331 textentry.mouse_over = false
|
|
Tercio@11
|
332
|
|
Tercio@11
|
333 if (textentry:IsEnabled()) then
|
|
Tercio@11
|
334 textentry:SetBackdropBorderColor (unpack (textentry.current_bordercolor))
|
|
Tercio@11
|
335 end
|
|
Tercio@22
|
336
|
|
Tercio@11
|
337 end
|
|
Tercio@11
|
338
|
|
Tercio@11
|
339 local OnHide = function (textentry)
|
|
Tercio@11
|
340 if (textentry.MyObject.OnHideHook) then
|
|
Tercio@11
|
341 local interrupt = textentry.MyObject.OnHideHook (textentry)
|
|
Tercio@11
|
342 if (interrupt) then
|
|
Tercio@11
|
343 return
|
|
Tercio@11
|
344 end
|
|
Tercio@11
|
345 end
|
|
Tercio@11
|
346 end
|
|
Tercio@11
|
347
|
|
Tercio@11
|
348 local OnShow = function (textentry)
|
|
Tercio@11
|
349 if (textentry.MyObject.OnShowHook) then
|
|
Tercio@11
|
350 local interrupt = textentry.MyObject.OnShowHook (textentry)
|
|
Tercio@11
|
351 if (interrupt) then
|
|
Tercio@11
|
352 return
|
|
Tercio@11
|
353 end
|
|
Tercio@11
|
354 end
|
|
Tercio@11
|
355 end
|
|
Tercio@11
|
356
|
|
Tercio@11
|
357 local OnEnterPressed = function (textentry, byScript)
|
|
Tercio@11
|
358
|
|
Tercio@11
|
359 if (textentry.MyObject.OnEnterPressedHook) then
|
|
Tercio@11
|
360 local interrupt = textentry.MyObject.OnEnterPressedHook (textentry)
|
|
Tercio@11
|
361 if (interrupt) then
|
|
Tercio@11
|
362 return
|
|
Tercio@11
|
363 end
|
|
Tercio@11
|
364 end
|
|
Tercio@11
|
365
|
|
Tercio@11
|
366 local texto = DF:trim (textentry:GetText())
|
|
Tercio@11
|
367 if (_string_len (texto) > 0) then
|
|
Tercio@11
|
368 textentry.text = texto
|
|
Tercio@11
|
369 if (textentry.MyObject.func) then
|
|
Tercio@11
|
370 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, byScript or textentry)
|
|
Tercio@11
|
371 end
|
|
Tercio@11
|
372 else
|
|
Tercio@11
|
373 textentry:SetText ("")
|
|
Tercio@11
|
374 textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
375 end
|
|
Tercio@11
|
376 textentry.focuslost = true --> perdeu_focus isso aqui pra quando estiver editando e clicar em outra caixa
|
|
Tercio@11
|
377 textentry:ClearFocus()
|
|
Tercio@11
|
378
|
|
Tercio@11
|
379 if (textentry.MyObject.tab_on_enter and textentry.MyObject.next) then
|
|
Tercio@11
|
380 textentry.MyObject.next:SetFocus()
|
|
Tercio@11
|
381 end
|
|
Tercio@11
|
382 end
|
|
Tercio@11
|
383
|
|
Tercio@11
|
384 local OnEscapePressed = function (textentry)
|
|
Tercio@11
|
385
|
|
Tercio@11
|
386 if (textentry.MyObject.OnEscapePressedHook) then
|
|
Tercio@11
|
387 local interrupt = textentry.MyObject.OnEscapePressedHook (textentry)
|
|
Tercio@11
|
388 if (interrupt) then
|
|
Tercio@11
|
389 return
|
|
Tercio@11
|
390 end
|
|
Tercio@11
|
391 end
|
|
Tercio@11
|
392
|
|
Tercio@11
|
393 --textentry:SetText("")
|
|
Tercio@11
|
394 --textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
395 textentry.focuslost = true
|
|
Tercio@11
|
396 textentry:ClearFocus()
|
|
Tercio@11
|
397 end
|
|
Tercio@11
|
398
|
|
Tercio@11
|
399 local OnEditFocusLost = function (textentry)
|
|
Tercio@11
|
400
|
|
Tercio@11
|
401 if (textentry:IsShown()) then
|
|
Tercio@11
|
402
|
|
Tercio@11
|
403 if (textentry.MyObject.OnEditFocusLostHook) then
|
|
Tercio@11
|
404 local interrupt = textentry.MyObject.OnEditFocusLostHook (textentry)
|
|
Tercio@11
|
405 if (interrupt) then
|
|
Tercio@11
|
406 return
|
|
Tercio@11
|
407 end
|
|
Tercio@11
|
408 end
|
|
Tercio@11
|
409
|
|
Tercio@11
|
410 if (not textentry.focuslost) then
|
|
Tercio@11
|
411 local texto = DF:trim (textentry:GetText())
|
|
Tercio@11
|
412 if (_string_len (texto) > 0) then
|
|
Tercio@11
|
413 textentry.MyObject.currenttext = texto
|
|
Tercio@11
|
414 if (textentry.MyObject.func) then
|
|
Tercio@11
|
415 textentry.MyObject.func (textentry.MyObject.param1, textentry.MyObject.param2, texto, textentry, nil)
|
|
Tercio@11
|
416 end
|
|
Tercio@11
|
417 else
|
|
Tercio@11
|
418 textentry:SetText ("")
|
|
Tercio@11
|
419 textentry.MyObject.currenttext = ""
|
|
Tercio@11
|
420 end
|
|
Tercio@11
|
421 else
|
|
Tercio@11
|
422 textentry.focuslost = false
|
|
Tercio@11
|
423 end
|
|
Tercio@11
|
424
|
|
Tercio@11
|
425 textentry.MyObject.label:SetTextColor (.8, .8, .8, 1)
|
|
Tercio@11
|
426
|
|
Tercio@11
|
427 end
|
|
Tercio@11
|
428 end
|
|
Tercio@11
|
429
|
|
Tercio@11
|
430 local OnEditFocusGained = function (textentry)
|
|
Tercio@11
|
431 if (textentry.MyObject.OnEditFocusGainedHook) then
|
|
Tercio@11
|
432 local interrupt = textentry.MyObject.OnEditFocusGainedHook (textentry)
|
|
Tercio@11
|
433 if (interrupt) then
|
|
Tercio@11
|
434 return
|
|
Tercio@11
|
435 end
|
|
Tercio@11
|
436 end
|
|
Tercio@11
|
437 textentry.MyObject.label:SetTextColor (1, 1, 1, 1)
|
|
Tercio@11
|
438 end
|
|
Tercio@11
|
439
|
|
Tercio@11
|
440 local OnChar = function (textentry, text)
|
|
Tercio@11
|
441 if (textentry.MyObject.OnCharHook) then
|
|
Tercio@11
|
442 local interrupt = textentry.MyObject.OnCharHook (textentry, text)
|
|
Tercio@11
|
443 if (interrupt) then
|
|
Tercio@11
|
444 return
|
|
Tercio@11
|
445 end
|
|
Tercio@11
|
446 end
|
|
Tercio@11
|
447 end
|
|
Tercio@11
|
448
|
|
Tercio@11
|
449 local OnTextChanged = function (textentry, byUser)
|
|
Tercio@11
|
450 if (textentry.MyObject.OnTextChangedHook) then
|
|
Tercio@11
|
451 local interrupt = textentry.MyObject.OnTextChangedHook (textentry, byUser)
|
|
Tercio@11
|
452 if (interrupt) then
|
|
Tercio@11
|
453 return
|
|
Tercio@11
|
454 end
|
|
Tercio@11
|
455 end
|
|
Tercio@11
|
456 end
|
|
Tercio@11
|
457
|
|
Tercio@11
|
458 local OnTabPressed = function (textentry)
|
|
Tercio@11
|
459 if (textentry.MyObject.OnTabPressedHook) then
|
|
Tercio@11
|
460 local interrupt = textentry.MyObject.OnTabPressedHook (textentry, byUser)
|
|
Tercio@11
|
461 if (interrupt) then
|
|
Tercio@11
|
462 return
|
|
Tercio@11
|
463 end
|
|
Tercio@11
|
464 end
|
|
Tercio@11
|
465
|
|
Tercio@11
|
466 if (textentry.MyObject.next) then
|
|
Tercio@11
|
467 OnEnterPressed (textentry, false)
|
|
Tercio@11
|
468 textentry.MyObject.next:SetFocus()
|
|
Tercio@11
|
469 end
|
|
Tercio@11
|
470 end
|
|
Tercio@11
|
471
|
|
Tercio@11
|
472 function TextEntryMetaFunctions:PressEnter (byScript)
|
|
Tercio@11
|
473 OnEnterPressed (self.editbox, byScript)
|
|
Tercio@11
|
474 end
|
|
Tercio@11
|
475
|
|
Tercio@11
|
476 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@22
|
477
|
|
Tercio@22
|
478 function TextEntryMetaFunctions:SetTemplate (template)
|
|
Tercio@22
|
479 if (template.width) then
|
|
Tercioo@29
|
480 self.editbox:SetWidth (template.width)
|
|
Tercio@22
|
481 end
|
|
Tercio@22
|
482 if (template.height) then
|
|
Tercioo@29
|
483 self.editbox:SetHeight (template.height)
|
|
Tercio@22
|
484 end
|
|
Tercio@22
|
485
|
|
Tercio@22
|
486 if (template.backdrop) then
|
|
Tercioo@29
|
487 self.editbox:SetBackdrop (template.backdrop)
|
|
Tercio@22
|
488 end
|
|
Tercio@22
|
489 if (template.backdropcolor) then
|
|
Tercio@22
|
490 local r, g, b, a = DF:ParseColors (template.backdropcolor)
|
|
Tercioo@29
|
491 self.editbox:SetBackdropColor (r, g, b, a)
|
|
Tercio@22
|
492 self.onleave_backdrop = {r, g, b, a}
|
|
Tercio@22
|
493 end
|
|
Tercio@22
|
494 if (template.backdropbordercolor) then
|
|
Tercio@22
|
495 local r, g, b, a = DF:ParseColors (template.backdropbordercolor)
|
|
Tercioo@29
|
496 self.editbox:SetBackdropBorderColor (r, g, b, a)
|
|
Tercio@22
|
497 self.editbox.current_bordercolor[1] = r
|
|
Tercio@22
|
498 self.editbox.current_bordercolor[2] = g
|
|
Tercio@22
|
499 self.editbox.current_bordercolor[3] = b
|
|
Tercio@22
|
500 self.editbox.current_bordercolor[4] = a
|
|
Tercio@22
|
501 self.onleave_backdrop_border_color = {r, g, b, a}
|
|
Tercio@22
|
502 end
|
|
Tercio@22
|
503 end
|
|
Tercio@22
|
504
|
|
Tercio@22
|
505 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
506 --> object constructor
|
|
Tercio@11
|
507
|
|
Tercio@22
|
508 function DF:CreateTextEntry (parent, func, w, h, member, name, with_label, entry_template, label_template)
|
|
Tercio@22
|
509 return DF:NewTextEntry (parent, parent, name, member, w, h, func, nil, nil, nil, with_label, entry_template, label_template)
|
|
Tercio@11
|
510 end
|
|
Tercio@11
|
511
|
|
Tercio@22
|
512 function DF:NewTextEntry (parent, container, name, member, w, h, func, param1, param2, space, with_label, entry_template, label_template)
|
|
Tercio@11
|
513
|
|
Tercio@11
|
514 if (not name) then
|
|
Tercio@11
|
515 name = "DetailsFrameworkTextEntryNumber" .. DF.TextEntryCounter
|
|
Tercio@11
|
516 DF.TextEntryCounter = DF.TextEntryCounter + 1
|
|
Tercio@11
|
517
|
|
Tercio@11
|
518 elseif (not parent) then
|
|
Tercioo@29
|
519 return error ("Details! FrameWork: parent not found.", 2)
|
|
Tercio@11
|
520 end
|
|
Tercio@11
|
521
|
|
Tercio@11
|
522 if (not container) then
|
|
Tercio@11
|
523 container = parent
|
|
Tercio@11
|
524 end
|
|
Tercio@11
|
525
|
|
Tercio@11
|
526 if (name:find ("$parent")) then
|
|
Tercioo@29
|
527 local parentName = DF.GetParentName (parent)
|
|
Tercioo@29
|
528 name = name:gsub ("$parent", parentName)
|
|
Tercio@11
|
529 end
|
|
Tercio@11
|
530
|
|
Tercio@11
|
531 local TextEntryObject = {type = "textentry", dframework = true}
|
|
Tercio@11
|
532
|
|
Tercio@11
|
533 if (member) then
|
|
Tercio@11
|
534 parent [member] = TextEntryObject
|
|
Tercio@11
|
535 end
|
|
Tercio@11
|
536
|
|
Tercio@11
|
537 if (parent.dframework) then
|
|
Tercio@11
|
538 parent = parent.widget
|
|
Tercio@11
|
539 end
|
|
Tercio@11
|
540 if (container.dframework) then
|
|
Tercio@11
|
541 container = container.widget
|
|
Tercio@11
|
542 end
|
|
Tercio@11
|
543
|
|
Tercio@11
|
544 --> default members:
|
|
Tercio@11
|
545 --> hooks
|
|
Tercio@11
|
546 TextEntryObject.OnEnterHook = nil
|
|
Tercio@11
|
547 TextEntryObject.OnLeaveHook = nil
|
|
Tercio@11
|
548 TextEntryObject.OnHideHook = nil
|
|
Tercio@11
|
549 TextEntryObject.OnShowHook = nil
|
|
Tercio@11
|
550 TextEntryObject.OnEnterPressedHook = nil
|
|
Tercio@11
|
551 TextEntryObject.OnEscapePressedHook = nil
|
|
Tercio@11
|
552 TextEntryObject.OnEditFocusGainedHook = nil
|
|
Tercio@11
|
553 TextEntryObject.OnEditFocusLostHook = nil
|
|
Tercio@11
|
554 TextEntryObject.OnCharHook = nil
|
|
Tercio@11
|
555 TextEntryObject.OnTextChangedHook = nil
|
|
Tercio@11
|
556 TextEntryObject.OnTabPressedHook = nil
|
|
Tercio@11
|
557
|
|
Tercio@11
|
558 --> misc
|
|
Tercio@11
|
559 TextEntryObject.container = container
|
|
Tercio@11
|
560 TextEntryObject.have_tooltip = nil
|
|
Tercio@11
|
561
|
|
Tercio@11
|
562 TextEntryObject.editbox = CreateFrame ("EditBox", name, parent, "DetailsFrameworkEditBoxTemplate2")
|
|
Tercio@11
|
563 TextEntryObject.widget = TextEntryObject.editbox
|
|
Tercio@11
|
564
|
|
Tercio@11
|
565 TextEntryObject.editbox:SetTextInsets (3, 0, 0, -3)
|
|
Tercio@11
|
566
|
|
Tercio@11
|
567 if (not APITextEntryFunctions) then
|
|
Tercio@11
|
568 APITextEntryFunctions = true
|
|
Tercio@11
|
569 local idx = getmetatable (TextEntryObject.editbox).__index
|
|
Tercio@11
|
570 for funcName, funcAddress in pairs (idx) do
|
|
Tercio@11
|
571 if (not TextEntryMetaFunctions [funcName]) then
|
|
Tercio@11
|
572 TextEntryMetaFunctions [funcName] = function (object, ...)
|
|
Tercio@20
|
573 local x = loadstring ( "return _G['"..object.editbox:GetName().."']:"..funcName.."(...)")
|
|
Tercio@11
|
574 return x (...)
|
|
Tercio@11
|
575 end
|
|
Tercio@11
|
576 end
|
|
Tercio@11
|
577 end
|
|
Tercio@11
|
578 end
|
|
Tercio@11
|
579
|
|
Tercio@11
|
580 TextEntryObject.editbox.MyObject = TextEntryObject
|
|
Tercio@11
|
581
|
|
Tercio@11
|
582 if (not w and space) then
|
|
Tercio@11
|
583 w = space
|
|
Tercio@11
|
584 elseif (w and space) then
|
|
Tercio@11
|
585 if (DF.debug) then
|
|
Tercio@11
|
586 print ("warning: you are using width and space, try use only space for better results.")
|
|
Tercio@11
|
587 end
|
|
Tercio@11
|
588 end
|
|
Tercio@11
|
589
|
|
Tercio@11
|
590 TextEntryObject.editbox:SetWidth (w)
|
|
Tercio@11
|
591 TextEntryObject.editbox:SetHeight (h)
|
|
Tercio@11
|
592
|
|
Tercio@11
|
593 TextEntryObject.editbox:SetJustifyH ("center")
|
|
Tercio@11
|
594 TextEntryObject.editbox:EnableMouse (true)
|
|
Tercio@11
|
595 TextEntryObject.editbox:SetText ("")
|
|
Tercio@11
|
596
|
|
Tercio@11
|
597 TextEntryObject.editbox:SetAutoFocus (false)
|
|
Tercio@11
|
598 TextEntryObject.editbox:SetFontObject ("GameFontHighlightSmall")
|
|
Tercio@11
|
599
|
|
Tercio@11
|
600 TextEntryObject.editbox.current_bordercolor = {1, 1, 1, 0.7}
|
|
Tercio@11
|
601 TextEntryObject.editbox:SetBackdropBorderColor (1, 1, 1, 0.7)
|
|
Tercio@11
|
602 TextEntryObject.enabled_border_color = {TextEntryObject.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
603 TextEntryObject.enabled_backdrop_color = {TextEntryObject.editbox:GetBackdropColor()}
|
|
Tercio@11
|
604 TextEntryObject.enabled_text_color = {TextEntryObject.editbox:GetTextColor()}
|
|
Tercio@22
|
605 TextEntryObject.onleave_backdrop = {TextEntryObject.editbox:GetBackdropColor()}
|
|
Tercio@22
|
606 TextEntryObject.onleave_backdrop_border_color = {TextEntryObject.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
607
|
|
Tercio@11
|
608 TextEntryObject.func = func
|
|
Tercio@11
|
609 TextEntryObject.param1 = param1
|
|
Tercio@11
|
610 TextEntryObject.param2 = param2
|
|
Tercio@11
|
611 TextEntryObject.next = nil
|
|
Tercio@11
|
612 TextEntryObject.space = space
|
|
Tercio@11
|
613 TextEntryObject.tab_on_enter = false
|
|
Tercio@11
|
614
|
|
Tercio@11
|
615 TextEntryObject.label = _G [name .. "_Desc"]
|
|
Tercio@11
|
616
|
|
Tercio@11
|
617 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
|
618
|
|
Tercio@11
|
619 --> hooks
|
|
Tercio@11
|
620 TextEntryObject.editbox:SetScript ("OnEnter", OnEnter)
|
|
Tercio@11
|
621 TextEntryObject.editbox:SetScript ("OnLeave", OnLeave)
|
|
Tercio@11
|
622 TextEntryObject.editbox:SetScript ("OnHide", OnHide)
|
|
Tercio@11
|
623 TextEntryObject.editbox:SetScript ("OnShow", OnShow)
|
|
Tercio@11
|
624
|
|
Tercio@11
|
625 TextEntryObject.editbox:SetScript ("OnEnterPressed", OnEnterPressed)
|
|
Tercio@11
|
626 TextEntryObject.editbox:SetScript ("OnEscapePressed", OnEscapePressed)
|
|
Tercio@11
|
627 TextEntryObject.editbox:SetScript ("OnEditFocusLost", OnEditFocusLost)
|
|
Tercio@11
|
628 TextEntryObject.editbox:SetScript ("OnEditFocusGained", OnEditFocusGained)
|
|
Tercio@11
|
629 TextEntryObject.editbox:SetScript ("OnChar", OnChar)
|
|
Tercio@11
|
630 TextEntryObject.editbox:SetScript ("OnTextChanged", OnTextChanged)
|
|
Tercio@11
|
631 TextEntryObject.editbox:SetScript ("OnTabPressed", OnTabPressed)
|
|
Tercio@11
|
632
|
|
Tercio@11
|
633 _setmetatable (TextEntryObject, TextEntryMetaFunctions)
|
|
Tercio@11
|
634
|
|
Tercio@22
|
635 if (with_label) then
|
|
Tercio@22
|
636 local label = DF:CreateLabel (TextEntryObject.editbox, with_label, nil, nil, nil, "label", nil, "overlay")
|
|
Tercio@22
|
637 label.text = with_label
|
|
Tercio@22
|
638 TextEntryObject.editbox:SetPoint ("left", label.widget, "right", 2, 0)
|
|
Tercio@22
|
639 if (label_template) then
|
|
Tercio@22
|
640 label:SetTemplate (label_template)
|
|
Tercio@22
|
641 end
|
|
Tercio@22
|
642 with_label = label
|
|
Tercio@22
|
643 end
|
|
Tercio@11
|
644
|
|
Tercio@22
|
645 if (entry_template) then
|
|
Tercio@22
|
646 TextEntryObject:SetTemplate (entry_template)
|
|
Tercio@22
|
647 end
|
|
Tercio@22
|
648
|
|
Tercio@22
|
649 return TextEntryObject, with_label
|
|
Tercio@22
|
650
|
|
Tercio@22
|
651 end
|
|
Tercio@22
|
652
|
|
Tercio@22
|
653 function DF:NewSpellEntry (parent, func, w, h, param1, param2, member, name)
|
|
Tercio@22
|
654 local editbox = DF:NewTextEntry (parent, parent, name, member, w, h, func, param1, param2)
|
|
Tercio@22
|
655
|
|
Tercio@22
|
656 editbox:SetHook ("OnEditFocusGained", SpellEntryOnEditFocusGained)
|
|
Tercio@22
|
657 editbox:SetHook ("OnTextChanged", SpellEntryOnTextChanged)
|
|
Tercio@22
|
658
|
|
Tercio@22
|
659 return editbox
|
|
Tercio@11
|
660 end
|
|
Tercio@11
|
661
|
|
Tercio@11
|
662 local function_gettext = function (self)
|
|
Tercio@11
|
663 return self.editbox:GetText()
|
|
Tercio@11
|
664 end
|
|
Tercio@11
|
665 local function_settext = function (self, text)
|
|
Tercio@11
|
666 return self.editbox:SetText (text)
|
|
Tercio@11
|
667 end
|
|
Tercio@11
|
668 local function_clearfocus = function (self)
|
|
Tercio@11
|
669 return self.editbox:ClearFocus()
|
|
Tercio@11
|
670 end
|
|
Tercio@11
|
671 local function_setfocus = function (self)
|
|
Tercio@11
|
672 return self.editbox:SetFocus (true)
|
|
Tercio@11
|
673 end
|
|
Tercio@11
|
674
|
|
Tercio@11
|
675 function DF:NewSpecialLuaEditorEntry (parent, w, h, member, name, nointent)
|
|
Tercio@11
|
676
|
|
Tercio@11
|
677 if (name:find ("$parent")) then
|
|
Tercioo@29
|
678 local parentName = DF.GetParentName (parent)
|
|
Tercioo@29
|
679 name = name:gsub ("$parent", parentName)
|
|
Tercio@11
|
680 end
|
|
Tercio@11
|
681
|
|
Tercio@11
|
682 local borderframe = CreateFrame ("Frame", name, parent)
|
|
Tercio@11
|
683 borderframe:SetSize (w, h)
|
|
Tercio@11
|
684
|
|
Tercio@11
|
685 if (member) then
|
|
Tercio@11
|
686 parent [member] = borderframe
|
|
Tercio@11
|
687 end
|
|
Tercio@11
|
688
|
|
Tercio@11
|
689 local scrollframe = CreateFrame ("ScrollFrame", name, borderframe, "DetailsFrameworkEditBoxMultiLineTemplate")
|
|
Tercio@11
|
690
|
|
Tercio@11
|
691 scrollframe:SetScript ("OnSizeChanged", function (self)
|
|
Tercio@11
|
692 scrollframe.editbox:SetSize (self:GetSize())
|
|
Tercio@11
|
693 end)
|
|
Tercio@11
|
694
|
|
Tercio@11
|
695 scrollframe:SetPoint ("topleft", borderframe, "topleft", 10, -10)
|
|
Tercio@11
|
696 scrollframe:SetPoint ("bottomright", borderframe, "bottomright", -30, 10)
|
|
Tercio@11
|
697
|
|
Tercio@11
|
698 scrollframe.editbox:SetMultiLine (true)
|
|
Tercio@11
|
699 scrollframe.editbox:SetJustifyH ("left")
|
|
Tercio@11
|
700 scrollframe.editbox:SetJustifyV ("top")
|
|
Tercio@11
|
701 scrollframe.editbox:SetMaxBytes (1024000)
|
|
Tercio@11
|
702 scrollframe.editbox:SetMaxLetters (128000)
|
|
Tercio@11
|
703
|
|
Tercio@11
|
704 borderframe.GetText = function_gettext
|
|
Tercio@11
|
705 borderframe.SetText = function_settext
|
|
Tercio@11
|
706 borderframe.ClearFocus = function_clearfocus
|
|
Tercio@11
|
707 borderframe.SetFocus = function_setfocus
|
|
Tercio@11
|
708
|
|
Tercio@22
|
709 borderframe.Enable = TextEntryMetaFunctions.Enable
|
|
Tercio@22
|
710 borderframe.Disable = TextEntryMetaFunctions.Disable
|
|
Tercio@22
|
711
|
|
Tercio@22
|
712 borderframe.SetTemplate = TextEntryMetaFunctions.SetTemplate
|
|
Tercio@22
|
713
|
|
Tercio@11
|
714 if (not nointent) then
|
|
Tercio@11
|
715 IndentationLib.enable (scrollframe.editbox, nil, 4)
|
|
Tercio@11
|
716 end
|
|
Tercio@11
|
717
|
|
Tercio@11
|
718 borderframe:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
|
|
Tercio@11
|
719 tile = 1, tileSize = 16, edgeSize = 16, insets = {left = 5, right = 5, top = 5, bottom = 5}})
|
|
Tercio@22
|
720
|
|
Tercio@22
|
721 scrollframe.editbox.current_bordercolor = {1, 1, 1, 0.7}
|
|
Tercio@22
|
722 borderframe:SetBackdropBorderColor (1, 1, 1, 0.7)
|
|
Tercio@11
|
723 borderframe:SetBackdropColor (0.090195, 0.090195, 0.188234, 1)
|
|
Tercio@22
|
724
|
|
Tercio@22
|
725 borderframe.enabled_border_color = {borderframe:GetBackdropBorderColor()}
|
|
Tercio@22
|
726 borderframe.enabled_backdrop_color = {borderframe:GetBackdropColor()}
|
|
Tercio@22
|
727 borderframe.enabled_text_color = {scrollframe.editbox:GetTextColor()}
|
|
Tercio@22
|
728
|
|
Tercio@22
|
729 borderframe.onleave_backdrop = {scrollframe.editbox:GetBackdropColor()}
|
|
Tercio@22
|
730 borderframe.onleave_backdrop_border_color = {scrollframe.editbox:GetBackdropBorderColor()}
|
|
Tercio@11
|
731
|
|
Tercio@11
|
732 borderframe.scroll = scrollframe
|
|
Tercio@11
|
733 borderframe.editbox = scrollframe.editbox
|
|
Tercio@22
|
734 borderframe.editbox.borderframe = borderframe
|
|
Tercio@11
|
735
|
|
Tercio@11
|
736 return borderframe
|
|
Tercio@11
|
737 end |