diff ObjectiveFrame.lua @ 10:f03c75f63566

ObjectiveStyle & ObjectiveFrame - abstract aesthetic details away from ObjectiveFrame - revise SetBlockStyle into a more general algorithm for every frame - implement caching of resolved attribute combinations - use loadstring functions to store resolved attributes and call upon those when, for example, a MouseUp leads a tracker block to restore its original style
author Nenue
date Sat, 02 Apr 2016 03:19:25 -0400
parents 2698173edd40
children 8238cddaddb1
line wrap: on
line diff
--- a/ObjectiveFrame.lua	Fri Apr 01 14:54:01 2016 -0400
+++ b/ObjectiveFrame.lua	Sat Apr 02 03:19:25 2016 -0400
@@ -4,11 +4,11 @@
 -- @file-revision@ @file-hash@
 -- Created: 3/30/2016 12:49 AM
 local B = select(2,...).frame
+local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
 local ipairs, max, min, unpack, floor, pairs, tostring, type = ipairs, max, min, unpack, floor, pairs, tostring, type
 local IsResting, UnitXP, UnitXPMax, GetXPExhaustion = IsResting, UnitXP, UnitXPMax, GetXPExhaustion
 local UnitLevel, IsQuestWatched, UIParent = UnitLevel, IsQuestWatched, UIParent
 local CreateFrame = CreateFrame
-local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
 local print = B.print('Objectives')
 --------------------------------------------------------------------
 --- Global frame layout
@@ -26,7 +26,7 @@
 local scrollWidth, scrollHeight
 local previousBlock
 local currentBlock
---- todo: map these into config table when its sorted out
+--- todo: source these from config
 local itemButtonSize, itemButtonSpacing =  36, 1
 local titleFont, textFont = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]]
 local titleSize, textSize = 15, 15
@@ -40,110 +40,13 @@
 local wrapperPosition = {'RIGHT', UIParent, 'RIGHT', -84, 0}
 
 --- These are mostly aesthetic choices so it lives here
-mod.defaults = {
-  ObjectiveTrackerAnchor = {'BOTTOM', 'RIGHT'},
-  ObjectiveTrackerParent = 'DebuffButton',
-  ObjectiveTrackerSize = {250, 600},
-  ObjectiveWrapperParent = '',
-  WrapperStyle = {
-    Header = {
-      Background = {Left = '', Right = '', Tile = ''},
-      BackgroundCrop = {Left = {0, 0.4, 0,1}, Right={0.6,1,0,1}, Tile = {0.4,.6,0,1,}},
-      BackgroundScale = {Left = 100, Right = 100},
-      Font = {wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline}
-    }
-  },
-  ObjectiveHeaderStyle = {
-    Normal = {
-      Gradient = {MinColor = {.05,.15,0.5,0.7}, MaxColor = {.05,.15,0.5,.35}},
-      Font = {headerFont, headerSize, headerOutline}, Spacing = headerSpacing,
-    }
-  },
-  ObjectiveTrackerStyle = {
-    Normal = {
-      Title = {
-        Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}},
-        Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing,
-      },
-      Text = {
-        Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}},
-        Font = {textFont, textSize, textOutline}, Spacing = textSpacing,
-      },
-    },
-    Super = {
-      Title = {
-        Gradient = { MinColor = {0, .7, .6, .8}, MaxColor = {0, .7, .6, 0.2}},
-        Font = {titleFont, titleSize, titleOutline},
-        Spacing = titleSpacing, BackgroundFullWidth = true
-      },
-      Text = {
-        Gradient = { MinColor = {0, .7, .6, 0.5}, MaxColor = {0, .7, .6, 0.1} },
-        Font = {textFont, textSize, textOutline}, Spacing = textSpacing,
-      },
-    },
-    Active = {
-      Title = {
-        Gradient = {          MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .4},        },
-        Font = {titleFont, titleSize, titleOutline},
-        Spacing = titleSpacing,
-        BackgroundFullWidth = true
-      },
-      Text = {
-        Gradient = {          MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .2},        },
-        Font = {textFont, textSize, textOutline},
-        Spacing = textSpacing,
-        BackgroundFullWidth = true
-      }
-    },
-    Complete = {
-      Title = {
-        Gradient = {          MinColor = {0, 1, 0, 0.34},          MaxColor = {0, 1, 0, .17},        },
-        Font = {titleFont, titleSize, titleOutline},        Spacing = titleSpacing,
-        BackgroundFullWidth = true
-      },
-      Text = {
-        Gradient = {          MinColor = {0, 1, 0, .25},          MaxColor = {0, 1, 0, 0.12},        },
-        Font = {textFont, textSize, textOutline},        Spacing = textSpacing,
-        BackgroundFullWidth = true
-      }
-    },
-    CheevNormal = {
 
-      Title = {
-        Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}},
-        Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing,
-      },
-      Text = {
-        Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}},
-        Font = {textFont, textSize, textOutline}, Spacing = textSpacing,
-      },
-    },
-    CheevComplete = {
-
-      Title = {
-        Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}},
-        Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing,
-      },
-      Text = {
-        Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}},
-        Font = {textFont, textSize, textOutline}, Spacing = textSpacing,
-      },
-    }
-  }
-}
-
-local FontBank = {
-  ['Normal'] = VeneerCriteriaFontNormal,
-  ['Progress'] = VeneerCriteriaFontProgress,
-  ['Complete'] = VeneerCriteriaFontComplete,
-  ['Failed'] = VeneerCriteriaFontFailed,
-}
 
 local Scroller_OnShow = function()
   Wrapper.watchMoneyReasons = 0;
   mod.UpdateWrapper()
   mod.SetEvents()
