diff 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
line wrap: on
line diff
--- a/ObjectiveCore.lua	Fri Apr 08 06:12:05 2016 -0400
+++ b/ObjectiveCore.lua	Sat Apr 09 07:32:45 2016 -0400
@@ -4,13 +4,16 @@
 -- @file-revision@ @file-hash@
 -- Created: 3/26/2016 1:51 AM
 local B, _G = select(2,...).frame, _G
-local pairs, setmetatable, type, tostring = _G.pairs, _G.setmetatable, _G.type, _G.tostring
-local format = _G.format
+local pairs, setmetatable, type, tostring, band, format = _G.pairs, _G.setmetatable, _G.type, _G.tostring, bit.band, string.format
+local ipairs, tinsert, hooksecurefunc = _G.ipairs, _G.tinsert, _G.hooksecurefunc
+local PlaySoundFile, IsQuestTask, SortQuestWatches, GetCurrentMapAreaID, GetZoneText, GetMinimapZoneText = PlaySoundFile, IsQuestTask, SortQuestWatches, GetCurrentMapAreaID, GetZoneText, GetMinimapZoneText
+local AddQuestWatch, SetSuperTrackedQuestID, GetNumQuestWatches, AUTO_QUEST_WATCH, MAX_WATCHABLE_QUESTS = AddQuestWatch, SetSuperTrackedQuestID, GetNumQuestWatches, AUTO_QUEST_WATCH, MAX_WATCHABLE_QUESTS
+local QuestPOIUpdateIcons, GetCVar, IsPlayerInMicroDungeon, WorldMapFrame, GetCVarBool, SetMapToCurrentZone = QuestPOIUpdateIcons, GetCVar, IsPlayerInMicroDungeon, WorldMapFrame, GetCVarBool, SetMapToCurrentZone
+local AddAutoQuestPopUp = AddAutoQuestPopUp
 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
 local print = B.print('Objectives')
 local ObjectiveTrackerFrame, VeneerObjectiveScroll, CreateFrame = _G.ObjectiveTrackerFrame, _G.VeneerObjectiveScroll, _G.CreateFrame
 local Wrapper = _G.VeneerObjectiveWrapper
-local ipairs, tinsert, hooksecurefunc = _G.ipairs, _G.tinsert, _G.hooksecurefunc
 local Scroller = VeneerObjectiveWrapper.scrollArea
 local Scroll = _G.VeneerObjectiveScroll
 
@@ -142,11 +145,7 @@
   name = "Bonus",
   displayName = "Bonus Objectives",
   updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE,
-  updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_QUEST +
-        OBJECTIVE_TRACKER_UPDATE_TASK_ADDED +
-        OBJECTIVE_TRACKER_UPDATE_SCENARIO +
-        OBJECTIVE_TRACKER_UPDATE_SCENARIO_NEW_STAGE +
-        OBJECTIVE_TRACKER_UPDATE_SCENARIO_BONUS_DELAYED
+  updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_QUEST + OBJECTIVE_TRACKER_UPDATE_TASK_ADDED
 }
 
 local Tracker_string = function (self)
@@ -209,101 +208,109 @@
   return true
 end
 
+local Event = {}
+Event.QUEST_LOG_UPDATE =  function()
+  return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST + OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE
+end
+Event.QUEST_ACCEPTED = function(questLogIndex, questID)
+  if ( IsQuestTask(questID) ) then
+    return OBJECTIVE_TRACKER_UPDATE_TASK_ADDED, questID
+  else
+    if ( AUTO_QUEST_WATCH == "1" and GetNumQuestWatches() < MAX_WATCHABLE_QUESTS ) then
+      AddQuestWatch(questLogIndex);
+      SetSuperTrackedQuestID(questID);
+    end
+    return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST
+  end
+end
+Event.QUEST_WATCH_LIST_CHANGED = function(questID, added)
+  if ( added ) then
+    if ( not IsQuestTask(questID) ) then
+      return OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added
+    end
+  else
+    return OBJECTIVE_TRACKER_UPDATE_QUEST, questID, added
+  end
+end
+Event.QUEST_POI_UPDATE = function()
 
-function mod:OnEvent (event, ...)
-  local isHandled
-  print('OnEvent(|cFF00FF00'.. event ..'|r):', ...)
-  if ( event == "QUEST_LOG_UPDATE" ) then
-    mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST);
+  QuestPOIUpdateIcons();
+  if ( GetCVar("trackQuestSorting") == "proximity" ) then
+    SortQuestWatches();
+  end
 
-  elseif ( event == "TRACKED_ACHIEVEMENT_UPDATE" ) then
-    --AchievementObjectiveTracker_OnAchievementUpdate(...);
-    mod.Cheevs:Update(OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT)
+  return OBJECTIVE_TRACKER_UPDATE_ALL
 
