diff ObjectiveInfo.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/ObjectiveInfo.lua	Fri Apr 08 06:12:05 2016 -0400
+++ b/ObjectiveInfo.lua	Sat Apr 09 07:32:45 2016 -0400
@@ -1,5 +1,5 @@
 local B = select(2,...).frame
-local wipe, pairs, ipairs, min, max, unpack, format = table.wipe, pairs, ipairs, min, max, unpack, format
+local wipe, pairs, ipairs, min, max, unpack, format, mod = table.wipe, pairs, ipairs, min, max, unpack, format, mod
 local tinsert, tostring = tinsert, tostring
 local GetQuestTagInfo, GetQuestLogTitle = GetQuestTagInfo, GetQuestLogTitle
 local GetNumQuestLogEntries, GetNumQuestWatches, GetQuestLogCompletionText, IsQuestWatched, IsQuestHardWatched, GetQuestLogSpecialItemInfo, GetQuestLogSpecialItemCooldown = GetNumQuestLogEntries, GetNumQuestWatches, GetQuestLogCompletionText, IsQuestWatched, IsQuestHardWatched, GetQuestLogSpecialItemInfo, GetQuestLogSpecialItemCooldown
@@ -9,8 +9,9 @@
 local GetQuestWatchIndex, GetQuestLogIndexByID, GetSuperTrackedQuestID, SetSuperTrackedQuestID, GetQuestWatchInfo = GetQuestWatchIndex, GetQuestLogIndexByID, GetSuperTrackedQuestID, SetSuperTrackedQuestID, GetQuestWatchInfo
 local QuestHasPOIInfo, GetDistanceSqToQuest, GetQuestFactionGroup = QuestHasPOIInfo, GetDistanceSqToQuest, GetQuestFactionGroup
 local GetTrackedAchievements, GetNumTrackedAchievements, GetAchievementInfo = GetTrackedAchievements, GetNumTrackedAchievements, GetAchievementInfo
-local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
-local print = B.print('TrackerInfo')
+local GetMoney, floor = GetMoney, floor
+local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
+local print = B.print('Info')
 local QUEST_TAG_DUNGEON = QUEST_TAG_DUNGEON
 local QUEST_TAG_GROUP = QUEST_TAG_GROUP
 local QUEST_TAG_ACCOUNT = QUEST_TAG_ACCOUNT
@@ -19,12 +20,57 @@
 local LE_QUEST_FREQUENCY_WEEKLY = LE_QUEST_FREQUENCY_WEEKLY
 local FACTION_ALLIANCE, LE_QUEST_FACTION_HORDE, FACTION_HORDE, LE_QUEST_FACTION_HORDE = FACTION_ALLIANCE, LE_QUEST_FACTION_HORDE, FACTION_HORDE, LE_QUEST_FACTION_HORDE
 
-local Tracker, Bonus, AutoQuest, Quest, Cheevs = mod.DefaultTracker, mod.Bonus, mod.AutoQuest, mod.Quest, mod.Cheevs
+local Tracker, Bonus, AutoQuest, Quest, Cheevs = T.DefaultTracker, T.Bonus, T.AutoQuest, T.Quest, T.Cheevs
 --------------------------------------------------------------------
 --- Tracker-specific data retrieval functions
 --------------------------------------------------------------------
 
 
+local DoQuestRewards= function(t, questID)
+  local rewards = {}
+  t.numCurrencies = GetNumQuestLogRewardCurrencies(questID)
+  for i = 1, t.numCurrencies do
+    local name, texture, count = GetQuestLogRewardCurrencyInfo(i, questID)
+    tinsert(rewards,{
+      type = 'currency',
+      index = i,
+      name = name,
+      texture = texture,
+      count = count
+    });
+  end
+  -- items
+  t.numItems = GetNumQuestLogRewards(questID)
+  for i = 1, t.numItems do
+    local name, texture, count, quality, isUsable = GetQuestLogRewardInfo(i, questID)
+    tinsert(rewards, {
+      type = 'item',
+      index = i ,
+      name = name,
+      texture = texture,
+      count = count,
+      quality = quality,
+      isUsable = isUsable
+    });
+  end
+  -- money
+
+  local money = GetQuestLogRewardMoney(questID)
+  if ( money > 0 ) then
+    tinsert(rewards, {
+      type = 'money',
+      name = GetMoneyString(money),
+      texture = "Interface\\Icons\\inv_misc_coin_01",
+      count = 0,
+    });
+  end
+
+  if #rewards >= 1 then
+    t.rewardInfo = rewards
+  end
+end
+
+
 -----------------------------
 --- AUTO_QUEST
 AutoQuest.LogInfo = {}
