changeset 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 34d9fbf7af20
files ClassPlan.lua ClassPlan.xml
diffstat 2 files changed, 156 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/ClassPlan.lua	Tue Oct 18 01:50:06 2016 -0400
+++ b/ClassPlan.lua	Fri Oct 21 18:10:53 2016 -0400
@@ -26,18 +26,18 @@
   playerFirst = false,
   prototypes = {}
 }
-ClassPlanBlockMixin = {
-  templateName = 'ClassPlanBlock',
+ClassPlanMissionMixin = {
+  templateName = 'ClassPlanMissionEntry',
   events = {'GARRISON_MISSION_LIST_UPDATE', 'GARRISON_MISSION_STARTED', 'GARRISON_MISSION_FINISHED'},}
 ClassPlanShipmentMixin = {
-  templateName = 'ClassPlanShipment',
+  templateName = 'ClassPlanShipmentEntry',
   parent = false,
   point = 'TOPRIGHT',
   relativePoint ='TOPRIGHT',
   events = {'GARRISON_LANDINGPAGE_SHIPMENTS', 'GARRISON_TALENT_UPDATE', "GARRISON_TALENT_COMPLETE", "GARRISON_SHIPMENT_RECEIVED"},
 }
-setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanBlockMixin})
-local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanBlockMixin, ClassPlanShipmentMixin
+setmetatable(ClassPlanShipmentMixin, {__index = ClassPlanMissionMixin})
+local core, MissionsHandler, ShipmentsHandler = ClassOrderPlanCore, ClassPlanMissionMixin, ClassPlanShipmentMixin
 local print = DEVIAN_WORKSPACE and function(...) print('ClassPlan', ...) end or nop
 
 local GetTimeLeftString = function(timeLeft)
@@ -46,9 +46,9 @@
   local minutes = floor(mod(timeLeft, 3600) / 60)
   local seconds = mod(timeLeft, 60)
   if days >= 1 then
-    return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h ') or '')
+    return (days .. 'd' .. ' ') .. ((hours > 0) and (hours .. 'h') or '')
   else
-    return ((hours > 0) and (hours .. 'h ') or '') .. ((minutes > 0) and (minutes .. ' min') or '')
+    return ((hours > 0) and (hours .. 'h') or '') .. ((minutes > 0) and (' ' ..minutes .. ' min') or '')
   end
 end
 
@@ -101,10 +101,12 @@
   if data.shipmentsTotal then
     local timeLeft = data.creationTime + data.duration - GI_currentTime
     if (timeLeft <= 0) and (data.shipmentsReady < data.shipmentsTotal) then
-      local numOrders = -1*floor(timeLeft/data.duration)
+      local numOrders = min(-1*floor(timeLeft/data.duration), (data.shipmentsTotal - data.shipmentsReady))
 
-      data.originalCreationTime = data.creationTime
-      data.originalShipmentsReady = data.shipmentsReady
+      if not data.originalCreationTime then
+        data.originalCreationTime = data.creationTime
+        data.originalShipmentsReady = data.shipmentsReady
+      end
 
       data.creationTime = data.creationTime + numOrders*data.duration
       data.shipmentsReady = data.shipmentsReady + numOrders
@@ -123,13 +125,14 @@
   end
 end
 
