diff Modules/WorldState.lua @ 89:74e714637d6a

WorldStateProgress fade-in is called for all visibility check falses
author Nenue
date Fri, 21 Oct 2016 18:03:35 -0400
parents b107b4df7eb6
children 6e2cb847c3c6
line wrap: on
line diff
--- a/Modules/WorldState.lua	Thu Oct 20 04:08:11 2016 -0400
+++ b/Modules/WorldState.lua	Fri Oct 21 18:03:35 2016 -0400
@@ -11,7 +11,7 @@
 VeneerWorldStateCurrencyMixin = {
 }
 VeneerWorldStateProgressMixin = {
-  keepOpen = true
+  keepOpen = true,
 }
 VeneerWorldStateMixin = {
   maxHeight = 0,
@@ -107,10 +107,18 @@
 function VeneerWorldStateMixin:Reanchor(isUpdate)
   print('  |cFF0088FF'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks')
   self.maxHeight = 0
+  local lastFrame
   for i, frame in ipairs(self.modules) do
     print('  '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight())
     if frame:IsShown() then
-      self.maxHeight = max(self.maxHeight, frame:GetHeight())
+      if lastFrame then
+        frame:SetPoint('TOP', lastFrame, 'BOTTOM')
+      else
+        frame:SetPoint('TOP', self, 'TOP')
+      end
+
+      self.maxHeight = self.maxHeight + frame:GetHeight()
+      lastFrame = frame
     end
   end
   if self.maxHeight == 0 then
@@ -179,14 +187,12 @@
 end
 
 function VeneerWorldStateCurrencyMixin:OnLoad ()
-
   self:RegisterEvent("PLAYER_ENTERING_WORLD");
   self:RegisterEvent("ZONE_CHANGED");
   self:RegisterEvent("ZONE_CHANGED_INDOORS");
   self:RegisterEvent("ZONE_CHANGED_NEW_AREA");
   self:RegisterEvent('CURRENCY_DISPLAY_UPDATE')
   self:RegisterEvent('CHAT_MSG_CURRENCY')
-
 end
 
 function VeneerWorldStateCurrencyMixin:OnEvent (event, arg)
@@ -204,7 +210,6 @@
     self.Label:SetFormattedText("%d / %d", earned, totalMax)
     self:Show()
     self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6)
-    self:SetSize(200,16)
   else
     self:Hide()
   end
@@ -292,28 +297,10 @@
 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo
 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank
 
-function VeneerWorldStateProgressMixin:AnimateProgress(progressChange)
 
-  local progressWidth = self:GetWidth() * progressChange
-
-  print('  Render change:', progressChange, progressWidth)
-  self.ProgressAdded:Show()
-  self.ProgressAdded:ClearAllPoints()
-  self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0)
-  self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (progressWidth), 0)
-
-
-  self.ProgressFlash.translation:SetOffset(progressWidth, 0)
-  self.ProgressFlash:Play()
-end
-
-function VeneerWorldStateProgressMixin:Update(isBatchUpdate)
-  local hasNewInfo = false
-  local progressChange = false
-  print('  current mode:', self.mode)
-
-
-  if self.mode == 'xp' then
+local progressHandlers = {
+  xp = function(self)
+    local hasNewInfo, showChange = false, false
     local xp = UnitXP('player')
     local xpMax = UnitXPMax('player')
     local bonusXP = GetXPExhaustion()
@@ -322,27 +309,29 @@
     end
     self.progressText = '|cFFFFCC00' .. UnitLevel('player') .. '|r ' .. xp .. '/' .. xpMax
     if bonusXP then
-      self.ProgressBar:SetColorTexture(0, 0.5,1)
-      self.OverflowBar:Show()
-      self.OverflowBar:ClearAllPoints()
-      self.OverflowBar:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', 0, 0)
+      self.progressOverflow = min(1,(bonusXP / xpMax))
+      self.OverflowBar:SetColorTexture(0.5, 0.5,0.5, 0.25)
+      self.OverflowBar:SetPoint('LEFT', self.ProgressBar, 'LEFT')
     else
-      self.ProgressBar:SetColorTexture(0.5,0,1)
+      self.progressOverflow = nil
     end
-    hasNewInfo = (self.progressAmount ~= xp)
-    progressChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax)
-    self.progressOverflow = bonusXP or 0
+    self.ProgressBar:SetColorTexture(0, 0.5,1,1)
+    self.OverflowAnchor = self.ProgressBar
+    self.hasNewInfo = (self.progressAmount ~= xp)
+    showChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax)
+
     self.progressAmount = xp
     self.progressMax = xpMax
-
-  elseif self.mode == 'artifact' then
+    return hasNewInfo, showChange
+  end,
+  artifact = function(self)
+    local hasNewInfo, showChange = false, false
     local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo()
-
     if itemID then
       local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0
       print('    API:', itemID, name, 'XP:', totalXP, 'Points:', pointsSpent, 'Next:', nextRankCost)
       hasNewInfo = (self.progressAmount ~= totalXP)
-      progressChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost))
+      showChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost))
 
       if totalXP > nextRankCost then
         self.progressPercent = 1
@@ -355,66 +344,103 @@
       self.ProgressBar:SetColorTexture(1,0.5,0,1)
       self.OverflowBar:Hide()
 
