comparison Gui.lua @ 69:b7352f007028

Working on bids/rolls in the GUI Added debug mode to populate things with dummy data.
author John@Yosemite-PC
date Thu, 29 Mar 2012 20:17:59 -0400
parents a177b863ed6c
children 236117ab8a49
comparison
equal deleted inserted replaced
68:a177b863ed6c 69:b7352f007028
9 local sformat=string.format 9 local sformat=string.format
10 local tostring=tostring 10 local tostring=tostring
11 local type=type 11 local type=type
12 local getn=getn 12 local getn=getn
13 setfenv(1,bsk) 13 setfenv(1,bsk)
14
15 -- todo: switching lists should close a presently-open bid
14 16
15 local copy = function(t) 17 local copy = function(t)
16 local c = {} 18 local c = {}
17 if not t then return c end 19 if not t then return c end
18 for i,v in pairs(t) do c[i] = v end 20 for i,v in pairs(t) do c[i] = v end
149 self.lref = LootLists:Select(value) 151 self.lref = LootLists:Select(value)
150 self:Redraw() 152 self:Redraw()
151 end, 153 end,
152 ["DataEvent"] = function(self) 154 ["DataEvent"] = function(self)
153 self:Redraw() 155 self:Redraw()
154 end 156 end,
157 ["GetMe"] = function(self)
158 local me = _G.UnitName("player")
159 for i,v in pairs(self.data) do
160 if v.textPlain == me then
161 return v
162 end
163 end
164 end,
165 }
166
167 local LListPopulator =
168 {
169 -- todo: set event receivers from the comm and for loot
170 data = {},
171 widget = nil,
172 ["Release"] = function(self) self.data = {}; self.widget = nil end,
173 ["Redraw"]= function(self)
174 self.widget:SetList(self.data)
175 LListEventDispatch:Event("Redraw")
176 end,
177 ["SetWidget"] = function(self,w)
178 if type(w) ~= "table" or type(w.SetList) ~= "function" then
179 _G.error("Bad SetWidget")
180 end
181 self.widget = w
182 if debug then
183 self.data = {
184 {
185 value=1,
186 text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
187 link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
188 },
189 {
190 value=2,
191 text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r",
192 link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r"
193 },
194 {
195 value=3,
196 text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r",
197 link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r"
198 },
199 {
200 value=4,
201 text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r",
202 link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r"
203 },
204 {
205 value=5,
206 text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
207 link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
208 },
209 }
210 end
211 self:Redraw()
212 end,
213 }
214
215 local RListPopulator =
216 {
217 data = {},
218 widget = nil,
219 ["Release"] = function(self) self.data = {}; self.widget = nil end,
220 ["Redraw"] = function(self)
221 self.widget:SetList(self.data)
222 RListEventDispatch:Event("Redraw")
223 end,
224 ["SetWidget"] = function(self,w)
225 if type(w) ~= "table" or type(w.SetList) ~= "function" then
226 _G.error("Bad SetWidget")
227 end
228 self.widget = w
229 if debug then
230 local dummydata = {}
231 local tree = SListPopulator.data
232 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
233 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
234 self.data = dummydata
235 end
236 self:Redraw()
237 end,
238 ["Force"] = function(self,who)
239 for i,v in pairs(self.data) do
240 if who.value == v.value then
241 print(who.value .. " is already on the list")
242 return -- no double adds please
243 end
244 end
245 local new = self.Convert(who,72)
246 table.insert(self.data,new)
247 -- todo: keep this list sorted
248 self:Redraw()
249 end,
250 ["Retract"] = function(self,who)
251 for i,v in pairs(self.data) do
252 if who.value == v.value then
253 table.remove(self.data,i)
254 end
255 end
256 self:Redraw()
257 end,
258 ["Convert"] = function(who,roll) -- convert an LE object into one suitable to put in a SelectorList
259 local new = copy(who)
260 new.disabled = false -- todo: should be unnessary - they can't get on the list like this
261 if roll then
262 new.text = new.text .. " (roll 73)"
263 end
264 return new
265 end,
155 } 266 }
156 267
157 DataEventDispatch = 268 DataEventDispatch =
158 { 269 {
159 -- todo: batch events 270 -- todo: batch events
183 --escapeButton.shown = true 294 --escapeButton.shown = true
184 --_G["BSK_ESCAPEBUTTON"] = escapeButton 295 --_G["BSK_ESCAPEBUTTON"] = escapeButton
185 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON") 296 --table.insert(_G.UISpecialFrames, "BSK_ESCAPEBUTTON")
186 297
187 if f then return end -- no second gui please 298 if f then return end -- no second gui please
188 local admin = bsk.admin or true 299 local admin = admin or true
189 f = AceGUI:Create("Frame") 300 f = AceGUI:Create("Frame")
190 301
191 f:SetCallback("OnClose",function(widget) escapeButton.shown = false; AceGUI:Release(widget); f=nil; right=nil; SListEventDispatch:Release(); LListEventDispatch:Release(); SListPopulator:Release(); RListEventDispatch:Release() end) 302 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)
192 f:SetTitle("BSK") 303 f:SetTitle("BSK")
193 f:SetLayout("Flow") 304 f:SetLayout("Flow")
194 f:SetHeight(680) 305 f:SetHeight(680)
195 f:SetWidth(580) 306 f:SetWidth(580)
196 307
208 319
209 local t1 = AceGUI:Create("SelectorList") 320 local t1 = AceGUI:Create("SelectorList")
210 t1:SetNumLines(25) 321 t1:SetNumLines(25)
211 t1:SetFullWidth(true) 322 t1:SetFullWidth(true)
212 t1:SetInteractive(admin) 323 t1:SetInteractive(admin)
324 SListEventDispatch:SetTarget(t1)
213 SListPopulator:SetWidget(t1) 325 SListPopulator:SetWidget(t1)
214 SListEventDispatch:SetTarget(t1)
215 326
216 local p1 = CreateListSelector(SListPopulator) 327 local p1 = CreateListSelector(SListPopulator)
217 p1:SetFullWidth(true) 328 p1:SetFullWidth(true)
218 329
219 left:AddChild(p1) 330 left:AddChild(p1)
221 332
222 local t2 = AceGUI:Create("SelectorList") 333 local t2 = AceGUI:Create("SelectorList")
223 t2:SetNumLines(7) 334 t2:SetNumLines(7)
224 t2:SetFullWidth(true) 335 t2:SetFullWidth(true)
225 t2:EnableButtonTooltips(true) 336 t2:EnableButtonTooltips(true)
226 t2:SetList({
227 {
228 value=1,
229 text = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
230 link = "|cffa335ee|Hitem:77109:4080:4009:0:0:0:0:0:85:0|h[Band of Reconstruction]|h|r",
231 },
232 {
233 value=2,
234 text = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r",
235 link = "|cffa335ee|Hitem:19351:0:0:0:0:0:0:0:85:0|h[Maladath, Runed Blade of the Black Flight]|h|r"
236 },
237 {
238 value=3,
239 text = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r",
240 link = "|cffa335ee|Hitem:31986:0:0:0:0:0:0:0:85:0|h[Merciless Gladiator's Crossbow of the Phoenix]|h|r"
241 },
242 {
243 value=4,
244 text = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r",
245 link = "|cffa335ee|Hitem:65003:0:0:0:0:0:0:0:85:0|h[Reclaimed Ashkandi, Greatsword of the Brotherhood]|h|r"
246 },
247 {
248 value=5,
249 text = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r",
250 link = "|cffff8000|Hitem:19019:0:0:0:0:0:0:0:85:0|h[Thunderfury, Blessed Blade of the Windseeker]|h|r"
251 },
252 })
253 LListEventDispatch:SetTarget(t2) 337 LListEventDispatch:SetTarget(t2)
338 LListPopulator:SetWidget(t2)
254 339
255 local biddingZone = AceGUI:Create("SimpleGroup") 340 local biddingZone = AceGUI:Create("SimpleGroup")
256 biddingZone:SetLayout("Flow") 341 biddingZone:SetLayout("Flow")
257 biddingZone:SetFullWidth(true) 342 biddingZone:SetFullWidth(true)
258 343
302 bidTitle:SetFullWidth(true) 387 bidTitle:SetFullWidth(true)
303 388
304 local bidRetractButton = AceGUI:Create("Button") 389 local bidRetractButton = AceGUI:Create("Button")
305 bidRetractButton:SetText("Place Bid") 390 bidRetractButton:SetText("Place Bid")
306 bidRetractButton:SetWidth(100) 391 bidRetractButton:SetWidth(100)
392 bidRetractButton:SetCallback("OnClick", function(widget) RListPopulator:Force(SListPopulator:GetMe()) end)
307 local rollButton = AceGUI:Create("Button") 393 local rollButton = AceGUI:Create("Button")
308 rollButton:SetText("Offset Roll") 394 rollButton:SetText("Offset Roll")
309 rollButton:SetWidth(100) 395 rollButton:SetWidth(100)
310 396
311 local dummydata= {} 397 RListEventDispatch:SetTarget(b1)
312 local tree =SListPopulator.data 398 RListPopulator:SetWidget(b1)
313 for i,v in pairs(tree) do dummydata[i] = copy(v); dummydata[i].disabled = false end
314 if dummydata[2] then dummydata[2].text = dummydata[2].text .. " (roll 73)" end
315 b1:SetList(dummydata)
316 399
317 local g1 400 local g1
318 if admin then 401 if admin then
319 RListEventDispatch:SetTarget(b1)
320 b1.alignoffset = 0.25 -- or else g1 won't align well 402 b1.alignoffset = 0.25 -- or else g1 won't align well
321 g1 = AceGUI:Create("SimpleGroup") 403 g1 = AceGUI:Create("SimpleGroup")
322 g1.alignoffset = 0.25 404 g1.alignoffset = 0.25
323 g1:SetWidth(120) 405 g1:SetWidth(120)
324 g1:SetLayout("List") 406 g1:SetLayout("List")
332 else 414 else
333 adminForce:SetText("Force bid") 415 adminForce:SetText("Force bid")
334 adminForce:SetDisabled(true) 416 adminForce:SetDisabled(true)
335 end 417 end
336 adminForce:SetWidth(160) 418 adminForce:SetWidth(160)
419 adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end)
337 adminForce.userdata = 420 adminForce.userdata =
338 { 421 {
339 widget = adminForce, 422 widget = adminForce,
340 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end, 423 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Force bid") end,
341 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end, 424 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Force bid (%s)",SListEventDispatch:LatestValue().textPlain)) end,
357 widget = adminRetract, 440 widget = adminRetract,
358 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end, 441 ["Redraw"] = function(self,_) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end,
359 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end, 442 ["OnSelection"] = function(self,_) self.widget:SetDisabled(false); self.widget:SetText(sformat("Retract bid (%s)",RListEventDispatch:LatestValue().textPlain)) end,
360 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end 443 ["OnSelectionCleared"] = function(self) self.widget:SetDisabled(true); self.widget:SetText("Retract bid") end
361 } 444 }
445 adminRetract:SetCallback("OnClick",function(widget) RListPopulator:Retract(RListEventDispatch:LatestValue()) end)
362 RListEventDispatch:RegisterListener(adminRetract.userdata) 446 RListEventDispatch:RegisterListener(adminRetract.userdata)
363 adminRetract:SetDisabled(true) 447 adminRetract:SetDisabled(true)
364 448
365 g1:AddChildren(adminForce,adminRetract) 449 g1:AddChildren(adminForce,adminRetract)
366 end 450 end