2020-01-27 16:34:25 +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-10-09 14:38:58 +08:00
|
|
|
using System;
|
2020-01-27 16:34:25 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
|
|
|
|
using osu.Game.Screens.Edit.Components.Timelines.Summary.Visualisations;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
2020-10-09 14:38:58 +08:00
|
|
|
public class TimelineTickDisplay : TimelinePart<PointVisualisation>
|
2020-01-27 16:34:25 +08:00
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap beatmap { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Bindable<WorkingBeatmap> working { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private BindableBeatDivisor beatDivisor { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2020-01-27 17:07:46 +08:00
|
|
|
public TimelineTickDisplay()
|
2020-01-27 16:34:25 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2020-10-09 14:38:58 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private Timeline timeline { get; set; }
|
2020-01-27 16:34:25 +08:00
|
|
|
|
2020-10-09 14:38:58 +08:00
|
|
|
protected override void Update()
|
2020-01-27 16:34:25 +08:00
|
|
|
{
|
2020-10-09 14:38:58 +08:00
|
|
|
base.Update();
|
|
|
|
|
|
|
|
int drawableIndex = 0;
|
|
|
|
|
|
|
|
double minVisibleTime = double.MinValue;
|
|
|
|
double maxVisibleTime = double.MaxValue;
|
|
|
|
|
|
|
|
if (timeline != null)
|
|
|
|
{
|
|
|
|
minVisibleTime = ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopLeft).X / DrawWidth * Content.RelativeChildSize.X;
|
|
|
|
maxVisibleTime = ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopRight).X / DrawWidth * Content.RelativeChildSize.X;
|
|
|
|
}
|
2020-01-27 16:34:25 +08:00
|
|
|
|
|
|
|
for (var i = 0; i < beatmap.ControlPointInfo.TimingPoints.Count; i++)
|
|
|
|
{
|
|
|
|
var point = beatmap.ControlPointInfo.TimingPoints[i];
|
2020-02-01 01:05:26 +08:00
|
|
|
var until = i + 1 < beatmap.ControlPointInfo.TimingPoints.Count ? beatmap.ControlPointInfo.TimingPoints[i + 1].Time : working.Value.Track.Length;
|
2020-01-27 16:34:25 +08:00
|
|
|
|
|
|
|
int beat = 0;
|
|
|
|
|
|
|
|
for (double t = point.Time; t < until; t += point.BeatLength / beatDivisor.Value)
|
|
|
|
{
|
2020-10-09 14:38:58 +08:00
|
|
|
if (t >= minVisibleTime && t <= maxVisibleTime)
|
2020-01-27 16:34:25 +08:00
|
|
|
{
|
2020-10-09 14:38:58 +08:00
|
|
|
var indexInBeat = beat % beatDivisor.Value;
|
2020-01-27 16:34:25 +08:00
|
|
|
|
2020-10-09 14:38:58 +08:00
|
|
|
if (indexInBeat == 0)
|
2020-01-27 16:34:25 +08:00
|
|
|
{
|
2020-10-09 14:38:58 +08:00
|
|
|
var downbeatPoint = getNextUsablePoint();
|
|
|
|
downbeatPoint.X = (float)t;
|
2020-01-27 16:34:25 +08:00
|
|
|
|
2020-10-09 14:38:58 +08:00
|
|
|
downbeatPoint.Colour = BindableBeatDivisor.GetColourFor(1, colours);
|
|
|
|
downbeatPoint.Anchor = Anchor.TopLeft;
|
|
|
|
downbeatPoint.Origin = Anchor.TopCentre;
|
|
|
|
downbeatPoint.Height = 1;
|
|
|
|
}
|
|
|
|
else
|
2020-01-27 16:34:25 +08:00
|
|
|
{
|
2020-10-09 14:38:58 +08:00
|
|
|
var divisor = BindableBeatDivisor.GetDivisorForBeatIndex(beat, beatDivisor.Value);
|
|
|
|
var colour = BindableBeatDivisor.GetColourFor(divisor, colours);
|
|
|
|
var height = 0.1f - (float)divisor / BindableBeatDivisor.VALID_DIVISORS.Last() * 0.08f;
|
|
|
|
|
|
|
|
var topPoint = getNextUsablePoint();
|
|
|
|
topPoint.X = (float)t;
|
|
|
|
topPoint.Colour = colour;
|
|
|
|
topPoint.Height = height;
|
|
|
|
topPoint.Anchor = Anchor.TopLeft;
|
|
|
|
topPoint.Origin = Anchor.TopCentre;
|
|
|
|
|
|
|
|
var bottomPoint = getNextUsablePoint();
|
|
|
|
bottomPoint.X = (float)t;
|
|
|
|
bottomPoint.Colour = colour;
|
|
|
|
bottomPoint.Anchor = Anchor.BottomLeft;
|
|
|
|
bottomPoint.Origin = Anchor.BottomCentre;
|
|
|
|
bottomPoint.Height = height;
|
|
|
|
}
|
2020-01-27 16:34:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
beat++;
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 14:38:58 +08:00
|
|
|
|
|
|
|
int usedDrawables = drawableIndex;
|
|
|
|
|
|
|
|
// save a few drawables beyond the currently used for edge cases.
|
|
|
|
while (drawableIndex < Math.Min(usedDrawables + 16, Count))
|
|
|
|
Children[drawableIndex++].Hide();
|
|
|
|
|
|
|
|
// expire any excess
|
|
|
|
while (drawableIndex < Count)
|
|
|
|
Children[drawableIndex++].Expire();
|
|
|
|
|
|
|
|
Drawable getNextUsablePoint()
|
|
|
|
{
|
|
|
|
PointVisualisation point;
|
|
|
|
if (drawableIndex >= Count)
|
|
|
|
Add(point = new PointVisualisation());
|
|
|
|
else
|
|
|
|
point = Children[drawableIndex++];
|
|
|
|
|
|
|
|
point.Show();
|
|
|
|
|
|
|
|
return point;
|
|
|
|
}
|
2020-01-27 16:34:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|