Load paintings instantly and allow overwriting saves in the paint HUD

Load now applies the selected slot immediately instead of going through a
confirmation dialog. Save keeps its OK button enabled even when the name
already exists (the warning text stays, purely informational) and writes
through with overwrite, so re-saving under the same name replaces the slot.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-06-30 21:47:16 +02:00
1 parent b6d60d7a98
commit 44cea8dd15
2 files changed
+16 -14

No files matched your search

+5 -4
View File
@@ -71,14 +71,15 @@ public partial class MeshPainter
} }
/// <summary> /// <summary>
/// Writes the current painted maps to a new named slot. Returns false without writing if the painter /// Writes the current painted maps to a named slot. Returns false without writing if the painter is
/// is not ready or a slot with this name already exists (no silent overwrite). /// not ready. An existing slot of the same name is overwritten only when <paramref name="overwrite"/>
/// is true; otherwise the call fails rather than clobbering it.
/// </summary> /// </summary>
public bool SavePaintAs(string name) public bool SavePaintAs(string name, bool overwrite = false)
{ {
if (!_setupValid || string.IsNullOrWhiteSpace(name)) return false; if (!_setupValid || string.IsNullOrWhiteSpace(name)) return false;
name = name.Trim(); name = name.Trim();
if (PaintExists(name)) return false; if (!overwrite && PaintExists(name)) return false;
try try
{ {
+11 -10
View File
@@ -9,9 +9,10 @@ using UnityEngine.UI;
/// list, an entry template, and the Save / Confirm dialogs) is authored inside the PaintHudPanel layout /// list, an entry template, and the Save / Confirm dialogs) is authored inside the PaintHudPanel layout
/// prefab - this code only finds those objects by their stable names and wires the behaviour, exactly like /// prefab - this code only finds those objects by their stable names and wires the behaviour, exactly like
/// <see cref="WirePanel"/> does for the brush widgets. The list is populated by cloning the authored /// <see cref="WirePanel"/> does for the brush widgets. The list is populated by cloning the authored
/// Lib_EntryTemplate per saved slot. Save opens a name dialog (blocked if the name already exists, no /// Lib_EntryTemplate per saved slot. Save opens a name dialog (an existing name is overwritten, with a
/// overwrite); Load and Delete go through a confirmation dialog. Loading replaces the current painting and, /// warning shown while typing); Load applies the selected slot immediately; Delete goes through a
/// when networked, re-broadcasts the loaded state to every other peer. /// confirmation dialog. Loading replaces the current painting and, when networked, re-broadcasts the
/// loaded state to every other peer.
/// </summary> /// </summary>
public partial class PaintHud public partial class PaintHud
{ {
@@ -55,7 +56,6 @@ public partial class PaintHud
private static readonly Color EntryNormal = new Color(0.18f, 0.18f, 0.22f, 1f); private static readonly Color EntryNormal = new Color(0.18f, 0.18f, 0.22f, 1f);
private static readonly Color EntrySelected = new Color(0.20f, 0.45f, 0.80f, 1f); private static readonly Color EntrySelected = new Color(0.20f, 0.45f, 0.80f, 1f);
private static readonly Color OkAccent = new Color(0.20f, 0.45f, 0.80f, 1f);
private static readonly Color OkDanger = new Color(0.62f, 0.26f, 0.26f, 1f); private static readonly Color OkDanger = new Color(0.62f, 0.26f, 0.26f, 1f);
// --- Bind (find authored objects, hook listeners) --- // --- Bind (find authored objects, hook listeners) ---
@@ -200,17 +200,19 @@ public partial class PaintHud
string name = _nameInput ? _nameInput.text.Trim() : ""; string name = _nameInput ? _nameInput.text.Trim() : "";
bool empty = string.IsNullOrEmpty(name); bool empty = string.IsNullOrEmpty(name);
bool exists = !empty && MeshPainter.PaintExists(name); bool exists = !empty && MeshPainter.PaintExists(name);
if (_saveOkButton) _saveOkButton.interactable = !empty && !exists && painter; // Overwrite is allowed -> the OK button stays enabled even when the name exists; the warning is
if (_saveInfo) _saveInfo.text = exists ? "A painting with this name already exists." : ""; // purely informational so you know you are about to replace an existing slot.
if (_saveOkButton) _saveOkButton.interactable = !empty && painter;
if (_saveInfo) _saveInfo.text = exists ? "A painting with this name already exists and will be overwritten." : "";
} }
private void ConfirmSave() private void ConfirmSave()
{ {
if (!painter || !_nameInput) return; if (!painter || !_nameInput) return;
string name = _nameInput.text.Trim(); string name = _nameInput.text.Trim();
if (string.IsNullOrEmpty(name) || MeshPainter.PaintExists(name)) { ValidateSaveName(); return; } if (string.IsNullOrEmpty(name)) { ValidateSaveName(); return; }
if (painter.SavePaintAs(name)) if (painter.SavePaintAs(name, overwrite: true))
{ {
_selectedPainting = name; _selectedPainting = name;
if (_saveDialog) _saveDialog.SetActive(false); if (_saveDialog) _saveDialog.SetActive(false);
@@ -225,8 +227,7 @@ public partial class PaintHud
private void OnLoadClicked() private void OnLoadClicked()
{ {
if (!painter || string.IsNullOrEmpty(_selectedPainting)) return; if (!painter || string.IsNullOrEmpty(_selectedPainting)) return;
string name = _selectedPainting; DoLoad(_selectedPainting); // load immediately, no confirmation
ShowConfirm($"Load \"{name}\"?\nThe current painting will be lost.", OkAccent, () => DoLoad(name));
} }
private void OnDeleteClicked() private void OnDeleteClicked()