diff ObjectiveTracker/ObjectiveTracker.lua @ 34:9856ebc63fa4

- half solution to Update being fired multiple times during load - change securefunc handlers to dispense a reason code; catch that reason code in the enclosure passed to hooksecurefunc, and decide whether to update or not from there.
author Nenue
date Sun, 17 Apr 2016 00:21:45 -0400
parents 64f2a9bbea79
children 69d03f8e293e
line wrap: on
line diff
--- a/ObjectiveTracker/ObjectiveTracker.lua	Fri Apr 15 17:01:06 2016 -0400
+++ b/ObjectiveTracker/ObjectiveTracker.lua	Sun Apr 17 00:21:45 2016 -0400
@@ -67,33 +67,6 @@
 T.strings.CLICK_TO_COMPLETE = 'Click to complete'
 T.colors ={
   enable = true,
-  default = {
-    titlebg = {'HORIZONTAL', 1, 0, .7, .25,    1, 0, .7, .125},
-    textbg = {'HORIZONTAL', 0, 0, 0, 0.4,      0, 0, 0, 0 },
-    selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225},
-  },
-  daily = {
-    titlebg = {'HORIZONTAL', 0, .7, 1, .25,  0, 1, .7, .125},
-    textbg = {'HORIZONTAL', 0, .7, 1, .1,    0, 1, .7, .075 },
-  },
-  weekly = {
-    titlebg = {'HORIZONTAL', 0, .35, .7, .25,   0, .35, .7, .125},
-    textbg = {'HORIZONTAL', 0, .35, .7, .1,     0, .35, .7, .075 },
-  },
-  account = {
-    titlebg = {'HORIZONTAL', .1, .1, .1, .25, .1, .1, .1, .125},
-    textbg = {'HORIZONTAL', .1, .1, .1, 0.4, .1, .1, .1, .085 },
-  },
-  -- alliance
-  faction_1 = {
-    titlebg = {'HORIZONTAL', .2, .4, 1, 0.4, .2, .4, 1, .085 },
-    textbg = {'HORIZONTAL', .2, .4, 1, 0.4, .2, .4, 1, .085 },
-  },
-  -- horde
-  faction_2 = {
-    titlebg = {'HORIZONTAL', .6, 0, 0.4, 0.4,  .6, 0, 0.4, .085 },
-    textbg = {'HORIZONTAL', .6, 0, 0.4, 0.4,   .6, 0, 0.4, .085 },
-  }
 }
 
 T.watchMoneyReasons = 0
@@ -101,6 +74,7 @@
 --- Baseline defaults table; values defined in the files that they pertain to
 T.defaults = {}
 
+
 --- Tracker display order
 T.orderedNames = {'Bonus', 'AutoQuest', 'Quest', 'Cheevs'}
 
@@ -146,15 +120,17 @@
   numWatched = 0,   --- number of entries being handled
   numBlocks = 0,    --- number of blocks created
   actualBlocks = 0, --- number of blocks in use
+  Info = {},        --- stored watch list information, keyed by whatever unique ID is involved for that tracker
+  Watched = {},     --- stores whether the given unique ID is tracked
 
-  freeBlocks = {},  --- block heap
-  usedBlocks = {},
+  freeBlocks = {},  --- blocks hidden due to list shrinkage
+  usedBlocks = {},  --- block in use
+  BlockInfo = {},   --- by block creation offset, used by framescript
 
-  Info = {},        -- find data by ID
-  BlockInfo = {},   -- find data by block ID
-  Watched = {},     -- find watchIndex by data ID
-  WatchInfo = {},   -- find data by watch index
-  WatchBlock = {},  -- find block by watch index
+  --- Indexes
+  LogBlock = {},    --- by API log offset, used by GetBlock if possible
+  WatchBlock = {},  --- block by internal offset, used in GetBlock scope
+  WatchInfo = {},   --- info by internal offset, used in Update scope
 }
 
 T.AutoQuest = {
@@ -163,7 +139,6 @@
   updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST,
   updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_QUEST + OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED,
   LogInfo = {},
-  LogBlock = {},
   QuestBlock = {},
 }
 T.Quest = {
@@ -174,7 +149,6 @@
   itemButtons = {},
   freeButtons = {},
   LogInfo = {},
-  LogBlock = {},
   QuestBlock = {},
 }
 T.Cheevs = {
@@ -273,10 +247,6 @@
   if ( IsQuestTask(questID) ) then
     return OBJECTIVE_TRACKER_UPDATE_TASK_ADDED, questID
   else
-    if ( _G.AUTO_QUEST_WATCH == "1" ) then
-      AddQuestWatch(questLogIndex);
-      SetSuperTrackedQuestID(questID);
-    end
     return OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added
   end
 end
@@ -374,6 +344,7 @@
 
 --- Done once per ui load
 local BlizzHooks = {
+  ['AcceptQuest'] = 'AcceptQuest',
   ['AddQuestWatch'] = 'AddQuestWatch',
   ['RemoveQuestWatch'] = 'RemoveQuestWatch',
   ['AbandonQuest'] = 'AbandonQuest',
@@ -413,6 +384,7 @@
 
 local iprint = B.print('Info')
 T.SetRewards = function(t, questID)
+  local previousSelection = GetQuestLogSelection()
 
   SelectQuestLogEntry(GetQuestLogIndexByID(questID))
   local numQuestChoices = GetNumQuestLogChoices();
@@ -420,6 +392,10 @@
   local xp = GetQuestLogRewardXP();
   local playerTitle = GetQuestLogRewardTitle();
   ProcessQuestLogRewardFactions();
+  if previousSelection then
+    SelectQuestLogEntry(previousSelection)
+  end
+
   local rewards = {}
   local texture, name, isTradeskillSpell, isSpellLearned, hideSpellLearnText, isBoostSpell, garrFollowerID = GetQuestLogRewardSpell(questID)
   if name  then
@@ -474,6 +450,15 @@
 
 local Play = function(file) if Devian and Devian.InWorkspace() then PlaySoundFile(file) end end
 
+T.OnHookedFunc = function(name, ...)
+  print('|cFFFF8800securehook:|r', name, '|cFF00FFFFargs:|r', ...)
+  local updateReason = T[name](...)
+  if updateReason then
+    print('|cFF00FFFFupdate reason:|r', updateReason)
+    T:Update(updateReason)
+  end
+end
+
 function T:OnEvent (event, ...)
   local isHandled
   print('OnEvent(|cFF00FF00'.. event ..'|r):', ...)
@@ -522,7 +507,7 @@
     T.isHooked = true
     for blizzFunc, veneerFunc in pairs(BlizzHooks) do
       if T[veneerFunc] then
-        hooksecurefunc(blizzFunc, T[veneerFunc])
+        hooksecurefunc(blizzFunc, function(...) return T.OnHookedFunc(blizzFunc, ...) end)
       else
         hooksecurefunc(blizzFunc, function(...)
           print('|cFFFF0088securehook('..tostring(blizzFunc)..')|r args:', ...)
@@ -551,9 +536,7 @@
 function T:OnEnable()
 
   print(B.Conf.VeneerObjectiveWrapper.enabled)
-  if not B.Conf.VeneerObjectiveWrapper.enabled then
-    return
-  end
+
 
   for event, action in pairs(Event) do
     print('|cFFFF0088listen to', event, 'for action|r', tostring(action))