Nenue@28: --- ${PACKAGE_NAME} Nenue@28: -- @file-author@ Nenue@28: -- @project-revision@ @project-hash@ Nenue@28: -- @file-revision@ @file-hash@ Nenue@28: -- Created: 4/13/2016 7:48 PM Nenue@28: local B = select(2,...).frame Nenue@28: local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') Nenue@29: local band = bit.band Nenue@30: local RemoveTrackedAchievement, GetAchievementLink = RemoveTrackedAchievement, GetAchievementLink Nenue@29: local AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement = AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement Nenue@29: local GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo = GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo Nenue@29: local GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo = GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo Nenue@29: local Default, Cheevs = T.DefaultHandler, T.Cheevs Nenue@37: local wipe = table.wipe Nenue@37: local print, bprint, lprint, iprint = B.print('Tracker'), B.print('Block'), B.print('Line'), B.print('iprint') Nenue@28: Nenue@40: --- Frame data Nenue@40: Cheevs.UpdateObjectives = function(handler, block, block_schema) Nenue@40: -- if completed on another character, only show the heading for CHATLINK Nenue@40: if block.info.completed then Nenue@40: return 0, block_schema Nenue@40: end Nenue@40: Nenue@40: if block.info.description then Nenue@40: handler:AddLine(block, block.info.description, nil, 'defalut') Nenue@40: end Nenue@40: local attachments = Default.UpdateObjectives(handler, block, block_schema) Nenue@40: Nenue@40: return attachments, block_schema Nenue@40: end Nenue@40: Nenue@40: Cheevs.UpdateLine = function(handler, block, data) Nenue@40: local print = lprint Nenue@40: local attachment Nenue@40: local text Nenue@40: local lineSchema = 'default' Nenue@40: print(' ', data.objectiveIndex,'|cFF'..handler.internalColor..'-|r', data.objectiveType, data.text) Nenue@40: if data.type == CRITERIA_TYPE_ACHIEVEMENT then Nenue@40: if data.value == 1 then Nenue@40: return nil, nil Nenue@40: end Nenue@40: Nenue@40: text = data.text Nenue@40: lineSchema = (data.quantity == 1) and 'achievement_complete' or 'achievement' Nenue@40: elseif band(data.flags, 0x00000001) > 0 then Nenue@40: attachment = T.GetWidget(data, 'StatusBar', data.criteriaID) Nenue@40: attachment.format = "%d/%d" Nenue@40: attachment.value = data.value Nenue@40: attachment.maxValue = data.maxValue Nenue@40: attachment:SetParent(block) Nenue@40: Nenue@40: print(attachment:GetNumPoints()) Nenue@40: for i = 1, attachment:GetNumPoints() do Nenue@40: print(' ',attachment:GetPoint(i)) Nenue@40: end Nenue@40: attachment.status:SetFormattedText("%d/%d", data.value, data.maxValue) Nenue@40: attachment:SetPoint('TOP', line, 'TOP') Nenue@40: lineSchema = 'progressbar' Nenue@40: else Nenue@40: Nenue@40: text = format("%d/%d %s", data.value, data.maxValue, data.text) Nenue@40: lineSchema = 'default' Nenue@40: end Nenue@40: print(' |cFF'..handler.internalColor..'UpdateLine:|r', data.type, data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID) Nenue@40: return text, attachment, lineSchema Nenue@40: end Nenue@40: Nenue@40: Cheevs.Select = function(self, block) Nenue@40: Cheevs.Link(self, block) Nenue@40: T:Update(self.updateReasonModule, block.info.cheevID) Nenue@40: end Nenue@40: Nenue@40: Cheevs.Remove = function(self, block) Nenue@40: Nenue@40: RemoveTrackedAchievement(block.info.cheevID) Nenue@40: end Nenue@40: Cheevs.OnMouseUp = function(self, button) Nenue@40: Nenue@40: Default.OnMouseUp(self, button) Nenue@40: end Nenue@40: Cheevs.Link = function(self, block) Nenue@40: local achievementLink = GetAchievementLink(block.info.cheevID); Nenue@40: if ( achievementLink ) then Nenue@40: _G.ChatEdit_InsertLink(achievementLink); Nenue@40: end Nenue@40: end Nenue@40: Nenue@40: --- Data accessors Nenue@37: Cheevs.GetNumWatched = function(self, targetID, isNew) Nenue@37: local trackedList = {GetTrackedAchievements() } Nenue@37: local numWatched, numAll = #trackedList, #self.WatchList Nenue@38: print(' |cFF'..self.internalColor..'GetNumWatched:|r',self.name, numWatched, ' ('..numAll..' recorded)') Nenue@37: local start = 1 Nenue@37: local limit = max(numAll, #trackedList) Nenue@37: if targetID then Nenue@37: if not isNew and self.Info[targetID] then Nenue@37: -- if it's only an update, we can limit the scope Nenue@37: start = self.Info[targetID].watchIndex Nenue@38: print(' |cFF'..self.internalColor..'GetNumWatched: limit selection to['..start..'-'..limit..']') Nenue@37: if self.InfoBlock[targetID] then Nenue@37: self.InfoBlock[targetID]:Hide() Nenue@37: end Nenue@28: Nenue@37: end Nenue@34: end Nenue@34: Nenue@37: for index = start, limit do Nenue@37: if index > numWatched then Nenue@37: self.WatchList[index] = nil Nenue@37: print(' % dropping watch entry #'..index) Nenue@37: else Nenue@37: local cheevID = trackedList[index] Nenue@37: if not self.Info[cheevID] then Nenue@37: self.Info[cheevID] = self:GetInfo(cheevID, index) Nenue@37: else Nenue@38: print(' |cFF'..self.internalColor..'GetInfo:', cheevID, 'already pulled') Nenue@37: end Nenue@37: self:GetObjectives(cheevID) Nenue@34: Nenue@37: local info = self.Info[cheevID] Nenue@37: local watchBlock = self.WatchBlock[cheevID] Nenue@37: Nenue@37: self.Info[cheevID].watchIndex = index Nenue@37: self.WatchList[index] = info Nenue@37: end Nenue@37: end Nenue@37: Nenue@37: numAll = #self.WatchList Nenue@37: return numWatched, numAll, self.WatchList Nenue@37: end Nenue@37: Cheevs.GetInfo = function(self, cheevID, watchIndex) Nenue@37: --- step 1: confirm primary data and begin an entry if needed Nenue@37: local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID) Nenue@37: if not id then return nil end Nenue@37: Nenue@38: print(' |cFF'..self.internalColor..'GetInfo: pulling', id..',', name, earnedBy) Nenue@37: Nenue@37: Nenue@37: self.Info[cheevID] = self.Info[cheevID] or {} Nenue@37: local c = self.Info[cheevID] Nenue@34: local rewards = {} Nenue@34: Nenue@37: c.schema = 'achievement' Nenue@34: c.rewardInfo = rewards Nenue@29: c.type = 'Cheevs' Nenue@34: c.title = name Nenue@34: c.points = points Nenue@34: c.completed = completed Nenue@34: c.month = month Nenue@34: c.day = day Nenue@34: c.year = year Nenue@34: c.description = description Nenue@34: c.flags = flags Nenue@34: c.icon = icon Nenue@34: c.rewardText = rewardText Nenue@34: c.isGuildAch = isGuildAch Nenue@34: c.wasEarnedByMe = wasEarnedByMe Nenue@34: c.earnedBy = earnedBy Nenue@34: Nenue@37: local tagInfo = {} Nenue@34: c.tagInfo = tagInfo Nenue@34: c.watchIndex = watchIndex Nenue@30: c.id = cheevID Nenue@29: c.cheevID = cheevID Nenue@37: Nenue@37: self.Info[cheevID] = c Nenue@34: self.WatchInfo[watchIndex] = c Nenue@37: return c Nenue@37: end Nenue@37: Nenue@37: Cheevs.GetObjectives = function(self, cheevID) Nenue@37: local c = self.Info[cheevID] Nenue@37: c.numObjectives = GetAchievementNumCriteria(cheevID) Nenue@37: c.objectives = c.objectives or {} Nenue@37: for i = 1, c.numObjectives do Nenue@37: local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i) Nenue@37: local line = c.objectives[i] or {} Nenue@37: line.objectiveIndex = i Nenue@37: line.cheevID = cheevID Nenue@37: line.text = description Nenue@37: line.type = type Nenue@37: line.finished = completed Nenue@37: line.value = quantity Nenue@37: line.maxValue = requiredQuantity Nenue@37: line.characterName = characterName Nenue@37: line.flags = flags Nenue@37: line.assetID = assetID Nenue@37: line.quantityString = quantityString Nenue@37: line.criteriaID = criteriaID Nenue@37: c.objectives[i] = line Nenue@37: Nenue@38: print(' |cFF'..self.internalColor..'GetObjectives:|r', i, format('|cFF0088FF%02X|r(%d)', type, type), format('|cFF88FF00%01X|r', flags or 0), '|cFF00FF00'..tostring(quantity)..'|r/|cFF00FF00'.. tostring(requiredQuantity)..'|r', '"|cFF88FF00'..tostring(description)..'|r"') Nenue@37: end Nenue@29: end Nenue@29: Nenue@28: Nenue@30: Cheevs.Open = function(self, block) Nenue@28: Nenue@30: if ( not _G.AchievementFrame ) then Nenue@30: _G.AchievementFrame_LoadUI(); Nenue@28: end Nenue@30: if ( not _G.AchievementFrame:IsShown() ) then Nenue@30: _G.AchievementFrame_ToggleAchievementFrame(); Nenue@28: end Nenue@30: _G.AchievementFrame_SelectAchievement(block.info.cheevID); Nenue@28: end