2021-04-28 06:14:48 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2021-05-11 08:49:00 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
2021-04-28 06:14:48 +00:00
|
|
|
using System.Linq;
|
2021-05-11 08:49:00 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-04-28 06:14:48 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-05-11 09:37:41 +00:00
|
|
|
using osu.Framework.Screens;
|
2021-04-28 06:14:48 +00:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-05-11 09:37:41 +00:00
|
|
|
using osu.Game.Screens;
|
2021-04-28 06:14:48 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Editor
|
|
|
|
{
|
2021-05-13 08:06:00 +00:00
|
|
|
public class SkinBlueprintContainer : BlueprintContainer<ISkinnableDrawable>
|
2021-04-28 06:14:48 +00:00
|
|
|
{
|
|
|
|
private readonly Drawable target;
|
|
|
|
|
2021-05-13 08:06:00 +00:00
|
|
|
private readonly List<BindableList<ISkinnableDrawable>> targetComponents = new List<BindableList<ISkinnableDrawable>>();
|
2021-05-13 04:03:23 +00:00
|
|
|
|
2022-04-07 10:12:10 +00:00
|
|
|
[Resolved]
|
|
|
|
private SkinEditor editor { get; set; }
|
|
|
|
|
2021-04-28 06:14:48 +00:00
|
|
|
public SkinBlueprintContainer(Drawable target)
|
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-04-07 10:12:10 +00:00
|
|
|
SelectedItems.BindTo(editor.SelectedComponents);
|
|
|
|
|
2021-05-11 08:49:00 +00:00
|
|
|
// track each target container on the current screen.
|
2021-05-12 06:58:21 +00:00
|
|
|
var targetContainers = target.ChildrenOfType<ISkinnableTarget>().ToArray();
|
2021-05-11 09:37:41 +00:00
|
|
|
|
|
|
|
if (targetContainers.Length == 0)
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
string targetScreen = target.ChildrenOfType<Screen>().LastOrDefault()?.GetType().Name ?? "this screen";
|
2021-05-11 09:37:41 +00:00
|
|
|
|
|
|
|
AddInternal(new ScreenWhiteBox.UnderConstructionMessage(targetScreen, "doesn't support skin customisation just yet."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var targetContainer in targetContainers)
|
2021-05-11 08:49:00 +00:00
|
|
|
{
|
2021-05-13 08:06:00 +00:00
|
|
|
var bindableList = new BindableList<ISkinnableDrawable> { BindTarget = targetContainer.Components };
|
2021-05-11 08:49:00 +00:00
|
|
|
bindableList.BindCollectionChanged(componentsChanged, true);
|
|
|
|
|
|
|
|
targetComponents.Add(bindableList);
|
|
|
|
}
|
2021-04-28 09:59:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 10:12:10 +00:00
|
|
|
private void componentsChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() =>
|
2021-04-28 09:59:55 +00:00
|
|
|
{
|
2021-05-11 08:49:00 +00:00
|
|
|
switch (e.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
2021-05-13 08:06:00 +00:00
|
|
|
foreach (var item in e.NewItems.Cast<ISkinnableDrawable>())
|
2021-05-11 08:49:00 +00:00
|
|
|
AddBlueprintFor(item);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
|
|
|
case NotifyCollectionChangedAction.Reset:
|
2021-05-13 08:06:00 +00:00
|
|
|
foreach (var item in e.OldItems.Cast<ISkinnableDrawable>())
|
2021-05-11 08:49:00 +00:00
|
|
|
RemoveBlueprintFor(item);
|
|
|
|
break;
|
2021-05-06 06:16:16 +00:00
|
|
|
|
2021-05-11 08:49:00 +00:00
|
|
|
case NotifyCollectionChangedAction.Replace:
|
2021-05-13 08:06:00 +00:00
|
|
|
foreach (var item in e.OldItems.Cast<ISkinnableDrawable>())
|
2021-05-11 08:49:00 +00:00
|
|
|
RemoveBlueprintFor(item);
|
2021-04-28 06:14:48 +00:00
|
|
|
|
2021-05-13 08:06:00 +00:00
|
|
|
foreach (var item in e.NewItems.Cast<ISkinnableDrawable>())
|
2021-05-11 08:49:00 +00:00
|
|
|
AddBlueprintFor(item);
|
|
|
|
break;
|
|
|
|
}
|
2022-04-07 10:12:10 +00:00
|
|
|
});
|
2021-04-28 06:14:48 +00:00
|
|
|
|
2021-05-13 08:06:00 +00:00
|
|
|
protected override void AddBlueprintFor(ISkinnableDrawable item)
|
2021-05-13 08:03:17 +00:00
|
|
|
{
|
|
|
|
if (!item.IsEditable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base.AddBlueprintFor(item);
|
|
|
|
}
|
|
|
|
|
2021-05-13 08:06:00 +00:00
|
|
|
protected override SelectionHandler<ISkinnableDrawable> CreateSelectionHandler() => new SkinSelectionHandler();
|
2021-04-28 06:14:48 +00:00
|
|
|
|
2021-05-13 08:06:00 +00:00
|
|
|
protected override SelectionBlueprint<ISkinnableDrawable> CreateBlueprintFor(ISkinnableDrawable component)
|
2021-04-28 06:14:48 +00:00
|
|
|
=> new SkinBlueprint(component);
|
2022-04-07 10:12:10 +00:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
foreach (var list in targetComponents)
|
|
|
|
list.UnbindAll();
|
|
|
|
}
|
2021-04-28 06:14:48 +00:00
|
|
|
}
|
|
|
|
}
|