Add buttons to tab bar rhs to revert self.

This commit is contained in:
Ottermandias 2023-10-01 00:20:24 +02:00
parent 49768e797d
commit 3b618a08bc
4 changed files with 88 additions and 20 deletions

View file

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

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Numerics; using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin; using Dalamud.Plugin;
using Glamourer.Designs; using Glamourer.Designs;
@ -28,9 +29,10 @@ public class MainWindow : Window, IDisposable
Unlocks = 5, Unlocks = 5,
} }
private readonly Configuration _config; private readonly Configuration _config;
private readonly TabSelected _event; private readonly TabSelected _event;
private readonly ITab[] _tabs; private readonly ConvenienceRevertButtons _convenienceButtons;
private readonly ITab[] _tabs;
public readonly SettingsTab Settings; public readonly SettingsTab Settings;
public readonly ActorTab Actors; public readonly ActorTab Actors;
@ -42,7 +44,7 @@ public class MainWindow : Window, IDisposable
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, TabSelected @event) DebugTab debugTab, AutomationTab automation, UnlocksTab unlocks, TabSelected @event, ConvenienceRevertButtons convenienceButtons)
: base(GetLabel()) : base(GetLabel())
{ {
pi.UiBuilder.DisableGposeUiHide = true; pi.UiBuilder.DisableGposeUiHide = true;
@ -51,14 +53,15 @@ public class MainWindow : Window, IDisposable
MinimumSize = new Vector2(700, 675), MinimumSize = new Vector2(700, 675),
MaximumSize = ImGui.GetIO().DisplaySize, MaximumSize = ImGui.GetIO().DisplaySize,
}; };
Settings = settings; Settings = settings;
Actors = actors; Actors = actors;
Designs = designs; Designs = designs;
Automation = automation; Automation = automation;
Debug = debugTab; Debug = debugTab;
Unlocks = unlocks; Unlocks = unlocks;
_event = @event; _event = @event;
_config = config; _convenienceButtons = convenienceButtons;
_config = config;
_tabs = new ITab[] _tabs = new ITab[]
{ {
settings, settings,
@ -69,7 +72,6 @@ public class MainWindow : Window, IDisposable
debugTab, debugTab,
}; };
_event.Subscribe(OnTabSelected, TabSelected.Priority.MainWindow); _event.Subscribe(OnTabSelected, TabSelected.Priority.MainWindow);
IsOpen = _config.DebugMode; IsOpen = _config.DebugMode;
} }
@ -78,12 +80,15 @@ public class MainWindow : Window, IDisposable
public override void Draw() public override void Draw()
{ {
if (!TabBar.Draw("##tabs", ImGuiTabBarFlags.None, ToLabel(SelectTab), out var currentTab, () => { }, _tabs)) var yPos = ImGui.GetCursorPosY();
return; if (TabBar.Draw("##tabs", ImGuiTabBarFlags.None, ToLabel(SelectTab), out var currentTab, () => { }, _tabs))
{
SelectTab = TabType.None;
_config.SelectedTab = FromLabel(currentTab);
_config.Save();
}
SelectTab = TabType.None; _convenienceButtons.DrawButtons(yPos);
_config.SelectedTab = FromLabel(currentTab);
_config.Save();
} }
private ReadOnlySpan<byte> ToLabel(TabType type) private ReadOnlySpan<byte> ToLabel(TabType type)

View file

@ -119,4 +119,4 @@ public static class UiHelpers
(true, false) => (true, false), (true, false) => (true, false),
(false, true) => (false, true), (false, true) => (false, true),
}; };
} }

View file

@ -138,7 +138,8 @@ public static class ServiceManager
.AddSingleton<SetSelector>() .AddSingleton<SetSelector>()
.AddSingleton<SetPanel>() .AddSingleton<SetPanel>()
.AddSingleton<IdentifierDrawer>() .AddSingleton<IdentifierDrawer>()
.AddSingleton<GlamourerChangelog>(); .AddSingleton<GlamourerChangelog>()
.AddSingleton<ConvenienceRevertButtons>();
private static IServiceCollection AddApi(this IServiceCollection services) private static IServiceCollection AddApi(this IServiceCollection services)
=> services.AddSingleton<CommandService>() => services.AddSingleton<CommandService>()