Mercurial > wow > buffalo2
changeset 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 | 03ed70f846de |
files | ObjectiveTracker/DefaultTracker.lua ObjectiveTracker/Events.lua ObjectiveTracker/Frame.lua ObjectiveTracker/ObjectiveTracker.lua ObjectiveTracker/Quests.lua ObjectiveTracker/Schema.lua ObjectiveTracker/Widgets.lua |
diffstat | 7 files changed, 273 insertions(+), 249 deletions(-) [+] |
line wrap: on
line diff
--- a/ObjectiveTracker/DefaultTracker.lua Thu Apr 21 11:36:41 2016 -0400 +++ b/ObjectiveTracker/DefaultTracker.lua Thu Apr 21 16:43:37 2016 -0400 @@ -3,6 +3,7 @@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 4/17/2016 7:33 AM +--- Baseline update work local B = select(2,...).frame local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') local Devian = Devian
--- a/ObjectiveTracker/Events.lua Thu Apr 21 11:36:41 2016 -0400 +++ b/ObjectiveTracker/Events.lua Thu Apr 21 16:43:37 2016 -0400 @@ -31,13 +31,11 @@ end T.AddTrackedAchievement = function(cheevID) - T.CleanWidgets() --return OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT end T.RemoveTrackedAchievement = function(cheevID) - T.CleanWidgets() --return OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT end @@ -66,4 +64,13 @@ T.SetSuperTrackedQuestID = function(questID) --T:Update() +end + +local previousSelection +local tprint = B.print('Tracker') +T.SelectQuestLogEntry = function(logIndex) + if previousSelection and previousSelection ~= logIndex then + tprint('swapping selection from', previousSelection, 'to', logIndex) + end + previousSelection = logIndex end \ No newline at end of file
--- a/ObjectiveTracker/Frame.lua Thu Apr 21 11:36:41 2016 -0400 +++ b/ObjectiveTracker/Frame.lua Thu Apr 21 16:43:37 2016 -0400 @@ -3,6 +3,7 @@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 3/30/2016 12:49 AM +--- Everything that involves directly placing elements on the screen goes here. Sizing, spacing, tiling, etc. local B = select(2,...).frame local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band @@ -67,7 +68,12 @@ local textbg = {'HORIZONTAL', 0, 0, 0, 0.4, 0, 0, 0, 0 } local textFont, textSize, textOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]], 16, 'OUTLINE' -local textColor = {1,1,1,1} +local textColor = {1,1,1,1 } + +local widgetTextFont, widgetTextSize, widgetTextOutline = [[Interface\Addons\SharedMedia_MyMedia\font\XOIREQE.TTF]], 11, 'OUTLINE' +local widgetTextColor = {1,1,1,1 } +local widgetHeight, widgetBorder = 17, 1 + local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225} local titleSpacing, textSpacing, blockSpacing = 3, 3, 1 @@ -125,6 +131,9 @@ elseif layer == 'line' then textColor = c.textColor lineSchema = newSchema + elseif layer == 'widget' then + widgetTextColor = c.textSpacing + widgetTextFont, widgetTextSize, widgetTextOutline = unpack(c.textFont) end tprint('|cFFFF0088 Schema:|r', layer, lastSchema[layer], '->', newSchema) end @@ -614,3 +623,203 @@ Scroll:Show() 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 + local isNew + 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 + -- creating a new frame + isNew = true + 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) + T.UpdateSchema(widgetType, data.schema or 'default') + else + -- recycling for a different criteria set + isNew = true + 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, isNew) + 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, isNew, ...) + -- todo: config pull + if not wrapperWidth then + wrapperWidth = T.Conf.Wrapper.Width + textIndent = T.Conf.Wrapper.TextIndent + end + + tprint('Initialize', frame:GetName(), isNew, ...) + 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, isNew) + T.UpdateWidget[frame.widgetType](frame, isNew) + end, +}) + +--- WidgetTemplate 'OnEvent' +T.UpdateWidget = setmetatable({}, { + __call = function(t, frame, isNew, ...) + tprint('Update', frame:GetName(), isNew, ...) + if not frame.widgetType then + return + end + + return t[frame.widgetType](frame, isNew) + end +}) + + +local progressHeight = 17 +local progressBorder = 1 +local progressFont = _G.VeneerCriteriaFontNormal + +local lprint = B.print('Line') +T.InitializeWidget.StatusBar = function(self, isNew) + local print = lprint + local c = T.Conf.Wrapper + + tprint(self:GetName(), isNew) + if isNew then + self.maxValue = self.maxValue or 1 + self:SetMinMaxValues(0, self.maxValue) + + self:SetHeight(widgetHeight) + self.height = widgetHeight + + self.status:SetFont(widgetTextFont, widgetTextSize, widgetTextOutline) + self.status:SetTextColor(unpack(widgetTextColor)) + end + self.value = self.value or 1 + self:SetValue(self.value) + + 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.width = self.width or self:GetWidth() + 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
--- a/ObjectiveTracker/ObjectiveTracker.lua Thu Apr 21 11:36:41 2016 -0400 +++ b/ObjectiveTracker/ObjectiveTracker.lua Thu Apr 21 16:43:37 2016 -0400 @@ -264,8 +264,9 @@ end local Event = {} + Event.QUEST_LOG_UPDATE = function() - return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST + OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE + return OBJECTIVE_TRACKER_UPDATE_QUEST end local GetNumQuestWatches, AddQuestWatch, SetSuperTrackedQuestID = GetNumQuestWatches, AddQuestWatch, SetSuperTrackedQuestID Event.QUEST_ACCEPTED = function(questLogIndex, questID, added) @@ -277,10 +278,6 @@ AddQuestWatch(questID) end -Event.QUEST_REMOVED = function(questLogIndex, questID) - return OBJECTIVE_TRACKER_UPDATE_QUEST, questID, false -end - Event.QUEST_WATCH_LIST_CHANGED = function(questID, added) if ( added == true ) then if ( not IsQuestTask(questID) ) then @@ -377,7 +374,8 @@ ['RemoveAutoQuestPopUp'] = 'RemoveAutoQuestPopUp', ['AddTrackedAchievement'] = 'AddTrackedAchievement', ['RemoveTrackedAchievement'] = 'RemoveTrackedAchievement', - ['SetSuperTrackedQuestID'] = 'SetSuperTrackedQuestID' + ['SetSuperTrackedQuestID'] = 'SetSuperTrackedQuestID', + ['SelectQuestLogEntry'] = 'SelectQuestLogEntry', } local VeneerData @@ -403,9 +401,6 @@ local xp = GetQuestLogRewardXP(); local playerTitle = GetQuestLogRewardTitle(); ProcessQuestLogRewardFactions(); - if previousSelection then - SelectQuestLogEntry(previousSelection) - end local rewards = {} local texture, name, isTradeskillSpell, isSpellLearned, hideSpellLearnText, isBoostSpell, garrFollowerID = GetQuestLogRewardSpell(questID) @@ -416,6 +411,9 @@ texture = texture, }) end + if previousSelection then + SelectQuestLogEntry(previousSelection) + end t.numCurrencies = GetNumQuestLogRewardCurrencies(questID) for i = 1, t.numCurrencies do
--- a/ObjectiveTracker/Quests.lua Thu Apr 21 11:36:41 2016 -0400 +++ b/ObjectiveTracker/Quests.lua Thu Apr 21 16:43:37 2016 -0400 @@ -124,9 +124,19 @@ tremove(used, info.posIndex) tinsert(free, block) end +end +Quest.OnRemoved = function(block) end + +Quest.GetBlock = function(self, index) + local block = Default.GetBlock(self, index) + block:SetScript('OnEvent', Quest.OnRemoved) + block:RegisterEvent('QUEST_REMOVED') + return block +end + local watchesChecked = {} local infosChecked = {} local blocksChecked = {} @@ -304,6 +314,7 @@ -- Case 3: quest in progress -- * Multiple objective lines -- * Possible extra lines for money and timer data respectively + self.print(' QuestInfo', title, questType, isAutoComplete) objectives = Quest.GetObjectives(logIndex, numObjectives, false, isSequenced, isStory) q.objectives = objectives @@ -505,14 +516,33 @@ Quest.GetObjectives = function(logIndex, numObjectives, isComplete, isSequenced, isStory) local print = Quest.print local objectives = {} + if not logIndex then + return + end + for i = 1, numObjectives do local text, type, finished = GetQuestLogLeaderBoard(i, logIndex) - print('GetObjectives', format('|cFF88FF88#%d %s %s %s', i, tostring(type), tostring(text), tostring(finished))) + + local progress = 0 + if finished then + progress = 1 + elseif text then + local quantity, maxQuantity = text:match('^(%d+)/(%d+)') + if quantity and maxQuantity then + progress = quantity / maxQuantity + --print('GetObjectives', 'calculated objective progress:', quantity, '/', maxQuantity, '=', progress) + end + end + + print('GetObjectives', format('|cFF88FF88#%d %s %s %s', i, tostring(type), tostring(text), tostring(finished)), '('.. tostring(progress)..')') + + objectives[i] = { index = i, type = type, text = text, - finished = finished + finished = finished, + progress = progress } end return objectives
--- a/ObjectiveTracker/Schema.lua Thu Apr 21 11:36:41 2016 -0400 +++ b/ObjectiveTracker/Schema.lua Thu Apr 21 16:43:37 2016 -0400 @@ -111,31 +111,31 @@ textIndent = 3, }, completed = { - textColor = {0, 1, 0} + textColor = {.5, 1, .5} }, failed = { - textColor = {1,0,0 } + textColor = {1,.25,.25 } }, autocomplete = { - textColor = {0,1,0 } + textColor = {.5,1,1 } }, - objectColor = { + object = { textColor = {0,1,1} }, monster = { textColor = {1,1,0} }, item = { - textColor = {1,.25,.5} + textColor = {1,.75,.75} }, achievement_complete = { textColor = {1, 1, 1, 1}, }, achievement = { - textColor = {0, 0.7, 1, 1}, + textColor = {0.5, 0.85, 1, 1}, }, achievement_account = { - textColor = {.35, 0.7, 1, 1}, + textColor = {.4, 0.7, 1, 1}, }, } T.defaults.Schema.widget = { @@ -145,4 +145,11 @@ timer = { } +} + +T.defaults.Schema.statusbar = { + default = { + textFont = {[[Interface\Addons\SharedMedia_MyMedia\font\XOIREQE.TTF]], 11, 'OUTLINE'}, + textColor = {1,1,1,1}, + } } \ No newline at end of file
--- 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