-  for i, region in ipairs(Wrapper.header) do
+  for i, region in ipairs(Wrapper.headerComplex) do
     region:Show()
   end
 end
@@ -152,7 +55,7 @@
   local self = Wrapper
   Wrapper:UnregisterAllEvents()
   Wrapper:SetScript('OnEvent', nil)
-  for i, region in ipairs(Wrapper.header) do
+  for i, region in ipairs(Wrapper.headerComplex) do
     region:Hide()
   end
 end
@@ -183,9 +86,6 @@
 
 mod.InitializeTrackers = function()
 
-  local c = mod.defaults.ObjectiveHeaderStyle.Normal
-  local g1, g2, g3, g4 = unpack(c.Gradient.MinColor)
-  local h1, h2, h3, h4 = unpack(c.Gradient.MaxColor)
 
   for i, name in ipairs(orderedNames) do
     if not mod.orderedHandlers[i] then
@@ -193,19 +93,16 @@
         local handler = mod[name]
 
         local tracker = CreateFrame('Frame', 'Veneer'..name..'Tracker', Scroll, 'VeneerTrackerTemplate')
-        tracker.header:SetText(handler.name)
-        tracker.header:SetHeight(headerHeight)
-        tracker.header:SetFont(unpack(c.Font))
-        tracker.header:SetTextColor(unpack(headerColor))
-
-        tracker.headerbg:SetGradientAlpha('HORIZONTAL', g1, g2 ,g3, g4, h1, h2, h3, h4)
-        tracker.headerbg:SetHeight(headerHeight)
+        tracker.title:SetText(name)
+        mod.SetBlockStyle(tracker, 'Tracker', 'Normal')
 
         handler.Tracker = tracker
         mod.orderedTrackers[i] = tracker
         mod.namedTrackers[name] = tracker
         mod.indexedTrackers[handler] = tracker
         print('created new tracker frames for new handler')
+
+
       end
     end
   end
@@ -301,80 +198,18 @@
   end
 end
 
-mod.UpdateReputation = function(self)
-end
 
