annotate Gui.lua @ 101:25c127c4c1e8

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