changeset 65:d3f64d7246b3

Significant effort to start making the GUI behave in an intuitive way. But it's still completely useless ...
author John@Yosemite-PC
date Mon, 26 Mar 2012 23:47:24 -0400
parents f0450883c283
children 331b5e176d79
files Gui.lua
diffstat 1 files changed, 165 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/Gui.lua	Mon Mar 26 23:46:17 2012 -0400
+++ b/Gui.lua	Mon Mar 26 23:47:24 2012 -0400
@@ -3,6 +3,7 @@
 local _G=_G
 local table=table 
 local pairs=pairs
+local setmetatable=setmetatable
 local ipairs=ipairs
 local string=string
 local tostring=tostring
@@ -49,7 +50,7 @@
     return pulldown
 end
 
-local f
+local f, right
 local escapeButton = 
 {
     shown = false,
@@ -57,29 +58,28 @@
     ["Hide"] = function(self) if f then AceGUI:Release(f); self.shown=false end end
 }
 
-local function FilterEventDispatcher()
-end
 
-SListEventDispatch =
+SelectorListEventDispatcher =
 {
-    listeners= {},
+    listeners = nil,
     target = nil,
     ["SetTarget"] = function(self,other)
         self.target = other 
-        self.target:SetCallback("OnSelectionCleared",SListListenerRebindOSC)
-        self.target:SetCallback("OnSelection",SListListenerRebindOS)
+        self.target:SetCallback("OnSelectionCleared",function(...) self:OnSelectionCleared(...) end)
+        self.target:SetCallback("OnSelection",function(...) self:OnSelection(...) end)
     end,
     ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end,
     ["OnSelectionCleared"] = function(self,_)
         self:Event("OnSelectionCleared")
     end,
-    ["OnSelection"] = function(self,_,line)
+    ["OnSelection"] = function(self,_,_,line)
         self:Event("OnSelection",line)
     end,
     ["Event"] = function(self,event,arg)
         if not self.target then error("Event called with no listener...") end
         if not self.listeners then return end
         for i,v in pairs(self.listeners) do
+            bsk.print("listener")
             if type(v) == "table" then
                 if v[event] then
                     v[event](v,arg)
@@ -91,14 +91,32 @@
             end
         end
     end,
-    ["Release"] = function(self) self.listeners = {}; target=nil end
+    ["Release"] = function(self) self.listeners = {}; self.target=nil end
 }
-function SListListenerRebindOSC(...)
-    SListEventDispatch:OnSelectionCleared(...)
+function SelectorListEventDispatcher:new()
+    local t = {}
+    setmetatable(t,SelectorListEventDispatcher)
+    self.__index = self
+    t.listeners = {}
+    return t
 end
-function SListListenerRebindOS(...)
-    SListEventDispatch:OnSelection(...)
-end
+
+SListEventDispatch = SelectorListEventDispatcher:new()
+LListEventDispatch = SelectorListEventDispatcher:new()
+
+local AdminLootEventCollector =
+{
+    listeners = {},
+    target1 = 
+    {
+    },
+    target2 =
+    {
+    },
+
+
+}
+
 local SListPopulator =
 {
     filtered = false,
@@ -121,9 +139,10 @@
             end
         end
         self.widget:SetList(self.data)
+        SListEventDispatch:Event("Redraw")
     end,
     ["SetWidget"] = function(self,w) 
-        if type(w) ~= "table" or w["SetList"] == nil then
+        if type(w) ~= "table" or type(w.SetList) ~= "function" then
             _G.error("Bad SetWidget")
         end
         self.widget = w
@@ -148,7 +167,7 @@
     local admin = bsk.admin or true
     f = AceGUI:Create("Frame")
 
-    f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; SListEventDispatch:Release(); SListPopulator:Release() end)
+    f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release() end)
     f:SetTitle("BSK")
     f:SetLayout("Flow")
     f:SetHeight(680) 
@@ -160,7 +179,7 @@
     left:SetFullHeight(true)
     left.alignoffset=0.25 -- hack, as per http://forums.wowace.com/showthread.php?t=17114
 
