diff --git a/BestiaryUI.cs b/BestiaryUI.cs index 8a72230..6ab889e 100644 --- a/BestiaryUI.cs +++ b/BestiaryUI.cs @@ -272,7 +272,7 @@ private bool PassNPCFilters(UINPCSlot slot) } } - if (RecipeBrowserUI.modIndex != RecipeBrowserUI.instance.mods.Length - 1) + if (RecipeBrowserUI.modIndex != 0) { if (slot.npc.modNPC == null) { diff --git a/ItemCatalogueUI.cs b/ItemCatalogueUI.cs index 7bb6871..aca94c2 100644 --- a/ItemCatalogueUI.cs +++ b/ItemCatalogueUI.cs @@ -262,7 +262,7 @@ internal void SetItem(UIItemCatalogueItemSlot slot) private bool PassItemFilters(UIItemCatalogueItemSlot slot) { - if (RecipeBrowserUI.modIndex != RecipeBrowserUI.instance.mods.Length - 1) + if (RecipeBrowserUI.modIndex != 0) { if (slot.item.modItem == null) { diff --git a/Localization/en-US.lang b/Localization/en-US.lang index dc591a0..e4704d7 100644 --- a/Localization/en-US.lang +++ b/Localization/en-US.lang @@ -20,7 +20,7 @@ RecipeCatalogueUI.EmptyQuerySlotHint=Place item here CraftUI.EmptyQuerySlotHint=Place item here CraftUI.Calc=Calc -CraftUI.CalcTooltip=Toggles Preemptive Extended Craft Calculation in Recipes +CraftUI.CalcTooltip=Toggles Preemptive Extended Craft Calculation in Recipes\nCan cause lag CraftUI.Loot=Loot CraftUI.LootTooltip=Allow Farming in Craft Path (Only works for Enemies with Banners) CraftUI.Shop=Shop diff --git a/Patches.cs b/Patches.cs index 9394dbf..be758ae 100644 --- a/Patches.cs +++ b/Patches.cs @@ -1,5 +1,4 @@ -using Harmony; -using System; +using System; using System.Diagnostics; using System.Linq; using Terraria; @@ -8,7 +7,7 @@ namespace RecipeBrowser { public static class Patches { - + private static bool AdjTilesActive = false; public static void Apply() { // Patches are automatically unapplied on unload by TerrariaHooks. -ade @@ -18,7 +17,8 @@ public static void Apply() { orig(); - if (!new StackTrace().GetFrames().Any(x => x.GetMethod().Name.StartsWith("AdjTiles"))) + if(!AdjTilesActive) + //if (!new StackTrace().GetFrames().Any(x => x.GetMethod().Name.StartsWith("AdjTiles"))) { RecipeCatalogueUI.instance.InvalidateExtendedCraft(); //Main.NewText("FindRecipes postfix: InvalidateExtendedCraft"); @@ -31,6 +31,7 @@ public static void Apply() // This patch will call FindRecipes even if the player inventory is closed, keeping Craft tool buttons accurate. On.Terraria.Player.AdjTiles += (orig, player) => { + AdjTilesActive = true; orig(player); // AdjTiles does the opposite. This way recipes will be calculated @@ -56,6 +57,7 @@ public static void Apply() Recipe.FindRecipes(); } } + AdjTilesActive = false; }; } diff --git a/RecipeBrowser.cs b/RecipeBrowser.cs index ab91918..0d86395 100644 --- a/RecipeBrowser.cs +++ b/RecipeBrowser.cs @@ -1,5 +1,4 @@ -using Harmony; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Newtonsoft.Json; using System; diff --git a/RecipeBrowserUI.cs b/RecipeBrowserUI.cs index a4e8740..7e9b440 100644 --- a/RecipeBrowserUI.cs +++ b/RecipeBrowserUI.cs @@ -106,7 +106,7 @@ public void PostSetupContent() FieldInfo loadModsField = type.GetField("items", BindingFlags.Instance | BindingFlags.NonPublic); mods = ModLoader.Mods.Where(mod => ((Dictionary)loadModsField.GetValue(mod)).Count > 0).Select(mod => mod.Name).ToArray(); - modIndex = mods.Length - 1; + modIndex = 0; } public override void OnInitialize() @@ -313,7 +313,7 @@ private void ModFilterButton_OnRightClick(UIMouseEvent evt, UIElement listeningE private void ModFilterButton_OnMiddleClick(UIMouseEvent evt, UIElement listeningElement) { UIHoverImageButtonMod button = (evt.Target as UIHoverImageButtonMod); - modIndex = mods.Length - 1; + modIndex = 0; button.hoverText = RBText("ModFilter") + ": " + RBText("All"); UpdateModHoverImage(button); AllUpdateNeeded(); @@ -336,7 +336,7 @@ private void UpdateModHoverImage(UIHoverImageButtonMod button) private string GetModFilterTooltip(bool increment) { modIndex = increment ? (modIndex + 1) % mods.Length : (mods.Length + modIndex - 1) % mods.Length; - return modIndex == mods.Length - 1 ? RBText("All") : mods[modIndex]; + return modIndex == 0 ? RBText("All") : mods[modIndex]; } internal void AllUpdateNeeded() diff --git a/RecipeCatalogueUI.cs b/RecipeCatalogueUI.cs index 2ab8532..f25798f 100644 --- a/RecipeCatalogueUI.cs +++ b/RecipeCatalogueUI.cs @@ -503,7 +503,7 @@ private int ItemGridSort(UIElement x, UIElement y) private bool PassRecipeFilters(UIRecipeSlot recipeSlot, Recipe recipe, List groups) { // TODO: Option to filter by source of Recipe rather than by createItem maybe? - if (RecipeBrowserUI.modIndex != RecipeBrowserUI.instance.mods.Length - 1) + if (RecipeBrowserUI.modIndex != 0) { if (recipe.createItem.modItem == null) { diff --git a/RecipePath.cs b/RecipePath.cs index 6854594..096b89c 100644 --- a/RecipePath.cs +++ b/RecipePath.cs @@ -16,8 +16,8 @@ namespace RecipeBrowser internal class RecipePathTester { //internal static IdDictionary Search; - internal static bool print = true; - internal static bool printResults = true; + internal static bool print = false; + internal static bool printResults = false; //internal static bool printResultCounts = true; //internal static bool calculateAll = false; //internal static int calculateAllRepeat = 1; @@ -272,11 +272,12 @@ private static void FindCraftPaths(List paths, CraftPath inProgress, if (token.IsCancellationRequested) return; // Some notion of limiting depth of tree might help. - //int count = inProgress.root.GetAllChildrenPreOrder().Count(); //.OfType() - //if (count > 20) - //{ - // return; - //} + // TODO + // Limit by Total steps (TODO: steps only, not HAves) + int count = inProgress.root.GetAllChildrenPreOrder().Count(); //.OfType() + if (count > 20) { + return; + } // Current will always be an unfulfilled CraftPath.UnfulfilledNode current = inProgress.GetCurrent(); @@ -378,13 +379,16 @@ private static void FindCraftPaths(List paths, CraftPath inProgress, { bool encountered = false; - int npc = loots[lootable.First()].First(); // Only checks 1 item in Group, and first NPC that drops it. Fix later. - - int bannerID = Item.NPCtoBanner(npc); - if (bannerID > 0) - { - if (NPC.killCount[bannerID] > 0) - encountered = true; + // Only checks 1 item in Group. Fix later. + var npcs = loots[lootable.First()]; + foreach (var npc in npcs) { + int bannerID = Item.NPCtoBanner(npc); + if (bannerID > 0) { + if (NPC.killCount[bannerID] > 0) { + encountered = true; + break; + } + } } if (encountered) diff --git a/UIElements/UIRecipeInfo.cs b/UIElements/UIRecipeInfo.cs index 25f69ff..77d7e94 100644 --- a/UIElements/UIRecipeInfo.cs +++ b/UIElements/UIRecipeInfo.cs @@ -1,12 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using RecipeBrowser.UIElements; -using System.Collections.Generic; -using System.Text; -using Terraria; -using Terraria.GameContent.UI.Elements; -using Terraria.ID; -using Terraria.Map; using System.Text; using Terraria; using Terraria.GameContent.UI.Elements; @@ -94,22 +88,11 @@ protected override void DrawSelf(SpriteBatch spriteBatch) { row++; int tileID = selectedRecipe.requiredTile[tileIndex]; - string tileName = Lang.GetMapObjectName(MapHelper.TileToLookup(tileID, 0)); - if (tileName == "") - { - if (tileID < TileID.Count) - tileName = $"Tile {tileID}"; - else - tileName = Terraria.ModLoader.TileLoader.GetTile(tileID).Name + " (err no entry)"; - } - sb.Append($"{(comma ? ", " : "")}[c/{(Main.LocalPlayer.adjTile[tileID] ? yesColor : noColor).Hex3()}:{tileName}]"); - sbTiles.Append($"{(comma ? ", " : "")}[c/{(Main.LocalPlayer.adjTile[tileID] ? yesColor : noColor).Hex3()}:{tileName}]"); - //Terraria.UI.Chat.ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, tileName, new Vector2(positionX, positionY + num63), Main.LocalPlayer.adjTile[tileID] ? yesColor : noColor, 0f, Vector2.Zero, Vector2.One, -1f, 2f); -/* TODO: figure out if this code is still correct. string tileName = Utilities.GetTileName(tileID); + //Terraria.UI.Chat.ChatManager.DrawColorCodedStringWithShadow(spriteBatch, Main.fontMouseText, tileName, new Vector2(positionX, positionY + num63), Main.LocalPlayer.adjTile[tileID] ? yesColor : noColor, 0f, Vector2.Zero, Vector2.One, -1f, 2f); DoChatTag(sb, comma, Main.LocalPlayer.adjTile[tileID], tileName); DoChatTag(sbTiles, comma, Main.LocalPlayer.adjTile[tileID], tileName); -*/ + tileIndex++; comma = true; }