@@ -40,19 +86,22 @@
 end
 AutoQuest.GetInfo = function(self, popupIndex)
 
+
   local questID, type = GetAutoQuestPopUp(popupIndex)
   local questIndex = GetQuestLogIndexByID(questID)
   local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questIndex)
 
-  self.Info[questID] = {
-    title = title,
-    description = type,
-    popupType = type,
-    questID = questID,
-    questIndex = questIndex,
-    popupIndex = popupIndex,
-  }
-  self.WatchInfo[popupIndex] = self.Info[questID]
+  self.Info[questID] = self.Info[questID] or {}
+  local popup = self.Info[questID]
+  popup.title = title
+  popup.description = type
+  popup.popupType = type
+  popup.questID = questID
+  popup.questIndex = questIndex
+  popup.popupIndex = popupIndex
+
+  self.Info[questID] = popup
+  self.WatchInfo[popupIndex] = popup
 
 
   return self.Info[questID]
@@ -71,9 +120,23 @@
 -- It's kind of dumb, but this avoids the risk of code taint.
 
 --- Returns a tasks table modified to include recently completed objectives
-local completedTasks = {}
+local UnitName, GetRealmName = UnitName, GetRealmName
 local InternalGetTasksTable = function()
+  local completedTasks = T.Conf.TasksLog
+  local char = UnitName("player")
+  local realm = GetRealmName()
   local tasks = GetTasksTable()
+
+  for questID, data in pairs(Bonus.Info) do
+
+    print('  -- questID:', questID, #data.objectives)
+      for i, o in ipairs(data.objectives) do
+        print('    --', i, o.text)
+      end
+
+  end
+
+
   for questID, data in pairs(completedTasks) do
     if questID > 0  then
       local found = false
@@ -98,6 +161,7 @@
 
 --- 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
     return true, true, #completedTasks[questID].objectives
   else
@@ -107,7 +171,9 @@
 
 --- 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;
   else
     return GetQuestObjectiveInfo(questID, objectiveIndex, false);
@@ -121,25 +187,27 @@
 Bonus.POI = {}
 Bonus.Scenario = {}
 Bonus.QuestBlock = {}
+Bonus.WatchInfo = {}
 function Bonus:GetNumWatched ()
   print(self.name, self)
+
   local tasks = InternalGetTasksTable()
   local numWatched = 0
   local numAll = 0
   self.WatchInfo = {}
   print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks)
+  print('  TasksTable pull:')
   for i, questID in ipairs(tasks) do
     local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
     local existingTask = self.QuestBlock[questID]
     local displayObjectiveHeader = false;
-    print ('   |cFF00FF00taskIndex', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'))
-    if isInArea or isOnMap then
+    local test = (isInArea or (isOnMap and existingTask))
+    --local test = true
+    if test then
       self.Info[questID] = self.Info[questID] or {}
 
       local t = self.Info[questID]
-      local title = GetQuestLogTitle(questID)
       self.WatchInfo[i] = t
-      t.title = title
       t.isInArea = isInArea
       t.isOnMap = isOnMap
       t.existingTask = existingTask
@@ -147,10 +215,22 @@
       t.objectives = {}
       t.taskIndex = i
 
+
+      DoQuestRewards(t, questID)
+
+      local taskTitle
       local taskFinished = true;
       for objectiveIndex = 1, numObjectives do
         local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
         displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
+        if not taskTitle then
+          if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then
+            taskTitle = text
+            text = ''
+          end
+        end
+
+
         print('  --', text, objectiveType, finished, displayAsObjective)
         t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or  {}
         local  o = t.objectives[objectiveIndex]
@@ -162,15 +242,33 @@
         o.displayAsObjective = displayAsObjective
         print('     |cFF00FF88*', objectiveIndex, text)
       end
+
+      -- didn't get a name from progress bar? what about area name
+      if not taskTitle then
+        if isInArea then
+          taskTitle = GetMapNameByID(GetCurrentMapAreaID())
+        end
+      end
+      t.title = taskTitle
     end
+
+    print ('    |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r'))
   end
 
 
   self.numAll = #tasks
   self.numWatched = #self.WatchInfo
