Move UI Building to thread.

This commit is contained in:
Ottermandias 2023-03-10 15:17:45 +01:00
parent 23c1ee9dc6
commit d8e2a5ba28
3 changed files with 68 additions and 21 deletions

@ -1 +1 @@
Subproject commit a2b680a5991d9287c2dcda7cfa54183c37384fd0 Subproject commit f66e49bde2878542de17edf428de61f6c8a42efc

View file

@ -174,14 +174,22 @@ public class PenumbraApi : IDisposable, IPenumbraApi
public PenumbraApiEc OpenMainWindow( TabType tab, string modDirectory, string modName ) public PenumbraApiEc OpenMainWindow( TabType tab, string modDirectory, string modName )
{ {
CheckInitialized(); CheckInitialized();
if( _penumbra!.ConfigWindow == null )
{
return PenumbraApiEc.SystemDisposed;
}
_penumbra!.ConfigWindow.IsOpen = true; _penumbra!.ConfigWindow.IsOpen = true;
if( !Enum.IsDefined( tab ) ) if( !Enum.IsDefined( tab ) )
{
return PenumbraApiEc.InvalidArgument; return PenumbraApiEc.InvalidArgument;
}
if( tab != TabType.None ) if( tab != TabType.None )
{
_penumbra!.ConfigWindow.SelectTab = tab; _penumbra!.ConfigWindow.SelectTab = tab;
}
if( tab == TabType.Mods && ( modDirectory.Length > 0 || modName.Length > 0 ) ) if( tab == TabType.Mods && ( modDirectory.Length > 0 || modName.Length > 0 ) )
{ {
@ -194,12 +202,18 @@ public class PenumbraApi : IDisposable, IPenumbraApi
return PenumbraApiEc.ModMissing; return PenumbraApiEc.ModMissing;
} }
} }
return PenumbraApiEc.Success; return PenumbraApiEc.Success;
} }
public void CloseMainWindow() public void CloseMainWindow()
{ {
CheckInitialized(); CheckInitialized();
if( _penumbra!.ConfigWindow == null )
{
return;
}
_penumbra!.ConfigWindow.IsOpen = false; _penumbra!.ConfigWindow.IsOpen = false;
} }

