1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 08:02:54 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/Section.cs

134 lines
4.4 KiB
C#
Raw Normal View History

// 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.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Screens.Edit.Timing
{
2022-11-24 13:32:20 +08:00
internal abstract partial class Section<T> : CompositeDrawable
where T : ControlPoint
{
2023-01-14 07:23:21 +08:00
private OsuCheckbox checkbox = null!;
private Container content = null!;
2023-01-14 07:23:21 +08:00
protected FillFlowContainer Flow { get; private set; } = null!;
2023-01-14 07:23:21 +08:00
protected Bindable<T?> ControlPoint { get; } = new Bindable<T?>();
private const float header_height = 50;
[Resolved]
2023-01-14 07:23:21 +08:00
protected EditorBeatmap Beatmap { get; private set; } = null!;
[Resolved]
2023-01-14 07:23:21 +08:00
protected Bindable<ControlPointGroup> SelectedGroup { get; private set; } = null!;
2023-01-14 07:23:21 +08:00
[Resolved]
protected IEditorChangeHandler? ChangeHandler { get; private set; }
2020-10-02 16:55:47 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colours)
{
RelativeSizeAxes = Axes.X;
AutoSizeDuration = 200;
AutoSizeEasing = Easing.OutQuint;
AutoSizeAxes = Axes.Y;
Masking = true;
CornerRadius = 5;
InternalChildren = new Drawable[]
{
new Box
{
Colour = colours.Background4,
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.X,
Height = header_height,
Padding = new MarginPadding { Horizontal = 10 },
Children = new Drawable[]
{
checkbox = new OsuCheckbox
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
LabelText = typeof(T).Name.Replace(nameof(Beatmaps.ControlPoints.ControlPoint), string.Empty)
}
}
},
content = new Container
{
Y = header_height,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
Flow = new FillFlowContainer
{
Padding = new MarginPadding(10) { Top = 0 },
Spacing = new Vector2(20),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
checkbox.Current.BindValueChanged(selected =>
{
if (selected.NewValue)
{
if (SelectedGroup.Value == null)
{
checkbox.Current.Value = false;
return;
}
if (ControlPoint.Value == null)
SelectedGroup.Value.Add(ControlPoint.Value = CreatePoint());
}
else
{
if (ControlPoint.Value != null)
{
SelectedGroup.Value.Remove(ControlPoint.Value);
ControlPoint.Value = null;
}
}
content.BypassAutoSizeAxes = selected.NewValue ? Axes.None : Axes.Y;
}, true);
SelectedGroup.BindValueChanged(points =>
{
ControlPoint.Value = points.NewValue?.ControlPoints.OfType<T>().FirstOrDefault();
checkbox.Current.Value = ControlPoint.Value != null;
}, true);
ControlPoint.BindValueChanged(OnControlPointChanged, true);
}
2023-01-14 07:23:21 +08:00
protected abstract void OnControlPointChanged(ValueChangedEvent<T?> point);
protected abstract T CreatePoint();
}
}