-      self.progressOverflow = 0
+      if totalXP > nextRankCost then
+        self.progressText = self.progressText .. ' Level Up!'
+        self.progressOverflow = (totalXP - nextRankCost) / nextRankCost
+        self.OverflowBar:SetPoint('LEFT', self.ProgressBG, 'LEFT')
+        self.OverflowAnchor = self.OverflawBar
+      else
+        self.progressOverflow = nil
+        self.OverflowAnchor = self.ProgressBar
+      end
+
       self.progressAmount = totalXP
       self.progressMax = nextRankCost
     else
-      self.progressOverflow = 0
+      self.progressOverflow = nil
       self.progressAmount = 0
       self.progressMax = 1
       self.progressText = ''
     end
+    return hasNewInfo, showChange
+  end
+}
+
+function VeneerWorldStateProgressMixin:Update(isBatchUpdate)
+
+  local progressChange = false
+  print('  current mode:', self.mode)
+  if (not self.mode) or (not progressHandlers[self.mode]) then
+    self:HidePanel()
+    return
   end
 
-  if self.mode then
-    self:SetSize(600,16)
-    if hasNewInfo then
-      self.timeOut = nil
-      self.timeLived = 0
-      if self.TransitionFadeOut:IsPlaying() then
-        self.TransitionFadeOut:Stop()
-        self:SetAlpha(1)
-      end
-      if not self:IsVisible() then
-        self.TransitionFadeIn:Play()
-      else
-        self:ShowPanel()
-      end
+  local hasNewInfo, showProgress = progressHandlers[self.mode](self)
+  self:SetSize(600,16)
+  if hasNewInfo then
+    self.timeOut = nil
+    self.timeLived = 0
+  end
 
+  if not self:IsVisible() then
+    self.TransitionFadeIn:Play()
+  else
+    self:ShowPanel()
+  end
+
+  print('    Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'new:', hasNewInfo, 'shown:', self:IsShown())
+  print('    Metrics:', self:IsVisible(), self:GetWidth(), self.ProgressBG:GetWidth())
+  if self.progressPercent > 0 then
+    self.ProgressBar:Show()
+    self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0)
+    self.Label:SetText(self.progressText)
+
+    self.ProgressSpark:ClearAllPoints()
+    if self.progressOverflow then
+      print('    Overflow:', self.progressOverflow)
+      self.OverflowBar:Show()
+      self.OverflowBar:SetWidth(self.progressOverflow * self:GetWidth(), 0)
+    else
+      self.OverflowBar:Hide()
     end
+    self.ProgressSpark:SetPoint('CENTER', self.OverflowAnchor, 'RIGHT', 0, 0)
 
+  else
+    self.ProgressBar:Hide()
+  end
 
-    print('    Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'new:', hasNewInfo, 'shown:', self:IsShown())
-    print('    Metrics:', self:IsVisible(), self:GetWidth(), self.ProgressBG:GetWidth())
+  if self.progressOverflow and (self.progressOverflow >= self.progressPercent) then
+    self.OverflowBar:SetDrawLayer('ARTWORK', 1)
+    self.ProgressBar:SetDrawLayer('ARTWORK', 2)
+  else
+    self.OverflowBar:SetDrawLayer('ARTWORK', 2)
+    self.ProgressBar:SetDrawLayer('ARTWORK', 1)
+  end
 
     if progressChange then
-      self:AnimateProgress(progressChange)
-    end
-
-
-    if self.progressPercent > 0 then
-      self.ProgressBar:Show()
-      self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0)
-      self.Label:SetText(self.progressText)
-
-      self.progressLeft = self.progressMax - self.progressAmount
-      if self.progressOverflow >= self.progressLeft then
-
-        self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', 0, 0)
-      else
-        self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', (self.progressOverflow / self.progressMax) * self:GetWidth(), 0)
-      end
-
-    else
-      self.ProgressBar:Hide()
-    end
-  else
-    self:HidePanel()
+    self:AnimateProgress(progressChange)
   end
 
   self.modeChanged = nil
 end
 
+
+function VeneerWorldStateProgressMixin:AnimateProgress(progressChange)
+
+
+  local changeAnchor = (self.progressOverflow and self.OverflowBar) or self.ProgressBar
+  local progressWidth = self:GetWidth() * min(progressChange, changeAnchor:GetWidth())
+
+  self.ProgressAdded:Show()
+  self.ProgressAdded:ClearAllPoints()
+  self.ProgressAdded:SetPoint('TOPRIGHT', changeAnchor, 'TOPRIGHT', 0, 0)
+  self.ProgressAdded:SetPoint('BOTTOMLEFT', changeAnchor, 'BOTTOMRIGHT', - (progressWidth), 0)
+
+  print('  Render change:', progressWidth, changeAnchor)
+  self.ProgressFlash.translation:SetOffset(progressWidth, 0)
+  self.ProgressFlash:Play()
+end
+
 function VeneerWorldStateProgressMixin:OnMouseDown(button)
   if button == 'RightButton' then
     if self.keepOpen then
@@ -425,6 +451,7 @@
     end
     print('keepOpen =', self.keepOpen)
   else
+
     if self.mode == 'xp' then
       self.mode = 'artifact'
     else
@@ -433,6 +460,9 @@
       end
       self.mode = 'xp'
     end
+    print('|cFFFF4400Change mode:', self.mode)
+
+
     self:AnimateMode()
   end