diff ObjectiveTracker/Frame.lua @ 39:92534dc793f2

- restore the previous QuestLogSelection after pulling for selection-restricted quest data; fixes icon mixups while quest map is open - moved progressbar builders into the schema environment, with all the other Frame.lua functions; prep for configuration access - relegate the various removal events to a framescript in their corresponding blocks; this takes care of resolving dead frames
author Nenue
date Thu, 21 Apr 2016 16:43:37 -0400
parents 1f8f9cc3d956
children
line wrap: on
line diff
--- a/ObjectiveTracker/Frame.lua	Thu Apr 21 11:36:41 2016 -0400
+++ b/ObjectiveTracker/Frame.lua	Thu Apr 21 16:43:37 2016 -0400
@@ -3,6 +3,7 @@
 -- @project-revision@ @project-hash@
 -- @file-revision@ @file-hash@
 -- Created: 3/30/2016 12:49 AM
+--- Everything that involves directly placing elements on the screen goes here. Sizing, spacing, tiling, etc.
 local B = select(2,...).frame
 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
 local _G, ipairs, max, min, unpack, floor, pairs, tostring, type, band = _G, ipairs, max, min, unpack, floor, pairs, tostring, type, bit.band
@@ -67,7 +68,12 @@
 
 local textbg =  {'HORIZONTAL', 0, 0, 0, 0.4, 0, 0, 0, 0 }
 local textFont, textSize, textOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]], 16, 'OUTLINE'
-local textColor = {1,1,1,1}
+local textColor = {1,1,1,1 }
+
+local widgetTextFont, widgetTextSize, widgetTextOutline = [[Interface\Addons\SharedMedia_MyMedia\font\XOIREQE.TTF]], 11, 'OUTLINE'
+local widgetTextColor = {1,1,1,1 }
+local widgetHeight, widgetBorder = 17, 1
+
 
 local selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225}
 local titleSpacing, textSpacing, blockSpacing = 3, 3, 1
@@ -125,6 +131,9 @@
   elseif layer == 'line' then
     textColor = c.textColor
     lineSchema = newSchema
+  elseif layer == 'widget' then
+    widgetTextColor = c.textSpacing
+    widgetTextFont, widgetTextSize, widgetTextOutline = unpack(c.textFont)
   end
   tprint('|cFFFF0088       Schema:|r', layer, lastSchema[layer], '->', newSchema)
 end
@@ -614,3 +623,203 @@
   Scroll:Show()
 end
 
