Skip to content

Commit

Permalink
v0.4.5, Port 6e5a6fa to 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Apr 6, 2022
1 parent 3f5634e commit 335f26a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
14 changes: 14 additions & 0 deletions HEROsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class HEROsMod : Mod
{
public static HEROsMod instance;
internal static Dictionary<string, ModTranslation> translations; // reference to private field.
internal List<UIKit.UIComponents.ModCategory> modCategories;
internal Dictionary<string, Action<bool>> crossModGroupUpdated = new Dictionary<string, Action<bool>>();

public override void Load()
Expand All @@ -40,6 +41,8 @@ public override void Load()
translations = (Dictionary<string, ModTranslation>)translationsField.GetValue(null);
//LoadTranslations();

modCategories = new List<UIKit.UIComponents.ModCategory>();

// AddGlobalItem("HEROsModGlobalItem", new HEROsModGlobalItem());
// AddPlayer("HEROsModModPlayer", new HEROsModModPlayer());
//if (ModUtils.NetworkMode != NetworkMode.Server)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -300,6 +304,16 @@ args[3] as Action<bool>
);
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<Item> belongs = args[3] as Predicate<Item>;
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??
Expand Down
35 changes: 35 additions & 0 deletions UIKit/UIComponents/ItemBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,26 @@ public static void ParseList2()
new Category("Other", x=>false),
};

List<Category> categoryList = new List<Category>(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)
Expand Down Expand Up @@ -759,6 +779,21 @@ private void Button_onLeftClick(object sender, EventArgs e)
// internal UIImage button;
//}

// Represents a requested Category
internal class ModCategory
{
internal Predicate<Item> belongs;

internal string Name { get; private set; }
internal string Parent { get; private set; }
public ModCategory(string name, string parent, Predicate<Item> belongs)
{
Name = name;
Parent = parent;
this.belongs = belongs;
}
}

public class Category
{
//private Category _parentCategory = null;
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -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/
Expand Down

0 comments on commit 335f26a

Please sign in to comment.