view QuestPOI.lua @ 9:a2b623043970 v1.0-rc

WorldQuests: - Filter interface controls reworked: Left-Click toggles inclusive filtering, right-click toggle exclusion, and holding ctrl or shift will flip or reset the other filters of that type respectively. - Fix QuestPOI texture masks disappearing when toggling filter options * new masks aren't applied until SetTexture() is called, making a seemingly redundant call necessary for the change to manifest - Implemented configuration data storage and retrieval; tracking menu options should actually do something now. - Ignore remaining time for Profession quests that aren't part of the player's profession loadout - Alternate tooltip data appears for Pet Battle quests involved in the Family Familar achievement. A list of outstanding criteria is provided in the POI tooltip, and the quest name is highlighted in the filter tooltip. ClassPlan: - actually handle the mission complete icon
author Nenue
date Sun, 23 Oct 2016 17:18:31 -0400
parents 802abb8a10ea
children 4a7e89bffbcb
line wrap: on
line source
-- WorldPlan
-- QuestPOI.lua
-- Created: 10/1/2016 7:21 PM
-- %file-revision%
--
local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation
local TQ_GetQuestTimeLeftMinutes = C_TaskQuest.GetQuestTimeLeftMinutes
local TQ_IsActive = C_TaskQuest.IsActive
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 iprint = DEVIAN_WORKSPACE and function(...) _G.print('ItemScan', ...) end or function() end
local QuestPOI = WorldPlanPOIMixin

local ICON_UNKNOWN = "Interface\\ICONS\\inv_misc_questionmark"
local ICON_MONEY = "Interface\\Buttons\\UI-GroupLoot-Coin-Up"

local POI_BORDER_MASK = "Interface\\Minimap\\UI-Minimap-Background"
local POI_BORDER_FILL = "Interface\\BUTTONS\\YELLOWORANGE64"
local POI_BORDER_BLUE = "Interface\\BUTTONS\\GRADBLUE"
local POI_BORDER_RED = "Interface\\BUTTONS\\RedGrad64"
local POI_BORDER_YELLOW = "Interface\\BUTTONS\\YELLOWORANGE64"
local POI_BORDER_GREEN = "Interface\\BUTTONS\\GREENGRAD64"

  local familiars = {
      [42159] = {npc = 106552, name = 'Nightwatcher Merayl'},
      [40277] = {npc = 97804, name = 'Tiffany Nelson'},
      [40298] = {npc = 99182, name = 'Sir Galveston'},
      [40282] = {npc=  99150, name = 'Grixis Tinypop'},
      [40278] = {npc = 98270, name = 'Robert Craig'},
      [48195] = {npc = 105250, name = 'Aulier'},
      [41990] = {npc = 105674, name = 'Varenne'},
      [41860] = {npc = 104970, name = 'Xorvasc'},
      [40299] = {npc = 99210, name = 'Bodhi Sunwayver'},
      [42442] = {npc = 107489, name = 'Amalia'},
      [40280] = {npc = 99077, name = 'Bredda Tenderhide'},
      [41687] = {npc = 104553, name = 'Odrogg'},
      [41944] = {npc = 105455, name = 'Trapper Jarrun'},
      [40337] = {npc = 97709, name = 'Master Tamer Flummox'},
      [40279] = {npc = 99035, name = 'Durian Strongfruit'}
  }
  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
  region:SetMask(nil)
  region:SetTexture(file)
  region:SetMask(mask)
end

function QuestPOI:OnEnter()
  local completed = select(4,GetAchievementInfo(familiars_id))
  if not completed then
    if self.worldQuestType == LE_QUEST_TAG_TYPE_PET_BATTLE and familiars[self.questID] then
      WorldMapTooltip:SetOwner(self, 'ANCHOR_RIGHT')
      WorldMapTooltip:AddLine('Family Familiars')
      local trainer = familiars[self.questID].name
      local numCheevs = GetAchievementNumCriteria(familiars_id)
      for index = 1, numCheevs do
        local cheevName, cType, cCompleted, quantity, requiredQuantity, charName, flags, cheevID, quantityString, criteriaID = GetAchievementCriteriaInfo(familiars_id, index)
        local numTrainers = GetAchievementNumCriteria(cheevID)
        for subIndex = 1, numTrainers do
          local desc, cType, partCompleted = GetAchievementCriteriaInfo(cheevID, subIndex)
          if desc == trainer then
            if not partCompleted then
              local iconPath = select(10, GetAchievementInfo(cheevID))
              WorldMapTooltip:AddLine(cheevName)
              WorldMapTooltip:AddTexture(iconPath)
            end
          end
        end
      end
      WorldMapTooltip:Show()
      return
    end
  end
  TaskPOI_OnEnter(self)
end
function QuestPOI:OnLeave()
  TaskPOI_OnLeave(self)
end
function QuestPOI:OnMouseDown()
  TaskPOI_OnClick(self)
end


function WorldPlanPOIMixin:SetAchievementProgressTooltip()
  print('cheevos')


end


function QuestPOI:OnShow ()
  qprint('|cFFFFFF00["'..tostring(self.title)..'"]|r:OnShow()')
  -- pop this on principle
  self:Refresh()
end
function QuestPOI:OnHide()
  --qprint('|cFFFFFF00["'..tostring(self.title)..'"]|r:OnHide()')
end

