mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:35:10 +08:00
Merge pull request #11818 from peppy/fix-default-preview-time
Fix preview point not being set correctly for beatmaps which don't specify an explicit time value
This commit is contained in:
commit
1d567e2b2d
@ -51,7 +51,12 @@ namespace osu.Game.Beatmaps
|
||||
[JsonProperty(@"tags")]
|
||||
public string Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time in milliseconds to begin playing the track for preview purposes.
|
||||
/// If -1, the track should begin playing at 40% of its length.
|
||||
/// </summary>
|
||||
public int PreviewTime { get; set; }
|
||||
|
||||
public string AudioFile { get; set; }
|
||||
public string BackgroundFile { get; set; }
|
||||
|
||||
|
@ -266,6 +266,26 @@ namespace osu.Game.Beatmaps
|
||||
[NotNull]
|
||||
public Track LoadTrack() => loadedTrack = GetBeatmapTrack() ?? GetVirtualTrack(1000);
|
||||
|
||||
/// <summary>
|
||||
/// Reads the correct track restart point from beatmap metadata and sets looping to enabled.
|
||||
/// </summary>
|
||||
public void PrepareTrackForPreviewLooping()
|
||||
{
|
||||
Track.Looping = true;
|
||||
Track.RestartPoint = Metadata.PreviewTime;
|
||||
|
||||
if (Track.RestartPoint == -1)
|
||||
{
|
||||
if (!Track.IsLoaded)
|
||||
{
|
||||
// force length to be populated (https://github.com/ppy/osu-framework/issues/4202)
|
||||
Track.Seek(Track.CurrentTime);
|
||||
}
|
||||
|
||||
Track.RestartPoint = 0.4f * Track.Length;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transfer a valid audio track into this working beatmap. Used as an optimisation to avoid reload / track swap
|
||||
/// across difficulties in the same beatmap set.
|
||||
|
@ -168,7 +168,7 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
// Only start the current track if it is the menu music. A beatmap's track is started when entering the Main Menu.
|
||||
if (UsingThemedIntro)
|
||||
Track.Restart();
|
||||
Track.Start();
|
||||
}
|
||||
|
||||
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
||||
|
@ -179,14 +179,15 @@ namespace osu.Game.Screens.Menu
|
||||
base.OnEntering(last);
|
||||
buttons.FadeInFromZero(500);
|
||||
|
||||
var metadata = Beatmap.Value.Metadata;
|
||||
|
||||
if (last is IntroScreen && musicController.TrackLoaded)
|
||||
{
|
||||
if (!musicController.CurrentTrack.IsRunning)
|
||||
var track = musicController.CurrentTrack;
|
||||
|
||||
// presume the track is the current beatmap's track. not sure how correct this assumption is but it has worked until now.
|
||||
if (!track.IsRunning)
|
||||
{
|
||||
musicController.CurrentTrack.Seek(metadata.PreviewTime != -1 ? metadata.PreviewTime : 0.4f * musicController.CurrentTrack.Length);
|
||||
musicController.CurrentTrack.Start();
|
||||
Beatmap.Value.PrepareTrackForPreviewLooping();
|
||||
track.Restart();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,9 +173,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
|
||||
if (track != null)
|
||||
{
|
||||
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
|
||||
track.Looping = true;
|
||||
|
||||
Beatmap.Value.PrepareTrackForPreviewLooping();
|
||||
music?.EnsurePlayingSomething();
|
||||
}
|
||||
}
|
||||
@ -185,10 +183,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
var track = Beatmap?.Value?.Track;
|
||||
|
||||
if (track != null)
|
||||
{
|
||||
track.Looping = false;
|
||||
track.RestartPoint = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -648,8 +648,9 @@ namespace osu.Game.Screens.Select
|
||||
{
|
||||
Debug.Assert(!isHandlingLooping);
|
||||
|
||||
music.CurrentTrack.Looping = isHandlingLooping = true;
|
||||
isHandlingLooping = true;
|
||||
|
||||
ensureTrackLooping(Beatmap.Value, TrackChangeDirection.None);
|
||||
music.TrackChanged += ensureTrackLooping;
|
||||
}
|
||||
|
||||
@ -665,7 +666,7 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
|
||||
private void ensureTrackLooping(WorkingBeatmap beatmap, TrackChangeDirection changeDirection)
|
||||
=> music.CurrentTrack.Looping = true;
|
||||
=> beatmap.PrepareTrackForPreviewLooping();
|
||||
|
||||
public override bool OnBackButton()
|
||||
{
|
||||
@ -719,8 +720,6 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
bool isNewTrack = !lastTrack.TryGetTarget(out var last) || last != track;
|
||||
|
||||
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
|
||||
|
||||
if (!track.IsRunning && (music.UserPauseRequested != true || isNewTrack))
|
||||
music.Play(true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user