view CampFireButton.lua @ 98:b980c00affcd

Added a button to cast a campfire I got a problem with newlines and merging with a non-Mercurial repository, I hope noting broke...
author contrebasse
date Fri, 20 May 2011 18:32:43 +0200
parents
children 060f5d0f7a35
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()
	btn:Hide()
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