-  print('   stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
+  print('  stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
   --return #tasks
-  return GetNumQuestLogTasks()
+  return #self.WatchInfo
+end
+
+--- info cleanup done when  turn-ins are detected
+Bonus.OnTurnIn = function(self, questID, xp, money)
+  print('|cFFFF8800'..self.name..':OnTurnIn call', questID, xp, money)
+
+
+
 end
 
 Bonus.GetInfo = function(self, taskIndex)
@@ -215,48 +313,7 @@
 
   t.displayObjectives = displayObjectives
 
-
-  local rewards = {}
-  t.numCurrencies = GetNumQuestLogRewardCurrencies(questID)
-  for i = 1, t.numCurrencies do
-    local name, texture, count = GetQuestLogRewardCurrencyInfo(i, questID)
-    tinsert(rewards,{
-      type = 'currency',
-      index = i,
-      name = name,
-      texture = texture,
-      count = count
-    });
-  end
-  -- items
-  t.numItems = GetNumQuestLogRewards(questID)
-  for i = 1, t.numItems do
-    local name, texture, count, quality, isUsable = GetQuestLogRewardInfo(i, questID)
-    tinsert(rewards, {
-      type = 'item',
-      index = i ,
-      name = name,
-      texture = texture,
-      count = count,
-      quality = quality,
-      isUsable = isUsable
-    });
-  end
-  -- money
-
-  local money = GetQuestLogRewardMoney(questID)
-  if ( money > 0 ) then
-    tinsert(rewards, {
-      type = 'money',
-      name = GetMoneyString(money),
-      texture = "Interface\\Icons\\inv_misc_coin_01",
-      count = 0,
-    });
-  end
-
-  if #rewards >= 1 then
-    t.rewardInfo = rewards
-  end
+  DoQuestRewards(t, questID)
 
   Bonus.TasksTable[questID] = t
 
@@ -371,6 +428,7 @@
   q.objectives = {}
   for i = 1, q.numObjectives do
     local text, type, finished = GetQuestLogLeaderBoard(i, questIndex)
+    print(format('   #%d %s %s %s', i, tostring(type), tostring(text), tostring(finished)))
     q.objectives[i] = {
       index = i,
       type = type,
@@ -385,6 +443,46 @@
     end
   end
 
+  if requiredMoney >= 1 then
+    local money = GetMoney()
+    local moneyText = money
+    local requiredSilver, requiredCopper
+    local requiredGold = (requiredMoney > 10000) and (floor(requiredMoney/10000)) or nil
+    if mod(requiredMoney, 10000) ~= 0 then
+      requiredSilver = (requiredMoney > 100) and (mod(requiredMoney, 10000) / 100) or nil
+      if mod(requiredMoney, 100) ~= 0 then
+        requiredCopper = mod(requiredMoney, 100)
+      end
+    end
+
+    -- round the money value down
+    if requiredMoney > 9999 and not (requiredSilver or requiredCopper) then
+      moneyText = floor(money/10000)
+    elseif requiredMoney < 10000 and mod(requiredMoney,100) == 0 then
+      moneyText = floor(money/100)
+    end
+
+    local text = moneyText
+    local index = #q.objectives + 1
+    local finished = (GetMoney() >= requiredMoney)
+
+    if not finished then
+      text = text .. ' / ' .. GetCoinTextureString(requiredMoney, 15)
+    else
+      text = '' .. GetCoinTextureString(requiredMoney, 15)
+    end
+    q.objectives[index] = {
+      index = index,
+      type = 'progressbar',
+      quantity = money,
+      requiredQuantity = requiredMoney,
+      text = text,
+      finished = finished
+    }
+    print(format('   #%d %s %s %s', index, 'money', text, tostring(finished)))
+  end
+
+
   local link, icon, charges = GetQuestLogSpecialItemInfo(questIndex)
   local start, duration, enable = GetQuestLogSpecialItemCooldown(questIndex)
   if link or icon or charges then