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
|
|
|
|
2021-04-28 06:14:48 +00:00
|
|
|
public SkinBlueprintContainer(Drawable target)
|
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
2021-05-11 08:49:00 +00:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(SkinEditor editor)
|
|
|
|
{
|
|
|
|
SelectedItems.BindTo(editor.SelectedComponents);
|
|
|
|
}
|
|
|
|
|
2021-04-28 06:14:48 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-05-11 08:49:00 +00:00
|
|
|
private void componentsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
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;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|