diff ObjectiveTracker/Frame.lua @ 38:1f8f9cc3d956

- module integration brought up to speed with current frame management structure
author Nenue
date Thu, 21 Apr 2016 11:36:41 -0400
parents e84d645c8ab8
children 92534dc793f2
line wrap: on
line diff
--- a/ObjectiveTracker/Frame.lua	Mon Apr 18 07:56:23 2016 -0400
+++ b/ObjectiveTracker/Frame.lua	Thu Apr 21 11:36:41 2016 -0400
@@ -13,14 +13,24 @@
 local Default, AutoQuest, Quest, Bonus, Cheevs = T.DefaultHandler, T.AutoQuest, T.Quest, T.Bonus, T.Cheevs
 local InCombatLockdown, format, lshift, CreateFrame = InCombatLockdown, format, bit.lshift, CreateFrame
 local IsModifiedClick, ChatEdit_GetActiveWindow = IsModifiedClick, ChatEdit_GetActiveWindow
+local band, bor = bit.band, bit.bor
 local print = B.print('Layout')
 local oprint = B.print('Objectives')
 local bprint = B.print('Block')
 local tprint = B.print('Tracker')
 local lprint = B.print('Layout')
 local unitLevel = 1
-local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_REASON
-local debug = false
+
+local ANIM_STATE = 'Animation: %04X'
+local INIT_STATE = 'Init: %04X'
+
+--- Bitfields of import
+--- control value for everything
+local OBJECTIVE_TRACKER_UPDATE_REASON = _G.OBJECTIVE_TRACKER_UPDATE_REASON
+--- flags reason categories where frame layout requires initializing (starts high)
+local initReason = 0xFFFF
+--- flags reason categories where frame anchor updates must be delayed because of an ongoing animation (starts low)
+local animateReason = 0x0000
 
 --- FRAMES
 local Wrapper = _G.VeneerObjectiveWrapper
@@ -65,6 +75,22 @@
 --- END SCHEMA
 local blockPosition
 
+
+local SetAnimate = function(reason, animate)
+  print('comparing', animateReason, reason)
+  if animate then
+    if band(animateReason, reason) == 0 then
+      animateReason = animateReason + reason
+    end
+  else
+    if band(animateReason, reason) > 0 then
+      animateReason = animateReason - reason
+    end
+  end
+  Wrapper.AnimState:SetFormattedText(ANIM_STATE, animateReason)
+end
+
+
 --- schema swapper
 T.UpdateSchema = function(layer, newSchema)
   if not (T.Conf.Schema[layer] and T.Conf.Schema[layer][newSchema]) then
@@ -100,12 +126,31 @@
     textColor = c.textColor
     lineSchema = newSchema
   end
-  tprint('|cFFFF0088UpdateSchema:|r', layer, lastSchema[layer], '->', newSchema)
+  tprint('|cFFFF0088       Schema:|r', layer, lastSchema[layer], '->', newSchema)
 end
 -- todo: figure out why objectives go invisible
 local anchorPoint, anchorFrame
 local abs, GetTime = math.abs, GetTime
 Default.AddTracker = function(handler, frame, index)
+  local isInitialized = true
+  if initReason and (band(initReason, handler.updateReason) > 0 ) then
+    isInitialized = false
+    initReason = initReason - handler.updateReason
+    print('|cFF00FF00%%% initialization status update:', format('%04X', initReason))
+
+    frame.SlideIn:SetScript('OnPlay', function()
+      SetAnimate(handler.updateReasonModule, true)
+    end)
+
+    frame.SlideIn:SetScript('OnFinished',  function()
+      SetAnimate(handler.updateReasonModule, false)
+    end)
+
+    if initReason == 0 then
+      initReason = nil
+    end
+  end
+
   if index == 1 then
     print('|cFF00FF00### beginning wrapper layout -----------------')
     anchorPoint, anchorFrame = 'TOP', Scroll
@@ -114,7 +159,7 @@
 
   frame.destinationOffset = -wrapperHeight
   print(frame.destinationOffset, frame.previousOffset)
-  if  handler.initialized and (abs(frame.previousOffset - frame.destinationOffset) > 0.9) and frame:IsVisible() then
+  if isInitialized and (abs(frame.previousOffset - frame.destinationOffset) > 0.9) and frame:IsVisible() then
     if frame.wasEmpty then
       frame.previousOffset = -Wrapper:GetHeight()
     end
@@ -152,6 +197,8 @@
     frame:ClearAllPoints()
     frame:SetParent(Scroll)
     frame:SetPoint('TOP', Scroll, 'TOP', 0, frame.destinationOffset)
+    frame:SetPoint('LEFT', Scroll, 'LEFT')
+    frame:SetPoint('RIGHT', Scroll, 'RIGHT')
     frame.previousOffset = frame.destinationOffset
     handler.initialized = true
   end