---- Argument containers
-local a1, a2, a3, a4, b1, b2, b3, b4, f1, f2, f3, w1, w2
-mod.SetBlockStyle = function(block, name)
-  -- var names intended to reflect argument order
-  --@debug@
-  local c = mod.defaults.ObjectiveTrackerStyle[name]
-  --@end-debug@
-  --[===[@non-debug
-  local c = mod.Conf
-  --@end-non-debug]===]
-  a1, a2, a3, a4 = unpack(c.Title.Gradient.MinColor)
-  b1, b2, b3, b4 = unpack(c.Title.Gradient.MaxColor)
-  block.titlebg:SetGradientAlpha('HORIZONTAL', a1, a2, a3, a4, b1, b2, b3, b4)
-
-  a1, a2, a3, a4 = unpack(c.Text.Gradient.MinColor)
-  b1, b2, b3, b4 = unpack(c.Text.Gradient.MaxColor)
-  block.bg:SetGradientAlpha('HORIZONTAL', a1, a2, a3, a4, b1, b2, b3, b4)
-
-  f1, f2, f3 = unpack(c.Title.Font)
-  block.title:SetFont(f1, f2, f3)
-
-  f1, f2 ,f3 = unpack(c.Text.Font)
-  block.objectives:SetFont(f1,f2,f3)
-
-  w1 = Wrapper:GetWidth()
-  w2 = (c.Title.BackgroundFullWidth and w1 or  block.title:GetStringWidth())
-
-  local titleSpacing, titleSpacing2 = c.Title.Spacing, (c.Title.Spacing * 2)
-  local textSpacing, textSpacing2 = c.Text.Spacing, (c.Text.Spacing * 2)
-
-  if block.info.isTrivial then
-    block.title:SetTextColor(0.7, 0.7, 0.7, 1)
-  elseif block.info.isComplete then
-    block.title:SetTextColor(1,1,1,1)
-  else
-    block.title:SetTextColor(0,.7,1,1)
-  end
-  block.title:SetSpacing(titleSpacing)
-  block.objectives:SetSpacing(textSpacing)
-  block.objectives:SetWordWrap(true)
-
-  local titleHeight, textHeight = block.title:GetStringHeight(), block.objectives:GetStringHeight() + block.attachmentHeight
-  local blockHeight = titleHeight + titleSpacing2 + textHeight + textSpacing2
-  local blockWidth = wrapperMaxWidth
-
-  block.titlebg:SetSize(min(w1, w2), titleHeight + titleSpacing2)
-  block.bg:SetSize(w1, textHeight + textSpacing2)
-  block:SetSize(blockWidth, blockHeight)
-
-  block.title:SetPoint('TOPLEFT', block.titlebg, 'TOPLEFT', 0, -titleSpacing)
-  block.objectives:SetPoint('TOPLEFT', block.titlebg, 'BOTTOMLEFT', textIndent, -textSpacing)
-
-  -- store
-  block.titleHeight = titleHeight
-  block.textHeight = textHeight
-  block.width = blockWidth
-  block.height = blockHeight
-
-  print('    |cFF00FFFF'..block:GetName()..'|r:|cFF0088FFSetStyle|r(', blockWidth, 'x', blockHeight, '(textH', textHeight,', titleH', titleHeight, ')')
-end
 
 local segments = {'Left', 'Right', 'Tile'}
 mod.UpdateWrapperStyle = function()
-  local c = mod.defaults.WrapperStyle
-  for _, segment in ipairs(segments) do
-    Wrapper['Background'..segment]:SetAtlas(c.Header.Background[segment])
-    Wrapper['Background'..segment]:SetTexCoord(unpack(c.Header.BackgroundCrop[segment]))
-    if c.Header.BackgroundScale[segment] then
-    Wrapper['Background'..segment]:SetWidth(c.Header.BackgroundScale[segment])
+  --[[for _, segment in ipairs(segments) do
+    local texture, a1, a2, a3, a4, width = unpack(mod.defaults.Style.Wrapper.BackgroundComplex[segment])
+    Wrapper['Background'..segment]:SetAtlas(texture)
+    Wrapper['Background'..segment]:SetTexCoord(a1, a2, a3, a4)
+    if width then
+      Wrapper['Background'..segment]:SetWidth(width)
     end
-  end
+  end]]
 end
 
 --- Updates the selected block frame to display the given info batch
