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@29: --- Data retrieval Nenue@37: Cheevs.GetNumWatched = function(self, targetID, isNew) Nenue@37: local trackedList = {GetTrackedAchievements() } Nenue@37: local numWatched, numAll = #trackedList, #self.WatchList Nenue@37: print(' |cFF00FF88GetNumWatched:|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@37: print(' |cFF0088FFGetNumWatched: 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@37: print(' |cFF00FFBBGetInfo:', 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@37: print(' |cFF44AAFFGetInfo: 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@37: print(' |cFF44FFDDGetObjectives:|r', i, type, description, quantityString) Nenue@37: end Nenue@29: end Nenue@29: Nenue@29: --- Content handlers Nenue@28: Cheevs.UpdateLine = function(handler, block, line, data) Nenue@28: local print = B.print('CheevsLine') Nenue@30: local attachment Nenue@37: local text Nenue@28: line.progress = 0 Nenue@28: print(' ', data.objectiveIndex,'|cFF0088FF-|r', data.objectiveType, data.text) Nenue@28: if data.flags then Nenue@28: if band(data.flags, 0x00000001) > 0 then Nenue@28: line.format = "%d/%d" Nenue@37: attachment = T.SetWidget(line, data, 'ProgressBar', data.criteriaID) Nenue@37: attachment.value = data.value Nenue@37: attachment.maxValue = data.maxValue Nenue@37: attachment:SetParent(handler.frame) Nenue@37: Nenue@37: print(attachment:GetNumPoints()) Nenue@37: for i = 1, attachment:GetNumPoints() do Nenue@37: print(' ',attachment:GetPoint(i)) Nenue@37: end Nenue@37: attachment.status:SetFormattedText("%d/%d", data.value, data.maxValue) Nenue@37: attachment:SetPoint('TOP', line, 'TOP') Nenue@37: line.height = attachment.height Nenue@28: elseif band(data.flags, 0x00000002) then Nenue@28: line.widget = nil Nenue@37: text = line.text Nenue@28: else Nenue@28: line.widget = nil Nenue@28: line.displayColor = 'FFFFFF' Nenue@37: text = line.text Nenue@28: Nenue@28: end Nenue@28: else Nenue@28: Nenue@28: line.displayText = data.text Nenue@28: end Nenue@37: print(' |cFF00DD22UpdateLine:|r', data.type, data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID) Nenue@37: return text, attachment, 'default' Nenue@28: end Nenue@28: Nenue@30: Cheevs.Select = function(self, block) Nenue@30: Cheevs.Link(self, block) Nenue@37: T:Update(self.updateReasonModule, block.info.cheevID) Nenue@28: end Nenue@29: Nenue@30: Cheevs.Remove = function(self, block) Nenue@28: Nenue@30: RemoveTrackedAchievement(block.info.cheevID) Nenue@28: end Nenue@28: Cheevs.OnMouseUp = function(self, button) Nenue@28: Nenue@28: Default.OnMouseUp(self, button) Nenue@28: end Nenue@30: Cheevs.Link = function(self, block) Nenue@30: local achievementLink = GetAchievementLink(block.info.cheevID); Nenue@28: if ( achievementLink ) then Nenue@30: _G.ChatEdit_InsertLink(achievementLink); Nenue@28: end Nenue@28: end 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