extra.lua 3.6 KB
Newer Older
Azilroka's avatar
Azilroka committed
1
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
2 3 4 5 6 7 8 9 10 11 12
local AB = E:GetModule('ActionBars');

--Lua functions
local _G = _G
local unpack = unpack
--WoW API / Variables
local CreateFrame = CreateFrame
local GetActionCooldown = GetActionCooldown
local HasExtraActionBar = HasExtraActionBar

--Global variables that we don't cache, list them here for mikk's FindGlobals script
13
-- GLOBALS: ExtraActionBarFrame, ZoneAbilityFrame
14

15 16
local ExtraActionBarHolder, ZoneAbilityHolder

17 18 19 20 21 22
local function FixExtraActionCD(cd)
	local start, duration = GetActionCooldown(cd:GetParent().action)
	E.OnSetCooldown(cd, start, duration, 0, 0)
end

function AB:Extra_SetAlpha()
23
	if not E.private.actionbar.enable then return; end
24
	local alpha = E.db.actionbar.extraActionButton.alpha
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39
	for i=1, ExtraActionBarFrame:GetNumChildren() do
		local button = _G["ExtraActionButton"..i]
		if button then
			button:SetAlpha(alpha)
		end
	end

	local button = ZoneAbilityFrame.SpellButton
	if button then
		button:SetAlpha(alpha)
	end
end

function AB:Extra_SetScale()
40
	if not E.private.actionbar.enable then return; end
41
	local scale = E.db.actionbar.extraActionButton.scale
42

43 44
	if ExtraActionBarFrame then
		ExtraActionBarFrame:SetScale(scale)
45
		ExtraActionBarHolder:Size(ExtraActionBarFrame:GetWidth() * scale)
46 47 48 49
	end

	if ZoneAbilityFrame then
		ZoneAbilityFrame:SetScale(scale)
50
		ZoneAbilityHolder:Size(ZoneAbilityFrame:GetWidth() * scale)
51 52 53 54
	end
end

function AB:SetupExtraButton()
55
	ExtraActionBarHolder = CreateFrame('Frame', nil, E.UIParent)
56 57
	ExtraActionBarHolder:Point('BOTTOM', E.UIParent, 'BOTTOM', 0, 150)
	ExtraActionBarHolder:Size(ExtraActionBarFrame:GetSize())
58

59
	ExtraActionBarFrame:SetParent(ExtraActionBarHolder)
60
	ExtraActionBarFrame:ClearAllPoints()
61
	ExtraActionBarFrame:Point('CENTER', ExtraActionBarHolder, 'CENTER')
62 63
	ExtraActionBarFrame.ignoreFramePositionManager  = true

64
	ZoneAbilityHolder = CreateFrame('Frame', nil, E.UIParent)
65 66 67 68
	ZoneAbilityHolder:Point('BOTTOM', ExtraActionBarFrame, 'TOP', 0, 2)
	ZoneAbilityHolder:Size(ExtraActionBarFrame:GetSize())

	ZoneAbilityFrame:SetParent(ZoneAbilityHolder)
69
	ZoneAbilityFrame:ClearAllPoints()
70
	ZoneAbilityFrame:Point('CENTER', ZoneAbilityHolder, 'CENTER')
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	ZoneAbilityFrame.ignoreFramePositionManager = true

	for i=1, ExtraActionBarFrame:GetNumChildren() do
		local button = _G["ExtraActionButton"..i]
		if button then
			button.noResize = true;
			button.pushed = true
			button.checked = true

			self:StyleButton(button, true)
			button:SetTemplate()
			_G["ExtraActionButton"..i..'Icon']:SetDrawLayer('ARTWORK')
			local tex = button:CreateTexture(nil, 'OVERLAY')
			tex:SetColorTexture(0.9, 0.8, 0.1, 0.3)
			tex:SetInside()
			button:SetCheckedTexture(tex)

88
			if button.cooldown then
89
				button.cooldown.CooldownOverride = 'actionbar'
90 91 92 93 94 95 96
				E:RegisterCooldown(button.cooldown)
				button.cooldown:HookScript("OnShow", FixExtraActionCD)
			end
		end
	end

	local button = ZoneAbilityFrame.SpellButton
97
	if button then
98 99 100 101 102 103 104
		button:SetNormalTexture('')
		button:StyleButton(nil, nil, nil, true)
		button:SetTemplate()
		button.Icon:SetDrawLayer('ARTWORK')
		button.Icon:SetTexCoord(unpack(E.TexCoords))
		button.Icon:SetInside()

105
		if button.Cooldown then
106
			button.Cooldown.CooldownOverride = 'actionbar'
107 108 109 110 111 112 113 114
			E:RegisterCooldown(button.Cooldown)
		end
	end

	if HasExtraActionBar() then
		ExtraActionBarFrame:Show();
	end

115
	E:CreateMover(ExtraActionBarHolder, 'BossButton', L["Boss Button"], nil, nil, nil, 'ALL,ACTIONBARS', nil, 'actionbar,extraActionButton');
116
	E:CreateMover(ZoneAbilityHolder, 'ZoneAbility', L["Zone Ability"], nil, nil, nil, 'ALL,ACTIONBARS');
117 118 119

	AB:Extra_SetAlpha()
	AB:Extra_SetScale()
Simpy's avatar
Simpy committed
120
end