@@ -383,20 +218,19 @@
 -- @param info the reference returned by the GetXInfo functions
 -- REMEMBER: t.info and questData[questID] are the same table
 mod.UpdateTrackerBlock = function (handler, blockIndex, info)
+  local print = B.print('ObjectiveBlockParse')
   print('  |cFF00FFFFUpdateTrackerBlock('..blockIndex..'|r')
   if not blockIndex or not info then
     return
   end
 
+  local mainStyle = 'Normal'
+  local subStyle
   local tracker = handler.Tracker
 
   local t = handler:GetBlock(blockIndex)
   if previousBlock then
-    if blockIndex == 1 then
-      t:SetPoint('TOPLEFT', previousBlock, 'TOPLEFT', 0, -headerHeight)
-    else
-      t:SetPoint('TOPLEFT', previousBlock, 'BOTTOMLEFT', 0, 0)
-    end
+    t:SetPoint('TOPLEFT', previousBlock, 'BOTTOMLEFT', 0, 0)
     t:SetPoint('RIGHT', tracker,'RIGHT', 0, 0)
   end
   --print(t:GetName(), t:GetSize())
@@ -421,38 +255,38 @@
 
   t.attachmentHeight = 0
   if info.isComplete then
-    t.objectives:Show()
-    t.objectives:SetText(info.completionText)
+    t.status:Show()
+    t.status:SetText(info.completionText)
   elseif info.numObjectives >= 1 then
     t.attachmentHeight = textSpacing
-    t.objectives:Show()
-    print('  - objective lines:', info.numObjectives, 'can wrap:', t.objectives:CanWordWrap())
+    t.status:Show()
+    print('  - objective lines:', info.numObjectives, 'can wrap:', t.status:CanWordWrap())
 
     local text = ''
 
     --- todo: implement objective displays
      -- in an accumulator loop, call upon handler for the appropriate display frame, each defining:
-      -- * height of whatever display widget is involved in conveying the task
-      -- * number of non-wrapped text lines to account for line space; may be discarded depending on things
-      -- * boolean that determines listening for money events or not
-    t.attachmentHeight, text = mod.UpdateObjectives(t, info, text)
+      -- * height   - height of whatever display widget is involved in conveying the task
+      -- * lines    - number of non-wrapped text lines to account for line space; may be discarded depending on things
+      -- * money    - boolean that determines listening for money events or not
+      -- * progress - number ranging 0 to 2 indicating none/partial/full completion respectively
+    text = mod.UpdateObjectives(t, info, text)
 
-    t.objectives:SetText(text)
-    t.objectives:SetWordWrap(true)
-
-
+    t.status:SetText(text)
+    t.status:SetWordWrap(true)
 
   elseif info.description then
-    t.objectives:SetText(info.description)
-    t.objectives:SetWordWrap(true)
+    t.status:SetText(info.description)
+    t.status:SetWordWrap(true)
   else
-    t.objectives:SetText(nil)
+    t.status:SetText(nil)
   end
-  local style = 'Normal'
+
   if info.isComplete then
-    style = 'Complete'
-  elseif info.superTracked then
-    style = 'Super'
+    mainStyle = 'Complete'
+  end
+  if info.superTracked then
+    subStyle = 'Super'
   end
 
   if info.specialItem and not info.itemButton then
@@ -468,7 +302,7 @@
   end
 
   --- metrics are calculated in SetStyle
-  t:SetStyle(style)
+  t:SetStyle('TrackerBlock', handler.name, mainStyle, subStyle)
   t:Show()
 
   print('  |cFF00FFFF)|r -> ', t, t:GetHeight())
@@ -476,11 +310,14 @@
 end
 
 mod.UpdateObjectives = function(block, info, text)
+  local print = B.print('ObjectiveBlockParse')
+
   local attachmentHeight = block.attachmentHeight
   if info.description then
     print('  -- has description text:', select('#', info.description), info.description)
     text = info.description
   end
