diff SecureMenu.lua @ 33:218e1dd1b821

Hide external frame when selecting a recipe which doesn't need this reagent
author contrebasse
date Fri, 29 Apr 2011 00:14:25 +0200
parents 416c307fd00b
children 0af9cb8a79f0
line wrap: on
line diff
--- a/SecureMenu.lua	Thu Apr 28 23:39:30 2011 +0200
+++ b/SecureMenu.lua	Fri Apr 29 00:14:25 2011 +0200
@@ -51,6 +51,18 @@
 	GameTooltip:Hide()
 	A.tooltipRecipe:Hide()
 end)
+
+-- Hide frame when selecting a recipe which doesn't need this reagent
+hooksecurefunc("SelectTradeSkill",function()
+	local selectedIndex = GetTradeSkillSelectionIndex()
+	for reagentRecipeIndex = 1,GetTradeSkillNumReagents(selectedIndex) do
+		local reagentID = A.link2ID(GetTradeSkillReagentItemLink(selectedIndex, reagentRecipeIndex))
+		if reagentID == MenuFrame.itemID or (MenuFrame.superItemID and reagentID == MenuFrame.superItemID) then
+			return
+		end
+	end
+	MenuFrame:Hide()
+end)
 A.MenuFrame = MenuFrame
 
 -- Background adaptable vertically
@@ -272,7 +284,7 @@
 end -- function
 
 -- Fill the window and open it
-function A.externalCraftWindow(itemID)
+function A.externalCraftWindow(itemID,superItemID)
 	-- Do not open during combat
 	if InCombatLockdown() then return end
 
@@ -296,6 +308,8 @@
 	-- Save vars to show the tooltip later
 	MenuFrame.reagentLink = link
 	MenuFrame.spellLink = A.data[itemID].spellLink
+	MenuFrame.itemID = itemID
+	MenuFrame.superItemID = superItemID -- optional
 	
 	-- Loop over the available recipes
 	for _,reagent in ipairs(A.data[itemID]) do