view ClassPlanMissions.lua @ 36:21bcff08b0f4

WorldPlan: - Quest pins are now placed on the flight map. Their visibility rules will mirror the filter options from the world map. - Filter controls polish: - First click negates other reward type filters. Subsequent clicks will then toggle individual reward types until the filters are reset via Right-click. - Adheres to the Blizzard CVars added in patch 7.1 - Numerous optimizations to how data and visual updates are handled; should see an even better load time, and snappier world map interaction. ClassPlan: - The 'Available Missions' list is now recorded. It can be reviewed by clicking on the mission list heading. - Information filtering by character and realm.
author Nenue
date Fri, 04 Nov 2016 01:40:39 -0400
parents 26dfa661daa7
children 589c444d4837
line wrap: on
line source
local MissionList = ClassPlanMissionHandler
local ListEntry = ClassPlanMissionEntryMixin
local ORDERHALL_TYPE = LE_GARRISON_TYPE_7_0
function ClassPlanMissionHandler:Reanchor()
  self:SetPoint('TOPRIGHT', 0, -24)
  self:SetPoint('BOTTOMLEFT', ClassOrderPlan:GetWidth()/2, 0)

end
local GetPrimaryGarrisonFollowerType = GetPrimaryGarrisonFollowerType
local C_Garrison = C_Garrison

local wipe, tinsert, date, ipairs = table.wipe, table.insert, date, ipairs
local GetItemIcon = GetItemIcon
local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop

function ClassPlanMissionHandler:GetPlayerData (profile)
  local items = C_Garrison.GetAvailableMissions(GetPrimaryGarrisonFollowerType(ORDERHALL_TYPE));
  if not items then
    return
  end
  wipe(profile.missions)
  wipe(profile.available)


  for i = 1, #items do
    if (not items[i].isBuilding and items[i].isZoneSupport) then
    else

      tinsert(profile.available, items[i])
    end
  end

  local items = C_Garrison.GetLandingPageItems(ORDERHALL_TYPE)
  for index, data in ipairs(items) do
    print(' -',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
    tinsert(profile.missions, data)
  end
  return true
end

function ClassPlanMissionHandler:OnGetItem (data)
  if data.missionEndTime and (data.missionEndTime < self.currentTime) then
    data.isComplete = true
  end
  if data.offerEndTime and (data.offerEndTime < self.currentTime) then
    data.isExpired = true
    data.timeToKeep = self.currentTime + 300
  end
end

MissionList.SortHandler = function (a,b)
  local result = false
  --if not a or not b then
  --  return true
  --else
  --if (a.isMine ~= b.isMine) then
  --  result = a.isMine
  --else
  --if (not b.missionEndTime) or (not a.missionEndTime) then
  --  print('missing article', b.missionEndTime, a.missionEndTime)
  --end
  if b.isComplete ~= a.isComplete then
    return a.isComplete
  elseif b.isMine ~= a.isMine then
    return a.isMine
  elseif b.missionEndTime then
    return ( b.missionEndTime > a.missionEndTime)
  else
    return  ((b.offerEndTime or 0) > (a.offerEndTime or 0))
  end

  --end
  --end
end


function MissionList:OnShow()
  print('|cFF00FF88'..self:GetName()..':OnShow()|r')
end



function ClassPlanMissionEntryMixin:OnComplete()
  print('flagging complete', self.name)
  self:Update()
end

function ClassPlanMissionEntryMixin:OnUpdate(sinceLast)
  self.throttle = (self.throttle or .5) + sinceLast
  if self.throttle < .5 then
    return
  else
    self.throttle = self.throttle - .5
  end
  if self.offerEndTime then
    self:SetTimeLeft(self.offerEndTime)
  elseif self.missionEndTime then
    self:SetTimeLeft(self.missionEndTime, self.durationSeconds)
  end
end

function ClassPlanMissionEntryMixin:OnLoad()
  print('|cFFFF4400',self:GetName() or tostring(self), 'onload')
  self.Count = self.Overlay.Count
  self.Name = self.Overlay.Name
  self.TimeLeft = self.Overlay.TimeLeft
  self.Owner = self.Overlay.Owner
  self.maxDisplayed = 10

  self.Icon:SetDesaturated(false)
  self.Done:Hide()
end

function ClassPlanMissionEntryMixin:Update()
  local r,g,b = 1, 1, 1
  if self.isRare then
    r,g,b = 0.1, 0.4, 1
    self.IconBorder:SetVertexColor(r, g, b, 1)
  end

  --self.missionData = data
  self.Name:SetText(self.name)
  if #self.rewards >= 1 then
    self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID))
    self.rewardInfo = self.rewards[1]
  else
    self.Icon:SetAtlas(self.typeAtlas, false)
  end



  if self.isComplete then
    self.TimeLeft:SetText('Complete!')
    self.Background:SetColorTexture(.25,.25,.25,1)
  else
    self.Background:SetColorTexture(0,0,0,0.5)
  end
end

function ListEntry:OnEnter()
  if self.rewardInfo and self.rewardInfo.itemID then
    GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
    GameTooltip:SetItemByID(self.rewardInfo.itemID)
    GameTooltip:Show()
  end
end

function ListEntry:OnLeave()
  if GameTooltip:IsOwned(self) then
    GameTooltip:Hide()
  end
end