Mercurial > wow > breuesk
changeset 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 | 15844864a5f7 |
files | Core.lua Gui.lua Looting.lua State.lua breuesk.toc |
diffstat | 5 files changed, 143 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Sat Apr 07 13:35:57 2012 -0400 +++ b/Core.lua Sun Apr 08 22:13:17 2012 -0400 @@ -53,10 +53,12 @@ bsk:RegisterChatCommand("bsk", HandlePassThrough) bsk:OnInitializeSetStaticData() InitializeComm() + InitializeLooting() end function OnEnable() CreateWorkingStateFromChanges(db.profile.changes) + InitializeState() --CreateGUI() end
--- a/Gui.lua Sat Apr 07 13:35:57 2012 -0400 +++ b/Gui.lua Sun Apr 08 22:13:17 2012 -0400 @@ -33,7 +33,6 @@ PersonList:RefreshRaidList() local pulldown = AceGUI:Create("Dropdown") local pull = {} - local ltemp = 0 local lids = LootLists:GetAllIds() for _,v in pairs(lids) do local l = LootLists:Select(v) @@ -41,16 +40,13 @@ --local entry = {value=i,text=v.name} if l:GetLength() > 0 then pulldown:SetItemDisabled(i,true) - if ltemp == 0 then - ltemp = l:GetId() - end end end pulldown:SetWidth(175) pulldown:SetList(pull) SListPopulator:SetSwidget(pulldown) pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:PulldownEvent(value) end) - if ltemp > 0 then SListPopulator:PulldownEvent(ltemp) end -- default value + if stateactivelist > 0 then SListPopulator:PulldownEvent(stateactivelist) end -- default value return pulldown end @@ -175,6 +171,7 @@ self:Redraw() end, ["StateEvent"] = function(self) + print("State event in SL: ", state, admin) if state == "bidding" or (state == "looting" and not admin) then self.swidget:SetDisabled(true) self:SelectList(stateactivelist) @@ -210,9 +207,17 @@ data = {}, widget = nil, ["Release"] = function(self) self.data = {}; self.widget = nil end, + ["ItemListEvent"] = function(self) self:Redraw() end, ["Redraw"]= function(self) - self.widget:SetList(self.data) - LListEventDispatch:Event("Redraw") + self.data = {} + for i,v in pairs(stateitemlist) do + local entry = {value=i, text=v, link=v} + table.insert(self.data,entry) + end + if self.widget then + self.widget:SetList(self.data) + LListEventDispatch:Event("Redraw") + end end, ["SetWidget"] = function(self,w) if type(w) ~= "table" or type(w.SetList) ~= "function" then @@ -325,6 +330,7 @@ RegisterListenerActiveListChanged(SListPopulator) RegisterListenerStateChange(SListPopulator) RegisterListenerRolls(RListPopulator) + RegisterItemListListener(LListPopulator) end function CreateGUI()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looting.lua Sun Apr 08 22:13:17 2012 -0400 @@ -0,0 +1,69 @@ +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 getn=getn + +local event = LibStub("AceEvent-3.0") + +setfenv(1,bsk) + +local isMasterLootEvent = false + +local function OpenMasterLootList() + print("Open!") + isMasterLootEvent = true +end + +local function UpdateMasterLootList() + print("Update MLL!") +end + +local function LootClosed() + print("Close!") + if isMasterLootEvent then + isMasterLootEvent = false -- end the event + InitiateCloseLooting() + end +end + +local function LootOpened() + print("Open loot!") + isMasterLootEvent = false + local n = _G.GetNumLootItems() + for i = 1,n do + _G.LootSlot(i) + end + local items = {} + for i = 1,n do + local link = _G.GetLootSlotLink(i) + if link then + table.insert(items,link) + print("Item: ", link) + end + end + if not isMasterLootEvent then return end + + print("Let's get started SKing") + -- todo: check that I am ML and that I'm an admin! + + -- make state: gather all item links, transmit them plus the new looting + -- state + -- + InitiateBeginLoot(items,stateactivelist) + +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) +end +
--- 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 +