changeset 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 15844864a5f7
children 39be9328acd0
files Gui.lua State.lua
diffstat 2 files changed, 134 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/Gui.lua	Mon Apr 09 09:40:14 2012 -0400
+++ b/Gui.lua	Mon Apr 09 09:40:53 2012 -0400
@@ -171,12 +171,12 @@
         self:Redraw()
     end,
     ["StateEvent"] = function(self)
+        -- todo: events still happen even if the gui is closed. protect the api.
+
         print("State event in SL: ", state, admin)
         if state == "bidding" or (state == "looting" and not admin) then
             self.swidget:SetDisabled(true)
             self:SelectList(stateactivelist)
-        elseif state == "looting" and admin then
-            self.swidget:SetDisabled(false)
         else
             self.swidget:SetDisabled(false)
         end
@@ -305,6 +305,124 @@
     end,
 }
 
+local BZPopulator =
+{
+    group = nil,
+    ["SetGroup"] = function(self,g)
+        if type(g) ~= "table" or type(g.AddChild) ~= "function" then
+            _G.error("Bad SetGroup for BZPopulator")
+        end
+        self.group = g
+    end,
+
+
+    ["Release"] = function(self) self.group = nil; RListEventDispatch:Release(); RListPopulator:Release() end,  
+
+    ["StateEvent"] = function(self)
+        if state == "bidding" then
+
+            local spacer = AceGUI:Create("Label")
+            spacer:SetText(" ")
+            spacer:SetFullWidth(true)
+            local spacer2 = AceGUI:Create("Label")
+            spacer2:SetText(" ")
+            spacer2:SetFullWidth(true)
+
+            local label = AceGUI:Create("Label")
+            label:SetText("Bidding now open for ...")
+            local biddingOn = AceGUI:Create("InteractiveLabel")
+            biddingOn.userdata = { stateitem.link } 
+            biddingOn:SetText(biddingOn.userdata[1])
+            biddingOn:SetFullWidth(true)
+            biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT");  _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
+            biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
+            local b1 = AceGUI:Create("SelectorList")
+            b1:SetNumLines(6)
+            b1:SetInteractive(admin)
+            local bidTitle = AceGUI:Create("Label")
+            bidTitle:SetText("Current bids")
+            bidTitle:SetFullWidth(true)
+
+            local bidRetractButton = AceGUI:Create("Button")
+            bidRetractButton:SetText("Place Bid")
+            bidRetractButton:SetWidth(100)
+            bidRetractButton:SetCallback("OnClick", function(widget) RListPopulator:Force(SListPopulator:GetMe()) end) -- todo: Force is not the desired thing here.
+            local rollButton = AceGUI:Create("Button")
+            rollButton:SetText("Offset Roll")
+            rollButton:SetWidth(100)
+
+            RListEventDispatch:SetTarget(b1)
+            RListPopulator:SetWidget(b1)
+
+
+            local g1
+            if admin then
+                b1.alignoffset = 0.25 -- or else g1 won't align well
+                g1 = AceGUI:Create("SimpleGroup")
+                g1.alignoffset = 0.25
+                g1:SetWidth(120)
+                g1:SetLayout("List")
+
+                -- todo: convoluted and repetitive - surely there's a
+                -- better way than this ...
+                adminForce = AceGUI:Create("Button")
+                if SListEventDispatch:LatestValue() then
+                    adminForce:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain))
+                    adminForce:SetDisabled(false)
+                else
+                    adminForce:SetText("Force bid")
+                    adminForce:SetDisabled(true)
+                end
+                adminForce:SetWidth(160)
+                adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end)
+                adminForce.userdata = 
+                {
+                    widget = adminForce,
+                    ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end,
+                    ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end,
+                    ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end
+                }
+                SListEventDispatch:RegisterListener(adminForce.userdata)
+
+                adminRetract = AceGUI:Create("Button")
+                if RListEventDispatch:LatestValue() then
+                    adminRetract:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain))
+                    adminRetract:SetDisabled(false)
+                else
+                    adminRetract:SetText("Retract bid")
+                    adminRetract:SetDisabled(true)
+                end
+                adminRetract:SetWidth(160)
+                adminRetract.userdata = 
+                {
+                    widget = adminRetract,
+                    ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end,
+                    ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end,
+                    ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end
+                }
+                adminRetract:SetCallback("OnClick",function(widget) RListPopulator:Retract(RListEventDispatch:LatestValue()) end)
+                RListEventDispatch:RegisterListener(adminRetract.userdata)
+                adminRetract:SetDisabled(true)
+
+                g1:AddChildren(adminForce,adminRetract)
+            end
+
+            self.group:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
+            if admin then self.group:AddChildren(g1) end
+
+        else
+
+
+            self.group:ReleaseChildren()
+            RListEventDispatch:Release()
+            RListPopulator:Release() 
+        end
+
+    end,
+    
+    
+}
+
 DataEventDispatch =
 {
     -- todo: batch events
@@ -331,6 +449,7 @@
     RegisterListenerStateChange(SListPopulator)
     RegisterListenerRolls(RListPopulator)
     RegisterItemListListener(LListPopulator)
+    RegisterListenerStateChange(BZPopulator)
 end
 
 function CreateGUI()
@@ -342,7 +461,7 @@
     if f then return end -- no second gui please
     f = AceGUI:Create("Frame")
 
-    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)
+    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)
     f:SetTitle("BSK")
     f:SetLayout("Flow")
     f:SetHeight(680) 
@@ -380,9 +499,10 @@
     LListEventDispatch:SetTarget(t2)
     LListPopulator:SetWidget(t2)
 