-local AddShipmentInfo = function(self, shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID)
+local ShipmentsInfo = {}
+local AddShipmentInfo = function(shipmentType, name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID, followerID)
   -- early login queries may return empty tables, causing the sorter to compare nil
   if not creationTime then
     return
   end
   print(shipmentType, name, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
-  tinsert(self.shipments,
+  tinsert(ShipmentsInfo,
     {
       shipmentType = shipmentType,
       name = name,
@@ -151,7 +154,7 @@
   if not self.profile then
     return
   end
-  wipe(self.shipments)
+  wipe(ShipmentsInfo)
 
 
   local garrisonType = LE_GARRISON_TYPE_7_0
@@ -160,21 +163,21 @@
   --print('Buildings:')
   for i = 1, #buildings do
     local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID = C_Garrison.GetLandingPageShipmentInfo(buildingID);
-    AddShipmentInfo(self, 'Building', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID)
+    AddShipmentInfo('Building', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, itemName, itemIcon, itemQuality, itemID)
   end
 
   --print('Follower:')
   local followerShipments = C_Garrison.GetFollowerShipments(garrisonType);
   for i = 1, #followerShipments do
     local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, _, _, _, _, followerID = C_Garrison.GetLandingPageShipmentInfoByContainerID(followerShipments[i]);
-    AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID)
+    AddShipmentInfo('Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString, nil, nil, nil, nil, followerID)
   end
 
   --print('Loose:')
   local looseShipments = C_Garrison.GetLooseShipments(garrisonType)
   for i = 1, #looseShipments do
     local name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString = C_Garrison.GetLandingPageShipmentInfoByContainerID(looseShipments[i]);
-    AddShipmentInfo(self, 'Follower', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
+    AddShipmentInfo('Misc', name, texture, shipmentCapacity, shipmentsReady, shipmentsTotal, creationTime, duration, timeleftString)
   end
 
   local talentTrees = C_Garrison.GetTalentTrees(garrisonType, select(3, UnitClass("player")));
@@ -186,22 +189,19 @@
       for talentIndex, talent in ipairs(tree) do
         local showTalent = false;
         if (talent.isBeingResearched) or (talent.id == completeTalentID) then
-          AddShipmentInfo(self, 'Talent', talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString)
+          AddShipmentInfo('Talent', talent.name, talent.icon, 1, (talent.isBeingResearched and 0 or 1), 1, talent.researchStartTime, talent.researchDuration, talent.timeleftString)
         end
       end
     end
   end
 
   self.profile.shipments = self.profile.shipments or {}
-  if #self.shipments >= 1 then
-    wipe(self.profile.shipments)
-    for index, data in ipairs(self.shipments) do
-
-      --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration))
-      tinsert(self.profile.shipments, data)
-    end
-    self.isStale = true
+  wipe(self.profile.shipments)
+  for index, data in ipairs(ShipmentsInfo) do
+    --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration))
+    tinsert(self.profile.shipments, data)
   end
+  self.isStale = true
 
   if self:IsVisible() then
     self:Refresh()
@@ -322,9 +322,16 @@
 function core:OnEvent (event, ...)
   print(event)
   if event == 'PLAYER_REGEN_DISABLED' then
-    self:SetShown(false)
+    if self:IsVisible() then
+      self.combatHide = true
+      self:SetShown(false)
+    end
+
   elseif event == 'PLAYER_REGEN_ENABLED' then
-    self:SetShown(true)
+    if self.combatHide == true then
+      self.combatHide = nil
+      self:SetShown(true)
+    end
   elseif event == 'PLAYER_LOGIN' then
     if not self.initialized then
       self:Setup()
@@ -508,10 +515,17 @@
   self:Refresh()
 end
 
-function MissionsHandler:OnUpdate()
+function MissionsHandler:OnUpdate(sinceLast)
   if self.isComplete then
     return
   end
+  self.throttle = (self.throttle or .5) + sinceLast
+  if self.throttle >= .5 then
+    self.throttle = self.throttle - .5
+  else
+    return
+  end
+
 
   if self.missionEndTime then
     local timeLeft = self.missionEndTime - time()
@@ -525,8 +539,24 @@
       else
         self.TimeLeft:SetTextColor(1,1,0)
       end
+    end
 
+    if not self.isComplete then
+      local progress = (self.missionEndTime - time()) / self.durationSeconds
+      local w = self.ProgressBG:GetWidth()
+      if progress >= 1 then
+        self.ProgressBar:SetWidth(w)
+      else
+        self.ProgressBar:SetWidth(w - (progress * w))
+      end
+
+      self.ProgressBG:Show()
+      self.ProgressBar:Show()
+    else
+      self.ProgressBG:Hide()
+      self.ProgressBar:Hide()
     end
+
   else
     self.TimeLeft:SetText(self.missionEndTime)
   end
@@ -551,6 +581,8 @@
   else
     self.Icon:SetAtlas(self.typeAtlas, false)
   end
+
+
 end
 
 
@@ -602,7 +634,7 @@
 
 
   -- flag as complete
-  if ( self.shipmentsReady == self.shipmentsTotal ) and (not self.isBeingResearched) then
+  if ( self.shipmentsReady >= self.shipmentsTotal ) and (not self.isBeingResearched) then
     self.Swipe:SetCooldownUNIX(0, 0);
     self.Done:Show();
     self.isComplete = true
@@ -616,15 +648,29 @@
 local time = time
 function ShipmentsHandler:OnUpdate()
 
-  if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady ~= self.shipmentsTotal) then
+  if (self.shipmentsReady and self.shipmentsTotal) and (self.shipmentsReady < self.shipmentsTotal) then
     local timeLeft = self.creationTime + self.duration - time()
