Skip to content

Commit

Permalink
move masque support to its own module (buttonThemer)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuller committed Mar 7, 2015
1 parent e7bf81d commit 3c0bc71
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 85 deletions.
1 change: 1 addition & 0 deletions Dominos.toc
Expand Up @@ -31,3 +31,4 @@ bars\vehicleBar.lua
plugins\slashCommands.lua
plugins\launcher.lua
plugins\blizzardHider.lua
plugins\buttonThemer.lua
28 changes: 9 additions & 19 deletions bars/actionButton.lua
Expand Up @@ -3,13 +3,14 @@
A dominos action button
--]]
local AddonName, Addon = ...
local AddonName = ...
local Addon = LibStub('AceAddon-3.0'):GetAddon(AddonName)
local KeyBound = LibStub('LibKeyBound-1.0')
local Bindings = Dominos.BindingsController
local Tooltips = Dominos:GetModule('Tooltips')
local Bindings = Addon.BindingsController
local Tooltips = Addon:GetModule('Tooltips')
local ActionButton = Dominos:CreateClass('CheckButton', Dominos.BindableButton)
Dominos.ActionButton = ActionButton
local ActionButton = Addon:CreateClass('CheckButton', Addon.BindableButton)
Addon.ActionButton = ActionButton
ActionButton.unused = {}
ActionButton.active = {}
Expand Down Expand Up @@ -66,7 +67,7 @@ function ActionButton:New(id)
end
]])

Bindings:Register(button, button:GetName():match('DominosActionButton%d'))
Bindings:Register(button, button:GetName():match(AddonName .. 'ActionButton%d'))
Tooltips:Register(button)

--get rid of range indicator text
Expand Down Expand Up @@ -101,7 +102,8 @@ function ActionButton:Create(id)
button:SetAttribute('useparent-unit', true)
button:EnableMouseWheel(true)
button:HookScript('OnEnter', self.OnEnter)
button:Skin()

Addon:GetModule('ButtonThemer'):Register(button, 'Action Bar')
end

return button
Expand Down Expand Up @@ -193,15 +195,3 @@ function ActionButton:LoadAction()

self:SetAttribute('action', id)
end

function ActionButton:Skin()
if not Dominos:Masque('Action Bar', self) then
self.icon:SetTexCoord(0.06, 0.94, 0.06, 0.94)
self:GetNormalTexture():SetVertexColor(1, 1, 1, 0.5)

local floatingBG = _G[self:GetName() .. 'FloatingBG']
if floatingBG then
floatingBG:Hide()
end
end
end
42 changes: 22 additions & 20 deletions bars/bagBar.lua
Expand Up @@ -8,26 +8,6 @@ local Addon = _G[AddonName]
-- register buttons for use later
local bagButtons = {}
do
local function addButton(buttonName)
local button = _G[buttonName]
Addon:Masque(
'Bag Bar',
button,
{ Icon = _G[button:GetName() .. 'IconTexture'] }
)
table.insert(bagButtons, button)
end
for slot = (NUM_BAG_SLOTS - 1), 0, -1 do
addButton(('CharacterBag%dSlot'):format(slot))
end
addButton('MainMenuBarBackpackButton')
end
--[[ Bag Bar ]]--
Expand Down Expand Up @@ -102,6 +82,20 @@ end
local BagBarController = Addon:NewModule('BagBar')
function BagBarController:OnInitialize()
for slot = (NUM_BAG_SLOTS - 1), 0, -1 do
self:RegisterButton(('CharacterBag%dSlot'):format(slot))
end
self:RegisterButton('MainMenuBarBackpackButton')
end
function BagBarController:OnEnable()
for i, button in pairs(bagButtons) do
Addon:GetModule('ButtonThemer'):Register(button, 'Bag Bar', { Icon = button.icon, Border = button.IconBorder })
end
end
function BagBarController:Load()
self.frame = BagBar:New()
end
Expand All @@ -112,3 +106,11 @@ function BagBarController:Unload()
self.frame = nil
end
end
function BagBarController:RegisterButton(name)
local button = _G[name]
table.insert(bagButtons, button)
end
11 changes: 1 addition & 10 deletions bars/extraActionBar.lua
Expand Up @@ -30,21 +30,12 @@ do
if button then
button.buttonType = 'EXTRAACTIONBUTTON'
button:HookScript('OnEnter', self.OnEnter)
button:Skin()
Addon:GetModule('ButtonThemer'):Register(button, 'Extra Bar')

return button
end
end

--if we have button facade support, then skin the button that way
--otherwise, apply the dominos style to the button to make it pretty
function ExtraActionButton:Skin()
if not Addon:Masque('Extra Bar', self) then
self.icon:SetTexCoord(0.06, 0.94, 0.06, 0.94)
self:GetNormalTexture():SetVertexColor(1, 1, 1, 0.5)
end
end