View file

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
@ -56,7 +57,6 @@ public class Penumbra : IDalamudPlugin
public static IObjectIdentifier Identifier { get; private set; } = null!; public static IObjectIdentifier Identifier { get; private set; } = null!;
public static IGamePathParser GamePathParser { get; private set; } = null!; public static IGamePathParser GamePathParser { get; private set; } = null!;
public static StainManager StainManager { get; private set; } = null!; public static StainManager StainManager { get; private set; } = null!;
public static ItemData ItemData { get; private set; } = null!;
public static ValidityChecker ValidityChecker { get; private set; } = null!; public static ValidityChecker ValidityChecker { get; private set; } = null!;
@ -71,12 +71,15 @@ public class Penumbra : IDalamudPlugin
public readonly PenumbraApi Api; public readonly PenumbraApi Api;
public readonly HttpApi HttpApi; public readonly HttpApi HttpApi;
public readonly PenumbraIpcProviders IpcProviders; public readonly PenumbraIpcProviders IpcProviders;
internal readonly ConfigWindow ConfigWindow; internal ConfigWindow? ConfigWindow { get; private set; }
private readonly LaunchButton _launchButton; private LaunchButton? _launchButton;
private readonly WindowSystem _windowSystem; private WindowSystem? _windowSystem;
private readonly Changelog _changelog; private Changelog? _changelog;
private readonly CommandHandler _commandHandler; private CommandHandler? _commandHandler;
private readonly ResourceWatcher _resourceWatcher; private readonly ResourceWatcher _resourceWatcher;
private bool _disposed;
public static ItemData ItemData { get; private set; } = null!;
public Penumbra( DalamudPluginInterface pluginInterface ) public Penumbra( DalamudPluginInterface pluginInterface )
{ {
@ -94,7 +97,7 @@ public class Penumbra : IDalamudPlugin
StartTimer.Measure( StartTimeType.Identifier, () => Identifier = GameData.GameData.GetIdentifier( Dalamud.PluginInterface, Dalamud.GameData ) ); StartTimer.Measure( StartTimeType.Identifier, () => Identifier = GameData.GameData.GetIdentifier( Dalamud.PluginInterface, Dalamud.GameData ) );
StartTimer.Measure( StartTimeType.GamePathParser, () => GamePathParser = GameData.GameData.GetGamePathParser() ); StartTimer.Measure( StartTimeType.GamePathParser, () => GamePathParser = GameData.GameData.GetGamePathParser() );
StartTimer.Measure( StartTimeType.Stains, () => StainManager = new StainManager( Dalamud.PluginInterface, Dalamud.GameData ) ); StartTimer.Measure( StartTimeType.Stains, () => StainManager = new StainManager( Dalamud.PluginInterface, Dalamud.GameData ) );
StartTimer.Measure( StartTimeType.Items, () => ItemData = new ItemData( Dalamud.PluginInterface, Dalamud.GameData, Dalamud.GameData.Language ) ); ItemData = StartTimer.Measure( StartTimeType.Items, () => new ItemData( Dalamud.PluginInterface, Dalamud.GameData, Dalamud.GameData.Language ) );
StartTimer.Measure( StartTimeType.Actors, StartTimer.Measure( StartTimeType.Actors,
() => Actors = new ActorManager( Dalamud.PluginInterface, Dalamud.Objects, Dalamud.ClientState, Dalamud.Framework, Dalamud.GameData, Dalamud.GameGui, () => Actors = new ActorManager( Dalamud.PluginInterface, Dalamud.Objects, Dalamud.ClientState, Dalamud.Framework, Dalamud.GameData, Dalamud.GameGui,
ResolveCutscene ) ); ResolveCutscene ) );
@ -128,8 +131,7 @@ public class Penumbra : IDalamudPlugin
ObjectReloader = new ObjectReloader(); ObjectReloader = new ObjectReloader();
PathResolver = new PathResolver( ResourceLoader ); PathResolver = new PathResolver( ResourceLoader );
SetupInterface( out ConfigWindow, out _launchButton, out _windowSystem, out _changelog ); SetupInterface();
_commandHandler = new CommandHandler( Dalamud.Commands, ObjectReloader, Config, this, ConfigWindow, ModManager, CollectionManager, Actors );
if( Config.EnableMods ) if( Config.EnableMods )
{ {
@ -140,7 +142,6 @@ public class Penumbra : IDalamudPlugin
if( Config.DebugMode ) if( Config.DebugMode )
{ {
ResourceLoader.EnableDebug(); ResourceLoader.EnableDebug();
ConfigWindow.IsOpen = true;
} }
using( var tApi = StartTimer.Measure( StartTimeType.Api ) ) using( var tApi = StartTimer.Measure( StartTimeType.Api ) )
@ -156,8 +157,6 @@ public class Penumbra : IDalamudPlugin
SubscribeItemLinks(); SubscribeItemLinks();
} }
Dalamud.PluginInterface.UiBuilder.Draw += _windowSystem.Draw;
ValidityChecker.LogExceptions(); ValidityChecker.LogExceptions();
Log.Information( $"Penumbra Version {Version}, Commit #{CommitHash} successfully Loaded from {pluginInterface.SourceRepository}." ); Log.Information( $"Penumbra Version {Version}, Commit #{CommitHash} successfully Loaded from {pluginInterface.SourceRepository}." );
OtterTex.NativeDll.Initialize( Dalamud.PluginInterface.AssemblyLocation.DirectoryName ); OtterTex.NativeDll.Initialize( Dalamud.PluginInterface.AssemblyLocation.DirectoryName );
@ -175,17 +174,40 @@ public class Penumbra : IDalamudPlugin
} }
} }
private void SetupInterface( out ConfigWindow cfg, out LaunchButton btn, out WindowSystem system, out Changelog changelog ) private void SetupInterface()
{
Task.Run( () =>
{ {
using var tInterface = StartTimer.Measure( StartTimeType.Interface ); using var tInterface = StartTimer.Measure( StartTimeType.Interface );
cfg = new ConfigWindow( this, _resourceWatcher ); var changelog = ConfigWindow.CreateChangelog();
btn = new LaunchButton( ConfigWindow ); var cfg = new ConfigWindow( this, _resourceWatcher )
system = new WindowSystem( Name ); {
changelog = ConfigWindow.CreateChangelog(); IsOpen = Config.DebugMode,
system.AddWindow( ConfigWindow ); };
var btn = new LaunchButton( cfg );
var system = new WindowSystem( Name );
var cmd = new CommandHandler( Dalamud.Commands, ObjectReloader, Config, this, cfg, ModManager, CollectionManager, Actors );
system.AddWindow( cfg );
system.AddWindow( cfg.ModEditPopup ); system.AddWindow( cfg.ModEditPopup );
system.AddWindow( changelog ); system.AddWindow( changelog );
if( !_disposed )
{
_changelog = changelog;
ConfigWindow = cfg;
_windowSystem = system;
_launchButton = btn;
_commandHandler = cmd;
Dalamud.PluginInterface.UiBuilder.OpenConfigUi += cfg.Toggle; Dalamud.PluginInterface.UiBuilder.OpenConfigUi += cfg.Toggle;
Dalamud.PluginInterface.UiBuilder.Draw += _windowSystem.Draw;
}
else
{
cfg.Dispose();
btn.Dispose();
cmd.Dispose();
}
}
);
} }
private void DisposeInterface() private void DisposeInterface()
@ -243,7 +265,12 @@ public class Penumbra : IDalamudPlugin
} }
public void ForceChangelogOpen() public void ForceChangelogOpen()
=> _changelog.ForceOpen = true; {
if( _changelog != null )
{
_changelog.ForceOpen = true;
}
}
private void SubscribeItemLinks() private void SubscribeItemLinks()
{ {
@ -268,6 +295,12 @@ public class Penumbra : IDalamudPlugin
public void Dispose() public void Dispose()
{ {
if( _disposed )
{
return;
}
_disposed = true;
HttpApi?.Dispose(); HttpApi?.Dispose();
IpcProviders?.Dispose(); IpcProviders?.Dispose();
Api?.Dispose(); Api?.Dispose();