1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-20 00:12:57 +08:00
osu-lazer/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectDisplay.cs

109 lines
3.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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
internal class TimelineHitObjectDisplay : TimelinePart
{
2019-12-05 19:12:25 +08:00
private IEditorBeatmap beatmap { get; }
public TimelineHitObjectDisplay(IEditorBeatmap beatmap)
{
2019-12-06 10:26:50 +08:00
RelativeSizeAxes = Axes.Both;
2019-12-05 19:12:25 +08:00
this.beatmap = beatmap;
}
[BackgroundDependencyLoader]
private void load()
{
foreach (var h in beatmap.HitObjects)
add(h);
beatmap.HitObjectAdded += add;
beatmap.HitObjectRemoved += remove;
2019-12-05 19:12:25 +08:00
beatmap.StartTimeChanged += h =>
{
remove(h);
add(h);
};
}
private void remove(HitObject h)
{
2019-12-05 19:12:25 +08:00
foreach (var d in Children.OfType<TimelineHitObjectRepresentation>().Where(c => c.HitObject == h))
d.Expire();
}
2019-12-05 22:31:21 +08:00
private void add(HitObject h)
{
var yOffset = Children.Count(d => d.X == h.StartTime);
2019-12-06 09:48:18 +08:00
Add(new TimelineHitObjectRepresentation(h) { Y = -yOffset * TimelineHitObjectRepresentation.THICKNESS });
2019-12-05 22:31:21 +08:00
}
private class TimelineHitObjectRepresentation : CompositeDrawable
{
2019-12-06 09:48:18 +08:00
public const float THICKNESS = 3;
public readonly HitObject HitObject;
public TimelineHitObjectRepresentation(HitObject hitObject)
{
2019-12-05 22:31:21 +08:00
HitObject = hitObject;
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
Width = (float)(hitObject.GetEndTime() - hitObject.StartTime);
X = (float)hitObject.StartTime;
RelativePositionAxes = Axes.X;
RelativeSizeAxes = Axes.X;
if (hitObject is IHasEndTime)
{
2019-12-05 22:31:21 +08:00
AddInternal(new Container
{
2019-12-05 22:31:21 +08:00
CornerRadius = 2,
Masking = true,
2019-12-06 09:48:18 +08:00
Size = new Vector2(1, THICKNESS),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativePositionAxes = Axes.X,
RelativeSizeAxes = Axes.X,
2019-12-05 22:31:21 +08:00
Colour = Color4.Black,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
}
});
}
2019-12-05 22:31:21 +08:00
AddInternal(new Circle
{
Size = new Vector2(16),
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.X,
AlwaysPresent = true,
Colour = Color4.White,
BorderColour = Color4.Black,
2019-12-06 09:48:18 +08:00
BorderThickness = THICKNESS,
2019-12-05 22:31:21 +08:00
});
}
}
}
}