comparison Gui.lua @ 76:39be9328acd0

Turning bidding admin buttons into state responders Starting to integrate master looting along with the bids
author John@Yosemite-PC
date Tue, 10 Apr 2012 23:50:07 -0400
parents ed1c9fd4cc95
children 5b507f4125d4
comparison
equal deleted inserted replaced
75:ed1c9fd4cc95 76:39be9328acd0
201 end, 201 end,
202 } 202 }
203 203
204 local LListPopulator = 204 local LListPopulator =
205 { 205 {
206 -- todo: set event receivers from the comm and for loot
207 data = {}, 206 data = {},
208 widget = nil, 207 widget = nil,
209 ["Release"] = function(self) self.data = {}; self.widget = nil end, 208 ["Release"] = function(self) self.data = {}; self.widget = nil end,
210 ["ItemListEvent"] = function(self) self:Redraw() end, 209 ["ItemListEvent"] = function(self) self:Redraw() end,
211 ["Redraw"]= function(self) 210 ["Redraw"]= function(self)
222 ["SetWidget"] = function(self,w) 221 ["SetWidget"] = function(self,w)
223 if type(w) ~= "table" or type(w.SetList) ~= "function" then 222 if type(w) ~= "table" or type(w.SetList) ~= "function" then
224 _G.error("Bad SetWidget") 223 _G.error("Bad SetWidget")
225 end 224 end
226 self.widget = w 225 self.widget = w
227 if debug then 226 --if debug then
228 self.data = { 227 -- self.data = {
229 { 228 -- {
230 value=1, 229 -- value=1,
231 text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r", 230 -- text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
232 link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r", 231 -- link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
233 }, 232 -- },
234 { 233 -- {
235 value=2, 234 -- value=2,
236 text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r", 235 -- text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r",
237 link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r" 236 -- link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r"
238 }, 237 -- },
239 { 238 -- {
240 value=3, 239 -- value=3,
241 text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r", 240 -- text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r",
242 link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r" 241 -- link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r"
243 }, 242 -- },
244 { 243 -- {
245 value=4, 244 -- value=4,
246 text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r", 245 -- text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r",
247 link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r" 246 -- link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r"
248 }, 247 -- },
249 { 248 -- {
250 value=5, 249 -- value=5,
251 text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r", 250 -- text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
252 link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r" 251 -- link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
253 }, 252 -- },
254 } 253 -- }
255 end 254 --end
256 self:Redraw() 255 self:Redraw()
257 end, 256 end,
258 } 257 }
259 258
260 local RListPopulator = 259 local RListPopulator =
322 if state == "bidding" then 321 if state == "bidding" then
323 322
324 local spacer = AceGUI:Create("Label") 323 local spacer = AceGUI:Create("Label")
325 spacer:SetText(" ") 324 spacer:SetText(" ")
326 spacer:SetFullWidth(true) 325 spacer:SetFullWidth(true)
327 local spacer2 = AceGUI:Create("Label") 326 local spacer2 = AceGUI:Create("Label") -- don't try to combine this with "spacer" - you can't add a child more than once
328 spacer2:SetText(" ") 327 spacer2:SetText(" ")
329 spacer2:SetFullWidth(true) 328 spacer2:SetFullWidth(true)
330 329
331 local label = AceGUI:Create("Label") 330 local label = AceGUI:Create("Label")
332 label:SetText("Bidding now open for ...") 331 label:SetText("Bidding now open for ...")
344 bidTitle:SetFullWidth(true) 343 bidTitle:SetFullWidth(true)
345 344
346 local bidRetractButton = AceGUI:Create("Button") 345 local bidRetractButton = AceGUI:Create("Button")
347 bidRetractButton:SetText("Place Bid") 346 bidRetractButton:SetText("Place Bid")
348 bidRetractButton:SetWidth(100) 347 bidRetractButton:SetWidth(100)
349 bidRetractButton:SetCallback("OnClick", function(widget) RListPopulator:Force(SListPopulator:GetMe()) end) -- todo: Force is not the desired thing here. 348 bidRetractButton:SetCallback("OnClick", function(widget) InitiateBid(SListPopulator:GetMe()) end)
349
350 local rollButton = AceGUI:Create("Button") 350 local rollButton = AceGUI:Create("Button")
351 rollButton:SetText("Offset Roll") 351 rollButton:SetText("Offset Roll")
352 rollButton:SetWidth(100) 352 rollButton:SetWidth(100)
353 -- todo: callback
353 354
354 RListEventDispatch:SetTarget(b1) 355 RListEventDispatch:SetTarget(b1)
355 RListPopulator:SetWidget(b1) 356 RListPopulator:SetWidget(b1)
356
357 357
358 local g1 358 local g1
359 if admin then 359 if admin then
360 b1.alignoffset = 0.25 -- or else g1 won't align well 360 b1.alignoffset = 0.25 -- or else g1 won't align well
361 g1 = AceGUI:Create("SimpleGroup") 361 g1 = AceGUI:Create("SimpleGroup")
440 end 440 end
441 table.insert(self.listeners,listener) 441 table.insert(self.listeners,listener)
442 end 442 end
443 } 443 }
444 444
445 AdminLootButtons =
446 {
447 openButton = nil,
448 assignButton = nil,
449 suicideButton = nil,
450 -- todo - open roll button
451
452 eventsFromLL =
453 {
454 ["Redraw"] = function(self) AdminLootButtons:Redraw() end,
455 ["OnSelection"] = function(self) AdminLootButtons:Redraw() end,
456 ["OnSelectionCleared"] = function(self) AdminLootButtons:Redraw() end,
457 },
458 eventsFromSL =
459 {
460 ["Redraw"] = function(self) AdminLootButtons:Redraw() end,
461 ["OnSelection"] = function(self) AdminLootButtons:Redraw() end,
462 ["OnSelectionCleared"] = function(self) AdminLootButtons:Redraw() end,
463 },
464 ["StateEvent"] = function(self) self:Redraw() end,
465 ["RollEvent"] = function(self) self:Redraw() end,
466
467 ["SetButtons"] = function(self,open,assign,suicide)
468 self.openButton = open
469 self.assignButton = assign
470 self.suicideButton = suicide
471 SListEventDispatch:RegisterListener(self.eventsFromSL)
472 LListEventDispatch:RegisterListener(self.eventsFromLL)
473 self:Redraw()
474 end,
475 ["Release"] = function(self)
476 self.openButton = nil
477 self.assignButton = nil
478 self.suicideButton = nil
479 end,
480
481 ["Redraw"] = function(self)
482 if state == "neutral" then -- gray all buttons
483 self.openButton:SetText("Open Bids")
484 self.openButton:SetDisabled(true)
485 self.assignButton:SetText("Assign")
486 self.assignButton:SetDisabled(true)
487 self.suicideButton:SetText("Suicide")
488 self.suicideButton:SetDisabled(true)
489 elseif state == "looting" then
490 if LListEventDispatch.line then
491 self.openButton:SetDisabled(false)
492 self.openButton:SetText("Open Bids")
493 self.openButton:SetCallback("OnClick", function(widget) InitiateOpenBid(LListEventDispatch:LatestValue()) end)
494 else
495 self.openButton:SetText("Open Bids")
496 self.openButton:SetDisabled(true)
497 end
498 if LListEventDispatch.line and SListEventDispatch.line then
499 self.assignButton:SetText("Assign")
500 self.assignButton:SetDisabled(false)
501 self.assignButton:SetCallback("OnClick", function(widget) FreeLoot(LListEventDispatch:LatestValue(),SListEventDispatch:LatestValue()) end)
502 self.suicideButton:SetText("Suicide")
503 self.suicideButton:SetDisabled(false)
504 else
505 self.assignButton:SetText("Assign")
506 self.assignButton:SetDisabled(true)
507 self.suicideButton:SetText("Suicide")
508 self.suicideButton:SetDisabled(true)
509 end
510 -- if item selected, light up Open button
511 -- if item selected and name selected, light up assign/suicide
512 -- buttons
513 elseif state == "bidding" then
514 self.openButton:SetDisabled(false)
515 self.openButton:SetText("Cancel Bidding")
516 self.openButton:SetCallback("OnClick", function(widget) InitiateCloseBidding() end)
517 self.assignButton:SetText("Finish & Assign")
518 self.assignButton:SetDisabled(not (getn(staterolls) > 0 or getn(statebids) > 0))
519 self.assignButton:SetCallback("OnClick", function(widget) ExpensiveLoot(LListEventDispatch:LatestValue(),SListPopulator.lref) end)
520 self.suicideButton:SetText(" ")
521 self.suicideButton:SetDisabled(true)
522
523 -- change open button to cancel
524 -- change assign button to award
525 -- disable ... and rename? the third button
526
527 end
528 end,
529 }
530
445 function OnInitializeSetStaticData() 531 function OnInitializeSetStaticData()
446 SetChangeListener(DataEventDispatch) 532 SetChangeListener(DataEventDispatch)
447 DataEventDispatch:RegisterListener(SListPopulator) 533 DataEventDispatch:RegisterListener(SListPopulator)
448 RegisterListenerActiveListChanged(SListPopulator) 534 RegisterListenerActiveListChanged(SListPopulator)
449 RegisterListenerStateChange(SListPopulator) 535 RegisterListenerStateChange(SListPopulator)
450 RegisterListenerRolls(RListPopulator) 536 RegisterListenerRolls(RListPopulator)
451 RegisterItemListListener(LListPopulator) 537 RegisterItemListListener(LListPopulator)
452 RegisterListenerStateChange(BZPopulator) 538 RegisterListenerStateChange(BZPopulator)
539 if admin then
540 RegisterListenerStateChange(AdminLootButtons)
541 RegisterListenerRolls(AdminLootButtons)
542 end
453 end 543 end
454 544
455 function CreateGUI() 545 function CreateGUI()
456 -- special registration procedure to be closable with the escape button 546 -- special registration procedure to be closable with the escape button
457 --escapeButton.shown = true 547 --escapeButton.shown = true
459 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON") 549 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON")
460 550
461 if f then return end -- no second gui please 551 if f then return end -- no second gui please
462 f = AceGUI:Create("Frame") 552 f = AceGUI:Create("Frame")
463 553
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) 554 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(); AdminLootButtons:Release() end)
465 f:SetTitle("BSK") 555 f:SetTitle("BSK")
466 f:SetLayout("Flow") 556 f:SetLayout("Flow")
467 f:SetHeight(680) 557 f:SetHeight(680)
468 f:SetWidth(580) 558 f:SetWidth(580)
469 559
505 BZPopulator:SetGroup(biddingZone) 595 BZPopulator:SetGroup(biddingZone)
506 596
507 local alb1, alb2, alb3 597 local alb1, alb2, alb3
508 if admin then 598 if admin then
509 alb1 = AceGUI:Create("Button") 599 alb1 = AceGUI:Create("Button")
510 alb1:SetWidth(100) 600 alb1:SetWidth(120)
511 alb1:SetText("Open Bids") 601 --alb1:SetText("Open Bids")
512 alb1.userdata = 602 --alb1.userdata =
513 { 603 --{
514 state = false, 604 -- state = false,
515 widget = alb1, 605 -- widget = alb1,
516 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end, 606 -- ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end,
517 ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end, 607 -- ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end,
518 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end 608 -- ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end
519 } 609 --}
520 alb1:SetDisabled(true) 610 --alb1:SetDisabled(true)
521 LListEventDispatch:RegisterListener(alb1.userdata) 611 --LListEventDispatch:RegisterListener(alb1.userdata)
522 alb1:SetCallback("OnClick", 612 --alb1:SetCallback("OnClick",
523 function(widget) 613 -- function(widget)
524 if widget.userdata.state then -- we were bidding when the button was pressed 614 -- if widget.userdata.state then -- we were bidding when the button was pressed
525 widget:SetText("Open Bids") 615 -- widget:SetText("Open Bids")
526 InitiateCloseBidding() -- todo: plug in loot award, etc 616 -- InitiateCloseBidding() -- todo: plug in loot award, etc
527 else 617 -- else
528 widget:SetText("Close bids") 618 -- widget:SetText("Close bids")
529 InitiateOpenBid(LListEventDispatch:LatestValue()) 619 -- InitiateOpenBid(LListEventDispatch:LatestValue())
530 end 620 -- end
531 widget.userdata.state = not widget.userdata.state 621 -- widget.userdata.state = not widget.userdata.state
532 end 622 -- end
533 ) 623 --)
534 624
535 alb2 = AceGUI:Create("Button") 625 alb2 = AceGUI:Create("Button")
536 alb2:SetWidth(100) 626 alb2:SetWidth(120)
537 alb2:SetText("Assign") 627 --alb2:SetText("Assign")
538 alb2.userdata = 628 --alb2.userdata =
539 { 629 --{
540 widget = alb2, 630 -- widget = alb2,
541 ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end, 631 -- ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
542 } 632 --}
543 alb2.userdata.slist = 633 --alb2.userdata.slist =
544 { 634 --{
545 parent = alb2.userdata, 635 -- parent = alb2.userdata,
546 checked = false, 636 -- checked = false,
547 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end, 637 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
548 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end, 638 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
549 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end, 639 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
550 } 640 --}
551 alb2.userdata.llist = 641 --alb2.userdata.llist =
552 { 642 --{
553 parent = alb2.userdata, 643 -- parent = alb2.userdata,
554 checked = false, 644 -- checked = false,
555 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end, 645 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
556 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end, 646 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
557 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end, 647 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
558 } 648 --}
559 SListEventDispatch:RegisterListener(alb2.userdata.slist) 649 --SListEventDispatch:RegisterListener(alb2.userdata.slist)
560 LListEventDispatch:RegisterListener(alb2.userdata.llist) 650 --LListEventDispatch:RegisterListener(alb2.userdata.llist)
561 651
562 alb3 = AceGUI:Create("Button") 652 alb3 = AceGUI:Create("Button")
563 alb3:SetWidth(100) 653 alb3:SetWidth(120)
564 alb3:SetText("Suicide") 654 --alb3:SetText("Suicide")
565 alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this .... 655 --alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this ....
566 { 656 --{
567 widget = alb3, 657 -- widget = alb3,
568 ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end, 658 -- ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
569 } 659 --}
570 alb3.userdata.slist = 660 --alb3.userdata.slist =
571 { 661 --{
572 parent = alb3.userdata, 662 -- parent = alb3.userdata,
573 checked = false, 663 -- checked = false,
574 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end, 664 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
575 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end, 665 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
576 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end, 666 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
577 } 667 --}
578 alb3.userdata.llist = 668 --alb3.userdata.llist =
579 { 669 --{
580 parent = alb3.userdata, 670 -- parent = alb3.userdata,
581 checked = false, 671 -- checked = false,
582 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end, 672 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
583 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end, 673 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
584 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end, 674 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
585 } 675 --}
586 SListEventDispatch:RegisterListener(alb3.userdata.slist) 676 --SListEventDispatch:RegisterListener(alb3.userdata.slist)
587 LListEventDispatch:RegisterListener(alb3.userdata.llist) 677 --LListEventDispatch:RegisterListener(alb3.userdata.llist)
678 AdminLootButtons:SetButtons(alb1,alb2,alb3)
588 end 679 end
589 680
590 local suicideSelected, undo 681 local suicideSelected, undo
591 if admin then 682 if admin then
592 683