annotate Gui.lua @ 77:0a3f590f69e6

Update todo list Helper function to print list status
author John@Yosemite-PC
date Thu, 12 Apr 2012 22:18:05 -0400
parents 39be9328acd0
children 5b507f4125d4
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 lids = LootLists:GetAllIds()
John@56 37 for _,v in pairs(lids) do
John@56 38 local l = LootLists:Select(v)
John@56 39 pull[l:GetId()] = l:GetName()
John@56 40 --local entry = {value=i,text=v.name}
John@56 41 if l:GetLength() > 0 then
John@56 42 pulldown:SetItemDisabled(i,true)
John@51 43 end
John@1 44 end
John@56 45 pulldown:SetWidth(175)
John@56 46 pulldown:SetList(pull)
John@71 47 SListPopulator:SetSwidget(pulldown)
John@72 48 pulldown:SetCallback("OnValueChanged", function(_,_,value) SListPopulator:PulldownEvent(value) end)
John@73 49 if stateactivelist > 0 then SListPopulator:PulldownEvent(stateactivelist) end -- default value
John@56 50 return pulldown
John@1 51 end
John@1 52
John@72 53 local f, right -- important gui elements
John@59 54 local escapeButton =
John@59 55 {
John@59 56 shown = false,
John@59 57 ["IsShown"] = function(self) return self.shown end,
John@60 58 ["Hide"] = function(self) if f then AceGUI:Release(f); self.shown=false end end
John@59 59 }
John@38 60
John@65 61 SelectorListEventDispatcher =
John@63 62 {
John@65 63 listeners = nil,
John@63 64 target = nil,
John@67 65 line = nil,
John@63 66 ["SetTarget"] = function(self,other)
John@63 67 self.target = other
John@65 68 self.target:SetCallback("OnSelectionCleared",function(...) self:OnSelectionCleared(...) end)
John@65 69 self.target:SetCallback("OnSelection",function(...) self:OnSelection(...) end)
John@63 70 end,
John@63 71 ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end,
John@63 72 ["OnSelectionCleared"] = function(self,_)
John@67 73 self.line = nil
John@63 74 self:Event("OnSelectionCleared")
John@63 75 end,
John@65 76 ["OnSelection"] = function(self,_,_,line)
John@67 77 self.line = line
John@63 78 self:Event("OnSelection",line)
John@63 79 end,
John@63 80 ["Event"] = function(self,event,arg)
John@63 81 if not self.target then error("Event called with no listener...") end
John@63 82 if not self.listeners then return end
John@63 83 for i,v in pairs(self.listeners) do
John@67 84 --bsk.print("listener")
John@63 85 if type(v) == "table" then
John@63 86 if v[event] then
John@63 87 v[event](v,arg)
John@63 88 end
John@63 89 elseif type(v) == "function" then
John@63 90 v(event,arg)
John@63 91 elseif type(v) ~= "nil" then -- allow nils to pass quietly
John@63 92 _G.error("Bad listener - "..type(v))
John@63 93 end
John@63 94 end
John@63 95 end,
John@67 96 ["Release"] = function(self) self.listeners = {}; self.target=nil; self.line=nil end,
John@67 97 ["LatestValue"] = function(self) return self.line end
John@63 98 }
John@65 99 function SelectorListEventDispatcher:new()
John@65 100 local t = {}
John@65 101 setmetatable(t,SelectorListEventDispatcher)
John@65 102 self.__index = self
John@65 103 t.listeners = {}
John@65 104 return t
John@63 105 end
John@65 106
John@65 107 SListEventDispatch = SelectorListEventDispatcher:new()
John@65 108 LListEventDispatch = SelectorListEventDispatcher:new()
John@67 109 RListEventDispatch = SelectorListEventDispatcher:new()
John@65 110
John@63 111 local SListPopulator =
John@63 112 {
John@63 113 filtered = false,
John@63 114 widget = nil,
John@71 115 swidget = nil,
John@63 116 data = nil,
John@63 117 lref = nil,
John@63 118
John@71 119 ["Release"] = function(self) self.filtered, self.widget, self.swidget, self.data, self.lref = false, nil, nil, nil, nil end,
John@63 120 ["Redraw"] = function(self)
John@63 121 if self.lref == nil or self.widget == nil then return end -- don't do work if not fully initialized
John@63 122 self.data = {}
John@63 123 for le in self.lref:OrderedListEntryIter() do
John@63 124 local disabled = not PersonList:IsActive(le:GetId())
John@63 125 if not self.filtered or not disabled then
John@63 126 local line = {value=le:GetId(),text=le:GetName(),icon=[[Interface\Glues\CharacterCreate\UI-CharacterCreate-Classes]]}
John@63 127 line.iconCoords=_G.CLASS_ICON_TCOORDS[le:GetClass()]
John@67 128 line.textPlain = line.text
John@63 129 line.text=colorize(line.text,_G.RAID_CLASS_COLORS[le:GetClass()])
John@63 130 line.disabled = disabled
John@63 131 table.insert(self.data,line)
John@63 132 end
John@63 133 end
John@63 134 self.widget:SetList(self.data)
John@65 135 SListEventDispatch:Event("Redraw")
John@63 136 end,
John@71 137 ["SetSwidget"] = function(self,w)
John@71 138 if type(w) ~= "table" or type(w.SetList) ~= "function" then
John@71 139 _G.error("Bad SetWidget")
John@71 140 end
John@71 141 self.swidget = w
John@71 142 end,
John@63 143 ["SetWidget"] = function(self,w)
John@65 144 if type(w) ~= "table" or type(w.SetList) ~= "function" then
John@63 145 _G.error("Bad SetWidget")
John@63 146 end
John@63 147 self.widget = w
John@63 148 end,
John@63 149 ["SetFiltered"] = function(self,value)
John@63 150 self.filtered = value
John@63 151 self:Redraw()
John@63 152 end,
John@72 153 ["SelectList"] = function(self,value,nocomm)
John@71 154 self.swidget:SetValue(value)
John@72 155 local l = LootLists:Select(value)
John@72 156 if l ~= self.lref then
John@72 157 self.lref = l
John@72 158 self:Redraw()
John@72 159 end
John@72 160 if nocomm then InitiateActiveList(value) end
John@72 161 end,
John@72 162
John@72 163
John@72 164 ["PulldownEvent"] = function(self,value)
John@72 165 self:SelectList(value)
John@72 166 if admin and state == "looting" then
John@72 167 InitiateActivateList(value)
John@72 168 end
John@68 169 end,
John@68 170 ["DataEvent"] = function(self)
John@68 171 self:Redraw()
John@69 172 end,
John@72 173 ["StateEvent"] = function(self)
John@75 174 -- todo: events still happen even if the gui is closed. protect the api.
John@75 175
John@73 176 print("State event in SL: ", state, admin)
John@72 177 if state == "bidding" or (state == "looting" and not admin) then
John@72 178 self.swidget:SetDisabled(true)
John@72 179 self:SelectList(stateactivelist)
John@72 180 else
John@72 181 self.swidget:SetDisabled(false)
John@72 182 end
John@72 183 -- if bidding then disable pulldown
John@72 184 -- if looting and not admin then disable pulldown
John@72 185 -- if looting and admin then enable pulldown
John@72 186 -- otherwise enable pulldown
John@72 187 end,
John@72 188 ["ActiveListEvent"] = function(self)
John@72 189 self:SelectList(stateactivelist)
John@72 190 end,
John@72 191
John@72 192
John@72 193
John@69 194 ["GetMe"] = function(self)
John@69 195 local me = _G.UnitName("player")
John@69 196 for i,v in pairs(self.data) do
John@69 197 if v.textPlain == me then
John@69 198 return v
John@69 199 end
John@69 200 end
John@69 201 end,
John@69 202 }
John@69 203
John@69 204 local LListPopulator =
John@69 205 {
John@69 206 data = {},
John@69 207 widget = nil,
John@69 208 ["Release"] = function(self) self.data = {}; self.widget = nil end,
John@73 209 ["ItemListEvent"] = function(self) self:Redraw() end,
John@69 210 ["Redraw"]= function(self)
John@73 211 self.data = {}
John@73 212 for i,v in pairs(stateitemlist) do
John@73 213 local entry = {value=i, text=v, link=v}
John@73 214 table.insert(self.data,entry)
John@73 215 end
John@73 216 if self.widget then
John@73 217 self.widget:SetList(self.data)
John@73 218 LListEventDispatch:Event("Redraw")
John@73 219 end
John@69 220 end,
John@69 221 ["SetWidget"] = function(self,w)
John@69 222 if type(w) ~= "table" or type(w.SetList) ~= "function" then
John@69 223 _G.error("Bad SetWidget")
John@69 224 end
John@69 225 self.widget = w
John@76 226 --if debug then
John@76 227 -- self.data = {
John@76 228 -- {
John@76 229 -- value=1,
John@76 230 -- text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
John@76 231 -- link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
John@76 232 -- },
John@76 233 -- {
John@76 234 -- value=2,
John@76 235 -- text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r",
John@76 236 -- link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r"
John@76 237 -- },
John@76 238 -- {
John@76 239 -- value=3,
John@76 240 -- text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r",
John@76 241 -- link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r"
John@76 242 -- },
John@76 243 -- {
John@76 244 -- value=4,
John@76 245 -- text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r",
John@76 246 -- link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r"
John@76 247 -- },
John@76 248 -- {
John@76 249 -- value=5,
John@76 250 -- text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
John@76 251 -- link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
John@76 252 -- },
John@76 253 -- }
John@76 254 --end
John@69 255 self:Redraw()
John@69 256 end,
John@69 257 }
John@69 258
John@69 259 local RListPopulator =
John@69 260 {
John@69 261 widget = nil,
John@71 262 ["RollEvent"] = function(self) self:Redraw() end,
John@71 263 ["Release"] = function(self) self.widget = nil end,
John@69 264 ["Redraw"] = function(self)
John@71 265 self.widget:SetList(statebids)
John@69 266 RListEventDispatch:Event("Redraw")
John@69 267 end,
John@69 268 ["SetWidget"] = function(self,w)
John@69 269 if type(w) ~= "table" or type(w.SetList) ~= "function" then
John@69 270 _G.error("Bad SetWidget")
John@69 271 end
John@69 272 self.widget = w
John@71 273 --if debug then
John@71 274 -- local dummydata = {}
John@71 275 -- local tree = SListPopulator.data
John@71 276 -- for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
John@71 277 -- if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
John@71 278 -- self.data = dummydata
John@71 279 --end
John@69 280 self:Redraw()
John@69 281 end,
John@69 282 ["Force"] = function(self,who)
John@69 283 local new = self.Convert(who,72)
John@71 284 InitiateBid(new)
John@71 285 --self:Redraw()
John@69 286 end,
John@69 287 ["Retract"] = function(self,who)
John@71 288 -- todo
John@71 289 --for i,v in pairs(self.data) do
John@71 290 -- if who.value == v.value then
John@71 291 -- table.remove(self.data,i)
John@71 292 -- end
John@71 293 --end
John@71 294 InitiateRetract(copy(who))
John@71 295 --self:Redraw()
John@69 296 end,
John@69 297 ["Convert"] = function(who,roll) -- convert an LE object into one suitable to put in a SelectorList
John@69 298 local new = copy(who)
John@69 299 new.disabled = false -- todo: should be unnessary - they can't get on the list like this
John@69 300 if roll then
John@69 301 new.text = new.text .. " (roll 73)"
John@69 302 end
John@69 303 return new
John@69 304 end,
John@63 305 }
John@63 306
John@75 307 local BZPopulator =
John@75 308 {
John@75 309 group = nil,
John@75 310 ["SetGroup"] = function(self,g)
John@75 311 if type(g) ~= "table" or type(g.AddChild) ~= "function" then
John@75 312 _G.error("Bad SetGroup for BZPopulator")
John@75 313 end
John@75 314 self.group = g
John@75 315 end,
John@75 316
John@75 317
John@75 318 ["Release"] = function(self) self.group = nil; RListEventDispatch:Release(); RListPopulator:Release() end,
John@75 319
John@75 320 ["StateEvent"] = function(self)
John@75 321 if state == "bidding" then
John@75 322
John@75 323 local spacer = AceGUI:Create("Label")
John@75 324 spacer:SetText(" ")
John@75 325 spacer:SetFullWidth(true)
John@76 326 local spacer2 = AceGUI:Create("Label") -- don't try to combine this with "spacer" - you can't add a child more than once
John@75 327 spacer2:SetText(" ")
John@75 328 spacer2:SetFullWidth(true)
John@75 329
John@75 330 local label = AceGUI:Create("Label")
John@75 331 label:SetText("Bidding now open for ...")
John@75 332 local biddingOn = AceGUI:Create("InteractiveLabel")
John@75 333 biddingOn.userdata = { stateitem.link }
John@75 334 biddingOn:SetText(biddingOn.userdata[1])
John@75 335 biddingOn:SetFullWidth(true)
John@75 336 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end )
John@75 337 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end )
John@75 338 local b1 = AceGUI:Create("SelectorList")
John@75 339 b1:SetNumLines(6)
John@75 340 b1:SetInteractive(admin)
John@75 341 local bidTitle = AceGUI:Create("Label")
John@75 342 bidTitle:SetText("Current bids")
John@75 343 bidTitle:SetFullWidth(true)
John@75 344
John@75 345 local bidRetractButton = AceGUI:Create("Button")
John@75 346 bidRetractButton:SetText("Place Bid")
John@75 347 bidRetractButton:SetWidth(100)
John@76 348 bidRetractButton:SetCallback("OnClick", function(widget) InitiateBid(SListPopulator:GetMe()) end)
John@76 349
John@75 350 local rollButton = AceGUI:Create("Button")
John@75 351 rollButton:SetText("Offset Roll")
John@75 352 rollButton:SetWidth(100)
John@76 353 -- todo: callback
John@75 354
John@75 355 RListEventDispatch:SetTarget(b1)
John@75 356 RListPopulator:SetWidget(b1)
John@75 357
John@75 358 local g1
John@75 359 if admin then
John@75 360 b1.alignoffset = 0.25 -- or else g1 won't align well
John@75 361 g1 = AceGUI:Create("SimpleGroup")
John@75 362 g1.alignoffset = 0.25
John@75 363 g1:SetWidth(120)
John@75 364 g1:SetLayout("List")
John@75 365
John@75 366 -- todo: convoluted and repetitive - surely there's a
John@75 367 -- better way than this ...
John@75 368 adminForce = AceGUI:Create("Button")
John@75 369 if SListEventDispatch:LatestValue() then
John@75 370 adminForce:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain))
John@75 371 adminForce:SetDisabled(false)
John@75 372 else
John@75 373 adminForce:SetText("Force bid")
John@75 374 adminForce:SetDisabled(true)
John@75 375 end
John@75 376 adminForce:SetWidth(160)
John@75 377 adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end)
John@75 378 adminForce.userdata =
John@75 379 {
John@75 380 widget = adminForce,
John@75 381 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end,
John@75 382 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end,
John@75 383 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end
John@75 384 }
John@75 385 SListEventDispatch:RegisterListener(adminForce.userdata)
John@75 386
John@75 387 adminRetract = AceGUI:Create("Button")
John@75 388 if RListEventDispatch:LatestValue() then
John@75 389 adminRetract:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain))
John@75 390 adminRetract:SetDisabled(false)
John@75 391 else
John@75 392 adminRetract:SetText("Retract bid")
John@75 393 adminRetract:SetDisabled(true)
John@75 394 end
John@75 395 adminRetract:SetWidth(160)
John@75 396 adminRetract.userdata =
John@75 397 {
John@75 398 widget = adminRetract,
John@75 399 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end,
John@75 400 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end,
John@75 401 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end
John@75 402 }
John@75 403 adminRetract:SetCallback("OnClick",function(widget) RListPopulator:Retract(RListEventDispatch:LatestValue()) end)
John@75 404 RListEventDispatch:RegisterListener(adminRetract.userdata)
John@75 405 adminRetract:SetDisabled(true)
John@75 406
John@75 407 g1:AddChildren(adminForce,adminRetract)
John@75 408 end
John@75 409
John@75 410 self.group:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
John@75 411 if admin then self.group:AddChildren(g1) end
John@75 412
John@75 413 else
John@75 414
John@75 415
John@75 416 self.group:ReleaseChildren()
John@75 417 RListEventDispatch:Release()
John@75 418 RListPopulator:Release()
John@75 419 end
John@75 420
John@75 421 end,
John@75 422
John@75 423
John@75 424 }
John@75 425
John@68 426 DataEventDispatch =
John@68 427 {
John@68 428 -- todo: batch events
John@68 429 listeners = {},
John@68 430 ["DataEvent"] = function(self,_) --todo: pass along the received event
John@68 431 for i,v in pairs(self.listeners) do
John@68 432 if v and v["DataEvent"] then
John@68 433 v:DataEvent()
John@68 434 end
John@68 435 end
John@68 436 end,
John@68 437 ["RegisterListener"] = function(self,listener)
John@68 438 if not listener or not listener["DataEvent"] then
John@68 439 _G.error("Bad listener")
John@68 440 end
John@68 441 table.insert(self.listeners,listener)
John@68 442 end
John@68 443 }
John@68 444
John@76 445 AdminLootButtons =
John@76 446 {
John@76 447 openButton = nil,
John@76 448 assignButton = nil,
John@76 449 suicideButton = nil,
John@76 450 -- todo - open roll button
John@76 451
John@76 452 eventsFromLL =
John@76 453 {
John@76 454 ["Redraw"] = function(self) AdminLootButtons:Redraw() end,
John@76 455 ["OnSelection"] = function(self) AdminLootButtons:Redraw() end,
John@76 456 ["OnSelectionCleared"] = function(self) AdminLootButtons:Redraw() end,
John@76 457 },
John@76 458 eventsFromSL =
John@76 459 {
John@76 460 ["Redraw"] = function(self) AdminLootButtons:Redraw() end,
John@76 461 ["OnSelection"] = function(self) AdminLootButtons:Redraw() end,
John@76 462 ["OnSelectionCleared"] = function(self) AdminLootButtons:Redraw() end,
John@76 463 },
John@76 464 ["StateEvent"] = function(self) self:Redraw() end,
John@76 465 ["RollEvent"] = function(self) self:Redraw() end,
John@76 466
John@76 467 ["SetButtons"] = function(self,open,assign,suicide)
John@76 468 self.openButton = open
John@76 469 self.assignButton = assign
John@76 470 self.suicideButton = suicide
John@76 471 SListEventDispatch:RegisterListener(self.eventsFromSL)
John@76 472 LListEventDispatch:RegisterListener(self.eventsFromLL)
John@76 473 self:Redraw()
John@76 474 end,
John@76 475 ["Release"] = function(self)
John@76 476 self.openButton = nil
John@76 477 self.assignButton = nil
John@76 478 self.suicideButton = nil
John@76 479 end,
John@76 480
John@76 481 ["Redraw"] = function(self)
John@76 482 if state == "neutral" then -- gray all buttons
John@76 483 self.openButton:SetText("Open Bids")
John@76 484 self.openButton:SetDisabled(true)
John@76 485 self.assignButton:SetText("Assign")
John@76 486 self.assignButton:SetDisabled(true)
John@76 487 self.suicideButton:SetText("Suicide")
John@76 488 self.suicideButton:SetDisabled(true)
John@76 489 elseif state == "looting" then
John@76 490 if LListEventDispatch.line then
John@76 491 self.openButton:SetDisabled(false)
John@76 492 self.openButton:SetText("Open Bids")
John@76 493 self.openButton:SetCallback("OnClick", function(widget) InitiateOpenBid(LListEventDispatch:LatestValue()) end)
John@76 494 else
John@76 495 self.openButton:SetText("Open Bids")
John@76 496 self.openButton:SetDisabled(true)
John@76 497 end
John@76 498 if LListEventDispatch.line and SListEventDispatch.line then
John@76 499 self.assignButton:SetText("Assign")
John@76 500 self.assignButton:SetDisabled(false)
John@76 501 self.assignButton:SetCallback("OnClick", function(widget) FreeLoot(LListEventDispatch:LatestValue(),SListEventDispatch:LatestValue()) end)
John@76 502 self.suicideButton:SetText("Suicide")
John@76 503 self.suicideButton:SetDisabled(false)
John@76 504 else
John@76 505 self.assignButton:SetText("Assign")
John@76 506 self.assignButton:SetDisabled(true)
John@76 507 self.suicideButton:SetText("Suicide")
John@76 508 self.suicideButton:SetDisabled(true)
John@76 509 end
John@76 510 -- if item selected, light up Open button
John@76 511 -- if item selected and name selected, light up assign/suicide
John@76 512 -- buttons
John@76 513 elseif state == "bidding" then
John@76 514 self.openButton:SetDisabled(false)
John@76 515 self.openButton:SetText("Cancel Bidding")
John@76 516 self.openButton:SetCallback("OnClick", function(widget) InitiateCloseBidding() end)
John@76 517 self.assignButton:SetText("Finish & Assign")
John@76 518 self.assignButton:SetDisabled(not (getn(staterolls) > 0 or getn(statebids) > 0))
John@76 519 self.assignButton:SetCallback("OnClick", function(widget) ExpensiveLoot(LListEventDispatch:LatestValue(),SListPopulator.lref) end)
John@76 520 self.suicideButton:SetText(" ")
John@76 521 self.suicideButton:SetDisabled(true)
John@76 522
John@76 523 -- change open button to cancel
John@76 524 -- change assign button to award
John@76 525 -- disable ... and rename? the third button
John@76 526
John@76 527 end
John@76 528 end,
John@76 529 }
John@76 530
John@68 531 function OnInitializeSetStaticData()
John@68 532 SetChangeListener(DataEventDispatch)
John@68 533 DataEventDispatch:RegisterListener(SListPopulator)
John@72 534 RegisterListenerActiveListChanged(SListPopulator)
John@72 535 RegisterListenerStateChange(SListPopulator)
John@71 536 RegisterListenerRolls(RListPopulator)
John@73 537 RegisterItemListListener(LListPopulator)
John@75 538 RegisterListenerStateChange(BZPopulator)
John@76 539 if admin then
John@76 540 RegisterListenerStateChange(AdminLootButtons)
John@76 541 RegisterListenerRolls(AdminLootButtons)
John@76 542 end
John@68 543 end
John@68 544
John@42 545 function CreateGUI()
John@59 546 -- special registration procedure to be closable with the escape button
John@59 547 --escapeButton.shown = true
John@59 548 --_G["BSK_ESCAPEBUTTON"] = escapeButton
John@59 549 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON")
John@59 550
John@60 551 if f then return end -- no second gui please
John@59 552 f = AceGUI:Create("Frame")
John@1 553
John@76 554 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(); BZPopulator:Release(); AdminLootButtons:Release() end)
John@56 555 f:SetTitle("BSK")
John@56 556 f:SetLayout("Flow")
John@56 557 f:SetHeight(680)
John@56 558 f:SetWidth(580)
John@1 559
John@56 560 local left = AceGUI:Create("InlineGroup")
John@56 561 left:SetLayout("List")
John@56 562 left:SetWidth(175)
John@56 563 left:SetFullHeight(true)
John@56 564 left.alignoffset=0.25 -- hack, as per http://forums.wowace.com/showthread.php?t=17114
John@1 565
John@65 566 right = AceGUI:Create("InlineGroup")
John@56 567 right:SetLayout("Flow")
John@56 568 right:SetWidth(700-175-160)
John@56 569 right:SetFullHeight(true)
John@56 570 right.alignoffset=0.25
John@38 571
John@56 572 local t1 = AceGUI:Create("SelectorList")
John@56 573 t1:SetNumLines(25)
John@56 574 t1:SetFullWidth(true)
John@56 575 t1:SetInteractive(admin)
John@69 576 SListEventDispatch:SetTarget(t1)
John@63 577 SListPopulator:SetWidget(t1)
John@38 578
John@63 579 local p1 = CreateListSelector(SListPopulator)
John@56 580 p1:SetFullWidth(true)
John@38 581
John@56 582 left:AddChild(p1)
John@56 583 left:AddChild(t1)
John@38 584
John@56 585 local t2 = AceGUI:Create("SelectorList")
John@56 586 t2:SetNumLines(7)
John@56 587 t2:SetFullWidth(true)
John@56 588 t2:EnableButtonTooltips(true)
John@65 589 LListEventDispatch:SetTarget(t2)
John@69 590 LListPopulator:SetWidget(t2)
John@65 591
John@75 592 biddingZone = AceGUI:Create("SimpleGroup")
John@65 593 biddingZone:SetLayout("Flow")
John@65 594 biddingZone:SetFullWidth(true)
John@75 595 BZPopulator:SetGroup(biddingZone)
John@38 596
John@60 597 local alb1, alb2, alb3
John@60 598 if admin then
John@60 599 alb1 = AceGUI:Create("Button")
John@76 600 alb1:SetWidth(120)
John@76 601 --alb1:SetText("Open Bids")
John@76 602 --alb1.userdata =
John@76 603 --{
John@76 604 -- state = false,
John@76 605 -- widget = alb1,
John@76 606 -- ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.item = nil end,
John@76 607 -- ["OnSelection"] = function(self,value) self.widget:SetDisabled(false); self.item = value end,
John@76 608 -- ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.item = nil end
John@76 609 --}
John@76 610 --alb1:SetDisabled(true)
John@76 611 --LListEventDispatch:RegisterListener(alb1.userdata)
John@76 612 --alb1:SetCallback("OnClick",
John@76 613 -- function(widget)
John@76 614 -- if widget.userdata.state then -- we were bidding when the button was pressed
John@76 615 -- widget:SetText("Open Bids")
John@76 616 -- InitiateCloseBidding() -- todo: plug in loot award, etc
John@76 617 -- else
John@76 618 -- widget:SetText("Close bids")
John@76 619 -- InitiateOpenBid(LListEventDispatch:LatestValue())
John@76 620 -- end
John@76 621 -- widget.userdata.state = not widget.userdata.state
John@76 622 -- end
John@76 623 --)
John@60 624
John@60 625 alb2 = AceGUI:Create("Button")
John@76 626 alb2:SetWidth(120)
John@76 627 --alb2:SetText("Assign")
John@76 628 --alb2.userdata =
John@76 629 --{
John@76 630 -- widget = alb2,
John@76 631 -- ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
John@76 632 --}
John@76 633 --alb2.userdata.slist =
John@76 634 --{
John@76 635 -- parent = alb2.userdata,
John@76 636 -- checked = false,
John@76 637 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 638 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@76 639 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 640 --}
John@76 641 --alb2.userdata.llist =
John@76 642 --{
John@76 643 -- parent = alb2.userdata,
John@76 644 -- checked = false,
John@76 645 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 646 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@76 647 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 648 --}
John@76 649 --SListEventDispatch:RegisterListener(alb2.userdata.slist)
John@76 650 --LListEventDispatch:RegisterListener(alb2.userdata.llist)
John@60 651
John@60 652 alb3 = AceGUI:Create("Button")
John@76 653 alb3:SetWidth(120)
John@76 654 --alb3:SetText("Suicide")
John@76 655 --alb3.userdata = -- TODO: holy hell, come up with a pattern or something for this ....
John@76 656 --{
John@76 657 -- widget = alb3,
John@76 658 -- ["OnUpdate"] = function(self) self.widget:SetDisabled(not (self.slist.checked and self.llist.checked)) end,
John@76 659 --}
John@76 660 --alb3.userdata.slist =
John@76 661 --{
John@76 662 -- parent = alb3.userdata,
John@76 663 -- checked = false,
John@76 664 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 665 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@76 666 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 667 --}
John@76 668 --alb3.userdata.llist =
John@76 669 --{
John@76 670 -- parent = alb3.userdata,
John@76 671 -- checked = false,
John@76 672 -- ["Redraw"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 673 -- ["OnSelection"] = function(self) self.checked = true; self.parent:OnUpdate() end,
John@76 674 -- ["OnSelectionCleared"] = function(self) self.checked = false; self.parent:OnUpdate() end,
John@76 675 --}
John@76 676 --SListEventDispatch:RegisterListener(alb3.userdata.slist)
John@76 677 --LListEventDispatch:RegisterListener(alb3.userdata.llist)
John@76 678 AdminLootButtons:SetButtons(alb1,alb2,alb3)
John@60 679 end
John@38 680
John@65 681 local suicideSelected, undo
John@60 682 if admin then
John@60 683
John@60 684 suicideSelected = AceGUI:Create("Button")
John@60 685 suicideSelected:SetFullWidth(true)
John@60 686 suicideSelected:SetText("Suicide")
John@68 687 suicideSelected:SetCallback("OnClick",
John@68 688 function(_)
John@68 689 local p = SListEventDispatch:LatestValue()
John@68 690 local lref = SListPopulator.lref
John@68 691 lref:SuicidePerson(p.value)
John@68 692 end
John@68 693 )
John@68 694
John@63 695 -- use userdata + SListEventDispatch to toggle state
John@63 696 suicideSelected.userdata =
John@63 697 {
John@63 698 widget = suicideSelected,
John@65 699 ["Redraw"] = function(self,_) self.widget:SetDisabled(true) end,
John@63 700 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false) end,
John@63 701 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true) end
John@63 702 }
John@63 703 SListEventDispatch:RegisterListener(suicideSelected.userdata)
John@60 704
John@60 705 undo = AceGUI:Create("Button")
John@63 706 undo:SetText("Undo / out of order")
John@60 707 undo:SetFullWidth(true)
John@63 708 undo:SetDisabled(true)
John@60 709 end
John@60 710
John@56 711 local filter = AceGUI:Create("CheckBox")
John@56 712 filter:SetLabel("Only show active")
John@56 713 filter:SetFullWidth(true)
John@63 714 filter:SetValue(false)
John@63 715 SListPopulator:SetFiltered(false)
John@63 716 filter:SetCallback("OnValueChanged",function(widget,_,value) SListPopulator:SetFiltered(value) end)
John@56 717
John@56 718 left:AddChildren(filter)
John@56 719 if admin then left:AddChildren(suicideSelected,undo) end
John@56 720 right:AddChildren(t2)
John@56 721 if admin then right:AddChildren(alb1,alb2,alb3) end
John@56 722 right:AddChildren(biddingZone)
John@56 723 f:AddChildren(left,right)
John@58 724
John@58 725
John@1 726 end