-    local right = AceGUI:Create("InlineGroup")
+    right = AceGUI:Create("InlineGroup")
     right:SetLayout("Flow")
     right:SetWidth(700-175-160)
     right:SetFullHeight(true)
@@ -210,86 +229,160 @@
             link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
         },
     })
+    LListEventDispatch:SetTarget(t2)
+
+    local biddingZone = AceGUI:Create("SimpleGroup")
+    biddingZone:SetLayout("Flow")
+    biddingZone:SetFullWidth(true)
 
     local alb1, alb2, alb3
     if admin then 
         alb1 = AceGUI:Create("Button")
         alb1:SetWidth(100)
         alb1:SetText("Open Bids")
+        alb1.userdata = 
+        {
+            state = false,
+            widget = alb1,
+            ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end,
+            ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end,
+            ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end
+        }
+        alb1:SetDisabled(true)
+        LListEventDispatch:RegisterListener(alb1.userdata)
+        alb1:SetCallback("OnClick", 
+            function(widget) 
+                if widget.userdata.state then -- we were bidding when the button was pressed
+                    biddingZone:ReleaseChildren()
+                else
+                    local spacer = AceGUI:Create("Label")
+                    spacer:SetText(" ")
+                    spacer:SetFullWidth(true)
+                    local spacer2 = AceGUI:Create("Label")
+                    spacer2:SetText(" ")
+                    spacer2:SetFullWidth(true)
+
+                    local label = AceGUI:Create("Label")
+                    label:SetText("Bidding now open for ...")
+                    local biddingOn = AceGUI:Create("InteractiveLabel")
+                    biddingOn.userdata = { "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r" } 
+                    biddingOn:SetText(biddingOn.userdata[1])
+                    biddingOn:SetFullWidth(true)
+                    biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT");  _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
+                    biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
+                    local b1 = AceGUI:Create("SelectorList")
+                    b1:SetNumLines(6)
+                    b1:SetInteractive(admin)
+                    local dummydata= {}
+                    local tree =SListPopulator.data
+                    for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
+                    if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
+                    b1:SetList(dummydata)
+                    local bidTitle = AceGUI:Create("Label")
+                    bidTitle:SetText("Current bids")
+                    bidTitle:SetFullWidth(true)
+
+                    local bidRetractButton = AceGUI:Create("Button")
+                    bidRetractButton:SetText("Place Bid")
+                    bidRetractButton:SetWidth(100)
+                    local rollButton = AceGUI:Create("Button")
+                    rollButton:SetText("Offset Roll")
+                    rollButton:SetWidth(100)
+
+                    local g1
+                    if admin then
+                        b1.alignoffset = 0.25 -- or else g1 won't align well
+                        g1 = AceGUI:Create("SimpleGroup")
+                        g1.alignoffset = 0.25
+                        g1:SetWidth(120)
+                        g1:SetLayout("List")
+
+                        adminForce = AceGUI:Create("Button")
+                        adminForce:SetText("Force bid")
+                        adminForce:SetWidth(100)
+
+                        adminRetract = AceGUI:Create("Button")
+                        adminRetract:SetText("Retract bid")
+                        adminRetract:SetWidth(100)
+
+                        g1:AddChildren(adminForce,adminRetract)
+                    end
+
+                    biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
+                    if admin then biddingZone:AddChildren(g1) end
+
+
+                end
+                widget.userdata.state = not widget.userdata.state
+            end
+        )
 
         alb2 = AceGUI:Create("Button")
         alb2:SetWidth(100)
         alb2:SetText("Assign")
+        alb2.userdata =
+        {
+            widget = alb2,
+            ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
+        }
+        alb2.userdata.slist = 
+        {
+            parent = alb2.userdata,
+            checked = false,
+            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        }
+        alb2.userdata.llist = 
+        {
+            parent = alb2.userdata,
+            checked = false,
+            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        }
+        SListEventDispatch:RegisterListener(alb2.userdata.slist)
+        LListEventDispatch:RegisterListener(alb2.userdata.llist)
 
         alb3 = AceGUI:Create("Button")
         alb3:SetWidth(100)
         alb3:SetText("Suicide")
