Mercurial > wow > breuesk
diff State.lua @ 73:7eb2963eea7d
Further splitting up GUI and State
Starting to integrate looting events
author | John@Yosemite-PC |
---|---|
date | Sun, 08 Apr 2012 22:13:17 -0400 |
parents | 9e5b0a2368ad |
children | ed1c9fd4cc95 |
line wrap: on
line diff
--- a/State.lua Sat Apr 07 13:35:57 2012 -0400 +++ b/State.lua Sun Apr 08 22:13:17 2012 -0400 @@ -41,9 +41,10 @@ local looting = false stateactive = nil stateitem = nil +stateitemlist = {} statebids = {} staterolls = {} -stateactivelist = nil +stateactivelist = nil local rollListeners = {} function RegisterListenerRolls(listener) @@ -78,16 +79,35 @@ end end -function BeginLoot(listValue) +local itemListListeners = {} +function RegisterItemListListener(listener) + table.insert(itemListListeners,listener) +end +function AlertItemListListeners() + for i,v in pairs(itemListListeners) do + print("item change") + v["ItemListEvent"](v) + end +end + +function BeginLoot(packet) + local items, listValue = unpack(packet) if state == "neutral" then state = "looting" - looting = true - active = listValue + stateactivelist = listValue + stateitemlist = items + AlertItemListListeners() + CreateGUI() -- todo: bad spot, but that's ok for now else _G.error("Bad state transition", state, "looting") end end +function InitiateBeginLoot(items,listValue) + if state == "neutral" then + Comm:SendStateChange("BL",items,listValue) + end +end -- Activate List {{{ function ActivateList(packet) -- doesn't cause a transition, but we only enforce a list selection during certain times @@ -107,16 +127,17 @@ -- Open Bidding {{{ function OpenBid(packet) local item = unpack(packet) - --if state == "looting" then + if state == "looting" then state = "bidding" + AlertStateChangeListeners() item = value - --end + end end function InitiateOpenBid(item) - --if state == "looting" then - Comm:SendStateChange("OB",item) - --end + if state == "looting" then + Comm:SendStateChange("OB",item) + end end --}}} -- Bid {{{ @@ -171,6 +192,7 @@ function CloseBidding(packet) local awardedTo = unpack(packet) state = "looting" + AlertStateChangeListeners() -- remove the item from the window, record history end @@ -178,31 +200,36 @@ Comm:SendStateChange("CB",awardedTo) end --}}} - +-- Close Looting {{{ function CloseLooting(packet) state = "neutral" - active = nil - item = nil - bids = {} - rolls = {} + stateactive = nil + stateitem = nil + stateitemlist = {} + statebids = {} + staterolls = {} + AlertStateChangeListeners() + AlertItemListListeners() 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 == "BL" then + BeginLoot(packet) elseif state == "RR" then ReceivedRetraction(packet) elseif state == "OB" then OpenBid(packet) elseif state == "CB" then CloseBidding(packet) - elseif state == "CB" then + elseif state == "CL" then CloseLooting(packet) elseif state == "AL" then ActivateList(packet) @@ -211,3 +238,17 @@ end end +function InitializeState() + local ltemp = 0 + local lids = LootLists:GetAllIds() + for _,v in pairs(lids) do + local l = LootLists:Select(v) + if l:GetLength() > 0 then + if ltemp == 0 then + ltemp = l:GetId() + end + end + end + stateactivelist = ltemp +end +