-    local biddingZone = AceGUI:Create("SimpleGroup")
+    biddingZone = AceGUI:Create("SimpleGroup")
     biddingZone:SetLayout("Flow")
     biddingZone:SetFullWidth(true)
+    BZPopulator:SetGroup(biddingZone)
 
     local alb1, alb2, alb3
     if admin then 
@@ -402,101 +522,11 @@
         alb1:SetCallback("OnClick", 
             function(widget) 
                 if widget.userdata.state then -- we were bidding when the button was pressed
-                    biddingZone:ReleaseChildren()
                     widget:SetText("Open Bids")
-                    RListEventDispatch:Release()
-                    RListPopulator:Release() 
+                    InitiateCloseBidding() -- todo: plug in loot award, etc
                 else
                     widget:SetText("Close bids")
-                    local spacer = AceGUI:Create("Label")
-                    spacer:SetText(" ")
-                    spacer:SetFullWidth(true)
-                    local spacer2 = AceGUI:Create("Label")
-                    spacer2:SetText(" ")
-                    spacer2:SetFullWidth(true)
-
-                    local label = AceGUI:Create("Label")
-                    label:SetText("Bidding now open for ...")
-                    local biddingOn = AceGUI:Create("InteractiveLabel")
-                    biddingOn.userdata = { LListEventDispatch:LatestValue().link } 
-                    biddingOn:SetText(biddingOn.userdata[1])
-                    biddingOn:SetFullWidth(true)
-                    biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT");  _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
-                    biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
-                    local b1 = AceGUI:Create("SelectorList")
-                    b1:SetNumLines(6)
-                    b1:SetInteractive(admin)
-                    local bidTitle = AceGUI:Create("Label")
-                    bidTitle:SetText("Current bids")
-                    bidTitle:SetFullWidth(true)
-
-                    local bidRetractButton = AceGUI:Create("Button")
-                    bidRetractButton:SetText("Place Bid")
-                    bidRetractButton:SetWidth(100)
-                    bidRetractButton:SetCallback("OnClick", function(widget) RListPopulator:Force(SListPopulator:GetMe()) end) -- todo: Force is not the desired thing here.
-                    local rollButton = AceGUI:Create("Button")
-                    rollButton:SetText("Offset Roll")
-                    rollButton:SetWidth(100)
-
-                    RListEventDispatch:SetTarget(b1)
-                    RListPopulator:SetWidget(b1)
-
                     InitiateOpenBid(LListEventDispatch:LatestValue())
-
-                    local g1
-                    if admin then
-                        b1.alignoffset = 0.25 -- or else g1 won't align well
-                        g1 = AceGUI:Create("SimpleGroup")
-                        g1.alignoffset = 0.25
-                        g1:SetWidth(120)
-                        g1:SetLayout("List")
-
-                        -- todo: convoluted and repetitive - surely there's a
-                        -- better way than this ...
-                        adminForce = AceGUI:Create("Button")
-                        if SListEventDispatch:LatestValue() then
-                            adminForce:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain))
-                            adminForce:SetDisabled(false)
-                        else
-                            adminForce:SetText("Force bid")
-                            adminForce:SetDisabled(true)
-                        end
-                        adminForce:SetWidth(160)
-                        adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end)
-                        adminForce.userdata = 
-                        {
-                            widget = adminForce,
-                            ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end,
-                            ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end,
-                            ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end
-                        }
-                        SListEventDispatch:RegisterListener(adminForce.userdata)
-
-                        adminRetract = AceGUI:Create("Button")
-                        if RListEventDispatch:LatestValue() then
-                            adminRetract:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain))
-                            adminRetract:SetDisabled(false)
-                        else
-                            adminRetract:SetText("Retract bid")
-                            adminRetract:SetDisabled(true)
-                        end
-                        adminRetract:SetWidth(160)
-                        adminRetract.userdata = 
-                        {
-                            widget = adminRetract,
-                            ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end,
-                            ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end,
-                            ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end
-                        }
-                        adminRetract:SetCallback("OnClick",function(widget) RListPopulator:Retract(RListEventDispatch:LatestValue()) end)
-                        RListEventDispatch:RegisterListener(adminRetract.userdata)
-                        adminRetract:SetDisabled(true)
-
-                        g1:AddChildren(adminForce,adminRetract)
-                    end
-
-                    biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
-                    if admin then biddingZone:AddChildren(g1) end
                 end
                 widget.userdata.state = not widget.userdata.state
             end
--- a/State.lua	Mon Apr 09 09:40:14 2012 -0400
+++ b/State.lua	Mon Apr 09 09:40:53 2012 -0400
@@ -129,8 +129,8 @@
     local item = unpack(packet)
     if state == "looting" then
         state = "bidding"
+        stateitem = item
         AlertStateChangeListeners()
-        item = value
     end
 end
 
@@ -191,13 +191,17 @@
 -- Close Bidding {{{
 function CloseBidding(packet)
     local awardedTo = unpack(packet) 
-    state = "looting"
-    AlertStateChangeListeners()
-    -- remove the item from the window, record history
+    if state == "bidding" then
+        state = "looting"
+        AlertStateChangeListeners()
+        -- todo: remove the item from the window, record history
+    end
 end
 
 function InitiateCloseBidding(awardedTo)
-    Comm:SendStateChange("CB",awardedTo)
+    if state == "bidding" then
+        Comm:SendStateChange("CB",awardedTo)
+    end
 end
 --}}}
 -- Close Looting {{{