From 519bfffbb2a38b50493388b4ae616f345851e67d Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 14 Jul 2023 14:34:30 +0200 Subject: [PATCH] Change how customization config works a bit. --- .../CustomizationDrawer.Color.cs | 6 ++- .../Customization/CustomizationDrawer.Icon.cs | 42 +++---------------- .../CustomizationDrawer.Simple.cs | 40 +++++++++++++----- .../Gui/Customization/CustomizationDrawer.cs | 7 ++++ Glamourer/Gui/Equipment/EquipmentDrawer.cs | 17 +++++--- 5 files changed, 57 insertions(+), 55 deletions(-) diff --git a/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs b/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs index 8068cbe..200cca6 100644 --- a/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs +++ b/Glamourer/Gui/Customization/CustomizationDrawer.Color.cs @@ -25,6 +25,7 @@ public partial class CustomizationDrawer ImGui.OpenPopup(ColorPickerPopupName); } + var npc = false; if (current < 0) { using var font = ImRaii.PushFont(UiBuilder.IconFont); @@ -32,13 +33,14 @@ public partial class CustomizationDrawer var pos = ImGui.GetItemRectMin() + (ImGui.GetItemRectSize() - size) / 2; ImGui.GetWindowDrawList().AddText(pos, ImGui.GetColorU32(ImGuiCol.Text), FontAwesomeIcon.Question.ToIconString()); current = 0; + npc = true; } ImGui.SameLine(); using (var group = ImRaii.Group()) { - DataInputInt(current); + DataInputInt(current, npc); if (_withApply) { ApplyCheckbox(); @@ -46,7 +48,7 @@ public partial class CustomizationDrawer } ImGui.AlignTextToFramePadding(); - ImGui.TextUnformatted(custom.Color == 0 ? $"{_currentOption} (Custom #{custom.Value})" : _currentOption); + ImGui.TextUnformatted(custom.Color == 0 ? $"{_currentOption} (NPC)" : _currentOption); } DrawColorPickerPopup(); diff --git a/Glamourer/Gui/Customization/CustomizationDrawer.Icon.cs b/Glamourer/Gui/Customization/CustomizationDrawer.Icon.cs index bbf18e5..34a6490 100644 --- a/Glamourer/Gui/Customization/CustomizationDrawer.Icon.cs +++ b/Glamourer/Gui/Customization/CustomizationDrawer.Icon.cs @@ -19,11 +19,13 @@ public partial class CustomizationDrawer var label = _currentOption; var current = _set.DataByValue(index, _currentByte, out var custom, _customize.Face); + var npc = false; if (current < 0) { - label = $"{_currentOption} (Custom #{_customize[index]})"; + label = $"{_currentOption} (NPC)"; current = 0; custom = _set.Data(index, 0); + npc = true; } var icon = _service.AwaitedService.GetIcon(custom!.Value.IconId); @@ -34,10 +36,7 @@ public partial class CustomizationDrawer ImGui.SameLine(); using (var group = ImRaii.Group()) { - if (_currentIndex == CustomizeIndex.Face) - FaceInputInt(current); - else - DataInputInt(current); + DataInputInt(current, npc); if (_withApply) { @@ -45,38 +44,12 @@ public partial class CustomizationDrawer ImGui.SameLine(); } - ImGui.TextUnformatted($"{label} ({custom.Value.Value})"); + ImGui.TextUnformatted(label); } DrawIconPickerPopup(); } - private bool UpdateFace(CustomizeData data) - { - // Hrothgar Hack - var value = _set.Race == Race.Hrothgar ? data.Value + 4 : data.Value; - if (_customize.Face == value) - return false; - - _customize.Face = value; - Changed |= CustomizeFlag.Face; - return true; - } - - private void FaceInputInt(int currentIndex) - { - ++currentIndex; - ImGui.SetNextItemWidth(_inputIntSize); - if (ImGui.InputInt("##text", ref currentIndex, 1, 1)) - { - currentIndex = Math.Clamp(currentIndex - 1, 0, _currentCount - 1); - var data = _set.Data(_currentIndex, currentIndex, _customize.Face); - UpdateFace(data); - } - - ImGuiUtil.HoverTooltip($"Input Range: [1, {_currentCount}]"); - } - private void DrawIconPickerPopup() { using var popup = ImRaii.Popup(IconSelectorPopup, ImGuiWindowFlags.AlwaysAutoResize); @@ -93,10 +66,7 @@ public partial class CustomizationDrawer { if (ImGui.ImageButton(icon.ImGuiHandle, _iconSize)) { - if (_currentIndex == CustomizeIndex.Face) - UpdateFace(custom); - else - UpdateValue(custom.Value); + UpdateValue(custom.Value); ImGui.CloseCurrentPopup(); } diff --git a/Glamourer/Gui/Customization/CustomizationDrawer.Simple.cs b/Glamourer/Gui/Customization/CustomizationDrawer.Simple.cs index 19fb431..e338dc9 100644 --- a/Glamourer/Gui/Customization/CustomizationDrawer.Simple.cs +++ b/Glamourer/Gui/Customization/CustomizationDrawer.Simple.cs @@ -1,8 +1,10 @@ using System; +using System.Numerics; using Glamourer.Customization; using ImGuiNET; using OtterGui; using OtterGui.Raii; +using Penumbra.GameData.Enums; namespace Glamourer.Gui.Customization; @@ -45,18 +47,33 @@ public partial class CustomizationDrawer } // Integral input for an icon- or color based item. - private void DataInputInt(int currentIndex) + private void DataInputInt(int currentIndex, bool npc) { - ++currentIndex; - ImGui.SetNextItemWidth(_inputIntSize); - if (ImGui.InputInt("##text", ref currentIndex, 1, 1)) - { - currentIndex = Math.Clamp(currentIndex - 1, 0, _currentCount - 1); - var data = _set.Data(_currentIndex, currentIndex, _customize.Face); - UpdateValue(data.Value); - } + int value = _currentByte.Value; + // Hrothgar face hack. + if (_currentIndex is CustomizeIndex.Face && _set.Race is Race.Hrothgar) + value -= 4; - ImGuiUtil.HoverTooltip($"Input Range: [1, {_currentCount}]"); + ImGui.SetNextItemWidth(_inputIntSizeNoButtons); + if (ImGui.InputInt("##text", ref value, 0, 0)) + { + var index = _set.DataByValue(_currentIndex, (CustomizeValue)value, out var data, _customize.Face); + if (index >= 0) + UpdateValue(data!.Value.Value); + else if (ImGui.GetIO().KeyCtrl) + UpdateValue((CustomizeValue)value); + } + if (!_withApply) + ImGuiUtil.HoverTooltip("Hold Control to force updates with invalid/unknown options at your own risk."); + + ImGui.SameLine(); + if (ImGuiUtil.DrawDisabledButton("-", new Vector2(ImGui.GetFrameHeight()), "Select the previous available option in order.", + currentIndex <= 0)) + UpdateValue(_set.Data(_currentIndex, currentIndex - 1, _customize.Face).Value); + ImGui.SameLine(); + if (ImGuiUtil.DrawDisabledButton("+", new Vector2(ImGui.GetFrameHeight()), "Select the next available option in order.", + currentIndex >= _currentCount - 1 || npc)) + UpdateValue(_set.Data(_currentIndex, currentIndex + 1, _customize.Face).Value); } private void DrawListSelector(CustomizeIndex index) @@ -109,7 +126,8 @@ public partial class CustomizationDrawer var tmp = _currentByte != CustomizeValue.Zero; if (_withApply) { - switch (UiHelpers.DrawMetaToggle(_currentIndex.ToDefaultName(), string.Empty, tmp, _currentApply, out var newValue, out var newApply, _locked)) + switch (UiHelpers.DrawMetaToggle(_currentIndex.ToDefaultName(), string.Empty, tmp, _currentApply, out var newValue, + out var newApply, _locked)) { case DataChange.Item: ChangeApply = newApply ? ChangeApply | _currentFlag : ChangeApply & ~_currentFlag; diff --git a/Glamourer/Gui/Customization/CustomizationDrawer.cs b/Glamourer/Gui/Customization/CustomizationDrawer.cs index f92d84d..17410ad 100644 --- a/Glamourer/Gui/Customization/CustomizationDrawer.cs +++ b/Glamourer/Gui/Customization/CustomizationDrawer.cs @@ -8,6 +8,7 @@ using Glamourer.Services; using ImGuiNET; using OtterGui; using OtterGui.Raii; +using Penumbra.GameData.Enums; using CustomizeData = Penumbra.GameData.Structs.CustomizeData; namespace Glamourer.Gui.Customization; @@ -42,6 +43,7 @@ public partial class CustomizationDrawer : IDisposable private Vector2 _iconSize; private Vector2 _framedIconSize; private float _inputIntSize; + private float _inputIntSizeNoButtons; private float _comboSelectorSize; private float _raceSelectorWidth; private bool _withApply; @@ -116,6 +118,10 @@ public partial class CustomizationDrawer : IDisposable if (_currentByte == value) return; + // Hrothgar Face Hack. + if (_currentIndex is CustomizeIndex.Face && _set.Race is Race.Hrothgar) + value += 4; + _customize[_currentIndex] = value; Changed |= _currentFlag; } @@ -198,6 +204,7 @@ public partial class CustomizationDrawer : IDisposable _iconSize = new Vector2(ImGui.GetTextLineHeight() * 2 + ImGui.GetStyle().ItemSpacing.Y + 2 * ImGui.GetStyle().FramePadding.Y); _framedIconSize = _iconSize + 2 * ImGui.GetStyle().FramePadding; _inputIntSize = 2 * _framedIconSize.X + 1 * _spacing.X; + _inputIntSizeNoButtons = _inputIntSize - 2 * _spacing.X - 2 * ImGui.GetFrameHeight(); _comboSelectorSize = 4 * _framedIconSize.X + 3 * _spacing.X; _raceSelectorWidth = _inputIntSize + _comboSelectorSize - _framedIconSize.X; } diff --git a/Glamourer/Gui/Equipment/EquipmentDrawer.cs b/Glamourer/Gui/Equipment/EquipmentDrawer.cs index 40bcd9a..02be500 100644 --- a/Glamourer/Gui/Equipment/EquipmentDrawer.cs +++ b/Glamourer/Gui/Equipment/EquipmentDrawer.cs @@ -107,6 +107,7 @@ public class EquipmentDrawer StainId cMainhandStain, out StainId rMainhandStain, StainId cOffhandStain, out StainId rOffhandStain, EquipFlag? cApply, out bool rApplyMainhand, out bool rApplyMainhandStain, out bool rApplyOffhand, out bool rApplyOffhandStain, bool locked) { + var allWeapons = cApply.HasValue; if (_config.HideApplyCheckmarks) cApply = null; @@ -116,10 +117,12 @@ public class EquipmentDrawer if (_config.SmallEquip) return DrawWeaponsSmall(cMainhand, out rMainhand, cOffhand, out rOffhand, cMainhandStain, out rMainhandStain, cOffhandStain, - out rOffhandStain, cApply, out rApplyMainhand, out rApplyMainhandStain, out rApplyOffhand, out rApplyOffhandStain, locked); + out rOffhandStain, cApply, out rApplyMainhand, out rApplyMainhandStain, out rApplyOffhand, out rApplyOffhandStain, locked, + allWeapons); return DrawWeaponsNormal(cMainhand, out rMainhand, cOffhand, out rOffhand, cMainhandStain, out rMainhandStain, cOffhandStain, - out rOffhandStain, cApply, out rApplyMainhand, out rApplyMainhandStain, out rApplyOffhand, out rApplyOffhandStain, locked); + out rOffhandStain, cApply, out rApplyMainhand, out rApplyMainhandStain, out rApplyOffhand, out rApplyOffhandStain, locked, + allWeapons); } public bool DrawHatState(bool currentValue, out bool newValue, bool locked) @@ -408,7 +411,8 @@ public class EquipmentDrawer private DataChange DrawWeaponsSmall(EquipItem cMainhand, out EquipItem rMainhand, EquipItem cOffhand, out EquipItem rOffhand, StainId cMainhandStain, out StainId rMainhandStain, StainId cOffhandStain, out StainId rOffhandStain, EquipFlag? cApply, - out bool rApplyMainhand, out bool rApplyMainhandStain, out bool rApplyOffhand, out bool rApplyOffhandStain, bool locked) + out bool rApplyMainhand, out bool rApplyMainhandStain, out bool rApplyOffhand, out bool rApplyOffhandStain, bool locked, + bool allWeapons) { var changes = DataChange.None; if (DrawStain(EquipSlot.MainHand, cMainhandStain, out rMainhandStain, locked, true)) @@ -416,7 +420,7 @@ public class EquipmentDrawer ImGui.SameLine(); rOffhand = cOffhand; - if (DrawMainhand(cMainhand, cApply.HasValue, out rMainhand, out var mainhandLabel, locked, true)) + if (DrawMainhand(cMainhand, allWeapons, out rMainhand, out var mainhandLabel, locked, true)) { changes |= DataChange.Item; if (rMainhand.Type.ValidOffhand() != cMainhand.Type.ValidOffhand()) @@ -480,7 +484,8 @@ public class EquipmentDrawer private DataChange DrawWeaponsNormal(EquipItem cMainhand, out EquipItem rMainhand, EquipItem cOffhand, out EquipItem rOffhand, StainId cMainhandStain, out StainId rMainhandStain, StainId cOffhandStain, out StainId rOffhandStain, EquipFlag? cApply, - out bool rApplyMainhand, out bool rApplyMainhandStain, out bool rApplyOffhand, out bool rApplyOffhandStain, bool locked) + out bool rApplyMainhand, out bool rApplyMainhandStain, out bool rApplyOffhand, out bool rApplyOffhandStain, bool locked, + bool allWeapons) { var changes = DataChange.None; @@ -492,7 +497,7 @@ public class EquipmentDrawer using (var group = ImRaii.Group()) { rOffhand = cOffhand; - if (DrawMainhand(cMainhand, cApply.HasValue, out rMainhand, out var mainhandLabel, locked, false)) + if (DrawMainhand(cMainhand, allWeapons, out rMainhand, out var mainhandLabel, locked, false)) { changes |= DataChange.Item; if (rMainhand.Type.ValidOffhand() != cMainhand.Type.ValidOffhand())