Fix some weapon display stuff.

This commit is contained in:
Ottermandias 2023-09-23 03:18:21 +02:00
parent ffa1eadfd4
commit 16d4cedbf2
3 changed files with 24 additions and 16 deletions

View file

@ -6,6 +6,7 @@ using System.Numerics;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Events;
using Glamourer.Services; using Glamourer.Services;
using Glamourer.Structs; using Glamourer.Structs;
using ImGuiNET; using ImGuiNET;
@ -30,16 +31,19 @@ public class EquipmentDrawer
private readonly CodeService _codes; private readonly CodeService _codes;
private readonly TextureService _textures; private readonly TextureService _textures;
private readonly Configuration _config; private readonly Configuration _config;
private readonly GPoseService _gPose;
private float _requiredComboWidthUnscaled; private float _requiredComboWidthUnscaled;
private float _requiredComboWidth; private float _requiredComboWidth;
public EquipmentDrawer(IDataManager gameData, ItemManager items, CodeService codes, TextureService textures, Configuration config) public EquipmentDrawer(IDataManager gameData, ItemManager items, CodeService codes, TextureService textures, Configuration config,
GPoseService gPose)
{ {
_items = items; _items = items;
_codes = codes; _codes = codes;
_textures = textures; _textures = textures;
_config = config; _config = config;
_gPose = gPose;
_stainData = items.Stains; _stainData = items.Stains;
_stainCombo = new FilterComboColors(DefaultWidth - 20, _stainCombo = new FilterComboColors(DefaultWidth - 20,
_stainData.Data.Prepend(new KeyValuePair<byte, (string Name, uint Dye, bool Gloss)>(0, ("None", 0, false)))); _stainData.Data.Prepend(new KeyValuePair<byte, (string Name, uint Dye, bool Gloss)>(0, ("None", 0, false))));
@ -184,7 +188,8 @@ public class EquipmentDrawer
} }
label = combo.Label; label = combo.Label;
using var disabled = ImRaii.Disabled(locked); locked |= !_gPose.InGPose && current.Type is FullEquipType.Unknown;
using var disabled = ImRaii.Disabled(locked );
if (!locked && open) if (!locked && open)
UiHelpers.OpenCombo($"##{combo.Label}"); 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))
@ -205,6 +210,7 @@ public class EquipmentDrawer
} }
label = combo.Label; label = combo.Label;
locked |= !_gPose.InGPose && (current.Type is FullEquipType.Unknown || mainhand.Type is FullEquipType.Unknown);
using var disabled = ImRaii.Disabled(locked); using var disabled = ImRaii.Disabled(locked);
if (!locked && open) if (!locked && open)
UiHelpers.OpenCombo($"##{combo.Label}"); UiHelpers.OpenCombo($"##{combo.Label}");
@ -435,7 +441,7 @@ public class EquipmentDrawer
EquipFlag? cApply, out bool rApply, out bool rApplyStain, bool locked, Gender gender, Race race) EquipFlag? cApply, out bool rApply, out bool rApplyStain, bool locked, Gender gender, Race race)
{ {
var changes = DataChange.None; var changes = DataChange.None;
cArmor.DrawIcon(_textures, _iconSize); cArmor.DrawIcon(_textures, _iconSize, slot);
var right = ImGui.IsItemClicked(ImGuiMouseButton.Right); var right = ImGui.IsItemClicked(ImGuiMouseButton.Right);
var left = ImGui.IsItemClicked(ImGuiMouseButton.Left); var left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();
@ -560,7 +566,7 @@ public class EquipmentDrawer
using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing,
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, EquipSlot.MainHand);
var left = ImGui.IsItemClicked(ImGuiMouseButton.Left); var left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();
using (var group = ImRaii.Group()) using (var group = ImRaii.Group())
@ -612,7 +618,7 @@ public class EquipmentDrawer
return changes; return changes;
} }
rOffhand.DrawIcon(_textures, _iconSize); rOffhand.DrawIcon(_textures, _iconSize, EquipSlot.OffHand);
var right = ImGui.IsItemClicked(ImGuiMouseButton.Right); var right = ImGui.IsItemClicked(ImGuiMouseButton.Right);
left = ImGui.IsItemClicked(ImGuiMouseButton.Left); left = ImGui.IsItemClicked(ImGuiMouseButton.Left);
ImGui.SameLine(); ImGui.SameLine();

