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.Disposed.Enable();
|
||||
_pluginState.EnabledChange.Enable();
|
||||
_redrawing.Redrawn.Enable();
|
||||
_ui.PreSettingsDraw.Enable();
|
||||
_ui.PostSettingsDraw.Enable();
|
||||
|
|
@ -99,6 +100,7 @@ public class IpcTester : IDisposable
|
|||
{
|
||||
_pluginState.Initialized.Disable();
|
||||
_pluginState.Disposed.Disable();
|
||||
_pluginState.EnabledChange.Disable();
|
||||
_redrawing.Redrawn.Disable();
|
||||
_ui.PreSettingsDraw.Disable();
|
||||
_ui.PostSettingsDraw.Disable();
|
||||
|
|
@ -117,6 +119,7 @@ public class IpcTester : IDisposable
|
|||
{
|
||||
_pluginState.Initialized.Dispose();
|
||||
_pluginState.Disposed.Dispose();
|
||||
_pluginState.EnabledChange.Dispose();
|
||||
_redrawing.Redrawn.Dispose();
|
||||
_ui.PreSettingsDraw.Dispose();
|
||||
_ui.PostSettingsDraw.Dispose();
|
||||
|
|
@ -145,15 +148,20 @@ public class IpcTester : IDisposable
|
|||
private readonly DalamudPluginInterface _pi;
|
||||
public readonly EventSubscriber Initialized;
|
||||
public readonly EventSubscriber Disposed;
|
||||
public readonly EventSubscriber< bool > EnabledChange;
|
||||
|
||||
private readonly List< DateTimeOffset > _initializedList = new();
|
||||
private readonly List< DateTimeOffset > _disposedList = new();
|
||||
|
||||
private DateTimeOffset _lastEnabledChange = DateTimeOffset.UnixEpoch;
|
||||
private bool? _lastEnabledValue;
|
||||
|
||||
public PluginState( DalamudPluginInterface pi )
|
||||
{
|
||||
_pi = pi;
|
||||
Initialized = Ipc.Initialized.Subscriber( pi, AddInitialized );
|
||||
Disposed = Ipc.Disposed.Subscriber( pi, AddDisposed );
|
||||
EnabledChange = Ipc.EnabledChange.Subscriber( pi, SetLastEnabled );
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
|
|
@ -193,6 +201,10 @@ public class IpcTester : IDisposable
|
|||
DrawIntro( Ipc.ApiVersions.Label, "Current Version" );
|
||||
var (breaking, features) = Ipc.ApiVersions.Subscriber( _pi ).Invoke();
|
||||
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()
|
||||
|
|
@ -200,6 +212,9 @@ public class IpcTester : IDisposable
|
|||
|
||||
private void AddDisposed()
|
||||
=> _disposedList.Add( DateTimeOffset.UtcNow );
|
||||
|
||||
private void SetLastEnabled( bool val )
|
||||
=> ( _lastEnabledChange, _lastEnabledValue ) = ( DateTimeOffset.Now, val );
|
||||
}
|
||||
|
||||
private class Configuration
|
||||
|
|
|
|||
|
|
@ -33,22 +33,46 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
|
||||
public event GameObjectRedrawnDelegate? GameObjectRedrawn
|
||||
{
|
||||
add => _penumbra!.ObjectReloader.GameObjectRedrawn += value;
|
||||
remove => _penumbra!.ObjectReloader.GameObjectRedrawn -= value;
|
||||
add
|
||||
{
|
||||
CheckInitialized();
|
||||
_penumbra!.ObjectReloader.GameObjectRedrawn += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
CheckInitialized();
|
||||
_penumbra!.ObjectReloader.GameObjectRedrawn -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public event ModSettingChangedDelegate? ModSettingChanged;
|
||||
|
||||
public event CreatingCharacterBaseDelegate? CreatingCharacterBase
|
||||
{
|
||||
add => PathResolver.DrawObjectState.CreatingCharacterBase += value;
|
||||
remove => PathResolver.DrawObjectState.CreatingCharacterBase -= value;
|
||||
add
|
||||
{
|
||||
CheckInitialized();
|
||||
PathResolver.DrawObjectState.CreatingCharacterBase += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
CheckInitialized();
|
||||
PathResolver.DrawObjectState.CreatingCharacterBase -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public event CreatedCharacterBaseDelegate? CreatedCharacterBase
|
||||
{
|
||||
add => PathResolver.DrawObjectState.CreatedCharacterBase += value;
|
||||
remove => PathResolver.DrawObjectState.CreatedCharacterBase -= value;
|
||||
add
|
||||
{
|
||||
CheckInitialized();
|
||||
PathResolver.DrawObjectState.CreatedCharacterBase += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
CheckInitialized();
|
||||
PathResolver.DrawObjectState.CreatedCharacterBase -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Valid
|
||||
|
|
@ -104,8 +128,33 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
|
||||
public event Action< string, bool >? ModDirectoryChanged
|
||||
{
|
||||
add => Penumbra.ModManager.ModDirectoryChanged += value;
|
||||
remove => Penumbra.ModManager.ModDirectoryChanged -= value;
|
||||
add
|
||||
{
|
||||
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()
|
||||
|
|
@ -334,7 +383,9 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
{
|
||||
CheckInitialized();
|
||||
if( !Penumbra.ModManager.TryGetMod( modDirectory, modName, out var mod ) )
|
||||
{
|
||||
return PenumbraApiEc.NothingChanged;
|
||||
}
|
||||
|
||||
Penumbra.ModManager.DeleteMod( mod.Index );
|
||||
return PenumbraApiEc.Success;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Plugin;
|
||||
using Penumbra.Collections;
|
||||
using Penumbra.GameData.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -21,6 +20,8 @@ public class PenumbraIpcProviders : IDisposable
|
|||
internal readonly EventProvider Disposed;
|
||||
internal readonly FuncProvider< int > ApiVersion;
|
||||
internal readonly FuncProvider< (int Breaking, int Features) > ApiVersions;
|
||||
internal readonly FuncProvider< bool > GetEnabledState;
|
||||
internal readonly EventProvider< bool > EnabledChange;
|
||||
|
||||
// Configuration
|
||||
internal readonly FuncProvider< string > GetModDirectory;
|
||||
|
|
@ -102,6 +103,8 @@ public class PenumbraIpcProviders : IDisposable
|
|||
Disposed = Ipc.Disposed.Provider( pi );
|
||||
ApiVersion = Ipc.ApiVersion.Provider( pi, DeprecatedVersion );
|
||||
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
|
||||
GetModDirectory = Ipc.GetModDirectory.Provider( pi, Api.GetModDirectory );
|
||||
|
|
@ -195,6 +198,8 @@ public class PenumbraIpcProviders : IDisposable
|
|||
Initialized.Dispose();
|
||||
ApiVersion.Dispose();
|
||||
ApiVersions.Dispose();
|
||||
GetEnabledState.Dispose();
|
||||
EnabledChange.Dispose();
|
||||
|
||||
// Configuration
|
||||
GetModDirectory.Dispose();
|
||||
|
|
@ -290,6 +295,9 @@ public class PenumbraIpcProviders : IDisposable
|
|||
ChangedItemTooltip.Invoke( type, id );
|
||||
}
|
||||
|
||||
private void EnabledChangeEvent( bool value )
|
||||
=> EnabledChange.Invoke( value );
|
||||
|
||||
private void OnGameObjectRedrawn( IntPtr objectAddress, int objectTableIndex )
|
||||
=> GameObjectRedrawn.Invoke( objectAddress, objectTableIndex );
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ using Penumbra.Collections;
|
|||
using Penumbra.Interop.Loader;
|
||||
using Penumbra.Interop.Resolver;
|
||||
using Penumbra.Mods;
|
||||
using Action = System.Action;
|
||||
using CharacterUtility = Penumbra.Interop.CharacterUtility;
|
||||
using ResidentResourceManager = Penumbra.Interop.ResidentResourceManager;
|
||||
|
||||
|
|
@ -185,6 +186,8 @@ public class Penumbra : IDalamudPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public event Action< bool >? EnabledChange;
|
||||
|
||||
public bool Enable()
|
||||
{
|
||||
if( Config.EnableMods )
|
||||
|
|
@ -202,6 +205,7 @@ public class Penumbra : IDalamudPlugin
|
|||
ResidentResources.Reload();
|
||||
ObjectReloader.RedrawAll( RedrawType.Redraw );
|
||||
}
|
||||
EnabledChange?.Invoke( true );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -223,6 +227,7 @@ public class Penumbra : IDalamudPlugin
|
|||
ResidentResources.Reload();
|
||||
ObjectReloader.RedrawAll( RedrawType.Redraw );
|
||||
}
|
||||
EnabledChange?.Invoke( false );
|
||||
|
||||
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( "Fixed a bug when manually adding EQP or EQDP entries to Mods." )
|
||||
.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 )
|
||||
=> log.NextVersion( "Version 0.5.10.0" )
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using ImGuiNET;
|
|||
using OtterGui;
|
||||
using OtterGui.Raii;
|
||||
using OtterGui.Widgets;
|
||||
using Penumbra.GameData.Enums;
|
||||
using Penumbra.UI.Classes;
|
||||
|
||||
namespace Penumbra.UI;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue