Let left- and right-clicks on equip icons behave as on the combo.

This commit is contained in:
Ottermandias 2023-08-04 02:13:48 +02:00
parent 59284157c6
commit a2eb6ccc1f
2 changed files with 32 additions and 11 deletions

View file

@ -170,7 +170,7 @@ public class EquipmentDrawer
"Change the visibility of the characters weapons when not drawn: Hidden, Visible or Don't Apply.", currentValue, currentApply, "Change the visibility of the characters weapons when not drawn: Hidden, Visible or Don't Apply.", currentValue, currentApply,
out newValue, out newApply, locked); out newValue, out newApply, locked);
private bool DrawMainhand(EquipItem current, bool drawAll, out EquipItem weapon, out string label, bool locked, bool small) private bool DrawMainhand(EquipItem current, bool drawAll, out EquipItem weapon, out string label, bool locked, bool small, bool open)
{ {
weapon = current; weapon = current;
if (!_weaponCombo.TryGetValue(drawAll ? FullEquipType.Unknown : current.Type, out var combo)) if (!_weaponCombo.TryGetValue(drawAll ? FullEquipType.Unknown : current.Type, out var combo))
@ -181,6 +181,8 @@ public class EquipmentDrawer
label = combo.Label; label = combo.Label;
using var disabled = ImRaii.Disabled(locked); using var disabled = ImRaii.Disabled(locked);
if (!locked && open)
UiHelpers.OpenCombo($"##{combo.Label}");
if (!combo.Draw(weapon.Name, weapon.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, _requiredComboWidth)) if (!combo.Draw(weapon.Name, weapon.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, _requiredComboWidth))
return false; return false;
@ -188,7 +190,7 @@ public class EquipmentDrawer
return true; return true;
} }
private bool DrawOffhand(EquipItem mainhand, EquipItem current, out EquipItem weapon, out string label, bool locked, bool small) private bool DrawOffhand(EquipItem mainhand, EquipItem current, out EquipItem weapon, out string label, bool locked, bool small, bool clear, bool open)
{ {
weapon = current; weapon = current;
if (!_weaponCombo.TryGetValue(current.Type, out var combo)) if (!_weaponCombo.TryGetValue(current.Type, out var combo))
@ -199,6 +201,8 @@ public class EquipmentDrawer
label = combo.Label; label = combo.Label;
using var disabled = ImRaii.Disabled(locked); using var disabled = ImRaii.Disabled(locked);
if (!locked && open)
UiHelpers.OpenCombo($"##{combo.Label}");
var change = combo.Draw(weapon.Name, weapon.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, _requiredComboWidth); var change = combo.Draw(weapon.Name, weapon.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, _requiredComboWidth);
if (change) if (change)
weapon = combo.CurrentSelection; weapon = combo.CurrentSelection;
@ -209,7 +213,7 @@ public class EquipmentDrawer
if (defaultOffhand.Id != weapon.Id) if (defaultOffhand.Id != weapon.Id)
{ {
ImGuiUtil.HoverTooltip("Right-click to set to Default."); ImGuiUtil.HoverTooltip("Right-click to set to Default.");
if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) if (clear || ImGui.IsItemClicked(ImGuiMouseButton.Right))
{ {
change = true; change = true;
weapon = defaultOffhand; weapon = defaultOffhand;
@ -228,12 +232,15 @@ public class EquipmentDrawer
=> UiHelpers.DrawCheckbox($"##applyStain{slot}", "Apply this dye when applying the Design.", flags.HasFlag(slot.ToStainFlag()), => UiHelpers.DrawCheckbox($"##applyStain{slot}", "Apply this dye when applying the Design.", flags.HasFlag(slot.ToStainFlag()),
out enabled, locked); out enabled, locked);
private bool DrawItem(EquipSlot slot, EquipItem current, out EquipItem armor, out string label, bool locked, bool small) private bool DrawItem(EquipSlot slot, EquipItem current, out EquipItem armor, out string label, bool locked, bool small, bool clear, bool open)
{ {
Debug.Assert(slot.IsEquipment() || slot.IsAccessory(), $"Called {nameof(DrawItem)} on {slot}."); Debug.Assert(slot.IsEquipment() || slot.IsAccessory(), $"Called {nameof(DrawItem)} on {slot}.");
var combo = _itemCombo[slot.ToIndex()]; var combo = _itemCombo[slot.ToIndex()];
label = combo.Label; label = combo.Label;
armor = current; armor = current;
if(!locked && open)
UiHelpers.OpenCombo($"##{combo.Label}");
using var disabled = ImRaii.Disabled(locked); using var disabled = ImRaii.Disabled(locked);
var change = combo.Draw(armor.Name, armor.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, _requiredComboWidth); var change = combo.Draw(armor.Name, armor.ItemId, small ? _comboLength - ImGui.GetFrameHeight() : _comboLength, _requiredComboWidth);
if (change) if (change)
@ -242,7 +249,7 @@ public class EquipmentDrawer
if (!locked && armor.ModelId.Id != 0) if (!locked && armor.ModelId.Id != 0)
{ {
ImGuiUtil.HoverTooltip("Right-click to clear."); ImGuiUtil.HoverTooltip("Right-click to clear.");
if (ImGui.IsItemClicked(ImGuiMouseButton.Right)) if (clear || ImGui.IsItemClicked(ImGuiMouseButton.Right))
{ {
change = true; change = true;
armor = ItemManager.NothingItem(slot); armor = ItemManager.NothingItem(slot);
@ -365,7 +372,7 @@ public class EquipmentDrawer
if (DrawStain(slot, cStain, out rStain, locked, true)) if (DrawStain(slot, cStain, out rStain, locked, true))
changes |= DataChange.Stain; changes |= DataChange.Stain;
ImGui.SameLine(); ImGui.SameLine();
if (DrawItem(slot, cArmor, out rArmor, out var label, locked, true)) if (DrawItem(slot, cArmor, out rArmor, out var label, locked, true, false, false))
changes |= DataChange.Item; changes |= DataChange.Item;
if (cApply.HasValue) if (cApply.HasValue)
{ {
@ -396,9 +403,11 @@ public class EquipmentDrawer
{ {
var changes = DataChange.None; var changes = DataChange.None;
cArmor.DrawIcon(_textures, _iconSize); cArmor.DrawIcon(_textures, _iconSize);
var right = ImGui.IsItemClicked(ImGuiMouseButton.Right);
var left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();
using var group = ImRaii.Group(); using var group = ImRaii.Group();
if (DrawItem(slot, cArmor, out rArmor, out var label, locked, false)) if (DrawItem(slot, cArmor, out rArmor, out var label, locked, false, right, left))
changes |= DataChange.Item; changes |= DataChange.Item;
if (cApply.HasValue) if (cApply.HasValue)
{ {
@ -446,7 +455,7 @@ public class EquipmentDrawer
ImGui.SameLine(); ImGui.SameLine();
rOffhand = cOffhand; rOffhand = cOffhand;
if (DrawMainhand(cMainhand, allWeapons, out rMainhand, out var mainhandLabel, locked, true)) if (DrawMainhand(cMainhand, allWeapons, out rMainhand, out var mainhandLabel, locked, true, false))
{ {
changes |= DataChange.Item; changes |= DataChange.Item;
if (rMainhand.Type.ValidOffhand() != cMainhand.Type.ValidOffhand()) if (rMainhand.Type.ValidOffhand() != cMainhand.Type.ValidOffhand())
@ -485,7 +494,7 @@ public class EquipmentDrawer
changes |= DataChange.Stain2; changes |= DataChange.Stain2;
ImGui.SameLine(); ImGui.SameLine();
if (DrawOffhand(rMainhand, rOffhand, out rOffhand, out var offhandLabel, locked, true)) if (DrawOffhand(rMainhand, rOffhand, out rOffhand, out var offhandLabel, locked, true, false, false))
changes |= DataChange.Item2; changes |= DataChange.Item2;
if (cApply.HasValue) if (cApply.HasValue)
{ {
@ -519,11 +528,12 @@ public class EquipmentDrawer
ImGui.GetStyle().ItemInnerSpacing with { Y = ImGui.GetStyle().ItemSpacing.Y }); ImGui.GetStyle().ItemInnerSpacing with { Y = ImGui.GetStyle().ItemSpacing.Y });
cMainhand.DrawIcon(_textures, _iconSize); cMainhand.DrawIcon(_textures, _iconSize);
var left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();
using (var group = ImRaii.Group()) using (var group = ImRaii.Group())
{ {
rOffhand = cOffhand; rOffhand = cOffhand;
if (DrawMainhand(cMainhand, allWeapons, out rMainhand, out var mainhandLabel, locked, false)) if (DrawMainhand(cMainhand, allWeapons, out rMainhand, out var mainhandLabel, locked, false, left))
{ {
changes |= DataChange.Item; changes |= DataChange.Item;
if (rMainhand.Type.ValidOffhand() != cMainhand.Type.ValidOffhand()) if (rMainhand.Type.ValidOffhand() != cMainhand.Type.ValidOffhand())
@ -570,10 +580,12 @@ public class EquipmentDrawer
} }
rOffhand.DrawIcon(_textures, _iconSize); rOffhand.DrawIcon(_textures, _iconSize);
var right = ImGui.IsItemClicked(ImGuiMouseButton.Right);
left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();
using (var group = ImRaii.Group()) using (var group = ImRaii.Group())
{ {
if (DrawOffhand(rMainhand, rOffhand, out rOffhand, out var offhandLabel, locked, false)) if (DrawOffhand(rMainhand, rOffhand, out rOffhand, out var offhandLabel, locked, false, right, left))
changes |= DataChange.Item2; changes |= DataChange.Item2;
if (cApply.HasValue) if (cApply.HasValue)
{ {

View file

@ -3,6 +3,7 @@ using System.Numerics;
using Dalamud.Interface; using Dalamud.Interface;
using Glamourer.Services; using Glamourer.Services;
using ImGuiNET; using ImGuiNET;
using Lumina.Misc;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;
@ -25,6 +26,14 @@ public enum DataChange : byte
public static class UiHelpers public static class UiHelpers
{ {
/// <summary> Open a combo popup with another method than the combo itself. </summary>
public static void OpenCombo(string comboLabel)
{
var windowId = ImGui.GetID(comboLabel);
var popupId = ~Crc32.Get("##ComboPopup", windowId);
ImGui.OpenPopup(popupId);
}
public static void DrawIcon(this EquipItem item, TextureService textures, Vector2 size) public static void DrawIcon(this EquipItem item, TextureService textures, Vector2 size)
{ {
var isEmpty = item.ModelId.Id == 0; var isEmpty = item.ModelId.Id == 0;