Mercurial > wow > breuesk
comparison Gui.lua @ 67:8387dc2ff658
Getting the rest of the UI elements to respond intuitively
| author | John@Doomsday |
|---|---|
| date | Tue, 27 Mar 2012 10:19:48 -0400 |
| parents | d3f64d7246b3 |
| children | a177b863ed6c |
comparison
equal
deleted
inserted
replaced
| 66:331b5e176d79 | 67:8387dc2ff658 |
|---|---|
| 4 local table=table | 4 local table=table |
| 5 local pairs=pairs | 5 local pairs=pairs |
| 6 local setmetatable=setmetatable | 6 local setmetatable=setmetatable |
| 7 local ipairs=ipairs | 7 local ipairs=ipairs |
| 8 local string=string | 8 local string=string |
| 9 local sformat=string.format | |
| 9 local tostring=tostring | 10 local tostring=tostring |
| 10 local type=type | 11 local type=type |
| 11 local getn=getn | 12 local getn=getn |
| 12 setfenv(1,bsk) | 13 setfenv(1,bsk) |
| 13 | 14 |
| 61 | 62 |
| 62 SelectorListEventDispatcher = | 63 SelectorListEventDispatcher = |
| 63 { | 64 { |
| 64 listeners = nil, | 65 listeners = nil, |
| 65 target = nil, | 66 target = nil, |
| 67 line = nil, | |
| 66 ["SetTarget"] = function(self,other) | 68 ["SetTarget"] = function(self,other) |
| 67 self.target = other | 69 self.target = other |
| 68 self.target:SetCallback("OnSelectionCleared",function(...) self:OnSelectionCleared(...) end) | 70 self.target:SetCallback("OnSelectionCleared",function(...) self:OnSelectionCleared(...) end) |
| 69 self.target:SetCallback("OnSelection",function(...) self:OnSelection(...) end) | 71 self.target:SetCallback("OnSelection",function(...) self:OnSelection(...) end) |
| 70 end, | 72 end, |
| 71 ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end, | 73 ["RegisterListener"] = function(self,other) table.insert(self.listeners,other) end, |
| 72 ["OnSelectionCleared"] = function(self,_) | 74 ["OnSelectionCleared"] = function(self,_) |
| 75 self.line = nil | |
| 73 self:Event("OnSelectionCleared") | 76 self:Event("OnSelectionCleared") |
| 74 end, | 77 end, |
| 75 ["OnSelection"] = function(self,_,_,line) | 78 ["OnSelection"] = function(self,_,_,line) |
| 79 self.line = line | |
| 76 self:Event("OnSelection",line) | 80 self:Event("OnSelection",line) |
| 77 end, | 81 end, |
| 78 ["Event"] = function(self,event,arg) | 82 ["Event"] = function(self,event,arg) |
| 79 if not self.target then error("Event called with no listener...") end | 83 if not self.target then error("Event called with no listener...") end |
| 80 if not self.listeners then return end | 84 if not self.listeners then return end |
| 81 for i,v in pairs(self.listeners) do | 85 for i,v in pairs(self.listeners) do |
| 82 bsk.print("listener") | 86 --bsk.print("listener") |
| 83 if type(v) == "table" then | 87 if type(v) == "table" then |
| 84 if v[event] then | 88 if v[event] then |
| 85 v[event](v,arg) | 89 v[event](v,arg) |
| 86 end | 90 end |
| 87 elseif type(v) == "function" then | 91 elseif type(v) == "function" then |
| 89 elseif type(v) ~= "nil" then -- allow nils to pass quietly | 93 elseif type(v) ~= "nil" then -- allow nils to pass quietly |
| 90 _G.error("Bad listener - "..type(v)) | 94 _G.error("Bad listener - "..type(v)) |
| 91 end | 95 end |
| 92 end | 96 end |
| 93 end, | 97 end, |
| 94 ["Release"] = function(self) self.listeners = {}; self.target=nil end | 98 ["Release"] = function(self) self.listeners = {}; self.target=nil; self.line=nil end, |
| 99 ["LatestValue"] = function(self) return self.line end | |
| 95 } | 100 } |
| 96 function SelectorListEventDispatcher:new() | 101 function SelectorListEventDispatcher:new() |
| 97 local t = {} | 102 local t = {} |
| 98 setmetatable(t,SelectorListEventDispatcher) | 103 setmetatable(t,SelectorListEventDispatcher) |
| 99 self.__index = self | 104 self.__index = self |
| 101 return t | 106 return t |
| 102 end | 107 end |
| 103 | 108 |
| 104 SListEventDispatch = SelectorListEventDispatcher:new() | 109 SListEventDispatch = SelectorListEventDispatcher:new() |
| 105 LListEventDispatch = SelectorListEventDispatcher:new() | 110 LListEventDispatch = SelectorListEventDispatcher:new() |
| 111 RListEventDispatch = SelectorListEventDispatcher:new() | |
| 106 | 112 |
| 107 local AdminLootEventCollector = | 113 local AdminLootEventCollector = |
| 108 { | 114 { |
| 109 listeners = {}, | 115 listeners = {}, |
| 110 target1 = | 116 target1 = |
| 131 for le in self.lref:OrderedListEntryIter() do | 137 for le in self.lref:OrderedListEntryIter() do |
| 132 local disabled = not PersonList:IsActive(le:GetId()) | 138 local disabled = not PersonList:IsActive(le:GetId()) |
| 133 if not self.filtered or not disabled then | 139 if not self.filtered or not disabled then |
| 134 local line = {value=le:GetId(),text=le:GetName(),icon=[[Interface\Glues\CharacterCreate\UI-CharacterCreate-Classes]]} | 140 local line = {value=le:GetId(),text=le:GetName(),icon=[[Interface\Glues\CharacterCreate\UI-CharacterCreate-Classes]]} |
| 135 line.iconCoords=_G.CLASS_ICON_TCOORDS[le:GetClass()] | 141 line.iconCoords=_G.CLASS_ICON_TCOORDS[le:GetClass()] |
| 142 line.textPlain = line.text | |
| 136 line.text=colorize(line.text,_G.RAID_CLASS_COLORS[le:GetClass()]) | 143 line.text=colorize(line.text,_G.RAID_CLASS_COLORS[le:GetClass()]) |
| 137 line.disabled = disabled | 144 line.disabled = disabled |
| 138 table.insert(self.data,line) | 145 table.insert(self.data,line) |
| 139 end | 146 end |
| 140 end | 147 end |
| 165 | 172 |
| 166 if f then return end -- no second gui please | 173 if f then return end -- no second gui please |
| 167 local admin = bsk.admin or true | 174 local admin = bsk.admin or true |
| 168 f = AceGUI:Create("Frame") | 175 f = AceGUI:Create("Frame") |
| 169 | 176 |
| 170 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release() end) | 177 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release(); RListEventDispatch:Release() end) |
| 171 f:SetTitle("BSK") | 178 f:SetTitle("BSK") |
| 172 f:SetLayout("Flow") | 179 f:SetLayout("Flow") |
| 173 f:SetHeight(680) | 180 f:SetHeight(680) |
| 174 f:SetWidth(580) | 181 f:SetWidth(580) |
| 175 | 182 |
| 252 LListEventDispatch:RegisterListener(alb1.userdata) | 259 LListEventDispatch:RegisterListener(alb1.userdata) |
| 253 alb1:SetCallback("OnClick", | 260 alb1:SetCallback("OnClick", |
| 254 function(widget) | 261 function(widget) |
| 255 if widget.userdata.state then -- we were bidding when the button was pressed | 262 if widget.userdata.state then -- we were bidding when the button was pressed |
| 256 biddingZone:ReleaseChildren() | 263 biddingZone:ReleaseChildren() |
| 264 RListEventDispatch:Release() | |
| 257 else | 265 else |
| 258 local spacer = AceGUI:Create("Label") | 266 local spacer = AceGUI:Create("Label") |
| 259 spacer:SetText(" ") | 267 spacer:SetText(" ") |
| 260 spacer:SetFullWidth(true) | 268 spacer:SetFullWidth(true) |
| 261 local spacer2 = AceGUI:Create("Label") | 269 local spacer2 = AceGUI:Create("Label") |
| 263 spacer2:SetFullWidth(true) | 271 spacer2:SetFullWidth(true) |
| 264 | 272 |
| 265 local label = AceGUI:Create("Label") | 273 local label = AceGUI:Create("Label") |
| 266 label:SetText("Bidding now open for ...") | 274 label:SetText("Bidding now open for ...") |
| 267 local biddingOn = AceGUI:Create("InteractiveLabel") | 275 local biddingOn = AceGUI:Create("InteractiveLabel") |
| 268 biddingOn.userdata = { "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r" } | 276 biddingOn.userdata = { LListEventDispatch:LatestValue().link } |
| 269 biddingOn:SetText(biddingOn.userdata[1]) | 277 biddingOn:SetText(biddingOn.userdata[1]) |
| 270 biddingOn:SetFullWidth(true) | 278 biddingOn:SetFullWidth(true) |
| 271 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end ) | 279 biddingOn:SetCallback("OnEnter", function(widget) _G.GameTooltip:SetOwner(widget.frame,"ANCHOR_RIGHT"); _G.GameTooltip:SetHyperlink(widget.userdata[1]); _G.GameTooltip:Show() end ) |
| 272 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end ) | 280 biddingOn:SetCallback("OnLeave", function(widget) _G.GameTooltip:Hide() end ) |
| 273 local b1 = AceGUI:Create("SelectorList") | 281 local b1 = AceGUI:Create("SelectorList") |
| 274 b1:SetNumLines(6) | 282 b1:SetNumLines(6) |
| 275 b1:SetInteractive(admin) | 283 b1:SetInteractive(admin) |
| 276 local dummydata= {} | |
| 277 local tree =SListPopulator.data | |
| 278 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end | |
| 279 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end | |
| 280 b1:SetList(dummydata) | |
| 281 local bidTitle = AceGUI:Create("Label") | 284 local bidTitle = AceGUI:Create("Label") |
| 282 bidTitle:SetText("Current bids") | 285 bidTitle:SetText("Current bids") |
| 283 bidTitle:SetFullWidth(true) | 286 bidTitle:SetFullWidth(true) |
| 284 | 287 |
| 285 local bidRetractButton = AceGUI:Create("Button") | 288 local bidRetractButton = AceGUI:Create("Button") |
| 287 bidRetractButton:SetWidth(100) | 290 bidRetractButton:SetWidth(100) |
| 288 local rollButton = AceGUI:Create("Button") | 291 local rollButton = AceGUI:Create("Button") |
| 289 rollButton:SetText("Offset Roll") | 292 rollButton:SetText("Offset Roll") |
| 290 rollButton:SetWidth(100) | 293 rollButton:SetWidth(100) |
| 291 | 294 |
| 295 local dummydata= {} | |
| 296 local tree =SListPopulator.data | |
| 297 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end | |
| 298 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end | |
| 299 b1:SetList(dummydata) | |
| 300 | |
| 292 local g1 | 301 local g1 |
| 293 if admin then | 302 if admin then |
| 303 RListEventDispatch:SetTarget(b1) | |
| 294 b1.alignoffset = 0.25 -- or else g1 won't align well | 304 b1.alignoffset = 0.25 -- or else g1 won't align well |
| 295 g1 = AceGUI:Create("SimpleGroup") | 305 g1 = AceGUI:Create("SimpleGroup") |
| 296 g1.alignoffset = 0.25 | 306 g1.alignoffset = 0.25 |
| 297 g1:SetWidth(120) | 307 g1:SetWidth(120) |
| 298 g1:SetLayout("List") | 308 g1:SetLayout("List") |
| 299 | 309 |
| 310 -- todo: convoluted and repetitive - surely there's a | |
| 311 -- better way than this ... | |
| 300 adminForce = AceGUI:Create("Button") | 312 adminForce = AceGUI:Create("Button") |
| 301 adminForce:SetText("Force bid") | 313 if SListEventDispatch:LatestValue() then |
| 302 adminForce:SetWidth(100) | 314 adminForce:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) |
| 315 adminForce:SetDisabled(false) | |
| 316 else | |
| 317 adminForce:SetText("Force bid") | |
| 318 adminForce:SetDisabled(true) | |
| 319 end | |
| 320 adminForce:SetWidth(160) | |
| 321 adminForce.userdata = | |
| 322 { | |
| 323 widget = adminForce, | |
| 324 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end, | |
| 325 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end, | |
| 326 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end | |
| 327 } | |
| 328 SListEventDispatch:RegisterListener(adminForce.userdata) | |
| 303 | 329 |
| 304 adminRetract = AceGUI:Create("Button") | 330 adminRetract = AceGUI:Create("Button") |
| 305 adminRetract:SetText("Retract bid") | 331 if RListEventDispatch:LatestValue() then |
| 306 adminRetract:SetWidth(100) | 332 adminRetract:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) |
| 333 adminRetract:SetDisabled(false) | |
| 334 else | |
| 335 adminRetract:SetText("Retract bid") | |
| 336 adminRetract:SetDisabled(true) | |
| 337 end | |
| 338 adminRetract:SetWidth(160) | |
| 339 adminRetract.userdata = | |
| 340 { | |
| 341 widget = adminRetract, | |
| 342 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end, | |
| 343 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end, | |
| 344 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end | |
| 345 } | |
| 346 RListEventDispatch:RegisterListener(adminRetract.userdata) | |
| 347 adminRetract:SetDisabled(true) | |
| 307 | 348 |
| 308 g1:AddChildren(adminForce,adminRetract) | 349 g1:AddChildren(adminForce,adminRetract) |
| 309 end | 350 end |
| 310 | 351 |
| 311 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1) | 352 biddingZone:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1) |
| 312 if admin then biddingZone:AddChildren(g1) end | 353 if admin then biddingZone:AddChildren(g1) end |
| 313 | |
| 314 | |
| 315 end | 354 end |
| 316 widget.userdata.state = not widget.userdata.state | 355 widget.userdata.state = not widget.userdata.state |
| 317 end | 356 end |
| 318 ) | 357 ) |
| 319 | 358 |
