diff ObjectiveTracker/BonusObjectives.lua @ 40:03ed70f846de

- move block accessors into a new file - define a tMove function for reconciling the free/used tables as needed - when retrieving an old block frame, confirm ID still matches; resolves multiple watch items on one block - stop any animations when a block is freed; resolves stuck flare graphics
author Nenue
date Sun, 24 Apr 2016 14:15:25 -0400
parents 1f8f9cc3d956
children
line wrap: on
line diff
--- a/ObjectiveTracker/BonusObjectives.lua	Thu Apr 21 16:43:37 2016 -0400
+++ b/ObjectiveTracker/BonusObjectives.lua	Sun Apr 24 14:15:25 2016 -0400
@@ -17,10 +17,12 @@
 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime
 local TASK_DISPLAY_TEST = 1 -- 1: normal (is nearby or on the map) 2: strict (is nearby) 3: data exists
 
+--- Holds data for recently completed tasks
+local completedTasks = {}
+
 --- Returns a tasks table modified to include recently completed objectives
 local InternalGetTasksTable = function()
   local print = Bonus.print
-  local savedTasks = T.Conf.TasksLog
   local char = UnitName("player")
   local realm = GetRealmName()
   local tasks = GetTasksTable()
@@ -32,7 +34,7 @@
     end
   end
 
-  for questID, data in pairs(savedTasks) do
+  for questID, data in pairs(completedTasks) do
     if questID > 0  then
       local found = false
       for i = 1, #tasks do
@@ -55,9 +57,10 @@
 end
 
 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull
+
 local InternalGetTaskInfo = function(questID)
-  local completedTasks = T.Conf.TasksLog
   if completedTasks[questID] then
+    -- if it's a recently completed task, use the information stored for it
     return true, true, #completedTasks[questID].objectives
   else
     return GetTaskInfo(questID)
@@ -66,7 +69,6 @@
 
 --- Same as above but for the objective entries
 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex)
-  local completedTasks = T.Conf.TasksLog
   if ( completedTasks[questID] ) then
     print('using internal data')
     return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true;
@@ -111,7 +113,8 @@
     local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
     local existingTask = self.InfoBlock[questID]
     local displayObjectiveHeader = false;
-    if CanShowTask(isInArea, isOnMap, existingTask) then
+    local displayTask = CanShowTask(isInArea, isOnMap, existingTask)
+    if displayTask then
       print('TaskInfo', '|cFF00FF00showable objective list', questID)
       self.Info[questID] = self.Info[questID] or {}
 
@@ -126,7 +129,7 @@
       local taskTitle
       t.id = questID
       t.objectives = {}
-      local taskFinished = true;
+      local isComplete = true;
       for objectiveIndex = 1, numObjectives do
         local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
         displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
@@ -147,6 +150,7 @@
         o.type = objectiveType
         o.finished = finished
         o.displayAsObjective = displayAsObjective
+        isComplete = (isComplete and finished)
       end
 
       T.SetRewards(t, questID)
@@ -165,13 +169,15 @@
       t.id = questID
       t.taskIndex = i
       t.title = taskTitle
+      t.isComplete = isComplete
       self.WatchList[i] = t
     elseif existingTask then
       print('TaskInfo', '|cFFFF4400hideable task', questID)
       existingTask:Hide()
     end
 
-    print ('TaskInfo', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r'))
+
+    print ('TaskInfo', i, '|cFFFFFF00'.. questID..'|r', '('..(isInArea and '|cFF88FF88' or '|cFF666666') .. 'isInArea|r', 'AND', (isOnMap and '|cFF88FF88' or '|cFF666666') .. 'isOnMap|r)', 'OR', (existingTask and '|cFF88FF88' or '|cFF666666') .. 'existingTask|r', (displayTask and '|cFF00FF00show|r' or '|cFFFF4400hide|r'))
   end
 
 
@@ -180,6 +186,24 @@
   return self.numWatched, self.numWatched, self.WatchList
 end
 
+Bonus.OnEvent = function(block, event, ...)
+  if event == 'QUEST_LOG_UPDATE' then
+    local info = block.info
+
+    local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(info.questID)
+    if not CanShowTask(isInArea, isOnMap, block, numObjectives) then
+      block:Hide()
+    end
+  end
+end
+
+Bonus.GetBlock = function(self, index)
+  local block = Default.GetBlock(self, index)
+  block:SetScript('OnEvent', self.OnEvent)
+  block:RegisterEvent('QUEST_LOG_UPDATE')
+  return block
+end
+
 --- info cleanup done when  turn-ins are detected
 Bonus.OnTurnIn = function(self, block, questID, xp, money)
   --[=[
@@ -254,21 +278,19 @@
   if data.type == 'progressbar' then
     print('    |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID)))
     local percent = 100
-    attachment = T.GetWidget(data, 'StatusBar', info.questID..'-'..data.index)
-    attachment:SetParent(block)
-
     if not data.finished then
       percent = GetQuestProgressBarPercent(info.questID)
     end
     data.value = percent
     data.maxValue = 100
 
+    attachment = T.GetWidget(data, 'StatusBar', info.questID..'-'..data.index)
+    attachment:SetParent(block)
     print(attachment:GetNumPoints())
     for i = 1, attachment:GetNumPoints() do
       print('  ',attachment:GetPoint(i))
     end
 
-
     attachment.value = percent
     attachment.maxValue = 100
     attachment.status:SetFormattedText(PERCENTAGE_STRING, percent)