-  elseif ( event == "QUEST_ACCEPTED" ) then
-    local questLogIndex, questID = ...;
-    if ( IsQuestTask(questID) ) then
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_TASK_ADDED, questID);
-    else
-      if ( AUTO_QUEST_WATCH == "1" and GetNumQuestWatches() < MAX_WATCHABLE_QUESTS ) then
-        AddQuestWatch(questLogIndex);
-        SetSuperTrackedQuestID(questID);
-      end
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST)
-    end
+end
+Event.SUPER_TRACKED_QUEST_CHANGED = function()
+  return OBJECTIVE_TRACKER_UPDATE_QUEST
+end
+Event.ZONE_CHANGED = function()
 
-  elseif ( event == "TRACKED_ACHIEVEMENT_LIST_CHANGED" ) then
-    local achievementID, added = ...;
-    if ( added ) then
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED, achievementID);
-    else
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT);
-    end
-
-  elseif ( event == "QUEST_WATCH_LIST_CHANGED" ) then
-    local questID, added = ...;
-    if ( added ) then
-      if ( not IsQuestTask(questID) ) then
-        mod:Update(OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added);
-      end
-    else
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_QUEST, questID, added);
-    end
-
-  elseif ( event == "QUEST_POI_UPDATE" ) then
-    QuestPOIUpdateIcons();
-    if ( GetCVar("trackQuestSorting") == "proximity" ) then
-      SortQuestWatches();
-    end
-
-    mod:Update(OBJECTIVE_TRACKER_UPDATE_ALL);
-
-  elseif ( event == "SCENARIO_CRITERIA_UPDATE" ) then
-    mod:Update(OBJECTIVE_TRACKER_UPDATE_SCENARIO);
-  elseif ( event == "SUPER_TRACKED_QUEST_CHANGED" ) then
-    --mod:Update(OBJECTIVE_TRACKER_UPDATE_QUEST)
-  elseif ( event == "ZONE_CHANGED" ) then
-    local inMicroDungeon = IsPlayerInMicroDungeon();
-    if ( inMicroDungeon ~= self.inMicroDungeon ) then
-      if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
-        SetMapToCurrentZone();			-- update the zone to get the right POI numbers for the tracker
-      end
-      --SortQuestWatches();
-      self.inMicroDungeon = inMicroDungeon;
-    end
-  elseif ( event == "QUEST_AUTOCOMPLETE" ) then
-    local questId = ...;
-    AddAutoQuestPopUp(questId, "COMPLETE");
-    mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST)
-  elseif ( event == "SCENARIO_UPDATE" ) then
-    local newStage = ...;
-    if ( newStage ) then
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_SCENARIO_NEW_STAGE);
-    else
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_SCENARIO);
-    end
-  elseif ( event == "ZONE_CHANGED_NEW_AREA" ) then
+  local inMicroDungeon = IsPlayerInMicroDungeon();
+  if ( inMicroDungeon ~= mod.inMicroDungeon ) then
     if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
       SetMapToCurrentZone();			-- update the zone to get the right POI numbers for the tracker
     end
-    SortQuestWatches();
-    mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE)
-  elseif (event == 'CRITERIA_COMPLETE') then
-    mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE)
-
-  elseif ( event == "QUEST_TURNED_IN" ) then
-    local questID, xp, money = ...;
-    if ( IsQuestTask(questID) ) then
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE)
-    else
-
-      mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST)
-    end
-  elseif ( event == "PLAYER_MONEY" and self.watchMoneyReasons > 0 ) then
-    -- only update trackers that have money counters
-    mod:Update(self.watchMoneyReasons);
+    --SortQuestWatches();
+    mod.inMicroDungeon = inMicroDungeon;
   end
 end
+Event.QUEST_AUTOCOMPLETE = function(questId)
+  AddAutoQuestPopUp(questId, "COMPLETE");
+  return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST + OBJECTIVE_TRACKER_UPDATE_MODULE_AUTO_QUEST_POPUP
+end
+Event.SCENARIO_CRITERIA_UPDATE =  function()
+  return OBJECTIVE_TRACKER_UPDATE_SCENARIO
+end
+Event.SCENARIO_UPDATE = function(newStage)
+  if ( newStage ) then
+    return OBJECTIVE_TRACKER_UPDATE_SCENARIO_NEW_STAGE
+  else
+    return OBJECTIVE_TRACKER_UPDATE_SCENARIO
+  end
+end
+Event.TRACKED_ACHIEVEMENT_UPDATE = function()
+  return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT
+end
+Event.TRACKED_ACHIEVEMENT_LIST_CHANGED = function(achievementID, added)
+  if ( added ) then
+    return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED, achievementID
+  else
+    return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT
+  end
+end
+Event.ZONE_CHANGED_NEW_AREA = function ()
+  if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
+    SetMapToCurrentZone();			-- update the zone to get the right POI numbers for the tracker
+  end
+  SortQuestWatches();
+  mod.currentZoneArea = GetCurrentMapAreaID()
+  print('Updating zone ID to', mod.currentZoneArea, '=', GetZoneText(), GetMinimapZoneText())
+
+
+  return OBJECTIVE_TRACKER_UPDATE_TASK_ADDED
+end
+
+
+Event.PLAYER_MONEY = function()
+  if mod.watchMoneyReasons > 0 then
+    return mod.watchMoneyReasons
+  end
+end
+Event.CRITERIA_COMPLETE = function()
+  return OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE
+end
+Event.QUEST_TURN_IN = function(questID, xp, money)
+  if ( IsQuestTask(questID) ) then
+    mod.Bonus:OnTurnIn(questID, xp, money)
+    print('updating bonus modules (code', OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE, ',', questID, xp, money)
+    return OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE, questID, xp, money
+  else
+    return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST, questID, xp, money
+  end
+end
+mod.Event = Event
 
 --- Done once per ui load
 local BlizzHooks = {
@@ -318,6 +325,20 @@
   ['SetSuperTrackedQuestID'] = 'SetSuperTrackedQuestID'
 }
 local VeneerData
