Improve Gloss/Specular display

This commit is contained in:
Ottermandias 2024-08-09 16:01:17 +02:00
parent d594082165
commit d7074c5791
3 changed files with 39 additions and 9 deletions

View file

@ -228,10 +228,10 @@ public sealed class Design : DesignBase, ISavable, IDesignStandIn
if (array == null) if (array == null)
return; return;
foreach (var obj in array.OfType<JObject>()) foreach (var jObj in array.OfType<JObject>())
{ {
var identifier = obj["Design"]?.ToObject<Guid>() ?? throw new ArgumentNullException("Design"); var identifier = jObj["Design"]?.ToObject<Guid>() ?? throw new ArgumentNullException(nameof(design));
var type = (ApplicationType)(obj["Type"]?.ToObject<uint>() ?? 0); var type = (ApplicationType)(jObj["Type"]?.ToObject<uint>() ?? 0);
linkLoader.AddObject(design, new LinkData(identifier, type, order)); linkLoader.AddObject(design, new LinkData(identifier, type, order));
} }
} }

View file

@ -11,6 +11,7 @@ using ImGuiNET;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using OtterGui.Services; using OtterGui.Services;
using OtterGui.Text;
using OtterGui.Widgets; using OtterGui.Widgets;
using Penumbra.GameData.Enums; using Penumbra.GameData.Enums;
using Penumbra.GameData.Files.MaterialStructs; using Penumbra.GameData.Files.MaterialStructs;
@ -346,8 +347,7 @@ public sealed unsafe class AdvancedDyePopup(
if (_mode is not ColorRow.Mode.Dawntrail) if (_mode is not ColorRow.Mode.Dawntrail)
{ {
ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale); ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale);
applied |= ImGui.DragFloat("##Gloss", ref value.Model.GlossStrength, 0.01f, 0.001f, float.MaxValue, "%.3f G") applied |= DragGloss(ref value.Model.GlossStrength);
&& value.Model.GlossStrength > 0;
ImGuiUtil.HoverTooltip("Change the gloss strength for this row."); ImGuiUtil.HoverTooltip("Change the gloss strength for this row.");
} }
else else
@ -359,8 +359,7 @@ public sealed unsafe class AdvancedDyePopup(
if (_mode is not ColorRow.Mode.Dawntrail) if (_mode is not ColorRow.Mode.Dawntrail)
{ {
ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale); ImGui.SetNextItemWidth(100 * ImGuiHelpers.GlobalScale);
applied |= ImGui.DragFloat("##Specular Strength", ref value.Model.SpecularStrength, 0.01f, float.MinValue, float.MaxValue, applied |= DragSpecularStrength(ref value.Model.SpecularStrength);
"%.3f%% SS");
ImGuiUtil.HoverTooltip("Change the specular strength for this row."); ImGuiUtil.HoverTooltip("Change the specular strength for this row.");
} }
else else
@ -388,6 +387,36 @@ public sealed unsafe class AdvancedDyePopup(
stateManager.ChangeMaterialValue(_state, index, value, ApplySettings.Manual); 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 LabelStruct _label = new();
private struct LabelStruct private struct LabelStruct

View file

@ -1,6 +1,7 @@
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using FFXIVClientStructs.FFXIV.Common.Lua;
using Glamourer.Designs; using Glamourer.Designs;
using Glamourer.Interop.Material; using Glamourer.Interop.Material;
using ImGuiNET; 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"); applied |= ImGuiUtil.ColorPicker("##emissive", "Change the emissive value for this row.", row.Emissive, v => tmp.Emissive = v, "E");
ImGui.SameLine(0, _spacing); ImGui.SameLine(0, _spacing);
ImGui.SetNextItemWidth(GlossWidth * ImGuiHelpers.GlobalScale); 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."); ImGuiUtil.HoverTooltip("Change the gloss strength for this row.");
ImGui.SameLine(0, _spacing); ImGui.SameLine(0, _spacing);
ImGui.SetNextItemWidth(SpecularStrengthWidth * ImGuiHelpers.GlobalScale); 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."); ImGuiUtil.HoverTooltip("Change the specular strength for this row.");
if (applied) if (applied)
_designManager.ChangeMaterialValue(design, index, tmp); _designManager.ChangeMaterialValue(design, index, tmp);