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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-03-19 17:48:51 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-01-23 11:29:32 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-02-07 17:04:10 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-04-06 14:34:34 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-06-23 09:57:04 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2019-12-05 18:31:40 +08:00
|
|
|
using osu.Framework.Graphics;
|
2021-04-06 13:28:10 +08:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2019-12-05 18:31:40 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
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;
|
2021-04-06 13:28:10 +08:00
|
|
|
using osuTK;
|
2019-12-05 18:31:40 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
2021-04-27 14:40:35 +08:00
|
|
|
internal partial class TimelineBlueprintContainer : EditorBlueprintContainer
|
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
|
|
|
private Bindable<HitObject> placement;
|
2021-04-27 14:40:35 +08:00
|
|
|
private SelectionBlueprint<HitObject> placementBlueprint;
|
2020-02-07 17:04:10 +08:00
|
|
|
|
2022-10-11 21:39:53 +08:00
|
|
|
private bool hitObjectDragged;
|
|
|
|
|
2022-06-18 23:28:36 +08:00
|
|
|
/// <remarks>
|
|
|
|
/// Positional input must be received outside the container's bounds,
|
|
|
|
/// in order to handle timeline blueprints which are stacked offscreen.
|
|
|
|
/// </remarks>
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => timeline.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
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;
|
2021-04-06 13:28:10 +08:00
|
|
|
}
|
2020-01-22 13:58:15 +08:00
|
|
|
|
2021-04-06 13:28:10 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-07-18 23:20:30 +08:00
|
|
|
AddInternal(new SelectableAreaBackground
|
2020-01-22 13:58:15 +08:00
|
|
|
{
|
2021-04-13 17:12:46 +08:00
|
|
|
Colour = Color4.Black,
|
|
|
|
Depth = float.MaxValue,
|
2021-04-14 13:56:27 +08:00
|
|
|
Blending = BlendingParameters.Additive,
|
2020-01-22 13:58:15 +08:00
|
|
|
});
|
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();
|
2020-02-07 17:04:10 +08:00
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
placement = Beatmap.PlacementObject.GetBoundCopy();
|
2020-02-07 17:04:10 +08:00
|
|
|
placement.ValueChanged += placementChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void placementChanged(ValueChangedEvent<HitObject> obj)
|
|
|
|
{
|
|
|
|
if (obj.NewValue == null)
|
|
|
|
{
|
|
|
|
if (placementBlueprint != null)
|
|
|
|
{
|
2022-08-26 14:19:05 +08:00
|
|
|
SelectionBlueprints.Remove(placementBlueprint, true);
|
2020-02-07 17:04:10 +08:00
|
|
|
placementBlueprint = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-23 09:57:04 +08:00
|
|
|
placementBlueprint = CreateBlueprintFor(obj.NewValue).AsNonNull();
|
2020-02-07 17:04:10 +08:00
|
|
|
|
2023-05-17 16:19:18 +08:00
|
|
|
placementBlueprint.Colour = OsuColour.Gray(0.9f);
|
2020-02-07 17:04:10 +08:00
|
|
|
|
2023-05-17 16:49:04 +08:00
|
|
|
// TODO: this is out of order, causing incorrect stacking height.
|
2020-02-07 17:04:10 +08:00
|
|
|
SelectionBlueprints.Add(placementBlueprint);
|
|
|
|
}
|
2020-01-15 18:09:49 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
protected override Container<SelectionBlueprint<HitObject>> CreateSelectionBlueprintContainer() => new TimelineSelectionBlueprintContainer { RelativeSizeAxes = Axes.Both };
|
2020-01-24 16:50:36 +08:00
|
|
|
|
2022-10-05 19:23:59 +08:00
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
|
|
|
{
|
|
|
|
if (!base.ReceivePositionalInputAt(e.ScreenSpaceMouseDownPosition))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return base.OnDragStart(e);
|
|
|
|
}
|
|
|
|
|
2020-01-22 14:42:49 +08:00
|
|
|
protected override void Update()
|
2019-12-05 18:31:40 +08:00
|
|
|
{
|
2022-10-11 21:39:53 +08:00
|
|
|
if (IsDragged || hitObjectDragged)
|
|
|
|
handleScrollViaDrag();
|
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();
|
2021-03-19 17:48:51 +08:00
|
|
|
|
|
|
|
updateStacking();
|
|
|
|
}
|
|
|
|
|
2024-02-22 03:47:49 +08:00
|
|
|
private readonly Stack<HitObject> currentConcurrentObjects = new Stack<HitObject>();
|
|
|
|
|
2021-03-19 17:48:51 +08:00
|
|
|
private void updateStacking()
|
|
|
|
{
|
|
|
|
// because only blueprints of objects which are alive (via pooling) are displayed in the timeline, it's feasible to do this every-update.
|
|
|
|
|
|
|
|
const int stack_offset = 5;
|
|
|
|
|
|
|
|
// after the stack gets this tall, we can presume there is space underneath to draw subsequent blueprints.
|
|
|
|
const int stack_reset_count = 3;
|
|
|
|
|
2024-02-22 03:47:49 +08:00
|
|
|
currentConcurrentObjects.Clear();
|
2021-03-19 17:48:51 +08:00
|
|
|
|
2024-02-22 03:47:49 +08:00
|
|
|
for (int i = SelectionBlueprints.Count - 1; i >= 0; i--)
|
2021-03-19 17:48:51 +08:00
|
|
|
{
|
2024-02-22 03:47:49 +08:00
|
|
|
var b = SelectionBlueprints[i];
|
|
|
|
|
2021-03-25 15:28:30 +08:00
|
|
|
// remove objects from the stack as long as their end time is in the past.
|
|
|
|
while (currentConcurrentObjects.TryPeek(out HitObject hitObject))
|
2021-03-19 17:48:51 +08:00
|
|
|
{
|
2021-04-27 14:40:35 +08:00
|
|
|
if (Precision.AlmostBigger(hitObject.GetEndTime(), b.Item.StartTime, 1))
|
2021-03-19 17:48:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
currentConcurrentObjects.Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the stack gets too high, we should have space below it to display the next batch of objects.
|
|
|
|
// importantly, we only do this if time has incremented, else a stack of hitobjects all at the same time value would start to overlap themselves.
|
2021-04-27 14:40:35 +08:00
|
|
|
if (currentConcurrentObjects.TryPeek(out HitObject h) && !Precision.AlmostEquals(h.StartTime, b.Item.StartTime, 1))
|
2021-03-19 17:48:51 +08:00
|
|
|
{
|
|
|
|
if (currentConcurrentObjects.Count >= stack_reset_count)
|
|
|
|
currentConcurrentObjects.Clear();
|
|
|
|
}
|
|
|
|
|
2021-03-25 15:28:30 +08:00
|
|
|
b.Y = -(stack_offset * currentConcurrentObjects.Count);
|
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
currentConcurrentObjects.Push(b.Item);
|
2021-03-19 17:48:51 +08:00
|
|
|
}
|
2019-12-05 22:31:21 +08:00
|
|
|
}
|
2019-12-05 18:31:40 +08:00
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
protected override SelectionHandler<HitObject> CreateSelectionHandler() => new TimelineSelectionHandler();
|
2020-01-22 20:37:06 +08:00
|
|
|
|
2021-04-27 17:33:47 +08:00
|
|
|
protected override SelectionBlueprint<HitObject> CreateBlueprintFor(HitObject item)
|
2020-02-05 14:58:35 +08:00
|
|
|
{
|
2021-04-27 17:33:47 +08:00
|
|
|
return new TimelineHitObjectBlueprint(item)
|
2021-03-25 15:28:30 +08:00
|
|
|
{
|
2022-10-11 21:39:53 +08:00
|
|
|
OnDragHandled = e => hitObjectDragged = e != null,
|
2021-03-25 15:28:30 +08:00
|
|
|
};
|
|
|
|
}
|
2020-01-23 15:23:42 +08:00
|
|
|
|
2022-10-05 19:43:02 +08:00
|
|
|
protected sealed override DragBox CreateDragBox() => new TimelineDragBox();
|
|
|
|
|
|
|
|
protected override void UpdateSelectionFromDragBox()
|
|
|
|
{
|
2024-06-14 15:14:07 +08:00
|
|
|
Composer.BlueprintContainer.CommitIfPlacementActive();
|
|
|
|
|
2022-10-05 19:43:02 +08:00
|
|
|
var dragBox = (TimelineDragBox)DragBox;
|
|
|
|
double minTime = dragBox.MinTime;
|
|
|
|
double maxTime = dragBox.MaxTime;
|
|
|
|
|
2022-10-05 20:26:00 +08:00
|
|
|
SelectedItems.RemoveAll(hitObject => !shouldBeSelected(hitObject));
|
2022-10-06 12:59:54 +08:00
|
|
|
|
|
|
|
foreach (var hitObject in Beatmap.HitObjects.Except(SelectedItems).Where(shouldBeSelected))
|
|
|
|
{
|
|
|
|
Composer.Playfield.SetKeepAlive(hitObject, true);
|
|
|
|
SelectedItems.Add(hitObject);
|
|
|
|
}
|
2022-10-05 20:26:00 +08:00
|
|
|
|
2022-10-05 21:19:22 +08:00
|
|
|
bool shouldBeSelected(HitObject hitObject)
|
|
|
|
{
|
|
|
|
double midTime = (hitObject.StartTime + hitObject.GetEndTime()) / 2;
|
|
|
|
return minTime <= midTime && midTime <= maxTime;
|
|
|
|
}
|
2022-10-05 19:43:02 +08:00
|
|
|
}
|
2020-01-23 15:23:42 +08:00
|
|
|
|
2022-10-11 21:39:53 +08:00
|
|
|
private void handleScrollViaDrag()
|
2020-02-05 14:58:35 +08:00
|
|
|
{
|
2022-10-11 21:39:53 +08:00
|
|
|
if (timeline == null) return;
|
2020-02-05 14:58:35 +08:00
|
|
|
|
2022-10-11 21:39:53 +08:00
|
|
|
var timelineQuad = timeline.ScreenSpaceDrawQuad;
|
|
|
|
float mouseX = InputManager.CurrentState.Mouse.Position.X;
|
2020-02-05 14:58:35 +08:00
|
|
|
|
2024-07-23 17:05:53 +08:00
|
|
|
// for better UX do not require the user to drag all the way to the edge and beyond to initiate a drag-scroll.
|
|
|
|
// this is especially important in scenarios like fullscreen, where mouse confine will usually be on
|
|
|
|
// and the user physically *won't be able to* drag beyond the edge of the timeline
|
|
|
|
// (since its left edge is co-incident with the window edge).
|
|
|
|
const float scroll_tolerance = 20;
|
|
|
|
|
|
|
|
float leftBound = timelineQuad.TopLeft.X + scroll_tolerance;
|
|
|
|
float rightBound = timelineQuad.TopRight.X - scroll_tolerance;
|
|
|
|
|
2022-10-11 21:39:53 +08:00
|
|
|
// scroll if in a drag and dragging outside visible extents
|
2024-07-23 17:05:53 +08:00
|
|
|
if (mouseX > rightBound)
|
|
|
|
timeline.ScrollBy((float)((mouseX - rightBound) / 10 * Clock.ElapsedFrameTime));
|
|
|
|
else if (mouseX < leftBound)
|
|
|
|
timeline.ScrollBy((float)((mouseX - leftBound) / 10 * Clock.ElapsedFrameTime));
|
2020-02-05 14:58:35 +08:00
|
|
|
}
|
|
|
|
|
2021-04-06 14:34:34 +08:00
|
|
|
private partial class SelectableAreaBackground : CompositeDrawable
|
|
|
|
{
|
2021-07-22 14:39:01 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2021-07-16 22:16:34 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
|
|
|
{
|
|
|
|
float localY = ToLocalSpace(screenSpacePos).Y;
|
|
|
|
return DrawRectangle.Top <= localY && DrawRectangle.Bottom >= localY;
|
|
|
|
}
|
|
|
|
|
2021-04-06 14:34:34 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Alpha = 0.1f;
|
|
|
|
|
|
|
|
AddRangeInternal(new[]
|
|
|
|
{
|
|
|
|
// fade out over intro time, outside the valid time bounds.
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = 200,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.White.Opacity(0), Color4.White),
|
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-07-16 22:16:34 +08:00
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
this.FadeColour(colours.BlueLighter, 120, Easing.OutQuint);
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
this.FadeColour(Color4.Black, 600, Easing.OutQuint);
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
2021-04-06 14:34:34 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 14:40:35 +08:00
|
|
|
protected partial class TimelineSelectionBlueprintContainer : Container<SelectionBlueprint<HitObject>>
|
2020-01-22 14:42:49 +08:00
|
|
|
{
|
2021-04-27 14:40:35 +08:00
|
|
|
protected override Container<SelectionBlueprint<HitObject>> Content { get; }
|
2020-01-22 14:42:49 +08:00
|
|
|
|
|
|
|
public TimelineSelectionBlueprintContainer()
|
|
|
|
{
|
2021-04-27 14:40:35 +08:00
|
|
|
AddInternal(new TimelinePart<SelectionBlueprint<HitObject>>(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
|
|
|
}
|
|
|
|
}
|