diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bff2d76
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.iml
diff --git a/SousChef.lua b/SousChef.lua
index 59e7c25..5d3cf49 100644
--- a/SousChef.lua
+++ b/SousChef.lua
@@ -5,11 +5,12 @@
inspired by ingeniousclown's Research Assistant
------------------------------------------------------------------]]--
+SousChef = {}
+
local LAM = LibStub:GetLibrary("LibAddonMenu-1.0")
local BACKPACK = ZO_PlayerInventoryBackpack
local BANK = ZO_PlayerBankBackpack
local GUILD_BANK = ZO_GuildBankBackpack
-local GUILD_SHOP = ZO_TradingHouse
local COOKING_RANK_1 = [[SousChef\media\One.dds]]
local COOKING_RANK_2 = [[SousChef\media\Two.dds]]
@@ -30,56 +31,83 @@ local COOKINGB = { COOKING_RANK_1B, COOKING_RANK_2B, COOKING_RANK_3B, COOKING_RA
local CANLEARN = [[/esoui/art/loot/loot_finesseitem.dds]]
local containerHooks = { INVENTORY_BACKPACK, INVENTORY_BANK, INVENTORY_GUILD_BANK }
local itemQuality = { ITEM_QUALITY_MAGIC = { 0, 0, 1 }, ITEM_QUALITY_NORMAL = {1,1,1}, ITEM_QUALITY_ARCANE = {1, 0, 1}}
-local Pantry = {}
-local Cookbook = {}
-local ReverseCookbook = {}
-local settings = nil
-local slotLines = {}
-local hookedFunctions = {}
-local hookedDataFunction
+SousChef.Pantry = {}
+SousChef.Cookbook = {}
+SousChef.ReverseCookbook = {}
+SousChef.settings = nil
+SousChef.slotLines = {}
+SousChef.hookedFunctions = {}
+SousChef.hookedDataFunction = nil
local function GetItemID(link)
return tonumber(string.match(string.match(link, "%d+:"), "%d+"))
end
-function EndsWith(String,End)
+local function EndsWith(String,End)
return End=='' or string.sub(String,-string.len(End))==End
end
-local function CleanString(entry)
- return entry:gsub("%^(%a+)", ""):gsub(" ",""):lower()
+local function StartsWith(String,Start)
+ return Start=='' or string.sub(String, 1, string.len(Start))==Start
end
-local function MatchInCookbook(bag, slot)
- return Cookbook[CleanString(GetItemName(bag, slot))]
+local function CleanString(entry)
+ return entry:gsub("%^(%a+)", ""):gsub(" ",""):gsub("-",""):lower()
end
-local function MatchInGlobalCookbook(bag, slot)
- return settings.Cookbook[CleanString(GetItemName(bag,slot))]
+local function MatchesRecipe(entry)
+ return CleanString(entry):find(CleanString(GetString(SI_ITEMTYPE29)))
+end
+
+local function MatchInCookbook(name)
+ name = CleanString(name)
+ for recipe,known in pairs(SousChef.Cookbook) do
+ if StartsWith(name,recipe) or EndsWith(name, recipe) then
+ if (#recipe + #CleanString(GetString(SI_ITEMTYPE29)) - #name) < 3 then
+ return known
+ end
+ end
+ end
+ return nil
+end
+
+local function MatchInGlobalCookbook(name)
+ name = CleanString(name)
+ for recipe,known in pairs(SousChef.settings.Cookbook) do
+ if StartsWith(name,recipe) or EndsWith(name, recipe) then
+ if (#recipe + #CleanString(GetString(SI_ITEMTYPE29)) - #name) < 3 then
+ return known
+ end
+ end
+ end
+ return nil
end
rowClicked = {}
local function AddDetails(row)
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
-
- local gmatch = settings.Cookbook[CleanString(row.dataEntry.data.name)]
- if gmatch then
- ItemTooltip:AddLine("")
- ItemTooltip:AddLine("Known by ", "ZoFontWinH5", 1,1,1, BOTTOM, MODIFY_TEXT_TYPE_UPPERCASE)
- for i,v in pairs(gmatch) do
- ItemTooltip:AddLine(i)
- end
- rowClicked[row] = true
- return
- end
+ local rowInfo = row.dataEntry.data
+ local bagId = rowInfo.bagId
+ local slotIndex = rowInfo.slotIndex
+
+ if MatchesRecipe(rowInfo.name) then
+ local gmatch = MatchInGlobalCookbook(rowInfo.name)
+ if gmatch then
+ ItemTooltip:AddLine("")
+ ItemTooltip:AddLine("Known by ", "ZoFontWinH5", 1,1,1, BOTTOM, MODIFY_TEXT_TYPE_UPPERCASE)
+ for i,v in pairs(gmatch) do
+ ItemTooltip:AddLine(i)
+ end
+ rowClicked[row] = true
+ return
+ end
+ end
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
+ local usableIngredient = SousChef.ReverseCookbook[GetItemID(GetItemLink(bagId, slotIndex))]
+ if SousChef.settings.showAltKnowledge then usableIngredient = SousChef.settings.ReverseCookbook[GetItemID(GetItemLink(bagId, slotIndex))] end
if usableIngredient then
ItemTooltip:AddLine("Used in:", "ZoFontWinH5", 1,1,1, BOTTOM, MODIFY_TEXT_TYPE_UPPERCASE)
for i,v in ipairs(usableIngredient) do
@@ -91,12 +119,12 @@ local function AddDetails(row)
end
local function getIcon(row)
- local rankIcon = slotLines[row:GetName()]
+ local rankIcon = SousChef.slotLines[row:GetName()]
if(not rankIcon) then
rankIcon = WINDOW_MANAGER:CreateControl(row:GetName() .. "SousChef", row, CT_TEXTURE)
- slotLines[row:GetName()] = rankIcon
+ SousChef.slotLines[row:GetName()] = rankIcon
ZO_PreHookHandler(row, "OnMouseDown", AddDetails)
- ZO_PreHookHandler(row, "OnMouseExit", function(self) rowClicked[self] = nil end )
+ ZO_PreHookHandler(row, "OnMouseExit", function(self) rowClicked[self] = nil return false end )
end
return rankIcon
end
@@ -104,9 +132,9 @@ end
local rowHandler = {}
local function AddRankToSlot(row)
- local bagId = row.dataEntry.data.bagId
- local slotIndex = row.dataEntry.data.slotIndex
-
+ local slot = row.dataEntry.data
+ local bagId = slot.bagId
+ local slotIndex = slot.slotIndex
local rankIcon = getIcon(row)
-- Allow for ingeniousclown's Inventory Grid View
@@ -120,13 +148,13 @@ local function AddRankToSlot(row)
rankIcon:SetHidden(true)
- 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 ((GetItemCraftingInfo(bagId, slotIndex)) == CRAFTING_TYPE_PROVISIONING) then
+ local texture = SousChef.Pantry[GetItemID(GetItemLink(bagId, slotIndex))]
+ if SousChef.settings.showAltKnowledge then texture = SousChef.settings.Pantry[GetItemID(GetItemLink(bagId, slotIndex))] end
if texture then
- rankIcon:SetColor(settings.colour[1], settings.colour[2], settings.colour[3])
+ rankIcon:SetColor(SousChef.settings.colour[1], SousChef.settings.colour[2], SousChef.settings.colour[3])
rankIcon:SetHidden(false)
- if settings.boldIcon then
+ if SousChef.settings.boldIcon then
rankIcon:SetTexture(COOKINGB[texture])
else
rankIcon:SetTexture(COOKING[texture])
@@ -135,13 +163,13 @@ local function AddRankToSlot(row)
end
else
if GetItemType(bagId, slotIndex) == ITEMTYPE_RECIPE then
- local match = MatchInCookbook(bagId, slotIndex)
- local gmatch = MatchInGlobalCookbook(bagId, slotIndex)
- if (match and settings.checkKnown == "known") or
- (not match and settings.checkKnown == "unknown")then
+ local match = MatchInCookbook(slot.name)
+ local gmatch = MatchInGlobalCookbook(slot.name)
+ if (match and SousChef.settings.checkKnown == "known") or
+ (not match and SousChef.settings.checkKnown == "unknown")then
rankIcon:SetTexture(CANLEARN)
rankIcon:SetHidden(false)
- if not match and gmatch and settings.checkKnown == "unknown" and settings.markAlt then
+ if not match and gmatch and SousChef.settings.checkKnown == "unknown" and SousChef.settings.markAlt then
rankIcon:SetColor(1,1,1,0.2)
else
rankIcon:SetColor(1,1,1,1)
@@ -157,16 +185,16 @@ local function AddTradingSlot(row, result)
rankIcon:SetHidden(true)
- if EndsWith(result.name:lower(), GetString(SI_ITEMTYPE29):lower()) then
- local match = Cookbook[CleanString(result.name)]
- local gmatch = settings.Cookbook[CleanString(result.name)]
- if (match and settings.checkKnown == "known") or
- (not match and settings.checkKnown == "unknown")then
+ if MatchesRecipe(result.name) then
+ local match = MatchInCookbook(result.name)
+ local gmatch = MatchInGlobalCookbook(result.name)
+ if (match and SousChef.settings.checkKnown == "known") or
+ (not match and SousChef.settings.checkKnown == "unknown")then
rankIcon:SetDimensions(30, 30)
rankIcon:SetAnchor(CENTER, row, CENTER, 230)
rankIcon:SetTexture(CANLEARN)
rankIcon:SetHidden(false)
- if not match and gmatch and settings.checkKnown == "unknown" and settings.markAlt then
+ if not match and gmatch and SousChef.settings.checkKnown == "unknown" and SousChef.settings.markAlt then
rankIcon:SetColor(1,1,1,0.2)
else
rankIcon:SetColor(1,1,1,1)
@@ -189,24 +217,24 @@ local function ParseRecipes()
for recipeIndex = 1, count do
if GetRecipeInfo(listIndex, recipeIndex) then
-- Store the recipes known
- local recipeName = CleanString((GetRecipeResultItemInfo(listIndex, recipeIndex)).. GetString(SI_ITEMTYPE29))
- Cookbook[recipeName] = true
- if not settings.Cookbook[recipeName] then
- settings.Cookbook[recipeName] = {}
+ local recipeName = CleanString((GetRecipeResultItemInfo(listIndex, recipeIndex)))
+ SousChef.Cookbook[recipeName] = true
+ if not SousChef.settings.Cookbook[recipeName] then
+ SousChef.settings.Cookbook[recipeName] = {}
end
- settings.Cookbook[recipeName][GetUnitName("player")] = true
+ SousChef.settings.Cookbook[recipeName][GetUnitName("player")] = true
local _, _, ingredientCount, level = GetRecipeInfo(listIndex, recipeIndex)
for ingredientIndex = 1, ingredientCount do
local link = GetItemID(GetRecipeIngredientItemLink(listIndex, recipeIndex, ingredientIndex, LINK_STYLE_NORMAL))
-- Store the fact that the ingredient is used
- Pantry[link] = math.max(level, Pantry[link] or 0)
- settings.Pantry[link] = math.max(level, Pantry[link] or 0)
+ SousChef.Pantry[link] = math.max(level, SousChef.Pantry[link] or 0)
+ SousChef.settings.Pantry[link] = math.max(level, SousChef.Pantry[link] or 0)
-- Store the recipe it's used in
- if not ReverseCookbook[link] then ReverseCookbook[link] = {} end
- AddRecipe(ReverseCookbook[link], zo_strformat(SI_TOOLTIP_ITEM_NAME, GetRecipeResultItemLink(listIndex, recipeIndex, LINK_STYLE_BRACKETS)))
+ if not SousChef.ReverseCookbook[link] then SousChef.ReverseCookbook[link] = {} end
+ AddRecipe(SousChef.ReverseCookbook[link], zo_strformat(SI_TOOLTIP_ITEM_NAME, GetRecipeResultItemLink(listIndex, recipeIndex, LINK_STYLE_BRACKETS)))
-- Store the global reference
- if not settings.ReverseCookbook[link] then settings.ReverseCookbook[link] = {} end
- AddRecipe(settings.ReverseCookbook[link], zo_strformat(SI_TOOLTIP_ITEM_NAME, GetRecipeResultItemLink(listIndex, recipeIndex, LINK_STYLE_BRACKETS)))
+ if not SousChef.settings.ReverseCookbook[link] then SousChef.settings.ReverseCookbook[link] = {} end
+ AddRecipe(SousChef.settings.ReverseCookbook[link], zo_strformat(SI_TOOLTIP_ITEM_NAME, GetRecipeResultItemLink(listIndex, recipeIndex, LINK_STYLE_BRACKETS)))
end
end
@@ -214,37 +242,38 @@ local function ParseRecipes()
end
end
-local function SousChefCreateSettings()
- local panel = LAM:CreateControlPanel("SousChef", "Sous Chef")
+local function SousChefCreateSettings()
+ d("Creating menu")
+ local panel = LAM:CreateControlPanel("SousChefMenu", "Sous Chef")
LAM:AddHeader(panel, "SousChef_General", "Settings")
LAM:AddDropdown(panel, "markLearnt", "Mark if recipes are ",
"How do you want Sous Chef to indicate your knowledge of a recipe?",
- {"known", "unknown"}, function() return settings.checkKnown end,
- function(valueString) settings.checkKnown = valueString end)
+ {"known", "unknown"}, function() return SousChef.settings.checkKnown end,
+ function(valueString) SousChef.settings.checkKnown = valueString end)
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)
+ function() return SousChef.settings.markAlt end,
+ function(value) SousChef.settings.markAlt = not SousChef.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)
+ function() return SousChef.settings.showAltKnowledge end,
+ function(value) SousChef.settings.showAltKnowledge = not SousChef.settings.showAltKnowledge end)
LAM:AddCheckbox(panel, "useBold", "Use bolder icons", "Swap out rank icon to a more flat display",
- function() return settings.boldIcon end,
- function(value) settings.boldIcon = not settings.boldIcon end)
+ function() return SousChef.settings.boldIcon end,
+ function(value) SousChef.settings.boldIcon = not SousChef.settings.boldIcon 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,
- function(r,g,b) settings.colour[1] = r; settings.colour[2] = g; settings.colour[3] = b end)
+ function() return SousChef.settings.colour[1], SousChef.settings.colour[2], SousChef.settings.colour[3] end,
+ function(r,g,b) SousChef.settings.colour[1] = r; SousChef.settings.colour[2] = g; SousChef.settings.colour[3] = b end)
end
local function HookTrading(...)
- if hookedDataFunction then return end
- hookedDataFunction = ZO_TradingHouseItemPaneSearchResults.dataTypes[1].setupCallback
+ if SousChef.hookedDataFunction then return end
+ SousChef.hookedDataFunction = ZO_TradingHouseItemPaneSearchResults.dataTypes[1].setupCallback
ZO_TradingHouseItemPaneSearchResults.dataTypes[1].setupCallback = function(...)
local row, data = ...
- hookedDataFunction(...)
+ SousChef.hookedDataFunction(...)
AddTradingSlot(row, data)
end
end
@@ -265,17 +294,9 @@ local function SousChef_Loaded(eventCode, addOnName)
showAltKnowledge = false,
boldIcon = false
}
-
- settings = ZO_SavedVars:NewAccountWide("SousChef_Settings", 7, nil, defaults)
-
- SLASH_COMMANDS["/SCDebug"] = function()
- d("Debug mode on")
- SCCookbook = Cookbook
- SCRCookbook = ReverseCookbook
- SCPantry = Pantry
- SCslotList = slotLines
- SCsettings = settings
- end
+
+ SousChef.settings = ZO_SavedVars:NewAccountWide("SousChef_Settings", 8, nil, defaults)
+
local function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
@@ -283,8 +304,8 @@ local function SousChef_Loaded(eventCode, addOnName)
end
SLASH_COMMANDS['/scstats'] = function()
- d("Number of recipes known: ".. tablelength(settings.Cookbook))
- d("Number of ingredients tracked: "..tablelength(settings.Pantry))
+ d("Number of recipes known: ".. tablelength(SousChef.settings.Cookbook))
+ d("Number of ingredients tracked: "..tablelength(SousChef.settings.Pantry))
end
SousChefCreateSettings()
@@ -297,11 +318,11 @@ local function SousChef_Loaded(eventCode, addOnName)
for _,v in pairs(PLAYER_INVENTORY.inventories) do
local listView = v.listView
if listView and listView.dataTypes and listView.dataTypes[1] then
- hookedFunctions = listView.dataTypes[1].setupCallback
+ SousChef.hookedFunctions = listView.dataTypes[1].setupCallback
listView.dataTypes[1].setupCallback =
- function(rowControl, slot)
- hookedFunctions(rowControl, slot)
+ function(rowControl, slot)
+ SousChef.hookedFunctions(rowControl, slot)
AddRankToSlot(rowControl)
end
end