diff --git a/osu.Game/Skinning/Editor/SkinEditor.cs b/osu.Game/Skinning/Editor/SkinEditor.cs index 6427d6298b..c594f8d271 100644 --- a/osu.Game/Skinning/Editor/SkinEditor.cs +++ b/osu.Game/Skinning/Editor/SkinEditor.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -193,14 +194,16 @@ namespace osu.Game.Skinning.Editor SelectedComponents.Add(component); } + private IEnumerable availableTargets => targetScreen.ChildrenOfType(); + private ISkinnableTarget getTarget(SkinnableTarget target) { - return targetScreen.ChildrenOfType().FirstOrDefault(c => c.Target == target); + return availableTargets.FirstOrDefault(c => c.Target == target); } private void revert() { - SkinnableTargetContainer[] targetContainers = targetScreen.ChildrenOfType().ToArray(); + ISkinnableTarget[] targetContainers = availableTargets.ToArray(); foreach (var t in targetContainers) { @@ -216,7 +219,7 @@ namespace osu.Game.Skinning.Editor if (!hasBegunMutating) return; - SkinnableTargetContainer[] targetContainers = targetScreen.ChildrenOfType().ToArray(); + ISkinnableTarget[] targetContainers = availableTargets.ToArray(); foreach (var t in targetContainers) currentSkin.Value.UpdateDrawableTarget(t); @@ -237,5 +240,11 @@ namespace osu.Game.Skinning.Editor { this.FadeOut(TRANSITION_DURATION, Easing.OutQuint); } + + public void DeleteItems(ISkinnableDrawable[] items) + { + foreach (var item in items.ToArray()) + availableTargets.FirstOrDefault(t => t.Components.Contains(item))?.Remove(item); + } } } diff --git a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs index 9bcdc6e08b..7931a5ec41 100644 --- a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs +++ b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using osu.Framework.Allocation; using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; @@ -17,6 +18,9 @@ namespace osu.Game.Skinning.Editor { public class SkinSelectionHandler : SelectionHandler { + [Resolved] + private SkinEditor skinEditor { get; set; } + public override bool HandleRotation(float angle) { // TODO: this doesn't correctly account for origin/anchor specs being different in a multi-selection. @@ -72,14 +76,8 @@ namespace osu.Game.Skinning.Editor SelectionBox.CanReverse = false; } - protected override void DeleteItems(IEnumerable items) - { - foreach (var i in items) - { - ((Drawable)i).Expire(); - SelectedItems.Remove(i); - } - } + protected override void DeleteItems(IEnumerable items) => + skinEditor.DeleteItems(items.ToArray()); protected override IEnumerable GetContextMenuItemsForSelection(IEnumerable> selection) { diff --git a/osu.Game/Skinning/ISkinnableTarget.cs b/osu.Game/Skinning/ISkinnableTarget.cs index 65b8ba7b17..15cad2c817 100644 --- a/osu.Game/Skinning/ISkinnableTarget.cs +++ b/osu.Game/Skinning/ISkinnableTarget.cs @@ -37,8 +37,15 @@ namespace osu.Game.Skinning void Reload(); /// - /// Add the provided item to this target. + /// Add a new skinnable component to this target. /// + /// The component to add. void Add(ISkinnableDrawable drawable); + + /// + /// Remove an existing skinnable component to this target. + /// + /// The component to add. + public void Remove(ISkinnableDrawable component); } } diff --git a/osu.Game/Skinning/SkinnableTargetContainer.cs b/osu.Game/Skinning/SkinnableTargetContainer.cs index a4d7f621eb..f055fb2533 100644 --- a/osu.Game/Skinning/SkinnableTargetContainer.cs +++ b/osu.Game/Skinning/SkinnableTargetContainer.cs @@ -43,10 +43,7 @@ namespace osu.Game.Skinning } } - /// - /// Add a new skinnable component to this target. - /// - /// The component to add. + /// /// Thrown when attempting to add an element to a target which is not supported by the current skin. /// Thrown if the provided instance is not a . public void Add(ISkinnableDrawable component) @@ -61,6 +58,21 @@ namespace osu.Game.Skinning components.Add(component); } + /// + /// Thrown when attempting to add an element to a target which is not supported by the current skin. + /// Thrown if the provided instance is not a . + public void Remove(ISkinnableDrawable component) + { + if (content == null) + throw new NotSupportedException("Attempting to add a new component to a target container which is not supported by the current skin."); + + if (!(component is Drawable drawable)) + throw new ArgumentException($"Provided argument must be of type {nameof(Drawable)}.", nameof(drawable)); + + content.Remove(drawable); + components.Remove(component); + } + protected override void SkinChanged(ISkinSource skin, bool allowFallback) { base.SkinChanged(skin, allowFallback);