From 99f1c38b4cdc3603967fb2e6a1c7b318d713e3b2 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Mon, 28 Dec 2020 08:33:12 +0100 Subject: [PATCH] Plugins/GUI: Implement conditional option enabling --- .../Plugins/API/V100/IPluginOption.cs | 12 +++++ Il2CppInspector.GUI/App.xaml.cs | 4 +- .../PluginConfigurationDialog.xaml | 52 ++++++++++++------- .../PluginConfigurationDialog.xaml.cs | 34 +++++++++++- 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs b/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs index 8e3d6b2..7850ec3 100644 --- a/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs +++ b/Il2CppInspector.Common/Plugins/API/V100/IPluginOption.cs @@ -37,6 +37,12 @@ namespace Il2CppInspector.PluginAPI.V100 /// Becomes the current value of the option when supplied by the user /// public object Value { get; set; } + + /// + /// A condition that determines whether the option is enabled, + /// based on the settings of other options or any other desired criteria + /// + public Func If { get; set; } } /// @@ -100,6 +106,12 @@ namespace Il2CppInspector.PluginAPI.V100 } } + /// + /// This can be set to a predicate that determines whether the option is enabled in the GUI + /// By default, enable all options unless overridden + /// + public Func If { get; set; } = () => true; + /// /// Optional validation function for the option in addition to basic automatic validation /// Must either throw an exception or return true diff --git a/Il2CppInspector.GUI/App.xaml.cs b/Il2CppInspector.GUI/App.xaml.cs index edfcc15..a599369 100644 --- a/Il2CppInspector.GUI/App.xaml.cs +++ b/Il2CppInspector.GUI/App.xaml.cs @@ -48,7 +48,7 @@ namespace Il2CppInspectorGUI } public override void Write(Utf8JsonWriter writer, IPluginOption value, JsonSerializerOptions options) { - JsonSerializer.Serialize(writer, value, value.GetType(), options); + JsonSerializer.Serialize(writer, new PluginOptionState { Name = value.Name, Value = value.Value }, typeof(PluginOptionState), options); } } @@ -75,6 +75,8 @@ namespace Il2CppInspectorGUI [JsonIgnore] public bool Required { get; set; } public object Value { get; set; } + [JsonIgnore] + public Func If { get; set; } } // Application startup diff --git a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml index 37e96ce..472e140 100644 --- a/Il2CppInspector.GUI/PluginConfigurationDialog.xaml +++ b/Il2CppInspector.GUI/PluginConfigurationDialog.xaml @@ -13,10 +13,16 @@ Closing="Window_Closing"> + + + + +