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

Move player constructor configuration to dedicated class; add AllowRestart parameter

This commit is contained in:
Dean Herbert 2020-12-23 17:39:08 +09:00
parent d7279dab40
commit 3c8f871b28
12 changed files with 146 additions and 83 deletions

View File

@ -355,7 +355,11 @@ namespace osu.Game.Rulesets.Mania.Tests
protected override bool PauseOnFocusLost => false;
public ScoreAccessibleReplayPlayer(Score score)
: base(score, false, false)
: base(score, new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
}
}

View File

@ -176,7 +176,11 @@ namespace osu.Game.Rulesets.Mania.Tests
protected override bool PauseOnFocusLost => false;
public ScoreAccessibleReplayPlayer(Score score)
: base(score, false, false)
: base(score, new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
}
}

View File

@ -74,7 +74,11 @@ namespace osu.Game.Rulesets.Osu.Tests
private readonly bool userHasCustomColours;
public ExposedPlayer(bool userHasCustomColours)
: base(false, false)
: base(new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
this.userHasCustomColours = userHasCustomColours;
}

View File

@ -439,7 +439,11 @@ namespace osu.Game.Rulesets.Osu.Tests
protected override bool PauseOnFocusLost => false;
public ScoreAccessibleReplayPlayer(Score score)
: base(score, false, false)
: base(score, new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
}
}

View File

@ -378,7 +378,11 @@ namespace osu.Game.Rulesets.Osu.Tests
protected override bool PauseOnFocusLost => false;
public ScoreAccessibleReplayPlayer(Score score)
: base(score, false, false)
: base(score, new PlayerConfiguration
{
AllowPause = false,
ShowResults = false,
})
{
}
}

View File

@ -37,8 +37,8 @@ namespace osu.Game.Screens.Multi.Play
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
public TimeshiftPlayer(PlaylistItem playlistItem, bool allowPause = true)
: base(allowPause)
public TimeshiftPlayer(PlaylistItem playlistItem, PlayerConfiguration configuration = null)
: base(configuration)
{
PlaylistItem = playlistItem;
}

View File

@ -12,6 +12,7 @@ using osu.Game.Online.Multiplayer;
using osu.Game.Online.RealtimeMultiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Play;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
namespace osu.Game.Screens.Multi.RealtimeMultiplayer
@ -31,7 +32,11 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
private readonly ManualResetEventSlim startedEvent = new ManualResetEventSlim();
public RealtimePlayer(PlaylistItem playlistItem)
: base(playlistItem, false)
: base(playlistItem, new PlayerConfiguration
{
AllowPause = false,
AllowRestart = false,
})
{
}

View File

