Create enable/disable functions and clean up PR.

This commit is contained in:
Ottermandias 2021-10-19 11:30:08 +02:00
parent 5084bf603c
commit 982385ccbb
3 changed files with 61 additions and 40 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="UserContentModel"> <component name="ContentModelUserStore">
<attachedFolders /> <attachedFolders />
<explicitIncludes /> <explicitIncludes />
<explicitExcludes /> <explicitExcludes />

View file

@ -90,6 +90,47 @@ namespace Penumbra
Ipc = new PenumbraIpc( pluginInterface, Api ); 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() private void SubscribeItemLinks()
{ {
Api.ChangedItemTooltip += it => Api.ChangedItemTooltip += it =>
@ -149,6 +190,9 @@ namespace Penumbra
private void OnCommand( string command, string rawArgs ) 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 ); var args = rawArgs.Split( new[] { ' ' }, 2 );
if( args.Length > 0 && args[ 0 ].Length > 0 ) if( args.Length > 0 && args[ 0 ].Length > 0 )
{ {
@ -182,40 +226,24 @@ namespace Penumbra
} }
case "enable": case "enable":
{ {
if( Config.IsEnabled ) Dalamud.Chat.Print( Enable()
{ ? "Your mods are already enabled. To disable your mods, please run the following command instead: /penumbra disable"
Dalamud.Chat.Print("Your mods are already enabled. To disable your mods, please run the following command instead: /penumbra disable"); : modsEnabled );
}
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.");
}
break; break;
} }
case "disable": case "disable":
{ {
if( !Config.IsEnabled ) Dalamud.Chat.Print( Disable()
{ ? "Your mods are already disabled. To enable your mods, please run the following command instead: /penumbra enable"
Dalamud.Chat.Print("Your mods are already disabled. To enable your mods, please run the following command instead: /penumbra enable"); : modsDisabled );
break;
} }
else case "toggle":
{ {
Config.IsEnabled = false; SetEnabled( !Config.IsEnabled );
ObjectReloader.RedrawAll( RedrawType.WithoutSettings ); Dalamud.Chat.Print( Config.IsEnabled
if( Config.EnablePlayerWatch ) ? modsEnabled
{ : modsDisabled );
Penumbra.PlayerWatcher.SetStatus( false );
}
Config.Save();
Dalamud.Chat.Print("Your mods have now been disabled.");
}
break; break;
} }
} }

View file

@ -146,14 +146,7 @@ namespace Penumbra.UI
var enabled = _config.IsEnabled; var enabled = _config.IsEnabled;
if( ImGui.Checkbox( LabelEnabled, ref enabled ) ) if( ImGui.Checkbox( LabelEnabled, ref enabled ) )
{ {
_config.IsEnabled = enabled; _base._penumbra.SetEnabled( enabled );
_configChanged = true;
Service< ResidentResources >.Get().ReloadPlayerResources();
_base._penumbra.ObjectReloader.RedrawAll( enabled ? RedrawType.WithSettings : RedrawType.WithoutSettings );
if( _config.EnablePlayerWatch )
{
Penumbra.PlayerWatcher.SetStatus( enabled );
}
} }
} }