diff --git a/Glamourer/Gui/ConvenienceRevertButtons.cs b/Glamourer/Gui/ConvenienceRevertButtons.cs new file mode 100644 index 0000000..bf8bd11 --- /dev/null +++ b/Glamourer/Gui/ConvenienceRevertButtons.cs @@ -0,0 +1,62 @@ +using System.Numerics; +using Dalamud.Interface; +using Glamourer.Automation; +using Glamourer.Events; +using Glamourer.Interop; +using Glamourer.State; +using ImGuiNET; +using OtterGui; +using OtterGui.Raii; + +namespace Glamourer.Gui; + +public class ConvenienceRevertButtons +{ + private readonly StateManager _stateManager; + private readonly AutoDesignApplier _autoDesignApplier; + private readonly ObjectManager _objects; + private readonly Configuration _config; + + + public ConvenienceRevertButtons(StateManager stateManager, AutoDesignApplier autoDesignApplier, ObjectManager objects, + Configuration config) + { + _stateManager = stateManager; + _autoDesignApplier = autoDesignApplier; + _objects = objects; + _config = config; + } + + public void DrawButtons(float yPos) + { + _objects.Update(); + var (playerIdentifier, playerData) = _objects.PlayerData; + + string? error = null; + if (!playerIdentifier.IsValid || !playerData.Valid) + error = "No player character available."; + + if (!_stateManager.TryGetValue(playerIdentifier, out var state)) + error = "The player character was not modified by Glamourer yet."; + else if (state.IsLocked) + error = "The state of the player character is currently locked."; + + var buttonSize = new Vector2(ImGui.GetFrameHeight()); + var spacing = ImGui.GetStyle().ItemInnerSpacing; + ImGui.SetCursorPos(new Vector2(ImGui.GetWindowContentRegionMax().X - 2 * buttonSize.X - spacing.X, yPos - 1)); + + using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, spacing); + if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.RedoAlt.ToIconString(), buttonSize, + error ?? "Revert the player character to its game state.", error != null, true)) + _stateManager.ResetState(state, StateChanged.Source.Manual); + + ImGui.SameLine(); + if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.SyncAlt.ToIconString(), buttonSize, + error ?? "Revert the player character to its automation state.", error != null && _config.EnableAutoDesigns, true)) + foreach (var actor in playerData.Objects) + { + _autoDesignApplier.ReapplyAutomation(actor, playerIdentifier, state); + _stateManager.ReapplyState(actor); + } + } +} diff --git a/Glamourer/Gui/MainWindow.cs b/Glamourer/Gui/MainWindow.cs index ab572f0..6c823a8 100644 --- a/Glamourer/Gui/MainWindow.cs +++ b/Glamourer/Gui/MainWindow.cs @@ -1,5 +1,6 @@ using System; using System.Numerics; +using Dalamud.Interface; using Dalamud.Interface.Windowing; using Dalamud.Plugin; using Glamourer.Designs; @@ -28,9 +29,10 @@ public class MainWindow : Window, IDisposable Unlocks = 5, } - private readonly Configuration _config; - private readonly TabSelected _event; - private readonly ITab[] _tabs; + private readonly Configuration _config; + private readonly TabSelected _event; + private readonly ConvenienceRevertButtons _convenienceButtons; + private readonly ITab[] _tabs; public readonly SettingsTab Settings; public readonly ActorTab Actors; @@ -42,7 +44,7 @@ public class MainWindow : Window, IDisposable public TabType SelectTab = TabType.None; public MainWindow(DalamudPluginInterface pi, Configuration config, SettingsTab settings, ActorTab actors, DesignTab designs, - DebugTab debugTab, AutomationTab automation, UnlocksTab unlocks, TabSelected @event) + DebugTab debugTab, AutomationTab automation, UnlocksTab unlocks, TabSelected @event, ConvenienceRevertButtons convenienceButtons) : base(GetLabel()) { pi.UiBuilder.DisableGposeUiHide = true; @@ -51,14 +53,15 @@ public class MainWindow : Window, IDisposable MinimumSize = new Vector2(700, 675), MaximumSize = ImGui.GetIO().DisplaySize, }; - Settings = settings; - Actors = actors; - Designs = designs; - Automation = automation; - Debug = debugTab; - Unlocks = unlocks; - _event = @event; - _config = config; + Settings = settings; + Actors = actors; + Designs = designs; + Automation = automation; + Debug = debugTab; + Unlocks = unlocks; + _event = @event; + _convenienceButtons = convenienceButtons; + _config = config; _tabs = new ITab[] { settings, @@ -69,7 +72,6 @@ public class MainWindow : Window, IDisposable debugTab, }; _event.Subscribe(OnTabSelected, TabSelected.Priority.MainWindow); - IsOpen = _config.DebugMode; } @@ -78,12 +80,15 @@ public class MainWindow : Window, IDisposable public override void Draw() { - if (!TabBar.Draw("##tabs", ImGuiTabBarFlags.None, ToLabel(SelectTab), out var currentTab, () => { }, _tabs)) - return; + var yPos = ImGui.GetCursorPosY(); + if (TabBar.Draw("##tabs", ImGuiTabBarFlags.None, ToLabel(SelectTab), out var currentTab, () => { }, _tabs)) + { + SelectTab = TabType.None; + _config.SelectedTab = FromLabel(currentTab); + _config.Save(); + } - SelectTab = TabType.None; - _config.SelectedTab = FromLabel(currentTab); - _config.Save(); + _convenienceButtons.DrawButtons(yPos); } private ReadOnlySpan ToLabel(TabType type) diff --git a/Glamourer/Gui/UiHelpers.cs b/Glamourer/Gui/UiHelpers.cs index 7e9d357..223d71d 100644 --- a/Glamourer/Gui/UiHelpers.cs +++ b/Glamourer/Gui/UiHelpers.cs @@ -119,4 +119,4 @@ public static class UiHelpers (true, false) => (true, false), (false, true) => (false, true), }; -} +} \ No newline at end of file diff --git a/Glamourer/Services/ServiceManager.cs b/Glamourer/Services/ServiceManager.cs index 0a7157f..2a1cbc8 100644 --- a/Glamourer/Services/ServiceManager.cs +++ b/Glamourer/Services/ServiceManager.cs @@ -138,7 +138,8 @@ public static class ServiceManager .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton(); private static IServiceCollection AddApi(this IServiceCollection services) => services.AddSingleton()