diff QuestPOI.lua @ 29:c1612c2c1840

WorldPlan: - Optimizations to in a lot of areas that should lead to better load-times and snappier world map. * Responding to quest log and map events by setting flags instead of tailing into the complete works. * Using a generic getter function for resolving pin visual attributes. and making use of blizzard constants for sanity's sake.
author Nenue
date Thu, 27 Oct 2016 13:50:56 -0400
parents 4a7e89bffbcb
children 8cb750e79952
line wrap: on
line diff
--- a/QuestPOI.lua	Thu Oct 27 06:19:05 2016 -0400
+++ b/QuestPOI.lua	Thu Oct 27 13:50:56 2016 -0400
@@ -3,13 +3,17 @@
 -- Created: 10/1/2016 7:21 PM
 -- %file-revision%
 --
+
+local TQ_GetQuestInfoByQuestID = C_TaskQuest.GetQuestInfoByQuestID -- Return the name of a quest with a given ID
 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation
 local TQ_GetQuestTimeLeftMinutes = C_TaskQuest.GetQuestTimeLeftMinutes
 local TQ_IsActive = C_TaskQuest.IsActive
+local TQ_RequestPreloadRewardData = C_TaskQuest.RequestPreloadRewardData
 local QuestPOIGetIconInfo, WorldMapPOIFrame =  QuestPOIGetIconInfo, WorldMapPOIFrame
 
 local print = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end
+local wqprint = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuest', ...) end or function() end
 local iprint = DEVIAN_WORKSPACE and function(...) _G.print('ItemScan', ...) end or function() end
 local QuestPOI = WorldPlanPOIMixin
 
@@ -23,6 +27,27 @@
 local POI_BORDER_YELLOW = "Interface\\BUTTONS\\YELLOWORANGE64"
 local POI_BORDER_GREEN = "Interface\\BUTTONS\\GREENGRAD64"
 
