comparison Gui.lua @ 75:ed1c9fd4cc95

Progress on bidding events and GUI. Slave GUIs now respond properly.
author John@Doomsday
date Mon, 09 Apr 2012 09:40:53 -0400
parents 7eb2963eea7d
children 39be9328acd0
comparison
equal deleted inserted replaced
74:15844864a5f7 75:ed1c9fd4cc95
169 end, 169 end,
170 ["DataEvent"] = function(self) 170 ["DataEvent"] = function(self)
171 self:Redraw() 171 self:Redraw()
172 end, 172 end,
173 ["StateEvent"] = function(self) 173 ["StateEvent"] = function(self)
174 -- todo: events still happen even if the gui is closed. protect the api.
175
174 print("State event in SL: ", state, admin) 176 print("State event in SL: ", state, admin)
175 if state == "bidding" or (state == "looting" and not admin) then 177 if state == "bidding" or (state == "looting" and not admin) then
176 self.swidget:SetDisabled(true) 178 self.swidget:SetDisabled(true)
177 self:SelectList(stateactivelist) 179 self:SelectList(stateactivelist)
178 elseif state == "looting" and admin then
179 self.swidget:SetDisabled(false)
180 else 180 else
181 self.swidget:SetDisabled(false) 181 self.swidget:SetDisabled(false)
182 end 182 end
183 -- if bidding then disable pulldown 183 -- if bidding then disable pulldown
184 -- if looting and not admin then disable pulldown 184 -- if looting and not admin then disable pulldown
303 end 303 end
304 return new 304 return new
305 end, 305 end,
306 } 306 }
307 307
308 local BZPopulator =
309 {
310 group = nil,
311 ["SetGroup"] = function(self,g)
312 if type(g) ~= "table" or type(g.AddChild) ~= "function" then
313 _G.error("Bad SetGroup for BZPopulator")
314 end
315 self.group = g
316 end,
317
318
319 ["Release"] = function(self) self.group = nil; RListEventDispatch:Release(); RListPopulator:Release() end,
320
321 ["StateEvent"] = function(self)
322 if state == "bidding" then
323
324 local spacer = AceGUI:Create("Label")
325 spacer:SetText(" ")
326 spacer:SetFullWidth(true)
327 local spacer2 = AceGUI:Create("Label")
328 spacer2:SetText(" ")
329 spacer2:SetFullWidth(true)
330
331 local label = AceGUI:Create("Label")
332 label:SetText("Bidding now open for ...")
333 local biddingOn = AceGUI:Create("InteractiveLabel")
334 biddingOn.userdata = { stateitem.link }
335 biddingOn:SetText(biddingOn.userdata[1])
336 biddingOn:SetFullWidth(true)
337 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
338 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
339 local b1 = AceGUI:Create("SelectorList")
340 b1:SetNumLines(6)
341 b1:SetInteractive(admin)
342 local bidTitle = AceGUI:Create("Label")
343 bidTitle:SetText("Current bids")
344 bidTitle:SetFullWidth(true)
345
346 local bidRetractButton = AceGUI:Create("Button")
347 bidRetractButton:SetText("Place Bid")
348 bidRetractButton:SetWidth(100)
349 bidRetractButton:SetCallback("OnClick", function(widget) RListPopulator:Force(SListPopulator:GetMe()) end) -- todo: Force is not the desired thing here.
350 local rollButton = AceGUI:Create("Button")
351 rollButton:SetText("Offset Roll")
352 rollButton:SetWidth(100)
353
354 RListEventDispatch:SetTarget(b1)
355 RListPopulator:SetWidget(b1)
356
357
358 local g1
359 if admin then
360 b1.alignoffset = 0.25 -- or else g1 won't align well
361 g1 = AceGUI:Create("SimpleGroup")
362 g1.alignoffset = 0.25
363 g1:SetWidth(120)
364 g1:SetLayout("List")
365
366 -- todo: convoluted and repetitive - surely there's a
367 -- better way than this ...
368 adminForce = AceGUI:Create("Button")
369 if SListEventDispatch:LatestValue() then
370 adminForce:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain))
371 adminForce:SetDisabled(false)
372 else
373 adminForce:SetText("Force bid")
374 adminForce:SetDisabled(true)
375 end
376 adminForce:SetWidth(160)
377 adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end)
378 adminForce.userdata =
379 {
380 widget = adminForce,
381 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end,
382 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end,
383 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end
384 }
385 SListEventDispatch:RegisterListener(adminForce.userdata)
386
387 adminRetract = AceGUI:Create("Button")
388 if RListEventDispatch:LatestValue() then
389 adminRetract:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain))
390 adminRetract:SetDisabled(false)
391 else
392 adminRetract:SetText("Retract bid")
393 adminRetract:SetDisabled(true)
394 end
395 adminRetract:SetWidth(160)
396 adminRetract.userdata =
397 {
398 widget = adminRetract,
399 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end,
400 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end,
401 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end
402 }
403 adminRetract:SetCallback("OnClick",function(widget) RListPopulator:Retract(RListEventDispatch:LatestValue()) end)
404 RListEventDispatch:RegisterListener(adminRetract.userdata)
405 adminRetract:SetDisabled(true)
406
407 g1:AddChildren(adminForce,adminRetract)
408 end
409
410 self.group:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
411 if admin then self.group:AddChildren(g1) end
412
413 else
414
415
416 self.group:ReleaseChildren()
417 RListEventDispatch:Release()
418 RListPopulator:Release()
419 end
420
421 end,
422
423
424 }
425
308 DataEventDispatch = 426 DataEventDispatch =
309 { 427 {
310 -- todo: batch events 428 -- todo: batch events
311 listeners = {}, 429 listeners = {},
312 ["DataEvent"] = function(self,_) --todo: pass along the received event 430 ["DataEvent"] = function(self,_) --todo: pass along the received event
329 DataEventDispatch:RegisterListener(SListPopulator) 447 DataEventDispatch:RegisterListener(SListPopulator)
330 RegisterListenerActiveListChanged(SListPopulator) 448 RegisterListenerActiveListChanged(SListPopulator)
331 RegisterListenerStateChange(SListPopulator) 449 RegisterListenerStateChange(SListPopulator)
332 RegisterListenerRolls(RListPopulator) 450 RegisterListenerRolls(RListPopulator)
333 RegisterItemListListener(LListPopulator) 451 RegisterItemListListener(LListPopulator)
452 RegisterListenerStateChange(BZPopulator)
334 end 453 end
335 454
336 function CreateGUI() 455 function CreateGUI()
337 -- special registration procedure to be closable with the escape button 456 -- special registration procedure to be closable with the escape button
338 --escapeButton.shown = true 457 --escapeButton.shown = true
340 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON") 459 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON")
341 460
342 if f then return end -- no second gui please 461 if f then return end -- no second gui please
343 f = AceGUI:Create("Frame") 462 f = AceGUI:Create("Frame")
344 463
345 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release(); RListEventDispatch:Release(); LListPopulator:Release(); RListPopulator:Release() end) 464 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release(); RListEventDispatch:Release(); LListPopulator:Release(); RListPopulator:Release(); BZPopulator:Release() end)
346 f:SetTitle("BSK") 465 f:SetTitle("BSK")
347 f:SetLayout("Flow") 466 f:SetLayout("Flow")
348 f:SetHeight(680) 467 f:SetHeight(680)
349 f:SetWidth(580) 468 f:SetWidth(580)
350 469
378 t2:SetFullWidth(true) 497 t2:SetFullWidth(true)
379 t2:EnableButtonTooltips(true) 498 t2:EnableButtonTooltips(true)
380 LListEventDispatch:SetTarget(t2) 499 LListEventDispatch:SetTarget(t2)
381 LListPopulator:SetWidget(t2) 500 LListPopulator:SetWidget(t2)
382 501
383 local biddingZone = AceGUI:Create("SimpleGroup") 502 biddingZone = AceGUI:Create("SimpleGroup")
384 biddingZone:SetLayout("Flow") 503 biddingZone:SetLayout("Flow")
385 biddingZone:SetFullWidth(true) 504 biddingZone:SetFullWidth(true)
505 BZPopulator:SetGroup(biddingZone)
386 506
387 local alb1, alb2, alb3 507 local alb1, alb2, alb3
388 if admin then 508 if admin then
389 alb1 = AceGUI:Create("Button") 509 alb1 = AceGUI:Create("Button")
390 alb1:SetWidth(100) 510 alb1:SetWidth(100)
400 alb1:SetDisabled(true) 520 alb1:SetDisabled(true)
401 LListEventDispatch:RegisterListener(alb1.userdata) 521 LListEventDispatch:RegisterListener(alb1.userdata)
402 alb1:SetCallback("OnClick", 522 alb1:SetCallback("OnClick",
403 function(widget) 523 function(widget)
404 if widget.userdata.state then -- we were bidding when the button was pressed 524 if widget.userdata.state then -- we were bidding when the button was pressed
405 biddingZone:ReleaseChildren()
406 widget:SetText("Open Bids") 525 widget:SetText("Open Bids")
407 RListEventDispatch:Release() 526 InitiateCloseBidding() -- todo: plug in loot award, etc
408 RListPopulator:Release()
409 else 527 else
410 widget:SetText("Close bids") 528 widget:SetText("Close bids")
411 local spacer = AceGUI:Create("Label")
412 spacer:SetText(" ")
413 spacer:SetFullWidth(true)
414 local spacer2 = AceGUI:Create("Label")
415 spacer2:SetText(" ")
416 spacer2:SetFullWidth(true)
417
418 local label = AceGUI:Create("Label")
419 label:SetText("Bidding now open for ...")
420 local biddingOn = AceGUI:Create("InteractiveLabel")
421 biddingOn.userdata = { LListEventDispatch:LatestValue().link }
422 biddingOn:SetText(biddingOn.userdata[1])
423 biddingOn:SetFullWidth(true)
424 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
425 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
426 local b1 = AceGUI:Create("SelectorList")
427 b1:SetNumLines(6)
428 b1:SetInteractive(admin)
429 local bidTitle = AceGUI:Create("Label")
430 bidTitle:SetText("Current bids")
431 bidTitle:SetFullWidth(true)
432
433 local bidRetractButton = AceGUI:Create("Button")
434 bidRetractButton:SetText("Place Bid")
435 bidRetractButton:SetWidth(100)
436 bidRetractButton:SetCallback("OnClick", function(widget) RListPopulator:Force(SListPopulator:GetMe()) end) -- todo: Force is not the desired thing here.
437 local rollButton = AceGUI:Create("Button")
438 rollButton:SetText("Offset Roll")
439 rollButton:SetWidth(100)
440
441 RListEventDispatch:SetTarget(b1)
442 RListPopulator:SetWidget(b1)
443
444 InitiateOpenBid(LListEventDispatch:LatestValue()) 529 InitiateOpenBid(LListEventDispatch:LatestValue())
445
446 local g1
447 if admin then
448 b1.alignoffset = 0.25 -- or else g1 won't align well
449 g1 = AceGUI:Create("SimpleGroup")
450 g1.alignoffset = 0.25
451 g1:SetWidth(120)
452 g1:SetLayout("List")
453
454 -- todo: convoluted and repetitive - surely there's a
455 -- better way than this ...
456 adminForce = AceGUI:Create("Button")
457 if SListEventDispatch:LatestValue() then
458 adminForce:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain))
459 adminForce:SetDisabled(false)
460 else
461 adminForce:SetText("Force bid")
462 adminForce:SetDisabled(true)
463 end
464 adminForce:SetWidth(160)
465 adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end)
466 adminForce.userdata =
467 {
468 widget = adminForce,
469 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end,
470 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end,
471 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end
472 }
473 SListEventDispatch:RegisterListener(adminForce.userdata)
474
475 adminRetract = AceGUI:Create("Button")
476 if RListEventDispatch:LatestValue() then
477 adminRetract:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain))
478 adminRetract:SetDisabled(false)
479 else
480 adminRetract:SetText("Retract bid")
481 adminRetract:SetDisabled(true)
482 end
483 adminRetract:SetWidth(160)
484 adminRetract.userdata =
485 {
486 widget = adminRetract,
487 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end,
488 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end,
489 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end
490 }
491 adminRetract:SetCallback("OnClick",function(widget) RListPopulator:Retract(RListEventDispatch:LatestValue()) end)
492 RListEventDispatch:RegisterListener(adminRetract.userdata)
493 adminRetract:SetDisabled(true)
494
495 g1:AddChildren(adminForce,adminRetract)
496 end
497
498 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
499 if admin then biddingZone:AddChildren(g1) end
500 end 530 end
501 widget.userdata.state = not widget.userdata.state 531 widget.userdata.state = not widget.userdata.state
502 end 532 end
503 ) 533 )
504 534