comparison ObjectiveCore.lua @ 22:9b3fa734abff

ObjectiveFrame - polish quest rewards display - implement money objectives - set line metrics in UpdateLine - set block metrics in UpdateBlock (sum of line metrics)
author Nenue
date Sat, 09 Apr 2016 07:32:45 -0400
parents d5ee940de273
children
comparison
equal deleted inserted replaced
21:d5ee940de273 22:9b3fa734abff
2 -- @file-author@ 2 -- @file-author@
3 -- @project-revision@ @project-hash@ 3 -- @project-revision@ @project-hash@
4 -- @file-revision@ @file-hash@ 4 -- @file-revision@ @file-hash@
5 -- Created: 3/26/2016 1:51 AM 5 -- Created: 3/26/2016 1:51 AM
6 local B, _G = select(2,...).frame, _G 6 local B, _G = select(2,...).frame, _G
7 local pairs, setmetatable, type, tostring = _G.pairs, _G.setmetatable, _G.type, _G.tostring 7 local pairs, setmetatable, type, tostring, band, format = _G.pairs, _G.setmetatable, _G.type, _G.tostring, bit.band, string.format
8 local format = _G.format 8 local ipairs, tinsert, hooksecurefunc = _G.ipairs, _G.tinsert, _G.hooksecurefunc
9 local PlaySoundFile, IsQuestTask, SortQuestWatches, GetCurrentMapAreaID, GetZoneText, GetMinimapZoneText = PlaySoundFile, IsQuestTask, SortQuestWatches, GetCurrentMapAreaID, GetZoneText, GetMinimapZoneText
10 local AddQuestWatch, SetSuperTrackedQuestID, GetNumQuestWatches, AUTO_QUEST_WATCH, MAX_WATCHABLE_QUESTS = AddQuestWatch, SetSuperTrackedQuestID, GetNumQuestWatches, AUTO_QUEST_WATCH, MAX_WATCHABLE_QUESTS
11 local QuestPOIUpdateIcons, GetCVar, IsPlayerInMicroDungeon, WorldMapFrame, GetCVarBool, SetMapToCurrentZone = QuestPOIUpdateIcons, GetCVar, IsPlayerInMicroDungeon, WorldMapFrame, GetCVarBool, SetMapToCurrentZone
12 local AddAutoQuestPopUp = AddAutoQuestPopUp
9 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') 13 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
10 local print = B.print('Objectives') 14 local print = B.print('Objectives')
11 local ObjectiveTrackerFrame, VeneerObjectiveScroll, CreateFrame = _G.ObjectiveTrackerFrame, _G.VeneerObjectiveScroll, _G.CreateFrame 15 local ObjectiveTrackerFrame, VeneerObjectiveScroll, CreateFrame = _G.ObjectiveTrackerFrame, _G.VeneerObjectiveScroll, _G.CreateFrame
12 local Wrapper = _G.VeneerObjectiveWrapper 16 local Wrapper = _G.VeneerObjectiveWrapper
13 local ipairs, tinsert, hooksecurefunc = _G.ipairs, _G.tinsert, _G.hooksecurefunc
14 local Scroller = VeneerObjectiveWrapper.scrollArea 17 local Scroller = VeneerObjectiveWrapper.scrollArea
15 local Scroll = _G.VeneerObjectiveScroll 18 local Scroll = _G.VeneerObjectiveScroll
16 19
17 --- Performance values 20 --- Performance values
18 --[[ 21 --[[
140 } 143 }
141 mod.Bonus = { 144 mod.Bonus = {
142 name = "Bonus", 145 name = "Bonus",
143 displayName = "Bonus Objectives", 146 displayName = "Bonus Objectives",
144 updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE, 147 updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE,
145 updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_QUEST + 148 updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_QUEST + OBJECTIVE_TRACKER_UPDATE_TASK_ADDED
146 OBJECTIVE_TRACKER_UPDATE_TASK_ADDED +
147 OBJECTIVE_TRACKER_UPDATE_SCENARIO +
148 OBJECTIVE_TRACKER_UPDATE_SCENARIO_NEW_STAGE +
149 OBJECTIVE_TRACKER_UPDATE_SCENARIO_BONUS_DELAYED
150 } 149 }
151 150
152 local Tracker_string = function (self) 151 local Tracker_string = function (self)
153 return self.name 152 return self.name
154 end 153 end
207 206
208 mod.orderedHandlers[index] = handler 207 mod.orderedHandlers[index] = handler
209 return true 208 return true
210 end 209 end
211 210
212 211 local Event = {}
213 function mod:OnEvent (event, ...) 212 Event.QUEST_LOG_UPDATE = function()
214 local isHandled 213 return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST + OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE
215 print('OnEvent(|cFF00FF00'.. event ..'|r):', ...) 214 end
216 if ( event == "QUEST_LOG_UPDATE" ) then 215 Event.QUEST_ACCEPTED = function(questLogIndex, questID)
217 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST); 216 if ( IsQuestTask(questID) ) then
218 217 return OBJECTIVE_TRACKER_UPDATE_TASK_ADDED, questID
219 elseif ( event == "TRACKED_ACHIEVEMENT_UPDATE" ) then 218 else
220 --AchievementObjectiveTracker_OnAchievementUpdate(...); 219 if ( AUTO_QUEST_WATCH == "1" and GetNumQuestWatches() < MAX_WATCHABLE_QUESTS ) then
221 mod.Cheevs:Update(OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT) 220 AddQuestWatch(questLogIndex);
222 221 SetSuperTrackedQuestID(questID);
223 elseif ( event == "QUEST_ACCEPTED" ) then 222 end
224 local questLogIndex, questID = ...; 223 return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST
225 if ( IsQuestTask(questID) ) then 224 end
226 mod:Update(OBJECTIVE_TRACKER_UPDATE_TASK_ADDED, questID); 225 end
227 else 226 Event.QUEST_WATCH_LIST_CHANGED = function(questID, added)
228 if ( AUTO_QUEST_WATCH == "1" and GetNumQuestWatches() < MAX_WATCHABLE_QUESTS ) then 227 if ( added ) then
229 AddQuestWatch(questLogIndex); 228 if ( not IsQuestTask(questID) ) then
230 SetSuperTrackedQuestID(questID); 229 return OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added
231 end 230 end
232 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST) 231 else
233 end 232 return OBJECTIVE_TRACKER_UPDATE_QUEST, questID, added
234 233 end
235 elseif ( event == "TRACKED_ACHIEVEMENT_LIST_CHANGED" ) then 234 end
236 local achievementID, added = ...; 235 Event.QUEST_POI_UPDATE = function()
237 if ( added ) then 236
238 mod:Update(OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED, achievementID); 237 QuestPOIUpdateIcons();
239 else 238 if ( GetCVar("trackQuestSorting") == "proximity" ) then
240 mod:Update(OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT); 239 SortQuestWatches();
241 end 240 end
242 241
243 elseif ( event == "QUEST_WATCH_LIST_CHANGED" ) then 242 return OBJECTIVE_TRACKER_UPDATE_ALL
244 local questID, added = ...; 243
245 if ( added ) then 244 end
246 if ( not IsQuestTask(questID) ) then 245 Event.SUPER_TRACKED_QUEST_CHANGED = function()
247 mod:Update(OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added); 246 return OBJECTIVE_TRACKER_UPDATE_QUEST
248 end 247 end
249 else 248 Event.ZONE_CHANGED = function()
250 mod:Update(OBJECTIVE_TRACKER_UPDATE_QUEST, questID, added); 249
251 end 250 local inMicroDungeon = IsPlayerInMicroDungeon();
252 251 if ( inMicroDungeon ~= mod.inMicroDungeon ) then
253 elseif ( event == "QUEST_POI_UPDATE" ) then
254 QuestPOIUpdateIcons();
255 if ( GetCVar("trackQuestSorting") == "proximity" ) then
256 SortQuestWatches();
257 end
258
259 mod:Update(OBJECTIVE_TRACKER_UPDATE_ALL);
260
261 elseif ( event == "SCENARIO_CRITERIA_UPDATE" ) then
262 mod:Update(OBJECTIVE_TRACKER_UPDATE_SCENARIO);
263 elseif ( event == "SUPER_TRACKED_QUEST_CHANGED" ) then
264 --mod:Update(OBJECTIVE_TRACKER_UPDATE_QUEST)
265 elseif ( event == "ZONE_CHANGED" ) then
266 local inMicroDungeon = IsPlayerInMicroDungeon();
267 if ( inMicroDungeon ~= self.inMicroDungeon ) then
268 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
269 SetMapToCurrentZone(); -- update the zone to get the right POI numbers for the tracker
270 end
271 --SortQuestWatches();
272 self.inMicroDungeon = inMicroDungeon;
273 end
274 elseif ( event == "QUEST_AUTOCOMPLETE" ) then
275 local questId = ...;
276 AddAutoQuestPopUp(questId, "COMPLETE");
277 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST)
278 elseif ( event == "SCENARIO_UPDATE" ) then
279 local newStage = ...;
280 if ( newStage ) then
281 mod:Update(OBJECTIVE_TRACKER_UPDATE_SCENARIO_NEW_STAGE);
282 else
283 mod:Update(OBJECTIVE_TRACKER_UPDATE_SCENARIO);
284 end
285 elseif ( event == "ZONE_CHANGED_NEW_AREA" ) then
286 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then 252 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
287 SetMapToCurrentZone(); -- update the zone to get the right POI numbers for the tracker 253 SetMapToCurrentZone(); -- update the zone to get the right POI numbers for the tracker
288 end 254 end
289 SortQuestWatches(); 255 --SortQuestWatches();
290 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE) 256 mod.inMicroDungeon = inMicroDungeon;
291 elseif (event == 'CRITERIA_COMPLETE') then 257 end
292 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE) 258 end
293 259 Event.QUEST_AUTOCOMPLETE = function(questId)
294 elseif ( event == "QUEST_TURNED_IN" ) then 260 AddAutoQuestPopUp(questId, "COMPLETE");
295 local questID, xp, money = ...; 261 return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST + OBJECTIVE_TRACKER_UPDATE_MODULE_AUTO_QUEST_POPUP
296 if ( IsQuestTask(questID) ) then 262 end
297 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE) 263 Event.SCENARIO_CRITERIA_UPDATE = function()
298 else 264 return OBJECTIVE_TRACKER_UPDATE_SCENARIO
299 265 end
300 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST) 266 Event.SCENARIO_UPDATE = function(newStage)
301 end 267 if ( newStage ) then
302 elseif ( event == "PLAYER_MONEY" and self.watchMoneyReasons > 0 ) then 268 return OBJECTIVE_TRACKER_UPDATE_SCENARIO_NEW_STAGE
303 -- only update trackers that have money counters 269 else
304 mod:Update(self.watchMoneyReasons); 270 return OBJECTIVE_TRACKER_UPDATE_SCENARIO
305 end 271 end
306 end 272 end
273 Event.TRACKED_ACHIEVEMENT_UPDATE = function()
274 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT
275 end
276 Event.TRACKED_ACHIEVEMENT_LIST_CHANGED = function(achievementID, added)
277 if ( added ) then
278 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED, achievementID
279 else
280 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT
281 end
282 end
283 Event.ZONE_CHANGED_NEW_AREA = function ()
284 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
285 SetMapToCurrentZone(); -- update the zone to get the right POI numbers for the tracker
286 end
287 SortQuestWatches();
288 mod.currentZoneArea = GetCurrentMapAreaID()
289 print('Updating zone ID to', mod.currentZoneArea, '=', GetZoneText(), GetMinimapZoneText())
290
291
292 return OBJECTIVE_TRACKER_UPDATE_TASK_ADDED
293 end
294
295
296 Event.PLAYER_MONEY = function()
297 if mod.watchMoneyReasons > 0 then
298 return mod.watchMoneyReasons
299 end
300 end
301 Event.CRITERIA_COMPLETE = function()
302 return OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE
303 end
304 Event.QUEST_TURN_IN = function(questID, xp, money)
305 if ( IsQuestTask(questID) ) then
306 mod.Bonus:OnTurnIn(questID, xp, money)
307 print('updating bonus modules (code', OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE, ',', questID, xp, money)
308 return OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE, questID, xp, money
309 else
310 return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST, questID, xp, money
311 end
312 end
313 mod.Event = Event
307 314
308 --- Done once per ui load 315 --- Done once per ui load
309 local BlizzHooks = { 316 local BlizzHooks = {
310 ['AddQuestWatch'] = 'AddQuestWatch', 317 ['AddQuestWatch'] = 'AddQuestWatch',
311 ['RemoveQuestWatch'] = 'RemoveQuestWatch', 318 ['RemoveQuestWatch'] = 'RemoveQuestWatch',
316 ['AddTrackedAchievement'] = 'AddTrackedAchievement', 323 ['AddTrackedAchievement'] = 'AddTrackedAchievement',
317 ['RemoveTrackedAchievement'] = 'RemoveTrackedAchievement', 324 ['RemoveTrackedAchievement'] = 'RemoveTrackedAchievement',
318 ['SetSuperTrackedQuestID'] = 'SetSuperTrackedQuestID' 325 ['SetSuperTrackedQuestID'] = 'SetSuperTrackedQuestID'
319 } 326 }
320 local VeneerData 327 local VeneerData
328
329 mod.SetWatchMoney = function(watchMoney, reason)
330 if watchMoney then
331 if band(mod.watchMoneyReasons, reason) == 0 then
332 mod.watchMoneyReasons = mod.watchMoneyReasons + reason;
333 end
334 else
335 if band(mod.watchMoneyReasons, reason) > 0 then
336 mod.watchMoneyReasons = mod.watchMoneyReasons - reason;
337 end
338 end
339 end
340
341
321 function mod:OnInitialize() 342 function mod:OnInitialize()
322 local c = mod.Conf.Wrapper 343 local c = mod.Conf.Wrapper
323 VeneerData = _G.VeneerData 344 VeneerData = _G.VeneerData
324 VeneerData.CallLog = VeneerData.CallLog or {} 345 VeneerData.CallLog = VeneerData.CallLog or {}
325 if not mod.isHooked then 346 if not mod.isHooked then
333 tinsert(VeneerData.CallLog, {blizzFunc, ...}) 354 tinsert(VeneerData.CallLog, {blizzFunc, ...})
334 end) 355 end)
335 end 356 end
336 end 357 end
337 end 358 end
359
360 mod.Conf.TasksLog = mod.Conf.TasksLog or {}
361
338 Scroller:SetScrollChild(Scroll) 362 Scroller:SetScrollChild(Scroll)
339 Scroller:SetWidth(c.Width) 363 Scroller:SetWidth(c.Width)
340 Scroll:SetWidth(c.Width) 364 Scroll:SetWidth(c.Width)
341 Scroll:ClearAllPoints() 365 Scroll:ClearAllPoints()
342 Scroll:SetPoint('TOP', Scroller, 'TOP') 366 Scroll:SetPoint('TOP', Scroller, 'TOP')
343 ObjectiveTrackerFrame:UnregisterAllEvents() 367 ObjectiveTrackerFrame:UnregisterAllEvents()
344 ObjectiveTrackerFrame:Hide() 368 ObjectiveTrackerFrame:Hide()
345 end 369 end
346 370
371 function mod:OnEvent (event, ...)
372 local isHandled
373 print('OnEvent(|cFF00FF00'.. event ..'|r):', ...)
374 local reason, arg1, arg2, arg3
375 if Event[event] then
376 if type(Event[event]) == 'function' then
377 PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Info.ogg]])
378 reason, arg1, arg2, arg3 = Event[event](...)
379 elseif type(Event[event]) == 'table' then
380 PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Link.ogg]])
381 for i, action in ipairs(Event[event]) do
382 if type(action) == 'function' then
383 reason, arg1, arg2, arg3 = action(event, ...)
384 else
385 reason = action
386 end
387
388 if reason then
389 mod:Update(reason, arg1, arg2, arg3)
390 end
391 end
392 else
393 PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Heart.ogg]])
394 reason = Event[event]
395 end
396 else
397 PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Quack.ogg]])
398 end
399 if reason then
400 mod:Update(reason, arg1, arg2, arg3)
401 else
402 print('no reason value returned')
403 PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Quack.ogg]])
404 end
405 end
406
347 --- Done any time the the minimize button is toggled up 407 --- Done any time the the minimize button is toggled up
348
349
350 function mod:OnEnable() 408 function mod:OnEnable()
351 for id, name in ipairs(mod.orderedNames) do 409 for id, name in ipairs(mod.orderedNames) do
352 if not mod.orderedHandlers[id] then 410 if not mod.orderedHandlers[id] then
353 Handler_Initialize(mod.DefaultHandler, name, id) 411 Handler_Initialize(mod.DefaultHandler, name, id)
354 end 412 end
355 end 413 end
356 414
357 Wrapper:RegisterEvent("CRITERIA_COMPLETE"); 415 for event, action in pairs(Event) do
358 Wrapper:RegisterEvent("SCENARIO_UPDATE"); 416 print('|cFFFF0088listen to', event, 'for action|r', tostring(action))
359 Wrapper:RegisterEvent("SCENARIO_CRITERIA_UPDATE"); 417 Wrapper:RegisterEvent(event)
360 Wrapper:RegisterEvent("PLAYER_MONEY"); 418 end
361 Wrapper:RegisterEvent("QUEST_ACCEPTED"); 419
362 Wrapper:RegisterEvent("QUEST_AUTOCOMPLETE");
363 Wrapper:RegisterEvent("QUEST_LOG_UPDATE");
364 Wrapper:RegisterEvent("QUEST_POI_UPDATE");
365 Wrapper:RegisterEvent("QUEST_TURNED_IN");
366 Wrapper:RegisterEvent("QUEST_WATCH_LIST_CHANGED");
367 Wrapper:RegisterEvent("SUPER_TRACKED_QUEST_CHANGED");
368 Wrapper:RegisterEvent("TRACKED_ACHIEVEMENT_LIST_CHANGED");
369 Wrapper:RegisterEvent("TRACKED_ACHIEVEMENT_UPDATE");
370 Wrapper:RegisterEvent("VARIABLES_LOADED");
371 Wrapper:RegisterEvent("ZONE_CHANGED_NEW_AREA");
372 Wrapper:RegisterEvent("ZONE_CHANGED");
373 Wrapper:SetScript('OnEvent', mod.OnEvent) 420 Wrapper:SetScript('OnEvent', mod.OnEvent)
374 421
375 local c = mod.Conf.Wrapper 422 local c = mod.Conf.Wrapper
376 --Wrapper:SetPoint(c.AnchorPoint, UIParent, c.AnchorPoint, c.OffsetX, c.OffsetY) 423 --Wrapper:SetPoint(c.AnchorPoint, UIParent, c.AnchorPoint, c.OffsetX, c.OffsetY)
377 --B.Conf.FramePosition[Wrapper:GetName()] = {c.AnchorPoint, c.AnchorPoint, c.OffsetX, c.OffsetY} 424 --B.Conf.FramePosition[Wrapper:GetName()] = {c.AnchorPoint, c.AnchorPoint, c.OffsetX, c.OffsetY}
381 mod.InitializeWidgets() 428 mod.InitializeWidgets()
382 mod:Update() 429 mod:Update()
383 end 430 end
384 431
385 function mod:OnDisable() 432 function mod:OnDisable()
386 433 Wrapper:UnregisterAllEvents()
387 end 434 end
388 435
389 436