| 
contrebasse@98
 | 
     1 local addonName, A = ...
 | 
| 
contrebasse@98
 | 
     2 
 | 
| 
contrebasse@98
 | 
     3 local CAMPFIRE_ID = 818
 | 
| 
contrebasse@98
 | 
     4 local COOKING_ID = 2550
 | 
| 
contrebasse@98
 | 
     5 local btn
 | 
| 
contrebasse@98
 | 
     6 local cookingName
 | 
| 
contrebasse@98
 | 
     7 
 | 
| 
contrebasse@98
 | 
     8 -- Create button
 | 
| 
contrebasse@98
 | 
     9 function A.InitialiseCampFireBtn()
 | 
| 
contrebasse@98
 | 
    10 	-- create the frame
 | 
| 
contrebasse@98
 | 
    11 	btn = CreateFrame("Button", nil, TradeSkillFrame, "SecureActionButtonTemplate")
 | 
| 
contrebasse@98
 | 
    12 	btn:SetNormalTexture(select(3,GetSpellInfo(CAMPFIRE_ID)))
 | 
| 
contrebasse@98
 | 
    13 	btn:SetSize(24,24)
 | 
| 
contrebasse@98
 | 
    14 	btn:SetPoint("BOTTOMRIGHT",TradeSkillFrame,"BOTTOMRIGHT",-10,179)
 | 
| 
contrebasse@98
 | 
    15 
 | 
| 
contrebasse@98
 | 
    16 	-- Set the action
 | 
| 
contrebasse@98
 | 
    17 	btn:SetAttribute("type", "spell")
 | 
| 
contrebasse@98
 | 
    18 	btn:SetAttribute("spell", CAMPFIRE_ID)
 | 
| 
contrebasse@98
 | 
    19 
 | 
| 
contrebasse@98
 | 
    20 	-- Set the tooltip
 | 
| 
contrebasse@98
 | 
    21 	btn:SetScript("OnEnter",function(self)
 | 
| 
contrebasse@98
 | 
    22 		GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT")
 | 
| 
contrebasse@98
 | 
    23 		GameTooltip:SetSpellByID(CAMPFIRE_ID)
 | 
| 
contrebasse@98
 | 
    24 		GameTooltip:Show()
 | 
| 
contrebasse@98
 | 
    25 	end)
 | 
| 
contrebasse@98
 | 
    26 	btn:SetScript("OnLeave",function() GameTooltip:Hide(); end)
 | 
| 
contrebasse@98
 | 
    27 
 | 
| 
contrebasse@98
 | 
    28 	-- Add cooldown
 | 
| 
contrebasse@98
 | 
    29 	btn.cooldown = CreateFrame("Cooldown",nil,btn)
 | 
| 
contrebasse@98
 | 
    30 	btn.cooldown:SetAllPoints(btn)
 | 
| 
contrebasse@98
 | 
    31 	local CooldownFrame_SetTimer = CooldownFrame_SetTimer
 | 
| 
contrebasse@98
 | 
    32 	local GetSpellCooldown = GetSpellCooldown
 | 
| 
contrebasse@98
 | 
    33 	btn:SetScript("OnUpdate",function(self) CooldownFrame_SetTimer(self.cooldown,GetSpellCooldown(CAMPFIRE_ID)); end)
 | 
| 
contrebasse@98
 | 
    34 
 | 
| 
contrebasse@98
 | 
    35 	-- Save info
 | 
| 
contrebasse@98
 | 
    36 	cookingName = GetSpellInfo(COOKING_ID)
 | 
| 
contrebasse@98
 | 
    37 	
 | 
| 
contrebasse@98
 | 
    38 	-- Show if needed
 | 
| 
contrebasse@98
 | 
    39 	A.ManageCampFireBtn()
 | 
| 
contrebasse@98
 | 
    40 end
 | 
| 
contrebasse@98
 | 
    41 
 | 
| 
contrebasse@98
 | 
    42 -- Hide button
 | 
| 
contrebasse@98
 | 
    43 function A.HideCampFireBtn()
 | 
| 
contrebasse@98
 | 
    44 	btn:Hide()
 | 
| 
contrebasse@98
 | 
    45 end
 | 
| 
contrebasse@98
 | 
    46 
 | 
| 
contrebasse@98
 | 
    47 -- Show button if applicable
 | 
| 
contrebasse@98
 | 
    48 function A.ManageCampFireBtn()
 | 
| 
contrebasse@98
 | 
    49 	if not btn then return end
 | 
| 
contrebasse@98
 | 
    50 	-- Display only if the tradeskill is Cooking
 | 
| 
contrebasse@98
 | 
    51 	local tradeskillName = GetTradeSkillLine()
 | 
| 
contrebasse@98
 | 
    52 	if tradeskillName ~= cookingName then
 | 
| 
contrebasse@98
 | 
    53 		btn:Hide()
 | 
| 
contrebasse@98
 | 
    54 	else
 | 
| 
contrebasse@98
 | 
    55 		btn:Show()
 | 
| 
contrebasse@98
 | 
    56 	end
 | 
| 
contrebasse@98
 | 
    57 end
 |