mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 20:33:09 +08:00
Merge pull request #28030 from bdach/save-skin-on-change
Autosave edited skin on change
This commit is contained in:
commit
0c45a482eb
@ -3,6 +3,7 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -321,6 +322,30 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
AddUntilStep("nested input disabled", () => ((Player)Game.ScreenStack.CurrentScreen).ChildrenOfType<PassThroughInputManager>().All(manager => !manager.UseParentInput));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSkinSavesOnChange()
|
||||
{
|
||||
advanceToSongSelect();
|
||||
openSkinEditor();
|
||||
|
||||
Guid editedSkinId = Guid.Empty;
|
||||
AddStep("save skin id", () => editedSkinId = Game.Dependencies.Get<SkinManager>().CurrentSkinInfo.Value.ID);
|
||||
AddStep("add skinnable component", () =>
|
||||
{
|
||||
skinEditor.ChildrenOfType<SkinComponentToolbox.ToolboxComponentButton>().First().TriggerClick();
|
||||
});
|
||||
|
||||
AddStep("change to triangles skin", () => Game.Dependencies.Get<SkinManager>().SetSkinFromConfiguration(SkinInfo.TRIANGLES_SKIN.ToString()));
|
||||
AddUntilStep("components loaded", () => Game.ChildrenOfType<SkinComponentsContainer>().All(c => c.ComponentsLoaded));
|
||||
// sort of implicitly relies on song select not being skinnable.
|
||||
// TODO: revisit if the above ever changes
|
||||
AddUntilStep("skin changed", () => !skinEditor.ChildrenOfType<SkinBlueprint>().Any());
|
||||
|
||||
AddStep("change back to modified skin", () => Game.Dependencies.Get<SkinManager>().SetSkinFromConfiguration(editedSkinId.ToString()));
|
||||
AddUntilStep("components loaded", () => Game.ChildrenOfType<SkinComponentsContainer>().All(c => c.ComponentsLoaded));
|
||||
AddUntilStep("changes saved", () => skinEditor.ChildrenOfType<SkinBlueprint>().Any());
|
||||
}
|
||||
|
||||
private void advanceToSongSelect()
|
||||
{
|
||||
PushAndConfirm(() => songSelect = new TestPlaySongSelect());
|
||||
|
@ -255,8 +255,11 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
// schedule ensures this only happens when the skin editor is visible.
|
||||
// also avoid some weird endless recursion / bindable feedback loop (something to do with tracking skins across three different bindable types).
|
||||
// probably something which will be factored out in a future database refactor so not too concerning for now.
|
||||
currentSkin.BindValueChanged(_ =>
|
||||
currentSkin.BindValueChanged(val =>
|
||||
{
|
||||
if (val.OldValue != null && hasBegunMutating)
|
||||
save(val.OldValue);
|
||||
|
||||
hasBegunMutating = false;
|
||||
Scheduler.AddOnce(skinChanged);
|
||||
}, true);
|
||||
@ -537,7 +540,9 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
|
||||
protected void Redo() => changeHandler?.RestoreState(1);
|
||||
|
||||
public void Save(bool userTriggered = true)
|
||||
public void Save(bool userTriggered = true) => save(currentSkin.Value);
|
||||
|
||||
private void save(Skin skin, bool userTriggered = true)
|
||||
{
|
||||
if (!hasBegunMutating)
|
||||
return;
|
||||
@ -551,11 +556,11 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
return;
|
||||
|
||||
foreach (var t in targetContainers)
|
||||
currentSkin.Value.UpdateDrawableTarget(t);
|
||||
skin.UpdateDrawableTarget(t);
|
||||
|
||||
// In the case the save was user triggered, always show the save message to make them feel confident.
|
||||
if (skins.Save(skins.CurrentSkin.Value) || userTriggered)
|
||||
onScreenDisplay?.Display(new SkinEditorToast(ToastStrings.SkinSaved, currentSkin.Value.SkinInfo.ToString() ?? "Unknown"));
|
||||
if (skins.Save(skin) || userTriggered)
|
||||
onScreenDisplay?.Display(new SkinEditorToast(ToastStrings.SkinSaved, skin.SkinInfo.ToString() ?? "Unknown"));
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e) => true;
|
||||
|
Loading…
Reference in New Issue
Block a user