-    self.TimeLeft:SetText('Next: '.. GetTimeLeftString(timeLeft) .. ' |cFFFFFF00'..self.shipmentsTotal..' orders|r')
-  elseif self.isStale then
-    self.TimeLeft:SetText('|cFFFF0000Needs refresh|r')
+    if self.shipmentsReady >= 1 then
+      self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
+      self.TimeLeft:SetTextColor(0,1,0)
+    else
+      self.TimeLeft:SetText(GetTimeLeftString(timeLeft))
+      self.TimeLeft:SetTextColor(1,1,1)
+    end
+    if (timeLeft < 0) then
+      if self.shipmentsReady < self.shipmentsTotal then
+        self.shipmentsReady = self.shipmentsReady + 1
+        self.creationTime = self.creationTime + self.duration
+        -- text will be set on next update
+      end
+    end
+
   elseif self.isBeingResearched then
     self.TimeLeft:SetText(GetTimeLeftString(self.researchStartTime + self.researchDuration - time()))
+    self.TimeLeft:SetTextColor(1,1,0)
   else
     self.TimeLeft:SetText('Complete!')
+    self.TimeLeft:SetTextColor(0,1,0)
   end
 
 end
--- a/ClassPlan.xml	Tue Oct 18 01:50:06 2016 -0400
+++ b/ClassPlan.xml	Fri Oct 21 18:10:53 2016 -0400
@@ -21,7 +21,7 @@
       </Layer>
       <Layer level="ARTWORK">
 
-        <Texture parentKey="Grip" alphaMode="BLEND" file="Interface\RaidFrame\Raid-Move-Down">
+        <Texture parentKey="Grip" alphaMode="BLEND" file="Interface\RaidFrame\Raid-Move-Down" hidden="true">
           <Anchors>
             <Anchor point="TOP" />
           </Anchors>
@@ -78,9 +78,16 @@
   </Frame>
 
 
-  <Button name="ClassPlanBlock" mixin="ClassPlanBlockMixin" virtual="true" hidden="true">
-    <Size x="400" y="24" />
+  <Button name="ClassPlanListEntryTemplate" virtual="true" hidden="true">
+
     <Scripts>
+      <OnLoad>
+        self.Count = self.Overlay.Count
+        self.Name = self.Overlay.Name
+        self.TimeLeft = self.Overlay.TimeLeft
+        self.Owner = self.Overlay.Owner
+      </OnLoad>
+      <OnClick method="OnClick" />
       <OnUpdate method="OnUpdate" />
       <OnShow method="OnShow" />
       <OnEnter method="OnEnter" />
@@ -88,67 +95,42 @@
     </Scripts>
     <Layers>
       <Layer level="BACKGROUND">
