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