1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:02:55 +08:00

Avoid showing skin save message when changing scenes after making no changes

This commit is contained in:
Dean Herbert 2023-02-02 18:42:33 +09:00
parent 8dc2e6872e
commit 015f4f2b38
4 changed files with 26 additions and 9 deletions

View File

@ -125,7 +125,7 @@ namespace osu.Game.Overlays.SkinEditor
{ {
Items = new[] Items = new[]
{ {
new EditorMenuItem(Resources.Localisation.Web.CommonStrings.ButtonsSave, MenuItemType.Standard, Save), new EditorMenuItem(Resources.Localisation.Web.CommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()),
new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, revert), new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, revert),
new EditorMenuItemSpacer(), new EditorMenuItemSpacer(),
new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, () => skinEditorOverlay?.Hide()), new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, () => skinEditorOverlay?.Hide()),
@ -333,7 +333,7 @@ namespace osu.Game.Overlays.SkinEditor
} }
} }
public void Save() public void Save(bool userTriggered = true)
{ {
if (!hasBegunMutating) if (!hasBegunMutating)
return; return;
@ -343,8 +343,9 @@ namespace osu.Game.Overlays.SkinEditor
foreach (var t in targetContainers) foreach (var t in targetContainers)
currentSkin.Value.UpdateDrawableTarget(t); currentSkin.Value.UpdateDrawableTarget(t);
skins.Save(skins.CurrentSkin.Value); // In the case the save was user triggered, always show the save message to make them feel confident.
onScreenDisplay?.Display(new SkinEditorToast(ToastStrings.SkinSaved, currentSkin.Value.SkinInfo.ToString() ?? "Unknown")); if (skins.Save(skins.CurrentSkin.Value) || userTriggered)
onScreenDisplay?.Display(new SkinEditorToast(ToastStrings.SkinSaved, currentSkin.Value.SkinInfo.ToString() ?? "Unknown"));
} }
protected override bool OnHover(HoverEvent e) => true; protected override bool OnHover(HoverEvent e) => true;

View File

@ -147,7 +147,7 @@ namespace osu.Game.Overlays.SkinEditor
if (skinEditor == null) return; if (skinEditor == null) return;
skinEditor.Save(); skinEditor.Save(false);
// ensure the toolbar is re-hidden even if a new screen decides to try and show it. // ensure the toolbar is re-hidden even if a new screen decides to try and show it.
updateComponentVisibility(); updateComponentVisibility();

View File

@ -179,8 +179,14 @@ namespace osu.Game.Skinning
private Skin createInstance(SkinInfo item) => item.CreateInstance(skinResources); private Skin createInstance(SkinInfo item) => item.CreateInstance(skinResources);
public void Save(Skin skin) /// <summary>
/// Save a skin. Updates any drawable layouts that are out of date.
/// </summary>
/// <returns>Whether any change actually occurred.</returns>
public bool Save(Skin skin)
{ {
bool hadChanges = false;
skin.SkinInfo.PerformWrite(s => skin.SkinInfo.PerformWrite(s =>
{ {
// Update for safety // Update for safety
@ -212,8 +218,14 @@ namespace osu.Game.Skinning
} }
} }
s.Hash = ComputeHash(s); string newHash = ComputeHash(s);
hadChanges = newHash != s.Hash;
s.Hash = newHash;
}); });
return hadChanges;
} }
} }
} }

View File

@ -192,12 +192,16 @@ namespace osu.Game.Skinning
}); });
} }
public void Save(Skin skin) /// <summary>
/// Save a skin. Updates any drawable layouts that are out of date.
/// </summary>
/// <returns>Whether any change actually occurred.</returns>
public bool Save(Skin skin)
{ {
if (!skin.SkinInfo.IsManaged) if (!skin.SkinInfo.IsManaged)
throw new InvalidOperationException($"Attempting to save a skin which is not yet tracked. Call {nameof(EnsureMutableSkin)} first."); throw new InvalidOperationException($"Attempting to save a skin which is not yet tracked. Call {nameof(EnsureMutableSkin)} first.");
skinImporter.Save(skin); return skinImporter.Save(skin);
} }
/// <summary> /// <summary>