view Templates.lua @ 115:8c94bee4fdfc

- AddHandler simplified - Centralized combat start/stop hooks - WorldState removed
author Nenue
date Tue, 28 Mar 2017 07:02:26 -0400
parents 26938ae258b7
children 1f68c46bc4de
line wrap: on
line source
-- Veneer
-- Templates.lua
-- Created: 10/24/2016 9:16 AM
-- %file-revision%
--
-- Mover Widget base
local ADDON, Veneer = ...
local print = DEVIAN_WORKSPACE and function(...) _G.print('Veneer', ...) end or nop
local PlaySoundKitID = DEVIAN_WORKSPACE and PlaySoundKitID or nop
local ipairs, pairs = ipairs, pairs
local pack, unpack = pack, unpack

local Handler, ConfigLayer, Animation = {}, {}, {}

VeneerConfigLayerMixin = ConfigLayer
VeneerAnimationMixin = Animation
VeneerHandlerMixin = Handler
Handler.anchorPoint = 'CENTER'
Handler.anchorPriority = 4
Handler.data = {}
Veneer.HandlerBase = Handler
Veneer.ConfigLayerBase = ConfigLayer
Veneer.AnimationBase = Animation


function ConfigLayer:OnLoad()
  local handler = self:GetParent()
  print(handler:GetName(), 'configLayers')
  handler.ConfigLayers = handler.ConfigLayers or {}
  for i, region in ipairs(handler.ConfigLayers) do
    region:SetShown(Veneer.ConfigMode)
  end

end

function ConfigLayer:OnUpdate()
  local handler = self:GetParent()
  handler.ConfigLayers = handler.ConfigLayers or {}

  self.ConfigName:SetText(handler:GetName())
  self.ConfigID:SetText(handler:GetID())
end

-- Sets a state flag for use in OnUpdate conditionals
function Animation:OnPlay()
  PlaySoundKitID(229)
  self.animating = true
  print('|cFF00FF00Anim:OnPlay|r @', unpack(self.sourcePoint))
end
function Animation:OnStop()
  PlaySoundKitID(229)
  self.animating = nil
  print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint))
end
function Animation:OnFinished()
  PlaySoundKitID(229)
  self.animating = nil
  print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint))
end

-- Replace if module requires anything besides fixing frame anchors
function Handler:OnShow()
  self:Reanchor()
  Veneer:StaticReanchor(self)
end
function Handler:OnHide()
  Veneer:DynamicReanchor()
end
function Handler:Reanchor (anchorAll)
  Veneer:DynamicReanchor()
end

-- Replace if module needs to do more than reconcile SavedVariables pointers
function Handler:Setup()
  print(self:GetName(), '|cFF00FF88Setup()')
  local configName = self:GetName():gsub('^Veneer', '')
  VeneerData[configName] = VeneerData[configName] or self.defaultSettings or {}

  for k,v in pairs(self.data) do
    if not VeneerData[configName][k] then
      print('reconciling pre-data:', k, v)
      VeneerData[configName][k] = v
    end
  end

  if self.EventList then
    for _, event in ipairs(self.EventList) do
      print(self:GetName(), event, 'registered')
      self:RegisterEvent(event)
    end
  end

  local guid = UnitGUID('player')
  self.data = VeneerData[configName]
  self.data[guid] = self.data[guid] or {}
  self.profile = self.data[guid]
  print('data table loaded:', configName)
  self.initialized = true
end

-- Replace to stop collated outputs.
function Handler:Print(...)
  local txt = '|cFFFFFF00'..self:GetName()..'|r:'
  for i = 1, select('#', ...) do
    txt = txt .. ' '.. tostring(select(i, ...))
  end
  DEFAULT_CHAT_FRAME:AddMessage(txt)
end

-- Replace if not using the ConfigLayer template
function Handler:UpdateConfigLayers (configMode)
  -- Override to manage config visual elements when a config update is fired from /vn or login
  if not self:IsShown() then
    self:SetShown(configMode)
    self:Reanchor()
  end
  self.configMode = configMode
end