From 9df08560b69519f94779e22e2ce6c49433b1808b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 12 May 2021 16:07:00 +0900 Subject: [PATCH 1/4] Save skin editor changes on forced exit --- osu.Game/Skinning/Editor/SkinEditor.cs | 4 ++-- osu.Game/Skinning/Editor/SkinEditorOverlay.cs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index a00557ee4e..5deebe9800 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -108,7 +108,7 @@ namespace osu.Game.Skinning.Editor { Text = "Save Changes", Width = 140, - Action = save, + Action = Save, }, new DangerousTriangleButton { @@ -192,7 +192,7 @@ namespace osu.Game.Skinning.Editor } } - private void save() + public void Save() { SkinnableElementTargetContainer[] targetContainers = targetScreen.ChildrenOfType().ToArray(); diff --git a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs index cbed498a38..2d7cae71ff 100644 --- a/osu.Game/Skinning/Editor/SkinEditorOverlay.cs +++ b/osu.Game/Skinning/Editor/SkinEditorOverlay.cs @@ -92,8 +92,10 @@ namespace osu.Game.Skinning.Editor /// public void Reset() { + skinEditor?.Save(); skinEditor?.Hide(); skinEditor?.Expire(); + skinEditor = null; } } From be187e8ebdd8d981b1c3c1620960e1aaca27d44b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 12 May 2021 17:42:04 +0900 Subject: [PATCH 2/4] Avoid hard crash if `Save()` is called before preparing for mutation --- osu.Game/Skinning/Editor/SkinEditor.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index 5deebe9800..fcb1392ed5 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -38,6 +38,8 @@ namespace osu.Game.Skinning.Editor [Resolved] private OsuColour colours { get; set; } + private bool hasBegunMutating; + public SkinEditor(Drawable targetScreen) { this.targetScreen = targetScreen; @@ -139,7 +141,11 @@ namespace osu.Game.Skinning.Editor // 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(skin => Scheduler.AddOnce(skinChanged), true); + currentSkin.BindValueChanged(skin => + { + hasBegunMutating = false; + Scheduler.AddOnce(skinChanged); + }, true); } private void skinChanged() @@ -161,6 +167,7 @@ namespace osu.Game.Skinning.Editor }); skins.EnsureMutableSkin(); + hasBegunMutating = true; } private void placeComponent(Type type) @@ -194,6 +201,9 @@ namespace osu.Game.Skinning.Editor public void Save() { + if (!hasBegunMutating) + return; + SkinnableElementTargetContainer[] targetContainers = targetScreen.ChildrenOfType().ToArray(); foreach (var t in targetContainers) From 2f55d1e5ab9c734bb07519849d6ca4c31f32b375 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 12 May 2021 17:42:12 +0900 Subject: [PATCH 3/4] Also save on skin switch --- osu.Game/Skinning/Editor/SkinEditor.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index fcb1392ed5..9e50aab829 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -143,6 +143,8 @@ namespace osu.Game.Skinning.Editor // probably something which will be factored out in a future database refactor so not too concerning for now. currentSkin.BindValueChanged(skin => { + Save(); + hasBegunMutating = false; Scheduler.AddOnce(skinChanged); }, true); From 088335a0359f73ecb10625c5bcccbaefff9edbd4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 12 May 2021 17:45:51 +0900 Subject: [PATCH 4/4] Revert "Also save on skin switch" This reverts commit 2f55d1e5ab9c734bb07519849d6ca4c31f32b375. --- osu.Game/Skinning/Editor/SkinEditor.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index 9e50aab829..fcb1392ed5 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -143,8 +143,6 @@ namespace osu.Game.Skinning.Editor // probably something which will be factored out in a future database refactor so not too concerning for now. currentSkin.BindValueChanged(skin => { - Save(); - hasBegunMutating = false; Scheduler.AddOnce(skinChanged); }, true);