+local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD
+local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER
+local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT
+local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES
+local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS
+
+
+local LE_QUEST_TAG_TYPE_PVP = LE_QUEST_TAG_TYPE_PVP
+local LE_QUEST_TAG_TYPE_PET_BATTLE = LE_QUEST_TAG_TYPE_PET_BATTLE
+local LE_QUEST_TAG_TYPE_DUNGEON = LE_QUEST_TAG_TYPE_DUNGEON
+local LE_QUEST_TAG_TYPE_PROFESSION = LE_QUEST_TAG_TYPE_PROFESSION
+local LE_QUEST_TAG_TYPE_NORMAL = LE_QUEST_TAG_TYPE_NORMAL
+
+local LE_QUEST_TAG_TYPE_PVP = LE_QUEST_TAG_TYPE_PVP
+local LE_QUEST_TAG_TYPE_PET_BATTLE = LE_QUEST_TAG_TYPE_PET_BATTLE
+local LE_QUEST_TAG_TYPE_DUNGEON = LE_QUEST_TAG_TYPE_DUNGEON
+local LE_QUEST_TAG_TYPE_PROFESSION = LE_QUEST_TAG_TYPE_PROFESSION
+local LE_QUEST_TAG_TYPE_NORMAL = LE_QUEST_TAG_TYPE_NORMAL
+
+-- Pin color/display variables
+
   local familiars = {
       [42159] = {npc = 106552, name = 'Nightwatcher Merayl'},
       [40277] = {npc = 97804, name = 'Tiffany Nelson'},
@@ -43,25 +68,6 @@
   local familiars_id = 9696
 
 
-local PIN_TIME_CONTEXT = {
-  {max = 60,
-    r=1, g=0.25, b =0, format = function (minutes) return '|cFFFF4400'.. minutes .. 'm' end,
-    continentAlpha = 1, swipeTime = 1440,
-  },
-  {max = 240,
-    r=1, g=.5, b=0, format = function(minutes) return '|cFFFF4400'.. floor(minutes/60) .. 'h' end,
-    continentAlpha = 1, swipeTime = 1440,
-  },
-  {max = 1440,
-    r=1, g=1, b=0, format = function(minutes) return '|cFFFFFF00'.. floor(minutes/60) .. 'h' end,
-    continentAlpha = .55, swipeTime = 1440
-  },
-  {max = 10081,
-    r=0, g=1, b=0,
-    continentAlpha = .3,
-  }, -- 7 days + 1 minute
-}
-
 -- update a masked texture without messing up its blending mask
 local SetMaskedTexture = function(region, file, mask)
   mask = mask or POI_BORDER_MASK
@@ -70,6 +76,59 @@
   region:SetMask(mask)
 end
 
+
+-- use tooltip object to extract item details
+local ParseItemReward = function(questID)
+  local name, icon, quantity, quality, _, itemID = GetQuestLogRewardInfo(1, questID)
+  local scanner = _G.WorldPlanTooltip
+  if not itemID then
+    return
+  end
+
+  scanner:SetOwner(WorldPlan, "ANCHOR_NONE")
+  scanner:SetItemByID(itemID)
+  scanner:Show()
+  local ttl1 = _G['WorldPlanTooltipTextLeft1']
+  local ttl2 = _G['WorldPlanTooltipTextLeft2']
+  local ttl3 = _G['WorldPlanTooltipTextLeft3']
+  local ttl4 = _G['WorldPlanTooltipTextLeft4']
+  if ttl2 then
+    local text = ttl2:GetText()
+    -- Artifact Power
+    if text then
+      if text:match("|cFFE6CC80") then
+        --print('AP token!', text)
+        local power
+        if ttl4 then
+          local text = ttl4:GetText()
+          --print('tip line 4', text)
+          if text then
+            power = text:gsub("%p", ""):match("%d+")
+            power = tonumber(power)
+          end
+
+        end
+        return REWARD_ARTIFACT_POWER, "Interface\\ICONS\\inv_7xp_inscription_talenttome01", power, name, itemID
+      elseif text:match("Item Level") then
+        --print('equipment!', text)
+        quantity = text:match("Item Level ([%d\+]+)")
+        return REWARD_GEAR, icon, quantity, name, itemID
+      elseif  text:match("Crafting Reagent") then
+        --print('|cFFFF4400it is a reagent', text)
+        return REWARD_REAGENT, icon, quantity, name, itemID
+      end
+    end
+
+  elseif ttl3 then
+    local text = ttl3:GetText()
+    if  text:match("Crafting Reagent") then
+      --print('|cFFFF4400it is a reagent', text)
+      return REWARD_REAGENT, icon, quantity, name, itemID
+    end
+  end
+  return 128, icon, quantity, name, itemID
+end
+
 function WorldPlanPOIMixin:OnEnter()
   local completed = select(4,GetAchievementInfo(familiars_id))
   if not completed then
@@ -106,10 +165,113 @@
 end
 
 
+
+-- create or update the pin using the given questID and C_TaskQuest results
+function WorldPlanPOIMixin:RefreshData (info)
+
+  qprint('|cFF00FF88'..self:GetName()..':RefreshData()|r')
+
+  if info then
+
+    self.x = info.x or self.x
+    self.y = info.y or self.y
+    self.inProgress = info.inProgress
+    self.floor = info.floor
+    self.numObjectives = info.numObjectives or 0
+    print('|cFFFF4400subbing in new info', info.x, info.y, self.x, self.y)
+  end
+
+
+  local questID = self:GetID()
+  local questTitle, rewardIcon, rewardName, rewardCount, rewardStyle, rewardType, itemID, quantity, quality, _
+  local hasUpdate, isPending = self.isNew, false
+
+
+  if not HaveQuestData(questID) then
+    TQ_RequestPreloadRewardData(questID)
+    isPending = true
+    qprint('because not have data')
+  else
+
+    -- set reward category
+    local numRewards = GetNumQuestLogRewards(questID)
+    local numCurrency = GetNumQuestLogRewardCurrencies(questID)
+    local money = GetQuestLogRewardMoney(questID)
+    if numRewards >= 1 then
+      rewardType, rewardIcon, rewardCount, rewardName, itemID = ParseItemReward(questID)
+    elseif numCurrency >= 1 then
+      rewardName, rewardIcon, rewardCount = GetQuestLogRewardCurrencyInfo(1, questID)
+      rewardType = REWARD_CURRENCY
+    elseif money >= 1 then
+      rewardIcon = ICON_MONEY
+      rewardName = GetMoneyString(money)
+      rewardType = REWARD_CASH
+    end
+    rewardStyle = WorldPlan:GetTypeInfo(rewardType)
+
+    self.itemNumber = rewardCount or self.itemNumber
+    self.rewardType = rewardType or REWARD_ITEM
+    self.style = rewardStyle
+
+    -- title, faction, capped state
+    local questTitle, factionID, capped = TQ_GetQuestInfoByQuestID(questID)
+    self.factionID = factionID
+    self.capped = capped
+
+    -- set tag details
+    local tagID, tagName, worldQuestType, rarity, isElite, tradeskillLineIndex = GetQuestTagInfo(questID);
+    local tagAtlas
+    if worldQuestType == LE_QUEST_TAG_TYPE_PET_BATTLE then
+      tagAtlas = "worldquest-icon-petbattle"
+    elseif worldQuestType == LE_QUEST_TAG_TYPE_PVP then
+      tagAtlas = "worldquest-icon-pvp-ffa"
+    elseif worldQuestType == LE_QUEST_TAG_TYPE_PROFESSION then
+      local id = tradeskillLineIndex and select(7, GetProfessionInfo(tradeskillLineIndex))
+      if id then
+        tagAtlas = WORLD_QUEST_ICONS_BY_PROFESSION[id]
+      end
+    elseif worldQuestType == LE_QUEST_TAG_TYPE_DUNGEON then
+      tagAtlas = "worldquest-icon-dungeon"
+    end
+
+    self.tagID = tagID
+    self.tagName = tagName
+    self.worldQuestType = worldQuestType
+    self.isElite = isElite
+    self.tradeskillLineIndex = tradeskillLineIndex
+    self.rarity = rarity
+    self.tagAtlas = tagAtlas
+
+    -- flag unresolved info
+    if not (rewardIcon and rewardName) then
+      isPending = true
+      qprint('because not have icon')
+      TQ_RequestPreloadRewardData (questID)
+      --WorldPlan:print('|cFFFFFF00'..tostring(self.title)..'|r waiting on texture info')
+    else
+      if (rewardIcon and rewardName) and isPending then
+        --WorldPlan:print('|cFF00FF00'..tostring(self.title)..'|r has info', rewardIcon, rewardName)
+        hasUpdate = true
+      end
+      isPending = false
+    end
+
+    self.title = questTitle or "|cFFFF0000Retrieving..."
+    self.itemTexture = rewardIcon or self.itemTexture
+    self.itemName = rewardName or self.itemName
+    self.hasUpdate = hasUpdate
+    self.isPending = isPending
+
+
+    qprint('  |cFF00FFFF'..questID..'|r hasUpdate:', hasUpdate, 'isPending:', isPending)
+    qprint(' ', self.title, self.itemTexture, 'rewardType:', self.rewardType, 'tag:', self.tagID, 'style', self.style )
+  end
+  return hasUpdate, isPending
+end
+
+
 function WorldPlanPOIMixin:SetAchievementProgressTooltip()
   print('cheevos')
-
-
 end
 
 function WorldPlanPOIMixin:ShowNew()
@@ -133,8 +295,9 @@
 end
 
 function WorldPlanPOIMixin:SetAnchor(frame, mapID, mapWidth, mapHeight)
+  qprint('  |cFF00FF00'..self:GetName()..':SetAnchor()|r', self.questID, mapID, mapWidth)
   self:ClearAllPoints()
-  local dX, dY = TQ_GetQuestLocation(self.questID, mapID)
+  local dX, dY = TQ_GetQuestLocation(self.questID)
   if not dX or dX == 0 then
     local _, x, y = QuestPOIGetIconInfo(self.questID)
     if x and floor(x) ~= 0 then
@@ -146,7 +309,7 @@
   self.x = dX
   self.y = dY
 
-  qprint('  |cFF00FF00'..self.questID..':|r', format("%0.2f %0.2f", dX, dY))
+  --qprint('  |cFF00FF00'..self.questID..':|r', format("%0.2f %0.2f", dX, dY))
 
   local pX = (dX * mapWidth)
   local pY = (-dY * mapHeight)
@@ -187,7 +350,7 @@
   -- query for reward data if it wasn't found in the original scan
   local questID = self.questID
   if self.isPending then
-    self:Reset()
+    self:RefreshData()
     if not (self.PendingFade:IsPlaying() or self.isAnimating) then
       self.PendingFade:Play()
     end
@@ -207,25 +370,10 @@
   local tl = self.timeThreschold
   local timeLeft = TQ_GetQuestTimeLeftMinutes(questID)
   if timeLeft > 0 then
-    for i, context in ipairs(PIN_TIME_CONTEXT) do
-      if i > self.TimeleftStage then
-        self.timeLabel:SetText(nil)
-        break
-      end
-
-
-      if timeLeft <= context.max then
-        if tl ~= i then
-          tl = i
-        end
-
-        if context.format then
-          self.timeLabel:SetText(context.format(timeLeft))
-        else
-          self.timeLabel:SetText(nil)
-        end
-        break
-      end
+    local text, timeState = WorldPlan:GetTimeInfo(timeLeft, self.TimeleftStage)
+    if tl ~= timeState then
+      tl = timeState
+      self.timeLabel:SetText(text)
     end
   else
     -- remove self in a timely manner
@@ -255,9 +403,12 @@
 
 
 
-  local questID = self.questId
-  local style = self.style
-  local subStyle = style[(self.filtered and 'minimized' or 'continent')]
+  local questID = self:GetID()
+  local style,subStyle =  WorldPlan:GetTypeInfo(self.rewardType or ((self.quality or 0) + 127))
+  if self.filtered then
+    subStyle = style.minimized
+  end
+
   local borderMask = style.mask
   local borderFill = style.texture
   local iconBorder = self.iconBorder
@@ -280,18 +431,21 @@
     local color = self.rewardColor or COMMON_COLOR
 
 
-    self.label:SetShown( self.showNumber)
+
     if self.hasNumeric then
-      self.label:SetText(self.itemNumber)
-      self.label:SetTextColor(unpack(self.numberRGB))
+      self.count:SetShown(true)
+      self.count:SetText(self.itemNumber)
+      self.count:SetTextColor(unpack(self.numberRGB))
     else
-      self.label:SetText(nil)
+      self.count:SetShown(false)
+      self.count:SetText(nil)
     end
 
   end
 
   SetMaskedTexture(iconBorder, borderFill, borderMask)
-  local border = (self.rewardType and db.rewardStyle[self.rewardType]) or (WORLD_QUEST_QUALITY_COLORS[self.rarity] or db.defaultStyle)
+  local border = WorldPlan:GetTypeInfo(self.rewardType)
+  print(self.rewardType, print)
   iconBorder:SetVertexColor(border.r, border.g, border.b, border.a)
   iconBorder:SetDesaturated(true)
 
@@ -314,9 +468,9 @@
 
 
   if self.isElite then
-    self.EliteDecal:Show()
+    self.EliteBorder:Show()
   else
-    self.EliteDecal:Hide()
+    self.EliteBorder:Hide()
   end
   qprint('|cFF88FF00updated', questID, self.title, self.rewardType, (style.showNumber and self.itemNumber) or '')