Mercurial > wow > worldplan
comparison ClassPlanShipments.lua @ 40:589c444d4837
WowAce/Curseforge migration push
| author | Nenue |
|---|---|
| date | Sun, 25 Dec 2016 13:04:57 -0500 |
| parents | 26dfa661daa7 |
| children | b29b35cb8539 |
comparison
equal
deleted
inserted
replaced
| 39:89ddef0594bc | 40:589c444d4837 |
|---|---|
| 1 local _, db = ... | |
| 2 | |
| 3 local wipe, tinsert, ipairs, select = table.wipe, table.insert, ipairs, select | |
| 4 local UnitClass = UnitClass | |
| 5 local time, max, min = time, max, min | |
| 6 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop | |
| 7 | |
| 8 | |
| 9 local CG_GetBuildings = C_Garrison.GetBuildings | |
| 10 local CG_GetFollowerShipments = C_Garrison.GetFollowerShipments | |
| 11 local CG_GetLooseShipments = C_Garrison.GetLooseShipments | |
| 12 local CG_GetTalentTrees = C_Garrison.GetTalentTrees | |
| 13 local CG_GetCompleteTalent = C_Garrison.GetCompleteTalent | |
| 14 local CG_GetLandingPageShipmentInfo = C_Garrison.GetLandingPageShipmentInfo | |
| 15 local CG_GetLandingPageShipmentInfoByContainerID = C_Garrison.GetLandingPageShipmentInfoByContainerID | |
| 16 | |
| 17 local AK_NOTES, RECRUIT_MAJOR, RECRUIT_MINOR, OH_TALENT, NOMI = 2, 4, 8, 16, 32 | |
| 18 | |
| 19 local FollowerTypes = { | |
| 20 ['Pathfinders'] = true, | |
| 21 ['Acolytes'] = true, | |
| 22 } | |
| 23 local ShipmentOrder = { | |
| 24 [AK_NOTES] = 2, | |
| 25 [RECRUIT_MAJOR] = 3, | |
| 26 [RECRUIT_MINOR] = 4, | |
| 27 [NOMI] = 5, | |
| 28 [OH_TALENT] = 6, | |
| 29 } | |
| 30 local SortKey = 'shipmentType' | |
| 31 local SortTable = ShipmentOrder | |
| 32 | |
| 33 local ShipmentList = { | |
| 34 templateName = 'ClassPlanShipmentEntry', | |
| 35 listKey = {'shipments'}, | |
| 36 listTitle = {'Work Orders'}, | |
| 37 events = { | |
| 38 'GARRISON_MISSION_LIST_UPDATE', | |
| 39 'GARRISON_LANDINGPAGE_SHIPMENTS', | |
| 40 'GARRISON_TALENT_UPDATE', | |
| 41 "GARRISON_TALENT_COMPLETE", | |
| 42 "GARRISON_SHIPMENT_RECEIVED", | |
| 43 'GARRISON_FOLLOWER_LIST_UPDATE', | |
| 44 'SHIPMENT_CRAFTER_INFO', | |
| 45 'ITEM_PUSH'}, | |
| 46 } | |
| 47 | |
| 48 local ShipmentEntry = {} | |
| 49 | |
| 50 function ShipmentList:Reanchor() | |
| 51 print('|cFF00FFFF'..self:GetName()..':Reanchor|r') | |
| 52 self:SetPoint('TOPLEFT', ClassOrderPlan.BackgroundInset, 'TOPLEFT') | |
| 53 self:SetPoint('BOTTOMRIGHT', -ClassOrderPlan.BackgroundInset:GetWidth()/2, 0) | |
| 54 end | |
| 55 | |
| 56 do | |
| 57 local ShipmentsInfo = {} | |
| 58 local AddShipmentInfo = function(shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID) | |
| 59 -- early login queries may return empty tables, causing the sorter to compare nil | |
| 60 if not creationTime then | |
| 61 return | |
| 62 end | |
| 63 --print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) | |
| 64 tinsert(ShipmentsInfo, | |
| 65 { | |
| 66 shipmentType = shipmentType, | |
| 67 name = name, | |
| 68 icon = texture, | |
| 69 shipmentCapacity = shipmentCapacity, | |
| 70 shipmentsReady = shipmentsReady, | |
| 71 shipmentsTotal = shipmentsTotal, | |
| 72 creationTime = creationTime, | |
| 73 duration = duration, | |
| 74 timeleftString = timeleftString, | |
| 75 itemName = itemName, | |
| 76 itemIcon = itemIcon, | |
| 77 itemQuality = itemQuality, | |
| 78 itemID = itemID, | |
| 79 followerID = followerID, | |
| 80 }) | |
| 81 print(' ', name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration) | |
| 82 end | |
| 83 function ShipmentList:GetPlayerData () | |
| 84 local profileList = self:GetParent().profile.shipments | |
| 85 wipe(ShipmentsInfo) | |
| 86 | |
| 87 local garrisonType = LE_GARRISON_TYPE_7_0 | |
| 88 local buildings = CG_GetBuildings(garrisonType); | |
| 89 local shipmentIndex = 0 | |
| 90 --print('Buildings:') | |
| 91 for i = 1, #buildings do | |
| 92 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = CG_GetLandingPageShipmentInfo(i); | |
| 93 AddShipmentInfo(RECRUIT_MAJOR, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID) | |
| 94 end | |
| 95 | |
| 96 --print('Follower:') | |
| 97 local followerShipments = CG_GetFollowerShipments(garrisonType); | |
| 98 for i = 1, #followerShipments do | |
| 99 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = CG_GetLandingPageShipmentInfoByContainerID(followerShipments[i]); | |
| 100 AddShipmentInfo(RECRUIT_MINOR, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID) | |
| 101 end | |
| 102 | |
| 103 --print('Loose:') | |
| 104 local looseShipments = CG_GetLooseShipments(garrisonType) | |
| 105 for i = 1, #looseShipments do | |
| 106 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = CG_GetLandingPageShipmentInfoByContainerID(looseShipments[i]); | |
| 107 AddShipmentInfo(AK_NOTES, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) | |
| 108 end | |
| 109 | |
| 110 local talentTrees = CG_GetTalentTrees(garrisonType, select(3, UnitClass("player"))); | |
| 111 -- this is a talent that has completed, but has not been seen in the talent UI yet. | |
| 112 local completeTalentID = CG_GetCompleteTalent(garrisonType); | |
| 113 --print('Talents:') | |
| 114 if (talentTrees) then | |
| 115 for treeIndex, tree in ipairs(talentTrees) do | |
| 116 for talentIndex, talent in ipairs(tree) do | |
| 117 local showTalent = false; | |
| 118 if (talent.isBeingResearched) or (talent.id == completeTalentID) then | |
| 119 AddShipmentInfo(OH_TALENT, talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString) | |
| 120 end | |
| 121 end | |
| 122 end | |
| 123 end | |
| 124 | |
| 125 wipe(profileList) | |
| 126 for index, data in ipairs(ShipmentsInfo) do | |
| 127 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration)) | |
| 128 tinsert(profileList, data) | |
| 129 end | |
| 130 self.isStale = true | |
| 131 return true | |
| 132 end | |
| 133 end | |
| 134 -- Update shipment flags data | |
| 135 local SetActualShipmentTime = function(self) | |
| 136 | |
| 137 if self.isComplete then | |
| 138 return nil, nil | |
| 139 end | |
| 140 | |
| 141 local timestamp = time() | |
| 142 local timeLeft = self.creationTime + self.duration - timestamp | |
| 143 local duration = self.duration * (self.fullDuration and (self.shipmentsTotal - self.shipmentsReady) or 1) | |
| 144 local justFinished = false | |
| 145 while (self.shipmentsReady < self.shipmentsTotal) and (timeLeft <= 0) do | |
| 146 if not self.originalReady then | |
| 147 self.originalReady = self.shipmentsReady | |
| 148 self.originalCreationTime = self.creationTime | |
| 149 end | |
| 150 | |
| 151 self.shipmentsReady = self.shipmentsReady + 1 | |
| 152 self.creationTime = self.creationTime + self.duration | |
| 153 timeLeft = timeLeft + self.duration | |
| 154 print('|cFF00FF88 pre-parse "'..self.name..'"|r', 'timeLeft:', timeLeft, 'shipments:', self.shipmentsReady, self.shipmentsTotal) | |
| 155 end | |
| 156 | |
| 157 if (timeLeft <= 0) and (not self.isBeingResearched) then | |
| 158 self.isComplete = true | |
| 159 self.isStale = true | |
| 160 end | |
| 161 | |
| 162 local expires = (self.originalCreationTime or self.creationTime) + duration | |
| 163 return expires, duration | |
| 164 end | |
| 165 | |
| 166 function ShipmentList:OnEvent(event, ...) | |
| 167 if (event == 'SHIPMENT_CRAFTER_INFO' or event == 'ITEM_PUSH' or event == 'GARRISON_FOLLOWER_LIST_UPDATE') then | |
| 168 C_Garrison.RequestLandingPageShipmentInfo() | |
| 169 elseif event == 'SHIPMENT_UPDATE' then | |
| 170 local shipmentStarted = ... | |
| 171 if shipmentStarted then | |
| 172 C_Garrison.RequestLandingPageShipmentInfo() | |
| 173 end | |
| 174 elseif event == 'GARRISON_LANDINGPAGE_SHIPMENTS' then | |
| 175 --WorldPlan:print("New shipments data received.") | |
| 176 self:RefreshData() | |
| 177 else | |
| 178 ClassPlanHandlerBase.OnEvent(self, event, ...) | |
| 179 end | |
| 180 end | |
| 181 | |
| 182 | |
| 183 function ShipmentList:OnGetItem (data) | |
| 184 if data.shipmentsTotal then | |
| 185 local expires = SetActualShipmentTime(data) | |
| 186 if expires and (expires > time()) then | |
| 187 self:ScheduleUpdate(expires) | |
| 188 end | |
| 189 end | |
| 190 | |
| 191 if data.shipmentType == 255 or type(data.shipmentType == 'string') then | |
| 192 if data.name == 'Artifact Research Notes' then | |
| 193 data.shipmentType = AK_NOTES | |
| 194 elseif string.match(data.name, 'Recipes') then | |
| 195 data.shipmentType = NOMI | |
| 196 elseif FollowerTypes[data.name] then | |
| 197 data.shipmentType = RECRUIT_MINOR | |
| 198 else | |
| 199 data.shipmentType = OH_TALENT | |
| 200 end | |
| 201 end | |
| 202 | |
| 203 | |
| 204 end | |
| 205 | |
| 206 function ShipmentList:OnHeaderClick() | |
| 207 -- flip sort table and key, push a sort and refresh | |
| 208 end | |
| 209 | |
| 210 | |
| 211 ShipmentList.SortHandler = function(a, b) | |
| 212 if a[SortKey] then | |
| 213 if b[SortKey] then | |
| 214 return SortTable[a[SortKey]] < SortTable[b[SortKey]] | |
| 215 else | |
| 216 return true | |
| 217 end | |
| 218 else | |
| 219 if b.isComplete ~= a.isComplete then | |
| 220 return a.isComplete and true or false | |
| 221 else | |
| 222 if a.profileKey ~= b.profileKey then | |
| 223 return a.profileKey < b.profileKey | |
| 224 else | |
| 225 if a.shipmentsReady and b.shipmentsReady then | |
| 226 return (a.shipmentsReady) > (b.shipmentsReady) | |
| 227 elseif a.shipmentsReady or b.shipmentsReady then | |
| 228 return (a.shipmentsReady) or true or false | |
| 229 else | |
| 230 | |
| 231 if (a.creationTime ~= b.creationTime) then | |
| 232 return (a.creationTime) < (b.creationTime) | |
| 233 else | |
| 234 return (a.name) < (b.name) | |
| 235 end | |
| 236 end | |
| 237 | |
| 238 end | |
| 239 end | |
| 240 end | |
| 241 end | |
| 242 | |
| 243 function ShipmentList:OnLoad() | |
| 244 end | |
| 245 function ShipmentList:OnShow() | |
| 246 print('|cFF00FF88'..self:GetName()..':OnShow()|r') | |
| 247 end | |
| 248 | |
| 249 function ShipmentEntry:OnLoad() | |
| 250 ClassPlanMissionEntryMixin.OnLoad(self) | |
| 251 end | |
| 252 | |
| 253 | |
| 254 function ShipmentEntry:Update() | |
| 255 --print(' |cFF00FF88"'.. self.name..'":Update()|r') | |
| 256 self.Icon:SetTexture(self.icon) | |
| 257 self.Count:SetText(self.shipmentsReady ..'/'.. self.shipmentsTotal) | |
| 258 | |
| 259 -- flag as complete | |
| 260 local itemType = db.ClassPlanTypes.inProgress | |
| 261 if ( self.shipmentsReady >= self.shipmentsTotal ) and (not self.isBeingResearched) then | |
| 262 self.Swipe:SetCooldownUNIX(0, 0); | |
| 263 itemType = db.ClassPlanTypes.complete | |
| 264 else | |
| 265 if (self.shipmentsReady >= 1) and (self.shipmentsReady < self.shipmentsTotal) then | |
| 266 itemType = db.ClassPlanTypes.shipmentsReady | |
| 267 end | |
| 268 self.Swipe:SetCooldownUNIX(self.creationTime or 0 , self.duration or 0); | |
| 269 end | |
| 270 self.Background:SetColorTexture(unpack(itemType.backgroundColor)) | |
| 271 | |
| 272 SetActualShipmentTime(self) | |
| 273 self.throttle = 2 | |
| 274 end | |
| 275 | |
| 276 | |
| 277 | |
| 278 function ShipmentEntry:OnUpdate(sinceLast) | |
| 279 self.throttle = (self.throttle or 1) + sinceLast | |
| 280 if self.throttle >= 1 then | |
| 281 self.throttle = self.throttle - 1 | |
| 282 else | |
| 283 return | |
| 284 end | |
| 285 | |
| 286 if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady < self.shipmentsTotal) then | |
| 287 local expires, duration = SetActualShipmentTime(self) | |
| 288 if self.isComplete then | |
| 289 self.TimeLeft:SetText('Complete!') | |
| 290 self.TimeLeft:SetTextColor(0,1,1) | |
| 291 elseif self.shipmentsReady >= 1 then | |
| 292 self:SetTimeLeft(expires, duration) | |
| 293 self.TimeLeft:SetTextColor(1,1,0) | |
| 294 else | |
| 295 self:SetTimeLeft(expires, duration) | |
| 296 self.TimeLeft:SetTextColor(1,1,1) | |
| 297 end | |
| 298 elseif self.isBeingResearched then | |
| 299 self:SetTimeLeft(self.researchStartTime + self.researchDuration - time(), self.researchDuration) | |
| 300 self.TimeLeft:SetTextColor(1,1,1) | |
| 301 else | |
| 302 self.TimeLeft:SetText('Complete!') | |
| 303 self.TimeLeft:SetTextColor(0,1,0) | |
| 304 end | |
| 305 end | |
| 306 | |
| 307 function ShipmentEntry:OnEnter() | |
| 308 if ( self.shipmentsReady and self.shipmentsTotal ) then | |
| 309 GameTooltip:SetOwner(self, 'ANCHOR_LEFT') | |
| 310 GameTooltip:AddLine(self.Owner:GetText(), self.Owner:GetTextColor()) | |
| 311 GameTooltip:AddLine(self.shipmentsReady .. ' of '.. self.shipmentsTotal) | |
| 312 GameTooltip:Show() | |
| 313 end | |
| 314 end | |
| 315 | |
| 316 | |
| 317 function ShipmentEntry:OnLeave() | |
| 318 if GameTooltip:IsOwned(self) then | |
| 319 GameTooltip:Hide() | |
| 320 end | |
| 321 end | |
| 322 | |
| 323 function ShipmentEntry:OnClick(button) | |
| 324 self.fullDuration = not self.fullDuration | |
| 325 self:Update() | |
| 326 end | |
| 327 | |
| 328 ClassPlanShipmentHandler = CreateFromMixins(ClassPlanHandlerBase, ShipmentList) | |
| 329 ClassPlanShipmentEntryMixin = CreateFromMixins(ClassPlanEntryBase, ShipmentEntry) |
