Make shape names editable in models.

This commit is contained in:
Ottermandias 2025-06-01 13:04:20 +02:00
parent b48c4f440a
commit 6cba63ac98

View file

@ -31,19 +31,18 @@ public partial class ModEditWindow
private class LoadedData private class LoadedData
{ {
public MdlFile LastFile = null!; public MdlFile LastFile = null!;
public readonly List<TagButtons> SubMeshAttributeTags = []; public readonly List<TagButtons> SubMeshAttributeTags = [];
public long[] LodTriCount = []; public long[] LodTriCount = [];
} }
private string _modelNewMaterial = string.Empty; private string _modelNewMaterial = string.Empty;
private readonly LoadedData _main = new(); private readonly LoadedData _main = new();
private readonly LoadedData _preview = new(); private readonly LoadedData _preview = new();
private string _customPath = string.Empty; private string _customPath = string.Empty;
private Utf8GamePath _customGamePath = Utf8GamePath.Empty; private Utf8GamePath _customGamePath = Utf8GamePath.Empty;
private LoadedData UpdateFile(MdlFile file, bool force, bool disabled) private LoadedData UpdateFile(MdlFile file, bool force, bool disabled)
@ -68,7 +67,7 @@ public partial class ModEditWindow
private bool DrawModelPanel(MdlTab tab, bool disabled) private bool DrawModelPanel(MdlTab tab, bool disabled)
{ {
var ret = tab.Dirty; var ret = tab.Dirty;
var data = UpdateFile(tab.Mdl, ret, disabled); var data = UpdateFile(tab.Mdl, ret, disabled);
DrawVersionUpdate(tab, disabled); DrawVersionUpdate(tab, disabled);
DrawImportExport(tab, disabled); DrawImportExport(tab, disabled);
@ -89,7 +88,8 @@ public partial class ModEditWindow
if (disabled || tab.Mdl.Version is not MdlFile.V5) if (disabled || tab.Mdl.Version is not MdlFile.V5)
return; return;
if (!ImUtf8.ButtonEx("Update MDL Version from V5 to V6"u8, "Try using this if the bone weights of a pre-Dawntrail model seem wrong.\n\nThis is not revertible."u8, if (!ImUtf8.ButtonEx("Update MDL Version from V5 to V6"u8,
"Try using this if the bone weights of a pre-Dawntrail model seem wrong.\n\nThis is not revertible."u8,
new Vector2(-0.1f, 0), false, 0, Colors.PressEnterWarningBg)) new Vector2(-0.1f, 0), false, 0, Colors.PressEnterWarningBg))
return; return;
@ -350,7 +350,7 @@ public partial class ModEditWindow
if (!disabled) if (!disabled)
{ {
ImGui.TableSetupColumn("actions", ImGuiTableColumnFlags.WidthFixed, UiHelpers.IconButtonSize.X); ImGui.TableSetupColumn("actions", ImGuiTableColumnFlags.WidthFixed, UiHelpers.IconButtonSize.X);
ImGui.TableSetupColumn("help", ImGuiTableColumnFlags.WidthFixed, UiHelpers.IconButtonSize.X); ImGui.TableSetupColumn("help", ImGuiTableColumnFlags.WidthFixed, UiHelpers.IconButtonSize.X);
} }
var inputFlags = disabled ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None; var inputFlags = disabled ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None;
@ -369,10 +369,11 @@ public partial class ModEditWindow
ImGui.TableNextColumn(); ImGui.TableNextColumn();
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Plus.ToIconString(), UiHelpers.IconButtonSize, string.Empty, !validName, true)) if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Plus.ToIconString(), UiHelpers.IconButtonSize, string.Empty, !validName, true))
{ {
ret |= true; ret |= true;
tab.Mdl.Materials = materials.AddItem(_modelNewMaterial); tab.Mdl.Materials = materials.AddItem(_modelNewMaterial);
_modelNewMaterial = string.Empty; _modelNewMaterial = string.Empty;
} }
ImGui.TableNextColumn(); ImGui.TableNextColumn();
if (!validName && _modelNewMaterial.Length > 0) if (!validName && _modelNewMaterial.Length > 0)
DrawInvalidMaterialMarker(); DrawInvalidMaterialMarker();
@ -430,7 +431,9 @@ public partial class ModEditWindow
private static void DrawInvalidMaterialMarker() private static void DrawInvalidMaterialMarker()
{ {
using (ImRaii.PushFont(UiBuilder.IconFont)) using (ImRaii.PushFont(UiBuilder.IconFont))
{
ImGuiUtil.TextColored(0xFF0000FF, FontAwesomeIcon.TimesCircle.ToIconString()); ImGuiUtil.TextColored(0xFF0000FF, FontAwesomeIcon.TimesCircle.ToIconString());
}
ImGuiUtil.HoverTooltip( ImGuiUtil.HoverTooltip(
"Materials must be either relative (e.g. \"/filename.mtrl\")\n" "Materials must be either relative (e.g. \"/filename.mtrl\")\n"
@ -500,9 +503,9 @@ public partial class ModEditWindow
return; return;
var flags = ImGuiTableFlags.SizingFixedFit var flags = ImGuiTableFlags.SizingFixedFit
| ImGuiTableFlags.RowBg | ImGuiTableFlags.RowBg
| ImGuiTableFlags.Borders | ImGuiTableFlags.Borders
| ImGuiTableFlags.NoHostExtendX; | ImGuiTableFlags.NoHostExtendX;
using var table = ImRaii.Table(string.Empty, 4, flags); using var table = ImRaii.Table(string.Empty, 4, flags);
if (!table) if (!table)
return; return;
@ -590,6 +593,7 @@ public partial class ModEditWindow
if (!header) if (!header)
return false; return false;
var ret = false;
using (var table = ImRaii.Table("##data", 2, ImGuiTableFlags.SizingFixedFit)) using (var table = ImRaii.Table("##data", 2, ImGuiTableFlags.SizingFixedFit))
{ {
if (table) if (table)
@ -650,22 +654,49 @@ public partial class ModEditWindow
using (var attributes = ImRaii.TreeNode("Attributes", ImGuiTreeNodeFlags.DefaultOpen)) using (var attributes = ImRaii.TreeNode("Attributes", ImGuiTreeNodeFlags.DefaultOpen))
{ {
if (attributes) if (attributes)
foreach (var attribute in data.LastFile.Attributes) for (var i = 0; i < data.LastFile.Attributes.Length; ++i)
ImRaii.TreeNode(attribute, ImGuiTreeNodeFlags.Leaf).Dispose(); {
using var id = ImUtf8.PushId(i);
ref var attribute = ref data.LastFile.Attributes[i];
var name = attribute;
if (ImUtf8.InputText("##attribute"u8, ref name, "Attribute Name..."u8) && name.Length > 0 && name != attribute)
{
attribute = name;
ret = true;
}
}
} }
using (var bones = ImRaii.TreeNode("Bones", ImGuiTreeNodeFlags.DefaultOpen)) using (var bones = ImRaii.TreeNode("Bones", ImGuiTreeNodeFlags.DefaultOpen))
{ {
if (bones) if (bones)
foreach (var bone in data.LastFile.Bones) for (var i = 0; i < data.LastFile.Bones.Length; ++i)
ImRaii.TreeNode(bone, ImGuiTreeNodeFlags.Leaf).Dispose(); {
using var id = ImUtf8.PushId(i);
ref var bone = ref data.LastFile.Bones[i];
var name = bone;
if (ImUtf8.InputText("##bone"u8, ref name, "Bone Name..."u8) && name.Length > 0 && name != bone)
{
bone = name;
ret = true;
}
}
} }
using (var shapes = ImRaii.TreeNode("Shapes", ImGuiTreeNodeFlags.DefaultOpen)) using (var shapes = ImRaii.TreeNode("Shapes", ImGuiTreeNodeFlags.DefaultOpen))
{ {
if (shapes) if (shapes)
foreach (var shape in data.LastFile.Shapes) for (var i = 0; i < data.LastFile.Shapes.Length; ++i)
ImRaii.TreeNode(shape.ShapeName, ImGuiTreeNodeFlags.Leaf).Dispose(); {
using var id = ImUtf8.PushId(i);
ref var shape = ref data.LastFile.Shapes[i];
var name = shape.ShapeName;
if (ImUtf8.InputText("##shape"u8, ref name, "Shape Name..."u8) && name.Length > 0 && name != shape.ShapeName)
{
shape.ShapeName = name;
ret = true;
}
}
} }
if (data.LastFile.RemainingData.Length > 0) if (data.LastFile.RemainingData.Length > 0)
@ -675,7 +706,7 @@ public partial class ModEditWindow
Widget.DrawHexViewer(data.LastFile.RemainingData); Widget.DrawHexViewer(data.LastFile.RemainingData);
} }
return false; return ret;
} }
private static bool GetFirstModel(IEnumerable<string> files, [NotNullWhen(true)] out string? file) private static bool GetFirstModel(IEnumerable<string> files, [NotNullWhen(true)] out string? file)