1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 10:23:04 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/ControlPointSettings.cs

151 lines
4.6 KiB
C#

// 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.Collections.Generic;
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;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Timing
{
public class ControlPointSettings : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
RelativeSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new Box
{
Colour = colours.Gray3,
RelativeSizeAxes = Axes.Both,
},
new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(30),
Children = createSections()
},
}
};
}
private IReadOnlyList<Drawable> createSections() => new Drawable[]
{
new TimingSection(),
new DifficultySection(),
new SampleSection(),
new EffectSection(),
};
private class TimingSection : Section<TimingControlPoint>
{
}
private class DifficultySection : Section<DifficultyControlPoint>
{
}
private class SampleSection : Section<SampleControlPoint>
{
}
private class EffectSection : Section<EffectControlPoint>
{
}
private class Section<T> : Container
where T : ControlPoint
{
private const float header_height = 20;
protected override Container<Drawable> Content { get; }
[Resolved]
private Bindable<IEnumerable<ControlPoint>> selectedPoints { get; set; }
protected Section()
{
RelativeSizeAxes = Axes.X;
AutoSizeDuration = 200;
AutoSizeEasing = Easing.OutQuint;
AutoSizeAxes = Axes.Y;
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
Colour = Color4.Gray,
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.X,
Height = header_height,
Children = new Drawable[]
{
new OsuSpriteText
{
Text = typeof(T).Name.Replace(typeof(ControlPoint).Name, string.Empty)
},
}
},
Content = new Container()
{
Y = header_height,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
Colour = Color4.DarkGray,
RelativeSizeAxes = Axes.X,
Height = 100,
},
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
selectedPoints.BindValueChanged(points =>
{
var matching = points.NewValue?.OfType<T>().Where(p => !p.AutoGenerated).FirstOrDefault();
if (matching != null)
{
Content.BypassAutoSizeAxes = Axes.None;
}
else
{
Content.BypassAutoSizeAxes = Axes.Y;
}
}, true);
}
}
}
}