+
+-----------------------------------------
+-- Criteria frames
+
+--[[
+      text = description,
+      type = type,
+      finished = completed,
+      quantity = quantity,
+      requiredQuantity = requiredQuantity,
+      characterName = characterName,
+      flags = flags,
+      assetID = assetID,
+      quantityString = quantityString,
+      criteriaID = criteriaID,
+]]
+local newWidgetID = 0
+T.WidgetRegistry = {}
+local wr = T.WidgetRegistry
+
+--- Get a usable widget for the given achievement criteria set.
+-- Returns a frame object with dimensioning parameters needed to size the receiving tracker block
+T.GetWidget = function(data, objectiveType, objectiveKey)
+  local print = B.print('ObjectiveWidgets')
+  local widgetType = objectiveType
+  local widget
+  local isNew
+  if wr[widgetType] and wr[widgetType].used[objectiveKey] then
+    widget = wr[widgetType].used[objectiveKey]
+    print('|cFF00FF00Updating ('..objectiveKey..')', widget)
+  elseif not wr[widgetType] or #wr[widgetType].free == 0 then
+    -- creating a new frame
+    isNew = true
+    widget = CreateFrame(widgetType, 'VeneerObjective' .. widgetType .. (wr[widgetType] and (wr[widgetType].lastn+1) or (1)), VeneerObjectiveScroll, 'VeneerObjectiveCriteria' .. widgetType)
+    print('|cFFFF0088Creating `'..widget:GetName()..'` id', wr[widgetType].lastn)
+    T.UpdateSchema(widgetType, data.schema or 'default')
+  else
+    -- recycling for a different criteria set
+    isNew = true
+    widget = tremove(wr[widgetType].free)
+    print('|cFFFFFF00Acquiring released widget', widget:GetName())
+  end
+
+
+  wr[widgetType].used[objectiveKey] = widget
+  widget.objective = data
+  widget.key = objectiveKey
+  T.InitializeWidget(widget, isNew)
+  return widget
+end
+
+--- WidgetTemplate 'OnLoad'
+T.RegisterWidget = function(frame)
+  local print = B.print('ObjectiveWidgets')
+  local widgetType = frame.widgetType
+  if not wr[frame.widgetType] then
+    print('|cFFFF4400[[WidgetTemplate]]|r', widgetType)
+    wr[widgetType] = { lastn = 1, free = {}, used = {}, usedIndex = {}, freeIndex = {} }
+  else
+    print('|cFF0088FF+ [[WidgetTemplate]]r', widgetType, wr[widgetType].lastn)
+    wr[widgetType].lastn = wr[widgetType].lastn + 1
+  end
+end
+--- WidgetTemplate 'OnShow'
+local wrapperWidth, textIndent
+T.InitializeWidget = setmetatable({}, {
+  __call = function(t, frame, isNew, ...)
+    -- todo: config pull
+    if not wrapperWidth then
+      wrapperWidth = T.Conf.Wrapper.Width
+      textIndent = T.Conf.Wrapper.TextIndent
+    end
+
+    tprint('Initialize', frame:GetName(), isNew, ...)
+    frame:SetWidth(wrapperWidth - textIndent * 2)
+    frame:SetScript('OnEvent', T.UpdateWidget[frame.widgetType])
+    frame:RegisterEvent('QUEST_LOG_UPDATE')
+    frame:RegisterEvent('TRACKED_ACHIEVEMENT_UPDATE')
+    frame:RegisterEvent('TRACKED_ACHIEVEMENT_LIST_CHANGED')
+    frame:RegisterEvent('CRITERIA_UPDATE')
+    frame:RegisterEvent('CRITERIA_COMPLETE')
+    frame:RegisterEvent('CRITERIA_EARNED')
+    t[frame.widgetType](frame, isNew)
+    T.UpdateWidget[frame.widgetType](frame, isNew)
+  end,
+})
+
+--- WidgetTemplate 'OnEvent'
+T.UpdateWidget = setmetatable({}, {
+  __call = function(t, frame, isNew, ...)
+    tprint('Update', frame:GetName(), isNew, ...)
+    if not frame.widgetType then
+      return
+    end
+
+    return t[frame.widgetType](frame, isNew)
+  end
+})
+
+
+local progressHeight = 17
+local progressBorder = 1
+local progressFont = _G.VeneerCriteriaFontNormal
+
+local lprint = B.print('Line')
+T.InitializeWidget.StatusBar = function(self, isNew)
+  local print = lprint
+  local c = T.Conf.Wrapper
+
+  tprint(self:GetName(), isNew)
+  if isNew then
+    self.maxValue = self.maxValue or 1
+    self:SetMinMaxValues(0, self.maxValue)
+
+    self:SetHeight(widgetHeight)
+    self.height = widgetHeight
+
+    self.status:SetFont(widgetTextFont, widgetTextSize, widgetTextOutline)
+    self.status:SetTextColor(unpack(widgetTextColor))
+  end
+  self.value = self.value or 1
+  self:SetValue(self.value)
+
+  self.status:SetText(self.objective.quantityString)
+end
+
+T.UpdateWidget.StatusBar = function (self)
+  local value, maxValue = self.value, self.maxValue
+  print('update vals:')
+  for k,v in pairs(self) do
+    print(k, v)
+  end
+  self.width = self.width or self:GetWidth()
+  self:SetValue(self.value)
+  local format = self.format or '%d/%d'
+  self.status:SetFormattedText(format, value, maxValue)
+  local progress = (value / maxValue)
+  if progress > 0 then
+    print('color:', 1-progress*2 , progress*2 - 1,0,1)
+    print('width:', (self.width  -progressBorder * 2) * progress)
+    self:SetStatusBarColor(1-progress*2 , progress*2,0,1)
+  end
+end
+
+
+T.InitializeWidget.Hidden = function (self)
+  self.height = 0
+end
+T.UpdateWidget.Hidden = function (self)
+  self.height=  0
+end
+
+
+--- Queue any active item buttons for update for that frame
+local iprint = B.print('ItemButton')
+local Quest = T.Quest
+local IsQuestWatched, InCombatLockdown = IsQuestWatched, InCombatLockdown
+T.UpdateActionButtons = function(updateReason)
+  local print = iprint
+  Scroller.snap_upper = 0
+  Scroller.snap_lower = 0
+  local print = B.print('ItemButton')
+  if updateReason then
+    print = B.print('IB_'..updateReason)
+  end
+
+  local previousItem
+  for questID, itemButton in pairs(Quest.itemButtons) do
+    local info= T.Quest.Info[questID]
+
+    print('|cFF00FFFF'.. questID .. '|r', itemButton:GetName())
+    local block = T.Quest.QuestBlock[questID]
+    if block then
+      -- Dispatch the probe
+      if IsQuestWatched(info.logIndex) then
+        itemButton.previousItem = previousItem
+        print('  |cFFFFFF00probing', block:GetName())
+        block:SetScript('OnUpdate', function()
+          if block:GetBottom() and not InCombatLockdown() then
+            print('  '..block:GetName()..' |cFF00FF00probe hit!')
+            T.UpdateBlockAction(block, itemButton, itemButton.previousItem) -- needs to be previousItem from this scope
+            block:SetScript('OnUpdate', nil)
+
+          end
+        end)
+        previousItem = itemButton
+      else
+        print('hidden block or unwatched quest')
+        itemButton.previousItem = nil
+        itemButton:Hide()
+      end
+    elseif itemButton:IsVisible() then
+      print('  |cFFFF0088hiding unwatched quest button', itemButton:GetName())
+      itemButton.previousItem = nil
+      itemButton:Hide()
+    else
+      print('  |cFFBBBBBBignoring hidden log quest button', itemButton:GetName())
+    end
+  end
+end
\ No newline at end of file