Added button to jump to template editing from profile tab, made TemplateManager IDisposable

This commit is contained in:
RisaDev
2024-06-16 02:58:17 +03:00
parent faa4af97ad
commit ef6c7014e4
5 changed files with 178 additions and 20 deletions

View File

@@ -16,6 +16,9 @@ using CustomizePlus.Templates;
using ECommons.ImGuiMethods;
using static System.Windows.Forms.AxHost;
using Dalamud.Interface.Colors;
using CustomizePlus.Templates.Events;
using CustomizePlus.Templates.Data;
using ECommons.Schedulers;
namespace CustomizePlus.UI.Windows.MainWindow;
@@ -34,6 +37,15 @@ public class MainWindow : Window, IDisposable
private readonly PluginConfiguration _configuration;
private readonly HookingService _hookingService;
private readonly TemplateEditorEvent _templateEditorEvent;
/// <summary>
/// Used to force the main window to switch to specific tab
/// </summary>
private string? _switchToTab = null;
private Action? _actionAfterTabSwitch = null;
public MainWindow(
DalamudPluginInterface pluginInterface,
SettingsTab settingsTab,
@@ -45,7 +57,8 @@ public class MainWindow : Window, IDisposable
PluginStateBlock pluginStateBlock,
TemplateEditorManager templateEditorManager,
PluginConfiguration configuration,
HookingService hookingService
HookingService hookingService,
TemplateEditorEvent templateEditorEvent
) : base($"Customize+ v{Plugin.Version}###CPlusMainWindow")
{
_settingsTab = settingsTab;
@@ -61,6 +74,10 @@ public class MainWindow : Window, IDisposable
_configuration = configuration;
_hookingService = hookingService;
_templateEditorEvent = templateEditorEvent;
_templateEditorEvent.Subscribe(OnTemplateEditorEvent, TemplateEditorEvent.Priority.MainWindow);
pluginInterface.UiBuilder.DisableGposeUiHide = true;
SizeConstraints = new WindowSizeConstraints()
{
@@ -73,7 +90,7 @@ public class MainWindow : Window, IDisposable
public void Dispose()
{
//throw new NotImplementedException();
_templateEditorEvent.Unsubscribe(OnTemplateEditorEvent);
}
public override void Draw()
@@ -83,13 +100,21 @@ public class MainWindow : Window, IDisposable
using (var disabled = ImRaii.Disabled(_hookingService.RenderHookFailed || _hookingService.MovementHookFailed))
{
LockWindowClosureIfNeeded();
ImGuiEx.EzTabBar("##tabs", [
ImGuiEx.EzTabBar("##tabs", null, _switchToTab, [
("Settings", _settingsTab.Draw, null, true),
("Templates", _templatesTab.Draw, null, true),
("Profiles", _profilesTab.Draw, null, true),
(_configuration.DebuggingModeEnabled ? "IPC Test" : null, _ipcTestTab.Draw, ImGuiColors.DalamudGrey, true),
(_configuration.DebuggingModeEnabled ? "State monitoring" : null, _stateMonitoringTab.Draw, ImGuiColors.DalamudGrey, true),
]);
_switchToTab = null;
if (_actionAfterTabSwitch != null)
{
_actionAfterTabSwitch();
_actionAfterTabSwitch = null;
}
}
_pluginStateBlock.Draw(yPos);
@@ -108,4 +133,24 @@ public class MainWindow : Window, IDisposable
RespectCloseHotkey = true;
}
}
private void OnTemplateEditorEvent(TemplateEditorEvent.Type type, Template? template)
{
if (type != TemplateEditorEvent.Type.EditorEnableRequested)
return;
if (template == null)
return;
if (!template.IsWriteProtected && !_templateEditorManager.IsEditorActive)
{
new TickScheduler(() =>
{
_switchToTab = "Templates";
//To make sure the tab has switched, ugly but imgui is shit and I don't trust it.
_actionAfterTabSwitch = () => { _templateEditorEvent.Invoke(TemplateEditorEvent.Type.EditorEnableRequestedStage2, template); };
});
}
}
}