function QuestPOI:SetAnchor(frame, mapID, mapWidth, mapHeight)
  self:ClearAllPoints()
  local dX, dY = TQ_GetQuestLocation(self.questID, mapID)
  if not dX or dX == 0 then
    local _, x, y = QuestPOIGetIconInfo(self.questID)
    if x and floor(x) ~= 0 then
      dX, dY = x, y
    else
      dX, dY = self.x, self.y
    end
  end
  self.x = dX
  self.y = dY

  qprint('  |cFF00FF00'..self.questID..':|r', format("%0.2f %0.2f", dX, dY))

  local pX = (dX * mapWidth)
  local pY = (-dY * mapHeight)

  self:SetParent(WorldMapPOIFrame)
  self:SetPoint('CENTER', frame, 'TOPLEFT', pX, pY)
end


function QuestPOI:OnLoad()
  self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED')
end

function QuestPOI:OnEvent(event, ...)
  if event == 'SUPER_TRACKED_QUEST_CHANGED' then
    if self:IsVisible() then
      self:Refresh()
    end
  end
end


local PIN_UPDATE_DELAY = .016
local TOP_PIN_ID
function QuestPOI:OnUpdate (sinceLast)
  -- control update check intervals
  self.throttle = (self.throttle or PIN_UPDATE_DELAY) - sinceLast
  if self.throttle <= 0 then
    -- factor overtime into the throttle timer
    self.throttle = PIN_UPDATE_DELAY - self.throttle
  else
    return
  end

  -- query for reward data if it wasn't found in the original scan
  local questID = self.questID
  if self.isPending then
    self:Reset()
    if not (self.PendingFade:IsPlaying() or self.isAnimating) then
      self.PendingFade:Play()
    end
    return
  else
    if self.PendingFade:IsPlaying() then
      self.PendingFade:Stop()
    end
  end

  if self.hasUpdate then
    self:Refresh()
    self.hasUpdate = nil
  end

  -- update time elements
  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
    end
  else
    -- remove self in a timely manner
    if not TQ_IsActive(self.questID) then
      print('|cFFFF4400'..self:GetName()..' pin hard timeout')
      if self.worldQuestType ~= LE_QUEST_TAG_TYPE_PROFESSION then
        self:Hide()
      end
    end
  end
  self.timeThreschold = tl

  if self:IsMouseOver() then
    self.MouseGlow:Show()
  else
    self.MouseGlow:Hide()
  end
end



function QuestPOI:Refresh ()
  local db = WorldPlan.db
  local print = qprint
  print('|cFF00FF88["'..tostring(self.title)..'"]|r:Refresh()', tostring(self.title), "|T"..tostring(self.itemTexture)..":12:12|t", tostring(self.itemName))
  print(self.style)



  local questID = self.questId
  local style = self.style
  local borderMask = style.mask
  local borderFill = style.texture
  local iconBorder = self.iconBorder
  local icon = self.icon
  local count = self.count


  local subStyle = self.filtered and 'minimized' or 'continent'
  if subStyle ~= self.subStyle then
    print( '  - changed subStyle, need to redo masks')
  end
  self.subStyle = subStyle
  print('  - subStyle:', (self.filtered == true), self.subStyle)

  --WorldPlan:print(tostring(self.title), "|T"..tostring(self.itemTexture)..":16:16|t", tostring(self.itemName))
  SetMaskedTexture(icon, self.itemTexture or ICON_UNKNOWN, borderMask)
  icon:SetAllPoints(self)

  if self.itemName then
    local color = self.rewardColor or COMMON_COLOR
    if self.itemNumber and  self.target then
      self.count:SetText(color.hex .. tostring(self.itemNumber))
    else
      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)
  iconBorder:SetVertexColor(border.r, border.g, border.b, border.a)
  iconBorder:SetDesaturated(true)

  local trackingBorder = self.supertrackBorder

  self.highlight:SetMask(nil)
  if questID == GetSuperTrackedQuestID() then
    trackingBorder:SetVertexColor(0,0,0,1)
  else
    trackingBorder:SetVertexColor(0,0,0,0.5)
  end
  self.highlight:SetAllPoints(trackingBorder)

  SetMaskedTexture(trackingBorder, borderFill, borderMask)
  self.highlight:SetMask(borderMask)

  local qType = self.worldQuestType
  self.tagIcon:SetAtlas(self.tagAtlas)
  self.tagIcon:SetTexCoord(0,1,0,1)


  if self.isElite then
    self.EliteDecal:Show()
  else
    self.EliteDecal:Hide()
  end

  if style.showNumber then
    self.label:SetText(self.itemNumber)
  else
    self.label:SetText(nil)
  end
  qprint('|cFF88FF00updated', questID, self.title, self.rewardType, (style.showNumber and self.itemNumber) or '')


  self:UpdateSize()
end

function WorldPlanFilterPinMixin:OnEnter ()
  local filter = WorldPlan.FilterOptions[self:GetID()]
  local mapID = GetCurrentMapAreaID()
  local quests = (mapID == WorldPlan.BrokenIsleID) and WorldPlan.QuestsByID or WorldPlan.QuestsByZone[mapID]
  if quests then
    GameTooltip:SetOwner(self, 'ANCHOR_RIGHT')
    GameTooltip:AddLine(filter.label)
    local filterKey = self.filterKey
    local filterValue = self.filterValue
    if filterKey then
      for questID, pin in pairs(quests) do
        if pin.used and not pin.filtered then
          if  pin[filterKey] == filterValue then
            local style = pin.style or WorldPlan.FilterStyle

            if familiars[questID] then
              GameTooltip:AddLine(pin.title,0,1,0)
            else
              GameTooltip:AddLine(pin.title,1,1,1)
            end

          end
        end
      end
    else
      GameTooltip:AddLine('Reset all filters')
    end
    GameTooltip:Show()
  end
end