comparison Gui.lua @ 65:d3f64d7246b3

Significant effort to start making the GUI behave in an intuitive way. But it's still completely useless ...
author John@Yosemite-PC
date Mon, 26 Mar 2012 23:47:24 -0400
parents 00cb497201d0
children 8387dc2ff658
comparison
equal deleted inserted replaced
64:f0450883c283 65:d3f64d7246b3
1 local AceGUI = LibStub("AceGUI-3.0") 1 local AceGUI = LibStub("AceGUI-3.0")
2 local bsk=bsk 2 local bsk=bsk
3 local _G=_G 3 local _G=_G
4 local table=table 4 local table=table
5 local pairs=pairs 5 local pairs=pairs
6 local setmetatable=setmetatable
6 local ipairs=ipairs 7 local ipairs=ipairs
7 local string=string 8 local string=string
8 local tostring=tostring 9 local tostring=tostring
9 local type=type 10 local type=type
10 local getn=getn 11 local getn=getn
47 pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:SetList(value) end) 48 pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:SetList(value) end)
48 if ltemp > 0 then pulldown:SetValue(ltemp); SListPopulator:SetList(ltemp) end -- sadly, SetValue doesn't fire a OnValueChanged 49 if ltemp > 0 then pulldown:SetValue(ltemp); SListPopulator:SetList(ltemp) end -- sadly, SetValue doesn't fire a OnValueChanged
49 return pulldown 50 return pulldown
50 end 51 end
51 52
52 local f 53 local f, right
53 local escapeButton = 54 local escapeButton =
54 { 55 {
55 shown = false, 56 shown = false,
56 ["IsShown"] = function(self) return self.shown end, 57 ["IsShown"] = function(self) return self.shown end,
57 ["Hide"] = function(self) if f then AceGUI:Release(f); self.shown=false end end 58 ["Hide"] = function(self) if f then AceGUI:Release(f); self.shown=false end end
58 } 59 }
59 60
60 local function FilterEventDispatcher() 61
61 end 62 SelectorListEventDispatcher =
62
63 SListEventDispatch =
64 { 63 {
65 listeners= {}, 64 listeners = nil,
66 target = nil, 65 target = nil,
67 ["SetTarget"] = function(self,other) 66 ["SetTarget"] = function(self,other)
68 self.target = other 67 self.target = other
69 self.target:SetCallback("OnSelectionCleared",SListListenerRebindOSC) 68 self.target:SetCallback("OnSelectionCleared",function(...) self:OnSelectionCleared(...) end)
70 self.target:SetCallback("OnSelection",SListListenerRebindOS) 69 self.target:SetCallback("OnSelection",function(...) self:OnSelection(...) end)
71 end, 70 end,
72 ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end, 71 ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end,
73 ["OnSelectionCleared"] = function(self,_) 72 ["OnSelectionCleared"] = function(self,_)
74 self:Event("OnSelectionCleared") 73 self:Event("OnSelectionCleared")
75 end, 74 end,
76 ["OnSelection"] = function(self,_,line) 75 ["OnSelection"] = function(self,_,_,line)
77 self:Event("OnSelection",line) 76 self:Event("OnSelection",line)
78 end, 77 end,
79 ["Event"] = function(self,event,arg) 78 ["Event"] = function(self,event,arg)
80 if not self.target then error("Event called with no listener...") end 79 if not self.target then error("Event called with no listener...") end
81 if not self.listeners then return end 80 if not self.listeners then return end
82 for i,v in pairs(self.listeners) do 81 for i,v in pairs(self.listeners) do
82 bsk.print("listener")
83 if type(v) == "table" then 83 if type(v) == "table" then
84 if v[event] then 84 if v[event] then
85 v[event](v,arg) 85 v[event](v,arg)
86 end 86 end
87 elseif type(v) == "function" then 87 elseif type(v) == "function" then
89 elseif type(v) ~= "nil" then -- allow nils to pass quietly 89 elseif type(v) ~= "nil" then -- allow nils to pass quietly
90 _G.error("Bad listener - "..type(v)) 90 _G.error("Bad listener - "..type(v))
91 end 91 end
92 end 92 end
93 end, 93 end,
94 ["Release"] = function(self) self.listeners = {}; target=nil end 94 ["Release"] = function(self) self.listeners = {}; self.target=nil end
95 } 95 }
96 function SListListenerRebindOSC(...) 96 function SelectorListEventDispatcher:new()
97 SListEventDispatch:OnSelectionCleared(...) 97 local t = {}
98 setmetatable(t,SelectorListEventDispatcher)
99 self.__index = self
100 t.listeners = {}
101 return t
98 end 102 end
99 function SListListenerRebindOS(...) 103
100 SListEventDispatch:OnSelection(...) 104 SListEventDispatch = SelectorListEventDispatcher:new()
101 end 105 LListEventDispatch = SelectorListEventDispatcher:new()
106
107 local AdminLootEventCollector =
108 {
109 listeners = {},
110 target1 =
111 {
112 },
113 target2 =
114 {
115 },
116
117
118 }
119
102 local SListPopulator = 120 local SListPopulator =
103 { 121 {
104 filtered = false, 122 filtered = false,
105 widget = nil, 123 widget = nil,
106 data = nil, 124 data = nil,
119 line.disabled = disabled 137 line.disabled = disabled
120 table.insert(self.data,line) 138 table.insert(self.data,line)
121 end 139 end
122 end 140 end
123 self.widget:SetList(self.data) 141 self.widget:SetList(self.data)
142 SListEventDispatch:Event("Redraw")
124 end, 143 end,
125 ["SetWidget"] = function(self,w) 144 ["SetWidget"] = function(self,w)
126 if type(w) ~= "table" or w["SetList"] == nil then 145 if type(w) ~= "table" or type(w.SetList) ~= "function" then
127 _G.error("Bad SetWidget") 146 _G.error("Bad SetWidget")
128 end 147 end
129 self.widget = w 148 self.widget = w
130 end, 149 end,
131 ["SetFiltered"] = function(self,value) 150 ["SetFiltered"] = function(self,value)
146 165
147 if f then return end -- no second gui please 166 if f then return end -- no second gui please
148 local admin = bsk.admin or true 167 local admin = bsk.admin or true
149 f = AceGUI:Create("Frame") 168 f = AceGUI:Create("Frame")
150 169
151 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; SListEventDispatch:Release(); SListPopulator:Release() end) 170 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release() end)
152 f:SetTitle("BSK") 171 f:SetTitle("BSK")
153 f:SetLayout("Flow") 172 f:SetLayout("Flow")
154 f:SetHeight(680) 173 f:SetHeight(680)
155 f:SetWidth(580) 174 f:SetWidth(580)
156 175
158 left:SetLayout("List") 177 left:SetLayout("List")
159 left:SetWidth(175) 178 left:SetWidth(175)
160 left:SetFullHeight(true) 179 left:SetFullHeight(true)
161 left.alignoffset=0.25 -- hack, as per http://forums.wowace.com/showthread.php?t=17114 180 left.alignoffset=0.25 -- hack, as per http://forums.wowace.com/showthread.php?t=17114
162 181
163 local right = AceGUI:Create("InlineGroup") 182 right = AceGUI:Create("InlineGroup")
164 right:SetLayout("Flow") 183 right:SetLayout("Flow")
165 right:SetWidth(700-175-160) 184 right:SetWidth(700-175-160)
166 right:SetFullHeight(true) 185 right:SetFullHeight(true)
167 right.alignoffset=0.25 186 right.alignoffset=0.25
168 187
208 value=5, 227 value=5,
209 text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r", 228 text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
210 link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r" 229 link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
211 }, 230 },
212 }) 231 })
232 LListEventDispatch:SetTarget(t2)
233
234 local biddingZone = AceGUI:Create("SimpleGroup")
235 biddingZone:SetLayout("Flow")
236 biddingZone:SetFullWidth(true)
213 237
214 local alb1, alb2, alb3 238 local alb1, alb2, alb3
215 if admin then 239 if admin then
216 alb1 = AceGUI:Create("Button") 240 alb1 = AceGUI:Create("Button")
217 alb1:SetWidth(100) 241 alb1:SetWidth(100)
218 alb1:SetText("Open Bids") 242 alb1:SetText("Open Bids")
243 alb1.userdata =
244 {
245 state = false,
246 widget = alb1,
247 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end,
248 ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end,
249 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end
250 }
251 alb1:SetDisabled(true)
252 LListEventDispatch:RegisterListener(alb1.userdata)
253 alb1:SetCallback("OnClick",
254 function(widget)
255 if widget.userdata.state then -- we were bidding when the button was pressed
256 biddingZone:ReleaseChildren()
257 else
258 local spacer = AceGUI:Create("Label")
259 spacer:SetText(" ")
260 spacer:SetFullWidth(true)
261 local spacer2 = AceGUI:Create("Label")
262 spacer2:SetText(" ")
263 spacer2:SetFullWidth(true)
264
265 local label = AceGUI:Create("Label")
266 label:SetText("Bidding now open for ...")
267 local biddingOn = AceGUI:Create("InteractiveLabel")
268 biddingOn.userdata = { "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r" }
269 biddingOn:SetText(biddingOn.userdata[1])
270 biddingOn:SetFullWidth(true)
271 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
272 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
273 local b1 = AceGUI:Create("SelectorList")
274 b1:SetNumLines(6)
275 b1:SetInteractive(admin)
276 local dummydata= {}
277 local tree =SListPopulator.data
278 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
279 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
280 b1:SetList(dummydata)
281 local bidTitle = AceGUI:Create("Label")
282 bidTitle:SetText("Current bids")
283 bidTitle:SetFullWidth(true)
284
285 local bidRetractButton = AceGUI:Create("Button")
286 bidRetractButton:SetText("Place Bid")
287 bidRetractButton:SetWidth(100)
288 local rollButton = AceGUI:Create("Button")
289 rollButton:SetText("Offset Roll")
290 rollButton:SetWidth(100)
291
292 local g1
293 if admin then
294 b1.alignoffset = 0.25 -- or else g1 won't align well
295 g1 = AceGUI:Create("SimpleGroup")
296 g1.alignoffset = 0.25
297 g1:SetWidth(120)
298 g1:SetLayout("List")
299
300 adminForce = AceGUI:Create("Button")
301 adminForce:SetText("Force bid")
302 adminForce:SetWidth(100)
303
304 adminRetract = AceGUI:Create("Button")
305 adminRetract:SetText("Retract bid")
306 adminRetract:SetWidth(100)
307
308 g1:AddChildren(adminForce,adminRetract)
309 end
310
311 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
312 if admin then biddingZone:AddChildren(g1) end
313
314
315 end
316 widget.userdata.state = not widget.userdata.state
317 end
318 )
219 319
220 alb2 = AceGUI:Create("Button") 320 alb2 = AceGUI:Create("Button")
221 alb2:SetWidth(100) 321 alb2:SetWidth(100)
222 alb2:SetText("Assign") 322 alb2:SetText("Assign")
323 alb2.userdata =
324 {
325 widget = alb2,
326 ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
327 }
328 alb2.userdata.slist =
329 {
330 parent = alb2.userdata,
331 checked = false,
332 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
333 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
334 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
335 }
336 alb2.userdata.llist =
337 {
338 parent = alb2.userdata,
339 checked = false,
340 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
341 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
342 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
343 }
344 SListEventDispatch:RegisterListener(alb2.userdata.slist)
345 LListEventDispatch:RegisterListener(alb2.userdata.llist)
223 346
224 alb3 = AceGUI:Create("Button") 347 alb3 = AceGUI:Create("Button")
225 alb3:SetWidth(100) 348 alb3:SetWidth(100)
226 alb3:SetText("Suicide") 349 alb3:SetText("Suicide")
350 alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this ....
351 {
352 widget = alb3,
353 ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
354 }
355 alb3.userdata.slist =
356 {
357 parent = alb3.userdata,
358 checked = false,
359 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
360 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
361 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
362 }
363 alb3.userdata.llist =
364 {
365 parent = alb3.userdata,
366 checked = false,
367 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
368 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
369 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
370 }
371 SListEventDispatch:RegisterListener(alb3.userdata.slist)
372 LListEventDispatch:RegisterListener(alb3.userdata.llist)
227 end 373 end
228 374
229 local spacer = AceGUI:Create("Label") 375 local suicideSelected, undo
230 spacer:SetText(" ")
231 spacer:SetFullWidth(true)
232 local spacer2 = AceGUI:Create("Label")
233 spacer2:SetText(" ")
234 spacer2:SetFullWidth(true)
235
236 local biddingZone = AceGUI:Create("SimpleGroup")
237 biddingZone:SetLayout("Flow")
238 biddingZone:SetFullWidth(true)
239
240 local label = AceGUI:Create("Label")
241 label:SetText("Bidding now open for ...")
242 local biddingOn = AceGUI:Create("InteractiveLabel")
243 biddingOn.userdata = { "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r" }
244 biddingOn:SetText(biddingOn.userdata[1])
245 biddingOn:SetFullWidth(true)
246 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
247 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
248 local b1 = AceGUI:Create("SelectorList")
249 b1:SetNumLines(6)
250 b1:SetInteractive(admin)
251 local dummydata= {}
252 local tree =SListPopulator.data
253 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
254 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
255 b1:SetList(dummydata)
256 local bidTitle = AceGUI:Create("Label")
257 bidTitle:SetText("Current bids")
258 bidTitle:SetFullWidth(true)
259
260 local bidRetractButton = AceGUI:Create("Button")
261 bidRetractButton:SetText("Place Bid")
262 bidRetractButton:SetWidth(100)
263 local rollButton = AceGUI:Create("Button")
264 rollButton:SetText("Offset Roll")
265 rollButton:SetWidth(100)
266
267 local g1, suicideSelected, undo
268 if admin then 376 if admin then
269 b1.alignoffset = 0.25 -- or else g1 won't align well
270 g1 = AceGUI:Create("SimpleGroup")
271 g1.alignoffset = 0.25
272 g1:SetWidth(120)
273 g1:SetLayout("List")
274
275 adminForce = AceGUI:Create("Button")
276 adminForce:SetText("Force bid")
277 adminForce:SetWidth(100)
278
279 adminRetract = AceGUI:Create("Button")
280 adminRetract:SetText("Retract bid")
281 adminRetract:SetWidth(100)
282
283 g1:AddChildren(adminForce,adminRetract)
284 377
285 suicideSelected = AceGUI:Create("Button") 378 suicideSelected = AceGUI:Create("Button")
286 suicideSelected:SetFullWidth(true) 379 suicideSelected:SetFullWidth(true)
287 suicideSelected:SetText("Suicide") 380 suicideSelected:SetText("Suicide")
288 suicideSelected:SetDisabled(true) -- default is no selection has been made
289 -- use userdata + SListEventDispatch to toggle state 381 -- use userdata + SListEventDispatch to toggle state
290 suicideSelected.userdata = 382 suicideSelected.userdata =
291 { 383 {
292 widget = suicideSelected, 384 widget = suicideSelected,
385 ["Redraw"] = function(self,_) self.widget:SetDisabled(true) end,
293 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false) end, 386 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false) end,
294 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true) end 387 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true) end
295 } 388 }
296 SListEventDispatch:RegisterListener(suicideSelected.userdata) 389 SListEventDispatch:RegisterListener(suicideSelected.userdata)
297 390
298 undo = AceGUI:Create("Button") 391 undo = AceGUI:Create("Button")
299 undo:SetText("Undo / out of order") 392 undo:SetText("Undo / out of order")
300 undo:SetFullWidth(true) 393 undo:SetFullWidth(true)
301 undo:SetDisabled(true) 394 undo:SetDisabled(true)
302 end 395 end
303
304 396
305 local filter = AceGUI:Create("CheckBox") 397 local filter = AceGUI:Create("CheckBox")
306 filter:SetLabel("Only show active") 398 filter:SetLabel("Only show active")
307 filter:SetFullWidth(true) 399 filter:SetFullWidth(true)
308 filter:SetValue(false) 400 filter:SetValue(false)
309 SListPopulator:SetFiltered(false) 401 SListPopulator:SetFiltered(false)
310 filter:SetCallback("OnValueChanged",function(widget,_,value) SListPopulator:SetFiltered(value) end) 402 filter:SetCallback("OnValueChanged",function(widget,_,value) SListPopulator:SetFiltered(value) end)
311 403
312 left:AddChildren(filter) 404 left:AddChildren(filter)
313 if admin then left:AddChildren(suicideSelected,undo) end 405 if admin then left:AddChildren(suicideSelected,undo) end
314 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
315 if admin then biddingZone:AddChildren(g1) end
316 right:AddChildren(t2) 406 right:AddChildren(t2)
317 if admin then right:AddChildren(alb1,alb2,alb3) end 407 if admin then right:AddChildren(alb1,alb2,alb3) end
318 right:AddChildren(biddingZone) 408 right:AddChildren(biddingZone)
319 f:AddChildren(left,right) 409 f:AddChildren(left,right)
320 410