Mercurial > wow > breuesk
changeset 68:a177b863ed6c
Event chaining from the data storage to the GUI elements
author | John@Yosemite-PC |
---|---|
date | Wed, 28 Mar 2012 23:29:36 -0400 |
parents | 8387dc2ff658 |
children | b7352f007028 |
files | Core.lua Gui.lua Lists.lua |
diffstat | 3 files changed, 50 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Tue Mar 27 10:19:48 2012 -0400 +++ b/Core.lua Wed Mar 28 23:29:36 2012 -0400 @@ -48,6 +48,7 @@ local HandlePassThrough = function(...) HandleCommand(...) end bsk:RegisterChatCommand("bsk", HandlePassThrough) + bsk:OnInitializeSetStaticData() end function OnEnable()
--- a/Gui.lua Tue Mar 27 10:19:48 2012 -0400 +++ b/Gui.lua Wed Mar 28 23:29:36 2012 -0400 @@ -46,8 +46,8 @@ end pulldown:SetWidth(175) pulldown:SetList(pull) - pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:SetList(value) end) - if ltemp > 0 then pulldown:SetValue(ltemp); SListPopulator:SetList(ltemp) end -- sadly, SetValue doesn't fire a OnValueChanged + 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 return pulldown end @@ -110,19 +110,6 @@ LListEventDispatch = SelectorListEventDispatcher:new() RListEventDispatch = SelectorListEventDispatcher:new() -local AdminLootEventCollector = -{ - listeners = {}, - target1 = - { - }, - target2 = - { - }, - - -} - local SListPopulator = { filtered = false, @@ -158,12 +145,39 @@ self.filtered = value self:Redraw() end, - ["SetList"] = function(self,value) + ["SelectList"] = function(self,value) self.lref = LootLists:Select(value) self:Redraw() + end, + ["DataEvent"] = function(self) + self:Redraw() end } +DataEventDispatch = +{ + -- todo: batch events + listeners = {}, + ["DataEvent"] = function(self,_) --todo: pass along the received event + for i,v in pairs(self.listeners) do + if v and v["DataEvent"] then + v:DataEvent() + end + end + end, + ["RegisterListener"] = function(self,listener) + if not listener or not listener["DataEvent"] then + _G.error("Bad listener") + end + table.insert(self.listeners,listener) + end +} + +function OnInitializeSetStaticData() + SetChangeListener(DataEventDispatch) + DataEventDispatch:RegisterListener(SListPopulator) +end + function CreateGUI() -- special registration procedure to be closable with the escape button --escapeButton.shown = true @@ -261,8 +275,10 @@ function(widget) if widget.userdata.state then -- we were bidding when the button was pressed biddingZone:ReleaseChildren() + widget:SetText("Open Bids") RListEventDispatch:Release() else + widget:SetText("Close bids") local spacer = AceGUI:Create("Label") spacer:SetText(" ") spacer:SetFullWidth(true) @@ -417,6 +433,14 @@ suicideSelected = AceGUI:Create("Button") suicideSelected:SetFullWidth(true) suicideSelected:SetText("Suicide") + suicideSelected:SetCallback("OnClick", + function(_) + local p = SListEventDispatch:LatestValue() + local lref = SListPopulator.lref + lref:SuicidePerson(p.value) + end + ) + -- use userdata + SListEventDispatch to toggle state suicideSelected.userdata = {
--- a/Lists.lua Tue Mar 27 10:19:48 2012 -0400 +++ b/Lists.lua Wed Mar 28 23:29:36 2012 -0400 @@ -84,6 +84,8 @@ local setmetatable=setmetatable setfenv(1,bsk) +local changeListener = nil -- todo: really should not be scoped like this + ListEntry = { index = 0.0, @@ -530,6 +532,7 @@ -- todo: check that they're not already reserved self.active.reserve[le:GetId()] = true end + changeListener:DataEvent() -- todo: revisit end -- todo: remove reserve function PersonList:IsActive(id) -- todo: support LE as input - saves IsActive(le:GetId()) @@ -612,6 +615,9 @@ return ctime end +function SetChangeListener(object) + changeListener = object -- todo: needs correctness checking, at a minimum +end function InitiateChange(finalizeAction,acceptor,arg) local change = {} change.time = GetSafeTimestamp() @@ -620,6 +626,9 @@ if acceptor[finalizeAction](acceptor,arg,change.time) then table.insert(db.profile.changes,change) + if changeListener then + changeListener:DataEvent(change) + end -- TODO: broadcast return arg else