Nenue@90: -- Veneer Nenue@90: -- Templates.lua Nenue@90: -- Created: 10/24/2016 9:16 AM Nenue@90: -- %file-revision% Nenue@90: -- Nenue@90: -- Mover Widget base Nick@109: local ADDON, Veneer = ... Nenue@115: local print = DEVIAN_WORKSPACE and function(...) _G.print('Veneer', ...) end or nop Nick@109: local PlaySoundKitID = DEVIAN_WORKSPACE and PlaySoundKitID or nop Nick@109: local ipairs, pairs = ipairs, pairs Nick@109: local pack, unpack = pack, unpack Nenue@90: Nick@109: local Handler, ConfigLayer, Animation = {}, {}, {} Nenue@90: Nick@109: VeneerConfigLayerMixin = ConfigLayer Nick@109: VeneerAnimationMixin = Animation Nick@109: VeneerHandlerMixin = Handler Nick@109: Handler.anchorPoint = 'CENTER' Nick@109: Handler.anchorPriority = 4 Nick@109: Handler.data = {} Nick@109: Veneer.HandlerBase = Handler Nick@109: Veneer.ConfigLayerBase = ConfigLayer Nick@109: Veneer.AnimationBase = Animation Nick@109: Nenue@121: local ANCHOR_BUTTON_TYPES = { Nenue@121: 'TOPLEFT', 'TOP', 'TOPRIGHT', 'RIGHT', 'LEFT', 'CENTER', 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT' Nenue@121: } Nick@109: Nick@109: function ConfigLayer:OnLoad() Nenue@90: local handler = self:GetParent() Nenue@90: print(handler:GetName(), 'configLayers') Nenue@90: handler.ConfigLayers = handler.ConfigLayers or {} Nenue@90: for i, region in ipairs(handler.ConfigLayers) do Nenue@90: region:SetShown(Veneer.ConfigMode) Nenue@90: end Nenue@121: self.handler = handler Nenue@121: end Nenue@121: Nenue@121: function ConfigLayer:OnShow() Nenue@121: self:Update() Nenue@121: end Nenue@121: Nenue@122: local AnchorButton_OnClick = function(self) Nenue@122: Nenue@122: local module = self:GetParent().handler Nenue@122: module.anchorPoint = self.anchorPoint Nenue@122: module:Print('Anchor set to '.. self.anchorPoint) Nenue@122: self:GetParent():Update() Nenue@122: end Nenue@122: Nenue@122: local RelativeButton_OnClick = function(self) Nenue@122: end Nenue@122: Nenue@122: local RelativeButton_OnDragStart = function(self) end Nenue@122: local RelativeButton_OnDragStop = function(self) end Nenue@122: Nenue@122: Nenue@121: function ConfigLayer:Update() Nenue@121: if not self.anchorButtons then Nenue@121: self.anchorButtons = {} Nenue@121: for _, anchorPoint in ipairs(ANCHOR_BUTTON_TYPES) do Nenue@121: local button = CreateFrame('Button', nil, self, 'VeneerAnchorButtonTemplate') Nenue@121: button.anchorPoint = anchorPoint Nenue@122: button:RegisterForClicks('AnyUp') Nenue@122: button:SetScript('OnClick', AnchorButton_OnClick) Nenue@121: button:SetPoint(anchorPoint) Nenue@121: button:SetSize(16,16) Nenue@121: Nenue@121: self.anchorButtons[anchorPoint] = button Nenue@121: end Nenue@121: end Nenue@121: Nenue@121: for anchorPoint, button in pairs(self.anchorButtons) do Nenue@121: if anchorPoint == self.handler.anchorPoint then Nenue@121: button:GetNormalTexture():SetColorTexture(0,1,0,1) Nenue@121: else Nenue@121: button:GetNormalTexture():SetColorTexture(0.5,0.5,0.5,1) Nenue@121: end Nenue@121: end Nenue@121: Nenue@122: if self.handler.anchorFrom and self.handler.anchorFrame then Nenue@122: local rb = self.relativeButton Nenue@122: if not rb then Nenue@122: rb = CreateFrame('Button', nil, self, 'VeneerAnchorButtonTemplate') Nenue@122: self.relativeButton = rb Nenue@122: rb:RegisterForClicks('AnyUp') Nenue@122: rb:RegisterForDrag('AnyDown') Nenue@122: rb:SetScript('OnClick', RelativeButton_OnClick) Nenue@122: rb:SetScript('OnDragStart', RelativeButton_OnDragStart) Nenue@122: rb:SetScript('OnDragStop', RelativeButton_OnDragStop) Nenue@122: end Nenue@122: Nenue@122: print('|cFF00FF88Config|r',self.handler.anchorFrom, self.handler.anchorFrame) Nenue@122: rb:SetPoint(self.handler.anchorFrom, _G[self.handler.anchorFrame], self.handler.anchorFrom, 0, 0) Nenue@122: print(rb:GetPoint(1)) Nenue@122: rb:GetNormalTexture():SetColorTexture(1,1,1,1) Nenue@122: rb:SetSize(16,16) Nenue@122: end Nenue@122: Nenue@122: Nenue@121: self:RegisterForDrag('LeftButton') Nenue@121: end Nenue@121: Nenue@122: Nenue@122: Nenue@121: function ConfigLayer:OnDragStart() Nenue@122: self.originalX, self.originalY = self:GetCenter() Nenue@122: self.handler:SetMovable(true) Nenue@122: self.handler:StartMoving() Nenue@121: end Nenue@121: function ConfigLayer:OnDragStop() Nenue@115: Nenue@122: local newX, newY = self:GetCenter() Nenue@122: local dX = newX - self.originalX Nenue@122: local dY = newY - self.originalY Nenue@122: print('registering new X/Y:', dX, dY) Nenue@122: Nenue@122: Nenue@122: self.handler:StopMovingOrSizing() Nenue@90: end Nenue@90: Nick@109: function ConfigLayer:OnUpdate() Nenue@90: local handler = self:GetParent() Nenue@90: handler.ConfigLayers = handler.ConfigLayers or {} Nenue@90: Nenue@90: self.ConfigName:SetText(handler:GetName()) Nenue@90: self.ConfigID:SetText(handler:GetID()) Nenue@90: end Nenue@90: Nick@109: -- Sets a state flag for use in OnUpdate conditionals Nick@109: function Animation:OnPlay() Nenue@90: PlaySoundKitID(229) Nenue@90: self.animating = true Nenue@90: print('|cFF00FF00Anim:OnPlay|r @', unpack(self.sourcePoint)) Nenue@90: end Nick@109: function Animation:OnStop() Nenue@90: PlaySoundKitID(229) Nenue@90: self.animating = nil Nenue@90: print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint)) Nenue@90: end Nick@109: function Animation:OnFinished() Nenue@90: PlaySoundKitID(229) Nenue@90: self.animating = nil Nenue@90: print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint)) Nenue@93: end Nenue@93: Nick@109: -- Replace if module requires anything besides fixing frame anchors Nick@109: function Handler:OnShow() Nenue@93: self:Reanchor() Nenue@122: _G.Veneer:StaticReanchor(self) Nenue@93: end Nick@109: function Handler:OnHide() Nenue@122: _G.Veneer:DynamicReanchor() Nenue@93: end Nick@109: function Handler:Reanchor (anchorAll) Nenue@122: _G.Veneer:DynamicReanchor() Nenue@98: end Nick@109: Nick@109: -- Replace if module needs to do more than reconcile SavedVariables pointers Nick@109: function Handler:Setup() Nenue@115: print(self:GetName(), '|cFF00FF88Setup()') Nenue@102: local configName = self:GetName():gsub('^Veneer', '') Nenue@107: VeneerData[configName] = VeneerData[configName] or self.defaultSettings or {} Nenue@102: Nenue@102: for k,v in pairs(self.data) do Nenue@102: if not VeneerData[configName][k] then Nenue@102: print('reconciling pre-data:', k, v) Nenue@102: VeneerData[configName][k] = v Nenue@102: end Nenue@102: end Nenue@115: Nenue@115: if self.EventList then Nenue@115: for _, event in ipairs(self.EventList) do Nenue@115: print(self:GetName(), event, 'registered') Nenue@115: self:RegisterEvent(event) Nenue@115: end Nenue@115: end Nenue@115: Nenue@107: local guid = UnitGUID('player') Nenue@102: self.data = VeneerData[configName] Nenue@107: self.data[guid] = self.data[guid] or {} Nenue@107: self.profile = self.data[guid] Nenue@102: print('data table loaded:', configName) Nenue@102: self.initialized = true Nenue@102: end Nenue@98: Nick@109: -- Replace to stop collated outputs. Nick@109: function Handler:Print(...) Nenue@98: local txt = '|cFFFFFF00'..self:GetName()..'|r:' Nenue@98: for i = 1, select('#', ...) do Nenue@98: txt = txt .. ' '.. tostring(select(i, ...)) Nenue@98: end Nenue@98: DEFAULT_CHAT_FRAME:AddMessage(txt) Nenue@103: end Nenue@103: Nick@109: -- Replace if not using the ConfigLayer template Nick@109: function Handler:UpdateConfigLayers (configMode) Nenue@103: -- Override to manage config visual elements when a config update is fired from /vn or login Nenue@103: if not self:IsShown() then Nenue@103: self:SetShown(configMode) Nenue@103: self:Reanchor() Nenue@103: end Nenue@103: self.configMode = configMode Nenue@90: end