changeset 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 0a3f590f69e6
files Gui.lua Lists.lua Looting.lua State.lua
diffstat 4 files changed, 241 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/Gui.lua	Mon Apr 09 09:40:53 2012 -0400
+++ b/Gui.lua	Tue Apr 10 23:50:07 2012 -0400
@@ -203,7 +203,6 @@
 
 local LListPopulator =
 {
-    -- todo: set event receivers from the comm and for loot 
     data = {},
     widget = nil,
     ["Release"] = function(self) self.data = {}; self.widget = nil end,
@@ -224,35 +223,35 @@
             _G.error("Bad SetWidget")
         end
         self.widget = w
-        if debug then
-            self.data = {
-                {
-                    value=1, 
-                    text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
-                    link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
-                },
-                {
-                    value=2,
-                    text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r",
-                    link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r"
-                },
-                {
-                    value=3,
-                    text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r",
-                    link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r"
-                },
-                {
-                    value=4,
-                    text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r",
-                    link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r"
-                },
-                {
-                    value=5,
-                    text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
-                    link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
-                },
-            }
-        end
+        --if debug then
+        --    self.data = {
+        --        {
+        --            value=1, 
+        --            text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
+        --            link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
+        --        },
+        --        {
+        --            value=2,
+        --            text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r",
+        --            link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r"
+        --        },
+        --        {
+        --            value=3,
+        --            text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r",
+        --            link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r"
+        --        },
+        --        {
+        --            value=4,
+        --            text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r",
+        --            link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r"
+        --        },
+        --        {
+        --            value=5,
+        --            text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
+        --            link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
+        --        },
+        --    }
+        --end
         self:Redraw()
     end,
 }
@@ -324,7 +323,7 @@
             local spacer = AceGUI:Create("Label")
             spacer:SetText(" ")
             spacer:SetFullWidth(true)
-            local spacer2 = AceGUI:Create("Label")
+            local spacer2 = AceGUI:Create("Label") -- don't try to combine this with "spacer" - you can't add a child more than once
             spacer2:SetText(" ")
             spacer2:SetFullWidth(true)
 
@@ -346,15 +345,16 @@
             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.
+            bidRetractButton:SetCallback("OnClick", function(widget) InitiateBid(SListPopulator:GetMe()) end)
+
             local rollButton = AceGUI:Create("Button")
             rollButton:SetText("Offset Roll")
             rollButton:SetWidth(100)
+            -- todo: callback
 
             RListEventDispatch:SetTarget(b1)
             RListPopulator:SetWidget(b1)
 
-
             local g1
             if admin then
                 b1.alignoffset = 0.25 -- or else g1 won't align well
@@ -442,6 +442,92 @@
     end
 }
 
+AdminLootButtons =
+{
+    openButton = nil,
+    assignButton = nil,
+    suicideButton = nil,
+    -- todo - open roll button
+    
+    eventsFromLL = 
+    {
+        ["Redraw"] = function(self) AdminLootButtons:Redraw() end,
+        ["OnSelection"] = function(self) AdminLootButtons:Redraw() end,
+        ["OnSelectionCleared"] = function(self) AdminLootButtons:Redraw() end,
+    },
+    eventsFromSL = 
+    {
+        ["Redraw"] = function(self) AdminLootButtons:Redraw() end,
+        ["OnSelection"] = function(self) AdminLootButtons:Redraw() end,
+        ["OnSelectionCleared"] = function(self) AdminLootButtons:Redraw() end,
+    },
+    ["StateEvent"] = function(self) self:Redraw() end,
+    ["RollEvent"] = function(self) self:Redraw() end,
+
+    ["SetButtons"] = function(self,open,assign,suicide)
+        self.openButton = open
+        self.assignButton = assign
+        self.suicideButton = suicide
+        SListEventDispatch:RegisterListener(self.eventsFromSL)
+        LListEventDispatch:RegisterListener(self.eventsFromLL)
+        self:Redraw()
+    end,
+    ["Release"] = function(self)
+        self.openButton = nil
+        self.assignButton = nil
+        self.suicideButton = nil
+    end,
+
+    ["Redraw"] = function(self)
+        if state == "neutral" then -- gray all buttons
+            self.openButton:SetText("Open Bids")
+            self.openButton:SetDisabled(true)
+            self.assignButton:SetText("Assign")
+            self.assignButton:SetDisabled(true)
+            self.suicideButton:SetText("Suicide")
+            self.suicideButton:SetDisabled(true)
+        elseif state == "looting" then
+            if LListEventDispatch.line then
+                self.openButton:SetDisabled(false)
+                self.openButton:SetText("Open Bids")
+                self.openButton:SetCallback("OnClick", function(widget) InitiateOpenBid(LListEventDispatch:LatestValue()) end)
+            else
+                self.openButton:SetText("Open Bids")
+                self.openButton:SetDisabled(true)
+            end
+            if LListEventDispatch.line and SListEventDispatch.line then
+                self.assignButton:SetText("Assign")
+                self.assignButton:SetDisabled(false)
+                self.assignButton:SetCallback("OnClick", function(widget) FreeLoot(LListEventDispatch:LatestValue(),SListEventDispatch:LatestValue()) end)
+                self.suicideButton:SetText("Suicide")
+                self.suicideButton:SetDisabled(false)
+            else
+                self.assignButton:SetText("Assign")
+                self.assignButton:SetDisabled(true)
+                self.suicideButton:SetText("Suicide")
+                self.suicideButton:SetDisabled(true)
+            end
+            -- if item selected, light up Open button
+            -- if item selected and name selected, light up assign/suicide
+            -- buttons
+        elseif state == "bidding" then
+            self.openButton:SetDisabled(false)
+            self.openButton:SetText("Cancel Bidding")
+            self.openButton:SetCallback("OnClick", function(widget) InitiateCloseBidding() end)
+            self.assignButton:SetText("Finish & Assign")
+            self.assignButton:SetDisabled(not (getn(staterolls) > 0 or getn(statebids) > 0))
+            self.assignButton:SetCallback("OnClick", function(widget) ExpensiveLoot(LListEventDispatch:LatestValue(),SListPopulator.lref) end)
+            self.suicideButton:SetText(" ")
+            self.suicideButton:SetDisabled(true)
+
+            -- change open button to cancel
+            -- change assign button to award
+            -- disable ... and rename? the third button
+
+        end
+    end,
+}
+
 function OnInitializeSetStaticData()
     SetChangeListener(DataEventDispatch)
     DataEventDispatch:RegisterListener(SListPopulator)
