Added in Alternate Character Knowledge. Will now show the ranks on bank alts for any knowledge across all your characters

Wobin [04-13-14 - 14:48]
Added in Alternate Character Knowledge. Will now show the ranks on bank alts for any knowledge across all your characters
Filename
SousChef.lua
diff --git a/SousChef.lua b/SousChef.lua
index 465096e..9f7bb31 100644
--- a/SousChef.lua
+++ b/SousChef.lua
@@ -40,26 +40,27 @@ local function MatchInGlobalCookbook(bag, slot)
 	return settings.Cookbook[GetItemName(bag,slot):lower():gsub(" ", "")]
 end

+ rowClicked = {}
+
 local function AddDetails(row)
-	if not row.dataEntry or not row.dataEntry.data or row.AddedRecipes then return false end
+	if not row.dataEntry or not row.dataEntry.data or rowClicked[row] then return false end
 	local bagId = row.dataEntry.data.bagId
 	local slotIndex = row.dataEntry.data.slotIndex
 	if ((GetItemCraftingInfo(bagId, slotIndex)) ~= CRAFTING_TYPE_PROVISIONING) then	return false end

 	local usableIngredient = ReverseCookbook[GetItemID(GetItemLink(bagId, slotIndex))]
+	if settings.showAltKnowledge then usableIngredient = settings.ReverseCookbook[GetItemID(GetItemLink(bagId, slotIndex))] end
 	if usableIngredient then
 		ItemTooltip:AddLine("Used in:")
 		for i,v in ipairs(usableIngredient) do
 			ItemTooltip:AddLine(v)
 		end
-		row.AddedRecipes = true
+		rowClicked[row] = true
 	end
 	return false
 end

-
-
-rowHandler = {}
+local rowHandler = {}

 local function AddRankToSlot(row)
 	local bagId = row.dataEntry.data.bagId
@@ -70,7 +71,7 @@ local function AddRankToSlot(row)
 		rankIcon =  WINDOW_MANAGER:CreateControl(row:GetName() .. "SousChef", row, CT_TEXTURE)
 		slotLines[row:GetName()] = rankIcon
 		ZO_PreHookHandler(row, "OnMouseDown", AddDetails)
-		ZO_PreHookHandler(row, "OnMouseUp", function(self) self.AddedRecipes = nil end )
+		ZO_PreHookHandler(row, "OnMouseExit", function(self) rowClicked[self] = nil end )
 	end

 	-- Allow for ingeniousclown's Inventory Grid View
@@ -86,6 +87,7 @@ local function AddRankToSlot(row)

 	if ((GetItemCraftingInfo(bagId, slotIndex)) == CRAFTING_TYPE_PROVISIONING) then
 		local texture = Pantry[GetItemID(GetItemLink(bagId, slotIndex))]
+		if settings.showAltKnowledge then texture = settings.Pantry[GetItemID(GetItemLink(bagId, slotIndex))] end
 		if texture then
 			rankIcon:SetColor(settings.colour[1], settings.colour[2], settings.colour[3])
 			rankIcon:SetHidden(false)
@@ -112,6 +114,14 @@ local function AddRankToSlot(row)
 	end
 end

+local function AddRecipe(Cookbook, link)
+	for _,v in pairs(Cookbook) do
+		if v == link then return end
+	end
+	table.insert(Cookbook, link)
+end
+
+
 local function ParseRecipes()
 	local lists = GetNumRecipeLists()
 	for listIndex = 1, lists do
@@ -126,9 +136,13 @@ local function ParseRecipes()
 					local link = GetItemID(GetRecipeIngredientItemLink(listIndex, recipeIndex, ingredientIndex, LINK_STYLE_NORMAL))
 					-- Store the fact that the ingredient is used
 					Pantry[link] = level
+					settings.Pantry[link] = level
 					-- Store the recipe it's used in
 					if not ReverseCookbook[link] then ReverseCookbook[link] = {} end
-					table.insert(ReverseCookbook[link], GetRecipeResultItemLink(listIndex, recipeIndex, LINK_STYLE_BRACKETS))
+					AddRecipe(ReverseCookbook[link], GetRecipeResultItemLink(listIndex, recipeIndex, LINK_STYLE_BRACKETS))
+					-- Store the global reference
+					if not settings.ReverseCookbook[link] then settings.ReverseCookbook[link] = {} end
+					AddRecipe(settings.ReverseCookbook[link], GetRecipeResultItemLink(listIndex, recipeIndex, LINK_STYLE_BRACKETS))
 				end
 			end

@@ -148,6 +162,10 @@ local function SousChefCreateSettings()
 	LAM:AddCheckbox(panel, "markAltKnows", "Alternate Character Check", "Indicate if an alt knows the recipe on unknown recipes. Will only work if the above setting is set to 'unknown'",
 						function() return settings.markAlt end,
 						function(value) settings.markAlt = not settings.markAlt end)
+	LAM:AddCheckbox(panel, "showAltKnows", "Alternate Character Recipe Knowledge", "Show rank indicators on alts for all recipe knowledge of all alternate characters",
+						function() return settings.showAltKnowledge end,
+						function(value) settings.showAltKnowledge = not settings.showAltKnowledge end)
+
 	LAM:AddColorPicker(panel, "setColour", "Indicator colour",
 						"Allows you to set the colour of the indicator",
 						function() return settings.colour[1], settings.colour[2], settings.colour[3] end,
@@ -166,10 +184,13 @@ local function SousChef_Loaded(eventCode, addOnName)
 		checkKnown = "unknown",
 		markAlt = false,
 		colour = {1, 1, 1},
-		Cookbook = {}
+		Cookbook = {},
+		Pantry = {},
+		ReverseCookbook = {},
+		showAltKnowledge = false
 	}

-	settings = ZO_SavedVars:NewAccountWide("SousChef_Settings", 3, nil, defaults)
+	settings = ZO_SavedVars:NewAccountWide("SousChef_Settings", 5, nil, defaults)

     SLASH_COMMANDS["/SousChef"] = function()
     	settings.watching = not settings.watching
@@ -216,17 +237,6 @@ local function SousChef_Loaded(eventCode, addOnName)
 	ZO_ScrollList_RefreshVisible(BACKPACK)
 	ZO_ScrollList_RefreshVisible(BANK)
 	ZO_ScrollList_RefreshVisible(GUILD_BANK)
-
-
-
-	--[[ Hook into the tooltip
-	-- This causes security errors, will have to reconsider
-	SousChefTooltip = ZO_InventorySlot_OnMouseEnter
-	function ZO_InventorySlot_OnMouseEnter(...)
-		local control = ...
-		CallSecureProtected("SousChefTooltip", control, ...)
-		AddDetails(control)
-	end--]]
 end

 local function SousChef_Initialized()