Add support for jumping to Designs from Automated Design tab (later IPC probably).

This commit is contained in:
Ottermandias 2023-07-17 18:35:03 +02:00
parent 56ad7dc968
commit b47164ad4f
5 changed files with 83 additions and 18 deletions

View file

@ -0,0 +1,33 @@
using System;
using Glamourer.Designs;
using Glamourer.Gui;
using OtterGui.Classes;
namespace Glamourer.Events;
/// <summary>
/// Triggered when an automated design is changed in any way.
/// <list type="number">
/// <item>Parameter is the tab to select. </item>
/// <item>Parameter is the design to select if the tab is the designs tab. </item>
/// </list>
/// </summary>
public sealed class TabSelected : EventWrapper<Action<MainWindow.TabType, Design?>,
TabSelected.Priority>
{
public enum Priority
{
/// <seealso cref="Gui.Tabs.DesignTab.DesignFileSystemSelector.OnTabSelected"/>
DesignSelector = 0,
/// <seealso cref="Gui.MainWindow.OnTabSelected"/>
MainWindow = 1,
}
public TabSelected()
: base(nameof(TabSelected))
{ }
public void Invoke(MainWindow.TabType type, Design? design)
=> Invoke(this, type, design);
}

View file

@ -2,6 +2,8 @@
using System.Numerics; using System.Numerics;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Glamourer.Designs;
using Glamourer.Events;
using Glamourer.Gui.Tabs; using Glamourer.Gui.Tabs;
using Glamourer.Gui.Tabs.ActorTab; using Glamourer.Gui.Tabs.ActorTab;
using Glamourer.Gui.Tabs.AutomationTab; using Glamourer.Gui.Tabs.AutomationTab;
@ -13,7 +15,7 @@ using OtterGui.Widgets;
namespace Glamourer.Gui; namespace Glamourer.Gui;
public class MainWindow : Window public class MainWindow : Window, IDisposable
{ {
public enum TabType public enum TabType
{ {
@ -27,8 +29,10 @@ public class MainWindow : Window
} }
private readonly Configuration _config; private readonly Configuration _config;
private readonly TabSelected _event;
private readonly ITab[] _tabs; private readonly ITab[] _tabs;
public readonly SettingsTab Settings; public readonly SettingsTab Settings;
public readonly ActorTab Actors; public readonly ActorTab Actors;
public readonly DebugTab Debug; public readonly DebugTab Debug;
@ -39,7 +43,7 @@ public class MainWindow : Window
public TabType SelectTab = TabType.None; public TabType SelectTab = TabType.None;
public MainWindow(DalamudPluginInterface pi, Configuration config, SettingsTab settings, ActorTab actors, DesignTab designs, public MainWindow(DalamudPluginInterface pi, Configuration config, SettingsTab settings, ActorTab actors, DesignTab designs,
DebugTab debugTab, AutomationTab automation, UnlocksTab unlocks) DebugTab debugTab, AutomationTab automation, UnlocksTab unlocks, TabSelected @event)
: base(GetLabel()) : base(GetLabel())
{ {
pi.UiBuilder.DisableGposeUiHide = true; pi.UiBuilder.DisableGposeUiHide = true;
@ -54,6 +58,7 @@ public class MainWindow : Window
Automation = automation; Automation = automation;
Debug = debugTab; Debug = debugTab;
Unlocks = unlocks; Unlocks = unlocks;
_event = @event;
_config = config; _config = config;
_tabs = new ITab[] _tabs = new ITab[]
{ {
@ -64,10 +69,14 @@ public class MainWindow : Window
unlocks, unlocks,
debugTab, debugTab,
}; };
_event.Subscribe(OnTabSelected, TabSelected.Priority.MainWindow);
IsOpen = _config.DebugMode; IsOpen = _config.DebugMode;
} }
public void Dispose()
=> _event.Unsubscribe(OnTabSelected);
public override void Draw() public override void Draw()
{ {
if (!TabBar.Draw("##tabs", ImGuiTabBarFlags.None, ToLabel(SelectTab), out var currentTab, () => { }, _tabs)) if (!TabBar.Draw("##tabs", ImGuiTabBarFlags.None, ToLabel(SelectTab), out var currentTab, () => { }, _tabs))
@ -103,12 +112,6 @@ public class MainWindow : Window
return TabType.None; return TabType.None;
} }
private static string GetLabel()
=> Glamourer.Version.Length == 0
? "Glamourer###GlamourerMainWindow"
: $"Glamourer v{Glamourer.Version}###GlamourerMainWindow";
/// <summary> Draw the support button group on the right-hand side of the window. </summary> /// <summary> Draw the support button group on the right-hand side of the window. </summary>
public static void DrawSupportButtons() public static void DrawSupportButtons()
{ {
@ -124,4 +127,12 @@ public class MainWindow : Window
ImGui.SetCursorPos(new Vector2(xPos, ImGui.GetFrameHeightWithSpacing())); ImGui.SetCursorPos(new Vector2(xPos, ImGui.GetFrameHeightWithSpacing()));
CustomGui.DrawGuideButton(Glamourer.Chat, width); CustomGui.DrawGuideButton(Glamourer.Chat, width);
} }
private void OnTabSelected(TabType type, Design? _)
=> SelectTab = type;
private static string GetLabel()
=> Glamourer.Version.Length == 0
? "Glamourer###GlamourerMainWindow"
: $"Glamourer v{Glamourer.Version}###GlamourerMainWindow";
} }

View file

