Mercurial > wow > breuesk
changeset 71:d5e2dfe0c269
Starting to track loot state separately
author | John@Yosemite-PC |
---|---|
date | Tue, 03 Apr 2012 23:23:22 -0400 |
parents | 236117ab8a49 |
children | 9e5b0a2368ad |
files | Gui.lua Lists.lua State.lua breuesk.toc |
diffstat | 4 files changed, 196 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/Gui.lua Thu Mar 29 23:24:51 2012 -0400 +++ b/Gui.lua Tue Apr 03 23:23:22 2012 -0400 @@ -48,8 +48,9 @@ end pulldown:SetWidth(175) pulldown:SetList(pull) + SListPopulator:SetSwidget(pulldown) pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:SelectList(value) end) - if ltemp > 0 then pulldown:SetValue(ltemp); SListPopulator:SelectList(ltemp) end -- sadly, SetValue doesn't fire a OnValueChanged + if ltemp > 0 then SListPopulator:SelectList(ltemp) end -- default value return pulldown end @@ -115,10 +116,11 @@ { filtered = false, widget = nil, + swidget = nil, data = nil, lref = nil, - ["Release"] = function(self) self.filtered, self.widget, self.data, self.lref = false, nil, nil, nil end, + ["Release"] = function(self) self.filtered, self.widget, self.swidget, self.data, self.lref = false, nil, nil, nil, nil end, ["Redraw"] = function(self) if self.lref == nil or self.widget == nil then return end -- don't do work if not fully initialized self.data = {} @@ -136,6 +138,12 @@ self.widget:SetList(self.data) SListEventDispatch:Event("Redraw") end, + ["SetSwidget"] = function(self,w) + if type(w) ~= "table" or type(w.SetList) ~= "function" then + _G.error("Bad SetWidget") + end + self.swidget = w + end, ["SetWidget"] = function(self,w) if type(w) ~= "table" or type(w.SetList) ~= "function" then _G.error("Bad SetWidget") @@ -147,8 +155,10 @@ self:Redraw() end, ["SelectList"] = function(self,value) + self.swidget:SetValue(value) self.lref = LootLists:Select(value) self:Redraw() + Comm:ActivateList(value) end, ["DataEvent"] = function(self) self:Redraw() @@ -213,11 +223,11 @@ local RListPopulator = { - data = {}, widget = nil, - ["Release"] = function(self) self.data = {}; self.widget = nil end, + ["RollEvent"] = function(self) self:Redraw() end, + ["Release"] = function(self) self.widget = nil end, ["Redraw"] = function(self) - self.widget:SetList(self.data) + self.widget:SetList(statebids) RListEventDispatch:Event("Redraw") end, ["SetWidget"] = function(self,w) @@ -225,34 +235,29 @@ _G.error("Bad SetWidget") end self.widget = w - if debug then - local dummydata = {} - local tree = SListPopulator.data - for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end - if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end - self.data = dummydata - end + --if debug then + -- local dummydata = {} + -- local tree = SListPopulator.data + -- for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end + -- if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end + -- self.data = dummydata + --end self:Redraw() end, ["Force"] = function(self,who) - for i,v in pairs(self.data) do - if who.value == v.value then - print(who.value .. " is already on the list") - return -- no double adds please - end - end local new = self.Convert(who,72) - table.insert(self.data,new) - -- todo: keep this list sorted - self:Redraw() + InitiateBid(new) + --self:Redraw() end, ["Retract"] = function(self,who) - for i,v in pairs(self.data) do - if who.value == v.value then - table.remove(self.data,i) - end - end - self:Redraw() + -- todo + --for i,v in pairs(self.data) do + -- if who.value == v.value then + -- table.remove(self.data,i) + -- end + --end + InitiateRetract(copy(who)) + --self:Redraw() end, ["Convert"] = function(who,roll) -- convert an LE object into one suitable to put in a SelectorList local new = copy(who) @@ -286,6 +291,7 @@ function OnInitializeSetStaticData() SetChangeListener(DataEventDispatch) DataEventDispatch:RegisterListener(SListPopulator) + RegisterListenerRolls(RListPopulator) end function CreateGUI() @@ -397,6 +403,8 @@ 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
--- a/Lists.lua Thu Mar 29 23:24:51 2012 -0400 +++ b/Lists.lua Tue Apr 03 23:23:22 2012 -0400 @@ -626,10 +626,6 @@ if acceptor[finalizeAction](acceptor,arg,change.time) then table.insert(db.profile.changes,change) - if changeListener then - changeListener:DataEvent(change) - end - -- TODO: broadcast Comm:SendChange(change) return arg else
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/State.lua Tue Apr 03 23:23:22 2012 -0400 @@ -0,0 +1,160 @@ +local bsk=bsk +local _G=_G +local table=table +local pairs=pairs +local setmetatable=setmetatable +local ipairs=ipairs +local string=string +local sformat=string.format +local tostring=tostring +local type=type +local unpack=unpack +local getn=getn +setfenv(1,bsk) + +-- simple state machine + +--Begin loot +--Activate list ... only during looting? +--open bidding/rolling +--bid/roll occurred +--remove bid/roll +--close bidding +--remove item + + +-- we'll track state, but that may or may not result in a GUI change until down +-- the road + +-- todo: transmit this all to only the raid, not the guild? + +-- sample procedure +-- person B opens GUI. +-- person A begins looting, sets a list +-- person A begins bidding, transmists the state +-- person B goes into bidding state, their button activates +-- person B clicks the button. button changes state. +-- person B broadcasts their bid. if a bid, everyone just accepts it. +-- - if a roll, then the master does the roll and rebroadcasts + +state = "neutral" +local looting = false +stateactive = nil +stateitem = nil +statebids = {} +staterolls = {} + +local rollListeners = {} +function RegisterListenerRolls(listener) + table.insert(rollListeners,listener) +end +function AlertRollListeners() + for i,v in pairs(rollListeners) do + print("roll out") + v["RollEvent"](v) + end +end + +function BeginLoot(listValue) + if state == "neutral" then + state = "looting" + looting = true + active = listValue + else + _G.error("Bad state transition", state, "looting") + end +end + +function ActivateList(value) -- doesn't cause a transition, but we only enforce a list selection during certain times + if state == "looting" then + active = value + end +end + +function OpenBid(packet) + local item = unpack(packet) + --if state == "looting" then + state = "bidding" + item = value + --end +end + +function InitiateOpenBid(item) + --if state == "looting" then + Comm:SendStateChange("OB",item) + --end +end + +function DispatchState(packet) + local state = table.remove(packet,1) + print("Dispatching", state) + if state == "RB" then + ReceivedBid(packet) + elseif state == "RR" then + ReceivedRetraction(packet) + elseif state == "OB" then + OpenBid(packet) + else -- todo ... + + end +end + +function ReceivedBid(packet) -- no state transition, but only matters during one state + local person, roll = unpack(packet) + + if state == "bidding" then + if roll then + table.insert(statebids,person) -- todo: + else + table.insert(statebids,person) -- todo: keep sorted + end + AlertRollListeners() + end + + -- else ignore ... +end + +function InitiateBid(person,roll) + if state == "bidding" then + for i,v in pairs(statebids) do + if person.value == v.value then + print(person.value .. " is already on the list") + return -- no double adds please + end + end + Comm:SendStateChange("RB",person,roll) + end +end + + +function ReceivedRetraction(packet) + local person = unpack(packet) + if state == "bidding" then + for i,v in pairs(statebids) do + if v.value == person.value then + table.remove(statebids,i) + AlertRollListeners() + return + end + end + end +end + +function InitiateRetract(person) + if state == "bidding" then + Comm:SendStateChange("RR",person,roll) + end +end + +function CloseBidding(awardedTo) + state = "looting" + -- remove the item, record history +end + +function CloseLooting() + state = "neutral" + active = nil + item = nil + bids = {} + rolls = {} +end