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