view CampFireButton.lua @ 104:a9bda1f95232

Added tag v1.0beta11 for changeset c8d527a9fb3a
author contrebasse
date Sat, 21 May 2011 14:21:18 +0200
parents c8d527a9fb3a
children 08ede537787b
line wrap: on
line source
local addonName, A = ...

local CAMPFIRE_ID = 818
local COOKING_ID = 2550
local btn
local cookingName

-- Create button
function A.InitialiseCampFireBtn()
	if not GetTradeSkillLine() or InCombatLockdown() then return end

	-- create the frame
	btn = CreateFrame("Button", nil, TradeSkillFrame, "SecureActionButtonTemplate")
	btn:SetNormalTexture(select(3,GetSpellInfo(CAMPFIRE_ID)))
	btn:SetSize(24,24)
	btn:SetPoint("BOTTOMRIGHT",TradeSkillFrame,"BOTTOMRIGHT",-10,179)

	-- Set the action
	btn:SetAttribute("type", "spell")
	btn:SetAttribute("spell", CAMPFIRE_ID)

	-- Set the tooltip
	btn:SetScript("OnEnter",function(self)
		GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT")
		GameTooltip:SetSpellByID(CAMPFIRE_ID)
		GameTooltip:Show()
	end)
	btn:SetScript("OnLeave",function() GameTooltip:Hide(); end)

	-- Add cooldown
	btn.cooldown = CreateFrame("Cooldown",nil,btn)
	btn.cooldown:SetAllPoints(btn)
	local CooldownFrame_SetTimer = CooldownFrame_SetTimer
	local GetSpellCooldown = GetSpellCooldown
	btn:SetScript("OnUpdate",function(self) CooldownFrame_SetTimer(self.cooldown,GetSpellCooldown(CAMPFIRE_ID)); end)

	-- Show if needed
	A.ManageCampFireBtn()
end

-- Hide button
function A.HideCampFireBtn()
	if btn then btn:Hide() end
end

-- Show button if applicable
function A.ManageCampFireBtn()
	-- Display only if the tradeskill is Cooking
	if not cookingName then cookingName = GetSpellInfo(COOKING_ID) end
	if GetTradeSkillLine() ~= cookingName then
		if btn then btn:Hide() end
	else
		-- create button if necessary
		if not btn then
			A.InitialiseCampFireBtn()
		end
		-- It may not have been created
		if not btn then return end
		btn:Show()
	end
end