changeset 103:c8d527a9fb3a v1.0beta11

Better manage combat and secure buttons
author contrebasse
date Sat, 21 May 2011 14:19:33 +0200
parents e74ed53097d7
children a9bda1f95232
files CampFireButton.lua ReagentMaker.lua SecureMenu.lua
diffstat 3 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/CampFireButton.lua	Fri May 20 23:28:41 2011 +0200
+++ b/CampFireButton.lua	Sat May 21 14:19:33 2011 +0200
@@ -7,6 +7,8 @@
 
 -- 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)))
@@ -32,9 +34,6 @@
 	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
@@ -46,12 +45,17 @@
 
 -- 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()
+	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
--- a/ReagentMaker.lua	Fri May 20 23:28:41 2011 +0200
+++ b/ReagentMaker.lua	Sat May 21 14:19:33 2011 +0200
@@ -112,9 +112,6 @@
 
 	-- Button for enchanting directy on a scroll
 	A.LoadEnchantOnScroll()
-
-	-- Button to cast a campfire
-	A.InitialiseCampFireBtn()
 end -- function
 
 -- Function run after selecting a item in the tradeskill window
--- a/SecureMenu.lua	Fri May 20 23:28:41 2011 +0200
+++ b/SecureMenu.lua	Sat May 21 14:19:33 2011 +0200
@@ -324,7 +324,10 @@
 -- Fill the window and open it
 function A.externalCraftWindow(itemID,superItemID)
 	-- Do not open during combat
-	if InCombatLockdown() then return end
+	if InCombatLockdown() then
+		A.Error(SPELL_FAILED_AFFECTING_COMBAT)		
+		return
+	end
 
 	-- Save the tradeskill
 	A.currentTradeSkill = GetTradeSkillLine()