From f63903e3e6a4a7e20de582d1e097a2cb9073d3a8 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 17 Dec 2022 16:30:20 +0100 Subject: [PATCH] Add slots to demihuman imc. --- .../Import/TexToolsMeta.Deserialization.cs | 35 +++-------- .../Meta/Manipulations/ImcManipulation.cs | 33 +++++----- Penumbra/UI/Classes/ModEditWindow.Meta.cs | 62 +++++++++++++++---- 3 files changed, 77 insertions(+), 53 deletions(-) diff --git a/Penumbra/Import/TexToolsMeta.Deserialization.cs b/Penumbra/Import/TexToolsMeta.Deserialization.cs index 0142e444..1494d949 100644 --- a/Penumbra/Import/TexToolsMeta.Deserialization.cs +++ b/Penumbra/Import/TexToolsMeta.Deserialization.cs @@ -130,37 +130,18 @@ public partial class TexToolsMeta ushort i = 0; try { - if( metaFileInfo.PrimaryType is ObjectType.Equipment or ObjectType.Accessory ) + var manip = new ImcManipulation( metaFileInfo.PrimaryType, metaFileInfo.SecondaryType, metaFileInfo.PrimaryId, metaFileInfo.SecondaryId, i, metaFileInfo.EquipSlot, + new ImcEntry() ); + var def = new ImcFile( manip ); + var partIdx = ImcFile.PartIndex( manip.EquipSlot ); // Gets turned to unknown for things without equip, and unknown turns to 0. + foreach( var value in values ) { - var def = new ImcFile( new ImcManipulation( metaFileInfo.EquipSlot, i, metaFileInfo.PrimaryId, new ImcEntry() ) ); - var partIdx = ImcFile.PartIndex( metaFileInfo.EquipSlot ); - foreach( var value in values ) + if( !value.Equals( def.GetEntry( partIdx, i ) ) ) { - if( !value.Equals( def.GetEntry( partIdx, i ) ) ) - { - MetaManipulations.Add( new ImcManipulation( metaFileInfo.EquipSlot, i, metaFileInfo.PrimaryId, value ) ); - } - - ++i; + MetaManipulations.Add( manip.Copy( value ) ); } - } - else - { - var def = new ImcFile( new ImcManipulation( metaFileInfo.PrimaryType, metaFileInfo.SecondaryType, metaFileInfo.PrimaryId, - metaFileInfo.SecondaryId, i, - new ImcEntry() ) ); - foreach( var value in values ) - { - if( !value.Equals( def.GetEntry( 0, i ) ) ) - { - MetaManipulations.Add( new ImcManipulation( metaFileInfo.PrimaryType, metaFileInfo.SecondaryType, - metaFileInfo.PrimaryId, - metaFileInfo.SecondaryId, i, - value ) ); - } - ++i; - } + ++i; } } catch( Exception e ) diff --git a/Penumbra/Meta/Manipulations/ImcManipulation.cs b/Penumbra/Meta/Manipulations/ImcManipulation.cs index ed9822a8..f2b4e45d 100644 --- a/Penumbra/Meta/Manipulations/ImcManipulation.cs +++ b/Penumbra/Meta/Manipulations/ImcManipulation.cs @@ -16,8 +16,8 @@ public readonly struct ImcManipulation : IMetaManipulation< ImcManipulation > { public ImcEntry Entry { get; private init; } public ushort PrimaryId { get; private init; } - public ushort Variant { get; private init; } public ushort SecondaryId { get; private init; } + public byte Variant { get; private init; } [JsonConverter( typeof( StringEnumConverter ) )] public ObjectType ObjectType { get; private init; } @@ -32,25 +32,13 @@ public readonly struct ImcManipulation : IMetaManipulation< ImcManipulation > { Entry = entry; PrimaryId = primaryId; - Variant = variant; + Variant = ( byte )variant; SecondaryId = 0; ObjectType = equipSlot.IsAccessory() ? ObjectType.Accessory : ObjectType.Equipment; EquipSlot = equipSlot; BodySlot = BodySlot.Unknown; } - public ImcManipulation( ObjectType objectType, BodySlot bodySlot, ushort primaryId, ushort secondaryId, ushort variant, - ImcEntry entry ) - { - Entry = entry; - ObjectType = objectType; - BodySlot = bodySlot; - SecondaryId = secondaryId; - PrimaryId = primaryId; - Variant = variant; - EquipSlot = EquipSlot.Unknown; - } - [JsonConstructor] internal ImcManipulation( ObjectType objectType, BodySlot bodySlot, ushort primaryId, ushort secondaryId, ushort variant, EquipSlot equipSlot, ImcEntry entry ) @@ -58,13 +46,19 @@ public readonly struct ImcManipulation : IMetaManipulation< ImcManipulation > Entry = entry; ObjectType = objectType; PrimaryId = primaryId; - Variant = variant; + Variant = ( byte )variant; if( objectType is ObjectType.Accessory or ObjectType.Equipment ) { BodySlot = BodySlot.Unknown; SecondaryId = 0; EquipSlot = equipSlot; } + else if( objectType is ObjectType.DemiHuman ) + { + BodySlot = BodySlot.Unknown; + SecondaryId = secondaryId; + EquipSlot = equipSlot; + } else { BodySlot = bodySlot; @@ -115,6 +109,15 @@ public readonly struct ImcManipulation : IMetaManipulation< ImcManipulation > return e != 0 ? e : Variant.CompareTo( other.Variant ); } + if( ObjectType is ObjectType.DemiHuman ) + { + var e = EquipSlot.CompareTo( other.EquipSlot ); + if( e != 0 ) + { + return e; + } + } + var s = SecondaryId.CompareTo( other.SecondaryId ); if( s != 0 ) { diff --git a/Penumbra/UI/Classes/ModEditWindow.Meta.cs b/Penumbra/UI/Classes/ModEditWindow.Meta.cs index 8c2e8340..d1a4159f 100644 --- a/Penumbra/UI/Classes/ModEditWindow.Meta.cs +++ b/Penumbra/UI/Classes/ModEditWindow.Meta.cs @@ -79,7 +79,7 @@ public partial class ModEditWindow DrawEditHeader( _editor.Meta.Eqp, "Equipment Parameter Edits (EQP)###EQP", 5, EqpRow.Draw, EqpRow.DrawNew ); DrawEditHeader( _editor.Meta.Eqdp, "Racial Model Edits (EQDP)###EQDP", 7, EqdpRow.Draw, EqdpRow.DrawNew ); - DrawEditHeader( _editor.Meta.Imc, "Variant Edits (IMC)###IMC", 9, ImcRow.Draw, ImcRow.DrawNew ); + DrawEditHeader( _editor.Meta.Imc, "Variant Edits (IMC)###IMC", 10, ImcRow.Draw, ImcRow.DrawNew ); DrawEditHeader( _editor.Meta.Est, "Extra Skeleton Parameters (EST)###EST", 7, EstRow.Draw, EstRow.DrawNew ); DrawEditHeader( _editor.Meta.Gmp, "Visor/Gimmick Edits (GMP)###GMP", 7, GmpRow.Draw, GmpRow.DrawNew ); DrawEditHeader( _editor.Meta.Rsp, "Racial Scaling Edits (RSP)###RSP", 5, RspRow.Draw, RspRow.DrawNew ); @@ -143,7 +143,7 @@ public partial class ModEditWindow ImGuiUtil.HoverTooltip( ModelSetIdTooltip ); ImGui.TableNextColumn(); - if( EqpEquipSlotCombo( "##eqpSlot", _new.Slot, out var slot ) ) + if( EqpEquipSlotCombo( "##eqpSlot", 100, _new.Slot, out var slot ) ) { _new = new EqpManipulation( ExpandedEqpFile.GetDefault( setId ), slot, _new.SetId ); } @@ -358,8 +358,14 @@ public partial class ModEditWindow ImGui.TableNextColumn(); if( ImcTypeCombo( "##imcType", _new.ObjectType, out var type ) ) { - _new = new ImcManipulation( type, _new.BodySlot, _new.PrimaryId, _new.SecondaryId == 0 ? ( ushort )1 : _new.SecondaryId, - _new.Variant, _new.EquipSlot == EquipSlot.Unknown ? EquipSlot.Head : _new.EquipSlot, _new.Entry ); + var equipSlot = type switch + { + ObjectType.Equipment => _new.EquipSlot.IsEquipment() ? _new.EquipSlot : EquipSlot.Head, + ObjectType.DemiHuman => _new.EquipSlot.IsEquipment() ? _new.EquipSlot : EquipSlot.Head, + ObjectType.Accessory => _new.EquipSlot.IsAccessory() ? _new.EquipSlot : EquipSlot.Ears, + _ => EquipSlot.Unknown, + }; + _new = new ImcManipulation( type, _new.BodySlot, _new.PrimaryId, _new.SecondaryId == 0 ? ( ushort )1 : _new.SecondaryId, _new.Variant, equipSlot, _new.Entry ); } ImGuiUtil.HoverTooltip( ObjectTypeTooltip ); @@ -378,9 +384,19 @@ public partial class ModEditWindow ImGui.TableNextColumn(); // Equipment and accessories are slightly different imcs than other types. - if( _new.ObjectType is ObjectType.Equipment or ObjectType.Accessory ) + if( _new.ObjectType is ObjectType.Equipment ) { - if( EqdpEquipSlotCombo( "##imcSlot", _new.EquipSlot, out var slot ) ) + if( EqpEquipSlotCombo( "##imcSlot", 100, _new.EquipSlot, out var slot ) ) + { + _new = new ImcManipulation( _new.ObjectType, _new.BodySlot, _new.PrimaryId, _new.SecondaryId, _new.Variant, slot, _new.Entry ).Copy( GetDefault( _new ) + ?? new ImcEntry() ); + } + + ImGuiUtil.HoverTooltip( EquipSlotTooltip ); + } + else if( _new.ObjectType is ObjectType.Accessory ) + { + if( AccessorySlotCombo( "##imcSlot", _new.EquipSlot, out var slot ) ) { _new = new ImcManipulation( _new.ObjectType, _new.BodySlot, _new.PrimaryId, _new.SecondaryId, _new.Variant, slot, _new.Entry ).Copy( GetDefault( _new ) ?? new ImcEntry() ); @@ -406,6 +422,22 @@ public partial class ModEditWindow ?? new ImcEntry() ); } + ImGui.TableNextColumn(); + if( _new.ObjectType is ObjectType.DemiHuman ) + { + if( EqpEquipSlotCombo( "##imcSlot", 70, _new.EquipSlot, out var slot ) ) + { + _new = new ImcManipulation( _new.ObjectType, _new.BodySlot, _new.PrimaryId, _new.SecondaryId, _new.Variant, slot, _new.Entry ).Copy( GetDefault( _new ) + ?? new ImcEntry() ); + } + + ImGuiUtil.HoverTooltip( EquipSlotTooltip ); + } + else + { + ImGui.Dummy( new Vector2( 70 * ImGuiHelpers.GlobalScale, 0 ) ); + } + ImGuiUtil.HoverTooltip( VariantIdTooltip ); // Values @@ -470,6 +502,13 @@ public partial class ModEditWindow ImGui.TextUnformatted( meta.Variant.ToString() ); ImGuiUtil.HoverTooltip( VariantIdTooltip ); + ImGui.TableNextColumn(); + ImGui.SetCursorPosX( ImGui.GetCursorPosX() + ImGui.GetStyle().FramePadding.X ); + if( meta.ObjectType is ObjectType.DemiHuman ) + { + ImGui.TextUnformatted( meta.EquipSlot.ToName() ); + } + // Values using var style = ImRaii.PushStyle( ImGuiStyleVar.ItemSpacing, new Vector2( 3 * ImGuiHelpers.GlobalScale, ImGui.GetStyle().ItemSpacing.Y ) ); @@ -827,12 +866,13 @@ public partial class ModEditWindow => ImGuiUtil.GenericEnumCombo( label, 120 * ImGuiHelpers.GlobalScale, current, out gender, RaceEnumExtensions.ToName, 1 ); private static bool EqdpEquipSlotCombo( string label, EquipSlot current, out EquipSlot slot ) - => ImGuiUtil.GenericEnumCombo( label, 100 * ImGuiHelpers.GlobalScale, current, out slot, EquipSlotExtensions.EqdpSlots, - EquipSlotExtensions.ToName ); + => ImGuiUtil.GenericEnumCombo( label, 100 * ImGuiHelpers.GlobalScale, current, out slot, EquipSlotExtensions.EqdpSlots, EquipSlotExtensions.ToName ); - private static bool EqpEquipSlotCombo( string label, EquipSlot current, out EquipSlot slot ) - => ImGuiUtil.GenericEnumCombo( label, 100 * ImGuiHelpers.GlobalScale, current, out slot, EquipSlotExtensions.EquipmentSlots, - EquipSlotExtensions.ToName ); + private static bool EqpEquipSlotCombo( string label, float width, EquipSlot current, out EquipSlot slot ) + => ImGuiUtil.GenericEnumCombo( label, width * ImGuiHelpers.GlobalScale, current, out slot, EquipSlotExtensions.EquipmentSlots, EquipSlotExtensions.ToName ); + + private static bool AccessorySlotCombo( string label, EquipSlot current, out EquipSlot slot ) + => ImGuiUtil.GenericEnumCombo( label, 100 * ImGuiHelpers.GlobalScale, current, out slot, EquipSlotExtensions.AccessorySlots, EquipSlotExtensions.ToName ); private static bool SubRaceCombo( string label, SubRace current, out SubRace subRace ) => ImGuiUtil.GenericEnumCombo( label, 150 * ImGuiHelpers.GlobalScale, current, out subRace, RaceEnumExtensions.ToName, 1 );