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

128 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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
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 : BlueprintContainer
{
public TimelineHitObjectDisplay(EditorBeatmap beatmap)
2019-12-05 19:12:25 +08:00
{
2019-12-06 10:26:50 +08:00
RelativeSizeAxes = Axes.Both;
2019-12-05 19:12:25 +08:00
}
protected override SelectionBlueprintContainer CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both };
protected class TimelineSelectionBlueprintContainer : SelectionBlueprintContainer
{
protected override Container<SelectionBlueprint> Content { get; }
public TimelineSelectionBlueprintContainer()
2019-12-05 19:12:25 +08:00
{
AddInternal(new TimelinePart<SelectionBlueprint>(Content = new Container<SelectionBlueprint> { RelativeSizeAxes = Axes.Both }) { RelativeSizeAxes = Axes.Both });
}
}
protected override void LoadComplete()
{
base.LoadComplete();
DragBox.Alpha = 0;
}
protected override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
{
//var yOffset = content.Count(d => d.X == h.StartTime);
var yOffset = 0;
return new TimelineHitObjectRepresentation(hitObject) { Y = -yOffset * TimelineHitObjectRepresentation.THICKNESS };
2019-12-05 22:31:21 +08:00
}
protected override bool OnMouseDown(MouseDownEvent e)
{
base.OnMouseDown(e);
return false; // temporary until we correctly handle selections.
}
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new NoDragDragBox(performSelect);
internal class NoDragDragBox : DragBox
{
public NoDragDragBox(Action<RectangleF> performSelect)
: base(performSelect)
{
}
public override bool UpdateDrag(MouseButtonEvent e) => false;
}
private class TimelineHitObjectRepresentation : SelectionBlueprint
{
2020-01-21 13:21:00 +08:00
private Circle circle;
2019-12-06 09:48:18 +08:00
public const float THICKNESS = 3;
public TimelineHitObjectRepresentation(HitObject hitObject)
: base(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
2020-01-21 13:21:00 +08:00
AddInternal(circle = new Circle
2019-12-05 22:31:21 +08:00
{
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
});
}
2020-01-21 13:21:00 +08:00
protected override void OnSelected() => circle.BorderColour = Color4.Orange;
protected override void OnDeselected() => circle.BorderColour = Color4.Black;
}
}
}