mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-02 05:43:42 +01:00
Ensure materials contain at least one /
This commit is contained in:
parent
dbfaf37800
commit
aeb7bd5431
2 changed files with 49 additions and 18 deletions
|
|
@ -49,7 +49,7 @@ public partial class ModEditWindow
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool Valid
|
public bool Valid
|
||||||
=> Mdl.Valid;
|
=> Mdl.Valid && Mdl.Materials.All(ValidateMaterial);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public byte[] Write()
|
public byte[] Write()
|
||||||
|
|
@ -285,6 +285,17 @@ public partial class ModEditWindow
|
||||||
: _edit._gameData.GetFile(resolvedPath.InternalName.ToString())?.Data;
|
: _edit._gameData.GetFile(resolvedPath.InternalName.ToString())?.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Validate the specified material. </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// While materials can be relative (`/mt_...`) or absolute (`bg/...`),
|
||||||
|
/// they invariably must contain at least one directory seperator.
|
||||||
|
/// Missing this can lead to a crash.
|
||||||
|
/// </remarks>
|
||||||
|
public bool ValidateMaterial(string material)
|
||||||
|
{
|
||||||
|
return material.Contains('/');
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Remove the material given by the index. </summary>
|
/// <summary> Remove the material given by the index. </summary>
|
||||||
/// <remarks> Meshes using the removed material are redirected to material 0, and those after the index are corrected. </remarks>
|
/// <remarks> Meshes using the removed material are redirected to material 0, and those after the index are corrected. </remarks>
|
||||||
public void RemoveMaterial(int materialIndex)
|
public void RemoveMaterial(int materialIndex)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
|
using Dalamud.Interface.Components;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using OtterGui;
|
using OtterGui;
|
||||||
using OtterGui.Custom;
|
using OtterGui.Custom;
|
||||||
|
|
@ -295,7 +296,7 @@ public partial class ModEditWindow
|
||||||
if (!ImGui.CollapsingHeader("Materials"))
|
if (!ImGui.CollapsingHeader("Materials"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
using var table = ImRaii.Table(string.Empty, disabled ? 2 : 3, ImGuiTableFlags.SizingFixedFit);
|
using var table = ImRaii.Table(string.Empty, disabled ? 2 : 4, ImGuiTableFlags.SizingFixedFit);
|
||||||
if (!table)
|
if (!table)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -305,7 +306,10 @@ public partial class ModEditWindow
|
||||||
ImGui.TableSetupColumn("index", ImGuiTableColumnFlags.WidthFixed, 80 * UiHelpers.Scale);
|
ImGui.TableSetupColumn("index", ImGuiTableColumnFlags.WidthFixed, 80 * UiHelpers.Scale);
|
||||||
ImGui.TableSetupColumn("path", ImGuiTableColumnFlags.WidthStretch, 1);
|
ImGui.TableSetupColumn("path", ImGuiTableColumnFlags.WidthStretch, 1);
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
var inputFlags = disabled ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None;
|
var inputFlags = disabled ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None;
|
||||||
for (var materialIndex = 0; materialIndex < materials.Length; materialIndex++)
|
for (var materialIndex = 0; materialIndex < materials.Length; materialIndex++)
|
||||||
|
|
@ -321,12 +325,15 @@ public partial class ModEditWindow
|
||||||
ImGui.InputTextWithHint("##newMaterial", "Add new material...", ref _modelNewMaterial, Utf8GamePath.MaxGamePathLength, inputFlags);
|
ImGui.InputTextWithHint("##newMaterial", "Add new material...", ref _modelNewMaterial, Utf8GamePath.MaxGamePathLength, inputFlags);
|
||||||
var validName = _modelNewMaterial.Length > 0 && _modelNewMaterial[0] == '/';
|
var validName = _modelNewMaterial.Length > 0 && _modelNewMaterial[0] == '/';
|
||||||
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))
|
||||||
return ret;
|
{
|
||||||
|
ret |= true;
|
||||||
|
tab.Mdl.Materials = materials.AddItem(_modelNewMaterial);
|
||||||
|
_modelNewMaterial = string.Empty;
|
||||||
|
}
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
|
||||||
tab.Mdl.Materials = materials.AddItem(_modelNewMaterial);
|
return ret;
|
||||||
_modelNewMaterial = string.Empty;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool DrawMaterialRow(MdlTab tab, bool disabled, string[] materials, int materialIndex, ImGuiInputTextFlags inputFlags)
|
private bool DrawMaterialRow(MdlTab tab, bool disabled, string[] materials, int materialIndex, ImGuiInputTextFlags inputFlags)
|
||||||
|
|
@ -353,20 +360,33 @@ public partial class ModEditWindow
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
|
|
||||||
// Need to have at least one material.
|
// Need to have at least one material.
|
||||||
if (materials.Length <= 1)
|
if (materials.Length > 1)
|
||||||
return ret;
|
{
|
||||||
|
var tt = "Delete this material.\nAny meshes targeting this material will be updated to use material #1.";
|
||||||
|
var modifierActive = _config.DeleteModModifier.IsActive();
|
||||||
|
if (!modifierActive)
|
||||||
|
tt += $"\nHold {_config.DeleteModModifier} to delete.";
|
||||||
|
|
||||||
var tt = "Delete this material.\nAny meshes targeting this material will be updated to use material #1.";
|
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), UiHelpers.IconButtonSize, tt, !modifierActive, true))
|
||||||
var modifierActive = _config.DeleteModModifier.IsActive();
|
{
|
||||||
if (!modifierActive)
|
tab.RemoveMaterial(materialIndex);
|
||||||
tt += $"\nHold {_config.DeleteModModifier} to delete.";
|
ret |= true;
|
||||||
if (!ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Trash.ToIconString(), UiHelpers.IconButtonSize, tt, !modifierActive, true))
|
}
|
||||||
return ret;
|
}
|
||||||
|
|
||||||
tab.RemoveMaterial(materialIndex);
|
ImGui.TableNextColumn();
|
||||||
return true;
|
// Add markers to invalid materials.
|
||||||
|
if (!tab.ValidateMaterial(temp))
|
||||||
|
using (var colorHandle = ImRaii.PushColor(ImGuiCol.TextDisabled, 0xFF0000FF, true))
|
||||||
|
{
|
||||||
|
ImGuiComponents.HelpMarker(
|
||||||
|
"Materials must be either relative (e.g. \"/filename.mtrl\")\n"
|
||||||
|
+ "or absolute (e.g. \"chara/full/path/to/filename.mtrl\").",
|
||||||
|
FontAwesomeIcon.TimesCircle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool DrawModelLodDetails(MdlTab tab, int lodIndex, bool disabled)
|
private bool DrawModelLodDetails(MdlTab tab, int lodIndex, bool disabled)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue