Use Lunas IndexedWindow and WindowFactory.
Some checks failed
.NET Build / build (push) Has been cancelled

This commit is contained in:
Ottermandias 2025-10-20 23:28:56 +02:00
parent 97c9f1c8c4
commit cb275f57bf
7 changed files with 114 additions and 202 deletions

2
Luna

@ -1 +1 @@
Subproject commit ec5cc05211c5083f276e32816d8c3eb8c09d04b4
Subproject commit 7214f079cb9b8eeea6fa1a9fe1c6ca8118049969

View file

@ -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<ConfigTabBar>());
_services.GetService<CommandHandler>();
if (!_disposed)
{
_windowSystem = system;
if (_config is { OpenWindowAtStart: true, Ephemeral.AdvancedEditingOpen: true } && _services.GetService<ModSelection>().Mod is {} mod)
_services.GetService<ModEditWindowFactory>().OpenForMod(mod);
}
else
system.Dispose();
}

View file

@ -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;

View file

@ -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<ModEditWindow>, 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<ModEditWindow>(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)
@ -50,19 +55,22 @@ public class ModEditWindowFactory(FileDialogService fileDialog, ItemSwapTabFacto
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);
}

View file

@ -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);
}
}

View file

@ -1,70 +0,0 @@
using Dalamud.Interface.Windowing;
namespace Penumbra.UI.Classes;
public abstract class WindowFactory<T> where T : IndexedWindow
{
protected WindowSystem? WindowSystem;
private readonly HashSet<T> _openWindows = [];
private readonly HashSet<int> _reusableIndices = [];
private int _nextIndex = 0;
protected IEnumerable<T> 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);
}
}

View file

@ -1,6 +1,6 @@
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Luna;
using Penumbra.Interop.Services;
using Penumbra.UI.AdvancedWindow;
using Penumbra.UI.Knowledge;
@ -8,36 +8,34 @@ using Penumbra.UI.Tabs.Debug;
namespace Penumbra.UI;
public class PenumbraWindowSystem : IDisposable, Luna.IUiService
public class PenumbraWindowSystem : IDisposable, 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;
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)
KnowledgeWindow knowledgeWindow, TextureArraySlicer textureArraySlicer, WindowSystem windowSystem)
{
_uiBuilder = pi.UiBuilder;
_fileDialog = fileDialog;
_textureArraySlicer = textureArraySlicer;
_windowSystem = windowSystem;
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;