annotate ObjectiveTracker/AchievementData.lua @ 54:ed74c5cabe98

Core - updated comment notes Objectives - force hide blocks when their tracker is hidden Clock - convert clock into its own module - display zone coordinates alongside time
author Nenue
date Wed, 01 Jun 2016 20:48:14 -0400
parents 9480bd904f4c
children
rev   line source
Nenue@28 1 --- ${PACKAGE_NAME}
Nenue@28 2 -- @file-author@
Nenue@28 3 -- @project-revision@ @project-hash@
Nenue@28 4 -- @file-revision@ @file-hash@
Nenue@28 5 -- Created: 4/13/2016 7:48 PM
Nenue@28 6 local B = select(2,...).frame
Nenue@28 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@29 8 local band = bit.band
Nenue@30 9 local RemoveTrackedAchievement, GetAchievementLink = RemoveTrackedAchievement, GetAchievementLink
Nenue@29 10 local AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement = AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement
Nenue@29 11 local GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo = GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo
Nenue@29 12 local GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo = GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo
Nenue@29 13 local Default, Cheevs = T.DefaultHandler, T.Cheevs
Nenue@37 14 local wipe = table.wipe
Nenue@37 15 local print, bprint, lprint, iprint = B.print('Tracker'), B.print('Block'), B.print('Line'), B.print('iprint')
Nenue@28 16
Nenue@40 17 --- Frame data
Nenue@40 18 Cheevs.UpdateObjectives = function(handler, block, block_schema)
Nenue@40 19 -- if completed on another character, only show the heading for CHATLINK
Nenue@40 20 if block.info.completed then
Nenue@40 21 return 0, block_schema
Nenue@40 22 end
Nenue@40 23
Nenue@40 24 if block.info.description then
Nenue@40 25 handler:AddLine(block, block.info.description, nil, 'defalut')
Nenue@40 26 end
Nenue@40 27 local attachments = Default.UpdateObjectives(handler, block, block_schema)
Nenue@40 28
Nenue@40 29 return attachments, block_schema
Nenue@40 30 end
Nenue@40 31
Nenue@40 32 Cheevs.UpdateLine = function(handler, block, data)
Nenue@40 33 local print = lprint
Nenue@40 34 local attachment
Nenue@40 35 local text
Nenue@40 36 local lineSchema = 'default'
Nenue@40 37 print(' ', data.objectiveIndex,'|cFF'..handler.internalColor..'-|r', data.objectiveType, data.text)
Nenue@40 38 if data.type == CRITERIA_TYPE_ACHIEVEMENT then
Nenue@40 39 if data.value == 1 then
Nenue@40 40 return nil, nil
Nenue@40 41 end
Nenue@40 42
Nenue@40 43 text = data.text
Nenue@40 44 lineSchema = (data.quantity == 1) and 'achievement_complete' or 'achievement'
Nenue@40 45 elseif band(data.flags, 0x00000001) > 0 then
Nenue@40 46 attachment = T.GetWidget(data, 'StatusBar', data.criteriaID)
Nenue@40 47 attachment.format = "%d/%d"
Nenue@40 48 attachment.value = data.value
Nenue@40 49 attachment.maxValue = data.maxValue
Nenue@40 50 attachment:SetParent(block)
Nenue@40 51
Nenue@40 52 print(attachment:GetNumPoints())
Nenue@40 53 for i = 1, attachment:GetNumPoints() do
Nenue@40 54 print(' ',attachment:GetPoint(i))
Nenue@40 55 end
Nenue@40 56 attachment.status:SetFormattedText("%d/%d", data.value, data.maxValue)
Nenue@40 57 attachment:SetPoint('TOP', line, 'TOP')
Nenue@40 58 lineSchema = 'progressbar'
Nenue@40 59 else
Nenue@40 60
Nenue@40 61 text = format("%d/%d %s", data.value, data.maxValue, data.text)
Nenue@40 62 lineSchema = 'default'
Nenue@40 63 end
Nenue@40 64 print(' |cFF'..handler.internalColor..'UpdateLine:|r', data.type, data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID)
Nenue@40 65 return text, attachment, lineSchema
Nenue@40 66 end
Nenue@40 67
Nenue@40 68 Cheevs.Select = function(self, block)
Nenue@40 69 Cheevs.Link(self, block)
Nenue@40 70 T:Update(self.updateReasonModule, block.info.cheevID)
Nenue@40 71 end
Nenue@40 72
Nenue@40 73 Cheevs.Remove = function(self, block)
Nenue@40 74
Nenue@40 75 RemoveTrackedAchievement(block.info.cheevID)
Nenue@40 76 end
Nenue@40 77 Cheevs.OnMouseUp = function(self, button)
Nenue@40 78
Nenue@40 79 Default.OnMouseUp(self, button)
Nenue@40 80 end
Nenue@40 81 Cheevs.Link = function(self, block)
Nenue@40 82 local achievementLink = GetAchievementLink(block.info.cheevID);
Nenue@40 83 if ( achievementLink ) then
Nenue@40 84 _G.ChatEdit_InsertLink(achievementLink);
Nenue@40 85 end
Nenue@40 86 end
Nenue@40 87
Nenue@40 88 --- Data accessors
Nenue@37 89 Cheevs.GetNumWatched = function(self, targetID, isNew)
Nenue@37 90 local trackedList = {GetTrackedAchievements() }
Nenue@37 91 local numWatched, numAll = #trackedList, #self.WatchList
Nenue@38 92 print(' |cFF'..self.internalColor..'GetNumWatched:|r',self.name, numWatched, ' ('..numAll..' recorded)')
Nenue@37 93 local start = 1
Nenue@37 94 local limit = max(numAll, #trackedList)
Nenue@37 95 if targetID then
Nenue@37 96 if not isNew and self.Info[targetID] then
Nenue@37 97 -- if it's only an update, we can limit the scope
Nenue@37 98 start = self.Info[targetID].watchIndex
Nenue@38 99 print(' |cFF'..self.internalColor..'GetNumWatched: limit selection to['..start..'-'..limit..']')
Nenue@37 100 if self.InfoBlock[targetID] then
Nenue@37 101 self.InfoBlock[targetID]:Hide()
Nenue@37 102 end
Nenue@28 103
Nenue@37 104 end
Nenue@34 105 end
Nenue@34 106
Nenue@37 107 for index = start, limit do
Nenue@37 108 if index > numWatched then
Nenue@37 109 self.WatchList[index] = nil
Nenue@37 110 print(' % dropping watch entry #'..index)
Nenue@37 111 else
Nenue@37 112 local cheevID = trackedList[index]
Nenue@37 113 if not self.Info[cheevID] then
Nenue@37 114 self.Info[cheevID] = self:GetInfo(cheevID, index)
Nenue@37 115 else
Nenue@38 116 print(' |cFF'..self.internalColor..'GetInfo:', cheevID, 'already pulled')
Nenue@37 117 end
Nenue@37 118 self:GetObjectives(cheevID)
Nenue@34 119
Nenue@37 120 local info = self.Info[cheevID]
Nenue@37 121 local watchBlock = self.WatchBlock[cheevID]
Nenue@37 122
Nenue@37 123 self.Info[cheevID].watchIndex = index
Nenue@37 124 self.WatchList[index] = info
Nenue@37 125 end
Nenue@37 126 end
Nenue@37 127
Nenue@37 128 numAll = #self.WatchList
Nenue@37 129 return numWatched, numAll, self.WatchList
Nenue@37 130 end
Nenue@37 131 Cheevs.GetInfo = function(self, cheevID, watchIndex)
Nenue@37 132 --- step 1: confirm primary data and begin an entry if needed
Nenue@37 133 local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID)
Nenue@37 134 if not id then return nil end
Nenue@37 135
Nenue@38 136 print(' |cFF'..self.internalColor..'GetInfo: pulling', id..',', name, earnedBy)
Nenue@37 137
Nenue@37 138
Nenue@37 139 self.Info[cheevID] = self.Info[cheevID] or {}
Nenue@37 140 local c = self.Info[cheevID]
Nenue@34 141 local rewards = {}
Nenue@34 142
Nenue@37 143 c.schema = 'achievement'
Nenue@34 144 c.rewardInfo = rewards
Nenue@29 145 c.type = 'Cheevs'
Nenue@34 146 c.title = name
Nenue@34 147 c.points = points
Nenue@34 148 c.completed = completed
Nenue@34 149 c.month = month
Nenue@34 150 c.day = day
Nenue@34 151 c.year = year
Nenue@34 152 c.description = description
Nenue@34 153 c.flags = flags
Nenue@34 154 c.icon = icon
Nenue@34 155 c.rewardText = rewardText
Nenue@34 156 c.isGuildAch = isGuildAch
Nenue@34 157 c.wasEarnedByMe = wasEarnedByMe
Nenue@34 158 c.earnedBy = earnedBy
Nenue@34 159
Nenue@37 160 local tagInfo = {}
Nenue@34 161 c.tagInfo = tagInfo
Nenue@34 162 c.watchIndex = watchIndex
Nenue@30 163 c.id = cheevID
Nenue@29 164 c.cheevID = cheevID
Nenue@37 165
Nenue@37 166 self.Info[cheevID] = c
Nenue@34 167 self.WatchInfo[watchIndex] = c
Nenue@37 168 return c
Nenue@37 169 end
Nenue@37 170
Nenue@37 171 Cheevs.GetObjectives = function(self, cheevID)
Nenue@37 172 local c = self.Info[cheevID]
Nenue@37 173 c.numObjectives = GetAchievementNumCriteria(cheevID)
Nenue@37 174 c.objectives = c.objectives or {}
Nenue@37 175 for i = 1, c.numObjectives do
Nenue@37 176 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i)
Nenue@37 177 local line = c.objectives[i] or {}
Nenue@37 178 line.objectiveIndex = i
Nenue@37 179 line.cheevID = cheevID
Nenue@37 180 line.text = description
Nenue@37 181 line.type = type
Nenue@37 182 line.finished = completed
Nenue@37 183 line.value = quantity
Nenue@37 184 line.maxValue = requiredQuantity
Nenue@37 185 line.characterName = characterName
Nenue@37 186 line.flags = flags
Nenue@37 187 line.assetID = assetID
Nenue@37 188 line.quantityString = quantityString
Nenue@37 189 line.criteriaID = criteriaID
Nenue@37 190 c.objectives[i] = line
Nenue@37 191
Nenue@38 192 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 193 end
Nenue@29 194 end
Nenue@29 195
Nenue@28 196
Nenue@30 197 Cheevs.Open = function(self, block)
Nenue@28 198
Nenue@30 199 if ( not _G.AchievementFrame ) then
Nenue@30 200 _G.AchievementFrame_LoadUI();
Nenue@28 201 end
Nenue@30 202 if ( not _G.AchievementFrame:IsShown() ) then
Nenue@30 203 _G.AchievementFrame_ToggleAchievementFrame();
Nenue@28 204 end
Nenue@30 205 _G.AchievementFrame_SelectAchievement(block.info.cheevID);
Nenue@28 206 end