mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-13 12:14:18 +01:00
Add revert options to equip.
This commit is contained in:
parent
5ea779a34c
commit
bb671e8dd2
4 changed files with 59 additions and 33 deletions
|
|
@ -44,4 +44,7 @@ public readonly struct CustomizeParameterValue
|
||||||
|
|
||||||
public float this[int idx]
|
public float this[int idx]
|
||||||
=> _data[idx];
|
=> _data[idx];
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
=> _data.ToString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Glamourer.Designs;
|
using Dalamud.Game.Inventory;
|
||||||
|
using Glamourer.Designs;
|
||||||
using Glamourer.Events;
|
using Glamourer.Events;
|
||||||
using Glamourer.Services;
|
|
||||||
using Glamourer.State;
|
using Glamourer.State;
|
||||||
using Penumbra.GameData.Enums;
|
using Penumbra.GameData.Enums;
|
||||||
using Penumbra.GameData.Structs;
|
using Penumbra.GameData.Structs;
|
||||||
|
|
@ -12,6 +12,7 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData)
|
||||||
public readonly EquipSlot Slot = slot;
|
public readonly EquipSlot Slot = slot;
|
||||||
public bool Locked;
|
public bool Locked;
|
||||||
public bool DisplayApplication;
|
public bool DisplayApplication;
|
||||||
|
public bool AllowRevert;
|
||||||
|
|
||||||
public Action<EquipItem> ItemSetter = null!;
|
public Action<EquipItem> ItemSetter = null!;
|
||||||
public Action<StainId> StainSetter = null!;
|
public Action<StainId> StainSetter = null!;
|
||||||
|
|
@ -19,6 +20,8 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData)
|
||||||
public Action<bool> ApplyStainSetter = null!;
|
public Action<bool> ApplyStainSetter = null!;
|
||||||
public EquipItem CurrentItem = designData.Item(slot);
|
public EquipItem CurrentItem = designData.Item(slot);
|
||||||
public StainId CurrentStain = designData.Stain(slot);
|
public StainId CurrentStain = designData.Stain(slot);
|
||||||
|
public EquipItem GameItem = default;
|
||||||
|
public StainId GameStain = default;
|
||||||
public bool CurrentApply;
|
public bool CurrentApply;
|
||||||
public bool CurrentApplyStain;
|
public bool CurrentApplyStain;
|
||||||
|
|
||||||
|
|
@ -47,5 +50,8 @@ public ref struct EquipDrawData(EquipSlot slot, in DesignData designData)
|
||||||
StainSetter = i => manager.ChangeStain(state, slot, i, StateChanged.Source.Manual),
|
StainSetter = i => manager.ChangeStain(state, slot, i, StateChanged.Source.Manual),
|
||||||
Locked = state.IsLocked,
|
Locked = state.IsLocked,
|
||||||
DisplayApplication = false,
|
DisplayApplication = false,
|
||||||
|
GameItem = state.BaseData.Item(slot),
|
||||||
|
GameStain = state.BaseData.Stain(slot),
|
||||||
|
AllowRevert = true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -424,13 +424,8 @@ public class EquipmentDrawer
|
||||||
else if (_stainCombo.CurrentSelection.Key == Stain.None.RowIndex)
|
else if (_stainCombo.CurrentSelection.Key == Stain.None.RowIndex)
|
||||||
data.StainSetter(Stain.None.RowIndex);
|
data.StainSetter(Stain.None.RowIndex);
|
||||||
|
|
||||||
if (!data.Locked && data.CurrentStain != Stain.None.RowIndex)
|
if (ResetOrClear(data.Locked, false, data.AllowRevert, true, data.CurrentStain, data.GameStain, Stain.None.RowIndex, out var id))
|
||||||
{
|
|
||||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Right))
|
|
||||||
data.StainSetter(Stain.None.RowIndex);
|
data.StainSetter(Stain.None.RowIndex);
|
||||||
|
|
||||||
ImGuiUtil.HoverTooltip("Right-click to clear.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawItem(in EquipDrawData data, out string label, bool small, bool clear, bool open)
|
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)
|
else if (combo.CustomVariant.Id > 0)
|
||||||
data.ItemSetter(_items.Identify(data.Slot, combo.CustomSetId, combo.CustomVariant));
|
data.ItemSetter(_items.Identify(data.Slot, combo.CustomSetId, combo.CustomVariant));
|
||||||
|
|
||||||
if (!data.Locked && data.CurrentItem.PrimaryId.Id != 0)
|
if (ResetOrClear(data.Locked, clear, data.AllowRevert, true, data.CurrentItem, data.GameItem, ItemManager.NothingItem(data.Slot),
|
||||||
{
|
out var item))
|
||||||
if (clear || ImGui.IsItemClicked(ImGuiMouseButton.Right))
|
data.ItemSetter(item);
|
||||||
data.ItemSetter(ItemManager.NothingItem(data.Slot));
|
|
||||||
|
|
||||||
ImGuiUtil.HoverTooltip("Right-click to clear.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool ResetOrClear<T>(bool locked, bool clicked, bool allowRevert, bool allowClear,
|
||||||
|
in T currentItem, in T revertItem, in T clearItem, out T? item) where T : IEquatable<T>
|
||||||
|
{
|
||||||
|
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,
|
private void DrawMainhand(ref EquipDrawData mainhand, ref EquipDrawData offhand, out string label, bool drawAll, bool small,
|
||||||
|
|
@ -471,21 +488,28 @@ public class EquipmentDrawer
|
||||||
label = combo.Label;
|
label = combo.Label;
|
||||||
var unknown = !_gPose.InGPose && mainhand.CurrentItem.Type is FullEquipType.Unknown;
|
var unknown = !_gPose.InGPose && mainhand.CurrentItem.Type is FullEquipType.Unknown;
|
||||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemInnerSpacing);
|
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemInnerSpacing);
|
||||||
|
EquipItem? changedItem = null;
|
||||||
using (var _ = ImRaii.Disabled(mainhand.Locked | unknown))
|
using (var _ = ImRaii.Disabled(mainhand.Locked | unknown))
|
||||||
{
|
{
|
||||||
if (!mainhand.Locked && open)
|
if (!mainhand.Locked && open)
|
||||||
UiHelpers.OpenCombo($"##{label}");
|
UiHelpers.OpenCombo($"##{label}");
|
||||||
if (combo.Draw(mainhand.CurrentItem.Name, mainhand.CurrentItem.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength,
|
if (combo.Draw(mainhand.CurrentItem.Name, mainhand.CurrentItem.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength,
|
||||||
_requiredComboWidth))
|
_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);
|
mainhand.ItemSetter(changedItem.Value);
|
||||||
if (combo.CurrentSelection.Type.ValidOffhand() != mainhand.CurrentItem.Type.ValidOffhand())
|
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);
|
offhand.ItemSetter(offhand.CurrentItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
mainhand.CurrentItem = combo.CurrentSelection;
|
mainhand.CurrentItem = changedItem.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -511,16 +535,9 @@ public class EquipmentDrawer
|
||||||
_requiredComboWidth))
|
_requiredComboWidth))
|
||||||
offhand.ItemSetter(combo.CurrentSelection);
|
offhand.ItemSetter(combo.CurrentSelection);
|
||||||
|
|
||||||
if (locked)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var defaultOffhand = _items.GetDefaultOffhand(mainhand.CurrentItem);
|
var defaultOffhand = _items.GetDefaultOffhand(mainhand.CurrentItem);
|
||||||
if (defaultOffhand.Id == offhand.CurrentItem.Id)
|
if (ResetOrClear(locked, open, offhand.AllowRevert, true, offhand.CurrentItem, offhand.GameItem, defaultOffhand, out var item))
|
||||||
return;
|
offhand.ItemSetter(item);
|
||||||
|
|
||||||
ImGuiUtil.HoverTooltip("Right-click to set to Default.");
|
|
||||||
if (clear || ImGui.IsItemClicked(ImGuiMouseButton.Right))
|
|
||||||
offhand.ItemSetter(defaultOffhand);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawApply(in EquipDrawData data)
|
private static void DrawApply(in EquipDrawData data)
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 55535b445f51f09ada75d2803484025bb51cca01
|
Subproject commit f68b6eee157bc2016e1cb7d5ffac491b287b13a8
|
||||||
Loading…
Add table
Add a link
Reference in a new issue