-        <Texture setAllPoints="true" parentKey="Background">
-          <Color a=".5" r="0" g="0" b="0" />
-        </Texture>
-      </Layer>
-      <Layer level="ARTWORK">
-        <Texture name="$parentIcon" parentKey="Icon">
-          <Size x="24" y="24" />
-          <Anchors>
-            <Anchor point="TOPLEFT" />
-          </Anchors>
-          <TexCoords left="0.15" right=".85" top="0.15" bottom="0.85" />
-        </Texture>
-      </Layer>
-      <Layer level="OVERLAY">
-        <FontString name="$parentName" inherits="ClassPlanFont" parentKey="Name" text="base text">
-          <Anchors>
-            <Anchor point="LEFT" relativePoint="RIGHT" relativeKey="$parent.Icon" x="4" y="0" />
-          </Anchors>
-        </FontString>
-        <FontString name="$parentTimeLeft" inherits="ClassPlanNumberFont" parentKey="TimeLeft" text="base text">
-          <Anchors>
-            <Anchor point="RIGHT" x="-4" y="0" />
-          </Anchors>
-        </FontString>
-      </Layer>
-      <Layer level="HIGHLIGHT">
-        <Texture setAllPoints="true" alphaMode="ADD">
-          <Color a="1" r="0.1" g="0.1" b="0.1" />
-        </Texture>
-        <FontString name="$parentOwner" inherits="ClassPlanFont" parentKey="Owner" text="base text">
-          <Anchors>
-            <Anchor point="RIGHT" relativePoint="LEFT" x="-4" y="0" relativeKey="$parent.TimeLeft" />
-          </Anchors>
-        </FontString>
-      </Layer>
-    </Layers>
-  </Button>
-
-  <Button name="ClassPlanShipment" mixin="ClassPlanShipmentMixin" virtual="true">
-    <Scripts>
-      <OnClick method="OnClick" />
-      <OnUpdate method="OnUpdate" />
-      <OnShow method="OnShow" />
-      <OnEnter method="OnEnter" />
-      <OnLeave method="OnLeave" />
-    </Scripts>
-    <Size x="200" y="32" />
-    <Layers>
-      <Layer level="BACKGROUND">
         <Texture parentKey="Background" setAllPoints="true" />
       </Layer>
       <Layer level="BACKGROUND" textureSubLevel="1">
         <Texture parentKey="Icon" alpha="1" desaturated="true">
-          <Size x="32" y="32"/>
+          <Size x="24" y="24"/>
           <Anchors>
             <Anchor point="LEFT"/>
           </Anchors>
           <TexCoords left="0.15" right=".85" top="0.15" bottom="0.85" />
         </Texture>
+
+        <Texture parentKey="ProgressBG" hidden="true">
+          <Size y="2" />
+          <Anchors>
+            <Anchor point="RIGHT" />
+            <Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" relativeKey="$parent.Icon" />
+          </Anchors>
+          <Color a="0.5" r="0" g="0" b="0" />
+        </Texture>
       </Layer>
       <Layer level="BORDER">
+        <Texture parentKey="IconBorder" file="Interface\Common\WhiteIconFrame">
+          <Size x="24" y="24"/>
+          <Anchors>
+            <Anchor point="CENTER" relativeKey="$parent.Icon"/>
+          </Anchors>
+        </Texture>
+        <Texture parentKey="ProgressBar" hidden="true">
+          <Size y="1" />
+          <Anchors>
+            <Anchor point="BOTTOMLEFT" relativeKey="$parent.ProgressBG" />
+          </Anchors>
+          <Color a="0.5" r="1" g="1" b="1" />
+        </Texture>
+      </Layer>
+      <Layer level="ARTWORK">
         <Texture parentKey="Done" atlas="GarrLanding-ShipmentCompleteGlow">
           <Size x="24" y="24" />
           <Anchors>
@@ -156,41 +138,13 @@
           </Anchors>
         </Texture>
       </Layer>
