From bb671e8dd23ec761ef8f96062feb11abcbdd4d4f Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 9 Jan 2024 16:54:43 +0100 Subject: [PATCH] Add revert options to equip. --- Glamourer/GameData/CustomizeParameterValue.cs | 3 + Glamourer/Gui/Equipment/EquipDrawData.cs | 14 +++- Glamourer/Gui/Equipment/EquipmentDrawer.cs | 73 ++++++++++++------- Penumbra.GameData | 2 +- 4 files changed, 59 insertions(+), 33 deletions(-) diff --git a/Glamourer/GameData/CustomizeParameterValue.cs b/Glamourer/GameData/CustomizeParameterValue.cs index 74cf666..fc3e28d 100644 --- a/Glamourer/GameData/CustomizeParameterValue.cs +++ b/Glamourer/GameData/CustomizeParameterValue.cs @@ -44,4 +44,7 @@ public readonly struct CustomizeParameterValue public float this[int idx] => _data[idx]; + + public override string ToString() + => _data.ToString(); } diff --git a/Glamourer/Gui/Equipment/EquipDrawData.cs b/Glamourer/Gui/Equipment/EquipDrawData.cs index 2a902c8..57da890 100644 --- a/Glamourer/Gui/Equipment/EquipDrawData.cs +++ b/Glamourer/Gui/Equipment/EquipDrawData.cs @@ -1,6 +1,6 @@ -using Glamourer.Designs; +using Dalamud.Game.Inventory; +using Glamourer.Designs; using Glamourer.Events; -using Glamourer.Services; using Glamourer.State; using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; @@ -12,6 +12,7 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData) public readonly EquipSlot Slot = slot; public bool Locked; public bool DisplayApplication; + public bool AllowRevert; public Action ItemSetter = null!; public Action StainSetter = null!; @@ -19,6 +20,8 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData) public Action ApplyStainSetter = null!; public EquipItem CurrentItem = designData.Item(slot); public StainId CurrentStain = designData.Stain(slot); + public EquipItem GameItem = default; + public StainId GameStain = default; public bool CurrentApply; public bool CurrentApplyStain; @@ -28,8 +31,8 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData) public static EquipDrawData FromDesign(DesignManager manager, Design design, EquipSlot slot) => new(slot, design.DesignData) { - ItemSetter = slot.IsEquipment() || slot.IsAccessory() - ? i => manager.ChangeEquip(design, slot, i) + ItemSetter = slot.IsEquipment() || slot.IsAccessory() + ? i => manager.ChangeEquip(design, slot, i) : i => manager.ChangeWeapon(design, slot, i), StainSetter = i => manager.ChangeStain(design, slot, i), ApplySetter = b => manager.ChangeApplyEquip(design, slot, b), @@ -47,5 +50,8 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData) StainSetter = i => manager.ChangeStain(state, slot, i, StateChanged.Source.Manual), Locked = state.IsLocked, DisplayApplication = false, + GameItem = state.BaseData.Item(slot), + GameStain = state.BaseData.Stain(slot), + AllowRevert = true, }; } diff --git a/Glamourer/Gui/Equipment/EquipmentDrawer.cs b/Glamourer/Gui/Equipment/EquipmentDrawer.cs index 5910929..22f40d7 100644 --- a/Glamourer/Gui/Equipment/EquipmentDrawer.cs +++ b/Glamourer/Gui/Equipment/EquipmentDrawer.cs @@ -19,7 +19,7 @@ public class EquipmentDrawer private readonly ItemManager _items; private readonly GlamourerColorCombo _stainCombo; - private readonly DictStain _stainData; + private readonly DictStain _stainData; private readonly ItemCombo[] _itemCombo; private readonly Dictionary _weaponCombo; private readonly CodeService _codes; @@ -424,13 +424,8 @@ public class EquipmentDrawer else if (_stainCombo.CurrentSelection.Key == Stain.None.RowIndex) data.StainSetter(Stain.None.RowIndex); - if (!data.Locked && data.CurrentStain != Stain.None.RowIndex) - { - if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) - data.StainSetter(Stain.None.RowIndex); - - ImGuiUtil.HoverTooltip("Right-click to clear."); - } + if (ResetOrClear(data.Locked, false, data.AllowRevert, true, data.CurrentStain, data.GameStain, Stain.None.RowIndex, out var id)) + data.StainSetter(Stain.None.RowIndex); } private void DrawItem(in EquipDrawData data, out string label, bool small, bool clear, bool open) @@ -450,13 +445,35 @@ public class EquipmentDrawer else if (combo.CustomVariant.Id > 0) data.ItemSetter(_items.Identify(data.Slot, combo.CustomSetId, combo.CustomVariant)); - if (!data.Locked && data.CurrentItem.PrimaryId.Id != 0) - { - if (clear || ImGui.IsItemClicked(ImGuiMouseButton.Right)) - data.ItemSetter(ItemManager.NothingItem(data.Slot)); + if (ResetOrClear(data.Locked, clear, data.AllowRevert, true, data.CurrentItem, data.GameItem, ItemManager.NothingItem(data.Slot), + out var item)) + data.ItemSetter(item); + } - ImGuiUtil.HoverTooltip("Right-click to clear."); + private static bool ResetOrClear(bool locked, bool clicked, bool allowRevert, bool allowClear, + in T currentItem, in T revertItem, in T clearItem, out T? item) where T : IEquatable + { + if (locked) + { + item = default; + return false; } + + clicked = clicked || ImGui.IsItemClicked(ImGuiMouseButton.Right); + + (var tt, item, var valid) = (allowRevert && !revertItem.Equals(currentItem), allowClear && !clearItem.Equals(currentItem), + ImGui.GetIO().KeyCtrl) switch + { + (true, true, true) => ("Right-click to clear. Control and Right-Click to revert to game.", revertItem, true), + (true, true, false) => ("Right-click to clear. Control and Right-Click to revert to game.", clearItem, true), + (true, false, true) => ("Control and Right-Click to revert to game.", revertItem, true), + (true, false, false) => ("Control and Right-Click to revert to game.", (T?)default, false), + (false, true, _) => ("Right-click to clear.", clearItem, true), + (false, false, _) => (string.Empty, (T?)default, false), + }; + ImGuiUtil.HoverTooltip(tt); + + return clicked && valid; } private void DrawMainhand(ref EquipDrawData mainhand, ref EquipDrawData offhand, out string label, bool drawAll, bool small, @@ -469,23 +486,30 @@ public class EquipmentDrawer } label = combo.Label; - var unknown = !_gPose.InGPose && mainhand.CurrentItem.Type is FullEquipType.Unknown; - using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemInnerSpacing); + var unknown = !_gPose.InGPose && mainhand.CurrentItem.Type is FullEquipType.Unknown; + using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemInnerSpacing); + EquipItem? changedItem = null; using (var _ = ImRaii.Disabled(mainhand.Locked | unknown)) { if (!mainhand.Locked && open) UiHelpers.OpenCombo($"##{label}"); if (combo.Draw(mainhand.CurrentItem.Name, mainhand.CurrentItem.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, _requiredComboWidth)) + changedItem = combo.CurrentSelection; + else if (ResetOrClear(mainhand.Locked || unknown, open, mainhand.AllowRevert, false, mainhand.CurrentItem, mainhand.GameItem, + default, out var c)) + changedItem = c; + + if (changedItem != null) { - mainhand.ItemSetter(combo.CurrentSelection); - if (combo.CurrentSelection.Type.ValidOffhand() != mainhand.CurrentItem.Type.ValidOffhand()) + mainhand.ItemSetter(changedItem.Value); + if (changedItem.Value.Type.ValidOffhand() != mainhand.CurrentItem.Type.ValidOffhand()) { - offhand.CurrentItem = _items.GetDefaultOffhand(combo.CurrentSelection); + offhand.CurrentItem = _items.GetDefaultOffhand(changedItem.Value); offhand.ItemSetter(offhand.CurrentItem); } - mainhand.CurrentItem = combo.CurrentSelection; + mainhand.CurrentItem = changedItem.Value; } } @@ -511,16 +535,9 @@ public class EquipmentDrawer _requiredComboWidth)) offhand.ItemSetter(combo.CurrentSelection); - if (locked) - return; - var defaultOffhand = _items.GetDefaultOffhand(mainhand.CurrentItem); - if (defaultOffhand.Id == offhand.CurrentItem.Id) - return; - - ImGuiUtil.HoverTooltip("Right-click to set to Default."); - if (clear || ImGui.IsItemClicked(ImGuiMouseButton.Right)) - offhand.ItemSetter(defaultOffhand); + if (ResetOrClear(locked, open, offhand.AllowRevert, true, offhand.CurrentItem, offhand.GameItem, defaultOffhand, out var item)) + offhand.ItemSetter(item); } private static void DrawApply(in EquipDrawData data) diff --git a/Penumbra.GameData b/Penumbra.GameData index 55535b4..f68b6ee 160000 --- a/Penumbra.GameData +++ b/Penumbra.GameData @@ -1 +1 @@ -Subproject commit 55535b445f51f09ada75d2803484025bb51cca01 +Subproject commit f68b6eee157bc2016e1cb7d5ffac491b287b13a8