function ExtraActionButton:Restore(id)
local b = unused and unused[id]

Expand Down
30 changes: 11 additions & 19 deletions bars/petBar.lua
Expand Up @@ -5,8 +5,6 @@

local Addon = _G[...]
local KeyBound = LibStub('LibKeyBound-1.0')

local format = string.format
local unused = {}


Expand All @@ -15,31 +13,25 @@ local unused = {}
local PetButton = Addon:CreateClass('CheckButton', Addon.BindableButton)

function PetButton:New(id)
local b = self:Restore(id) or self:Create(id)
local button = self:Restore(id) or self:Create(id)

Addon.BindingsController:Register(b)
Addon:GetModule('Tooltips'):Register(b)
Addon.BindingsController:Register(button)
Addon:GetModule('Tooltips'):Register(button)

return b
return button
end

function PetButton:Create(id)
local b = self:Bind(_G['PetActionButton' .. id])
b.buttonType = 'BONUSACTIONBUTTON'
local buttonName = ('PetActionButton%d'):format(id)

b:HookScript('OnEnter', self.OnEnter)
b:Skin()
local button = self:Bind(_G[buttonName])
button.buttonType = 'BONUSACTIONBUTTON'

return b
end
button:HookScript('OnEnter', self.OnEnter)

--if we have button facade support, then skin the button that way
--otherwise, apply the dominos style to the button to make it pretty
function PetButton:Skin()
if not Addon:Masque('Pet Bar', self) then
_G[self:GetName() .. 'Icon']:SetTexCoord(0.06, 0.94, 0.06, 0.94)
self:GetNormalTexture():SetVertexColor(1, 1, 1, 0.5)
end
Addon:GetModule('ButtonThemer'):Register(button, 'Pet Bar')

return button
end

function PetButton:Restore(id)
Expand Down
18 changes: 1 addition & 17 deletions bars/stanceBar.lua
Expand Up @@ -37,28 +37,12 @@ do
if button then
button:HookScript('OnEnter', self.OnEnter)
button:Skin()
Addon:GetModule('ButtonThemer'):Register(button, 'Class Bar')
end
return button
end
--if we have button facade support, then skin the button that way
--otherwise, apply the dominos style to the button to make it pretty
function StanceButton:Skin()
if Addon:Masque('Class Bar', self) then return end
local r = self:GetWidth() / _G['ActionButton1']:GetWidth()
local nt = self:GetNormalTexture()
nt:ClearAllPoints()
nt:SetPoint('TOPLEFT', -15 * r, 15 * r)
nt:SetPoint('BOTTOMRIGHT', 15 * r, -15 * r)
self.icon:SetTexCoord(0.06, 0.94, 0.06, 0.94)
self:GetNormalTexture():SetVertexColor(1, 1, 1, 0.5)
end
function StanceButton:Restore(id)
local button = unused[id]
Expand Down
49 changes: 49 additions & 0 deletions plugins/buttonThemer.lua
@@ -0,0 +1,49 @@
local AddonName = ...
local ButtonThemer = LibStub('AceAddon-3.0'):GetAddon(AddonName):NewModule('ButtonThemer')

local _NormalButtonWidth = _G['ActionButton1']:GetWidth()

function ButtonThemer:OnInitialize()
local Masque = LibStub('Masque', true)

if Masque then
Masque:Register(AddonName, function(...)
local addon, group, skinId, gloss, backdrop, colors, disabled = ...

if disabled then
for button in pairs(Masque:Group(AddonName, group).Buttons) do
self:ApplyDefaultTheme(button)
end
end
end)

self.Register = function(self, button, groupName, ...)
local group = Masque:Group(AddonName, groupName)

group:AddButton(button, ...)

if group.Disable then
self:ApplyDefaultTheme(button)
end
end
else
self.Register = self.ApplyDefaultTheme
end
end

function ButtonThemer:ApplyDefaultTheme(button)
button.icon:SetTexCoord(0.06, 0.94, 0.06, 0.94)

local r = button:GetWidth() / _NormalButtonWidth

local nt = button:GetNormalTexture()
nt:ClearAllPoints()
nt:SetPoint('TOPLEFT', -15 * r, 15 * r)
nt:SetPoint('BOTTOMRIGHT', 15 * r, -15 * r)
nt:SetVertexColor(1, 1, 1, 0.5)

local floatingBG = _G[('%sFloatingBG'):format(button:GetName())]
if floatingBG then
floatingBG:Hide()
end
end

0 comments on commit 3c0bc71

Please sign in to comment.