-      <Layer level="ARTWORK">
-        <FontString parentKey="Name" inherits="ClassPlanFont" justifyV="TOP" justifyH="CENTER">
-          <Anchors>
-            <Anchor point="TOPLEFT" relativePoint="TOPRIGHT" relativeKey="$parent.Icon" x="2" y="-2"/>
-          </Anchors>
-          <Color r=".75" g=".75" b=".73"/>
-        </FontString>
-      </Layer>
-      <Layer level="OVERLAY">
-        <FontString parentKey="TimeLeft" inherits="ClassPlanFont" justifyH="CENTER">
-          <Anchors>
-            <Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" relativeKey="$parent.Name" x="0" y="-2"/>
-          </Anchors>
-        </FontString>
-        <FontString parentKey="Count" inherits="WorldPlanFont" justifyH="CENTER">
-          <Anchors>
-            <Anchor point="BOTTOMRIGHT" relativeKey="$parent.Icon" x="0" y="0"/>
-          </Anchors>
-        </FontString>
-      </Layer>
-      <Layer level="HIGHLIGHT">
-
-        <FontString name="$parentOwner" inherits="WorldPlanFont" parentKey="Owner" text="base text">
-          <Anchors>
-            <Anchor point="TOPRIGHT" x="-2" y="-2" />
-          </Anchors>
-        </FontString>
-      </Layer>
     </Layers>
     <Frames>
       <Cooldown parentKey="Swipe" inherits="CooldownFrameTemplate" reverse="true" hideCountdownNumbers="true">
-        <Size x="32" y="32"/>
+        <Size x="24" y="24"/>
         <Anchors>
           <Anchor point="TOPLEFT"/>
-          <Anchor point="BOTTOMRIGHT" relativePoint="BOTTOMLEFT" x="32" y="0" />
+          <Anchor point="BOTTOMRIGHT" relativePoint="BOTTOMLEFT" x="24" y="0" />
         </Anchors>
         <Scripts>
           <OnCooldownStart>
@@ -202,6 +156,46 @@
           </OnCoolDownDone>
         </Scripts>
       </Cooldown>
+      <Frame parentKey="Overlay" name="$parentOverlay" setAllPoints="true">
+        <Layers>
+          <Layer level="OVERLAY">
+
+            <FontString parentKey="Name" inherits="ClassPlanFont" justifyV="TOP" justifyH="CENTER">
+              <Anchors>
+                <Anchor point="LEFT" x="26" y="0"/>
+              </Anchors>
+              <Color r=".75" g=".75" b=".73"/>
+            </FontString>
+            <FontString parentKey="TimeLeft" inherits="ClassPlanFont" justifyH="CENTER">
+              <Anchors>
+                <Anchor point="RIGHT" x="-2" y="0"/>
+              </Anchors>
+            </FontString>
+            <FontString parentKey="Count" inherits="WorldPlanFont" justifyH="CENTER">
+              <Anchors>
+                <Anchor point="CENTER" relativePoint="LEFT" x="12" y="0"/>
+              </Anchors>
+            </FontString>
+          </Layer>
+          <Layer level="HIGHLIGHT">
+
+            <FontString parentKey="Owner" inherits="WorldPlanFont" text="base text">
+              <Anchors>
+                <Anchor point="TOPRIGHT" x="-2" y="-2" />
+              </Anchors>
+            </FontString>
+          </Layer>
+        </Layers>
+      </Frame>
     </Frames>
   </Button>
+
+
+  <Button name="ClassPlanMissionEntry" inherits="ClassPlanListEntryTemplate" mixin="ClassPlanMissionMixin" virtual="true">
+    <Size x="300" y="24" />
+  </Button>
+
+  <Button name="ClassPlanShipmentEntry" inherits="ClassPlanListEntryTemplate" mixin="ClassPlanShipmentMixin" virtual="true">
+    <Size x="300" y="24" />
+  </Button>
 </Ui>
\ No newline at end of file