2021-04-28 14:14:48 +08: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 16:49:00 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
2021-04-28 14:14:48 +08:00
|
|
|
using System.Linq;
|
2021-05-11 16:49:00 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-04-28 14:14:48 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2021-05-11 16:49:00 +08:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2021-04-28 14:14:48 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Editor
|
|
|
|
{
|
2021-04-28 17:34:34 +08:00
|
|
|
public class SkinBlueprintContainer : BlueprintContainer<ISkinnableComponent>
|
2021-04-28 14:14:48 +08:00
|
|
|
{
|
|
|
|
private readonly Drawable target;
|
|
|
|
|
|
|
|
public SkinBlueprintContainer(Drawable target)
|
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
2021-05-11 16:49:00 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(SkinEditor editor)
|
|
|
|
{
|
|
|
|
SelectedItems.BindTo(editor.SelectedComponents);
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly List<BindableList<ISkinnableComponent>> targetComponents = new List<BindableList<ISkinnableComponent>>();
|
|
|
|
|
2021-04-28 14:14:48 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-05-11 16:49:00 +08:00
|
|
|
// track each target container on the current screen.
|
|
|
|
foreach (var targetContainer in target.ChildrenOfType<SkinnableElementTargetContainer>())
|
|
|
|
{
|
|
|
|
var bindableList = new BindableList<ISkinnableComponent> { BindTarget = targetContainer.Components };
|
|
|
|
bindableList.BindCollectionChanged(componentsChanged, true);
|
|
|
|
|
|
|
|
targetComponents.Add(bindableList);
|
|
|
|
}
|
2021-04-28 17:59:55 +08:00
|
|
|
}
|
|
|
|
|
2021-05-11 16:49:00 +08:00
|
|
|
private void componentsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
2021-04-28 17:59:55 +08:00
|
|
|
{
|
2021-05-11 16:49:00 +08:00
|
|
|
switch (e.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
|
|
|
foreach (var item in e.NewItems.Cast<ISkinnableComponent>())
|
|
|
|
AddBlueprintFor(item);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
|
|
|
case NotifyCollectionChangedAction.Reset:
|
|
|
|
foreach (var item in e.OldItems.Cast<ISkinnableComponent>())
|
|
|
|
RemoveBlueprintFor(item);
|
|
|
|
break;
|
2021-05-06 14:16:16 +08:00
|
|
|
|
2021-05-11 16:49:00 +08:00
|
|
|
case NotifyCollectionChangedAction.Replace:
|
|
|
|
foreach (var item in e.OldItems.Cast<ISkinnableComponent>())
|
|
|
|
RemoveBlueprintFor(item);
|
2021-04-28 14:14:48 +08:00
|
|
|
|
2021-05-11 16:49:00 +08:00
|
|
|
foreach (var item in e.NewItems.Cast<ISkinnableComponent>())
|
|
|
|
AddBlueprintFor(item);
|
|
|
|
break;
|
|
|
|
}
|
2021-04-28 14:14:48 +08:00
|
|
|
}
|
|
|
|
|
2021-04-28 17:34:34 +08:00
|
|
|
protected override SelectionHandler<ISkinnableComponent> CreateSelectionHandler() => new SkinSelectionHandler();
|
2021-04-28 14:14:48 +08:00
|
|
|
|
2021-04-28 17:34:34 +08:00
|
|
|
protected override SelectionBlueprint<ISkinnableComponent> CreateBlueprintFor(ISkinnableComponent component)
|
2021-04-28 14:14:48 +08:00
|
|
|
=> new SkinBlueprint(component);
|
|
|
|
}
|
|
|
|
}
|