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>
/// Writes the current painted maps to a new named slot. Returns false without writing if the painter
/// is not ready or a slot with this name already exists (no silent overwrite).
/// Writes the current painted maps to a named slot. Returns false without writing if the painter is
/// 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>
public bool SavePaintAs(string name)
public bool SavePaintAs(string name, bool overwrite = false)
{
if (!_setupValid || string.IsNullOrWhiteSpace(name)) return false;
name = name.Trim();
if (PaintExists(name)) return false;
if (!overwrite && PaintExists(name)) return false;
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
/// 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
/// Lib_EntryTemplate per saved slot. Save opens a name dialog (blocked if the name already exists, no
/// overwrite); Load and Delete go through a confirmation dialog. Loading replaces the current painting and,
/// when networked, re-broadcasts the loaded state to every other peer.
/// Lib_EntryTemplate per saved slot. Save opens a name dialog (an existing name is overwritten, with a
/// warning shown while typing); Load applies the selected slot immediately; Delete goes through a
/// confirmation dialog. Loading replaces the current painting and, when networked, re-broadcasts the
/// loaded state to every other peer.
/// </summary>
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 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);
// --- Bind (find authored objects, hook listeners) ---
@@ -200,17 +200,19 @@ public partial class PaintHud
string name = _nameInput ? _nameInput.text.Trim() : "";
bool empty = string.IsNullOrEmpty(name);
bool exists = !empty && MeshPainter.PaintExists(name);
if (_saveOkButton) _saveOkButton.interactable = !empty && !exists && painter;
if (_saveInfo) _saveInfo.text = exists ? "A painting with this name already exists." : "";
// Overwrite is allowed -> the OK button stays enabled even when the name exists; the warning is
// 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()
{
if (!painter || !_nameInput) return;
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;
if (_saveDialog) _saveDialog.SetActive(false);
@@ -225,8 +227,7 @@ public partial class PaintHud
private void OnLoadClicked()
{
if (!painter || string.IsNullOrEmpty(_selectedPainting)) return;
string name = _selectedPainting;
ShowConfirm($"Load \"{name}\"?\nThe current painting will be lost.", OkAccent, () => DoLoad(name));
DoLoad(_selectedPainting); // load immediately, no confirmation
}
private void OnDeleteClicked()