comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown-Items.lua @ 0:169f5211fc7f

First public revision. At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 20 May 2010 19:22:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:169f5211fc7f
1 --[[ $Id: AceGUIWidget-DropDown-Items.lua 877 2009-11-02 15:56:50Z nevcairiel $ ]]--
2
3 local AceGUI = LibStub("AceGUI-3.0")
4
5 -- Lua APIs
6 local select, assert = select, assert
7
8 -- WoW APIs
9 local CreateFrame = CreateFrame
10
11 local function fixlevels(parent,...)
12 local i = 1
13 local child = select(i, ...)
14 while child do
15 child:SetFrameLevel(parent:GetFrameLevel()+1)
16 fixlevels(child, child:GetChildren())
17 i = i + 1
18 child = select(i, ...)
19 end
20 end
21
22 local function fixstrata(strata, parent, ...)
23 local i = 1
24 local child = select(i, ...)
25 parent:SetFrameStrata(strata)
26 while child do
27 fixstrata(strata, child, child:GetChildren())
28 i = i + 1
29 child = select(i, ...)
30 end
31 end
32
33 -- ItemBase is the base "class" for all dropdown items.
34 -- Each item has to use ItemBase.Create(widgetType) to
35 -- create an initial 'self' value.
36 -- ItemBase will add common functions and ui event handlers.
37 -- Be sure to keep basic usage when you override functions.
38
39 local ItemBase = {
40 -- NOTE: The ItemBase version is added to each item's version number
41 -- to ensure proper updates on ItemBase changes.
42 -- Use at least 1000er steps.
43 version = 1000,
44 counter = 0,
45 }
46
47 function ItemBase.Frame_OnEnter(this)
48 local self = this.obj
49
50 if self.useHighlight then
51 self.highlight:Show()
52 end
53 self:Fire("OnEnter")
54
55 if self.specialOnEnter then
56 self.specialOnEnter(self)
57 end
58 end
59
60 function ItemBase.Frame_OnLeave(this)
61 local self = this.obj
62
63 self.highlight:Hide()
64 self:Fire("OnLeave")
65
66 if self.specialOnLeave then
67 self.specialOnLeave(self)
68 end
69 end
70
71 -- exported, AceGUI callback
72 function ItemBase.OnAcquire(self)
73 self.frame:SetToplevel(true)
74 self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
75 end
76
77 -- exported, AceGUI callback
78 function ItemBase.OnRelease(self)
79 self:SetDisabled(false)
80 self.pullout = nil
81 self.frame:SetParent(nil)
82 self.frame:ClearAllPoints()
83 self.frame:Hide()
84 end
85
86 -- exported
87 -- NOTE: this is called by a Dropdown-Pullout.
88 -- Do not call this method directly
89 function ItemBase.SetPullout(self, pullout)
90 self.pullout = pullout
91
92 self.frame:SetParent(nil)
93 self.frame:SetParent(pullout.itemFrame)
94 self.parent = pullout.itemFrame
95 fixlevels(pullout.itemFrame, pullout.itemFrame:GetChildren())
96 end
97
98 -- exported
99 function ItemBase.SetText(self, text)
100 self.text:SetText(text or "")
101 end
102
103 -- exported
104 function ItemBase.GetText(self)
105 return self.text:GetText()
106 end
107
108 -- exported
109 function ItemBase.SetPoint(self, ...)
110 self.frame:SetPoint(...)
111 end
112
113 -- exported
114 function ItemBase.Show(self)
115 self.frame:Show()
116 end
117
118 -- exported
119 function ItemBase.Hide(self)
120 self.frame:Hide()
121 end
122
123 -- exported
124 function ItemBase.SetDisabled(self, disabled)
125 self.disabled = disabled
126 if disabled then
127 self.useHighlight = false
128 self.text:SetTextColor(.5, .5, .5)
129 else
130 self.useHighlight = true
131 self.text:SetTextColor(1, 1, 1)
132 end
133 end
134
135 -- exported
136 -- NOTE: this is called by a Dropdown-Pullout.
137 -- Do not call this method directly
138 function ItemBase.SetOnLeave(self, func)
139 self.specialOnLeave = func
140 end
141
142 -- exported
143 -- NOTE: this is called by a Dropdown-Pullout.
144 -- Do not call this method directly
145 function ItemBase.SetOnEnter(self, func)
146 self.specialOnEnter = func
147 end
148
149 function ItemBase.Create(type)
150 -- NOTE: Most of the following code is copied from AceGUI-3.0/Dropdown widget
151 local count = AceGUI:GetNextWidgetNum(type)
152 local frame = CreateFrame("Button", "AceGUI30DropDownItem"..count)
153 local self = {}
154 self.frame = frame
155 frame.obj = self
156 self.type = type
157
158 self.useHighlight = true
159
160 frame:SetHeight(17)
161 frame:SetFrameStrata("FULLSCREEN_DIALOG")
162
163 local text = frame:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
164 text:SetTextColor(1,1,1)
165 text:SetJustifyH("LEFT")
166 text:SetPoint("TOPLEFT",frame,"TOPLEFT",18,0)
167 text:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-8,0)
168 self.text = text
169
170 local highlight = frame:CreateTexture(nil, "OVERLAY")
171 highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
172 highlight:SetBlendMode("ADD")
173 highlight:SetHeight(14)
174 highlight:ClearAllPoints()
175 highlight:SetPoint("RIGHT",frame,"RIGHT",-3,0)
176 highlight:SetPoint("LEFT",frame,"LEFT",5,0)
177 highlight:Hide()
178 self.highlight = highlight
179
180 local check = frame:CreateTexture("OVERLAY")
181 check:SetWidth(16)
182 check:SetHeight(16)
183 check:SetPoint("LEFT",frame,"LEFT",3,-1)
184 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
185 check:Hide()
186 self.check = check
187
188 local sub = frame:CreateTexture("OVERLAY")
189 sub:SetWidth(16)
190 sub:SetHeight(16)
191 sub:SetPoint("RIGHT",frame,"RIGHT",-3,-1)
192 sub:SetTexture("Interface\\ChatFrame\\ChatFrameExpandArrow")
193 sub:Hide()
194 self.sub = sub
195
196 frame:SetScript("OnEnter", ItemBase.Frame_OnEnter)
197 frame:SetScript("OnLeave", ItemBase.Frame_OnLeave)
198
199 self.OnAcquire = ItemBase.OnAcquire
200 self.OnRelease = ItemBase.OnRelease
201
202 self.SetPullout = ItemBase.SetPullout
203 self.GetText = ItemBase.GetText
204 self.SetText = ItemBase.SetText
205 self.SetDisabled = ItemBase.SetDisabled
206
207 self.SetPoint = ItemBase.SetPoint
208 self.Show = ItemBase.Show
209 self.Hide = ItemBase.Hide
210
211 self.SetOnLeave = ItemBase.SetOnLeave
212 self.SetOnEnter = ItemBase.SetOnEnter
213
214 return self
215 end
216
217 --[[
218 Template for items:
219
220 -- Item:
221 --
222 do
223 local widgetType = "Dropdown-Item-"
224 local widgetVersion = 1
225
226 local function Constructor()
227 local self = ItemBase.Create(widgetType)
228
229 AceGUI:RegisterAsWidget(self)
230 return self
231 end
232
233 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
234 end
235 --]]
236
237 -- Item: Header
238 -- A single text entry.
239 -- Special: Different text color and no highlight
240 do
241 local widgetType = "Dropdown-Item-Header"
242 local widgetVersion = 1
243
244 local function OnEnter(this)
245 local self = this.obj
246 self:Fire("OnEnter")
247
248 if self.specialOnEnter then
249 self.specialOnEnter(self)
250 end
251 end
252
253 local function OnLeave(this)
254 local self = this.obj
255 self:Fire("OnLeave")
256
257 if self.specialOnLeave then
258 self.specialOnLeave(self)
259 end
260 end
261
262 -- exported, override
263 local function SetDisabled(self, disabled)
264 ItemBase.SetDisabled(self, disabled)
265 if not disabled then
266 self.text:SetTextColor(1, 1, 0)
267 end
268 end
269
270 local function Constructor()
271 local self = ItemBase.Create(widgetType)
272
273 self.SetDisabled = SetDisabled
274
275 self.frame:SetScript("OnEnter", OnEnter)
276 self.frame:SetScript("OnLeave", OnLeave)
277
278 self.text:SetTextColor(1, 1, 0)
279
280 AceGUI:RegisterAsWidget(self)
281 return self
282 end
283
284 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
285 end
286
287 -- Item: Execute
288 -- A simple button
289 do
290 local widgetType = "Dropdown-Item-Execute"
291 local widgetVersion = 1
292
293 local function Frame_OnClick(this, button)
294 local self = this.obj
295 if self.disabled then return end
296 self:Fire("OnClick")
297 if self.pullout then
298 self.pullout:Close()
299 end
300 end
301
302 local function Constructor()
303 local self = ItemBase.Create(widgetType)
304
305 self.frame:SetScript("OnClick", Frame_OnClick)
306
307 AceGUI:RegisterAsWidget(self)
308 return self
309 end
310
311 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
312 end
313
314 -- Item: Toggle
315 -- Some sort of checkbox for dropdown menus.
316 -- Does not close the pullout on click.
317 do
318 local widgetType = "Dropdown-Item-Toggle"
319 local widgetVersion = 2
320
321 local function UpdateToggle(self)
322 if self.value then
323 self.check:Show()
324 else
325 self.check:Hide()
326 end
327 end
328
329 local function OnRelease(self)
330 ItemBase.OnRelease(self)
331 self:SetValue(nil)
332 end
333
334 local function Frame_OnClick(this, button)
335 local self = this.obj
336 if self.disabled then return end
337 self.value = not self.value
338 UpdateToggle(self)
339 self:Fire("OnValueChanged", self.value)
340 end
341
342 -- exported
343 local function SetValue(self, value)
344 self.value = value
345 UpdateToggle(self)
346 end
347
348 -- exported
349 local function GetValue(self)
350 return self.value
351 end
352
353 local function Constructor()
354 local self = ItemBase.Create(widgetType)
355
356 self.frame:SetScript("OnClick", Frame_OnClick)
357
358 self.SetValue = SetValue
359 self.GetValue = GetValue
360 self.OnRelease = OnRelease
361
362 AceGUI:RegisterAsWidget(self)
363 return self
364 end
365
366 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
367 end
368
369 -- Item: Menu
370 -- Shows a submenu on mouse over
371 -- Does not close the pullout on click
372 do
373 local widgetType = "Dropdown-Item-Menu"
374 local widgetVersion = 2
375
376 local function OnEnter(this)
377 local self = this.obj
378 self:Fire("OnEnter")
379
380 if self.specialOnEnter then
381 self.specialOnEnter(self)
382 end
383
384 self.highlight:Show()
385
386 if not self.disabled and self.submenu then
387 self.submenu:Open("TOPLEFT", self.frame, "TOPRIGHT", self.pullout:GetRightBorderWidth(), 0, self.frame:GetFrameLevel() + 100)
388 end
389 end
390
391 local function OnHide(this)
392 local self = this.obj
393 if self.submenu then
394 self.submenu:Close()
395 end
396 end
397
398 -- exported
399 local function SetMenu(self, menu)
400 assert(menu.type == "Dropdown-Pullout")
401 self.submenu = menu
402 end
403
404 -- exported
405 local function CloseMenu(self)
406 self.submenu:Close()
407 end
408
409 local function Constructor()
410 local self = ItemBase.Create(widgetType)
411
412 self.sub:Show()
413
414 self.frame:SetScript("OnEnter", OnEnter)
415 self.frame:SetScript("OnHide", OnHide)
416
417 self.SetMenu = SetMenu
418 self.CloseMenu = CloseMenu
419
420 AceGUI:RegisterAsWidget(self)
421 return self
422 end
423
424 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
425 end
426
427 -- Item: Separator
428 -- A single line to separate items
429 do
430 local widgetType = "Dropdown-Item-Separator"
431 local widgetVersion = 1
432
433 -- exported, override
434 local function SetDisabled(self, disabled)
435 ItemBase.SetDisabled(self, disabled)
436 self.useHighlight = false
437 end
438
439 local function Constructor()
440 local self = ItemBase.Create(widgetType)
441
442 self.SetDisabled = SetDisabled
443
444 local line = self.frame:CreateTexture(nil, "OVERLAY")
445 line:SetHeight(1)
446 line:SetTexture(.5, .5, .5)
447 line:SetPoint("LEFT", self.frame, "LEFT", 10, 0)
448 line:SetPoint("RIGHT", self.frame, "RIGHT", -10, 0)
449
450 self.text:Hide()
451
452 self.useHighlight = false
453
454 AceGUI:RegisterAsWidget(self)
455 return self
456 end
457
458 AceGUI:RegisterWidgetType(widgetType, Constructor, widgetVersion + ItemBase.version)
459 end