From 982385ccbb64d7bcb925c1109bb4fd8cdc3190dd Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 19 Oct 2021 11:30:08 +0200 Subject: [PATCH] Create enable/disable functions and clean up PR. --- .idea/.idea.Penumbra/.idea/indexLayout.xml | 2 +- Penumbra/Penumbra.cs | 90 ++++++++++++++-------- Penumbra/UI/MenuTabs/TabSettings.cs | 9 +-- 3 files changed, 61 insertions(+), 40 deletions(-) diff --git a/.idea/.idea.Penumbra/.idea/indexLayout.xml b/.idea/.idea.Penumbra/.idea/indexLayout.xml index 7b08163c..27ba142e 100644 --- a/.idea/.idea.Penumbra/.idea/indexLayout.xml +++ b/.idea/.idea.Penumbra/.idea/indexLayout.xml @@ -1,6 +1,6 @@ - + diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 6cf1e395..093eaf06 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -90,6 +90,47 @@ namespace Penumbra Ipc = new PenumbraIpc( pluginInterface, Api ); } + public bool Enable() + { + if( Config.IsEnabled ) + { + return false; + } + + Config.IsEnabled = true; + Service< ResidentResources >.Get().ReloadPlayerResources(); + if( Config.EnablePlayerWatch ) + { + PlayerWatcher.SetStatus( true ); + } + + Config.Save(); + ObjectReloader.RedrawAll( RedrawType.WithSettings ); + return true; + } + + public bool Disable() + { + if( !Config.IsEnabled ) + { + return false; + } + + Config.IsEnabled = false; + Service< ResidentResources >.Get().ReloadPlayerResources(); + if( Config.EnablePlayerWatch ) + { + PlayerWatcher.SetStatus( false ); + } + + Config.Save(); + ObjectReloader.RedrawAll( RedrawType.WithoutSettings ); + return true; + } + + public bool SetEnabled( bool enabled ) + => enabled ? Enable() : Disable(); + private void SubscribeItemLinks() { Api.ChangedItemTooltip += it => @@ -149,6 +190,9 @@ namespace Penumbra private void OnCommand( string command, string rawArgs ) { + const string modsEnabled = "Your mods have now been enabled."; + const string modsDisabled = "Your mods have now been disabled."; + var args = rawArgs.Split( new[] { ' ' }, 2 ); if( args.Length > 0 && args[ 0 ].Length > 0 ) { @@ -182,40 +226,24 @@ namespace Penumbra } case "enable": { - if( Config.IsEnabled ) - { - Dalamud.Chat.Print("Your mods are already enabled. To disable your mods, please run the following command instead: /penumbra disable"); - } - else - { - Config.IsEnabled = true; - ObjectReloader.RedrawAll( RedrawType.WithSettings ); - if( Config.EnablePlayerWatch ) - { - Penumbra.PlayerWatcher.SetStatus( true ); - } - Config.Save(); - Dalamud.Chat.Print("Your mods have now been enabled."); - } + Dalamud.Chat.Print( Enable() + ? "Your mods are already enabled. To disable your mods, please run the following command instead: /penumbra disable" + : modsEnabled ); break; } case "disable": { - if( !Config.IsEnabled ) - { - Dalamud.Chat.Print("Your mods are already disabled. To enable your mods, please run the following command instead: /penumbra enable"); - } - else - { - Config.IsEnabled = false; - ObjectReloader.RedrawAll( RedrawType.WithoutSettings ); - if( Config.EnablePlayerWatch ) - { - Penumbra.PlayerWatcher.SetStatus( false ); - } - Config.Save(); - Dalamud.Chat.Print("Your mods have now been disabled."); - } + Dalamud.Chat.Print( Disable() + ? "Your mods are already disabled. To enable your mods, please run the following command instead: /penumbra enable" + : modsDisabled ); + break; + } + case "toggle": + { + SetEnabled( !Config.IsEnabled ); + Dalamud.Chat.Print( Config.IsEnabled + ? modsEnabled + : modsDisabled ); break; } } @@ -226,4 +254,4 @@ namespace Penumbra SettingsInterface.FlipVisibility(); } } -} +} \ No newline at end of file diff --git a/Penumbra/UI/MenuTabs/TabSettings.cs b/Penumbra/UI/MenuTabs/TabSettings.cs index 336d4443..f5a34cd1 100644 --- a/Penumbra/UI/MenuTabs/TabSettings.cs +++ b/Penumbra/UI/MenuTabs/TabSettings.cs @@ -146,14 +146,7 @@ namespace Penumbra.UI var enabled = _config.IsEnabled; if( ImGui.Checkbox( LabelEnabled, ref enabled ) ) { - _config.IsEnabled = enabled; - _configChanged = true; - Service< ResidentResources >.Get().ReloadPlayerResources(); - _base._penumbra.ObjectReloader.RedrawAll( enabled ? RedrawType.WithSettings : RedrawType.WithoutSettings ); - if( _config.EnablePlayerWatch ) - { - Penumbra.PlayerWatcher.SetStatus( enabled ); - } + _base._penumbra.SetEnabled( enabled ); } }