1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 23:27:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu/UI/ReplayAnalysis/CursorPathContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.5 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 System.Collections.Generic;
2024-09-04 19:25:29 +08:00
using osu.Framework.Allocation;
2024-09-05 13:02:05 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Lines;
using osu.Framework.Graphics.Performance;
2024-09-04 19:25:29 +08:00
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Rulesets.Osu.UI.ReplayAnalysis
{
2024-09-05 13:28:20 +08:00
public partial class CursorPathContainer : Path
{
private readonly LifetimeEntryManager lifetimeManager = new LifetimeEntryManager();
2024-09-04 19:25:29 +08:00
private readonly SortedSet<AnalysisFrameEntry> aliveEntries = new SortedSet<AnalysisFrameEntry>(new AimLinePointComparator());
2024-09-05 13:28:20 +08:00
public CursorPathContainer()
{
lifetimeManager.EntryBecameAlive += entryBecameAlive;
lifetimeManager.EntryBecameDead += entryBecameDead;
2024-09-04 20:04:59 +08:00
PathRadius = 0.5f;
2024-09-04 19:25:29 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = colours.Pink2;
2024-09-05 13:02:05 +08:00
BackgroundColour = colours.Pink2.Opacity(0);
}
protected override void Update()
{
base.Update();
lifetimeManager.Update(Time.Current);
}
2024-09-04 19:25:29 +08:00
public void Add(AnalysisFrameEntry entry) => lifetimeManager.AddEntry(entry);
private void entryBecameAlive(LifetimeEntry entry)
{
2024-09-04 19:25:29 +08:00
aliveEntries.Add((AnalysisFrameEntry)entry);
updateVertices();
}
private void entryBecameDead(LifetimeEntry entry)
{
2024-09-04 19:25:29 +08:00
aliveEntries.Remove((AnalysisFrameEntry)entry);
updateVertices();
}
private void updateVertices()
{
ClearVertices();
Vector2 min = Vector2.Zero;
foreach (var entry in aliveEntries)
{
AddVertex(entry.Position);
if (entry.Position.X < min.X)
min.X = entry.Position.X;
if (entry.Position.Y < min.Y)
min.Y = entry.Position.Y;
}
Position = min;
}
2024-09-04 19:25:29 +08:00
private sealed class AimLinePointComparator : IComparer<AnalysisFrameEntry>
{
2024-09-04 19:25:29 +08:00
public int Compare(AnalysisFrameEntry? x, AnalysisFrameEntry? y)
{
ArgumentNullException.ThrowIfNull(x);
ArgumentNullException.ThrowIfNull(y);
return x.LifetimeStart.CompareTo(y.LifetimeStart);
}
}
}
}