@ -128,18 +128,14 @@ namespace osu.Game.Screens.Play
/// </summary>
protected virtual bool CheckModsAllowFailure() => Mods.Value.OfType<IApplicableFailOverride>().All(m => m.PerformFail());
private readonly bool allowPause;
private readonly bool showResults;
public readonly PlayerConfiguration Configuration;
/// <summary>
/// Create a new player instance.
/// </summary>
/// <param name="allowPause">Whether pausing should be allowed. If not allowed, attempting to pause will quit.</param>
/// <param name="showResults">Whether results screen should be pushed on completion.</param>
public Player(bool allowPause = true, bool showResults = true)
public Player(PlayerConfiguration configuration = null)
{
this.allowPause = allowPause;
this.showResults = showResults;
this.Configuration = configuration ??= new PlayerConfiguration();
}
private GameplayBeatmap gameplayBeatmap;
@ -317,59 +313,77 @@ namespace osu.Game.Screens.Play
}
};
private Drawable createOverlayComponents(WorkingBeatmap working) => new Container
private Drawable createOverlayComponents(WorkingBeatmap working)
{
RelativeSizeAxes = Axes.Both,
Children = new[]
var container = new Container
{
DimmableStoryboard.OverlayLayerContainer.CreateProxy(),
BreakOverlay = new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, ScoreProcessor)
RelativeSizeAxes = Axes.Both,
Children = new[]
{
Clock = DrawableRuleset.FrameStableClock,
ProcessCustomClock = false,
Breaks = working.Beatmap.Breaks
},
// display the cursor above some HUD elements.
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
DrawableRuleset.ResumeOverlay?.CreateProxy() ?? new Container(),
HUDOverlay = new HUDOverlay(ScoreProcessor, HealthProcessor, DrawableRuleset, Mods.Value)
{
HoldToQuit =
DimmableStoryboard.OverlayLayerContainer.CreateProxy(),
BreakOverlay = new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, ScoreProcessor)
{
Action = performUserRequestedExit,
IsPaused = { BindTarget = GameplayClockContainer.IsPaused }
Clock = DrawableRuleset.FrameStableClock,
ProcessCustomClock = false,
Breaks = working.Beatmap.Breaks
},
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = GameplayClockContainer.UserPlaybackRate } } },
KeyCounter =
// display the cursor above some HUD elements.
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
DrawableRuleset.ResumeOverlay?.CreateProxy() ?? new Container(),
HUDOverlay = new HUDOverlay(ScoreProcessor, HealthProcessor, DrawableRuleset, Mods.Value)
{
AlwaysVisible = { BindTarget = DrawableRuleset.HasReplayLoaded },
IsCounting = false
HoldToQuit =
{
Action = performUserRequestedExit,
IsPaused = { BindTarget = GameplayClockContainer.IsPaused }
},
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = GameplayClockContainer.UserPlaybackRate } } },
KeyCounter =
{
AlwaysVisible = { BindTarget = DrawableRuleset.HasReplayLoaded },
IsCounting = false
},
RequestSeek = time =>
{
GameplayClockContainer.Seek(time);
GameplayClockContainer.Start();
},
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
RequestSeek = time =>
skipOverlay = new SkipOverlay(DrawableRuleset.GameplayStartTime)
{
GameplayClockContainer.Seek(time);
GameplayClockContainer.Start();
RequestSkip = GameplayClockContainer.Skip
},
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
skipOverlay = new SkipOverlay(DrawableRuleset.GameplayStartTime)
{
RequestSkip = GameplayClockContainer.Skip
},
FailOverlay = new FailOverlay
{
OnRetry = Restart,
OnQuit = performUserRequestedExit,
},
PauseOverlay = new PauseOverlay
{
OnResume = Resume,
Retries = RestartCount,
OnRetry = Restart,
OnQuit = performUserRequestedExit,
},
new HotkeyRetryOverlay
FailOverlay = new FailOverlay
{
OnRetry = Restart,
OnQuit = performUserRequestedExit,
},
PauseOverlay = new PauseOverlay
{
OnResume = Resume,
Retries = RestartCount,
OnRetry = Restart,
OnQuit = performUserRequestedExit,
},
new HotkeyExitOverlay
{
Action = () =>
{
if (!this.IsCurrentScreen()) return;
fadeOut(true);
performImmediateExit();
},
},
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, },
}
};
if (Configuration.AllowRestart)
{
container.Add(new HotkeyRetryOverlay
{
Action = () =>
{
@ -378,20 +392,11 @@ namespace osu.Game.Screens.Play
fadeOut(true);
Restart();
},
},
new HotkeyExitOverlay
{
Action = () =>
{
if (!this.IsCurrentScreen()) return;
fadeOut(true);
performImmediateExit();
},
},
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, },
});
}
};
return container;
}
private void onBreakTimeChanged(ValueChangedEvent<bool> isBreakTime)
{
@ -490,6 +495,9 @@ namespace osu.Game.Screens.Play
/// </summary>
public void Restart()
{
if (!Configuration.AllowRestart)
return;
// at the point of restarting the track should either already be paused or the volume should be zero.
// stopping here is to ensure music doesn't become audible after exiting back to PlayerLoader.
musicController.Stop();
@ -529,7 +537,7 @@ namespace osu.Game.Screens.Play
ValidForResume = false;
if (!showResults) return;
if (!Configuration.ShowResults) return;
scoreSubmissionTask ??= Task.Run(async () =>
{
@ -628,7 +636,7 @@ namespace osu.Game.Screens.Play
private bool canPause =>
// must pass basic screen conditions (beatmap loaded, instance allows pause)
LoadedBeatmapSuccessfully && allowPause && ValidForResume
LoadedBeatmapSuccessfully && Configuration.AllowPause && ValidForResume
// replays cannot be paused and exit immediately
&& !DrawableRuleset.HasReplayLoaded.Value
// cannot pause if we are already in a fail state

View File

@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
namespace osu.Game.Screens.Play
{
public class PlayerConfiguration
{
/// <summary>
/// Whether pausing should be allowed. If not allowed, attempting to pause will quit.
/// </summary>
public bool AllowPause { get; set; } = true;
/// <summary>
/// Whether results screen should be pushed on completion.
/// </summary>
public bool ShowResults { get; set; } = true;
/// <summary>
/// Whether the player should be allowed to trigger a restart.
/// </summary>
public bool AllowRestart { get; set; } = true;
}
}

View File

@ -16,8 +16,8 @@ namespace osu.Game.Screens.Play
// Disallow replays from failing. (see https://github.com/ppy/osu/issues/6108)
protected override bool CheckModsAllowFailure() => false;
public ReplayPlayer(Score score, bool allowPause = true, bool showResults = true)
: base(allowPause, showResults)
public ReplayPlayer(Score score, PlayerConfiguration configuration = null)
: base(configuration)
{
Score = score;
}

View File

@ -164,15 +164,18 @@ namespace osu.Game.Screens.Ranking
{
buttons.Add(new RetryButton { Width = 300 });
AddInternal(new HotkeyRetryOverlay
if (player?.Configuration.AllowRestart == true)
{
Action = () =>
AddInternal(new HotkeyRetryOverlay
{
if (!this.IsCurrentScreen()) return;
Action = () =>
{
if (!this.IsCurrentScreen()) return;
player?.Restart();
},
});
player?.Restart();
},
});
}
}
}

View File

@ -37,7 +37,11 @@ namespace osu.Game.Tests.Visual
public readonly List<JudgementResult> Results = new List<JudgementResult>();
public TestPlayer(bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false)
: base(allowPause, showResults)
: base(new PlayerConfiguration
{
AllowPause = allowPause,
ShowResults = showResults
})
{
PauseOnFocusLost = pauseOnFocusLost;
}