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)
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 type = (ApplicationType)(obj["Type"]?.ToObject<uint>() ?? 0);
var identifier = jObj["Design"]?.ToObject<Guid>() ?? throw new ArgumentNullException(nameof(design));
var type = (ApplicationType)(jObj["Type"]?.ToObject<uint>() ?? 0);
linkLoader.AddObject(design, new LinkData(identifier, type, order));
}
}

View file

@ -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

View file

@ -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);