diff SecureMenu.lua @ 34:0af9cb8a79f0

Manage items not ready (not in cache ?) when opening the external frame. Can potentially conflict with BAG_UPDATE event.
author contrebasse
date Fri, 29 Apr 2011 21:26:19 +0200
parents 218e1dd1b821
children 5394c492850e
line wrap: on
line diff
--- a/SecureMenu.lua	Fri Apr 29 00:14:25 2011 +0200
+++ b/SecureMenu.lua	Fri Apr 29 21:26:19 2011 +0200
@@ -1,7 +1,7 @@
 local addonName, A = ...
 
 -- Create the menu frame
-local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent) --, "ReagentMakerDropDownMenu"); -- Needs a global name ?
+local MenuFrame = CreateFrame("Frame","ReagentMaker_ExternalFrame",UIParent)
 MenuFrame:Hide()
 MenuFrame:SetSize(192,256)
 MenuFrame:SetFrameStrata("DIALOG")
@@ -233,18 +233,18 @@
 	end
 
 	-- Set text and icon
-	local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(reagent[1])
+	local name, _, _, _, _, _, _, _, _, texture = GetItemInfo(reagent[1])
 	if name then
 		btn.itemName:SetText(name)
 	else
-		A.DEBUG("No item name : "..reagent[1])
+		--A.DEBUG("No item name : "..reagent[1])
 		return
 	end
 
 	if texture then
 		btn.icon:SetTexture(texture)
 	else
-		A.DEBUG("No item texture : "..reagent[1])
+		--A.DEBUG("No item texture : "..reagent[1])
 		return
 	end
 
@@ -281,8 +281,20 @@
 
 	-- Increase the entry number
 	numActiveEntries = numActiveEntries + 1
+
+	-- Everything went well
+	return true
 end -- function
 
+-- Function used on OnUpdate tu update the frame if there were errors the previous time
+local function reopen()
+	-- Release OnUpdate frame (could conflict with BAG_UPDATE)
+	MenuFrame:SetScript("OnUpdate",nil)
+
+	-- reopen
+	A.externalCraftWindow(MenuFrame.itemID,MenuFrame.superItemID)
+end
+
 -- Fill the window and open it
 function A.externalCraftWindow(itemID,superItemID)
 	-- Do not open during combat
@@ -299,7 +311,7 @@
 	numActiveEntries = 0
 
 	-- Fill the info of the reagent to make
-	local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID)
+	local name, _, quality, _, _, _, _, _, _, texture = GetItemInfo(itemID)
 	SetPortraitToTexture(itemIcon, texture)
 	TitleText:SetText(name)
 	local color = ITEM_QUALITY_COLORS[quality]
@@ -310,15 +322,16 @@
 	MenuFrame.spellLink = A.data[itemID].spellLink
 	MenuFrame.itemID = itemID
 	MenuFrame.superItemID = superItemID -- optional
-	
+
 	-- Loop over the available recipes
+	MenuFrame.state = true
 	for _,reagent in ipairs(A.data[itemID]) do
 		if A.data[itemID].spell then
 			-- Special spell
-			menuAddItem(A.data[itemID].spell,itemID,reagent,A.data[itemID].spellLink)
+			MenuFrame.state = menuAddItem(A.data[itemID].spell,itemID,reagent,A.data[itemID].spellLink) and state
 		else
 			-- Standard tradeskill spell UNTESTED
-			menuAddItem(A.craft,itemID,reagent)
+			MenuFrame.state = menuAddItem(A.craft,itemID,reagent) and state
 		end -- if
 	end -- for
 
@@ -330,4 +343,8 @@
 	MenuFrame.updateCounts()
 
 	MenuFrame:Show()
+
+	if not MenuFrame.state then
+		MenuFrame:SetScript("OnUpdate",reopen)
+	end
 end