From d7074c5791de557344334b7679d87d3c7f52f725 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 9 Aug 2024 16:01:17 +0200 Subject: [PATCH] Improve Gloss/Specular display --- Glamourer/Designs/Design.cs | 6 ++-- Glamourer/Gui/Materials/AdvancedDyePopup.cs | 37 ++++++++++++++++++--- Glamourer/Gui/Materials/MaterialDrawer.cs | 5 +-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Glamourer/Designs/Design.cs b/Glamourer/Designs/Design.cs index 05ee948..8e4d366 100644 --- a/Glamourer/Designs/Design.cs +++ b/Glamourer/Designs/Design.cs @@ -228,10 +228,10 @@ public sealed class Design : DesignBase, ISavable, IDesignStandIn if (array == null) return; - foreach (var obj in array.OfType()) + foreach (var jObj in array.OfType()) { - var identifier = obj["Design"]?.ToObject() ?? throw new ArgumentNullException("Design"); - var type = (ApplicationType)(obj["Type"]?.ToObject() ?? 0); + var identifier = jObj["Design"]?.ToObject() ?? throw new ArgumentNullException(nameof(design)); + var type = (ApplicationType)(jObj["Type"]?.ToObject() ?? 0); linkLoader.AddObject(design, new LinkData(identifier, type, order)); } } diff --git a/Glamourer/Gui/Materials/AdvancedDyePopup.cs b/Glamourer/Gui/Materials/AdvancedDyePopup.cs index b857bf8..9991aae 100644 --- a/Glamourer/Gui/Materials/AdvancedDyePopup.cs +++ b/Glamourer/Gui/Materials/AdvancedDyePopup.cs @@ -11,6 +11,7 @@ using ImGuiNET; using OtterGui; using OtterGui.Raii; using OtterGui.Services; +using OtterGui.Text; using OtterGui.Widgets; using Penumbra.GameData.Enums; using Penumbra.GameData.Files.MaterialStructs; @@ -346,8 +347,7 @@ public sealed unsafe class AdvancedDyePopup( if (_mode is not ColorRow.Mode.Dawntrail) { ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale); - applied |= ImGui.DragFloat("##Gloss", ref value.Model.GlossStrength, 0.01f, 0.001f, float.MaxValue, "%.3f G") - && value.Model.GlossStrength > 0; + applied |= DragGloss(ref value.Model.GlossStrength); ImGuiUtil.HoverTooltip("Change the gloss strength for this row."); } else @@ -359,8 +359,7 @@ public sealed unsafe class AdvancedDyePopup( if (_mode is not ColorRow.Mode.Dawntrail) { ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale); - applied |= ImGui.DragFloat("##Specular Strength", ref value.Model.SpecularStrength, 0.01f, float.MinValue, float.MaxValue, - "%.3f%% SS"); + applied |= DragSpecularStrength(ref value.Model.SpecularStrength); ImGuiUtil.HoverTooltip("Change the specular strength for this row."); } else @@ -388,6 +387,36 @@ public sealed unsafe class AdvancedDyePopup( stateManager.ChangeMaterialValue(_state, index, value, ApplySettings.Manual); } + public static bool DragGloss(ref float value) + { + var tmp = value; + var minValue = ImGui.GetIO().KeyCtrl ? 0f : (float)Half.Epsilon; + if (!ImUtf8.DragScalar("##Gloss"u8, ref tmp, "%.1f G"u8, 0.001f, minValue, Math.Max(0.01f, 0.005f * value), ImGuiSliderFlags.AlwaysClamp)) + return false; + + var tmp2 = Math.Clamp(tmp, minValue, (float)Half.MaxValue); + if (tmp2 == value) + return false; + + value = tmp2; + return true; + } + + public static bool DragSpecularStrength(ref float value) + { + var tmp = value * 100f; + if (!ImUtf8.DragScalar("##SpecularStrength"u8, ref tmp, "%.0f%% SS"u8, 0f, (float)Half.MaxValue * 100f, 0.05f, + ImGuiSliderFlags.AlwaysClamp)) + return false; + + var tmp2 = Math.Clamp(tmp, 0f, (float)Half.MaxValue * 100f) / 100f; + if (tmp2 == value) + return false; + + value = tmp2; + return true; + } + private LabelStruct _label = new(); private struct LabelStruct diff --git a/Glamourer/Gui/Materials/MaterialDrawer.cs b/Glamourer/Gui/Materials/MaterialDrawer.cs index 95be750..3fcdbe1 100644 --- a/Glamourer/Gui/Materials/MaterialDrawer.cs +++ b/Glamourer/Gui/Materials/MaterialDrawer.cs @@ -1,6 +1,7 @@ using Dalamud.Interface; using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; +using FFXIVClientStructs.FFXIV.Common.Lua; using Glamourer.Designs; using Glamourer.Interop.Material; using ImGuiNET; @@ -196,11 +197,11 @@ public class MaterialDrawer(DesignManager _designManager, Configuration _config) applied |= ImGuiUtil.ColorPicker("##emissive", "Change the emissive value for this row.", row.Emissive, v => tmp.Emissive = v, "E"); ImGui.SameLine(0, _spacing); ImGui.SetNextItemWidth(GlossWidth * ImGuiHelpers.GlobalScale); - applied |= ImGui.DragFloat("##Gloss", ref tmp.GlossStrength, 0.01f, 0.001f, float.MaxValue, "%.3f G"); + applied |= AdvancedDyePopup.DragGloss(ref tmp.GlossStrength); ImGuiUtil.HoverTooltip("Change the gloss strength for this row."); ImGui.SameLine(0, _spacing); ImGui.SetNextItemWidth(SpecularStrengthWidth * ImGuiHelpers.GlobalScale); - applied |= ImGui.DragFloat("##Specular Strength", ref tmp.SpecularStrength, 0.01f, float.MinValue, float.MaxValue, "%.3f%% SS"); + applied |= AdvancedDyePopup.DragSpecularStrength(ref tmp.SpecularStrength); ImGuiUtil.HoverTooltip("Change the specular strength for this row."); if (applied) _designManager.ChangeMaterialValue(design, index, tmp);