From ebf97fb8aa13cd83cb36d1873c88bd4395b4b300 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Sun, 24 Oct 2021 19:41:01 +0800 Subject: [PATCH] feat: module toggle menu --- GodSeekerPlus/GodSeekerPlus.csproj | 3 ++- GodSeekerPlus/Menu.cs | 32 ++++++++++++++++++++++++++++++ GodSeekerPlus/Util/ModuleHelper.cs | 3 ++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 GodSeekerPlus/Menu.cs diff --git a/GodSeekerPlus/GodSeekerPlus.csproj b/GodSeekerPlus/GodSeekerPlus.csproj index 426ac55..06a2998 100644 --- a/GodSeekerPlus/GodSeekerPlus.csproj +++ b/GodSeekerPlus/GodSeekerPlus.csproj @@ -1,8 +1,9 @@ GodSeekerPlus - 0.6.0 + 0.7.0 A Hollow Knight mod to enhance your Godhome experience + Clazex Copyright © 2021 Clazex net472 diff --git a/GodSeekerPlus/Menu.cs b/GodSeekerPlus/Menu.cs new file mode 100644 index 0000000..15c15dc --- /dev/null +++ b/GodSeekerPlus/Menu.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Linq; +using GodSeekerPlus.Util; +using Modding; +using static Modding.IMenuMod; + +namespace GodSeekerPlus { + public sealed partial class GodSeekerPlus : IMenuMod { + bool IMenuMod.ToggleButtonInsideMenu => false; + + List IMenuMod.GetMenuData(MenuEntry? _) { + string[] states = { + Language.Language.Get("MOH_OFF", "MainMenu"), + Language.Language.Get("MOH_ON", "MainMenu") + }; + + return ModuleHelper + .GetToggleableModuleNames() + .Map(name => new( + name, + states, + "", + (val) => { + Instance.GlobalSettings.modules[name] = val != 0; + moduleManager.Modules[name].Update(); + }, + () => Instance.GlobalSettings.modules[name] ? 1 : 0 + )) + .ToList(); + } + } +} diff --git a/GodSeekerPlus/Util/ModuleHelper.cs b/GodSeekerPlus/Util/ModuleHelper.cs index 5567f17..3eaf2d5 100644 --- a/GodSeekerPlus/Util/ModuleHelper.cs +++ b/GodSeekerPlus/Util/ModuleHelper.cs @@ -13,7 +13,8 @@ internal static IEnumerable FindModules() => Assembly .Filter(HasModuleAttribute) .Filter(HasDefaultConstructor); - internal static IEnumerable GetModuleNames() => FindModules() + internal static IEnumerable GetToggleableModuleNames() => FindModules() + .Filter(type => type.GetCustomAttribute().toggleable) .Map(type => type.Name); internal static Dictionary GetDefaultModuleStateDict() => FindModules()