annotate 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
rev   line source
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@103 10 if not GetTradeSkillLine() or InCombatLockdown() then return end
contrebasse@103 11
contrebasse@98 12 -- create the frame
contrebasse@98 13 btn = CreateFrame("Button", nil, TradeSkillFrame, "SecureActionButtonTemplate")
contrebasse@98 14 btn:SetNormalTexture(select(3,GetSpellInfo(CAMPFIRE_ID)))
contrebasse@98 15 btn:SetSize(24,24)
contrebasse@98 16 btn:SetPoint("BOTTOMRIGHT",TradeSkillFrame,"BOTTOMRIGHT",-10,179)
contrebasse@98 17
contrebasse@98 18 -- Set the action
contrebasse@98 19 btn:SetAttribute("type", "spell")
contrebasse@98 20 btn:SetAttribute("spell", CAMPFIRE_ID)
contrebasse@98 21
contrebasse@98 22 -- Set the tooltip
contrebasse@98 23 btn:SetScript("OnEnter",function(self)
contrebasse@98 24 GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT")
contrebasse@98 25 GameTooltip:SetSpellByID(CAMPFIRE_ID)
contrebasse@98 26 GameTooltip:Show()
contrebasse@98 27 end)
contrebasse@98 28 btn:SetScript("OnLeave",function() GameTooltip:Hide(); end)
contrebasse@98 29
contrebasse@98 30 -- Add cooldown
contrebasse@98 31 btn.cooldown = CreateFrame("Cooldown",nil,btn)
contrebasse@98 32 btn.cooldown:SetAllPoints(btn)
contrebasse@98 33 local CooldownFrame_SetTimer = CooldownFrame_SetTimer
contrebasse@98 34 local GetSpellCooldown = GetSpellCooldown
contrebasse@98 35 btn:SetScript("OnUpdate",function(self) CooldownFrame_SetTimer(self.cooldown,GetSpellCooldown(CAMPFIRE_ID)); end)
contrebasse@98 36
contrebasse@98 37 -- Show if needed
contrebasse@98 38 A.ManageCampFireBtn()
contrebasse@98 39 end
contrebasse@98 40
contrebasse@98 41 -- Hide button
contrebasse@98 42 function A.HideCampFireBtn()
contrebasse@101 43 if btn then btn:Hide() end
contrebasse@98 44 end
contrebasse@98 45
contrebasse@98 46 -- Show button if applicable
contrebasse@98 47 function A.ManageCampFireBtn()
contrebasse@98 48 -- Display only if the tradeskill is Cooking
contrebasse@103 49 if not cookingName then cookingName = GetSpellInfo(COOKING_ID) end
contrebasse@103 50 if GetTradeSkillLine() ~= cookingName then
contrebasse@103 51 if btn then btn:Hide() end
contrebasse@98 52 else
contrebasse@103 53 -- create button if necessary
contrebasse@103 54 if not btn then
contrebasse@103 55 A.InitialiseCampFireBtn()
contrebasse@103 56 end
contrebasse@103 57 -- It may not have been created
contrebasse@103 58 if not btn then return end
contrebasse@98 59 btn:Show()
contrebasse@98 60 end
contrebasse@98 61 end