+
+mod.SetWatchMoney = function(watchMoney, reason)
+  if watchMoney then
+    if band(mod.watchMoneyReasons, reason) == 0 then
+      mod.watchMoneyReasons = mod.watchMoneyReasons + reason;
+    end
+  else
+    if band(mod.watchMoneyReasons, reason) > 0 then
+      mod.watchMoneyReasons = mod.watchMoneyReasons - reason;
+    end
+  end
+end
+
+
 function mod:OnInitialize()
   local c = mod.Conf.Wrapper
   VeneerData = _G.VeneerData
@@ -335,6 +356,9 @@
       end
     end
   end
+
+  mod.Conf.TasksLog = mod.Conf.TasksLog or {}
+
   Scroller:SetScrollChild(Scroll)
   Scroller:SetWidth(c.Width)
   Scroll:SetWidth(c.Width)
@@ -344,9 +368,43 @@
   ObjectiveTrackerFrame:Hide()
 end
 
+function mod:OnEvent (event, ...)
+  local isHandled
+  print('OnEvent(|cFF00FF00'.. event ..'|r):', ...)
+  local reason, arg1, arg2, arg3
+  if Event[event] then
+    if type(Event[event]) == 'function' then
+      PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Info.ogg]])
+      reason, arg1, arg2, arg3 = Event[event](...)
+    elseif type(Event[event]) == 'table' then
+      PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Link.ogg]])
+      for i, action in ipairs(Event[event]) do
+        if type(action) == 'function' then
+          reason, arg1, arg2, arg3 = action(event, ...)
+        else
+          reason = action
+        end
+
+        if reason then
+          mod:Update(reason, arg1, arg2, arg3)
+        end
+      end
+    else
+      PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Heart.ogg]])
+      reason = Event[event]
+    end
+  else
+    PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Quack.ogg]])
+  end
+  if reason then
+    mod:Update(reason, arg1, arg2, arg3)
+  else
+    print('no reason value returned')
+    PlaySoundFile([[Interface\Addons\SharedMedia_MyMedia\sound\Quack.ogg]])
+  end
+end
+
 --- Done any time the the minimize button is toggled up
-
-
 function mod:OnEnable()
   for id, name in ipairs(mod.orderedNames) do
     if not mod.orderedHandlers[id] then
@@ -354,22 +412,11 @@
     end
   end
 
-  Wrapper:RegisterEvent("CRITERIA_COMPLETE");
-  Wrapper:RegisterEvent("SCENARIO_UPDATE");
-  Wrapper:RegisterEvent("SCENARIO_CRITERIA_UPDATE");
-  Wrapper:RegisterEvent("PLAYER_MONEY");
-  Wrapper:RegisterEvent("QUEST_ACCEPTED");
-  Wrapper:RegisterEvent("QUEST_AUTOCOMPLETE");
-  Wrapper:RegisterEvent("QUEST_LOG_UPDATE");
-  Wrapper:RegisterEvent("QUEST_POI_UPDATE");
-  Wrapper:RegisterEvent("QUEST_TURNED_IN");
-  Wrapper:RegisterEvent("QUEST_WATCH_LIST_CHANGED");
-  Wrapper:RegisterEvent("SUPER_TRACKED_QUEST_CHANGED");
-  Wrapper:RegisterEvent("TRACKED_ACHIEVEMENT_LIST_CHANGED");
-  Wrapper:RegisterEvent("TRACKED_ACHIEVEMENT_UPDATE");
-  Wrapper:RegisterEvent("VARIABLES_LOADED");
-  Wrapper:RegisterEvent("ZONE_CHANGED_NEW_AREA");
-  Wrapper:RegisterEvent("ZONE_CHANGED");
+  for event, action in pairs(Event) do
+    print('|cFFFF0088listen to', event, 'for action|r', tostring(action))
+    Wrapper:RegisterEvent(event)
+  end
+
   Wrapper:SetScript('OnEvent', mod.OnEvent)
 
   local c = mod.Conf.Wrapper
@@ -383,7 +430,7 @@
 end
 
 function mod:OnDisable()
-
+  Wrapper:UnregisterAllEvents()
 end