mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Added Enabled State API.
This commit is contained in:
parent
8b156c7d58
commit
6039be8685
7 changed files with 102 additions and 22 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit 860f4d6287d5cbb4b70fef1e74d52992e98ed837
|
Subproject commit f41af0fb88626f1579d3c4370b32b901f3c4d3c2
|
||||||
|
|
@ -81,6 +81,7 @@ public class IpcTester : IDisposable
|
||||||
{
|
{
|
||||||
_pluginState.Initialized.Enable();
|
_pluginState.Initialized.Enable();
|
||||||
_pluginState.Disposed.Enable();
|
_pluginState.Disposed.Enable();
|
||||||
|
_pluginState.EnabledChange.Enable();
|
||||||
_redrawing.Redrawn.Enable();
|
_redrawing.Redrawn.Enable();
|
||||||
_ui.PreSettingsDraw.Enable();
|
_ui.PreSettingsDraw.Enable();
|
||||||
_ui.PostSettingsDraw.Enable();
|
_ui.PostSettingsDraw.Enable();
|
||||||
|
|
@ -99,6 +100,7 @@ public class IpcTester : IDisposable
|
||||||
{
|
{
|
||||||
_pluginState.Initialized.Disable();
|
_pluginState.Initialized.Disable();
|
||||||
_pluginState.Disposed.Disable();
|
_pluginState.Disposed.Disable();
|
||||||
|
_pluginState.EnabledChange.Disable();
|
||||||
_redrawing.Redrawn.Disable();
|
_redrawing.Redrawn.Disable();
|
||||||
_ui.PreSettingsDraw.Disable();
|
_ui.PreSettingsDraw.Disable();
|
||||||
_ui.PostSettingsDraw.Disable();
|
_ui.PostSettingsDraw.Disable();
|
||||||
|
|
@ -117,6 +119,7 @@ public class IpcTester : IDisposable
|
||||||
{
|
{
|
||||||
_pluginState.Initialized.Dispose();
|
_pluginState.Initialized.Dispose();
|
||||||
_pluginState.Disposed.Dispose();
|
_pluginState.Disposed.Dispose();
|
||||||
|
_pluginState.EnabledChange.Dispose();
|
||||||
_redrawing.Redrawn.Dispose();
|
_redrawing.Redrawn.Dispose();
|
||||||
_ui.PreSettingsDraw.Dispose();
|
_ui.PreSettingsDraw.Dispose();
|
||||||
_ui.PostSettingsDraw.Dispose();
|
_ui.PostSettingsDraw.Dispose();
|
||||||
|
|
@ -142,18 +145,23 @@ public class IpcTester : IDisposable
|
||||||
|
|
||||||
private class PluginState
|
private class PluginState
|
||||||
{
|
{
|
||||||
private readonly DalamudPluginInterface _pi;
|
private readonly DalamudPluginInterface _pi;
|
||||||
public readonly EventSubscriber Initialized;
|
public readonly EventSubscriber Initialized;
|
||||||
public readonly EventSubscriber Disposed;
|
public readonly EventSubscriber Disposed;
|
||||||
|
public readonly EventSubscriber< bool > EnabledChange;
|
||||||
|
|
||||||
private readonly List< DateTimeOffset > _initializedList = new();
|
private readonly List< DateTimeOffset > _initializedList = new();
|
||||||
private readonly List< DateTimeOffset > _disposedList = new();
|
private readonly List< DateTimeOffset > _disposedList = new();
|
||||||
|
|
||||||
|
private DateTimeOffset _lastEnabledChange = DateTimeOffset.UnixEpoch;
|
||||||
|
private bool? _lastEnabledValue;
|
||||||
|
|
||||||
public PluginState( DalamudPluginInterface pi )
|
public PluginState( DalamudPluginInterface pi )
|
||||||
{
|
{
|
||||||
_pi = pi;
|
_pi = pi;
|
||||||
Initialized = Ipc.Initialized.Subscriber( pi, AddInitialized );
|
Initialized = Ipc.Initialized.Subscriber( pi, AddInitialized );
|
||||||
Disposed = Ipc.Disposed.Subscriber( pi, AddDisposed );
|
Disposed = Ipc.Disposed.Subscriber( pi, AddDisposed );
|
||||||
|
EnabledChange = Ipc.EnabledChange.Subscriber( pi, SetLastEnabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
|
|
@ -193,6 +201,10 @@ public class IpcTester : IDisposable
|
||||||
DrawIntro( Ipc.ApiVersions.Label, "Current Version" );
|
DrawIntro( Ipc.ApiVersions.Label, "Current Version" );
|
||||||
var (breaking, features) = Ipc.ApiVersions.Subscriber( _pi ).Invoke();
|
var (breaking, features) = Ipc.ApiVersions.Subscriber( _pi ).Invoke();
|
||||||
ImGui.TextUnformatted( $"{breaking}.{features:D4}" );
|
ImGui.TextUnformatted( $"{breaking}.{features:D4}" );
|
||||||
|
DrawIntro( Ipc.GetEnabledState.Label, "Current State" );
|
||||||
|
ImGui.TextUnformatted( $"{Ipc.GetEnabledState.Subscriber( _pi ).Invoke()}" );
|
||||||
|
DrawIntro( Ipc.EnabledChange.Label, "Last Change" );
|
||||||
|
ImGui.TextUnformatted( _lastEnabledValue is { } v ? $"{_lastEnabledChange} (to {v})" : "Never" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddInitialized()
|
private void AddInitialized()
|
||||||
|
|
@ -200,6 +212,9 @@ public class IpcTester : IDisposable
|
||||||
|
|
||||||
private void AddDisposed()
|
private void AddDisposed()
|
||||||
=> _disposedList.Add( DateTimeOffset.UtcNow );
|
=> _disposedList.Add( DateTimeOffset.UtcNow );
|
||||||
|
|
||||||
|
private void SetLastEnabled( bool val )
|
||||||
|
=> ( _lastEnabledChange, _lastEnabledValue ) = ( DateTimeOffset.Now, val );
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Configuration
|
private class Configuration
|
||||||
|
|
|
||||||
|
|
@ -33,22 +33,46 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
||||||
|
|
||||||
public event GameObjectRedrawnDelegate? GameObjectRedrawn
|
public event GameObjectRedrawnDelegate? GameObjectRedrawn
|
||||||
{
|
{
|
||||||
add => _penumbra!.ObjectReloader.GameObjectRedrawn += value;
|
add
|
||||||
remove => _penumbra!.ObjectReloader.GameObjectRedrawn -= value;
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
_penumbra!.ObjectReloader.GameObjectRedrawn += value;
|
||||||
|
}
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
_penumbra!.ObjectReloader.GameObjectRedrawn -= value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public event ModSettingChangedDelegate? ModSettingChanged;
|
public event ModSettingChangedDelegate? ModSettingChanged;
|
||||||
|
|
||||||
public event CreatingCharacterBaseDelegate? CreatingCharacterBase
|
public event CreatingCharacterBaseDelegate? CreatingCharacterBase
|
||||||
{
|
{
|
||||||
add => PathResolver.DrawObjectState.CreatingCharacterBase += value;
|
add
|
||||||
remove => PathResolver.DrawObjectState.CreatingCharacterBase -= value;
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
PathResolver.DrawObjectState.CreatingCharacterBase += value;
|
||||||
|
}
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
PathResolver.DrawObjectState.CreatingCharacterBase -= value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public event CreatedCharacterBaseDelegate? CreatedCharacterBase
|
public event CreatedCharacterBaseDelegate? CreatedCharacterBase
|
||||||
{
|
{
|
||||||
add => PathResolver.DrawObjectState.CreatedCharacterBase += value;
|
add
|
||||||
remove => PathResolver.DrawObjectState.CreatedCharacterBase -= value;
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
PathResolver.DrawObjectState.CreatedCharacterBase += value;
|
||||||
|
}
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
PathResolver.DrawObjectState.CreatedCharacterBase -= value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Valid
|
public bool Valid
|
||||||
|
|
@ -104,8 +128,33 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
||||||
|
|
||||||
public event Action< string, bool >? ModDirectoryChanged
|
public event Action< string, bool >? ModDirectoryChanged
|
||||||
{
|
{
|
||||||
add => Penumbra.ModManager.ModDirectoryChanged += value;
|
add
|
||||||
remove => Penumbra.ModManager.ModDirectoryChanged -= value;
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
Penumbra.ModManager.ModDirectoryChanged += value;
|
||||||
|
}
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
Penumbra.ModManager.ModDirectoryChanged -= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetEnabledState()
|
||||||
|
=> Penumbra.Config.EnableMods;
|
||||||
|
|
||||||
|
public event Action< bool >? EnabledChange
|
||||||
|
{
|
||||||
|
add
|
||||||
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
_penumbra!.EnabledChange += value;
|
||||||
|
}
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
_penumbra!.EnabledChange -= value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetConfiguration()
|
public string GetConfiguration()
|
||||||
|
|
@ -334,7 +383,9 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
||||||
{
|
{
|
||||||
CheckInitialized();
|
CheckInitialized();
|
||||||
if( !Penumbra.ModManager.TryGetMod( modDirectory, modName, out var mod ) )
|
if( !Penumbra.ModManager.TryGetMod( modDirectory, modName, out var mod ) )
|
||||||
|
{
|
||||||
return PenumbraApiEc.NothingChanged;
|
return PenumbraApiEc.NothingChanged;
|
||||||
|
}
|
||||||
|
|
||||||
Penumbra.ModManager.DeleteMod( mod.Index );
|
Penumbra.ModManager.DeleteMod( mod.Index );
|
||||||
return PenumbraApiEc.Success;
|
return PenumbraApiEc.Success;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using Dalamud.Game.ClientState.Objects.Types;
|
using Dalamud.Game.ClientState.Objects.Types;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Penumbra.Collections;
|
|
||||||
using Penumbra.GameData.Enums;
|
using Penumbra.GameData.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -21,6 +20,8 @@ public class PenumbraIpcProviders : IDisposable
|
||||||
internal readonly EventProvider Disposed;
|
internal readonly EventProvider Disposed;
|
||||||
internal readonly FuncProvider< int > ApiVersion;
|
internal readonly FuncProvider< int > ApiVersion;
|
||||||
internal readonly FuncProvider< (int Breaking, int Features) > ApiVersions;
|
internal readonly FuncProvider< (int Breaking, int Features) > ApiVersions;
|
||||||
|
internal readonly FuncProvider< bool > GetEnabledState;
|
||||||
|
internal readonly EventProvider< bool > EnabledChange;
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
internal readonly FuncProvider< string > GetModDirectory;
|
internal readonly FuncProvider< string > GetModDirectory;
|
||||||
|
|
@ -98,10 +99,12 @@ public class PenumbraIpcProviders : IDisposable
|
||||||
Api = api;
|
Api = api;
|
||||||
|
|
||||||
// Plugin State
|
// Plugin State
|
||||||
Initialized = Ipc.Initialized.Provider( pi );
|
Initialized = Ipc.Initialized.Provider( pi );
|
||||||
Disposed = Ipc.Disposed.Provider( pi );
|
Disposed = Ipc.Disposed.Provider( pi );
|
||||||
ApiVersion = Ipc.ApiVersion.Provider( pi, DeprecatedVersion );
|
ApiVersion = Ipc.ApiVersion.Provider( pi, DeprecatedVersion );
|
||||||
ApiVersions = Ipc.ApiVersions.Provider( pi, () => Api.ApiVersion );
|
ApiVersions = Ipc.ApiVersions.Provider( pi, () => Api.ApiVersion );
|
||||||
|
GetEnabledState = Ipc.GetEnabledState.Provider( pi, Api.GetEnabledState );
|
||||||
|
EnabledChange = Ipc.EnabledChange.Provider( pi, () => Api.EnabledChange += EnabledChangeEvent, () => Api.EnabledChange -= EnabledChangeEvent );
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
GetModDirectory = Ipc.GetModDirectory.Provider( pi, Api.GetModDirectory );
|
GetModDirectory = Ipc.GetModDirectory.Provider( pi, Api.GetModDirectory );
|
||||||
|
|
@ -195,6 +198,8 @@ public class PenumbraIpcProviders : IDisposable
|
||||||
Initialized.Dispose();
|
Initialized.Dispose();
|
||||||
ApiVersion.Dispose();
|
ApiVersion.Dispose();
|
||||||
ApiVersions.Dispose();
|
ApiVersions.Dispose();
|
||||||
|
GetEnabledState.Dispose();
|
||||||
|
EnabledChange.Dispose();
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
GetModDirectory.Dispose();
|
GetModDirectory.Dispose();
|
||||||
|
|
@ -290,6 +295,9 @@ public class PenumbraIpcProviders : IDisposable
|
||||||
ChangedItemTooltip.Invoke( type, id );
|
ChangedItemTooltip.Invoke( type, id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EnabledChangeEvent( bool value )
|
||||||
|
=> EnabledChange.Invoke( value );
|
||||||
|
|
||||||
private void OnGameObjectRedrawn( IntPtr objectAddress, int objectTableIndex )
|
private void OnGameObjectRedrawn( IntPtr objectAddress, int objectTableIndex )
|
||||||
=> GameObjectRedrawn.Invoke( objectAddress, objectTableIndex );
|
=> GameObjectRedrawn.Invoke( objectAddress, objectTableIndex );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ using Penumbra.Collections;
|
||||||
using Penumbra.Interop.Loader;
|
using Penumbra.Interop.Loader;
|
||||||
using Penumbra.Interop.Resolver;
|
using Penumbra.Interop.Resolver;
|
||||||
using Penumbra.Mods;
|
using Penumbra.Mods;
|
||||||
|
using Action = System.Action;
|
||||||
using CharacterUtility = Penumbra.Interop.CharacterUtility;
|
using CharacterUtility = Penumbra.Interop.CharacterUtility;
|
||||||
using ResidentResourceManager = Penumbra.Interop.ResidentResourceManager;
|
using ResidentResourceManager = Penumbra.Interop.ResidentResourceManager;
|
||||||
|
|
||||||
|
|
@ -185,6 +186,8 @@ public class Penumbra : IDalamudPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public event Action< bool >? EnabledChange;
|
||||||
|
|
||||||
public bool Enable()
|
public bool Enable()
|
||||||
{
|
{
|
||||||
if( Config.EnableMods )
|
if( Config.EnableMods )
|
||||||
|
|
@ -202,6 +205,7 @@ public class Penumbra : IDalamudPlugin
|
||||||
ResidentResources.Reload();
|
ResidentResources.Reload();
|
||||||
ObjectReloader.RedrawAll( RedrawType.Redraw );
|
ObjectReloader.RedrawAll( RedrawType.Redraw );
|
||||||
}
|
}
|
||||||
|
EnabledChange?.Invoke( true );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -223,6 +227,7 @@ public class Penumbra : IDalamudPlugin
|
||||||
ResidentResources.Reload();
|
ResidentResources.Reload();
|
||||||
ObjectReloader.RedrawAll( RedrawType.Redraw );
|
ObjectReloader.RedrawAll( RedrawType.Redraw );
|
||||||
}
|
}
|
||||||
|
EnabledChange?.Invoke( false );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,9 @@ public partial class ConfigWindow
|
||||||
.RegisterEntry( "Meta Manipulation editing now highlights if the selected ID is 0 or 1." )
|
.RegisterEntry( "Meta Manipulation editing now highlights if the selected ID is 0 or 1." )
|
||||||
.RegisterEntry( "Fixed a bug when manually adding EQP or EQDP entries to Mods." )
|
.RegisterEntry( "Fixed a bug when manually adding EQP or EQDP entries to Mods." )
|
||||||
.RegisterEntry( "Updated some tooltips and hints." )
|
.RegisterEntry( "Updated some tooltips and hints." )
|
||||||
.RegisterEntry( "Backend changes regarding API/IPC, consumers can but do not need to use the Penumbra.Api library as a submodule." );
|
.RegisterEntry( "Backend changes regarding API/IPC, consumers can but do not need to use the Penumbra.Api library as a submodule." )
|
||||||
|
.RegisterEntry( "Added API to delete mods and read and set their pseudo-filesystem paths.", 1 )
|
||||||
|
.RegisterEntry( "Added API to check Penumbras enabled state and updates to it.", 1 );
|
||||||
|
|
||||||
private static void Add5_10_0( Changelog log )
|
private static void Add5_10_0( Changelog log )
|
||||||
=> log.NextVersion( "Version 0.5.10.0" )
|
=> log.NextVersion( "Version 0.5.10.0" )
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ using ImGuiNET;
|
||||||
using OtterGui;
|
using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using OtterGui.Widgets;
|
using OtterGui.Widgets;
|
||||||
using Penumbra.GameData.Enums;
|
|
||||||
using Penumbra.UI.Classes;
|
using Penumbra.UI.Classes;
|
||||||
|
|
||||||
namespace Penumbra.UI;
|
namespace Penumbra.UI;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue