1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +08:00

Move track looping logic into subscreens

This commit is contained in:
Salman Ahmed 2020-12-22 13:53:01 +03:00
parent 5c3df55cdf
commit e3483147e2
2 changed files with 52 additions and 53 deletions

View File

@ -9,6 +9,7 @@ using osu.Framework.Screens;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Overlays;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Screens.Multi.Match
@ -23,6 +24,9 @@ namespace osu.Game.Screens.Multi.Match
[Resolved(typeof(Room), nameof(Room.Playlist))]
protected BindableList<PlaylistItem> Playlist { get; private set; }
[Resolved]
private MusicController music { get; set; }
[Resolved]
private BeatmapManager beatmapManager { get; set; }
@ -61,6 +65,30 @@ namespace osu.Game.Screens.Multi.Match
var localBeatmap = beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == beatmap.OnlineBeatmapID);
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
if (this.IsCurrentScreen())
applyTrackLooping();
}
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
music?.EnsurePlayingSomething();
applyTrackLooping();
}
public override void OnSuspending(IScreen next)
{
cancelTrackLooping();
base.OnSuspending(next);
}
public override void OnResuming(IScreen last)
{
base.OnResuming(last);
music?.EnsurePlayingSomething();
applyTrackLooping();
}
public override bool OnExiting(IScreen next)
@ -68,7 +96,31 @@ namespace osu.Game.Screens.Multi.Match
RoomManager?.PartRoom();
Mods.Value = Array.Empty<Mod>();
cancelTrackLooping();
return base.OnExiting(next);
}
private void applyTrackLooping()
{
var track = Beatmap.Value?.Track;
if (track != null)
{
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
track.Looping = true;
}
}
private void cancelTrackLooping()
{
var track = Beatmap?.Value?.Track;
if (track != null)
{
track.Looping = false;
track.RestartPoint = 0;
}
}
}
}

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
@ -198,8 +197,6 @@ namespace osu.Game.Screens.Multi
{
this.FadeIn();
waves.Show();
beginHandlingTrack();
}
public override void OnResuming(IScreen last)
@ -209,8 +206,6 @@ namespace osu.Game.Screens.Multi
base.OnResuming(last);
beginHandlingTrack();
UpdatePollingRate(isIdle.Value);
}
@ -219,8 +214,6 @@ namespace osu.Game.Screens.Multi
this.ScaleTo(1.1f, 250, Easing.InSine);
this.FadeOut(250);
endHandlingTrack();
UpdatePollingRate(isIdle.Value);
}
@ -235,8 +228,6 @@ namespace osu.Game.Screens.Multi
if (screenStack.CurrentScreen != null)
loungeSubScreen.MakeCurrent();
endHandlingTrack();
base.OnExiting(next);
return false;
}
@ -275,17 +266,6 @@ namespace osu.Game.Screens.Multi
/// <returns>The created <see cref="Room"/>.</returns>
protected virtual Room CreateNewRoom() => new Room { Name = { Value = $"{api.LocalUser}'s awesome room" } };
private void beginHandlingTrack()
{
Beatmap.BindValueChanged(updateTrack, true);
}
private void endHandlingTrack()
{
cancelLooping();
Beatmap.ValueChanged -= updateTrack;
}
private void screenPushed(IScreen lastScreen, IScreen newScreen)
{
subScreenChanged(lastScreen, newScreen);
@ -322,43 +302,10 @@ namespace osu.Game.Screens.Multi
UpdatePollingRate(isIdle.Value);
createButton.FadeTo(newScreen is LoungeSubScreen ? 1 : 0, 200);
updateTrack();
}
protected IScreen CurrentSubScreen => screenStack.CurrentScreen;
private void updateTrack(ValueChangedEvent<WorkingBeatmap> _ = null)
{
if (screenStack.CurrentScreen is RoomSubScreen)
{
var track = Beatmap.Value?.Track;
if (track != null)
{
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
track.Looping = true;
music?.EnsurePlayingSomething();
}
}
else
{
cancelLooping();
}
}
private void cancelLooping()
{
var track = Beatmap?.Value?.Track;
if (track != null)
{
track.Looping = false;
track.RestartPoint = 0;
}
}
protected abstract RoomManager CreateRoomManager();
protected abstract LoungeSubScreen CreateLounge();