2019-06-18 14:53:03 +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.
|
|
|
|
|
2020-02-17 14:06:14 +08:00
|
|
|
using System.Collections.Specialized;
|
|
|
|
using System.Linq;
|
2019-06-18 16:59:33 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2019-06-18 14:53:03 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-05-16 09:07:27 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-06-18 14:53:03 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-06-18 16:59:33 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
2019-06-18 14:53:03 +08:00
|
|
|
using osu.Game.Tournament.Components;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Editors
|
|
|
|
{
|
2020-05-17 16:35:10 +08:00
|
|
|
public abstract class TournamentEditorScreen<TDrawable, TModel> : TournamentScreen, IProvideVideo
|
2019-06-18 16:59:33 +08:00
|
|
|
where TDrawable : Drawable, IModelBacked<TModel>
|
|
|
|
where TModel : class, new()
|
2019-06-18 14:53:03 +08:00
|
|
|
{
|
2019-06-18 16:59:33 +08:00
|
|
|
protected abstract BindableList<TModel> Storage { get; }
|
2019-06-18 14:53:03 +08:00
|
|
|
|
2019-06-18 16:59:33 +08:00
|
|
|
private FillFlowContainer<TDrawable> flow;
|
|
|
|
|
2020-05-16 09:07:27 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private TournamentSceneManager sceneManager { get; set; }
|
|
|
|
|
2019-06-18 16:59:33 +08:00
|
|
|
protected ControlPanel ControlPanel;
|
|
|
|
|
2020-05-16 18:50:56 +08:00
|
|
|
private readonly TournamentScreen parentScreen;
|
2020-05-16 09:07:27 +08:00
|
|
|
private BackButton backButton;
|
|
|
|
|
2020-05-16 18:50:56 +08:00
|
|
|
protected TournamentEditorScreen(TournamentScreen parentScreen = null)
|
|
|
|
{
|
|
|
|
this.parentScreen = parentScreen;
|
|
|
|
}
|
2020-05-16 09:07:27 +08:00
|
|
|
|
2019-06-18 16:59:33 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2019-06-18 14:53:03 +08:00
|
|
|
{
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(0.2f),
|
|
|
|
},
|
|
|
|
new OsuScrollContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2019-06-18 16:59:33 +08:00
|
|
|
Child = flow = new FillFlowContainer<TDrawable>
|
2019-06-18 14:53:03 +08:00
|
|
|
{
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-05-17 16:25:26 +08:00
|
|
|
Spacing = new Vector2(20),
|
2019-06-18 14:53:03 +08:00
|
|
|
},
|
|
|
|
},
|
2019-06-18 16:59:33 +08:00
|
|
|
ControlPanel = new ControlPanel
|
2019-06-18 14:53:03 +08:00
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2019-11-08 16:00:47 +08:00
|
|
|
new TourneyButton
|
2019-06-18 14:53:03 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Add new",
|
2019-06-18 16:59:33 +08:00
|
|
|
Action = () => Storage.Add(new TModel())
|
|
|
|
},
|
|
|
|
new DangerousSettingsButton
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = "Clear all",
|
|
|
|
Action = Storage.Clear
|
2019-06-18 14:53:03 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-06-18 16:59:33 +08:00
|
|
|
|
2020-05-16 18:50:56 +08:00
|
|
|
if (parentScreen != null)
|
2020-05-17 16:27:52 +08:00
|
|
|
{
|
2020-05-17 16:35:10 +08:00
|
|
|
AddInternal(backButton = new BackButton
|
2020-05-17 16:27:52 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
State = { Value = Visibility.Visible },
|
2020-05-17 16:35:10 +08:00
|
|
|
Action = () => sceneManager?.SetScreen(parentScreen.GetType())
|
2020-05-17 16:27:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
flow.Padding = new MarginPadding { Bottom = backButton.Height * 2 };
|
|
|
|
}
|
2020-05-16 09:07:27 +08:00
|
|
|
|
2020-02-17 14:06:14 +08:00
|
|
|
Storage.CollectionChanged += (_, args) =>
|
|
|
|
{
|
|
|
|
switch (args.Action)
|
|
|
|
{
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
|
|
|
args.NewItems.Cast<TModel>().ForEach(i => flow.Add(CreateDrawable(i)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
|
|
|
args.OldItems.Cast<TModel>().ForEach(i => flow.RemoveAll(d => d.Model == i));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2019-06-18 16:59:33 +08:00
|
|
|
|
|
|
|
foreach (var model in Storage)
|
|
|
|
flow.Add(CreateDrawable(model));
|
2019-06-18 14:53:03 +08:00
|
|
|
}
|
|
|
|
|
2019-06-18 16:59:33 +08:00
|
|
|
protected abstract TDrawable CreateDrawable(TModel model);
|
2019-06-18 14:53:03 +08:00
|
|
|
}
|
|
|
|
}
|