Split huge material shpk gui function.

This commit is contained in:
Ottermandias 2023-02-24 15:34:20 +01:00
parent d4f1097eba
commit 7619503a2b
2 changed files with 125 additions and 99 deletions

View file

@ -8,6 +8,7 @@ using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Interface.Internal.Notifications;
using ImGuiNET;
using Lumina.Data.Parsing;
using Lumina.Excel.GeneratedSheets;
using OtterGui;
using OtterGui.Classes;
using OtterGui.Raii;
@ -60,7 +61,7 @@ public partial class ModEditWindow
var samplers = file.GetSamplersByTexture();
_mtrlTabState.TextureLabels.Clear();
_mtrlTabState.TextureLabelWidth = 50f * ImGuiHelpers.GlobalScale;
using( var font = ImRaii.PushFont( UiBuilder.MonoFont ) )
using( var _ = ImRaii.PushFont( UiBuilder.MonoFont ) )
{
for( var i = 0; i < file.Textures.Length; ++i )
{
@ -166,18 +167,9 @@ public partial class ModEditWindow
ImGui.Dummy( new Vector2( ImGui.GetTextLineHeight() / 2 ) );
}
private bool DrawMaterialShaderResources( MtrlFile file, bool disabled )
private bool DrawMaterialShaderKeys( MtrlFile file, bool disabled )
{
var ret = false;
if( !ImGui.CollapsingHeader( "Advanced Shader Resources" ) )
{
return ret;
}
ret |= DrawPackageNameInput( file, disabled );
ret |= DrawShaderFlagsInput( file, disabled );
DrawCustomAssociations( file, disabled );
if( file.ShaderPackage.ShaderKeys.Length > 0 || !disabled && file.AssociatedShpk != null && file.AssociatedShpk.MaterialKeys.Length > 0 )
{
using var t = ImRaii.TreeNode( "Shader Keys" );
@ -263,6 +255,11 @@ public partial class ModEditWindow
}
}
return ret;
}
private void DrawMaterialShaders( MtrlFile file )
{
if( file.AssociatedShpk != null )
{
var definedKeys = new Dictionary<uint, uint>();
@ -300,7 +297,11 @@ public partial class ModEditWindow
.Dispose();
ImRaii.TreeNode( $"Pixel Shaders: {( pixelShaders.Count > 0 ? string.Join( ", ", pixelShaders.Select( i => $"#{i}" ) ) : "???" )}", ImGuiTreeNodeFlags.Leaf ).Dispose();
}
}
private bool DrawMaterialConstants( MtrlFile file, bool disabled )
{
var ret = false;
if( file.ShaderPackage.Constants.Length > 0
|| file.ShaderPackage.ShaderValues.Length > 0
|| !disabled && file.AssociatedShpk != null && file.AssociatedShpk.Constants.Length > 0 )
@ -457,6 +458,12 @@ public partial class ModEditWindow
}
}
return ret;
}
private bool DrawMaterialSamplers( MtrlFile file, bool disabled )
{
var ret = false;
if( file.ShaderPackage.Samplers.Length > 0
|| file.Textures.Length > 0
|| !disabled && file.AssociatedShpk != null && file.AssociatedShpk.Samplers.Any( sampler => sampler.Slot == 2 ) )
@ -593,4 +600,66 @@ public partial class ModEditWindow
return ret;
}
private bool DrawMaterialShaderResources( MtrlFile file, bool disabled )
{
var ret = false;
if( !ImGui.CollapsingHeader( "Advanced Shader Resources" ) )
{
return ret;
}
ret |= DrawPackageNameInput( file, disabled );
ret |= DrawShaderFlagsInput( file, disabled );
DrawCustomAssociations( file, disabled );
ret |= DrawMaterialShaderKeys( file, disabled );
DrawMaterialShaders( file );
ret |= DrawMaterialConstants( file, disabled );
ret |= DrawMaterialSamplers( file, disabled );
return ret;
}
private static (string?, bool) MaterialParamRangeName( string prefix, int valueOffset, int valueLength )
{
if( valueLength == 0 || valueOffset < 0 )
{
return (null, false);
}
var firstVector = valueOffset >> 2;
var lastVector = ( valueOffset + valueLength - 1 ) >> 2;
var firstComponent = valueOffset & 0x3;
var lastComponent = ( valueOffset + valueLength - 1 ) & 0x3;
static string VectorSwizzle( int firstComponent, int numComponents )
=> numComponents == 4 ? "" : string.Concat( ".", "xyzw".AsSpan( firstComponent, numComponents ) );
if( firstVector == lastVector )
{
return ($"{prefix}[{firstVector}]{VectorSwizzle( firstComponent, lastComponent + 1 - firstComponent )}", true);
}
var parts = new string[lastVector + 1 - firstVector];
parts[0] = $"{prefix}[{firstVector}]{VectorSwizzle( firstComponent, 4 - firstComponent )}";
parts[^1] = $"[{lastVector}]{VectorSwizzle( 0, lastComponent + 1 )}";
for( var i = firstVector + 1; i < lastVector; ++i )
{
parts[i - firstVector] = $"[{i}]";
}
return (string.Join( ", ", parts ), false);
}
private static string? MaterialParamName( bool componentOnly, int offset )
{
if( offset < 0 )
{
return null;
}
var component = "xyzw"[offset & 0x3];
return componentOnly ? new string( component, 1 ) : $"[{offset >> 2}].{component}";
}
}

View file

@ -647,47 +647,4 @@ public partial class ModEditWindow
}
}
}
private static (string?, bool) MaterialParamRangeName( string prefix, int valueOffset, int valueLength )
{
if( valueLength == 0 || valueOffset < 0 )
{
return ( null, false );
}
var firstVector = valueOffset >> 2;
var lastVector = ( valueOffset + valueLength - 1 ) >> 2;
var firstComponent = valueOffset & 0x3;
var lastComponent = ( valueOffset + valueLength - 1 ) & 0x3;
static string VectorSwizzle( int firstComponent, int numComponents )
=> numComponents == 4 ? "" : string.Concat( ".", "xyzw".AsSpan( firstComponent, numComponents ) );
if( firstVector == lastVector )
{
return ( $"{prefix}[{firstVector}]{VectorSwizzle( firstComponent, lastComponent + 1 - firstComponent )}", true );
}
var parts = new string[lastVector + 1 - firstVector];
parts[ 0 ] = $"{prefix}[{firstVector}]{VectorSwizzle( firstComponent, 4 - firstComponent )}";
parts[ ^1 ] = $"[{lastVector}]{VectorSwizzle( 0, lastComponent + 1 )}";
for( var i = firstVector + 1; i < lastVector; ++i )
{
parts[ i - firstVector ] = $"[{i}]";
}
return ( string.Join( ", ", parts ), false );
}
private static string? MaterialParamName( bool componentOnly, int offset )
{
if( offset < 0 )
{
return null;
}
var component = "xyzw"[ offset & 0x3 ];
return componentOnly ? new string( component, 1 ) : $"[{offset >> 2}].{component}";
}
}