Further work on Dye Template previews

This commit is contained in:
Ottermandias 2022-11-11 15:59:35 +01:00
parent 0b1a11132b
commit b3a993a2bc
4 changed files with 73 additions and 28 deletions

@ -1 +1 @@
Subproject commit f2d996094058059b67b27a208303627c83b26d69 Subproject commit cbf21c639f91d39422b2d4b7244bd8d8c5d5d4d7

View file

@ -2,6 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Numerics;
using Dalamud.Data; using Dalamud.Data;
using Lumina.Extensions; using Lumina.Extensions;
using Penumbra.GameData.Structs; using Penumbra.GameData.Structs;
@ -14,11 +15,11 @@ public partial class StmFile
public record struct DyePack public record struct DyePack
{ {
public uint Diffuse; public Vector3 Diffuse;
public uint Specular; public Vector3 Specular;
public uint Emissive; public Vector3 Emissive;
public float SpecularPower; public float SpecularPower;
public float Gloss; public float Gloss;
} }
public readonly struct StainingTemplateEntry public readonly struct StainingTemplateEntry
@ -31,9 +32,6 @@ public partial class StmFile
public readonly IReadOnlyList<Half> SpecularPowerEntries; public readonly IReadOnlyList<Half> SpecularPowerEntries;
public readonly IReadOnlyList<Half> GlossEntries; public readonly IReadOnlyList<Half> GlossEntries;
private static uint HalfToByte(Half value)
=> (byte)((float)value * byte.MaxValue + 0.5f);
public DyePack this[StainId idx] public DyePack this[StainId idx]
=> this[(int)idx.Value]; => this[(int)idx.Value];
@ -41,16 +39,20 @@ public partial class StmFile
{ {
get get
{ {
if (idx is <= 0 or > NumElements)
return default;
--idx;
var (dr, dg, db) = DiffuseEntries[idx]; var (dr, dg, db) = DiffuseEntries[idx];
var (sr, sg, sb) = SpecularEntries[idx]; var (sr, sg, sb) = SpecularEntries[idx];
var (er, eg, eb) = EmissiveEntries[idx]; var (er, eg, eb) = EmissiveEntries[idx];
var sp = SpecularPowerEntries[idx]; var sp = SpecularPowerEntries[idx];
var g = GlossEntries[idx]; var g = GlossEntries[idx];
return new DyePack() return new DyePack
{ {
Diffuse = 0xFF000000u | HalfToByte(dr) | (HalfToByte(dg) << 8) | (HalfToByte(db) << 16), Diffuse = new Vector3((float)dr, (float)dg, (float)db),
Emissive = 0xFF000000u | HalfToByte(sr) | (HalfToByte(sg) << 8) | (HalfToByte(sb) << 16), Emissive = new Vector3((float)sr, (float)sg, (float)sb),
Specular = 0xFF000000u | HalfToByte(er) | (HalfToByte(eg) << 8) | (HalfToByte(eb) << 16), Specular = new Vector3((float)er, (float)eg, (float)eb),
SpecularPower = (float)sp, SpecularPower = (float)sp,
Gloss = (float)g, Gloss = (float)g,
}; };

View file

@ -8,9 +8,12 @@ using System.Runtime.InteropServices;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.ImGuiFileDialog; using Dalamud.Interface.ImGuiFileDialog;
using ImGuiNET; using ImGuiNET;
using Lumina.Data.Parsing.Layer;
using OtterGui; using OtterGui;
using OtterGui.Raii; using OtterGui.Raii;
using OtterGui.Widgets;
using Penumbra.GameData.Files; using Penumbra.GameData.Files;
using Penumbra.GameData.Structs;
using Penumbra.Mods; using Penumbra.Mods;
using Penumbra.String.Classes; using Penumbra.String.Classes;
using Penumbra.String.Functions; using Penumbra.String.Functions;
@ -326,7 +329,14 @@ public partial class ModEditWindow
ColorSetCopyAllClipboardButton( file, 0 ); ColorSetCopyAllClipboardButton( file, 0 );
ImGui.SameLine(); ImGui.SameLine();
var ret = ColorSetPasteAllClipboardButton( file, 0 ); var ret = ColorSetPasteAllClipboardButton( file, 0 );
using var table = ImRaii.Table( "##ColorSets", 10, ImGui.SameLine();
ImGui.Dummy( ImGuiHelpers.ScaledVector2( 10, 0 ) );
ImGui.SameLine();
Penumbra.StainManager.StainCombo.Draw( "Preview Dye", Penumbra.StainManager.StainCombo.CurrentSelection.Value.Color, true );
ImGui.SameLine();
ImGui.Button( "Apply Preview Dyes." );
using var table = ImRaii.Table( "##ColorSets", 11,
ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersInnerV ); ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersInnerV );
if( !table ) if( !table )
{ {
@ -353,6 +363,8 @@ public partial class ModEditWindow
ImGui.TableHeader( "Skew" ); ImGui.TableHeader( "Skew" );
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TableHeader( "Dye" ); ImGui.TableHeader( "Dye" );
ImGui.TableNextColumn();
ImGui.TableHeader( "Dye Preview" );
for( var j = 0; j < file.ColorSets.Length; ++j ) for( var j = 0; j < file.ColorSets.Length; ++j )
{ {
@ -731,17 +743,37 @@ public partial class ModEditWindow
ImGui.TableNextColumn(); ImGui.TableNextColumn();
if( hasDye ) if( hasDye )
{ {
tmpInt = dye.Template; if( Penumbra.StainManager.TemplateCombo.Draw( "##dyeTemplate", dye.Template.ToString(), intSize
ImGui.SetNextItemWidth( intSize ); + ImGui.GetStyle().ScrollbarSize / 2, ImGui.GetTextLineHeightWithSpacing(), ImGuiComboFlags.NoArrowButton ) )
if( ImGui.InputInt( "##DyeTemplate", ref tmpInt, 0, 0 )
&& tmpInt != dye.Template
&& tmpInt is >= 0 and <= ushort.MaxValue )
{ {
file.ColorDyeSets[ colorSetIdx ].Rows[ rowIdx ].Template = ( ushort )tmpInt; file.ColorDyeSets[ colorSetIdx ].Rows[ rowIdx ].Template = Penumbra.StainManager.TemplateCombo.CurrentSelection;
ret = true; ret = true;
} }
ImGuiUtil.HoverTooltip( "Dye Template", ImGuiHoveredFlags.AllowWhenDisabled ); ImGuiUtil.HoverTooltip( "Dye Template", ImGuiHoveredFlags.AllowWhenDisabled );
ImGui.TableNextColumn();
var stain = Penumbra.StainManager.StainCombo.CurrentSelection.Key;
if( stain != 0 && Penumbra.StainManager.StmFile.Entries.TryGetValue( dye.Template, out var entry ) )
{
var values = entry[ ( int )stain ];
using var _ = ImRaii.Disabled();
ColorPicker( "##diffusePreview", string.Empty, values.Diffuse, c => { } );
ImGui.SameLine();
ColorPicker( "##specularPreview", string.Empty, values.Specular, c => { } );
ImGui.SameLine();
ColorPicker( "##emissivePreview", string.Empty, values.Emissive, c => { } );
ImGui.SameLine();
ImGui.SetNextItemWidth( floatSize );
ImGui.DragFloat( "##specularStrength", ref values.SpecularPower );
ImGui.SameLine();
ImGui.SetNextItemWidth( floatSize );
ImGui.DragFloat( "##gloss", ref values.Gloss );
}
}
else
{
ImGui.TableNextColumn();
} }

View file

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using Dalamud.Data; using Dalamud.Data;
using Dalamud.Plugin; using Dalamud.Plugin;
using OtterGui.Widgets; using OtterGui.Widgets;
@ -9,15 +11,24 @@ namespace Penumbra.Util;
public class StainManager : IDisposable public class StainManager : IDisposable
{ {
public readonly StainData StainData; public sealed class StainTemplateCombo : FilterComboCache< ushort >
public readonly FilterComboColors Combo;
public readonly StmFile StmFile;
public StainManager(DalamudPluginInterface pluginInterface, DataManager dataManager)
{ {
StainData = new StainData( pluginInterface, dataManager, dataManager.Language ); public StainTemplateCombo( IEnumerable< ushort > items )
Combo = new FilterComboColors( 140, StainData.Data ); : base( items )
StmFile = new StmFile( dataManager ); { }
}
public readonly StainData StainData;
public readonly FilterComboColors StainCombo;
public readonly StmFile StmFile;
public readonly StainTemplateCombo TemplateCombo;
public StainManager( DalamudPluginInterface pluginInterface, DataManager dataManager )
{
StainData = new StainData( pluginInterface, dataManager, dataManager.Language );
StainCombo = new FilterComboColors( 140, StainData.Data.Prepend( new KeyValuePair< byte, (string Name, uint Dye, bool Gloss) >( 0, ( "None", 0, false ) ) ) );
StmFile = new StmFile( dataManager );
TemplateCombo = new StainTemplateCombo( StmFile.Entries.Keys.Prepend( ( ushort )0 ) );
} }
public void Dispose() public void Dispose()