view CampFireButton.lua @ 102:e74ed53097d7

Tag as v1.0beta10
author contrebasse
date Fri, 20 May 2011 23:28:41 +0200
parents 060f5d0f7a35
children c8d527a9fb3a
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()
	-- 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)

	-- Save info
	cookingName = GetSpellInfo(COOKING_ID)

	-- 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()
	if not btn then return end
	-- Display only if the tradeskill is Cooking
	local tradeskillName = GetTradeSkillLine()
	if tradeskillName ~= cookingName then
		btn:Hide()
	else
		btn:Show()
	end
end