From cb275f57bfb41c7d7fd7ba43c736028bfcdec52c Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 20 Oct 2025 23:28:56 +0200 Subject: [PATCH] Use Lunas IndexedWindow and WindowFactory. --- Luna | 2 +- Penumbra/Penumbra.cs | 39 +++--- Penumbra/UI/AdvancedWindow/ModEditWindow.cs | 6 +- .../UI/AdvancedWindow/ModEditWindowFactory.cs | 52 ++++---- Penumbra/UI/Classes/IndexedWindow.cs | 31 ----- Penumbra/UI/Classes/WindowFactory.cs | 70 ----------- Penumbra/UI/WindowSystem.cs | 116 +++++++++--------- 7 files changed, 114 insertions(+), 202 deletions(-) delete mode 100644 Penumbra/UI/Classes/IndexedWindow.cs delete mode 100644 Penumbra/UI/Classes/WindowFactory.cs diff --git a/Luna b/Luna index ec5cc052..7214f079 160000 --- a/Luna +++ b/Luna @@ -1 +1 @@ -Subproject commit ec5cc05211c5083f276e32816d8c3eb8c09d04b4 +Subproject commit 7214f079cb9b8eeea6fa1a9fe1c6ca8118049969 diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index ab5e8fa9..770f809a 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -1,32 +1,35 @@ using Dalamud.Plugin; -using OtterGui; -using Penumbra.Api; -using Penumbra.Api.Enums; -using Penumbra.Collections; -using Penumbra.Collections.Cache; -using Penumbra.Interop.PathResolving; -using Penumbra.Services; -using Penumbra.Interop.Services; -using Penumbra.Mods.Manager; -using Penumbra.Collections.Manager; -using Penumbra.UI.Tabs; -using ChangedItemClick = Penumbra.Communication.ChangedItemClick; -using ChangedItemHover = Penumbra.Communication.ChangedItemHover; -using OtterGui.Tasks; -using Penumbra.UI; -using ResidentResourceManager = Penumbra.Interop.Services.ResidentResourceManager; using Dalamud.Plugin.Services; using ImSharp; using Lumina.Excel.Sheets; using Luna; +using OtterGui; +using OtterGui.Tasks; +using Penumbra.Api; +using Penumbra.Api.Enums; +using Penumbra.Collections; +using Penumbra.Collections.Cache; +using Penumbra.Collections.Manager; using Penumbra.Communication; using Penumbra.GameData.Data; using Penumbra.Interop; using Penumbra.Interop.Hooks; using Penumbra.Interop.Hooks.PostProcessing; +using Penumbra.Interop.PathResolving; +using Penumbra.Interop.Services; +using Penumbra.Mods; +using Penumbra.Mods.Manager; +using Penumbra.Services; +using Penumbra.UI; +using Penumbra.UI.AdvancedWindow; +using Penumbra.UI.Tabs; +using static System.Collections.Specialized.BitVector32; +using ChangedItemClick = Penumbra.Communication.ChangedItemClick; +using ChangedItemHover = Penumbra.Communication.ChangedItemHover; using DynamisIpc = OtterGui.Services.DynamisIpc; using MessageService = Penumbra.Services.MessageService; using MouseButton = Penumbra.Api.Enums.MouseButton; +using ResidentResourceManager = Penumbra.Interop.Services.ResidentResourceManager; namespace Penumbra; @@ -136,7 +139,11 @@ public class Penumbra : IDalamudPlugin system.Window.Setup(this, _services.GetService()); _services.GetService(); if (!_disposed) + { _windowSystem = system; + if (_config is { OpenWindowAtStart: true, Ephemeral.AdvancedEditingOpen: true } && _services.GetService().Mod is {} mod) + _services.GetService().OpenForMod(mod); + } else system.Dispose(); } diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs index a986704e..218d70f3 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs @@ -1,10 +1,10 @@ using Dalamud.Interface; using Dalamud.Interface.Components; using Dalamud.Interface.DragDrop; -using Dalamud.Interface.Windowing; using Dalamud.Plugin.Services; using Dalamud.Bindings.ImGui; using ImSharp; +using Luna; using OtterGui; using OtterGui.Raii; using OtterGui.Text; @@ -623,8 +623,8 @@ public partial class ModEditWindow : IndexedWindow, IDisposable CommunicatorService communicator, TextureManager textures, ModelManager models, IDragDropManager dragDropManager, ResourceTreeViewerFactory resourceTreeViewerFactory, IFramework framework, MetaDrawers metaDrawers, - MtrlTabFactory mtrlTabFactory, WindowSystem windowSystem, int index) - : base($"{WindowBaseLabel}{index}", windowSystem, index) + MtrlTabFactory mtrlTabFactory, int index) + : base(WindowBaseLabel, index) { _itemSwapTab = itemSwapTab; _gameData = gameData; diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindowFactory.cs b/Penumbra/UI/AdvancedWindow/ModEditWindowFactory.cs index ade0f0e4..b281577f 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindowFactory.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindowFactory.cs @@ -1,5 +1,6 @@ using Dalamud.Interface.DragDrop; using Dalamud.Plugin.Services; +using Luna; using Penumbra.Collections.Manager; using Penumbra.Import.Models; using Penumbra.Import.Textures; @@ -10,31 +11,35 @@ using Penumbra.Mods.Editor; using Penumbra.Services; using Penumbra.UI.AdvancedWindow.Materials; using Penumbra.UI.AdvancedWindow.Meta; -using Penumbra.UI.Classes; namespace Penumbra.UI.AdvancedWindow; -public class ModEditWindowFactory(FileDialogService fileDialog, ItemSwapTabFactory itemSwapTabFactory, IDataManager gameData, - Configuration config, ModEditorFactory editorFactory, ResourceTreeFactory resourceTreeFactory, MetaFileManager metaFileManager, - ActiveCollections activeCollections, ModMergeTab modMergeTab, - CommunicatorService communicator, TextureManager textures, ModelManager models, IDragDropManager dragDropManager, - ResourceTreeViewerFactory resourceTreeViewerFactory, IFramework framework, - MtrlTabFactory mtrlTabFactory, ModSelection selection) : WindowFactory, Luna.IUiService +public class ModEditWindowFactory( + FileDialogService fileDialog, + ItemSwapTabFactory itemSwapTabFactory, + IDataManager gameData, + Configuration config, + ModEditorFactory editorFactory, + ResourceTreeFactory resourceTreeFactory, + MetaFileManager metaFileManager, + ActiveCollections activeCollections, + ModMergeTab modMergeTab, + CommunicatorService communicator, + TextureManager textures, + ModelManager models, + IDragDropManager dragDropManager, + ResourceTreeViewerFactory resourceTreeViewerFactory, + IFramework framework, + WindowSystem windowSystem, + Logger log, + MtrlTabFactory mtrlTabFactory) : WindowFactory(log, windowSystem), IUiService { - protected override void OnWindowSystemSet() - { - if (config is { OpenWindowAtStart: true, Ephemeral.AdvancedEditingOpen: true } && selection.Mod is not null) - OpenForMod(selection.Mod); - } - - protected override ModEditWindow? DoCreateWindow() + protected override ModEditWindow CreateWindow(int index) { var editor = editorFactory.Create(); - - return new(fileDialog, itemSwapTabFactory.Create(), gameData, config, editor, resourceTreeFactory, metaFileManager, + return new ModEditWindow(fileDialog, itemSwapTabFactory.Create(), gameData, config, editor, resourceTreeFactory, metaFileManager, activeCollections, modMergeTab, communicator, textures, models, dragDropManager, resourceTreeViewerFactory, framework, - CreateMetaDrawers(editor.MetaEditor), mtrlTabFactory, WindowSystem ?? throw new InvalidOperationException("WindowSystem not set"), - GetFreeIndex()); + CreateMetaDrawers(editor.MetaEditor), mtrlTabFactory, index); } private MetaDrawers CreateMetaDrawers(ModMetaEditor metaEditor) @@ -49,20 +54,23 @@ public class ModEditWindowFactory(FileDialogService fileDialog, ItemSwapTabFacto var atch = new AtchMetaDrawer(metaEditor, metaFileManager); var shp = new ShpMetaDrawer(metaEditor, metaFileManager); var atr = new AtrMetaDrawer(metaEditor, metaFileManager); - - return new(eqdp, eqp, est, globalEqp, gmp, imc, rsp, atch, shp, atr); + + return new MetaDrawers(eqdp, eqp, est, globalEqp, gmp, imc, rsp, atch, shp, atr); } public void OpenForMod(Mod mod) { - var window = OpenWindows.FirstOrDefault(window => window.Mod == mod); + var window = Windows.FirstOrDefault(window => window.Mod == mod); if (window is not null) { window.BringToFront(); return; } - window = CreateWindow()!; + window = CreateWindowInternal(); + if (window is null) + return; + window.ChangeMod(mod); window.ChangeOption(mod.Default); } diff --git a/Penumbra/UI/Classes/IndexedWindow.cs b/Penumbra/UI/Classes/IndexedWindow.cs deleted file mode 100644 index 58d2386b..00000000 --- a/Penumbra/UI/Classes/IndexedWindow.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Dalamud.Interface.Windowing; -using ImSharp; -using Window = Luna.Window; - -namespace Penumbra.UI.Classes; - -public abstract class IndexedWindow : Window -{ - private readonly WindowSystem _windowSystem; - private readonly int _index; - - public int Index - => _index; - - public event EventHandler? Close; - - protected IndexedWindow(string name, WindowSystem windowSystem, int index, - WindowFlags flags = WindowFlags.None, bool forceMainWindow = false) : base( - name, flags, forceMainWindow - ) - { - _windowSystem = windowSystem; - _index = index; - } - - public override void OnClose() - { - _windowSystem.RemoveWindow(this); - Close?.Invoke(this, EventArgs.Empty); - } -} diff --git a/Penumbra/UI/Classes/WindowFactory.cs b/Penumbra/UI/Classes/WindowFactory.cs deleted file mode 100644 index 7cb37f61..00000000 --- a/Penumbra/UI/Classes/WindowFactory.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Dalamud.Interface.Windowing; - -namespace Penumbra.UI.Classes; - -public abstract class WindowFactory where T : IndexedWindow -{ - protected WindowSystem? WindowSystem; - - private readonly HashSet _openWindows = []; - private readonly HashSet _reusableIndices = []; - private int _nextIndex = 0; - - protected IEnumerable OpenWindows - => _openWindows; - - internal void SetWindowSystem(WindowSystem windowSystem) - { - if (WindowSystem is not null) - throw new InvalidOperationException("WindowSystem is already set"); - - WindowSystem = windowSystem; - - OnWindowSystemSet(); - } - - protected virtual void OnWindowSystemSet() - { - } - - protected int GetFreeIndex() - { - foreach (var index in _reusableIndices) { - _reusableIndices.Remove(index); - return index; - } - - return _nextIndex++; - } - - protected abstract T? DoCreateWindow(); - - protected T? CreateWindow() - { - var window = DoCreateWindow(); - if (window is not null) { - SetupWindow(window); - } - - return window; - } - - protected void SetupWindow(T window) - { - window.Close += WindowClose; - WindowSystem?.AddWindow(window); - window.IsOpen = true; - _openWindows.Add(window); - window.BringToFront(); - } - - private void WindowClose(object? sender, EventArgs e) - { - if (sender is not T window) { - return; - } - - _openWindows.Remove(window); - _reusableIndices.Add(window.Index); - } -} diff --git a/Penumbra/UI/WindowSystem.cs b/Penumbra/UI/WindowSystem.cs index be6b11cd..32f790c4 100644 --- a/Penumbra/UI/WindowSystem.cs +++ b/Penumbra/UI/WindowSystem.cs @@ -1,59 +1,57 @@ -using Dalamud.Interface; -using Dalamud.Interface.Windowing; -using Dalamud.Plugin; -using Penumbra.Interop.Services; -using Penumbra.UI.AdvancedWindow; -using Penumbra.UI.Knowledge; -using Penumbra.UI.Tabs.Debug; - -namespace Penumbra.UI; - -public class PenumbraWindowSystem : IDisposable, Luna.IUiService -{ - private readonly IUiBuilder _uiBuilder; - internal readonly WindowSystem _windowSystem; - private readonly FileDialogService _fileDialog; - private readonly TextureArraySlicer _textureArraySlicer; - public readonly ConfigWindow Window; - public readonly PenumbraChangelog Changelog; - public readonly KnowledgeWindow KnowledgeWindow; - - public PenumbraWindowSystem(IDalamudPluginInterface pi, Configuration config, PenumbraChangelog changelog, ConfigWindow window, - LaunchButton _, ModEditWindowFactory editWindowFactory, FileDialogService fileDialog, ImportPopup importPopup, DebugTab debugTab, - KnowledgeWindow knowledgeWindow, TextureArraySlicer textureArraySlicer) - { - _uiBuilder = pi.UiBuilder; - _fileDialog = fileDialog; - _textureArraySlicer = textureArraySlicer; - KnowledgeWindow = knowledgeWindow; - Changelog = changelog; - Window = window; - _windowSystem = new WindowSystem("Penumbra"); - _windowSystem.AddWindow(changelog.Changelog); - _windowSystem.AddWindow(window); - _windowSystem.AddWindow(importPopup); - _windowSystem.AddWindow(debugTab); - _windowSystem.AddWindow(KnowledgeWindow); - editWindowFactory.SetWindowSystem(_windowSystem); - _uiBuilder.OpenMainUi += Window.Toggle; - _uiBuilder.OpenConfigUi += Window.OpenSettings; - _uiBuilder.Draw += _windowSystem.Draw; - _uiBuilder.Draw += _fileDialog.Draw; - _uiBuilder.Draw += _textureArraySlicer.Tick; - _uiBuilder.DisableGposeUiHide = !config.HideUiInGPose; - _uiBuilder.DisableCutsceneUiHide = !config.HideUiInCutscenes; - _uiBuilder.DisableUserUiHide = !config.HideUiWhenUiHidden; - } - - public void ForceChangelogOpen() - => Changelog.Changelog.ForceOpen = true; - - public void Dispose() - { - _uiBuilder.OpenMainUi -= Window.Toggle; - _uiBuilder.OpenConfigUi -= Window.OpenSettings; - _uiBuilder.Draw -= _windowSystem.Draw; - _uiBuilder.Draw -= _fileDialog.Draw; - _uiBuilder.Draw -= _textureArraySlicer.Tick; - } -} +using Dalamud.Interface; +using Dalamud.Plugin; +using Luna; +using Penumbra.Interop.Services; +using Penumbra.UI.AdvancedWindow; +using Penumbra.UI.Knowledge; +using Penumbra.UI.Tabs.Debug; + +namespace Penumbra.UI; + +public class PenumbraWindowSystem : IDisposable, IUiService +{ + private readonly IUiBuilder _uiBuilder; + private readonly WindowSystem _windowSystem; + private readonly FileDialogService _fileDialog; + private readonly TextureArraySlicer _textureArraySlicer; + public readonly ConfigWindow Window; + public readonly PenumbraChangelog Changelog; + public readonly KnowledgeWindow KnowledgeWindow; + + public PenumbraWindowSystem(IDalamudPluginInterface pi, Configuration config, PenumbraChangelog changelog, ConfigWindow window, + LaunchButton _, ModEditWindowFactory editWindowFactory, FileDialogService fileDialog, ImportPopup importPopup, DebugTab debugTab, + KnowledgeWindow knowledgeWindow, TextureArraySlicer textureArraySlicer, WindowSystem windowSystem) + { + _uiBuilder = pi.UiBuilder; + _fileDialog = fileDialog; + _textureArraySlicer = textureArraySlicer; + _windowSystem = windowSystem; + KnowledgeWindow = knowledgeWindow; + Changelog = changelog; + Window = window; + _windowSystem.AddWindow(changelog.Changelog); + _windowSystem.AddWindow(window); + _windowSystem.AddWindow(importPopup); + _windowSystem.AddWindow(debugTab); + _windowSystem.AddWindow(KnowledgeWindow); + _uiBuilder.OpenMainUi += Window.Toggle; + _uiBuilder.OpenConfigUi += Window.OpenSettings; + _uiBuilder.Draw += _fileDialog.Draw; + _uiBuilder.Draw += _textureArraySlicer.Tick; + _uiBuilder.DisableGposeUiHide = !config.HideUiInGPose; + _uiBuilder.DisableCutsceneUiHide = !config.HideUiInCutscenes; + _uiBuilder.DisableUserUiHide = !config.HideUiWhenUiHidden; + } + + public void ForceChangelogOpen() + => Changelog.Changelog.ForceOpen = true; + + public void Dispose() + { + _uiBuilder.OpenMainUi -= Window.Toggle; + _uiBuilder.OpenConfigUi -= Window.OpenSettings; + _uiBuilder.Draw -= _windowSystem.Draw; + _uiBuilder.Draw -= _fileDialog.Draw; + _uiBuilder.Draw -= _textureArraySlicer.Tick; + } +}