@@ -450,6 +536,10 @@
     RegisterListenerRolls(RListPopulator)
     RegisterItemListListener(LListPopulator)
     RegisterListenerStateChange(BZPopulator)
+    if admin then 
+        RegisterListenerStateChange(AdminLootButtons)
+        RegisterListenerRolls(AdminLootButtons)
+    end
 end
 
 function CreateGUI()
@@ -461,7 +551,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(); BZPopulator: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(); AdminLootButtons:Release() end)
     f:SetTitle("BSK")
     f:SetLayout("Flow")
     f:SetHeight(680) 
@@ -507,84 +597,85 @@
     local alb1, alb2, alb3
     if admin then 
         alb1 = AceGUI:Create("Button")
-        alb1:SetWidth(100)
-        alb1:SetText("Open Bids")
-        alb1.userdata = 
-        {
-            state = false,
-            widget = alb1,
-            ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end,
-            ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end,
-            ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end
-        }
-        alb1:SetDisabled(true)
-        LListEventDispatch:RegisterListener(alb1.userdata)
-        alb1:SetCallback("OnClick", 
-            function(widget) 
-                if widget.userdata.state then -- we were bidding when the button was pressed
-                    widget:SetText("Open Bids")
-                    InitiateCloseBidding() -- todo: plug in loot award, etc
-                else
-                    widget:SetText("Close bids")
-                    InitiateOpenBid(LListEventDispatch:LatestValue())
-                end
-                widget.userdata.state = not widget.userdata.state
-            end
-        )
+        alb1:SetWidth(120)
+        --alb1:SetText("Open Bids")
+        --alb1.userdata = 
+        --{
+        --    state = false,
+        --    widget = alb1,
+        --    ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end,
+        --    ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end,
+        --    ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end
+        --}
+        --alb1:SetDisabled(true)
+        --LListEventDispatch:RegisterListener(alb1.userdata)
+        --alb1:SetCallback("OnClick", 
+        --    function(widget) 
+        --        if widget.userdata.state then -- we were bidding when the button was pressed
+        --            widget:SetText("Open Bids")
+        --            InitiateCloseBidding() -- todo: plug in loot award, etc
+        --        else
+        --            widget:SetText("Close bids")
+        --            InitiateOpenBid(LListEventDispatch:LatestValue())
+        --        end
+        --        widget.userdata.state = not widget.userdata.state
+        --    end
+        --)
 
         alb2 = AceGUI:Create("Button")
