From 335f26a6e9385f90d1982c6361da471622b57299 Mon Sep 17 00:00:00 2001 From: JavidPack Date: Wed, 6 Apr 2022 15:11:14 -0600 Subject: [PATCH] v0.4.5, Port 6e5a6fa7c5e37a213239d3b50abcc37b5afdd01c to 1.4 --- HEROsMod.cs | 14 +++++++++++++ UIKit/UIComponents/ItemBrowser.cs | 35 +++++++++++++++++++++++++++++++ build.txt | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/HEROsMod.cs b/HEROsMod.cs index 6447984..e2c3896 100644 --- a/HEROsMod.cs +++ b/HEROsMod.cs @@ -28,6 +28,7 @@ internal class HEROsMod : Mod { public static HEROsMod instance; internal static Dictionary translations; // reference to private field. + internal List modCategories; internal Dictionary> crossModGroupUpdated = new Dictionary>(); public override void Load() @@ -40,6 +41,8 @@ public override void Load() translations = (Dictionary)translationsField.GetValue(null); //LoadTranslations(); + modCategories = new List(); + // AddGlobalItem("HEROsModGlobalItem", new HEROsModGlobalItem()); // AddPlayer("HEROsModModPlayer", new HEROsModModPlayer()); //if (ModUtils.NetworkMode != NetworkMode.Server) @@ -125,6 +128,7 @@ public override void Unload() ServiceController = null; TimeWeatherControlHotbar.Unload(); ModUtils.previousInventoryItems = null; + modCategories = null; translations = null; instance = null; NetTextModule.DeserializeAsServer -= NetTextModule_DeserializeAsServer; @@ -300,6 +304,16 @@ args[3] as Action ); ModUtils.DebugText("...Permission Added"); } + else if (message == "AddItemCategory") + { + ModUtils.DebugText("Item Category Adding..."); + string sortName = args[1] as string; + string parentName = args[2] as string; + Predicate belongs = args[3] as Predicate; + if (!Main.dedServ) + modCategories.Add(new UIKit.UIComponents.ModCategory(sortName, parentName, belongs)); + ModUtils.DebugText("...Item Category Added"); + } else if (message == "HasPermission") { if (/*Main.netMode != Terraria.ID.NetmodeID.Server ||*/ argsLength != 3) // for now, only allow this call on Server (2) --> why?? diff --git a/UIKit/UIComponents/ItemBrowser.cs b/UIKit/UIComponents/ItemBrowser.cs index adbf166..2d27424 100644 --- a/UIKit/UIComponents/ItemBrowser.cs +++ b/UIKit/UIComponents/ItemBrowser.cs @@ -621,6 +621,26 @@ public static void ParseList2() new Category("Other", x=>false), }; + List categoryList = new List(Categories); + foreach (var modCallCategory in HEROsMod.instance.modCategories) + { + if (string.IsNullOrEmpty(modCallCategory.Parent)) + { + categoryList.Insert(categoryList.Count - 2, new Category(modCallCategory.Name, modCallCategory.belongs, true)); + } + else + { + foreach (var item in categoryList) + { + if (item.Name == modCallCategory.Parent) + { + item.SubCategories.Add(new Category(modCallCategory.Name, modCallCategory.belongs, true)); + } + } + } + } + Categories = categoryList.ToArray(); + foreach (var parent in Categories) { foreach (var sub in parent.SubCategories) @@ -759,6 +779,21 @@ private void Button_onLeftClick(object sender, EventArgs e) // internal UIImage button; //} + // Represents a requested Category + internal class ModCategory + { + internal Predicate belongs; + + internal string Name { get; private set; } + internal string Parent { get; private set; } + public ModCategory(string name, string parent, Predicate belongs) + { + Name = name; + Parent = parent; + this.belongs = belongs; + } + } + public class Category { //private Category _parentCategory = null; diff --git a/build.txt b/build.txt index 7ad7255..561e586 100644 --- a/build.txt +++ b/build.txt @@ -1,5 +1,5 @@ author = HERO, jopojelly, Matt Thompson, Panini -version = 0.4.4 +version = 0.4.5 versionScheme = ?.?.Fix.Quickfix displayName = HERO's Mod homepage = http://forums.terraria.org/index.php?threads/heros-mod-creative-mode-server-management-and-over-25-tools-1-3-1-1-compatible.44650/