1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-18 07:49:52 +08:00

Preview next song in quick play

This commit is contained in:
Dan Balasescu
2025-10-20 17:02:35 +09:00
Unverified
parent fbaf27e3db
commit 2dbfdc3d2c
@@ -16,6 +16,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics.Cursor;
@@ -37,7 +38,7 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Match
/// <summary>
/// The main matchmaking screen which houses a custom <see cref="ScreenStack"/> through the life cycle of a single session.
/// </summary>
public partial class ScreenMatchmaking : OsuScreen
public partial class ScreenMatchmaking : OsuScreen, IPreviewTrackOwner
{
/// <summary>
/// Padding between rows of the content.
@@ -74,6 +75,12 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Match
[Resolved]
private AudioManager audio { get; set; } = null!;
[Resolved]
private PreviewTrackManager previewTrackManager { get; set; } = null!;
[Resolved]
private MusicController music { get; set; } = null!;
private readonly MultiplayerRoom room;
private Sample? sampleStart;
@@ -308,6 +315,18 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Match
return false;
}
public override void OnEntering(ScreenTransitionEvent e)
{
base.OnEntering(e);
beginHandlingTrack();
}
public override void OnSuspending(ScreenTransitionEvent e)
{
onLeaving();
base.OnSuspending(e);
}
private bool exitConfirmed;
public override bool OnExiting(ScreenExitEvent e)
@@ -320,6 +339,7 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Match
return true;
}
onLeaving();
client.LeaveRoom().FireAndForget();
return false;
}
@@ -342,6 +362,7 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Match
public override void OnResuming(ScreenTransitionEvent e)
{
base.OnResuming(e);
beginHandlingTrack();
if (e.Last is not MultiplayerPlayerLoader playerLoader)
return;
@@ -355,6 +376,43 @@ namespace osu.Game.Screens.OnlinePlay.Matchmaking.Match
client.ChangeState(MultiplayerUserState.Idle);
}
private void onLeaving()
{
endHandlingTrack();
}
/// <summary>
/// Handles changes in the track to keep it looping while active.
/// </summary>
private void beginHandlingTrack()
{
Beatmap.BindValueChanged(applyLoopingToTrack, true);
}
/// <summary>
/// Stops looping the current track and stops handling further changes to the track.
/// </summary>
private void endHandlingTrack()
{
Beatmap.ValueChanged -= applyLoopingToTrack;
Beatmap.Value.Track.Looping = false;
previewTrackManager.StopAnyPlaying(this);
}
/// <summary>
/// Invoked on changes to the beatmap to loop the track. See: <see cref="beginHandlingTrack"/>.
/// </summary>
/// <param name="beatmap">The beatmap change event.</param>
private void applyLoopingToTrack(ValueChangedEvent<WorkingBeatmap> beatmap)
{
if (!this.IsCurrentScreen())
return;
beatmap.NewValue.PrepareTrackForPreview(true);
music.EnsurePlayingSomething();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);