From 0320ba770f1824b32fbb1e7d57366e7cf4b41481 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 7 Feb 2023 16:23:24 +0900 Subject: [PATCH] Handle component changes via `ISkinnableTarget.Components` rather than inside `SkinEditor` directly Seems saner? Maybe? --- osu.Game/Overlays/SkinEditor/SkinEditor.cs | 4 ---- .../SkinEditor/SkinEditorChangeHandler.cs | 15 ++++++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/SkinEditor/SkinEditor.cs b/osu.Game/Overlays/SkinEditor/SkinEditor.cs index 0716505f26..866de7e621 100644 --- a/osu.Game/Overlays/SkinEditor/SkinEditor.cs +++ b/osu.Game/Overlays/SkinEditor/SkinEditor.cs @@ -329,8 +329,6 @@ namespace osu.Game.Overlays.SkinEditor SelectedComponents.Clear(); SelectedComponents.Add(component); - - changeHandler?.SaveState(); } private void populateSettings() @@ -406,8 +404,6 @@ namespace osu.Game.Overlays.SkinEditor { foreach (var item in items) availableTargets.FirstOrDefault(t => t.Components.Contains(item))?.Remove(item); - - changeHandler?.SaveState(); } #region Drag & drop import handling diff --git a/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs b/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs index 95b24bbd6f..dfbd48a285 100644 --- a/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs +++ b/osu.Game/Overlays/SkinEditor/SkinEditorChangeHandler.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; using Newtonsoft.Json; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Testing; using osu.Game.Extensions; @@ -17,9 +18,10 @@ namespace osu.Game.Overlays.SkinEditor { public partial class SkinEditorChangeHandler : EditorChangeHandler { - private readonly Drawable targetScreen; + private readonly ISkinnableTarget? firstTarget; - private ISkinnableTarget? firstTarget => targetScreen.ChildrenOfType().FirstOrDefault(); + // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable + private readonly BindableList? components; public SkinEditorChangeHandler(Drawable targetScreen) { @@ -27,10 +29,13 @@ namespace osu.Game.Overlays.SkinEditor // In the future we'll want this to cover all changes, even to skin's `InstantiationInfo`. // We'll also need to consider cases where multiple targets are on screen at the same time. - this.targetScreen = targetScreen; + firstTarget = targetScreen?.ChildrenOfType().FirstOrDefault(); - // Save initial state. - SaveState(); + if (firstTarget == null) + return; + + components = new BindableList { BindTarget = firstTarget.Components }; + components.BindCollectionChanged((_, _) => SaveState()); } protected override void WriteCurrentStateToStream(MemoryStream stream)