Fixing a CtD bug in the tooltips

katkat42 [11-26-14 - 06:40]
Fixing a CtD bug in the tooltips
Filename
Common.lua
Inventory.lua
TradingHouse.lua
diff --git a/Common.lua b/Common.lua
index e2acf4a..f017659 100644
--- a/Common.lua
+++ b/Common.lua
@@ -101,17 +101,22 @@ local function CalculateHowManyCouldBeCreated(recipeListIndex, recipeIndex, numI
     return minCount or 0
 end

-function SousChef.AddDetails(row)
+function SousChef.AddDetails(row)
 	if not row.dataEntry or not row.dataEntry.data or rowClicked == row then return false end
 	rowClicked = row
 	local rowInfo = row.dataEntry.data
 	local bagId = rowInfo.bagId or rowInfo.lootId
 	local slotIndex = rowInfo.slotIndex
-	if bagId == nil then
-		bagId = slotIndex
+	if bagId == nil then
+		if slotIndex == nil then return end
+		bagId = slotIndex + 0
 		slotIndex = nil
 	end
-	local itemLink = (slotIndex and GetItemLink(bagId, slotIndex)) or (rowInfo.lootId and GetLootItemLink(bagId)) or (TRADING_HOUSE:IsAtTradingHouse() and GetTradingHouseSearchResultItemLink(bagId)) or (GetStoreItemLink(bagId))
+	local itemLink = (slotIndex and GetItemLink(bagId, slotIndex))
+		or (rowInfo.lootId and GetLootItemLink(bagId))
+		or (TRADING_HOUSE:IsAtTradingHouse() and TRADING_HOUSE.m_numItemsOnPage ~= 0 and GetTradingHouseSearchResultItemLink(bagId))
+		or (GetStoreItemLink(bagId))
+	if itemLink == "" then return end

 	-- item is a recipe
 	if GetItemLinkItemType(itemLink) == ITEMTYPE_RECIPE then
@@ -123,12 +128,12 @@ function SousChef.AddDetails(row)
             ItemTooltip:AddLine(u.TableKeyConcat(knownBy))
             return false
         end
-    end
+	end

-	-- if we're only showing items on the shopping list, and we've already hidden this item, then don't touch it!
+	--if we're only showing items on the shopping list, and we've already hidden this item, then don't touch it!
     if SousChef.settings.onlyShowShopping and SousChef.slotLines[row:GetName()] and SousChef.slotLines[row:GetName()]:IsHidden() then return end

-	-- item is an ingredient
+	--item is an ingredient
 	local itemId = u.GetItemID(itemLink) -- Get itemId of inventory or loot or store slot
 	local usableIngredient
 	if SousChef.settings.showAltIngredientKnowledge then
diff --git a/Inventory.lua b/Inventory.lua
index f7895a2..1693ef3 100644
--- a/Inventory.lua
+++ b/Inventory.lua
@@ -11,7 +11,7 @@ function SousChef.AddRankToSlot(row, funcs)

 	local rankIcon = SousChef.getIcon(row)

-	-- Allow for ingeniousclown's Inventory Grid View
+	--Allow for ingeniousclown's Inventory Grid View
 	if row:GetWidth() - row:GetHeight() < 5 then	-- if we're mostly square
 		rankIcon:SetDimensions(20,20)
 		rankIcon:ClearAnchors()
@@ -24,20 +24,21 @@ function SousChef.AddRankToSlot(row, funcs)

 	rankIcon:SetHidden(true)

-	-- Are we gold or soulgem slot? Stay hidden and go away
+	--Are we gold or soulgem slot? Stay hidden and go away
 	if not bagId or not slot.name or slot.name == "" then return end

 	local itemLink = idFunc(bagId, slotIndex)
 	local itemType = GetItemLinkItemType(itemLink)
-	-- let's try for a performance gain here: if it's not our type of item, go away now
+	--let's try for a performance gain here: if it's not our type of item, go away now
 	if (itemType ~= ITEMTYPE_FLAVORING) and (itemType ~= ITEMTYPE_INGREDIENT) and (itemType ~= ITEMTYPE_RECIPE) and (itemType ~= ITEMTYPE_SPICE) then
 		return
 	end
+
+	--are we an ingredient?
 	local id = u.GetItemID(itemLink)
 	local texture = SousChef.Pantry[id]
 	if SousChef.settings.showAltIngredientKnowledge then texture = SousChef.settings.Pantry[id] end
 	if texture then
-		-- we're an ingredient
 		rankIcon:SetHidden(false)

 		if SousChef.settings.boldIcon then
@@ -55,14 +56,13 @@ function SousChef.AddRankToSlot(row, funcs)
 		return
 	end

-	-- are we a recipe?
+	--are we a recipe?
     if SousChef.settings.processRecipes then
-    	if u.MatchInIgnoreList(slot.name) then return end
-    	if GetItemLinkItemType(itemLink) == ITEMTYPE_RECIPE then
-	        local match = SousChef.Cookbook[u.CleanString(GetItemLinkName(GetItemLinkRecipeResultItemLink(itemLink)))]
-	        local gmatch = SousChef.settings.Cookbook[u.CleanString(GetItemLinkName(GetItemLinkRecipeResultItemLink(itemLink)))]
-	        if (match and SousChef.settings.checkKnown == "known") or
-	           (not match and SousChef.settings.checkKnown == "unknown")then
+		if u.MatchInIgnoreList(slot.name) then return end
+		if GetItemLinkItemType(itemLink) == ITEMTYPE_RECIPE then
+			local match = SousChef.Cookbook[u.CleanString(GetItemLinkName(GetItemLinkRecipeResultItemLink(itemLink)))]
+			local gmatch = SousChef.settings.Cookbook[u.CleanString(GetItemLinkName(GetItemLinkRecipeResultItemLink(itemLink)))]
+			if (match and SousChef.settings.checkKnown == "known") or (not match and SousChef.settings.checkKnown == "unknown")then
 	            rankIcon:SetTexture(m.CANLEARN)
 	            rankIcon:SetHidden(false)
 	            if not match and gmatch and SousChef.settings.checkKnown == "unknown" and SousChef.settings.markAlt then
diff --git a/TradingHouse.lua b/TradingHouse.lua
index 49a3a22..6914b90 100644
--- a/TradingHouse.lua
+++ b/TradingHouse.lua
@@ -9,7 +9,7 @@ function SousChef.HookTrading(...)
         TRADING_HOUSE.m_searchResultsList.dataTypes[1].setupCallback = function(...)
             local row, data = ...
             SousChef.hookedDataFunction(...)
-            SousChef.AddRankToSlot(row, {GetTradingHouseSearchResultItemLink, "slotIndex", nil})
+            zo_callLater(function() SousChef.AddRankToSlot(row, {GetTradingHouseSearchResultItemLink, "slotIndex", nil}) end, 100)
         end
     else
         d("SousChef could not hook into the Trading House")