comparison ClassPlan.lua @ 6:48001b6a9496

shipment/missions list refresh should commit all result sets
author Nenue
date Fri, 21 Oct 2016 18:10:53 -0400
parents 4e1883842abf
children 802abb8a10ea
comparison
equal deleted inserted replaced
5:4e1883842abf 6:48001b6a9496
24 timers = {}, 24 timers = {},
25 shipments = {}, 25 shipments = {},
26 playerFirst = false, 26 playerFirst = false,
27 prototypes = {} 27 prototypes = {}
28 } 28 }
29 ClassPlanBlockMixin = { 29 ClassPlanMissionMixin = {
30 templateName = 'ClassPlanBlock', 30 templateName = 'ClassPlanMissionEntry',
31 events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_STARTED', 'GARRISON_MISSION_FINISHED'},} 31 events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_STARTED', 'GARRISON_MISSION_FINISHED'},}
32 ClassPlanShipmentMixin = { 32 ClassPlanShipmentMixin = {
33 templateName = 'ClassPlanShipment', 33 templateName = 'ClassPlanShipmentEntry',
34 parent = false, 34 parent = false,
35 point = 'TOPRIGHT', 35 point = 'TOPRIGHT',
36 relativePoint ='TOPRIGHT', 36 relativePoint ='TOPRIGHT',
37 events = {'GARRISON_LANDINGPAGE_SHIPMENTS', 'GARRISON_TALENT_UPDATE', "GARRISON_TALENT_COMPLETE", "GARRISON_SHIPMENT_RECEIVED"}, 37 events = {'GARRISON_LANDINGPAGE_SHIPMENTS', 'GARRISON_TALENT_UPDATE', "GARRISON_TALENT_COMPLETE", "GARRISON_SHIPMENT_RECEIVED"},
38 } 38 }
39 setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanBlockMixin}) 39 setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanMissionMixin})
40 local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanBlockMixin, ClassPlanShipmentMixin 40 local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanMissionMixin, ClassPlanShipmentMixin
41 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop 41 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop
42 42
43 local GetTimeLeftString = function(timeLeft) 43 local GetTimeLeftString = function(timeLeft)
44 local days = floor(timeLeft/(24*3600)) 44 local days = floor(timeLeft/(24*3600))
45 local hours = floor(mod(timeLeft, (24*3600)) / 3600) 45 local hours = floor(mod(timeLeft, (24*3600)) / 3600)
46 local minutes = floor(mod(timeLeft, 3600) / 60) 46 local minutes = floor(mod(timeLeft, 3600) / 60)
47 local seconds = mod(timeLeft, 60) 47 local seconds = mod(timeLeft, 60)
48 if days >= 1 then 48 if days >= 1 then
49 return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h ') or '') 49 return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h') or '')
50 else 50 else
51 return ((hours > 0) and (hours .. 'h ') or '') .. ((minutes > 0) and (minutes .. ' min') or '') 51 return ((hours > 0) and (hours .. 'h') or '') .. ((minutes > 0) and (' ' ..minutes .. ' min') or '')
52 end 52 end
53 end 53 end
54 54
55 MissionsHandler.GetPlayerData = function(self) 55 MissionsHandler.GetPlayerData = function(self)
56 if not self.profile then 56 if not self.profile then
99 99
100 ShipmentsHandler.OnGetItem = function(data) 100 ShipmentsHandler.OnGetItem = function(data)
101 if data.shipmentsTotal then 101 if data.shipmentsTotal then
102 local timeLeft = data.creationTime + data.duration - GI_currentTime 102 local timeLeft = data.creationTime + data.duration - GI_currentTime
103 if (timeLeft <= 0) and (data.shipmentsReady < data.shipmentsTotal) then 103 if (timeLeft <= 0) and (data.shipmentsReady < data.shipmentsTotal) then
104 local numOrders = -1*floor(timeLeft/data.duration) 104 local numOrders = min(-1*floor(timeLeft/data.duration), (data.shipmentsTotal - data.shipmentsReady))
105 105
106 data.originalCreationTime = data.creationTime 106 if not data.originalCreationTime then
107 data.originalShipmentsReady = data.shipmentsReady 107 data.originalCreationTime = data.creationTime
108 data.originalShipmentsReady = data.shipmentsReady
109 end
108 110
109 data.creationTime = data.creationTime + numOrders*data.duration 111 data.creationTime = data.creationTime + numOrders*data.duration
110 data.shipmentsReady = data.shipmentsReady + numOrders 112 data.shipmentsReady = data.shipmentsReady + numOrders
111 print(data.profileKey, 'shipment "'.. data.name..'" reconciling', numOrders, 'lapsed orders. -->', data.creationTime, data.shipmentsReady) 113 print(data.profileKey, 'shipment "'.. data.name..'" reconciling', numOrders, 'lapsed orders. -->', data.creationTime, data.shipmentsReady)
112 end 114 end
121 else 123 else
122 return (a.creationTime) < (b.creationTime) 124 return (a.creationTime) < (b.creationTime)
123 end 125 end
124 end 126 end
125 127
126 local AddShipmentInfo = function(self, shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID) 128 local ShipmentsInfo = {}
129 local AddShipmentInfo = function(shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID)
127 -- early login queries may return empty tables, causing the sorter to compare nil 130 -- early login queries may return empty tables, causing the sorter to compare nil
128 if not creationTime then 131 if not creationTime then
129 return 132 return
130 end 133 end
131 print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) 134 print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
132 tinsert(self.shipments, 135 tinsert(ShipmentsInfo,
133 { 136 {
134 shipmentType = shipmentType, 137 shipmentType = shipmentType,
135 name = name, 138 name = name,
136 icon = texture, 139 icon = texture,
137 shipmentCapacity = shipmentCapacity, 140 shipmentCapacity = shipmentCapacity,
149 end 152 end
150 ShipmentsHandler.GetPlayerData = function (self) 153 ShipmentsHandler.GetPlayerData = function (self)
151 if not self.profile then 154 if not self.profile then
152 return 155 return
153 end 156 end
154 wipe(self.shipments) 157 wipe(ShipmentsInfo)
155 158
156 159
157 local garrisonType = LE_GARRISON_TYPE_7_0 160 local garrisonType = LE_GARRISON_TYPE_7_0
158 local buildings = C_Garrison.GetBuildings(garrisonType); 161 local buildings = C_Garrison.GetBuildings(garrisonType);
159 local shipmentIndex = 0 162 local shipmentIndex = 0
160 --print('Buildings:') 163 --print('Buildings:')
161 for i = 1, #buildings do 164 for i = 1, #buildings do
162 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID); 165 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID);
163 AddShipmentInfo(self, 'Building', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID) 166 AddShipmentInfo('Building', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID)
164 end 167 end
165 168
166 --print('Follower:') 169 --print('Follower:')
167 local followerShipments = C_Garrison.GetFollowerShipments(garrisonType); 170 local followerShipments = C_Garrison.GetFollowerShipments(garrisonType);
168 for i = 1, #followerShipments do 171 for i = 1, #followerShipments do
169 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]); 172 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]);
170 AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID) 173 AddShipmentInfo('Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID)
171 end 174 end
172 175
173 --print('Loose:') 176 --print('Loose:')
174 local looseShipments = C_Garrison.GetLooseShipments(garrisonType) 177 local looseShipments = C_Garrison.GetLooseShipments(garrisonType)
175 for i = 1, #looseShipments do 178 for i = 1, #looseShipments do
176 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]); 179 local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]);
177 AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString) 180 AddShipmentInfo('Misc', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
178 end 181 end
179 182
180 local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player"))); 183 local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player")));
181 -- this is a talent that has completed, but has not been seen in the talent UI yet. 184 -- this is a talent that has completed, but has not been seen in the talent UI yet.
182 local completeTalentID = C_Garrison.GetCompleteTalent(garrisonType); 185 local completeTalentID = C_Garrison.GetCompleteTalent(garrisonType);
184 if (talentTrees) then 187 if (talentTrees) then
185 for treeIndex, tree in ipairs(talentTrees) do 188 for treeIndex, tree in ipairs(talentTrees) do
186 for talentIndex, talent in ipairs(tree) do 189 for talentIndex, talent in ipairs(tree) do
187 local showTalent = false; 190 local showTalent = false;
188 if (talent.isBeingResearched) or (talent.id == completeTalentID) then 191 if (talent.isBeingResearched) or (talent.id == completeTalentID) then
189 AddShipmentInfo(self, 'Talent', talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString) 192 AddShipmentInfo('Talent', talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString)
190 end 193 end
191 end 194 end
192 end 195 end
193 end 196 end
194 197
195 self.profile.shipments = self.profile.shipments or {} 198 self.profile.shipments = self.profile.shipments or {}
196 if #self.shipments >= 1 then 199 wipe(self.profile.shipments)
197 wipe(self.profile.shipments) 200 for index, data in ipairs(ShipmentsInfo) do
198 for index, data in ipairs(self.shipments) do 201 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration))
199 202 tinsert(self.profile.shipments, data)
200 --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration)) 203 end
201 tinsert(self.profile.shipments, data) 204 self.isStale = true
202 end
203 self.isStale = true
204 end
205 205
206 if self:IsVisible() then 206 if self:IsVisible() then
207 self:Refresh() 207 self:Refresh()
208 end 208 end
209 end 209 end
320 end 320 end
321 321
322 function core:OnEvent (event, ...) 322 function core:OnEvent (event, ...)
323 print(event) 323 print(event)
324 if event == 'PLAYER_REGEN_DISABLED' then 324 if event == 'PLAYER_REGEN_DISABLED' then
325 self:SetShown(false) 325 if self:IsVisible() then
326 self.combatHide = true
327 self:SetShown(false)
328 end
329
326 elseif event == 'PLAYER_REGEN_ENABLED' then 330 elseif event == 'PLAYER_REGEN_ENABLED' then
327 self:SetShown(true) 331 if self.combatHide == true then
332 self.combatHide = nil
333 self:SetShown(true)
334 end
328 elseif event == 'PLAYER_LOGIN' then 335 elseif event == 'PLAYER_LOGIN' then
329 if not self.initialized then 336 if not self.initialized then
330 self:Setup() 337 self:Setup()
331 end 338 end
332 elseif self.initialized and self.events[event] then 339 elseif self.initialized and self.events[event] then
506 function MissionsHandler:OnComplete() 513 function MissionsHandler:OnComplete()
507 print('flagging complete', self.name) 514 print('flagging complete', self.name)
508 self:Refresh() 515 self:Refresh()
509 end 516 end
510 517
511 function MissionsHandler:OnUpdate() 518 function MissionsHandler:OnUpdate(sinceLast)
512 if self.isComplete then 519 if self.isComplete then
513 return 520 return
514 end 521 end
522 self.throttle = (self.throttle or .5) + sinceLast
523 if self.throttle >= .5 then
524 self.throttle = self.throttle - .5
525 else
526 return
527 end
528
515 529
516 if self.missionEndTime then 530 if self.missionEndTime then
517 local timeLeft = self.missionEndTime - time() 531 local timeLeft = self.missionEndTime - time()
518 if timeLeft < 0 then 532 if timeLeft < 0 then
519 self:OnComplete() 533 self:OnComplete()
523 if timeLeft > 3600 then 537 if timeLeft > 3600 then
524 self.TimeLeft:SetTextColor(1,1,1) 538 self.TimeLeft:SetTextColor(1,1,1)
525 else 539 else
526 self.TimeLeft:SetTextColor(1,1,0) 540 self.TimeLeft:SetTextColor(1,1,0)
527 end 541 end
528 542 end
529 end 543
544 if not self.isComplete then
545 local progress = (self.missionEndTime - time()) / self.durationSeconds
546 local w = self.ProgressBG:GetWidth()
547 if progress >= 1 then
548 self.ProgressBar:SetWidth(w)
549 else
550 self.ProgressBar:SetWidth(w - (progress * w))
551 end
552
553 self.ProgressBG:Show()
554 self.ProgressBar:Show()
555 else
556 self.ProgressBG:Hide()
557 self.ProgressBar:Hide()
558 end
559
530 else 560 else
531 self.TimeLeft:SetText(self.missionEndTime) 561 self.TimeLeft:SetText(self.missionEndTime)
532 end 562 end
533 end 563 end
534 564
549 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID)) 579 self.Icon:SetTexture(self.rewards[1].icon or GetItemIcon(self.rewards[1].itemID))
550 self.rewardInfo = self.rewards[1] 580 self.rewardInfo = self.rewards[1]
551 else 581 else
552 self.Icon:SetAtlas(self.typeAtlas, false) 582 self.Icon:SetAtlas(self.typeAtlas, false)
553 end 583 end
584
585
554 end 586 end
555 587
556 588
557 function MissionsHandler:OnEnter() 589 function MissionsHandler:OnEnter()
558 if self.rewardInfo and self.rewardInfo.itemID then 590 if self.rewardInfo and self.rewardInfo.itemID then
600 self.Count:SetText(self.shipmentsReady) 632 self.Count:SetText(self.shipmentsReady)
601 self.Done:SetShown(self.shipmentsReady and (self.shipmentsReady >= 1)) 633 self.Done:SetShown(self.shipmentsReady and (self.shipmentsReady >= 1))
602 634
603 635
604 -- flag as complete 636 -- flag as complete
605 if ( self.shipmentsReady == self.shipmentsTotal ) and (not self.isBeingResearched) then 637 if ( self.shipmentsReady >= self.shipmentsTotal ) and (not self.isBeingResearched) then
606 self.Swipe:SetCooldownUNIX(0, 0); 638 self.Swipe:SetCooldownUNIX(0, 0);
607 self.Done:Show(); 639 self.Done:Show();
608 self.isComplete = true 640 self.isComplete = true
609 else 641 else
610 self.Swipe:SetCooldownUNIX(self.creationTime or 0 , self.duration or 0); 642 self.Swipe:SetCooldownUNIX(self.creationTime or 0 , self.duration or 0);
614 self.Background:SetAlpha(hasPickups and 1 or 0.1) 646 self.Background:SetAlpha(hasPickups and 1 or 0.1)
615 end 647 end
616 local time = time 648 local time = time
617 function ShipmentsHandler:OnUpdate() 649 function ShipmentsHandler:OnUpdate()
618 650
619 if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady ~= self.shipmentsTotal) then 651 if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady < self.shipmentsTotal) then
620 local timeLeft = self.creationTime + self.duration - time() 652 local timeLeft = self.creationTime + self.duration - time()
621 self.TimeLeft:SetText('Next: '.. GetTimeLeftString(timeLeft) .. ' |cFFFFFF00'..self.shipmentsTotal..' orders|r') 653 if self.shipmentsReady >= 1 then
622 elseif self.isStale then 654 self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
623 self.TimeLeft:SetText('|cFFFF0000Needs refresh|r') 655 self.TimeLeft:SetTextColor(0,1,0)
656 else
657 self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
658 self.TimeLeft:SetTextColor(1,1,1)
659 end
660 if (timeLeft < 0) then
661 if self.shipmentsReady < self.shipmentsTotal then
662 self.shipmentsReady = self.shipmentsReady + 1
663 self.creationTime = self.creationTime + self.duration
664 -- text will be set on next update
665 end
666 end
667
624 elseif self.isBeingResearched then 668 elseif self.isBeingResearched then
625 self.TimeLeft:SetText(GetTimeLeftString(self.researchStartTime + self.researchDuration - time())) 669 self.TimeLeft:SetText(GetTimeLeftString(self.researchStartTime + self.researchDuration - time()))
670 self.TimeLeft:SetTextColor(1,1,0)
626 else 671 else
627 self.TimeLeft:SetText('Complete!') 672 self.TimeLeft:SetText('Complete!')
673 self.TimeLeft:SetTextColor(0,1,0)
628 end 674 end
629 675
630 end 676 end
631 677
632 function ShipmentsHandler:OnEnter() 678 function ShipmentsHandler:OnEnter()