mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Add buttons to tab bar rhs to revert self.
This commit is contained in:
parent
49768e797d
commit
3b618a08bc
4 changed files with 88 additions and 20 deletions
62
Glamourer/Gui/ConvenienceRevertButtons.cs
Normal file
62
Glamourer/Gui/ConvenienceRevertButtons.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<byte> ToLabel(TabType type)
|
||||
|
|
|
|||
|
|
@ -119,4 +119,4 @@ public static class UiHelpers
|
|||
(true, false) => (true, false),
|
||||
(false, true) => (false, true),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -138,7 +138,8 @@ public static class ServiceManager
|
|||
.AddSingleton<SetSelector>()
|
||||
.AddSingleton<SetPanel>()
|
||||
.AddSingleton<IdentifierDrawer>()
|
||||
.AddSingleton<GlamourerChangelog>();
|
||||
.AddSingleton<GlamourerChangelog>()
|
||||
.AddSingleton<ConvenienceRevertButtons>();
|
||||
|
||||
private static IServiceCollection AddApi(this IServiceCollection services)
|
||||
=> services.AddSingleton<CommandService>()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue