Mercurial > wow > reagentmaker
view CampFireButton.lua @ 103:c8d527a9fb3a v1.0beta11
Better manage combat and secure buttons
author | contrebasse |
---|---|
date | Sat, 21 May 2011 14:19:33 +0200 |
parents | 060f5d0f7a35 |
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