Skip to content

Commit 335f26a

Browse files
committed
v0.4.5, Port 6e5a6fa to 1.4
1 parent 3f5634e commit 335f26a

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

HEROsMod.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ internal class HEROsMod : Mod
2828
{
2929
public static HEROsMod instance;
3030
internal static Dictionary<string, ModTranslation> translations; // reference to private field.
31+
internal List<UIKit.UIComponents.ModCategory> modCategories;
3132
internal Dictionary<string, Action<bool>> crossModGroupUpdated = new Dictionary<string, Action<bool>>();
3233

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

44+
modCategories = new List<UIKit.UIComponents.ModCategory>();
45+
4346
// AddGlobalItem("HEROsModGlobalItem", new HEROsModGlobalItem());
4447
// AddPlayer("HEROsModModPlayer", new HEROsModModPlayer());
4548
//if (ModUtils.NetworkMode != NetworkMode.Server)
@@ -125,6 +128,7 @@ public override void Unload()
125128
ServiceController = null;
126129
TimeWeatherControlHotbar.Unload();
127130
ModUtils.previousInventoryItems = null;
131+
modCategories = null;
128132
translations = null;
129133
instance = null;
130134
NetTextModule.DeserializeAsServer -= NetTextModule_DeserializeAsServer;
@@ -300,6 +304,16 @@ args[3] as Action<bool>
300304
);
301305
ModUtils.DebugText("...Permission Added");
302306
}
307+
else if (message == "AddItemCategory")
308+
{
309+
ModUtils.DebugText("Item Category Adding...");
310+
string sortName = args[1] as string;
311+
string parentName = args[2] as string;
312+
Predicate<Item> belongs = args[3] as Predicate<Item>;
313+
if (!Main.dedServ)
314+
modCategories.Add(new UIKit.UIComponents.ModCategory(sortName, parentName, belongs));
315+
ModUtils.DebugText("...Item Category Added");
316+
}
303317
else if (message == "HasPermission")
304318
{
305319
if (/*Main.netMode != Terraria.ID.NetmodeID.Server ||*/ argsLength != 3) // for now, only allow this call on Server (2) --> why??

UIKit/UIComponents/ItemBrowser.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,26 @@ public static void ParseList2()
621621
new Category("Other", x=>false),
622622
};
623623

624+
List<Category> categoryList = new List<Category>(Categories);
625+
foreach (var modCallCategory in HEROsMod.instance.modCategories)
626+
{
627+
if (string.IsNullOrEmpty(modCallCategory.Parent))
628+
{
629+
categoryList.Insert(categoryList.Count - 2, new Category(modCallCategory.Name, modCallCategory.belongs, true));
630+
}
631+
else
632+
{
633+
foreach (var item in categoryList)
634+
{
635+
if (item.Name == modCallCategory.Parent)
636+
{
637+
item.SubCategories.Add(new Category(modCallCategory.Name, modCallCategory.belongs, true));
638+
}
639+
}
640+
}
641+
}
642+
Categories = categoryList.ToArray();
643+
624644
foreach (var parent in Categories)
625645
{
626646
foreach (var sub in parent.SubCategories)
@@ -759,6 +779,21 @@ private void Button_onLeftClick(object sender, EventArgs e)
759779
// internal UIImage button;
760780
//}
761781

782+
// Represents a requested Category
783+
internal class ModCategory
784+
{
785+
internal Predicate<Item> belongs;
786+
787+
internal string Name { get; private set; }
788+
internal string Parent { get; private set; }
789+
public ModCategory(string name, string parent, Predicate<Item> belongs)
790+
{
791+
Name = name;
792+
Parent = parent;
793+
this.belongs = belongs;
794+
}
795+
}
796+
762797
public class Category
763798
{
764799
//private Category _parentCategory = null;

build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
author = HERO, jopojelly, Matt Thompson, Panini
2-
version = 0.4.4
2+
version = 0.4.5
33
versionScheme = ?.?.Fix.Quickfix
44
displayName = HERO's Mod
55
homepage = http://forums.terraria.org/index.php?threads/heros-mod-creative-mode-server-management-and-over-25-tools-1-3-1-1-compatible.44650/

0 commit comments

Comments
 (0)