mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +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]
|
||||
=> _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.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<EquipItem> ItemSetter = 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 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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<FullEquipType, WeaponCombo> _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<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,
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 55535b445f51f09ada75d2803484025bb51cca01
|
||||
Subproject commit f68b6eee157bc2016e1cb7d5ffac491b287b13a8
|
||||
Loading…
Add table
Add a link
Reference in a new issue