+        alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this ....
+        {
+            widget = alb3,
+            ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
+        }
+        alb3.userdata.slist = 
+        {
+            parent = alb3.userdata,
+            checked = false,
+            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        }
+        alb3.userdata.llist = 
+        {
+            parent = alb3.userdata,
+            checked = false,
+            ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+            ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
+            ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
+        }
+        SListEventDispatch:RegisterListener(alb3.userdata.slist)
+        LListEventDispatch:RegisterListener(alb3.userdata.llist)
     end
 
-    local spacer = AceGUI:Create("Label")
-    spacer:SetText(" ")
-    spacer:SetFullWidth(true)
-    local spacer2 = AceGUI:Create("Label")
-    spacer2:SetText(" ")
-    spacer2:SetFullWidth(true)
-
-    local biddingZone = AceGUI:Create("SimpleGroup")
-    biddingZone:SetLayout("Flow")
-    biddingZone:SetFullWidth(true)
-
-    local label = AceGUI:Create("Label")
-    label:SetText("Bidding now open for ...")
-    local biddingOn = AceGUI:Create("InteractiveLabel")
-    biddingOn.userdata = { "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r" } 
-    biddingOn:SetText(biddingOn.userdata[1])
-    biddingOn:SetFullWidth(true)
-    biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT");  _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
-    biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
-    local b1 = AceGUI:Create("SelectorList")
-    b1:SetNumLines(6)
-    b1:SetInteractive(admin)
-    local dummydata= {}
-    local tree =SListPopulator.data
-    for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
-    if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
-    b1:SetList(dummydata)
-    local bidTitle = AceGUI:Create("Label")
-    bidTitle:SetText("Current bids")
-    bidTitle:SetFullWidth(true)
-
-    local bidRetractButton = AceGUI:Create("Button")
-    bidRetractButton:SetText("Place Bid")
-    bidRetractButton:SetWidth(100)
-    local rollButton = AceGUI:Create("Button")
-    rollButton:SetText("Offset Roll")
-    rollButton:SetWidth(100)
-
-    local g1, suicideSelected, undo
+    local suicideSelected, undo
     if admin then
-        b1.alignoffset = 0.25 -- or else g1 won't align well
-        g1 = AceGUI:Create("SimpleGroup")
-        g1.alignoffset = 0.25
-        g1:SetWidth(120)
-        g1:SetLayout("List")
-
-        adminForce = AceGUI:Create("Button")
-        adminForce:SetText("Force bid")
-        adminForce:SetWidth(100)
-
-        adminRetract = AceGUI:Create("Button")
-        adminRetract:SetText("Retract bid")
-        adminRetract:SetWidth(100)
-
-        g1:AddChildren(adminForce,adminRetract)
 
         suicideSelected = AceGUI:Create("Button")
         suicideSelected:SetFullWidth(true)
         suicideSelected:SetText("Suicide")
-        suicideSelected:SetDisabled(true) -- default is no selection has been made
         -- use userdata + SListEventDispatch to toggle state
         suicideSelected.userdata = 
         {
             widget = suicideSelected,
+            ["Redraw"] = function(self,_) self.widget:SetDisabled(true) end,
             ["OnSelection"] = function(self,_) self.widget:SetDisabled(false) end,
             ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true) end
         }
@@ -301,7 +394,6 @@
         undo:SetDisabled(true)
     end
 
-
     local filter = AceGUI:Create("CheckBox")
     filter:SetLabel("Only show active")
     filter:SetFullWidth(true)
@@ -311,8 +403,6 @@
 
     left:AddChildren(filter)
     if admin then left:AddChildren(suicideSelected,undo) end
-    biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
-    if admin then biddingZone:AddChildren(g1) end
     right:AddChildren(t2)
     if admin then right:AddChildren(alb1,alb2,alb3) end
     right:AddChildren(biddingZone)