Use validation logic for new material field

This commit is contained in:
ackwell 2024-05-03 21:41:35 +10:00
parent 078688454a
commit 9063d131ba

View file

@ -337,7 +337,7 @@ public partial class ModEditWindow
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.SetNextItemWidth(-1); ImGui.SetNextItemWidth(-1);
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 = tab.ValidateMaterial(_modelNewMaterial);
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))
{ {
@ -346,6 +346,8 @@ public partial class ModEditWindow
_modelNewMaterial = string.Empty; _modelNewMaterial = string.Empty;
} }
ImGui.TableNextColumn(); ImGui.TableNextColumn();
if (!validName && _modelNewMaterial.Length > 0)
DrawInvalidMaterialMarker();
return ret; return ret;
} }
@ -392,8 +394,15 @@ public partial class ModEditWindow
ImGui.TableNextColumn(); ImGui.TableNextColumn();
// Add markers to invalid materials. // Add markers to invalid materials.
if (!tab.ValidateMaterial(temp)) if (!tab.ValidateMaterial(temp))
using (var colorHandle = ImRaii.PushColor(ImGuiCol.TextDisabled, 0xFF0000FF, true)) DrawInvalidMaterialMarker();
return ret;
}
private void DrawInvalidMaterialMarker()
{ {
using var colorHandle = ImRaii.PushColor(ImGuiCol.TextDisabled, 0xFF0000FF, true);
ImGuiComponents.HelpMarker( ImGuiComponents.HelpMarker(
"Materials must be either relative (e.g. \"/filename.mtrl\")\n" "Materials must be either relative (e.g. \"/filename.mtrl\")\n"
+ "or absolute (e.g. \"bg/full/path/to/filename.mtrl\"),\n" + "or absolute (e.g. \"bg/full/path/to/filename.mtrl\"),\n"
@ -401,9 +410,6 @@ public partial class ModEditWindow
FontAwesomeIcon.TimesCircle); FontAwesomeIcon.TimesCircle);
} }
return ret;
}
private bool DrawModelLodDetails(MdlTab tab, int lodIndex, bool disabled) private bool DrawModelLodDetails(MdlTab tab, int lodIndex, bool disabled)
{ {
using var lodNode = ImRaii.TreeNode($"Level of Detail #{lodIndex + 1}", ImGuiTreeNodeFlags.DefaultOpen); using var lodNode = ImRaii.TreeNode($"Level of Detail #{lodIndex + 1}", ImGuiTreeNodeFlags.DefaultOpen);