annotate ClassPlanMissions.lua @ 40:589c444d4837

WowAce/Curseforge migration push
author Nenue
date Sun, 25 Dec 2016 13:04:57 -0500
parents 26dfa661daa7
children b29b35cb8539
rev   line source
Nenue@40 1 local _, db= ...
Nenue@35 2 local ORDERHALL_TYPE = LE_GARRISON_TYPE_7_0
Nenue@40 3 local UnitClass = UnitClass
Nenue@40 4 local time, max, min = time, max, min
Nenue@40 5 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop
Nenue@35 6 local GetPrimaryGarrisonFollowerType = GetPrimaryGarrisonFollowerType
Nenue@35 7 local C_Garrison = C_Garrison
Nenue@35 8
Nenue@35 9 local wipe, tinsert, date, ipairs = table.wipe, table.insert, date, ipairs
Nenue@35 10 local GetItemIcon = GetItemIcon
Nenue@35 11
Nenue@40 12
Nenue@40 13 local MissionList = {
Nenue@40 14 templateName = 'ClassPlanMissionEntry',
Nenue@40 15 listKey = {'missions', 'available'},
Nenue@40 16 listTitle = {'In Progress', 'Available'},
Nenue@40 17
Nenue@40 18 point = 'TOPLEFT',
Nenue@40 19 relativePoint ='TOPLEFT',
Nenue@40 20 events = {
Nenue@40 21 'GARRISON_MISSION_LIST_UPDATE'},
Nenue@40 22 }
Nenue@40 23 local ListEntry = {}
Nenue@40 24
Nenue@40 25 function MissionList:Reanchor()
Nenue@40 26 self:SetPoint('TOPRIGHT', ClassOrderPlan.BackgroundInset, 'TOPRIGHT', 0, 0)
Nenue@40 27 self:SetPoint('BOTTOMLEFT', ClassOrderPlan:GetWidth()/2, 0)
Nenue@40 28 end
Nenue@40 29
Nenue@40 30
Nenue@40 31
Nenue@40 32
Nenue@40 33 function MissionList:GetPlayerData ()
Nenue@40 34 local profile = self:GetParent().profile
Nenue@35 35 local items = C_Garrison.GetAvailableMissions(GetPrimaryGarrisonFollowerType(ORDERHALL_TYPE));
Nenue@35 36 if not items then
Nenue@35 37 return
Nenue@35 38 end
Nenue@35 39 wipe(profile.missions)
Nenue@35 40 wipe(profile.available)
Nenue@35 41
Nenue@35 42
Nenue@35 43 for i = 1, #items do
Nenue@35 44 if (not items[i].isBuilding and items[i].isZoneSupport) then
Nenue@35 45 else
Nenue@35 46
Nenue@35 47 tinsert(profile.available, items[i])
Nenue@35 48 end
Nenue@35 49 end
Nenue@35 50
Nenue@35 51 local items = C_Garrison.GetLandingPageItems(ORDERHALL_TYPE)
Nenue@35 52 for index, data in ipairs(items) do
Nenue@35 53 print(' -',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
Nenue@35 54 tinsert(profile.missions, data)
Nenue@35 55 end
Nenue@35 56 return true
Nenue@35 57 end
Nenue@35 58
Nenue@40 59 function MissionList:OnGetItem (data)
Nenue@40 60 if data.missionEndTime then
Nenue@40 61 if (data.missionEndTime < self.currentTime) then
Nenue@40 62 data.isComplete = true
Nenue@40 63 else
Nenue@40 64 self:ScheduleUpdate(data.missionEndTime)
Nenue@40 65 end
Nenue@35 66 end
Nenue@40 67
Nenue@40 68 if data.offerEndTime then
Nenue@40 69 if (data.offerEndTime < self.currentTime) then
Nenue@40 70 data.isExpired = true
Nenue@40 71 data.timeToKeep = self.currentTime + 300
Nenue@40 72 else
Nenue@40 73 self:ScheduleUpdate(data.offerEndTime)
Nenue@40 74 end
Nenue@35 75 end
Nenue@40 76
Nenue@35 77 end
Nenue@35 78
Nenue@35 79 MissionList.SortHandler = function (a,b)
Nenue@35 80 local result = false
Nenue@35 81 if b.isComplete ~= a.isComplete then
Nenue@35 82 return a.isComplete
Nenue@35 83 else
Nenue@40 84 if b.isMine ~= a.isMine then
Nenue@40 85 return a.isMine
Nenue@40 86 else
Nenue@40 87 if a.isComplete then
Nenue@40 88 if a.profileKey ~= b.profileKey then
Nenue@40 89 return (a.profileKey < b.profileKey)
Nenue@40 90 else
Nenue@40 91 return (a.name < b.name)
Nenue@40 92 end
Nenue@40 93 else
Nenue@40 94 if b.missionEndTime then
Nenue@40 95 return ( b.missionEndTime > a.missionEndTime)
Nenue@40 96 else
Nenue@40 97 return ((b.offerEndTime or 0) > (a.offerEndTime or 0))
Nenue@40 98 end
Nenue@40 99 end
Nenue@40 100 end
Nenue@40 101 end
Nenue@40 102 end
Nenue@40 103
Nenue@40 104 function MissionList:OnEvent(event, ...)
Nenue@40 105 self:RefreshData()
Nenue@40 106 if event == 'GARRISON_MISSION_FINISHED' then
Nenue@40 107 local followerTypeID, missionID = ...;
Nenue@40 108 elseif event == 'GARRISON_TALENT_COMPLETE' then
Nenue@40 109 local garrisonType = ...;
Nenue@40 110 elseif event == '' then
Nenue@35 111 end
Nenue@35 112
Nenue@35 113 end
Nenue@35 114
Nenue@35 115 function MissionList:OnShow()
Nenue@35 116 print('|cFF00FF88'..self:GetName()..':OnShow()|r')
Nenue@35 117 end
Nenue@35 118
Nenue@40 119 function ListEntry:OnComplete()
Nenue@35 120 print('flagging complete', self.name)
Nenue@35 121 self:Update()
Nenue@35 122 end
Nenue@35 123
Nenue@40 124 function ListEntry:OnUpdate(sinceLast)
Nenue@40 125 if self.doAnimation then
Nenue@40 126 self.doAnimation = nil
Nenue@40 127 self.NewBlockFade:Play()
Nenue@40 128 end
Nenue@35 129 self.throttle = (self.throttle or .5) + sinceLast
Nenue@35 130 if self.throttle < .5 then
Nenue@35 131 return
Nenue@35 132 else
Nenue@35 133 self.throttle = self.throttle - .5
Nenue@35 134 end
Nenue@40 135
Nenue@35 136 if self.offerEndTime then
Nenue@35 137 self:SetTimeLeft(self.offerEndTime)
Nenue@35 138 elseif self.missionEndTime then
Nenue@35 139 self:SetTimeLeft(self.missionEndTime, self.durationSeconds)
Nenue@35 140 end
Nenue@35 141 end
Nenue@35 142
Nenue@40 143 function ListEntry:OnHide(...)
Nenue@40 144 print(self:GetName().. ':Hide()', ...)
Nenue@40 145 end
Nenue@40 146
Nenue@40 147 function ListEntry:OnLoad()
Nenue@40 148 print('|cFFFF4400'..self:GetName()..':OnLoad()')
Nenue@35 149 self.Count = self.Overlay.Count
Nenue@35 150 self.Name = self.Overlay.Name
Nenue@35 151 self.TimeLeft = self.Overlay.TimeLeft
Nenue@35 152 self.Owner = self.Overlay.Owner
Nenue@35 153 self.maxDisplayed = 10
Nenue@35 154
Nenue@35 155 self.Icon:SetDesaturated(false)
Nenue@35 156 self.Done:Hide()
Nenue@40 157 --[[
Nenue@40 158 hooksecurefunc(self.Background, 'SetColorTexture', function(self, ...)
Nenue@40 159 print(self:GetName(), ...)
Nenue@40 160 end)
Nenue@40 161 hooksecurefunc(self.Background, 'SetTexture', function(self, ...)
Nenue@40 162 --print(self:GetName(), ...)
Nenue@40 163 end)
Nenue@40 164 --]]
Nenue@35 165 end
Nenue@35 166
Nenue@40 167 function ListEntry:Update()
Nenue@35 168 local r,g,b = 1, 1, 1
Nenue@35 169 if self.isRare then
Nenue@35 170 r,g,b = 0.1, 0.4, 1
Nenue@35 171 self.IconBorder:SetVertexColor(r, g, b, 1)
Nenue@35 172 end
Nenue@35 173
Nenue@35 174 --self.missionData = data
Nenue@35 175 self.Name:SetText(self.name)
Nenue@35 176 if #self.rewards >= 1 then
Nenue@35 177 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID))
Nenue@35 178 self.rewardInfo = self.rewards[1]
Nenue@35 179 else
Nenue@35 180 self.Icon:SetAtlas(self.typeAtlas, false)
Nenue@35 181 end
Nenue@35 182
Nenue@40 183 local itemType = db.ClassPlanTypes.inProgress
Nenue@40 184 if self.isComplete then
Nenue@40 185 itemType = db.ClassPlanTypes.complete
Nenue@40 186 end
Nenue@35 187
Nenue@40 188 self.Background:SetColorTexture(unpack(itemType.backgroundColor))
Nenue@35 189 end
Nenue@35 190
Nenue@35 191 function ListEntry:OnEnter()
Nenue@40 192 WorldMap_HijackTooltip(self)
Nenue@35 193 if self.rewardInfo and self.rewardInfo.itemID then
Nenue@40 194 WorldMapTooltip:SetOwner(self, 'ANCHOR_LEFT')
Nenue@40 195 WorldMapTooltip:AddLine(self.name)
Nenue@40 196 EmbeddedItemTooltip_SetItemByID(WorldMapTooltip.ItemTooltip, self.rewardInfo.itemID)
Nenue@40 197 WorldMapTooltip:Show()
Nenue@35 198 end
Nenue@35 199 end
Nenue@35 200
Nenue@35 201 function ListEntry:OnLeave()
Nenue@40 202 WorldMap_RestoreTooltip()
Nenue@40 203 if WorldMapTooltip:IsOwned(self) then
Nenue@40 204 WorldMapTooltip:Hide()
Nenue@35 205 end
Nenue@40 206 end
Nenue@40 207
Nenue@40 208
Nenue@40 209 ClassPlanMissionHandler = CreateFromMixins(ClassPlanHandlerBase, MissionList)
Nenue@40 210 ClassPlanMissionEntryMixin = CreateFromMixins(ClassPlanEntryBase, ListEntry)