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.
|
|
|
|
|
|
2024-09-05 15:01:28 +08:00
|
|
|
|
using System.Threading;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2024-09-04 18:28:07 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2024-09-05 15:01:28 +08:00
|
|
|
|
using osu.Framework.Caching;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
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.Game.Replays;
|
2024-09-04 18:28:07 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Configuration;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Replays;
|
2024-09-04 19:07:31 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI.ReplayAnalysis;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI
|
|
|
|
|
{
|
2024-09-04 17:43:33 +08:00
|
|
|
|
public partial class ReplayAnalysisOverlay : CompositeDrawable
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-09-05 14:15:15 +08:00
|
|
|
|
private BindableBool showClickMarkers { get; } = new BindableBool();
|
|
|
|
|
private BindableBool showFrameMarkers { get; } = new BindableBool();
|
|
|
|
|
private BindableBool showCursorPath { get; } = new BindableBool();
|
2024-09-05 14:53:53 +08:00
|
|
|
|
private BindableInt displayLength { get; } = new BindableInt();
|
2024-09-04 18:28:07 +08:00
|
|
|
|
|
2024-09-05 15:01:28 +08:00
|
|
|
|
protected ClickMarkerContainer? ClickMarkers;
|
|
|
|
|
protected FrameMarkerContainer? FrameMarkers;
|
|
|
|
|
protected CursorPathContainer? CursorPath;
|
2024-09-03 12:59:42 +08:00
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
private readonly Replay replay;
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
2024-09-06 17:41:07 +08:00
|
|
|
|
private int replayFrameIndex;
|
2024-09-06 15:58:02 +08:00
|
|
|
|
|
2024-09-04 18:28:07 +08:00
|
|
|
|
public ReplayAnalysisOverlay(Replay replay)
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-09-04 19:07:31 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
this.replay = replay;
|
2024-09-03 12:59:42 +08:00
|
|
|
|
}
|
2024-02-24 12:32:35 +08:00
|
|
|
|
|
2024-09-05 14:53:53 +08:00
|
|
|
|
private bool requireDisplay => showClickMarkers.Value || showFrameMarkers.Value || showCursorPath.Value;
|
|
|
|
|
|
2024-02-24 12:32:35 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2024-09-04 18:28:07 +08:00
|
|
|
|
private void load(OsuRulesetConfigManager config)
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-09-05 14:15:15 +08:00
|
|
|
|
config.BindWith(OsuRulesetSetting.ReplayClickMarkersEnabled, showClickMarkers);
|
|
|
|
|
config.BindWith(OsuRulesetSetting.ReplayFrameMarkersEnabled, showFrameMarkers);
|
|
|
|
|
config.BindWith(OsuRulesetSetting.ReplayCursorPathEnabled, showCursorPath);
|
2024-09-05 14:53:53 +08:00
|
|
|
|
config.BindWith(OsuRulesetSetting.ReplayAnalysisDisplayLength, displayLength);
|
2024-09-03 12:59:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 17:35:27 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2024-09-05 14:53:53 +08:00
|
|
|
|
displayLength.BindValueChanged(_ =>
|
|
|
|
|
{
|
2024-09-05 15:01:28 +08:00
|
|
|
|
// Need to fully reload to make this work.
|
2024-09-06 15:58:02 +08:00
|
|
|
|
invalidateLoaded();
|
2024-09-05 14:53:53 +08:00
|
|
|
|
}, true);
|
2024-09-04 17:35:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-06 17:41:07 +08:00
|
|
|
|
/// <summary>
|
2024-09-09 14:06:24 +08:00
|
|
|
|
/// Invalidated when containers are not loaded nor loading, false if loading, and true if loaded
|
2024-09-06 17:41:07 +08:00
|
|
|
|
/// </summary>
|
2024-09-09 14:06:24 +08:00
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Knowing the loading/loaded state is for avoiding an enumeration error when adding
|
|
|
|
|
/// new entries and not starting a new load while loading
|
|
|
|
|
/// </remarks>
|
2024-09-06 17:41:07 +08:00
|
|
|
|
private readonly Cached<bool> loadState = new Cached<bool>();
|
2024-09-05 15:01:28 +08:00
|
|
|
|
|
|
|
|
|
private CancellationTokenSource? generationCancellationSource;
|
|
|
|
|
|
2024-09-06 15:58:02 +08:00
|
|
|
|
private void invalidateLoaded()
|
|
|
|
|
{
|
2024-09-06 17:41:07 +08:00
|
|
|
|
loadState.Invalidate();
|
2024-09-06 15:58:02 +08:00
|
|
|
|
replayFrameIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-05 15:01:28 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (requireDisplay)
|
2024-09-06 17:41:07 +08:00
|
|
|
|
{
|
2024-09-05 15:01:28 +08:00
|
|
|
|
initialise();
|
2024-09-06 17:41:07 +08:00
|
|
|
|
// adding entries while the component is asynchronously loading
|
|
|
|
|
// can collide with enumeration operations and cause an error
|
|
|
|
|
if (loadState.IsValid && loadState.Value)
|
|
|
|
|
addEntries();
|
|
|
|
|
}
|
2024-09-05 15:01:28 +08:00
|
|
|
|
|
2024-09-05 15:45:37 +08:00
|
|
|
|
if (ClickMarkers != null) ClickMarkers.Alpha = showClickMarkers.Value ? 1 : 0;
|
|
|
|
|
if (FrameMarkers != null) FrameMarkers.Alpha = showFrameMarkers.Value ? 1 : 0;
|
|
|
|
|
if (CursorPath != null) CursorPath.Alpha = showCursorPath.Value ? 1 : 0;
|
2024-09-05 15:01:28 +08:00
|
|
|
|
}
|
2024-09-05 14:53:53 +08:00
|
|
|
|
|
|
|
|
|
private void initialise()
|
2024-09-03 12:59:42 +08:00
|
|
|
|
{
|
2024-09-06 17:41:07 +08:00
|
|
|
|
if (loadState.IsValid)
|
2024-09-05 14:53:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2024-09-06 17:41:07 +08:00
|
|
|
|
loadState.Value = false;
|
2024-09-05 14:53:53 +08:00
|
|
|
|
|
2024-09-05 15:01:28 +08:00
|
|
|
|
generationCancellationSource?.Cancel();
|
|
|
|
|
generationCancellationSource = new CancellationTokenSource();
|
2024-09-05 14:53:53 +08:00
|
|
|
|
|
|
|
|
|
// It's faster to reinitialise the whole drawable stack than use `Clear` on `PooledDrawableWithLifetimeContainer`
|
2024-09-05 15:01:28 +08:00
|
|
|
|
var newDrawables = new Drawable[]
|
2024-09-05 14:53:53 +08:00
|
|
|
|
{
|
|
|
|
|
CursorPath = new CursorPathContainer(),
|
|
|
|
|
ClickMarkers = new ClickMarkerContainer(),
|
|
|
|
|
FrameMarkers = new FrameMarkerContainer(),
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-06 17:41:07 +08:00
|
|
|
|
LoadComponentsAsync(newDrawables, drawables =>
|
|
|
|
|
{
|
|
|
|
|
InternalChildrenEnumerable = drawables;
|
|
|
|
|
loadState.Value = true;
|
|
|
|
|
}, generationCancellationSource.Token);
|
2024-09-06 15:58:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addEntries()
|
|
|
|
|
{
|
2024-02-24 12:32:35 +08:00
|
|
|
|
bool leftHeld = false;
|
|
|
|
|
bool rightHeld = false;
|
2024-02-28 10:51:54 +08:00
|
|
|
|
|
2024-09-05 15:01:28 +08:00
|
|
|
|
// This should probably be async as well, but it's a bit of a pain to debounce and everything.
|
|
|
|
|
// Let's address concerns when they are raised.
|
2024-09-06 15:58:02 +08:00
|
|
|
|
while (replayFrameIndex < replay.Frames.Count)
|
2024-02-24 12:32:35 +08:00
|
|
|
|
{
|
2024-09-06 15:58:02 +08:00
|
|
|
|
var osuFrame = (OsuReplayFrame)replay.Frames[replayFrameIndex];
|
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)
|
|
|
|
|
{
|
|
|
|
|
leftHeld = true;
|
2024-09-06 15:58:02 +08:00
|
|
|
|
ClickMarkers!.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position, OsuAction.LeftButton));
|
2024-02-24 12:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rightHeld && !rightButton)
|
|
|
|
|
rightHeld = false;
|
|
|
|
|
else if (!rightHeld && rightButton)
|
|
|
|
|
{
|
|
|
|
|
rightHeld = true;
|
2024-09-06 15:58:02 +08:00
|
|
|
|
ClickMarkers!.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position, OsuAction.RightButton));
|
2024-02-24 12:32:35 +08:00
|
|
|
|
}
|
2024-09-04 20:04:59 +08:00
|
|
|
|
|
2024-09-06 15:58:02 +08:00
|
|
|
|
FrameMarkers!.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position, osuFrame.Actions.ToArray()));
|
|
|
|
|
CursorPath!.Add(new AnalysisFrameEntry(osuFrame.Time, displayLength.Value, osuFrame.Position));
|
2024-09-05 15:01:28 +08:00
|
|
|
|
|
2024-09-06 15:58:02 +08:00
|
|
|
|
replayFrameIndex++;
|
|
|
|
|
}
|
2024-02-24 12:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|