+  local completionScore, completionMax = 0, 0
   for o, obj in ipairs(info.objectives) do
     --- achievement criteria
     if obj.flags then
@@ -500,11 +337,21 @@
       print('obj.type =', obj.type)
       print('  ** qtyStr:', obj.quantityString, 'qty:', obj.quantity, 'assetID:', obj.assetID)
       obj.widget = mod.SetWidget(obj, info)
+      if obj.finished then
+        obj.progress = 2
+      elseif obj.quantity > 0 then
+        obj.progress  = 1
+      else
+        obj.progress = 0
+      end
+
+
       --- none of the above (most quests)
     else
       local line = obj.text
       local color = '00FFFF'
       if obj.finished then
+        obj.progress = 2
         color = 'FFFFFF'
       elseif obj.type == 'monster' then
         color = 'FFFF00'
@@ -522,10 +369,16 @@
       obj.widget:SetPoint('TOPLEFT', block.objectives, 'BOTTOMLEFT', 0, -attachmentHeight)
       print('have a widget, height is', obj.widget.height)
       attachmentHeight = attachmentHeight + obj.widget.height
+      completionScore = completionScore + obj.progress
+      completionMax = completionMax + 2
     end
 
   end
-  return attachmentHeight, text
+
+  block.completionScore = completionScore / completionMax
+  block.attachmentHeight = attachmentHeight
+
+  return text
 end
 
 mod.UpdateTracker = function(handler)
@@ -535,7 +388,7 @@
   local trackerHeight = headerHeight
   local w = 300
 
-  previousBlock = handler.Tracker
+  previousBlock = tracker.title
   local numWatched = handler.GetNumWatched()
   local numBlocks = handler.numBlocks
   local actualBlocks = 0
@@ -546,6 +399,7 @@
       if info then
         local currentBlock = mod.UpdateTrackerBlock(handler, blockIndex, info)
         previousBlock = currentBlock
+        print('|cFF00FF00'..currentBlock:GetName()..'|r', currentBlock.height)
         trackerHeight = trackerHeight + currentBlock.height
         numBlocks = max(numBlocks, watchIndex)
         actualBlocks = actualBlocks + 1
@@ -596,7 +450,7 @@
     if handler.actualBlocks >= 1 then
       local tracker = handler.Tracker
       print('setting', handler.Tracker, 'to anchor to offset', -scrollHeight)
-      tracker:SetParent(Scroll) -- this doesn't do anything that relativeTo doesn't
+      tracker:SetParent(Scroll)
       tracker:SetPoint('TOPLEFT', Scroll, 'TOPLEFT', 0, - scrollHeight)
       tracker:SetSize(wrapperWidth, tracker.height)
       print('adding ', tracker.height)
@@ -623,11 +477,11 @@
   headerHeight = floor(headerHeight+.5)
 
   if wrapperBlocks >= 1 then
-    for i, region in ipairs(Wrapper.header) do
+    for i, region in ipairs(Wrapper.headerComplex) do
       region:Show()
     end
   else
-    for i, region in ipairs(Wrapper.header) do
+    for i, region in ipairs(Wrapper.headerComplex) do
       region:Hide()
     end
     return
@@ -639,6 +493,10 @@
   print('|cFFFFFF00params:|r wrapper:', wrapperWidth, 'x', wrapperHeight)
   print('|cFFFFFF00params:|r header:', headerHeight)
 
+  mod.SetBlockStyle(Scroller, 'Scroller', 'Normal')
+  mod.SetBlockStyle(Scroller, 'Scroll', 'Normal')
+  mod.SetBlockStyle(Wrapper, 'Wrapper', 'Normal')
+
   Scroller:SetSize(wrapperWidth, wrapperHeight)
   Scroller:SetPoint('TOPLEFT', Wrapper, 'TOPLEFT', 0, -headerHeight)
   Scroller:SetPoint('BOTTOMRIGHT', Wrapper, 'BOTTOMRIGHT')