annotate Gui.lua @ 70:236117ab8a49

Decent sketch of what the communication system might look like
author John@Yosemite-PC
date Thu, 29 Mar 2012 23:24:51 -0400
parents b7352f007028
children d5e2dfe0c269
rev   line source
John@38 1 local AceGUI = LibStub("AceGUI-3.0")
John@42 2 local bsk=bsk
John@42 3 local _G=_G
John@42 4 local table=table
John@42 5 local pairs=pairs
John@65 6 local setmetatable=setmetatable
John@42 7 local ipairs=ipairs
John@42 8 local string=string
John@67 9 local sformat=string.format
John@42 10 local tostring=tostring
John@42 11 local type=type
John@42 12 local getn=getn
John@42 13 setfenv(1,bsk)
John@1 14
John@69 15 -- todo: switching lists should close a presently-open bid
John@69 16
John@56 17 local copy = function(t)
John@56 18 local c = {}
John@56 19 if not t then return c end
John@56 20 for i,v in pairs(t) do c[i] = v end
John@56 21 return c
John@56 22 end
John@56 23 local colorize = function(str,color)
John@56 24 if str==nil or str=="" then return "" end
John@56 25 if type(color) == "table" then
John@56 26 color = string.format("%02x%02x%02x",255*color.r,255*color.g,255*color.b)
John@56 27 end
John@56 28 if color == nil then return str end
John@56 29 return "|cff"..tostring(color or "ffffff")..str.."|r"
John@56 30 end
John@1 31
John@63 32 local CreateListSelector = function(SListPopulator)
John@56 33 PersonList:RefreshRaidList()
John@56 34 local pulldown = AceGUI:Create("Dropdown")
John@56 35 local pull = {}
John@56 36 local ltemp = 0
John@56 37 local lids = LootLists:GetAllIds()
John@56 38 for _,v in pairs(lids) do
John@56 39 local l = LootLists:Select(v)
John@56 40 pull[l:GetId()] = l:GetName()
John@56 41 --local entry = {value=i,text=v.name}
John@56 42 if l:GetLength() > 0 then
John@56 43 pulldown:SetItemDisabled(i,true)
John@56 44 if ltemp == 0 then
John@56 45 ltemp = l:GetId()
John@51 46 end
John@51 47 end
John@1 48 end
John@56 49 pulldown:SetWidth(175)
John@56 50 pulldown:SetList(pull)
John@68 51 pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:SelectList(value) end)
John@68 52 if ltemp > 0 then pulldown:SetValue(ltemp); SListPopulator:SelectList(ltemp) end -- sadly, SetValue doesn't fire a OnValueChanged
John@56 53 return pulldown
John@1 54 end
John@1 55
John@65 56 local f, right
John@59 57 local escapeButton =
John@59 58 {
John@59 59 shown = false,
John@59 60 ["IsShown"] = function(self) return self.shown end,
John@60 61 ["Hide"] = function(self) if f then AceGUI:Release(f); self.shown=false end end
John@59 62 }
John@38 63
John@65 64 SelectorListEventDispatcher =
John@63 65 {
John@65 66 listeners = nil,
John@63 67 target = nil,
John@67 68 line = nil,
John@63 69 ["SetTarget"] = function(self,other)
John@63 70 self.target = other
John@65 71 self.target:SetCallback("OnSelectionCleared",function(...) self:OnSelectionCleared(...) end)
John@65 72 self.target:SetCallback("OnSelection",function(...) self:OnSelection(...) end)
John@63 73 end,
John@63 74 ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end,
John@63 75 ["OnSelectionCleared"] = function(self,_)
John@67 76 self.line = nil
John@63 77 self:Event("OnSelectionCleared")
John@63 78 end,
John@65 79 ["OnSelection"] = function(self,_,_,line)
John@67 80 self.line = line
John@63 81 self:Event("OnSelection",line)
John@63 82 end,
John@63 83 ["Event"] = function(self,event,arg)
John@63 84 if not self.target then error("Event called with no listener...") end
John@63 85 if not self.listeners then return end
John@63 86 for i,v in pairs(self.listeners) do
John@67 87 --bsk.print("listener")
John@63 88 if type(v) == "table" then
John@63 89 if v[event] then
John@63 90 v[event](v,arg)
John@63 91 end
John@63 92 elseif type(v) == "function" then
John@63 93 v(event,arg)
John@63 94 elseif type(v) ~= "nil" then -- allow nils to pass quietly
John@63 95 _G.error("Bad listener - "..type(v))
John@63 96 end
John@63 97 end
John@63 98 end,
John@67 99 ["Release"] = function(self) self.listeners = {}; self.target=nil; self.line=nil end,
John@67 100 ["LatestValue"] = function(self) return self.line end
John@63 101 }
John@65 102 function SelectorListEventDispatcher:new()
John@65 103 local t = {}
John@65 104 setmetatable(t,SelectorListEventDispatcher)
John@65 105 self.__index = self
John@65 106 t.listeners = {}
John@65 107 return t
John@63 108 end
John@65 109
John@65 110 SListEventDispatch = SelectorListEventDispatcher:new()
John@65 111 LListEventDispatch = SelectorListEventDispatcher:new()
John@67 112 RListEventDispatch = SelectorListEventDispatcher:new()
John@65 113
John@63 114 local SListPopulator =
John@63 115 {
John@63 116 filtered = false,
John@63 117 widget = nil,
John@63 118 data = nil,
John@63 119 lref = nil,
John@63 120
John@63 121 ["Release"] = function(self) self.filtered, self.widget, self.data, self.lref = false, nil, nil, nil end,
John@63 122 ["Redraw"] = function(self)
John@63 123 if self.lref == nil or self.widget == nil then return end -- don't do work if not fully initialized
John@63 124 self.data = {}
John@63 125 for le in self.lref:OrderedListEntryIter() do
John@63 126 local disabled = not PersonList:IsActive(le:GetId())
John@63 127 if not self.filtered or not disabled then
John@63 128 local line = {value=le:GetId(),text=le:GetName(),icon=[[Interface\Glues\CharacterCreate\UI-CharacterCreate-Classes]]}
John@63 129 line.iconCoords=_G.CLASS_ICON_TCOORDS[le:GetClass()]
John@67 130 line.textPlain = line.text
John@63 131 line.text=colorize(line.text,_G.RAID_CLASS_COLORS[le:GetClass()])
John@63 132 line.disabled = disabled
John@63 133 table.insert(self.data,line)
John@63 134 end
John@63 135 end
John@63 136 self.widget:SetList(self.data)
John@65 137 SListEventDispatch:Event("Redraw")
John@63 138 end,
John@63 139 ["SetWidget"] = function(self,w)
John@65 140 if type(w) ~= "table" or type(w.SetList) ~= "function" then
John@63 141 _G.error("Bad SetWidget")
John@63 142 end
John@63 143 self.widget = w
John@63 144 end,
John@63 145 ["SetFiltered"] = function(self,value)
John@63 146 self.filtered = value
John@63 147 self:Redraw()
John@63 148 end,
John@68 149 ["SelectList"] = function(self,value)
John@63 150 self.lref = LootLists:Select(value)
John@63 151 self:Redraw()
John@68 152 end,
John@68 153 ["DataEvent"] = function(self)
John@68 154 self:Redraw()
John@69 155 end,
John@69 156 ["GetMe"] = function(self)
John@69 157 local me = _G.UnitName("player")
John@69 158 for i,v in pairs(self.data) do
John@69 159 if v.textPlain == me then
John@69 160 return v
John@69 161 end
John@69 162 end
John@69 163 end,
John@69 164 }
John@69 165
John@69 166 local LListPopulator =
John@69 167 {
John@69 168 -- todo: set event receivers from the comm and for loot
John@69 169 data = {},
John@69 170 widget = nil,
John@69 171 ["Release"] = function(self) self.data = {}; self.widget = nil end,
John@69 172 ["Redraw"]= function(self)
John@69 173 self.widget:SetList(self.data)
John@69 174 LListEventDispatch:Event("Redraw")
John@69 175 end,
John@69 176 ["SetWidget"] = function(self,w)
John@69 177 if type(w) ~= "table" or type(w.SetList) ~= "function" then
John@69 178 _G.error("Bad SetWidget")
John@69 179 end
John@69 180 self.widget = w
John@69 181 if debug then
John@69 182 self.data = {
John@69 183 {
John@69 184 value=1,
John@69 185 text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
John@69 186 link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
John@69 187 },
John@69 188 {
John@69 189 value=2,
John@69 190 text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r",
John@69 191 link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r"
John@69 192 },
John@69 193 {
John@69 194 value=3,
John@69 195 text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r",
John@69 196 link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r"
John@69 197 },
John@69 198 {
John@69 199 value=4,
John@69 200 text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r",
John@69 201 link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r"
John@69 202 },
John@69 203 {
John@69 204 value=5,
John@69 205 text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
John@69 206 link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
John@69 207 },
John@69 208 }
John@69 209 end
John@69 210 self:Redraw()
John@69 211 end,
John@69 212 }
John@69 213
John@69 214 local RListPopulator =
John@69 215 {
John@69 216 data = {},
John@69 217 widget = nil,
John@69 218 ["Release"] = function(self) self.data = {}; self.widget = nil end,
John@69 219 ["Redraw"] = function(self)
John@69 220 self.widget:SetList(self.data)
John@69 221 RListEventDispatch:Event("Redraw")
John@69 222 end,
John@69 223 ["SetWidget"] = function(self,w)
John@69 224 if type(w) ~= "table" or type(w.SetList) ~= "function" then
John@69 225 _G.error("Bad SetWidget")
John@69 226 end
John@69 227 self.widget = w
John@69 228 if debug then
John@69 229 local dummydata = {}
John@69 230 local tree = SListPopulator.data
John@69 231 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
John@69 232 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
John@69 233 self.data = dummydata
John@69 234 end
John@69 235 self:Redraw()
John@69 236 end,
John@69 237 ["Force"] = function(self,who)
John@69 238 for i,v in pairs(self.data) do
John@69 239 if who.value == v.value then
John@69 240 print(who.value .. " is already on the list")
John@69 241 return -- no double adds please
John@69 242 end
John@69 243 end
John@69 244 local new = self.Convert(who,72)
John@69 245 table.insert(self.data,new)
John@69 246 -- todo: keep this list sorted
John@69 247 self:Redraw()
John@69 248 end,
John@69 249 ["Retract"] = function(self,who)
John@69 250 for i,v in pairs(self.data) do
John@69 251 if who.value == v.value then
John@69 252 table.remove(self.data,i)
John@69 253 end
John@69 254 end
John@69 255 self:Redraw()
John@69 256 end,
John@69 257 ["Convert"] = function(who,roll) -- convert an LE object into one suitable to put in a SelectorList
John@69 258 local new = copy(who)
John@69 259 new.disabled = false -- todo: should be unnessary - they can't get on the list like this
John@69 260 if roll then
John@69 261 new.text = new.text .. " (roll 73)"
John@69 262 end
John@69 263 return new
John@69 264 end,
John@63 265 }
John@63 266
John@68 267 DataEventDispatch =
John@68 268 {
John@68 269 -- todo: batch events
John@68 270 listeners = {},
John@68 271 ["DataEvent"] = function(self,_) --todo: pass along the received event
John@68 272 for i,v in pairs(self.listeners) do
John@68 273 if v and v["DataEvent"] then
John@68 274 v:DataEvent()
John@68 275 end
John@68 276 end
John@68 277 end,
John@68 278 ["RegisterListener"] = function(self,listener)
John@68 279 if not listener or not listener["DataEvent"] then
John@68 280 _G.error("Bad listener")
John@68 281 end
John@68 282 table.insert(self.listeners,listener)
John@68 283 end
John@68 284 }
John@68 285
John@68 286 function OnInitializeSetStaticData()
John@68 287 SetChangeListener(DataEventDispatch)
John@68 288 DataEventDispatch:RegisterListener(SListPopulator)
John@68 289 end
John@68 290
John@42 291 function CreateGUI()
John@59 292 -- special registration procedure to be closable with the escape button
John@59 293 --escapeButton.shown = true
John@59 294 --_G["BSK_ESCAPEBUTTON"] = escapeButton
John@59 295 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON")
John@59 296
John@60 297 if f then return end -- no second gui please
John@69 298 local admin = admin or true
John@59 299 f = AceGUI:Create("Frame")
John@1 300
John@69 301 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release(); RListEventDispatch:Release(); LListPopulator:Release(); RListPopulator:Release() end)
John@56 302 f:SetTitle("BSK")
John@56 303 f:SetLayout("Flow")
John@56 304 f:SetHeight(680)
John@56 305 f:SetWidth(580)
John@1 306
John@56 307 local left = AceGUI:Create("InlineGroup")
John@56 308 left:SetLayout("List")
John@56 309 left:SetWidth(175)
John@56 310 left:SetFullHeight(true)
John@56 311 left.alignoffset=0.25 -- hack, as per http://forums.wowace.com/showthread.php?t=17114
John@1 312
John@65 313 right = AceGUI:Create("InlineGroup")
John@56 314 right:SetLayout("Flow")
John@56 315 right:SetWidth(700-175-160)
John@56 316 right:SetFullHeight(true)
John@56 317 right.alignoffset=0.25
John@38 318
John@56 319 local t1 = AceGUI:Create("SelectorList")
John@56 320 t1:SetNumLines(25)
John@56 321 t1:SetFullWidth(true)
John@56 322 t1:SetInteractive(admin)
John@69 323 SListEventDispatch:SetTarget(t1)
John@63 324 SListPopulator:SetWidget(t1)
John@38 325
John@63 326 local p1 = CreateListSelector(SListPopulator)
John@56 327 p1:SetFullWidth(true)
John@38 328
John@56 329 left:AddChild(p1)
John@56 330 left:AddChild(t1)
John@38 331
John@56 332 local t2 = AceGUI:Create("SelectorList")
John@56 333 t2:SetNumLines(7)
John@56 334 t2:SetFullWidth(true)
John@56 335 t2:EnableButtonTooltips(true)
John@65 336 LListEventDispatch:SetTarget(t2)
John@69 337 LListPopulator:SetWidget(t2)
John@65 338
John@65 339 local biddingZone = AceGUI:Create("SimpleGroup")
John@65 340 biddingZone:SetLayout("Flow")
John@65 341 biddingZone:SetFullWidth(true)
John@38 342
John@60 343 local alb1, alb2, alb3
John@60 344 if admin then
John@60 345 alb1 = AceGUI:Create("Button")
John@60 346 alb1:SetWidth(100)
John@60 347 alb1:SetText("Open Bids")
John@65 348 alb1.userdata =
John@65 349 {
John@65 350 state = false,
John@65 351 widget = alb1,
John@65 352 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end,
John@65 353 ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end,
John@65 354 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end
John@65 355 }
John@65 356 alb1:SetDisabled(true)
John@65 357 LListEventDispatch:RegisterListener(alb1.userdata)
John@65 358 alb1:SetCallback("OnClick",
John@65 359 function(widget)
John@65 360 if widget.userdata.state then -- we were bidding when the button was pressed
John@65 361 biddingZone:ReleaseChildren()
John@68 362 widget:SetText("Open Bids")
John@67 363 RListEventDispatch:Release()
John@70 364 RListPopulator:Release()
John@65 365 else
John@68 366 widget:SetText("Close bids")
John@65 367 local spacer = AceGUI:Create("Label")
John@65 368 spacer:SetText(" ")
John@65 369 spacer:SetFullWidth(true)
John@65 370 local spacer2 = AceGUI:Create("Label")
John@65 371 spacer2:SetText(" ")
John@65 372 spacer2:SetFullWidth(true)
John@65 373
John@65 374 local label = AceGUI:Create("Label")
John@65 375 label:SetText("Bidding now open for ...")
John@65 376 local biddingOn = AceGUI:Create("InteractiveLabel")
John@67 377 biddingOn.userdata = { LListEventDispatch:LatestValue().link }
John@65 378 biddingOn:SetText(biddingOn.userdata[1])
John@65 379 biddingOn:SetFullWidth(true)
John@65 380 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
John@65 381 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
John@65 382 local b1 = AceGUI:Create("SelectorList")
John@65 383 b1:SetNumLines(6)
John@65 384 b1:SetInteractive(admin)
John@65 385 local bidTitle = AceGUI:Create("Label")
John@65 386 bidTitle:SetText("Current bids")
John@65 387 bidTitle:SetFullWidth(true)
John@65 388
John@65 389 local bidRetractButton = AceGUI:Create("Button")
John@65 390 bidRetractButton:SetText("Place Bid")
John@65 391 bidRetractButton:SetWidth(100)
John@70 392 bidRetractButton:SetCallback("OnClick", function(widget) RListPopulator:Force(SListPopulator:GetMe()) end) -- todo: Force is not the desired thing here.
John@65 393 local rollButton = AceGUI:Create("Button")
John@65 394 rollButton:SetText("Offset Roll")
John@65 395 rollButton:SetWidth(100)
John@65 396
John@69 397 RListEventDispatch:SetTarget(b1)
John@69 398 RListPopulator:SetWidget(b1)
John@67 399
John@65 400 local g1
John@65 401 if admin then
John@65 402 b1.alignoffset = 0.25 -- or else g1 won't align well
John@65 403 g1 = AceGUI:Create("SimpleGroup")
John@65 404 g1.alignoffset = 0.25
John@65 405 g1:SetWidth(120)
John@65 406 g1:SetLayout("List")
John@65 407
John@67 408 -- todo: convoluted and repetitive - surely there's a
John@67 409 -- better way than this ...
John@65 410 adminForce = AceGUI:Create("Button")
John@67 411 if SListEventDispatch:LatestValue() then
John@67 412 adminForce:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain))
John@67 413 adminForce:SetDisabled(false)
John@67 414 else
John@67 415 adminForce:SetText("Force bid")
John@67 416 adminForce:SetDisabled(true)
John@67 417 end
John@67 418 adminForce:SetWidth(160)
John@69 419 adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end)
John@67 420 adminForce.userdata =
John@67 421 {
John@67 422 widget = adminForce,
John@67 423 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end,
John@67 424 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end,
John@67 425 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end
John@67 426 }
John@67 427 SListEventDispatch:RegisterListener(adminForce.userdata)
John@65 428
John@65 429 adminRetract = AceGUI:Create("Button")
John@67 430 if RListEventDispatch:LatestValue() then
John@67 431 adminRetract:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain))
John@67 432 adminRetract:SetDisabled(false)
John@67 433 else
John@67 434 adminRetract:SetText("Retract bid")
John@67 435 adminRetract:SetDisabled(true)
John@67 436 end
John@67 437 adminRetract:SetWidth(160)
John@67 438 adminRetract.userdata =
John@67 439 {
John@67 440 widget = adminRetract,
John@67 441 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end,
John@67 442 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end,
John@67 443 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end
John@67 444 }
John@69 445 adminRetract:SetCallback("OnClick",function(widget) RListPopulator:Retract(RListEventDispatch:LatestValue()) end)
John@67 446 RListEventDispatch:RegisterListener(adminRetract.userdata)
John@67 447 adminRetract:SetDisabled(true)
John@65 448
John@65 449 g1:AddChildren(adminForce,adminRetract)
John@65 450 end
John@65 451
John@65 452 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
John@65 453 if admin then biddingZone:AddChildren(g1) end
John@65 454 end
John@65 455 widget.userdata.state = not widget.userdata.state
John@65 456 end
John@65 457 )
John@60 458
John@60 459 alb2 = AceGUI:Create("Button")
John@60 460 alb2:SetWidth(100)
John@60 461 alb2:SetText("Assign")
John@65 462 alb2.userdata =
John@65 463 {
John@65 464 widget = alb2,
John@65 465 ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
John@65 466 }
John@65 467 alb2.userdata.slist =
John@65 468 {
John@65 469 parent = alb2.userdata,
John@65 470 checked = false,
John@65 471 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 472 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@65 473 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 474 }
John@65 475 alb2.userdata.llist =
John@65 476 {
John@65 477 parent = alb2.userdata,
John@65 478 checked = false,
John@65 479 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 480 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@65 481 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 482 }
John@65 483 SListEventDispatch:RegisterListener(alb2.userdata.slist)
John@65 484 LListEventDispatch:RegisterListener(alb2.userdata.llist)
John@60 485
John@60 486 alb3 = AceGUI:Create("Button")
John@60 487 alb3:SetWidth(100)
John@60 488 alb3:SetText("Suicide")
John@65 489 alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this ....
John@65 490 {
John@65 491 widget = alb3,
John@65 492 ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
John@65 493 }
John@65 494 alb3.userdata.slist =
John@65 495 {
John@65 496 parent = alb3.userdata,
John@65 497 checked = false,
John@65 498 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 499 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@65 500 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 501 }
John@65 502 alb3.userdata.llist =
John@65 503 {
John@65 504 parent = alb3.userdata,
John@65 505 checked = false,
John@65 506 ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 507 ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@65 508 ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@65 509 }
John@65 510 SListEventDispatch:RegisterListener(alb3.userdata.slist)
John@65 511 LListEventDispatch:RegisterListener(alb3.userdata.llist)
John@60 512 end
John@38 513
John@65 514 local suicideSelected, undo
John@60 515 if admin then
John@60 516
John@60 517 suicideSelected = AceGUI:Create("Button")
John@60 518 suicideSelected:SetFullWidth(true)
John@60 519 suicideSelected:SetText("Suicide")
John@68 520 suicideSelected:SetCallback("OnClick",
John@68 521 function(_)
John@68 522 local p = SListEventDispatch:LatestValue()
John@68 523 local lref = SListPopulator.lref
John@68 524 lref:SuicidePerson(p.value)
John@68 525 end
John@68 526 )
John@68 527
John@63 528 -- use userdata + SListEventDispatch to toggle state
John@63 529 suicideSelected.userdata =
John@63 530 {
John@63 531 widget = suicideSelected,
John@65 532 ["Redraw"] = function(self,_) self.widget:SetDisabled(true) end,
John@63 533 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false) end,
John@63 534 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true) end
John@63 535 }
John@63 536 SListEventDispatch:RegisterListener(suicideSelected.userdata)
John@60 537
John@60 538 undo = AceGUI:Create("Button")
John@63 539 undo:SetText("Undo / out of order")
John@60 540 undo:SetFullWidth(true)
John@63 541 undo:SetDisabled(true)
John@60 542 end
John@60 543
John@56 544 local filter = AceGUI:Create("CheckBox")
John@56 545 filter:SetLabel("Only show active")
John@56 546 filter:SetFullWidth(true)
John@63 547 filter:SetValue(false)
John@63 548 SListPopulator:SetFiltered(false)
John@63 549 filter:SetCallback("OnValueChanged",function(widget,_,value) SListPopulator:SetFiltered(value) end)
John@56 550
John@56 551 left:AddChildren(filter)
John@56 552 if admin then left:AddChildren(suicideSelected,undo) end
John@56 553 right:AddChildren(t2)
John@56 554 if admin then right:AddChildren(alb1,alb2,alb3) end
John@56 555 right:AddChildren(biddingZone)
John@56 556 f:AddChildren(left,right)
John@58 557
John@58 558
John@1 559 end