2024-09-03 16:49:50 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2024-02-24 12:32:35 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
2024-09-04 17:35:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
using osu.Framework.Graphics.Lines;
|
|
|
|
|
using osu.Framework.Graphics.Performance;
|
|
|
|
|
using osu.Framework.Graphics.Pooling;
|
|
|
|
|
using osu.Game.Replays;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Pooling;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Replays;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI
|
|
|
|
|
{
|
2024-09-04 17:35:27 +08:00
|
|
|
|
public partial class OsuAnalysisContainer : CompositeDrawable
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-09-04 17:35:27 +08:00
|
|
|
|
protected readonly HitMarkersContainer HitMarkers;
|
|
|
|
|
protected readonly AimMarkersContainer AimMarkers;
|
|
|
|
|
protected readonly AimLinesContainer AimLines;
|
2024-09-03 12:59:42 +08:00
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
public OsuAnalysisSettings Settings = null!;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
private readonly Replay replay;
|
|
|
|
|
private readonly DrawableRuleset drawableRuleset;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
2024-09-04 15:37:52 +08:00
|
|
|
|
public OsuAnalysisContainer(Replay replay, DrawableRuleset drawableRuleset)
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-09-04 17:35:27 +08:00
|
|
|
|
this.replay = replay;
|
|
|
|
|
this.drawableRuleset = drawableRuleset;
|
|
|
|
|
|
2024-02-24 12:32:35 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2024-02-28 10:51:54 +08:00
|
|
|
|
HitMarkers = new HitMarkersContainer(),
|
2024-09-04 17:35:27 +08:00
|
|
|
|
AimLines = new AimLinesContainer(),
|
|
|
|
|
AimMarkers = new AimMarkersContainer(),
|
2024-02-24 12:32:35 +08:00
|
|
|
|
};
|
2024-09-03 12:59:42 +08:00
|
|
|
|
}
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2024-02-24 12:46:50 +08:00
|
|
|
|
private void load()
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-09-04 17:35:27 +08:00
|
|
|
|
AddInternal(Settings = new OsuAnalysisSettings());
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
2024-09-03 12:59:42 +08:00
|
|
|
|
LoadReplay();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
Settings.HitMarkersEnabled.BindValueChanged(e => toggleHitMarkers(e.NewValue), true);
|
|
|
|
|
Settings.AimMarkersEnabled.BindValueChanged(e => toggleAimMarkers(e.NewValue), true);
|
|
|
|
|
Settings.AimLinesEnabled.BindValueChanged(e => toggleAimLines(e.NewValue), true);
|
|
|
|
|
Settings.CursorHideEnabled.BindValueChanged(e => toggleCursorHidden(e.NewValue), true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 16:49:50 +08:00
|
|
|
|
private void toggleHitMarkers(bool value) => HitMarkers.FadeTo(value ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
private void toggleAimMarkers(bool value) => AimMarkers.FadeTo(value ? 1 : 0);
|
|
|
|
|
|
|
|
|
|
private void toggleAimLines(bool value) => AimLines.FadeTo(value ? 1 : 0);
|
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
private void toggleCursorHidden(bool value) => drawableRuleset.Playfield.Cursor.FadeTo(value ? 0 : 1);
|
2024-09-03 16:49:50 +08:00
|
|
|
|
|
2024-09-03 12:59:42 +08:00
|
|
|
|
protected void LoadReplay()
|
|
|
|
|
{
|
2024-02-24 12:32:35 +08:00
|
|
|
|
bool leftHeld = false;
|
|
|
|
|
bool rightHeld = false;
|
2024-02-28 10:51:54 +08:00
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
foreach (var frame in replay.Frames)
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
var osuFrame = (OsuReplayFrame)frame;
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
AimMarkers.Add(new AimPointEntry(osuFrame.Time, osuFrame.Position));
|
|
|
|
|
AimLines.Add(new AimPointEntry(osuFrame.Time, osuFrame.Position));
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
|
|
|
|
bool leftButton = osuFrame.Actions.Contains(OsuAction.LeftButton);
|
|
|
|
|
bool rightButton = osuFrame.Actions.Contains(OsuAction.RightButton);
|
|
|
|
|
|
|
|
|
|
if (leftHeld && !leftButton)
|
|
|
|
|
leftHeld = false;
|
|
|
|
|
else if (!leftHeld && leftButton)
|
|
|
|
|
{
|
2024-02-28 10:51:54 +08:00
|
|
|
|
HitMarkers.Add(new HitMarkerEntry(osuFrame.Time, osuFrame.Position, true));
|
2024-02-24 12:32:35 +08:00
|
|
|
|
leftHeld = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rightHeld && !rightButton)
|
|
|
|
|
rightHeld = false;
|
|
|
|
|
else if (!rightHeld && rightButton)
|
|
|
|
|
{
|
2024-02-28 10:51:54 +08:00
|
|
|
|
HitMarkers.Add(new HitMarkerEntry(osuFrame.Time, osuFrame.Position, false));
|
2024-02-24 12:32:35 +08:00
|
|
|
|
rightHeld = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected partial class HitMarkersContainer : PooledDrawableWithLifetimeContainer<HitMarkerEntry, HitMarkerDrawable>
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly HitMarkerPool leftPool;
|
|
|
|
|
private readonly HitMarkerPool rightPool;
|
|
|
|
|
|
|
|
|
|
public HitMarkersContainer()
|
|
|
|
|
{
|
2024-02-28 10:51:54 +08:00
|
|
|
|
AddInternal(leftPool = new HitMarkerPool(OsuAction.LeftButton, 15));
|
|
|
|
|
AddInternal(rightPool = new HitMarkerPool(OsuAction.RightButton, 15));
|
2024-02-24 12:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override HitMarkerDrawable GetDrawable(HitMarkerEntry entry) => (entry.IsLeftMarker ? leftPool : rightPool).Get(d => d.Apply(entry));
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected partial class AimMarkersContainer : PooledDrawableWithLifetimeContainer<AimPointEntry, HitMarkerDrawable>
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly HitMarkerPool pool;
|
|
|
|
|
|
|
|
|
|
public AimMarkersContainer()
|
|
|
|
|
{
|
2024-02-28 10:51:54 +08:00
|
|
|
|
AddInternal(pool = new HitMarkerPool(null, 80));
|
2024-02-24 12:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override HitMarkerDrawable GetDrawable(AimPointEntry entry) => pool.Get(d => d.Apply(entry));
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected partial class AimLinesContainer : Path
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-02-28 10:51:54 +08:00
|
|
|
|
private readonly LifetimeEntryManager lifetimeManager = new LifetimeEntryManager();
|
|
|
|
|
private readonly SortedSet<AimPointEntry> aliveEntries = new SortedSet<AimPointEntry>(new AimLinePointComparator());
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
|
|
|
|
public AimLinesContainer()
|
|
|
|
|
{
|
|
|
|
|
lifetimeManager.EntryBecameAlive += entryBecameAlive;
|
|
|
|
|
lifetimeManager.EntryBecameDead += entryBecameDead;
|
|
|
|
|
|
|
|
|
|
PathRadius = 1f;
|
|
|
|
|
Colour = new Color4(255, 255, 255, 127);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
lifetimeManager.Update(Time.Current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(AimPointEntry entry) => lifetimeManager.AddEntry(entry);
|
|
|
|
|
|
2024-09-03 13:38:54 +08:00
|
|
|
|
public void Clear() => lifetimeManager.ClearEntries();
|
|
|
|
|
|
2024-02-24 12:32:35 +08:00
|
|
|
|
private void entryBecameAlive(LifetimeEntry entry)
|
|
|
|
|
{
|
|
|
|
|
aliveEntries.Add((AimPointEntry)entry);
|
|
|
|
|
updateVertices();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void entryBecameDead(LifetimeEntry entry)
|
|
|
|
|
{
|
|
|
|
|
aliveEntries.Remove((AimPointEntry)entry);
|
|
|
|
|
updateVertices();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateVertices()
|
|
|
|
|
{
|
|
|
|
|
ClearVertices();
|
2024-02-28 10:51:54 +08:00
|
|
|
|
|
2024-02-24 12:32:35 +08:00
|
|
|
|
foreach (var entry in aliveEntries)
|
|
|
|
|
{
|
|
|
|
|
AddVertex(entry.Position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class AimLinePointComparator : IComparer<AimPointEntry>
|
|
|
|
|
{
|
|
|
|
|
public int Compare(AimPointEntry? x, AimPointEntry? y)
|
|
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(x);
|
|
|
|
|
ArgumentNullException.ThrowIfNull(y);
|
|
|
|
|
|
|
|
|
|
return x.LifetimeStart.CompareTo(y.LifetimeStart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected partial class HitMarkerDrawable : PoolableDrawableWithLifetime<AimPointEntry>
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This constructor only exists to meet the <c>new()</c> type constraint of <see cref="DrawablePool{T}"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public HitMarkerDrawable()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
public HitMarkerDrawable(OsuAction? action)
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre;
|
2024-02-28 10:51:54 +08:00
|
|
|
|
InternalChild = new HitMarker(action);
|
2024-02-24 12:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnApply(AimPointEntry entry)
|
|
|
|
|
{
|
|
|
|
|
Position = entry.Position;
|
|
|
|
|
|
|
|
|
|
using (BeginAbsoluteSequence(LifetimeStart))
|
|
|
|
|
Show();
|
|
|
|
|
|
|
|
|
|
using (BeginAbsoluteSequence(LifetimeEnd - 200))
|
|
|
|
|
this.FadeOut(200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected partial class HitMarkerPool : DrawablePool<HitMarkerDrawable>
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly OsuAction? action;
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
public HitMarkerPool(OsuAction? action, int initialSize)
|
2024-02-24 12:32:35 +08:00
|
|
|
|
: base(initialSize)
|
|
|
|
|
{
|
|
|
|
|
this.action = action;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected override HitMarkerDrawable CreateNewDrawable() => new HitMarkerDrawable(action);
|
2024-02-24 12:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected partial class AimPointEntry : LifetimeEntry
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
public Vector2 Position { get; }
|
|
|
|
|
|
|
|
|
|
public AimPointEntry(double time, Vector2 position)
|
|
|
|
|
{
|
|
|
|
|
LifetimeStart = time;
|
|
|
|
|
LifetimeEnd = time + 1_000;
|
|
|
|
|
Position = position;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:51:54 +08:00
|
|
|
|
protected partial class HitMarkerEntry : AimPointEntry
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
|
|
|
|
public bool IsLeftMarker { get; }
|
|
|
|
|
|
|
|
|
|
public HitMarkerEntry(double lifetimeStart, Vector2 position, bool isLeftMarker)
|
|
|
|
|
: base(lifetimeStart, position)
|
|
|
|
|
{
|
|
|
|
|
IsLeftMarker = isLeftMarker;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|