Mercurial > wow > breuesk
diff Gui.lua @ 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 |
line wrap: on
line diff
--- 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 = {