2019-12-05 18:31:40 +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-01-15 18:09:49 +08:00
|
|
|
using System;
|
2019-12-05 18:31:40 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-15 18:09:49 +08:00
|
|
|
using osu.Framework.Graphics.Primitives;
|
2019-12-05 18:31:40 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-01-15 18:09:49 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2020-01-20 23:53:59 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2019-12-05 18:31:40 +08:00
|
|
|
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
|
|
|
|
{
|
2020-01-02 18:09:37 +08:00
|
|
|
internal class TimelineHitObjectDisplay : BlueprintContainer
|
2019-12-05 18:31:40 +08:00
|
|
|
{
|
2020-01-22 15:33:23 +08:00
|
|
|
private DragEvent lastDragEvent;
|
|
|
|
|
2019-12-27 18:46:33 +08:00
|
|
|
public TimelineHitObjectDisplay(EditorBeatmap beatmap)
|
2019-12-05 19:12:25 +08:00
|
|
|
{
|
2019-12-06 10:26:50 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2020-01-22 13:58:15 +08:00
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
Height = 0.4f;
|
|
|
|
|
|
|
|
AddInternal(new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Black,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0.1f,
|
|
|
|
});
|
2019-12-05 19:12:25 +08:00
|
|
|
}
|
2019-12-05 18:31:40 +08:00
|
|
|
|
2020-01-20 23:53:59 +08:00
|
|
|
protected override SelectionBlueprintContainer CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
2020-01-15 18:09:49 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
DragBox.Alpha = 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 14:42:49 +08:00
|
|
|
protected override bool OnDrag(DragEvent e)
|
|
|
|
{
|
|
|
|
lastDragEvent = e;
|
|
|
|
return base.OnDrag(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
2019-12-05 18:31:40 +08:00
|
|
|
{
|
2020-01-22 15:33:23 +08:00
|
|
|
// trigger every frame so drags continue to update selection while playback is scrolling the timeline.
|
|
|
|
if (IsDragged)
|
|
|
|
OnDrag(lastDragEvent);
|
2019-12-05 18:31:40 +08:00
|
|
|
|
2020-01-22 14:42:49 +08:00
|
|
|
base.Update();
|
2019-12-05 22:31:21 +08:00
|
|
|
}
|
2019-12-05 18:31:40 +08:00
|
|
|
|
2020-01-22 15:58:33 +08:00
|
|
|
protected override SelectionBlueprint CreateBlueprintFor(HitObject hitObject) => new TimelineHitObjectBlueprint(hitObject);
|
2020-01-22 14:42:49 +08:00
|
|
|
|
2020-01-22 15:58:33 +08:00
|
|
|
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new TimelineDragBox(performSelect);
|
2020-01-22 13:58:15 +08:00
|
|
|
|
2020-01-22 15:58:33 +08:00
|
|
|
private class TimelineDragBox : DragBox
|
2020-01-15 18:09:49 +08:00
|
|
|
{
|
2020-01-22 14:58:03 +08:00
|
|
|
private Vector2 lastMouseDown;
|
|
|
|
private float localMouseDown;
|
|
|
|
|
2020-01-22 15:58:33 +08:00
|
|
|
public TimelineDragBox(Action<RectangleF> performSelect)
|
2020-01-15 18:09:49 +08:00
|
|
|
: base(performSelect)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-22 13:58:15 +08:00
|
|
|
protected override Drawable CreateBox() => new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Alpha = 0.3f
|
|
|
|
};
|
|
|
|
|
|
|
|
public override bool UpdateDrag(MouseButtonEvent e)
|
|
|
|
{
|
2020-01-22 14:58:03 +08:00
|
|
|
// store the original position of the mouse down, as we may be scrolled during selection.
|
|
|
|
if (lastMouseDown != e.ScreenSpaceMouseDownPosition)
|
|
|
|
{
|
|
|
|
lastMouseDown = e.ScreenSpaceMouseDownPosition;
|
|
|
|
localMouseDown = e.MouseDownPosition.X;
|
|
|
|
}
|
|
|
|
|
|
|
|
float selection1 = localMouseDown;
|
2020-01-22 13:58:15 +08:00
|
|
|
float selection2 = e.MousePosition.X;
|
|
|
|
|
|
|
|
Box.X = Math.Min(selection1, selection2);
|
|
|
|
Box.Width = Math.Abs(selection1 - selection2);
|
|
|
|
|
|
|
|
PerformSelection?.Invoke(Box.ScreenSpaceDrawQuad.AABBFloat);
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-15 18:09:49 +08:00
|
|
|
}
|
|
|
|
|
2020-01-22 14:42:49 +08:00
|
|
|
protected class TimelineSelectionBlueprintContainer : SelectionBlueprintContainer
|
|
|
|
{
|
|
|
|
protected override Container<SelectionBlueprint> Content { get; }
|
|
|
|
|
|
|
|
public TimelineSelectionBlueprintContainer()
|
|
|
|
{
|
|
|
|
AddInternal(new TimelinePart<SelectionBlueprint>(Content = new Container<SelectionBlueprint> { RelativeSizeAxes = Axes.Both }) { RelativeSizeAxes = Axes.Both });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 15:58:33 +08:00
|
|
|
private class TimelineHitObjectBlueprint : SelectionBlueprint
|
2019-12-05 18:31:40 +08:00
|
|
|
{
|
2020-01-21 19:54:50 +08:00
|
|
|
private readonly Circle circle;
|
2020-01-21 13:21:00 +08:00
|
|
|
|
2020-01-22 14:42:49 +08:00
|
|
|
private readonly Container extensionBar;
|
2020-01-22 14:31:58 +08:00
|
|
|
|
2019-12-06 09:48:18 +08:00
|
|
|
public const float THICKNESS = 3;
|
|
|
|
|
2020-01-21 21:24:04 +08:00
|
|
|
private const float circle_size = 16;
|
|
|
|
|
2020-01-21 16:37:35 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => base.ReceivePositionalInputAt(screenSpacePos) || circle.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
2020-01-22 15:58:33 +08:00
|
|
|
public TimelineHitObjectBlueprint(HitObject hitObject)
|
2020-01-20 23:53:59 +08:00
|
|
|
: base(hitObject)
|
2019-12-05 18:31:40 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
Width = (float)(hitObject.GetEndTime() - hitObject.StartTime);
|
|
|
|
|
|
|
|
X = (float)hitObject.StartTime;
|
|
|
|
|
|
|
|
RelativePositionAxes = Axes.X;
|
2020-01-22 14:31:58 +08:00
|
|
|
|
2019-12-05 18:31:40 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
2020-01-22 14:31:58 +08:00
|
|
|
AutoSizeAxes = Axes.Y;
|
2019-12-05 18:31:40 +08:00
|
|
|
|
|
|
|
if (hitObject is IHasEndTime)
|
|
|
|
{
|
2020-01-22 14:31:58 +08:00
|
|
|
AddInternal(extensionBar = new Container
|
2019-12-05 18:31:40 +08:00
|
|
|
{
|
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),
|
2019-12-05 18:31:40 +08:00
|
|
|
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 18:31:40 +08:00
|
|
|
});
|
|
|
|
}
|
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
|
|
|
{
|
2020-01-21 21:24:04 +08:00
|
|
|
Size = new Vector2(circle_size),
|
2019-12-05 22:31:21 +08:00
|
|
|
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
|
|
|
});
|
2019-12-05 18:31:40 +08:00
|
|
|
}
|
2020-01-21 13:21:00 +08:00
|
|
|
|
2020-01-22 14:31:58 +08:00
|
|
|
protected override void OnSelected()
|
|
|
|
{
|
|
|
|
circle.BorderColour = Color4.Orange;
|
|
|
|
if (extensionBar != null)
|
|
|
|
extensionBar.Colour = Color4.Orange;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDeselected()
|
|
|
|
{
|
|
|
|
circle.BorderColour = Color4.Black;
|
|
|
|
if (extensionBar != null)
|
|
|
|
extensionBar.Colour = Color4.Black;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Quad SelectionQuad
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
// correctly include the circle in the selection quad region, as it is usually outside the blueprint itself.
|
|
|
|
var circleQuad = circle.ScreenSpaceDrawQuad;
|
|
|
|
var actualQuad = ScreenSpaceDrawQuad;
|
2020-01-21 13:21:00 +08:00
|
|
|
|
2020-01-22 14:31:58 +08:00
|
|
|
return new Quad(circleQuad.TopLeft, Vector2.ComponentMax(actualQuad.TopRight, circleQuad.TopRight),
|
|
|
|
circleQuad.BottomLeft, Vector2.ComponentMax(actualQuad.BottomRight, circleQuad.BottomRight));
|
|
|
|
}
|
|
|
|
}
|
2019-12-05 18:31:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|