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;
|
2020-01-23 11:29:32 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-02-07 17:04:10 +08:00
|
|
|
using osu.Framework.Bindables;
|
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-11-02 04:22:04 +08:00
|
|
|
using osu.Framework.Utils;
|
2020-12-21 17:10:11 +08:00
|
|
|
using osu.Game.Graphics;
|
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.Screens.Edit.Components.Timelines.Summary.Parts;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
2020-01-23 11:17:46 +08:00
|
|
|
internal class TimelineBlueprintContainer : BlueprintContainer
|
2019-12-05 18:31:40 +08:00
|
|
|
{
|
2020-01-23 11:29:32 +08:00
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
private Timeline timeline { get; set; }
|
|
|
|
|
2020-02-07 17:04:10 +08:00
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap beatmap { get; set; }
|
|
|
|
|
2020-12-21 17:10:11 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2020-01-22 15:33:23 +08:00
|
|
|
private DragEvent lastDragEvent;
|
2020-02-07 17:04:10 +08:00
|
|
|
private Bindable<HitObject> placement;
|
|
|
|
private SelectionBlueprint placementBlueprint;
|
|
|
|
|
2020-12-21 17:10:11 +08:00
|
|
|
private readonly Box backgroundBox;
|
|
|
|
|
2020-11-12 18:52:02 +08:00
|
|
|
public TimelineBlueprintContainer(HitObjectComposer composer)
|
|
|
|
: base(composer)
|
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;
|
|
|
|
|
2020-12-21 17:09:56 +08:00
|
|
|
Height = 0.6f;
|
2020-01-22 13:58:15 +08:00
|
|
|
|
2020-12-21 17:10:11 +08:00
|
|
|
AddInternal(backgroundBox = new Box
|
2020-01-22 13:58:15 +08:00
|
|
|
{
|
|
|
|
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-15 18:09:49 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
DragBox.Alpha = 0;
|
2020-02-07 17:04:10 +08:00
|
|
|
|
|
|
|
placement = beatmap.PlacementObject.GetBoundCopy();
|
|
|
|
placement.ValueChanged += placementChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void placementChanged(ValueChangedEvent<HitObject> obj)
|
|
|
|
{
|
|
|
|
if (obj.NewValue == null)
|
|
|
|
{
|
|
|
|
if (placementBlueprint != null)
|
|
|
|
{
|
|
|
|
SelectionBlueprints.Remove(placementBlueprint);
|
|
|
|
placementBlueprint = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
placementBlueprint = CreateBlueprintFor(obj.NewValue);
|
|
|
|
|
|
|
|
placementBlueprint.Colour = Color4.MediumPurple;
|
|
|
|
|
|
|
|
SelectionBlueprints.Add(placementBlueprint);
|
|
|
|
}
|
2020-01-15 18:09:49 +08:00
|
|
|
}
|
|
|
|
|
2020-11-18 12:33:22 +08:00
|
|
|
protected override Container<SelectionBlueprint> CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both };
|
2020-01-24 16:50:36 +08:00
|
|
|
|
2020-12-21 17:10:11 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
backgroundBox.FadeColour(colours.BlueLighter, 120, Easing.OutQuint);
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
backgroundBox.FadeColour(Color4.Black, 600, Easing.OutQuint);
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
2020-01-23 14:37:54 +08:00
|
|
|
protected override void OnDrag(DragEvent e)
|
2020-01-22 14:42:49 +08:00
|
|
|
{
|
2020-02-05 14:58:35 +08:00
|
|
|
handleScrollViaDrag(e);
|
2020-01-23 11:29:32 +08:00
|
|
|
|
2020-01-23 14:37:54 +08:00
|
|
|
base.OnDrag(e);
|
2020-01-22 14:42:49 +08:00
|
|
|
}
|
|
|
|
|
2020-01-23 14:37:54 +08:00
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
2020-01-22 16:54:11 +08:00
|
|
|
{
|
2020-01-23 14:37:54 +08:00
|
|
|
base.OnDragEnd(e);
|
2020-01-22 16:54:11 +08:00
|
|
|
lastDragEvent = null;
|
|
|
|
}
|
|
|
|
|
2020-01-22 14:42:49 +08:00
|
|
|
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.
|
2020-02-05 14:58:35 +08:00
|
|
|
if (lastDragEvent != null)
|
2020-01-22 15:33:23 +08:00
|
|
|
OnDrag(lastDragEvent);
|
2019-12-05 18:31:40 +08:00
|
|
|
|
2020-11-14 21:48:48 +08:00
|
|
|
if (Composer != null && timeline != null)
|
2020-11-13 16:10:29 +08:00
|
|
|
{
|
|
|
|
Composer.Playfield.PastLifetimeExtension = timeline.VisibleRange / 2;
|
|
|
|
Composer.Playfield.FutureLifetimeExtension = timeline.VisibleRange / 2;
|
|
|
|
}
|
|
|
|
|
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 20:37:06 +08:00
|
|
|
protected override SelectionHandler CreateSelectionHandler() => new TimelineSelectionHandler();
|
|
|
|
|
2020-02-05 14:58:35 +08:00
|
|
|
protected override SelectionBlueprint CreateBlueprintFor(HitObject hitObject) => new TimelineHitObjectBlueprint(hitObject)
|
|
|
|
{
|
|
|
|
OnDragHandled = handleScrollViaDrag
|
|
|
|
};
|
2020-01-23 15:23:42 +08:00
|
|
|
|
2020-11-02 04:22:04 +08:00
|
|
|
protected override DragBox CreateDragBox(Action<RectangleF> performSelect) => new TimelineDragBox(performSelect);
|
2020-01-23 15:23:42 +08:00
|
|
|
|
2020-02-05 14:58:35 +08:00
|
|
|
private void handleScrollViaDrag(DragEvent e)
|
|
|
|
{
|
|
|
|
lastDragEvent = e;
|
|
|
|
|
|
|
|
if (lastDragEvent == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (timeline != null)
|
|
|
|
{
|
|
|
|
var timelineQuad = timeline.ScreenSpaceDrawQuad;
|
|
|
|
var mouseX = e.ScreenSpaceMousePosition.X;
|
|
|
|
|
|
|
|
// scroll if in a drag and dragging outside visible extents
|
|
|
|
if (mouseX > timelineQuad.TopRight.X)
|
|
|
|
timeline.ScrollBy((float)((mouseX - timelineQuad.TopRight.X) / 10 * Clock.ElapsedFrameTime));
|
|
|
|
else if (mouseX < timelineQuad.TopLeft.X)
|
|
|
|
timeline.ScrollBy((float)((mouseX - timelineQuad.TopLeft.X) / 10 * Clock.ElapsedFrameTime));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 20:37:06 +08:00
|
|
|
internal class TimelineSelectionHandler : SelectionHandler
|
|
|
|
{
|
2020-01-23 15:23:42 +08:00
|
|
|
// for now we always allow movement. snapping is provided by the Timeline's "distance" snap implementation
|
2020-01-22 20:37:06 +08:00
|
|
|
public override bool HandleMovement(MoveSelectionEvent moveEvent) => true;
|
|
|
|
}
|
|
|
|
|
2020-01-22 15:58:33 +08:00
|
|
|
private class TimelineDragBox : DragBox
|
2020-01-15 18:09:49 +08:00
|
|
|
{
|
2020-11-02 04:22:04 +08:00
|
|
|
// the following values hold the start and end X positions of the drag box in the timeline's local space,
|
|
|
|
// but with zoom unapplied in order to be able to compensate for positional changes
|
|
|
|
// while the timeline is being zoomed in/out.
|
|
|
|
private float? selectionStart;
|
|
|
|
private float selectionEnd;
|
2020-10-27 19:39:50 +08:00
|
|
|
|
2020-11-02 04:22:04 +08:00
|
|
|
[Resolved]
|
|
|
|
private Timeline timeline { get; set; }
|
2020-01-22 14:58:03 +08:00
|
|
|
|
2020-11-02 04:22:04 +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
|
|
|
|
};
|
|
|
|
|
2020-01-22 16:54:11 +08:00
|
|
|
public override bool HandleDrag(MouseButtonEvent e)
|
2020-01-22 13:58:15 +08:00
|
|
|
{
|
2020-11-02 04:22:04 +08:00
|
|
|
selectionStart ??= e.MouseDownPosition.X / timeline.CurrentZoom;
|
|
|
|
|
|
|
|
// only calculate end when a transition is not in progress to avoid bouncing.
|
|
|
|
if (Precision.AlmostEquals(timeline.CurrentZoom, timeline.Zoom))
|
|
|
|
selectionEnd = e.MousePosition.X / timeline.CurrentZoom;
|
|
|
|
|
|
|
|
updateDragBoxPosition();
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-22 14:58:03 +08:00
|
|
|
|
2020-11-02 04:22:04 +08:00
|
|
|
private void updateDragBoxPosition()
|
|
|
|
{
|
|
|
|
if (selectionStart == null)
|
|
|
|
return;
|
2020-10-27 01:03:04 +08:00
|
|
|
|
2020-11-02 04:22:04 +08:00
|
|
|
float rescaledStart = selectionStart.Value * timeline.CurrentZoom;
|
|
|
|
float rescaledEnd = selectionEnd * timeline.CurrentZoom;
|
2020-01-22 13:58:15 +08:00
|
|
|
|
2020-11-02 04:22:04 +08:00
|
|
|
Box.X = Math.Min(rescaledStart, rescaledEnd);
|
|
|
|
Box.Width = Math.Abs(rescaledStart - rescaledEnd);
|
2020-01-22 13:58:15 +08:00
|
|
|
|
|
|
|
PerformSelection?.Invoke(Box.ScreenSpaceDrawQuad.AABBFloat);
|
2020-11-02 04:22:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Hide()
|
|
|
|
{
|
|
|
|
base.Hide();
|
|
|
|
selectionStart = null;
|
2020-01-22 13:58:15 +08:00
|
|
|
}
|
2020-01-15 18:09:49 +08:00
|
|
|
}
|
|
|
|
|
2020-11-18 12:33:22 +08:00
|
|
|
protected class TimelineSelectionBlueprintContainer : Container<SelectionBlueprint>
|
2020-01-22 14:42:49 +08:00
|
|
|
{
|
|
|
|
protected override Container<SelectionBlueprint> Content { get; }
|
|
|
|
|
|
|
|
public TimelineSelectionBlueprintContainer()
|
|
|
|
{
|
2020-11-18 12:33:22 +08:00
|
|
|
AddInternal(new TimelinePart<SelectionBlueprint>(Content = new HitObjectOrderedSelectionContainer { RelativeSizeAxes = Axes.Both }) { RelativeSizeAxes = Axes.Both });
|
2020-01-22 14:42:49 +08:00
|
|
|
}
|
|
|
|
}
|
2019-12-05 18:31:40 +08:00
|
|
|
}
|
|
|
|
}
|