Mercurial > wow > breuesk
changeset 72:9e5b0a2368ad
Big progress towards GUI usefulness and communication between clients
author | John@Yosemite-PC |
---|---|
date | Sat, 07 Apr 2012 13:35:57 -0400 |
parents | d5e2dfe0c269 |
children | 7eb2963eea7d |
files | Comm.lua Core.lua Gui.lua Lists.lua State.lua |
diffstat | 5 files changed, 222 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Comm.lua Sat Apr 07 13:35:57 2012 -0400 @@ -0,0 +1,99 @@ +local bsk=bsk +local _G=_G +local table=table +local pairs=pairs +local setmetatable=setmetatable +local ipairs=ipairs +local unpack=unpack +local string=string +local sformat=string.format +local tostring=tostring +local type=type +local getn=getn + +local commlib = LibStub("AceComm-3.0") or _G.error("Couldn't load up AceComm") +local s = LibStub("AceSerializer-3.0") or _G.error("Couldn't load up AceSerializer") + +setfenv(1,bsk) + +local function BuildPacket(handler,message) + local p = {handler,message} + local str = s:Serialize({handler,message}) + print("sending",str) + return p,str +end + +local function SendMessage(str) + --commlib:SendCommMessage("BSKADDON",str,"GUILD") + commlib:SendCommMessage("BSKADDON",str,"RAID") +end + +local function Send(handler,message) + local p,str = BuildPacket(handler,message) + SendMessage(str) +end + +-- todo: ActivateList and AddReserve -> state +Comm = +{ + ["SS"] = function(self,packet,sender,isloop) + print("isloop",isloop) + if not isloop then DispatchState(packet) end + end, + ["SendStateChange"] = function(self,...) + local p,str = BuildPacket("SS",{...}) + DispatchState(p[2]) + SendMessage(str) + end, + ["AR"] = function(self,packet,sender,isloop) + if isloop then return end + PersonList:AddReserve(packet) + changeListener:DataEvent() + end, + ["AddReserve"] = function(self,packet) + if changeListener then + changeListener:DataEvent(change) + end + Send("AR",packet) + end, + ["SendChange"] = function(self,change) + if changeListener then + changeListener:DataEvent(change) + end + Send("CC",change) + end, + ["CC"] = function(self,change,sender,isloop) + if isloop then return end + ProcessChange(change) + changeListener:DataEvent() + end, + ["Push"] = function(self) + Send("PU",{db.profile.lists,db.profile.persons,db.profile.changes}) + end, + ["PU"] = function(self,packet,sender,isloop) + if isloop then return end + db.profile.lists,db.profile.persons,db.profile.changes = unpack(packet) + CreateWorkingStateFromChanges(db.profile.changes) + if changeListener then + changeListener:DataEvent() + end + end, +} + +local function OnCommReceived(prefix, message, distribution, sender) + print("Received on", distribution) + local success,packet = s:Deserialize(message) + local isloop = _G.UnitName("player") == sender + + print("received",message) + + Comm[packet[1]](Comm,packet[2],sender,isloop) +end + +function InitializeComm() + commlib:RegisterComm("BSKADDON",OnCommReceived) +end + +function DeinitializeComm() + +end
--- a/Core.lua Tue Apr 03 23:23:22 2012 -0400 +++ b/Core.lua Sat Apr 07 13:35:57 2012 -0400 @@ -29,6 +29,7 @@ setfenv(1,bsk) local pkgrev = " @project-revision@ " +admin = admin or true -- important things to remember: -- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int @@ -183,6 +184,10 @@ PersonList:AddMissing() CreateList(arg1) PopulateListRandom(arg1) + elseif action == "push" then + Comm:Push() + elseif action == "state" then + print(state) else CreateGUI() end
--- a/Gui.lua Tue Apr 03 23:23:22 2012 -0400 +++ b/Gui.lua Sat Apr 07 13:35:57 2012 -0400 @@ -49,12 +49,12 @@ pulldown:SetWidth(175) pulldown:SetList(pull) SListPopulator:SetSwidget(pulldown) - pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:SelectList(value) end) - if ltemp > 0 then SListPopulator:SelectList(ltemp) end -- default value + pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:PulldownEvent(value) end) + if ltemp > 0 then SListPopulator:PulldownEvent(ltemp) end -- default value return pulldown end -local f, right +local f, right -- important gui elements local escapeButton = { shown = false, @@ -154,15 +154,46 @@ self.filtered = value self:Redraw() end, - ["SelectList"] = function(self,value) + ["SelectList"] = function(self,value,nocomm) self.swidget:SetValue(value) - self.lref = LootLists:Select(value) - self:Redraw() - Comm:ActivateList(value) + local l = LootLists:Select(value) + if l ~= self.lref then + self.lref = l + self:Redraw() + end + if nocomm then InitiateActiveList(value) end + end, + + + ["PulldownEvent"] = function(self,value) + self:SelectList(value) + if admin and state == "looting" then + InitiateActivateList(value) + end end, ["DataEvent"] = function(self) self:Redraw() end, + ["StateEvent"] = function(self) + 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 + -- if bidding then disable pulldown + -- if looting and not admin then disable pulldown + -- if looting and admin then enable pulldown + -- otherwise enable pulldown + end, + ["ActiveListEvent"] = function(self) + self:SelectList(stateactivelist) + end, + + + ["GetMe"] = function(self) local me = _G.UnitName("player") for i,v in pairs(self.data) do @@ -291,6 +322,8 @@ function OnInitializeSetStaticData() SetChangeListener(DataEventDispatch) DataEventDispatch:RegisterListener(SListPopulator) + RegisterListenerActiveListChanged(SListPopulator) + RegisterListenerStateChange(SListPopulator) RegisterListenerRolls(RListPopulator) end @@ -301,7 +334,6 @@ --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON") if f then return end -- no second gui please - local admin = admin or true 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)
--- a/Lists.lua Tue Apr 03 23:23:22 2012 -0400 +++ b/Lists.lua Sat Apr 07 13:35:57 2012 -0400 @@ -615,7 +615,7 @@ return ctime end -function SetChangeListener(object) +function SetChangeListener(object) -- todo: holy tits this needs to go changeListener = object -- todo: needs correctness checking, at a minimum end function InitiateChange(finalizeAction,acceptor,arg)
--- a/State.lua Tue Apr 03 23:23:22 2012 -0400 +++ b/State.lua Sat Apr 07 13:35:57 2012 -0400 @@ -37,12 +37,13 @@ -- 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" +state = "neutral" -- states that are possible: neutral, looting, bidding local looting = false stateactive = nil stateitem = nil statebids = {} staterolls = {} +stateactivelist = nil local rollListeners = {} function RegisterListenerRolls(listener) @@ -55,6 +56,28 @@ end end +local listChangeListeners = {} +function RegisterListenerActiveListChanged(listener) + table.insert(listChangeListeners,listener) +end +function AlertActiveListChangedListeners() + for i,v in pairs(listChangeListeners) do + print("list out") + v["ActiveListEvent"](v) + end +end + +local stateChangeListeners = {} +function RegisterListenerStateChange(listener) + table.insert(stateChangeListeners,listener) +end +function AlertStateChangeListeners() + for i,v in pairs(stateChangeListeners) do + print("state out") + v["StateEvent"](v) + end +end + function BeginLoot(listValue) if state == "neutral" then state = "looting" @@ -65,12 +88,23 @@ end end -function ActivateList(value) -- doesn't cause a transition, but we only enforce a list selection during certain times + +-- Activate List {{{ +function ActivateList(packet) -- doesn't cause a transition, but we only enforce a list selection during certain times + local list = unpack(packet) if state == "looting" then - active = value + stateactivelist = list + AlertActiveListChangedListeners() end end +function InitiateActivateList(list) + if state == "looting" then + Comm:SendStateChange("AL",list) + end +end +--}}} +-- Open Bidding {{{ function OpenBid(packet) local item = unpack(packet) --if state == "looting" then @@ -84,21 +118,8 @@ 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 - +--}}} +-- Bid {{{ function ReceivedBid(packet) -- no state transition, but only matters during one state local person, roll = unpack(packet) @@ -125,8 +146,8 @@ Comm:SendStateChange("RB",person,roll) end end - - +--}}} +-- Retration {{{ function ReceivedRetraction(packet) local person = unpack(packet) if state == "bidding" then @@ -145,16 +166,48 @@ Comm:SendStateChange("RR",person,roll) end end - -function CloseBidding(awardedTo) +--}}} +-- Close Bidding {{{ +function CloseBidding(packet) + local awardedTo = unpack(packet) state = "looting" - -- remove the item, record history + -- remove the item from the window, record history end -function CloseLooting() +function InitiateCloseBidding(awardedTo) + Comm:SendStateChange("CB",awardedTo) +end +--}}} + +function CloseLooting(packet) state = "neutral" active = nil item = nil bids = {} rolls = {} end + +function InitiateCloseLooting() + Comm:SendStateChange("CL") +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) + elseif state == "CB" then + CloseBidding(packet) + elseif state == "CB" then + CloseLooting(packet) + elseif state == "AL" then + ActivateList(packet) + else -- todo ... + + end +end +