comparison ObjectiveTracker/Widgets.lua @ 39:92534dc793f2

- restore the previous QuestLogSelection after pulling for selection-restricted quest data; fixes icon mixups while quest map is open - moved progressbar builders into the schema environment, with all the other Frame.lua functions; prep for configuration access - relegate the various removal events to a framescript in their corresponding blocks; this takes care of resolving dead frames
author Nenue
date Thu, 21 Apr 2016 16:43:37 -0400
parents 1f8f9cc3d956
children 9480bd904f4c
comparison
equal deleted inserted replaced
38:1f8f9cc3d956 39:92534dc793f2
252 SetItemButtonTextureVertexColor(itemButton, 1, 1, 1) 252 SetItemButtonTextureVertexColor(itemButton, 1, 1, 1)
253 end 253 end
254 end 254 end
255 end 255 end
256 256
257 -----------------------------------------
258 -- Criteria frames
259
260 --[[
261 text = description,
262 type = type,
263 finished = completed,
264 quantity = quantity,
265 requiredQuantity = requiredQuantity,
266 characterName = characterName,
267 flags = flags,
268 assetID = assetID,
269 quantityString = quantityString,
270 criteriaID = criteriaID,
271 ]]
272 local newWidgetID = 0
273 T.WidgetRegistry = {}
274 local wr = T.WidgetRegistry
275
276 --- Get a usable widget for the given achievement criteria set.
277 -- Returns a frame object with dimensioning parameters needed to size the receiving tracker block
278 T.GetWidget = function(data, objectiveType, objectiveKey)
279 local print = B.print('ObjectiveWidgets')
280 local widgetType = objectiveType
281 local widget
282 if wr[widgetType] and wr[widgetType].used[objectiveKey] then
283 widget = wr[widgetType].used[objectiveKey]
284 print('|cFF00FF00Updating ('..objectiveKey..')', widget)
285 elseif not wr[widgetType] or #wr[widgetType].free == 0 then
286 widget = CreateFrame(widgetType, 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType)
287 print('|cFFFF0088Creating `'..widget:GetName()..'` id', wr[widgetType].lastn)
288 else
289 widget = tremove(wr[widgetType].free)
290 print('|cFFFFFF00Acquiring released widget', widget:GetName())
291 end
292
293
294 wr[widgetType].used[objectiveKey] = widget
295 widget.objective = data
296 widget.key = objectiveKey
297 T.InitializeWidget(widget)
298 return widget
299 end
300
301 --- WidgetTemplate 'OnLoad'
302 T.RegisterWidget = function(frame)
303 local print = B.print('ObjectiveWidgets')
304 local widgetType = frame.widgetType
305 if not wr[frame.widgetType] then
306 print('|cFFFF4400[[WidgetTemplate]]|r', widgetType)
307 wr[widgetType] = { lastn = 1, free = {}, used = {}, usedIndex = {}, freeIndex = {} }
308 else
309 print('|cFF0088FF+ [[WidgetTemplate]]r', widgetType, wr[widgetType].lastn)
310 wr[widgetType].lastn = wr[widgetType].lastn + 1
311 end
312 end
313 --- WidgetTemplate 'OnShow'
314 local wrapperWidth, textIndent
315 T.InitializeWidget = setmetatable({}, {
316 __call = function(t, frame)
317 -- todo: config pull
318 if not wrapperWidth then
319 wrapperWidth = T.Conf.Wrapper.Width
320 textIndent = T.Conf.Wrapper.TextIndent
321 end
322
323 frame:SetWidth(wrapperWidth - textIndent * 2)
324 frame:SetScript('OnEvent', T.UpdateWidget[frame.widgetType])
325 frame:RegisterEvent('QUEST_LOG_UPDATE')
326 frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE')
327 frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED')
328 frame:RegisterEvent('CRITERIA_UPDATE')
329 frame:RegisterEvent('CRITERIA_COMPLETE')
330 frame:RegisterEvent('CRITERIA_EARNED')
331 t[frame.widgetType](frame)
332 T.UpdateWidget[frame.widgetType](frame)
333 end,
334 })
335
336 --- WidgetTemplate 'OnEvent'
337 T.UpdateWidget = setmetatable({}, {
338 __call = function(t, frame)
339 if not frame.widgetType then
340 error('Invalid widget template, needs .widgetType')
341 return
342 end
343
344 return t[frame.widgetType](frame)
345 end
346 })
347
348 --- WidgetTemplate 'OnHide'
349 T.ReleaseWidget = function(frame)
350 --[[
351 local print = B.print('ObjectiveWidgets')
352 local reg = wr[frame.widgetType]
353 if reg and reg.used[frame.key] then
354 reg.used[frame.key] = nil
355 frame.line = nil
356 frame.info = nil
357 frame:UnregisterAllEvents()
358 tinsert(reg.free, frame)
359 print('|cFFBBBBBBreleased from service', frame:GetName())
360 end
361 ]]
362 end
363
364 --- RemoveTrackedAchievement post-hook
365 T.CleanWidgets = function()
366 local print = B.print('ObjectiveWidgets')
367 local tracked = {GetTrackedAchievements() }
368 local tasks = GetTasksTable()
369 for type, reg in pairs(T.WidgetRegistry) do
370 print('collecting', type)
371 for key, frame in pairs(reg.used) do
372 if frame.objective.cheevID then
373 local id = frame.objective.cheevID
374
375 if id and not tContains(tracked, id) then
376
377 print(' untracked achievement', id, 'associated with', key, frame:GetName())
378 frame:Hide()
379 end
380 elseif frame.objective.questID then
381 -- do something for quest task
382 end
383 end
384 end
385 end
386
387
388
389 T.defaults.WidgetStyle = {
390
391 }
392
393 local progressHeight = 17
394 local progressBorder = 1
395 local progressFont = _G.VeneerCriteriaFontNormal
396
397 local lprint = B.print('Line')
398 T.InitializeWidget.StatusBar = function(self)
399 local print = lprint
400 local c = T.Conf.Wrapper
401 self.height = progressHeight + c.TextSpacing
402 self.width = c.Width - c.TextSpacing
403 self.value = self.value or 1
404 self.maxValue = self.maxValue or 1
405
406 self:SetHeight(progressHeight)
407 self:SetMinMaxValues(0, self.maxValue)
408 self:SetValue(self.value)
409
410 --self.status:SetFontObject(progressFont)
411 self.status:SetText(self.objective.quantityString)
412 end
413
414 T.UpdateWidget.StatusBar = function (self)
415 local value, maxValue = self.value, self.maxValue
416 print('update vals:')
417 for k,v in pairs(self) do
418 print(k, v)
419 end
420 self:SetValue(self.value)
421 local format = self.format or '%d/%d'
422 self.status:SetFormattedText(format, value, maxValue)
423 local progress = (value / maxValue)
424 if progress > 0 then
425 print('color:', 1-progress*2 , progress*2 - 1,0,1)
426 print('width:', (self.width -progressBorder * 2) * progress)
427 self:SetStatusBarColor(1-progress*2 , progress*2,0,1)
428 end
429 end
430
431
432 T.InitializeWidget.Hidden = function (self)
433 self.height = 0
434 end
435 T.UpdateWidget.Hidden = function (self)
436 self.height= 0
437 end
438
439
440 --- Queue any active item buttons for update for that frame
441 local iprint = B.print('ItemButton')
442 local Quest = T.Quest
443 local IsQuestWatched, InCombatLockdown = IsQuestWatched, InCombatLockdown
444 T.UpdateActionButtons = function(updateReason)
445 local print = iprint
446 Scroller.snap_upper = 0
447 Scroller.snap_lower = 0
448 local print = B.print('ItemButton')
449 if updateReason then
450 print = B.print('IB_'..updateReason)
451 end
452
453 local previousItem
454 for questID, itemButton in pairs(Quest.itemButtons) do
455 local info= T.Quest.Info[questID]
456
457 print('|cFF00FFFF'.. questID .. '|r', itemButton:GetName())
458 local block = T.Quest.QuestBlock[questID]
459 if block then
460 -- Dispatch the probe
461 if IsQuestWatched(info.logIndex) then
462 itemButton.previousItem = previousItem
463 print(' |cFFFFFF00probing', block:GetName())
464 block:SetScript('OnUpdate', function()
465 if block:GetBottom() and not InCombatLockdown() then
466 print(' '..block:GetName()..' |cFF00FF00probe hit!')
467 T.UpdateBlockAction(block, itemButton, itemButton.previousItem) -- needs to be previousItem from this scope
468 block:SetScript('OnUpdate', nil)
469
470 end
471 end)
472 previousItem = itemButton
473 else
474 print('hidden block or unwatched quest')
475 itemButton.previousItem = nil
476 itemButton:Hide()
477 end
478 elseif itemButton:IsVisible() then
479 print(' |cFFFF0088hiding unwatched quest button', itemButton:GetName())
480 itemButton.previousItem = nil
481 itemButton:Hide()
482 else
483 print(' |cFFBBBBBBignoring hidden log quest button', itemButton:GetName())
484 end
485 end
486 end