@ -1,6 +1,7 @@
using System.Linq; using System.Linq;
using Glamourer.Automation; using Glamourer.Automation;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events;
using ImGuiNET; using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
@ -12,12 +13,14 @@ public sealed class DesignCombo : FilterComboCache<Design>
{ {
private readonly AutoDesignManager _manager; private readonly AutoDesignManager _manager;
private readonly DesignFileSystem _fileSystem; private readonly DesignFileSystem _fileSystem;
private readonly TabSelected _tabSelected;
public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem) public DesignCombo(AutoDesignManager manager, DesignManager designs, DesignFileSystem fileSystem, TabSelected tabSelected)
: base(() => designs.Designs.OrderBy(d => d.Name).ToList()) : base(() => designs.Designs.OrderBy(d => d.Name).ToList())
{ {
_manager = manager; _manager = manager;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_tabSelected = tabSelected;
} }
protected override bool DrawSelectable(int globalIdx, bool selected) protected override bool DrawSelectable(int globalIdx, bool selected)
@ -26,7 +29,7 @@ public sealed class DesignCombo : FilterComboCache<Design>
if (_fileSystem.FindLeaf(Items[globalIdx], out var leaf)) if (_fileSystem.FindLeaf(Items[globalIdx], out var leaf))
{ {
var fullName = leaf.FullName(); var fullName = leaf.FullName();
if (!fullName.StartsWith(Items[globalIdx].Name)) if (!fullName.StartsWith(Items[globalIdx].Name))
{ {
using var color = ImRaii.PushColor(ImGuiCol.Text, ImGui.GetColorU32(ImGuiCol.TextDisabled)); using var color = ImRaii.PushColor(ImGuiCol.Text, ImGui.GetColorU32(ImGuiCol.TextDisabled));
@ -52,6 +55,13 @@ public sealed class DesignCombo : FilterComboCache<Design>
else else
_manager.AddDesign(set, CurrentSelection); _manager.AddDesign(set, CurrentSelection);
} }
if (design != null)
{
if (ImGui.IsItemClicked(ImGuiMouseButton.Right) && ImGui.GetIO().KeyCtrl)
_tabSelected.Invoke(MainWindow.TabType.Designs, design.Design);
ImGuiUtil.HoverTooltip("Control + Right-Click to move to design.");
}
} }
protected override string ToString(Design obj) protected override string ToString(Design obj)

View file

@ -22,6 +22,7 @@ public sealed class DesignFileSystemSelector : FileSystemSelector<Design, Design
private readonly DesignChanged _event; private readonly DesignChanged _event;
private readonly Configuration _config; private readonly Configuration _config;
private readonly DesignConverter _converter; private readonly DesignConverter _converter;
private readonly TabSelected _selectionEvent;
private string? _clipboardText; private string? _clipboardText;
private Design? _cloneDesign = null; private Design? _cloneDesign = null;
@ -46,14 +47,16 @@ public sealed class DesignFileSystemSelector : FileSystemSelector<Design, Design
} }
public DesignFileSystemSelector(DesignManager designManager, DesignFileSystem fileSystem, KeyState keyState, DesignChanged @event, public DesignFileSystemSelector(DesignManager designManager, DesignFileSystem fileSystem, KeyState keyState, DesignChanged @event,
Configuration config, DesignConverter converter) Configuration config, DesignConverter converter, TabSelected selectionEvent)
: base(fileSystem, keyState) : base(fileSystem, keyState)
{ {
_designManager = designManager; _designManager = designManager;
_event = @event; _event = @event;
_config = config; _config = config;
_converter = converter; _converter = converter;
_selectionEvent = selectionEvent;
_event.Subscribe(OnDesignChange, DesignChanged.Priority.DesignFileSystemSelector); _event.Subscribe(OnDesignChange, DesignChanged.Priority.DesignFileSystemSelector);
_selectionEvent.Subscribe(OnTabSelected, TabSelected.Priority.DesignSelector);
AddButton(NewDesignButton, 0); AddButton(NewDesignButton, 0);
AddButton(ImportDesignButton, 10); AddButton(ImportDesignButton, 10);
@ -79,6 +82,7 @@ public sealed class DesignFileSystemSelector : FileSystemSelector<Design, Design
{ {
base.Dispose(); base.Dispose();
_event.Unsubscribe(OnDesignChange); _event.Unsubscribe(OnDesignChange);
_selectionEvent.Unsubscribe(OnTabSelected);
} }
public override ISortMode<Design> SortMode public override ISortMode<Design> SortMode
@ -197,6 +201,12 @@ public sealed class DesignFileSystemSelector : FileSystemSelector<Design, Design
_newName = string.Empty; _newName = string.Empty;
} }
private void OnTabSelected(MainWindow.TabType type, Design? design)
{
if (type == MainWindow.TabType.Designs && design != null)
SelectByValue(design);
}
#region Filters #region Filters
private const StringComparison IgnoreCase = StringComparison.OrdinalIgnoreCase; private const StringComparison IgnoreCase = StringComparison.OrdinalIgnoreCase;

View file

@ -67,7 +67,8 @@ public static class ServiceManager
.AddSingleton<WeaponLoading>() .AddSingleton<WeaponLoading>()
.AddSingleton<HeadGearVisibilityChanged>() .AddSingleton<HeadGearVisibilityChanged>()
.AddSingleton<WeaponVisibilityChanged>() .AddSingleton<WeaponVisibilityChanged>()
.AddSingleton<ObjectUnlocked>(); .AddSingleton<ObjectUnlocked>()
.AddSingleton<TabSelected>();
private static IServiceCollection AddData(this IServiceCollection services) private static IServiceCollection AddData(this IServiceCollection services)
=> services.AddSingleton<IdentifierService>() => services.AddSingleton<IdentifierService>()