comparison Gui.lua @ 63:00cb497201d0

Left side of the GUI works ...
author John@Yosemite-PC
date Mon, 26 Mar 2012 20:31:45 -0400
parents dcf7c835d0a7
children d3f64d7246b3
comparison
equal deleted inserted replaced
62:619e4b9c3cd9 63:00cb497201d0
23 end 23 end
24 if color == nil then return str end 24 if color == nil then return str end
25 return "|cff"..tostring(color or "ffffff")..str.."|r" 25 return "|cff"..tostring(color or "ffffff")..str.."|r"
26 end 26 end
27 27
28 local CreateListSelector = function(OnValueChanged) 28 local CreateListSelector = function(SListPopulator)
29 PersonList:RefreshRaidList() 29 PersonList:RefreshRaidList()
30 local pulldown = AceGUI:Create("Dropdown") 30 local pulldown = AceGUI:Create("Dropdown")
31 local pull = {} 31 local pull = {}
32 local ltemp = 0 32 local ltemp = 0
33 local lids = LootLists:GetAllIds() 33 local lids = LootLists:GetAllIds()
42 end 42 end
43 end 43 end
44 end 44 end
45 pulldown:SetWidth(175) 45 pulldown:SetWidth(175)
46 pulldown:SetList(pull) 46 pulldown:SetList(pull)
47 pulldown:SetCallback("OnValueChanged", OnValueChanged) 47 pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:SetList(value) end)
48 if ltemp > 0 then pulldown:SetValue(ltemp); OnValueChanged(nil,nil,ltemp) end -- sadly, SetValue doesn't fire a OnValueChanged 48 if ltemp > 0 then pulldown:SetValue(ltemp); SListPopulator:SetList(ltemp) end -- sadly, SetValue doesn't fire a OnValueChanged
49 return pulldown 49 return pulldown
50 end 50 end
51 51
52 local tree = {}
53 local ovc = function(t1,value)
54 tree = {}
55 local l = LootLists:Select(value)
56 for le in l:OrderedListEntryIter() do
57 local line = {value=le:GetId(),text=le:GetName(),icon=[[Interface\Glues\CharacterCreate\UI-CharacterCreate-Classes]]}
58 line.iconCoords=_G.CLASS_ICON_TCOORDS[le:GetClass()]
59 line.text=colorize(line.text,_G.RAID_CLASS_COLORS[le:GetClass()])
60 line.disabled = not PersonList:IsActive(le:GetId())
61 table.insert(tree,line)
62 end
63 t1:SetList(tree)
64 end
65 local f 52 local f
66 local escapeButton = 53 local escapeButton =
67 { 54 {
68 shown = false, 55 shown = false,
69 ["IsShown"] = function(self) return self.shown end, 56 ["IsShown"] = function(self) return self.shown end,
70 ["Hide"] = function(self) if f then AceGUI:Release(f); self.shown=false end end 57 ["Hide"] = function(self) if f then AceGUI:Release(f); self.shown=false end end
71 } 58 }
72 59
60 local function FilterEventDispatcher()
61 end
62
63 SListEventDispatch =
64 {
65 listeners= {},
66 target = nil,
67 ["SetTarget"] = function(self,other)
68 self.target = other
69 self.target:SetCallback("OnSelectionCleared",SListListenerRebindOSC)
70 self.target:SetCallback("OnSelection",SListListenerRebindOS)
71 end,
72 ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end,
73 ["OnSelectionCleared"] = function(self,_)
74 self:Event("OnSelectionCleared")
75 end,
76 ["OnSelection"] = function(self,_,line)
77 self:Event("OnSelection",line)
78 end,
79 ["Event"] = function(self,event,arg)
80 if not self.target then error("Event called with no listener...") end
81 if not self.listeners then return end
82 for i,v in pairs(self.listeners) do
83 if type(v) == "table" then
84 if v[event] then
85 v[event](v,arg)
86 end
87 elseif type(v) == "function" then
88 v(event,arg)
89 elseif type(v) ~= "nil" then -- allow nils to pass quietly
90 _G.error("Bad listener - "..type(v))
91 end
92 end
93 end,
94 ["Release"] = function(self) self.listeners = {}; target=nil end
95 }
96 function SListListenerRebindOSC(...)
97 SListEventDispatch:OnSelectionCleared(...)
98 end
99 function SListListenerRebindOS(...)
100 SListEventDispatch:OnSelection(...)
101 end
102 local SListPopulator =
103 {
104 filtered = false,
105 widget = nil,
106 data = nil,
107 lref = nil,
108
109 ["Release"] = function(self) self.filtered, self.widget, self.data, self.lref = false, nil, nil, nil end,
110 ["Redraw"] = function(self)
111 if self.lref == nil or self.widget == nil then return end -- don't do work if not fully initialized
112 self.data = {}
113 for le in self.lref:OrderedListEntryIter() do
114 local disabled = not PersonList:IsActive(le:GetId())
115 if not self.filtered or not disabled then
116 local line = {value=le:GetId(),text=le:GetName(),icon=[[Interface\Glues\CharacterCreate\UI-CharacterCreate-Classes]]}
117 line.iconCoords=_G.CLASS_ICON_TCOORDS[le:GetClass()]
118 line.text=colorize(line.text,_G.RAID_CLASS_COLORS[le:GetClass()])
119 line.disabled = disabled
120 table.insert(self.data,line)
121 end
122 end
123 self.widget:SetList(self.data)
124 end,
125 ["SetWidget"] = function(self,w)
126 if type(w) ~= "table" or w["SetList"] == nil then
127 _G.error("Bad SetWidget")
128 end
129 self.widget = w
130 end,
131 ["SetFiltered"] = function(self,value)
132 self.filtered = value
133 self:Redraw()
134 end,
135 ["SetList"] = function(self,value)
136 self.lref = LootLists:Select(value)
137 self:Redraw()
138 end
139 }
140
73 function CreateGUI() 141 function CreateGUI()
74 -- special registration procedure to be closable with the escape button 142 -- special registration procedure to be closable with the escape button
75 --escapeButton.shown = true 143 --escapeButton.shown = true
76 --_G["BSK_ESCAPEBUTTON"] = escapeButton 144 --_G["BSK_ESCAPEBUTTON"] = escapeButton
77 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON") 145 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON")
78 146
79 if f then return end -- no second gui please 147 if f then return end -- no second gui please
80 local admin = bsk.admin or true 148 local admin = bsk.admin or true
81 f = AceGUI:Create("Frame") 149 f = AceGUI:Create("Frame")
82 150
83 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil end) 151 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; SListEventDispatch:Release(); SListPopulator:Release() end)
84 f:SetTitle("BSK") 152 f:SetTitle("BSK")
85 f:SetLayout("Flow") 153 f:SetLayout("Flow")
86 f:SetHeight(680) 154 f:SetHeight(680)
87 f:SetWidth(580) 155 f:SetWidth(580)
88 156
100 168
101 local t1 = AceGUI:Create("SelectorList") 169 local t1 = AceGUI:Create("SelectorList")
102 t1:SetNumLines(25) 170 t1:SetNumLines(25)
103 t1:SetFullWidth(true) 171 t1:SetFullWidth(true)
104 t1:SetInteractive(admin) 172 t1:SetInteractive(admin)
105 173 SListPopulator:SetWidget(t1)
106 local listChange = function(_,_,value) 174 SListEventDispatch:SetTarget(t1)
107 ovc(t1,value) 175
108 end 176 local p1 = CreateListSelector(SListPopulator)
109 local p1 = CreateListSelector(listChange)
110 p1:SetFullWidth(true) 177 p1:SetFullWidth(true)
111 178
112 left:AddChild(p1) 179 left:AddChild(p1)
113 left:AddChild(t1) 180 left:AddChild(t1)
114 181
179 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end ) 246 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
180 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end ) 247 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
181 local b1 = AceGUI:Create("SelectorList") 248 local b1 = AceGUI:Create("SelectorList")
182 b1:SetNumLines(6) 249 b1:SetNumLines(6)
183 b1:SetInteractive(admin) 250 b1:SetInteractive(admin)
184 local dummydata = {copy(tree[1]),copy( tree[2] ),copy( tree[3] )} 251 local dummydata= {}
185 for i,v in pairs(dummydata) do v.disabled = false end 252 local tree =SListPopulator.data
186 dummydata[2].text = dummydata[2].text .. " (roll 73)" 253 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
254 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
187 b1:SetList(dummydata) 255 b1:SetList(dummydata)
188 local bidTitle = AceGUI:Create("Label") 256 local bidTitle = AceGUI:Create("Label")
189 bidTitle:SetText("Current bids") 257 bidTitle:SetText("Current bids")
190 bidTitle:SetFullWidth(true) 258 bidTitle:SetFullWidth(true)
191 259
215 g1:AddChildren(adminForce,adminRetract) 283 g1:AddChildren(adminForce,adminRetract)
216 284
217 suicideSelected = AceGUI:Create("Button") 285 suicideSelected = AceGUI:Create("Button")
218 suicideSelected:SetFullWidth(true) 286 suicideSelected:SetFullWidth(true)
219 suicideSelected:SetText("Suicide") 287 suicideSelected:SetText("Suicide")
288 suicideSelected:SetDisabled(true) -- default is no selection has been made
289 -- use userdata + SListEventDispatch to toggle state
290 suicideSelected.userdata =
291 {
292 widget = suicideSelected,
293 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false) end,
294 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true) end
295 }
296 SListEventDispatch:RegisterListener(suicideSelected.userdata)
220 297
221 undo = AceGUI:Create("Button") 298 undo = AceGUI:Create("Button")
222 undo:SetText("Undo") 299 undo:SetText("Undo / out of order")
223 undo:SetFullWidth(true) 300 undo:SetFullWidth(true)
301 undo:SetDisabled(true)
224 end 302 end
225 303
226 304
227 local filter = AceGUI:Create("CheckBox") 305 local filter = AceGUI:Create("CheckBox")
228 filter:SetLabel("Only show active") 306 filter:SetLabel("Only show active")
229 filter:SetFullWidth(true) 307 filter:SetFullWidth(true)
308 filter:SetValue(false)
309 SListPopulator:SetFiltered(false)
310 filter:SetCallback("OnValueChanged",function(widget,_,value) SListPopulator:SetFiltered(value) end)
230 311
231 left:AddChildren(filter) 312 left:AddChildren(filter)
232 if admin then left:AddChildren(suicideSelected,undo) end 313 if admin then left:AddChildren(suicideSelected,undo) end
233 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1) 314 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
234 if admin then biddingZone:AddChildren(g1) end 315 if admin then biddingZone:AddChildren(g1) end