-        alb2:SetWidth(100)
-        alb2:SetText("Assign")
-        alb2.userdata =
-        {
-            widget = alb2,
-            ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
-        }
-        alb2.userdata.slist = 
-        {
-            parent = alb2.userdata,
-            checked = false,
-            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
-            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-        }
-        alb2.userdata.llist = 
-        {
-            parent = alb2.userdata,
-            checked = false,
-            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
-            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-        }
-        SListEventDispatch:RegisterListener(alb2.userdata.slist)
-        LListEventDispatch:RegisterListener(alb2.userdata.llist)
+        alb2:SetWidth(120)
+        --alb2:SetText("Assign")
+        --alb2.userdata =
+        --{
+        --    widget = alb2,
+        --    ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
+        --}
+        --alb2.userdata.slist = 
+        --{
+        --    parent = alb2.userdata,
+        --    checked = false,
+        --    ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --    ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+        --    ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --}
+        --alb2.userdata.llist = 
+        --{
+        --    parent = alb2.userdata,
+        --    checked = false,
+        --    ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --    ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+        --    ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --}
+        --SListEventDispatch:RegisterListener(alb2.userdata.slist)
+        --LListEventDispatch:RegisterListener(alb2.userdata.llist)
 
         alb3 = AceGUI:Create("Button")
-        alb3:SetWidth(100)
-        alb3:SetText("Suicide")
-        alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this ....
-        {
-            widget = alb3,
-            ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
-        }
-        alb3.userdata.slist = 
-        {
-            parent = alb3.userdata,
-            checked = false,
-            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
-            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-        }
-        alb3.userdata.llist = 
-        {
-            parent = alb3.userdata,
-            checked = false,
-            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
-            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
-        }
-        SListEventDispatch:RegisterListener(alb3.userdata.slist)
-        LListEventDispatch:RegisterListener(alb3.userdata.llist)
+        alb3:SetWidth(120)
+        --alb3:SetText("Suicide")
+        --alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this ....
+        --{
+        --    widget = alb3,
+        --    ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
+        --}
+        --alb3.userdata.slist = 
+        --{
+        --    parent = alb3.userdata,
+        --    checked = false,
+        --    ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --    ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+        --    ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --}
+        --alb3.userdata.llist = 
+        --{
+        --    parent = alb3.userdata,
+        --    checked = false,
+        --    ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --    ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+        --    ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        --}
+        --SListEventDispatch:RegisterListener(alb3.userdata.slist)
+        --LListEventDispatch:RegisterListener(alb3.userdata.llist)
+        AdminLootButtons:SetButtons(alb1,alb2,alb3)
     end
 
     local suicideSelected, undo
--- a/Lists.lua	Mon Apr 09 09:40:53 2012 -0400
+++ b/Lists.lua	Tue Apr 10 23:50:07 2012 -0400
@@ -813,7 +813,7 @@
     print("Removing " .. person)
     PersonList:Remove(person)
 end
-function ReservePerson(person)
+function ReservePerson(person) -- todo: move reserve state to ... State.lua
     print("Reserving " .. person)
     if PersonList:AddReserve(person) then -- todo: would be better if this were an ID ...
         Comm:AddReserve(person)
--- a/Looting.lua	Mon Apr 09 09:40:53 2012 -0400
+++ b/Looting.lua	Tue Apr 10 23:50:07 2012 -0400
@@ -60,10 +60,49 @@
 
 end
 
+function FreeLoot(item,person)
+    PrintTable(item)
+    PrintTable(person)
+    for ci = 1, 40 do
+        if _G.GetMasterLootCandidate(ci) == person.textPlain then
+            print("GML",item.value,ci)
+            _G.GiveMasterLoot(item.value, ci)
+            return true
+        end
+    end
+    
+    print("Could not assign loot to ", person.textPlain)
+end
+
+function ExpensiveLoot(item,lref)
+    local person
+    if getn(statebids) > 0 then
+        if FreeLoot(item,statebids[1]) then
+            lref:SuicidePerson(statebids[1].value)
+        else
+            printf("Could not suicide %s for item; they are ineligible or offline",statebids[1].textPlain)
+        end
+        return
+    end
+    if getn(staterolls) > 0 then
+        if FreeLoot(item,staterolls[1]) then
+            lref:SuicidePerson(staterolls[1].value)
+        else
+            printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain)
+        end
+        return
+    end
+    _G.error("Trying to suicide+loot without bids or rolls")
+end
+
 function InitializeLooting()
     event:RegisterEvent("OPEN_MASTER_LOOT_LIST",OpenMasterLootList)
     event:RegisterEvent("UPDATE_MASTER_LOOT_LIST",UpdateMasterLootList)
     event:RegisterEvent("LOOT_CLOSED",LootClosed)
     event:RegisterEvent("LOOT_OPENED",LootOpened)
+
+    -- todo: what are these
+    event:RegisterEvent("LOOT_SLOT_CLEARED",function() print("LSCleared") end)
+    event:RegisterEvent("LOOT_SLOT_CHANGED",function() print("LSChanged") end)
 end
 
--- a/State.lua	Mon Apr 09 09:40:53 2012 -0400
+++ b/State.lua	Tue Apr 10 23:50:07 2012 -0400
@@ -46,6 +46,8 @@
 staterolls = {}
 stateactivelist = nil 
 
+-- todo: protect initiators to admin only
+
 local rollListeners = {}
 function RegisterListenerRolls(listener)
     table.insert(rollListeners,listener)