@@ -187,7 +234,7 @@
   print('blockschema', blockSchema, block.schema)
   if blockSchema ~= block.schema then
     T.UpdateSchema('block', block.schema)
-    print('new schema detected, applicating...')
+    print('  ### activating block schema:|cFF0088FF', block.schema)
   end
 
   block:SetWidth(T.Conf.Wrapper.Width)
@@ -260,10 +307,21 @@
 
   block:SetPoint('TOPLEFT', self.frame, 'TOPLEFT', 0, blockPosition)
   block:SetPoint('RIGHT', tracker,'RIGHT', 0, 0)
+  block:Show()
   self.numBlocks = self.numBlocks + 1
   print('    |cFFFFFF00'..tracker.height..'|r', '|cFF00FF00'..block:GetName()..'|r', block.height, tracker.height)
   tracker.height = tracker.height + block.height
   blockPosition = blockPosition - block.height
+
+
+
+  if Devian and Devian.InWorkspace() then
+    block.DebugTab:SetParent(UIParent)
+    block.DebugTab:SetPoint('TOPRIGHT', block, 'TOPLEFT', 0, 0)
+    block.DebugTab.status:SetText(tostring(block.schema) .. ' @|cFF00FF00' .. tostring(block.posIndex) .. '|r #|cFFFFFF00'.. tostring(info.logIndex or info.id) .. '|r'..
+        ' H|cFFFFFF00' .. tostring(block.height) .. ' L|cFF00FFFF' .. tostring(block.numLines) ..'|r')
+    block.DebugTab:Show()
+  end
 end
 
 --- Used as an iterator of sorts for cascaded tag icon placements (the daily/faction/account icons)
@@ -285,6 +343,14 @@
   return tagPoint, tagAnchor, tagRelative
 end
 
+Default.AddReward = function(handler, block, rewardInfo, tagPoint, tagAnchor, tagRelative)
+  local print = bprint
+
+  for order, reward in ipairs(rewardInfo) do
+
+  end
+end
+
 --- Adds the given line to the current content and advances the anchor pointer to that new line for the following call.
 Default.AddLine = function(handler, block, text, attachment, template)
   local print = lprint
@@ -292,27 +358,36 @@
   local line = handler:GetLine(block, lineIndex)
 
   line.index = lineIndex
-  if template then
-    if line.schema ~= template then
+  template = template or 'default'
+  if template and lineSchema ~= template then
       print('      |cFF00FF00change schema', template)
       T.UpdateSchema('line', template)
-      line.status:SetSpacing(textSpacing)
-      line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
-      line.status:SetPoint('RIGHT', line, 'RIGHT',0, 0)
-      line.status:SetTextColor(unpack(textColor))
-      line.schema = template
-    else
-      print('      |cFFFFFF00keep schema', line.schema)
-    end
   end
+  line.status:SetSpacing(textSpacing)
+  line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
+  line.status:SetPoint('RIGHT', line, 'RIGHT',0, 0)
+  line.status:SetTextColor(unpack(textColor))
   line:SetPoint('TOP', block.endPoint, 'BOTTOM', 0, -textSpacing)
   line.status:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
   line:SetPoint('LEFT', block, 'LEFT')
   line:SetPoint('RIGHT', block, 'RIGHT')
   line:Show()
+  line:SetScript('OnMouseUp', function(self, button)
+    handler.OnMouseUp(block, button)
+  end)
 
 
   tprint('      |cFF0088FFAddLine|r (|cFF00FFFF'..tostring(line.schema)..'|r):', line:GetName())
+  --[[
+  for i = 1, line:GetNumPoints() do
+    tprint('      - ', line:GetPoint(i))
+  end
+  tprint('      - ', line:GetSize())
+  tprint('      - ', line:GetParent(), line:GetParent():IsVisible())
+  tprint('      - ', line:IsVisible())
+  --]]
+
+
 
 
   -- fill in the text, then derive pixel-rounded height
@@ -321,6 +396,9 @@
 
   -- For progressbar and timer lines, status text may be used as the title heading
   if attachment then
+    attachment:SetPoint('TOP', line, 'TOP')
+    attachment:SetPoint('LEFT', line, 'LEFT', textIndent, 0)
+    attachment:SetPoint('RIGHT', line, 'RIGHT')
     print('      |cFFFF0088doing things with a widget', attachment:GetSize())
     line.height = attachment:GetHeight()
     if text then
@@ -442,7 +520,6 @@
 
 
 
-
 ----------
 --- Top level methods
 
@@ -528,6 +605,10 @@
     print('|cFF00FF00 ', Scroll:GetPoint(i))
   end
 
+  if Devian and Devian.InWorkspace() then
+    Wrapper.AnimState:SetFormattedText(ANIM_STATE, animateReason)
+  end
+
   Wrapper:Show()
   Scroller:Show()
   Scroll:Show()