Mercurial > wow > buffalo2
diff 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 |
line wrap: on
line diff
--- a/ObjectiveTracker/Widgets.lua Thu Apr 21 11:36:41 2016 -0400 +++ b/ObjectiveTracker/Widgets.lua Thu Apr 21 16:43:37 2016 -0400 @@ -254,233 +254,3 @@ end end ------------------------------------------ --- Criteria frames - ---[[ - text = description, - type = type, - finished = completed, - quantity = quantity, - requiredQuantity = requiredQuantity, - characterName = characterName, - flags = flags, - assetID = assetID, - quantityString = quantityString, - criteriaID = criteriaID, -]] -local newWidgetID = 0 -T.WidgetRegistry = {} -local wr = T.WidgetRegistry - ---- Get a usable widget for the given achievement criteria set. --- Returns a frame object with dimensioning parameters needed to size the receiving tracker block -T.GetWidget = function(data, objectiveType, objectiveKey) - local print = B.print('ObjectiveWidgets') - local widgetType = objectiveType - local widget - if wr[widgetType] and wr[widgetType].used[objectiveKey] then - widget = wr[widgetType].used[objectiveKey] - print('|cFF00FF00Updating ('..objectiveKey..')', widget) - elseif not wr[widgetType] or #wr[widgetType].free == 0 then - widget = CreateFrame(widgetType, 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType) - print('|cFFFF0088Creating `'..widget:GetName()..'` id', wr[widgetType].lastn) - else - widget = tremove(wr[widgetType].free) - print('|cFFFFFF00Acquiring released widget', widget:GetName()) - end - - - wr[widgetType].used[objectiveKey] = widget - widget.objective = data - widget.key = objectiveKey - T.InitializeWidget(widget) - return widget -end - ---- WidgetTemplate 'OnLoad' -T.RegisterWidget = function(frame) - local print = B.print('ObjectiveWidgets') - local widgetType = frame.widgetType - if not wr[frame.widgetType] then - print('|cFFFF4400[[WidgetTemplate]]|r', widgetType) - wr[widgetType] = { lastn = 1, free = {}, used = {}, usedIndex = {}, freeIndex = {} } - else - print('|cFF0088FF+ [[WidgetTemplate]]r', widgetType, wr[widgetType].lastn) - wr[widgetType].lastn = wr[widgetType].lastn + 1 - end -end ---- WidgetTemplate 'OnShow' -local wrapperWidth, textIndent -T.InitializeWidget = setmetatable({}, { - __call = function(t, frame) - -- todo: config pull - if not wrapperWidth then - wrapperWidth = T.Conf.Wrapper.Width - textIndent = T.Conf.Wrapper.TextIndent - end - - frame:SetWidth(wrapperWidth - textIndent * 2) - frame:SetScript('OnEvent', T.UpdateWidget[frame.widgetType]) - frame:RegisterEvent('QUEST_LOG_UPDATE') - frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE') - frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED') - frame:RegisterEvent('CRITERIA_UPDATE') - frame:RegisterEvent('CRITERIA_COMPLETE') - frame:RegisterEvent('CRITERIA_EARNED') - t[frame.widgetType](frame) - T.UpdateWidget[frame.widgetType](frame) - end, -}) - ---- WidgetTemplate 'OnEvent' -T.UpdateWidget = setmetatable({}, { - __call = function(t, frame) - if not frame.widgetType then - error('Invalid widget template, needs .widgetType') - return - end - - return t[frame.widgetType](frame) - end -}) - ---- WidgetTemplate 'OnHide' -T.ReleaseWidget = function(frame) - --[[ - local print = B.print('ObjectiveWidgets') - local reg = wr[frame.widgetType] - if reg and reg.used[frame.key] then - reg.used[frame.key] = nil - frame.line = nil - frame.info = nil - frame:UnregisterAllEvents() - tinsert(reg.free, frame) - print('|cFFBBBBBBreleased from service', frame:GetName()) - end - ]] -end - ---- RemoveTrackedAchievement post-hook -T.CleanWidgets = function() - local print = B.print('ObjectiveWidgets') - local tracked = {GetTrackedAchievements() } - local tasks = GetTasksTable() - for type, reg in pairs(T.WidgetRegistry) do - print('collecting', type) - for key, frame in pairs(reg.used) do - if frame.objective.cheevID then - local id = frame.objective.cheevID - - if id and not tContains(tracked, id) then - - print(' untracked achievement', id, 'associated with', key, frame:GetName()) - frame:Hide() - end - elseif frame.objective.questID then - -- do something for quest task - end - end - end -end - - - -T.defaults.WidgetStyle = { - -} - -local progressHeight = 17 -local progressBorder = 1 -local progressFont = _G.VeneerCriteriaFontNormal - -local lprint = B.print('Line') -T.InitializeWidget.StatusBar = function(self) - local print = lprint - local c = T.Conf.Wrapper - self.height = progressHeight + c.TextSpacing - self.width = c.Width - c.TextSpacing - self.value = self.value or 1 - self.maxValue = self.maxValue or 1 - - self:SetHeight(progressHeight) - self:SetMinMaxValues(0, self.maxValue) - self:SetValue(self.value) - - --self.status:SetFontObject(progressFont) - self.status:SetText(self.objective.quantityString) -end - -T.UpdateWidget.StatusBar = function (self) - local value, maxValue = self.value, self.maxValue - print('update vals:') - for k,v in pairs(self) do - print(k, v) - end - self:SetValue(self.value) - local format = self.format or '%d/%d' - self.status:SetFormattedText(format, value, maxValue) - local progress = (value / maxValue) - if progress > 0 then - print('color:', 1-progress*2 , progress*2 - 1,0,1) - print('width:', (self.width -progressBorder * 2) * progress) - self:SetStatusBarColor(1-progress*2 , progress*2,0,1) - end -end - - -T.InitializeWidget.Hidden = function (self) - self.height = 0 -end -T.UpdateWidget.Hidden = function (self) - self.height= 0 -end - - ---- Queue any active item buttons for update for that frame -local iprint = B.print('ItemButton') -local Quest = T.Quest -local IsQuestWatched, InCombatLockdown = IsQuestWatched, InCombatLockdown -T.UpdateActionButtons = function(updateReason) - local print = iprint - Scroller.snap_upper = 0 - Scroller.snap_lower = 0 - local print = B.print('ItemButton') - if updateReason then - print = B.print('IB_'..updateReason) - end - - local previousItem - for questID, itemButton in pairs(Quest.itemButtons) do - local info= T.Quest.Info[questID] - - print('|cFF00FFFF'.. questID .. '|r', itemButton:GetName()) - local block = T.Quest.QuestBlock[questID] - if block then - -- Dispatch the probe - if IsQuestWatched(info.logIndex) then - itemButton.previousItem = previousItem - print(' |cFFFFFF00probing', block:GetName()) - block:SetScript('OnUpdate', function() - if block:GetBottom() and not InCombatLockdown() then - print(' '..block:GetName()..' |cFF00FF00probe hit!') - T.UpdateBlockAction(block, itemButton, itemButton.previousItem) -- needs to be previousItem from this scope - block:SetScript('OnUpdate', nil) - - end - end) - previousItem = itemButton - else - print('hidden block or unwatched quest') - itemButton.previousItem = nil - itemButton:Hide() - end - elseif itemButton:IsVisible() then - print(' |cFFFF0088hiding unwatched quest button', itemButton:GetName()) - itemButton.previousItem = nil - itemButton:Hide() - else - print(' |cFFBBBBBBignoring hidden log quest button', itemButton:GetName()) - end - end -end \ No newline at end of file