View file

@ -6,6 +6,7 @@ using ImGuiNET;
using Lumina.Misc; using Lumina.Misc;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;
namespace Glamourer.Gui; namespace Glamourer.Gui;
@ -34,18 +35,19 @@ public static class UiHelpers
ImGui.OpenPopup(popupId); 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, EquipSlot slot)
{ {
var isEmpty = item.ModelId.Id == 0; var isEmpty = item.ModelId.Id == 0;
var (ptr, textureSize, empty) = textures.GetIcon(item); var (ptr, textureSize, empty) = textures.GetIcon(item, slot);
if (empty) if (empty)
{ {
var (bgColor, tint) = isEmpty
? (ImGui.GetColorU32(ImGuiCol.FrameBg), new Vector4(0.1f, 0.1f, 0.1f, 0.5f))
: (ImGui.GetColorU32(ImGuiCol.FrameBgActive), new Vector4(0.3f, 0.3f, 0.3f, 0.8f));
var pos = ImGui.GetCursorScreenPos(); var pos = ImGui.GetCursorScreenPos();
ImGui.GetWindowDrawList().AddRectFilled(pos, pos + size, ImGui.GetWindowDrawList().AddRectFilled(pos, pos + size, bgColor, 5 * ImGuiHelpers.GlobalScale);
ImGui.GetColorU32(isEmpty ? ImGuiCol.FrameBg : ImGuiCol.FrameBgActive), 5 * ImGuiHelpers.GlobalScale);
if (ptr != nint.Zero) if (ptr != nint.Zero)
ImGui.Image(ptr, size, Vector2.Zero, Vector2.One, ImGui.Image(ptr, size, Vector2.Zero, Vector2.One, tint);
isEmpty ? new Vector4(0.1f, 0.1f, 0.1f, 0.5f) : new Vector4(0.3f, 0.3f, 0.3f, 0.8f));
else else
ImGui.Dummy(size); ImGui.Dummy(size);
} }

View file

@ -18,12 +18,12 @@ public sealed class TextureService : TextureCache, IDisposable
private readonly TextureWrap?[] _slotIcons; private readonly TextureWrap?[] _slotIcons;
public (nint, Vector2, bool) GetIcon(EquipItem item) public (nint, Vector2, bool) GetIcon(EquipItem item, EquipSlot slot)
{ {
if (item.IconId.Id != 0 && TryLoadIcon(item.IconId.Id, out var ret)) if (item.IconId.Id != 0 && TryLoadIcon(item.IconId.Id, out var ret))
return (ret.ImGuiHandle, new Vector2(ret.Width, ret.Height), false); return (ret.ImGuiHandle, new Vector2(ret.Width, ret.Height), false);
var idx = item.Type.ToSlot().ToIndex(); var idx = slot.ToIndex();
return idx < 12 && _slotIcons[idx] != null return idx < 12 && _slotIcons[idx] != null
? (_slotIcons[idx]!.ImGuiHandle, new Vector2(_slotIcons[idx]!.Width, _slotIcons[idx]!.Height), true) ? (_slotIcons[idx]!.ImGuiHandle, new Vector2(_slotIcons[idx]!.Width, _slotIcons[idx]!.Height), true)
: (nint.Zero, Vector2.Zero, true); : (nint.Zero, Vector2.Zero, true);
@ -59,7 +59,7 @@ public sealed class TextureService : TextureCache, IDisposable
ret[6] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 9)!; ret[6] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 9)!;
ret[7] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 10)!; ret[7] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 10)!;
ret[8] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 11)!; ret[8] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 11)!;
ret[9] = ret[10]; ret[9] = ret[8];
ret[10] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 0)!; ret[10] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 0)!;
ret[11] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 7)!; ret[11] = uldWrapper.LoadTexturePart("ui/uld/ArmouryBoard_hr1.tex", 7)!;