comparison ObjectiveTracker/QuestTracker.lua @ 23:e837384ac363

Separating objective tracker module
author Nenue
date Sun, 10 Apr 2016 04:35:32 -0400
parents
children 66b927b46776
comparison
equal deleted inserted replaced
22:9b3fa734abff 23:e837384ac363
1 local B = select(2,...).frame
2 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
3 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band
4 local GetAutoQuestPopUp, GetQuestLogCompletionText = GetAutoQuestPopUp, GetQuestLogCompletionText
5 local Default, Quest = T.DefaultHandler, T.Quest
6 local format = format
7 local print = B.print('Tracker')
8 local lprint = B.print('Line')
9
10 local colors = T.colors
11 Quest.UpdateObjectives = function(handler, block)
12 local print = lprint
13 print('|cFF00FFFFUpdateObjectives()')
14 local info = block.info
15
16 local titlebg, textbg = colors.default.titlebg, colors.default.textbg
17 print((info.isAccount and 'isAccount' or ''), (info.isFaction and 'isFaction' or ''), (info.isDaily and 'isDaily' or ''), (info.isWeekly and 'isWeekly' or ''), info.tagID, info.tagName)
18
19 if info.isAccount then
20 if info.isFaction then
21 print(' faction', info.tagID)
22 titlebg, textbg = colors['faction_'..info.tagID].titlebg, colors.default.textbg
23 else
24 print(' account', info.isAccount, info.isFaction)
25 titlebg, textbg = colors.account.titlebg, colors.account.textbg
26 end
27 elseif info.isDaily then
28 print(' daily', info.frequency)
29 titlebg, textbg = colors.daily.titlebg, colors.daily.textbg
30 elseif info.isWeekly then
31 print(' weekly', info.frequency)
32 titlebg, textbg = colors.weekly.titlebg, colors.weekly.textbg
33 end
34
35 block.titlebg:SetGradientAlpha(unpack(titlebg))
36 block.statusbg:SetGradientAlpha(unpack(textbg))
37
38 local completionText
39 if info.isAutoComplete then
40 local questID, popupType = GetAutoQuestPopUp(info.questLogIndex)
41 if popupType == 'COMPLETE' then
42 print(' :: auto-complete quest :: set the message')
43 info.completionText = CLICK_TO_COMPLETE
44 end
45 end
46 if info.isComplete then
47 if not completionText or info.completionText then
48 info.completionText = GetQuestLogCompletionText(info.questLogIndex)
49 end
50 print(' :: complete quest :: show instruction: "'.. tostring(info.completionText) .. '"')
51 end
52
53 Default.UpdateObjectives(handler, block)
54 end
55
56 Quest.UpdateLine = function(handler, block, line, data)
57 local print = lprint
58 local objectiveType = data.type
59 local r, g, b, a = 0, 1, 1, 1
60
61 line.progress = 0
62 if data.finished then
63 line.progress = 2
64 r, g, b, a = 0, 1, 0, 1
65 elseif objectiveType == 'monster' then
66 r, g, b, a = 1, .55, .2, 1
67 elseif objectiveType == 'item' then
68 r, g, b, a = .8, .8, .8, 1
69 elseif objectiveType == 'object' then
70 r, g, b, a = 1, 1, 1, 1
71 elseif objectiveType == 'player' then
72 r, g, b, a = 0, 0.8, 1, 1
73 end
74 print(format(' |cFF%02X%02X%02X%0.1f, %0.1f, %0.1f|r', (r * 255), g * 255, b * 255, r, g, b))
75
76 line.displayColor = {r, g, b, a}
77 line.status:SetTextColor(r, g, b, a)
78 line.displayText = data.text
79
80 return line
81 end
82
83 -----------------------------
84 --- QUEST
85 Quest.itemButtons = {}
86 Quest.freeButtons = {}
87 Quest.POI = {}
88 Quest.QuestBlock = {}
89 Quest.LogBlock = {}
90 Quest.LogInfo = {}
91
92 function Quest:GetNumWatched ()
93 print(self.name, self)
94 self.numAll = GetNumQuestLogEntries()
95 self.numWatched = GetNumQuestWatches()
96 return self.numWatched, self.numAll
97 end
98 Quest.GetInfo = function (self, watchIndex)
99 print('|cFF00DDFFQuest|r.|cFF0088FFGetInfo(|r'.. tostring(watchIndex)..'|r)')
100 local questID, title, questIndex, numObjectives, requiredMoney, isComplete,
101 startEvent, isAutoComplete, failureTime, timeElapsed, questType, isTask, isStory, isOnMap, hasLocalPOI = GetQuestWatchInfo(watchIndex)
102
103 if not questIndex then
104 return
105 end
106
107 local _, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, _, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questIndex)
108
109
110 if not questID then
111 return
112 end
113 Quest.Info[questID] = Quest.Info[questID] or {}
114
115 local q = Quest.Info[questID]
116 q.watchIndex = watchIndex
117 q.type = 'Quest'
118 q.questID = questID
119 q.title = title
120 q.level = level
121 q.displayQuestID = displayQuestID
122 q.suggestedGroup = suggestedGroup
123 q.questLogIndex = questIndex
124 q.numObjectives = numObjectives
125 q.requiredMoney = requiredMoney
126 q.isComplete = isComplete
127 q.startEvent = startEvent
128 q.isAutoComplete = isAutoComplete
129 q.failureTime = failureTime
130 q.timeElapsed = timeElapsed
131 q.questType = questType
132 q.isTask = isTask
133 q.isStory = isStory
134 q.isOnMap = isOnMap
135 q.hasLocalPOI = hasLocalPOI
136 q.frequency = frequency
137 q.isComplete = isComplete
138 q.isStory = isStory
139 q.isTask = isTask
140
141 --- resolve icon type and template
142 local questTagID, tagName = GetQuestTagInfo(questID)
143 local tagID
144
145 local factionGroup = GetQuestFactionGroup(questID);
146 if( questTagID and questTagID == QUEST_TAG_ACCOUNT ) then
147 if( factionGroup ) then
148 tagID = "ALLIANCE";
149 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
150 tagID = "HORDE";
151 end
152 q.isFaction = true
153 else
154 tagID = QUEST_TAG_ACCOUNT;
155 q.isAccount = true
156 end
157 q.typeTag = QUEST_TAG_TCOORDS[tagID]
158 elseif ( factionGroup) then
159 tagID = "ALLIANCE";
160 if ( factionGroup == LE_QUEST_FACTION_HORDE ) then
161 tagID = "HORDE";
162 end
163 q.isFaction = true
164 end
165
166 if( frequency == LE_QUEST_FREQUENCY_DAILY and (not isComplete or isComplete == 0) ) then
167 tagID = "DAILY";
168 q.frequencyTag = QUEST_TAG_TCOORDS["DAILY"]
169 q.isDaily = true
170 elseif( frequency == LE_QUEST_FREQUENCY_WEEKLY and (not isComplete or isComplete == 0) )then
171 tagID = "WEEKLY";
172 q.frequencyTag = QUEST_TAG_TCOORDS["WEEKLY"]
173 q.isWeekly = true
174 elseif( questTagID ) then
175 tagID = questTagID;
176 end
177
178 if ( isComplete and isComplete < 0 ) then
179 q.completionTag = QUEST_TAG_TCOORDS["FAILED"]
180 q.isFailed = true
181 elseif isComplete then
182 q.completionTag = QUEST_TAG_TCOORDS["COMPLETED"]
183 end
184
185
186 q.tagID = questTagID
187 q.tagName = tagName
188
189
190
191 --q.isBreadCrumb = isBreadCrumb
192 q.completionText= GetQuestLogCompletionText(questIndex)
193 q.numObjectives = GetNumQuestLeaderBoards(questIndex)
194 q.objectives = {}
195 for i = 1, q.numObjectives do
196 local text, type, finished = GetQuestLogLeaderBoard(i, questIndex)
197 print(format(' #%d %s %s %s', i, tostring(type), tostring(text), tostring(finished)))
198 q.objectives[i] = {
199 index = i,
200 type = type,
201 text = text,
202 finished = finished
203 }
204 if type == 'event' then
205 elseif type == 'monster' then
206 elseif type == 'object' then
207 elseif type == 'reputation' then
208 elseif type == 'item' then
209 end
210 end
211
212 if requiredMoney >= 1 then
213 local money = GetMoney()
214 local moneyText = money
215 local requiredSilver, requiredCopper
216 local requiredGold = (requiredMoney > 10000) and (floor(requiredMoney/10000)) or nil
217 if mod(requiredMoney, 10000) ~= 0 then
218 requiredSilver = (requiredMoney > 100) and (mod(requiredMoney, 10000) / 100) or nil
219 if mod(requiredMoney, 100) ~= 0 then
220 requiredCopper = mod(requiredMoney, 100)
221 end
222 end
223
224 -- round the money value down
225 if requiredMoney > 9999 and not (requiredSilver or requiredCopper) then
226 moneyText = floor(money/10000)
227 elseif requiredMoney < 10000 and mod(requiredMoney,100) == 0 then
228 moneyText = floor(money/100)
229 end
230
231 local text = moneyText
232 local index = #q.objectives + 1
233 local finished = (GetMoney() >= requiredMoney)
234
235 if not finished then
236 text = text .. ' / ' .. GetCoinTextureString(requiredMoney, 12)
237 else
238 text = '' .. GetCoinTextureString(requiredMoney, 12)
239 end
240 q.objectives[index] = {
241 index = index,
242 type = 'progressbar',
243 quantity = money,
244 requiredQuantity = requiredMoney,
245 text = text,
246 finished = finished
247 }
248 print(format(' #%d %s %s %s', index, 'money', text, tostring(finished)))
249 end
250
251
252 local link, icon, charges = GetQuestLogSpecialItemInfo(questIndex)
253 local start, duration, enable = GetQuestLogSpecialItemCooldown(questIndex)
254 if link or icon or charges then
255 q.specialItem = {
256 questID = questID,
257 questIndex = questIndex,
258 link = link,
259 charges = charges,
260 icon = icon,
261 start = start,
262 duration = duration,
263 enable = enable,
264 }
265 end
266
267 if QuestHasPOIInfo(questID) then
268 local distance, onContinent = GetDistanceSqToQuest(questIndex)
269 if distance ~= nil and distance > 0 then
270 self.POI[questIndex] = {
271 questIndex = questIndex,
272 questID = questID,
273 distance = distance,
274 onContinent = onContinent
275 }
276 end
277 end
278
279
280 q.selected = (questID == GetSuperTrackedQuestID()) -- call directly so artifact data doesn't become an issue
281 self.WatchInfo[watchIndex] = q
282 self.LogInfo[questIndex] = q
283 print('- logIndex =', questIndex, 'title =', title)
284 return q
285 end
286
287 Quest.GetClosest = function()
288 local minID, minTitle
289 local minDist = math.huge
290 local numQuests = GetNumQuestLogEntries()
291 for questIndex = 1, numQuests do
292 local distance, onContinent = GetDistanceSqToQuest(questIndex)
293 local title, level, _, _, _, _, _, _, questID = GetQuestLogTitle(questIndex)
294 if onContinent and distance < minDist then
295 minDist = distance
296 minTitle = title
297 minID = questID
298 end
299 end
300
301 print('nearest quest is', minTitle, 'by', math.sqrt(minDist))
302 return minID, minTitle, minDist
303 end
304
305 Quest.OnTurnIn = function(self, questID, xp, money)
306
307 end