2019-06-04 16:13:16 +09:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-01-24 17:43:03 +09:00
// See the LICENCE file in the repository root for full licence text.
2018-04-13 18:19:50 +09:00
using System ;
2019-04-09 13:33:16 +09:00
using System.Collections.Generic ;
2020-03-24 14:13:46 +09:00
using System.IO ;
2018-04-13 18:19:50 +09:00
using System.Linq ;
2020-12-18 16:51:59 +09:00
using System.Threading.Tasks ;
2020-12-17 16:17:13 +09:00
using JetBrains.Annotations ;
2018-04-13 18:19:50 +09:00
using osu.Framework.Allocation ;
using osu.Framework.Audio ;
using osu.Framework.Audio.Sample ;
2019-02-21 19:04:31 +09:00
using osu.Framework.Bindables ;
2018-04-13 18:19:50 +09:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
2018-10-02 12:02:47 +09:00
using osu.Framework.Input.Events ;
2018-04-13 18:19:50 +09:00
using osu.Framework.Logging ;
using osu.Framework.Screens ;
using osu.Framework.Threading ;
using osu.Game.Beatmaps ;
using osu.Game.Configuration ;
2019-01-04 13:29:37 +09:00
using osu.Game.Graphics.Containers ;
2020-03-24 14:13:46 +09:00
using osu.Game.IO.Archives ;
2018-04-13 18:19:50 +09:00
using osu.Game.Online.API ;
2018-06-06 15:10:09 +09:00
using osu.Game.Overlays ;
2020-12-18 18:31:49 +09:00
using osu.Game.Replays ;
2018-04-13 18:19:50 +09:00
using osu.Game.Rulesets ;
using osu.Game.Rulesets.Mods ;
2020-12-18 18:31:49 +09:00
using osu.Game.Rulesets.Replays ;
2018-04-13 18:19:50 +09:00
using osu.Game.Rulesets.Scoring ;
using osu.Game.Rulesets.UI ;
2018-11-28 16:12:57 +09:00
using osu.Game.Scoring ;
2020-03-24 14:13:46 +09:00
using osu.Game.Scoring.Legacy ;
2018-04-13 18:19:50 +09:00
using osu.Game.Screens.Ranking ;
using osu.Game.Skinning ;
2019-04-12 22:54:35 +02:00
using osu.Game.Users ;
2018-04-13 18:19:50 +09:00
namespace osu.Game.Screens.Play
{
2019-11-01 15:32:06 +09:00
[Cached]
2020-10-14 19:39:48 +09:00
[Cached(typeof(ISamplePlaybackDisabler))]
2021-03-23 14:47:15 +09:00
public abstract class Player : ScreenWithBeatmapBackground , ISamplePlaybackDisabler
2018-04-13 18:19:50 +09:00
{
2020-04-20 06:42:33 +03:00
/// <summary>
/// The delay upon completion of the beatmap before displaying the results screen.
/// </summary>
public const double RESULTS_DISPLAY_DELAY = 1000.0 ;
2019-06-25 16:55:49 +09:00
public override bool AllowBackButton = > false ; // handled by HoldForMenuButton
2018-04-13 18:19:50 +09:00
2019-06-12 16:33:15 +09:00
protected override UserActivity InitialActivity = > new UserActivity . SoloGame ( Beatmap . Value . BeatmapInfo , Ruleset . Value ) ;
2018-04-13 18:19:50 +09:00
2019-01-23 20:52:00 +09:00
public override float BackgroundParallaxAmount = > 0.1f ;
2018-04-13 18:19:50 +09:00
2019-01-28 15:41:54 +09:00
public override bool HideOverlaysOnEnter = > true ;
2018-04-13 18:19:50 +09:00
2020-08-31 11:16:13 +02:00
protected override OverlayActivation InitialOverlayActivationMode = > OverlayActivation . UserTriggered ;
2020-08-08 21:21:30 +02:00
2020-09-01 16:55:10 +09:00
// We are managing our own adjustments (see OnEntering/OnExiting).
public override bool AllowRateAdjustments = > false ;
2018-06-06 15:10:09 +09:00
2021-02-05 09:07:59 +03:00
private readonly IBindable < bool > gameActive = new Bindable < bool > ( true ) ;
2020-10-14 19:39:48 +09:00
private readonly Bindable < bool > samplePlaybackDisabled = new Bindable < bool > ( ) ;
2018-06-06 15:10:09 +09:00
2019-05-10 15:39:25 +09:00
/// <summary>
/// Whether gameplay should pause when the game window focus is lost.
/// </summary>
protected virtual bool PauseOnFocusLost = > true ;
2018-06-06 15:10:09 +09:00
2018-04-13 18:19:50 +09:00
public Action RestartRequested ;
public bool HasFailed { get ; private set ; }
private Bindable < bool > mouseWheelDisabled ;
2019-02-25 13:27:44 +09:00
private readonly Bindable < bool > storyboardReplacesBackground = new Bindable < bool > ( ) ;
2018-04-13 18:19:50 +09:00
2020-10-07 17:52:39 +10:30
protected readonly Bindable < bool > LocalUserPlaying = new Bindable < bool > ( ) ;
2020-10-06 22:39:35 +10:30
2018-04-13 18:19:50 +09:00
public int RestartCount ;
2018-11-29 14:56:29 +09:00
[Resolved]
private ScoreManager scoreManager { get ; set ; }
2018-04-13 18:19:50 +09:00
2019-08-26 12:21:49 +09:00
private RulesetInfo rulesetInfo ;
2018-04-13 18:19:50 +09:00
2019-08-26 12:21:49 +09:00
private Ruleset ruleset ;
2018-04-13 18:19:50 +09:00
2020-02-14 20:14:00 +07:00
[Resolved]
private IAPIProvider api { get ; set ; }
2018-04-13 18:19:50 +09:00
2020-09-01 18:07:19 +09:00
[Resolved]
private MusicController musicController { get ; set ; }
2020-08-02 21:34:35 +02:00
2021-01-19 17:11:40 +09:00
private Sample sampleRestart ;
2018-04-13 18:19:50 +09:00
2019-12-12 15:14:59 +09:00
public BreakOverlay BreakOverlay ;
2018-04-13 18:19:50 +09:00
2020-10-11 06:15:20 +08:00
/// <summary>
/// Whether the gameplay is currently in a break.
/// </summary>
2020-10-11 21:46:55 +09:00
public readonly IBindable < bool > IsBreakTime = new BindableBool ( ) ;
2020-10-10 21:07:17 +08:00
2020-03-26 15:28:56 +09:00
private BreakTracker breakTracker ;
2020-05-12 21:12:48 +02:00
private SkipOverlay skipOverlay ;
2019-02-28 20:01:15 +09:00
protected ScoreProcessor ScoreProcessor { get ; private set ; }
2019-12-19 20:03:14 +09:00
protected HealthProcessor HealthProcessor { get ; private set ; }
2019-03-19 23:44:15 +09:00
protected DrawableRuleset DrawableRuleset { get ; private set ; }
2018-04-13 18:19:50 +09:00
2019-02-28 20:01:15 +09:00
protected HUDOverlay HUDOverlay { get ; private set ; }
2018-04-13 18:19:50 +09:00
2019-03-19 23:44:15 +09:00
public bool LoadedBeatmapSuccessfully = > DrawableRuleset ? . Objects . Any ( ) = = true ;
2018-04-13 18:19:50 +09:00
2019-03-18 00:46:15 +09:00
protected GameplayClockContainer GameplayClockContainer { get ; private set ; }
2018-04-13 18:19:50 +09:00
2019-11-25 07:24:29 +00:00
public DimmableStoryboard DimmableStoryboard { get ; private set ; }
2018-04-13 18:19:50 +09:00
2019-04-09 13:33:16 +09:00
[Cached]
2019-04-17 16:11:59 +09:00
[Cached(Type = typeof(IBindable<IReadOnlyList<Mod>>))]
2019-04-25 17:36:17 +09:00
protected new readonly Bindable < IReadOnlyList < Mod > > Mods = new Bindable < IReadOnlyList < Mod > > ( Array . Empty < Mod > ( ) ) ;
2019-04-09 13:33:16 +09:00
2019-09-18 22:49:28 +03:00
/// <summary>
2019-09-19 07:58:54 +03:00
/// Whether failing should be allowed.
2019-09-19 08:31:11 +03:00
/// By default, this checks whether all selected mods allow failing.
2019-09-18 22:49:28 +03:00
/// </summary>
2020-05-12 20:08:35 +09:00
protected virtual bool CheckModsAllowFailure ( ) = > Mods . Value . OfType < IApplicableFailOverride > ( ) . All ( m = > m . PerformFail ( ) ) ;
2019-09-18 22:49:28 +03:00
2020-12-23 17:39:08 +09:00
public readonly PlayerConfiguration Configuration ;
2019-03-26 16:53:44 +09:00
/// <summary>
/// Create a new player instance.
/// </summary>
2021-03-23 14:47:15 +09:00
protected Player ( PlayerConfiguration configuration = null )
2019-03-26 16:53:44 +09:00
{
2020-12-23 18:07:38 +09:00
Configuration = configuration ? ? new PlayerConfiguration ( ) ;
2019-03-26 16:53:44 +09:00
}
2018-04-13 18:19:50 +09:00
2020-02-14 12:30:11 +09:00
private GameplayBeatmap gameplayBeatmap ;
2020-06-18 23:35:03 +09:00
private ScreenSuspensionHandler screenSuspension ;
2020-02-14 12:30:11 +09:00
private DependencyContainer dependencies ;
protected override IReadOnlyDependencyContainer CreateChildDependencies ( IReadOnlyDependencyContainer parent )
= > dependencies = new DependencyContainer ( base . CreateChildDependencies ( parent ) ) ;
2020-03-23 19:31:43 +09:00
protected override void LoadComplete ( )
{
base . LoadComplete ( ) ;
2020-10-23 14:47:21 +09:00
// replays should never be recorded or played back when autoplay is enabled
if ( ! Mods . Value . Any ( m = > m is ModAutoplay ) )
PrepareReplay ( ) ;
2021-02-05 09:07:59 +03:00
gameActive . BindValueChanged ( _ = > updatePauseOnFocusLostState ( ) , true ) ;
2020-03-23 19:31:43 +09:00
}
2020-12-17 16:17:13 +09:00
[CanBeNull]
2020-12-14 16:52:14 +09:00
private Score recordingScore ;
2020-03-23 19:31:43 +09:00
/// <summary>
/// Run any recording / playback setup for replays.
/// </summary>
protected virtual void PrepareReplay ( )
{
2020-12-17 16:14:41 +09:00
DrawableRuleset . SetRecordTarget ( recordingScore = new Score ( ) ) ;
2020-12-14 17:33:33 +09:00
ScoreProcessor . NewJudgement + = result = > ScoreProcessor . PopulateScore ( recordingScore . ScoreInfo ) ;
2020-03-23 19:31:43 +09:00
}
2020-10-07 16:16:58 +10:30
[BackgroundDependencyLoader(true)]
2021-02-08 19:59:07 +09:00
private void load ( AudioManager audio , OsuConfigManager config , OsuGameBase game )
2018-04-13 18:19:50 +09:00
{
2019-04-17 16:11:59 +09:00
Mods . Value = base . Mods . Value . Select ( m = > m . CreateCopy ( ) ) . ToArray ( ) ;
2019-04-09 13:33:16 +09:00
2019-12-12 15:58:11 +09:00
if ( Beatmap . Value is DummyWorkingBeatmap )
return ;
IBeatmap playableBeatmap = loadPlayableBeatmap ( ) ;
2019-03-06 20:30:14 +09:00
2019-12-12 15:58:11 +09:00
if ( playableBeatmap = = null )
2018-04-13 18:19:50 +09:00
return ;
2019-05-28 17:06:01 +09:00
sampleRestart = audio . Samples . Get ( @"Gameplay/restart" ) ;
2018-04-13 18:19:50 +09:00
mouseWheelDisabled = config . GetBindable < bool > ( OsuSetting . MouseDisableWheel ) ;
2020-10-07 16:16:58 +10:30
if ( game ! = null )
2021-02-08 15:58:41 +09:00
gameActive . BindTo ( game . IsActive ) ;
2021-02-08 20:05:16 +09:00
2021-02-08 19:59:07 +09:00
if ( game is OsuGame osuGame )
LocalUserPlaying . BindTo ( osuGame . LocalUserPlaying ) ;
2020-10-06 22:39:35 +10:30
2019-12-12 15:58:11 +09:00
DrawableRuleset = ruleset . CreateDrawableRulesetWith ( playableBeatmap , Mods . Value ) ;
2019-12-24 17:01:17 +09:00
ScoreProcessor = ruleset . CreateScoreProcessor ( ) ;
ScoreProcessor . ApplyBeatmap ( playableBeatmap ) ;
2019-04-25 13:56:57 +03:00
ScoreProcessor . Mods . BindTo ( Mods ) ;
2018-04-13 18:19:50 +09:00
2019-12-27 16:14:49 +09:00
HealthProcessor = ruleset . CreateHealthProcessor ( playableBeatmap . HitObjects [ 0 ] . StartTime ) ;
2019-12-24 17:01:17 +09:00
HealthProcessor . ApplyBeatmap ( playableBeatmap ) ;
2019-12-19 20:03:14 +09:00
2018-06-29 16:49:11 +09:00
if ( ! ScoreProcessor . Mode . Disabled )
config . BindWith ( OsuSetting . ScoreDisplayMode , ScoreProcessor . Mode ) ;
2018-04-13 18:19:50 +09:00
2020-10-27 18:56:28 +09:00
InternalChild = GameplayClockContainer = CreateGameplayClockContainer ( Beatmap . Value , DrawableRuleset . GameplayStartTime ) ;
2018-04-13 18:19:50 +09:00
2020-02-14 12:30:11 +09:00
AddInternal ( gameplayBeatmap = new GameplayBeatmap ( playableBeatmap ) ) ;
2020-06-18 23:35:03 +09:00
AddInternal ( screenSuspension = new ScreenSuspensionHandler ( GameplayClockContainer ) ) ;
2020-02-14 12:30:11 +09:00
dependencies . CacheAs ( gameplayBeatmap ) ;
2020-09-29 14:09:51 +09:00
var beatmapSkinProvider = new BeatmapSkinProvidingContainer ( Beatmap . Value . Skin ) ;
// the beatmapSkinProvider is used as the fallback source here to allow the ruleset-specific skin implementation
// full access to all skin sources.
var rulesetSkinProvider = new SkinProvidingContainer ( ruleset . CreateLegacySkinProvider ( beatmapSkinProvider , playableBeatmap ) ) ;
// load the skinning hierarchy first.
// this is intentionally done in two stages to ensure things are in a loaded state before exposing the ruleset to skin sources.
GameplayClockContainer . Add ( beatmapSkinProvider . WithChild ( rulesetSkinProvider ) ) ;
rulesetSkinProvider . AddRange ( new [ ]
{
// underlay and gameplay should have access the to skinning sources.
createUnderlayComponents ( ) ,
createGameplayComponents ( Beatmap . Value , playableBeatmap )
} ) ;
2020-10-16 18:19:09 +09:00
// also give the HUD a ruleset container to allow rulesets to potentially override HUD elements (used to disable combo counters etc.)
// we may want to limit this in the future to disallow rulesets from outright replacing elements the user expects to be there.
var hudRulesetContainer = new SkinProvidingContainer ( ruleset . CreateLegacySkinProvider ( beatmapSkinProvider , playableBeatmap ) ) ;
2020-09-29 14:09:51 +09:00
// add the overlay components as a separate step as they proxy some elements from the above underlay/gameplay components.
2020-10-16 18:19:09 +09:00
GameplayClockContainer . Add ( hudRulesetContainer . WithChild ( createOverlayComponents ( Beatmap . Value ) ) ) ;
2018-04-13 18:19:50 +09:00
2020-05-08 09:37:50 +02:00
if ( ! DrawableRuleset . AllowGameplayOverlays )
2020-05-07 08:52:36 +02:00
{
HUDOverlay . ShowHud . Value = false ;
HUDOverlay . ShowHud . Disabled = true ;
BreakOverlay . Hide ( ) ;
2020-05-12 21:12:48 +02:00
skipOverlay . Hide ( ) ;
2020-05-07 08:52:36 +02:00
}
2020-10-27 18:13:45 +09:00
DrawableRuleset . FrameStableClock . WaitingOnFrames . BindValueChanged ( waiting = >
{
if ( waiting . NewValue )
GameplayClockContainer . Stop ( ) ;
else
GameplayClockContainer . Start ( ) ;
} ) ;
2020-10-27 14:10:12 +09:00
DrawableRuleset . IsPaused . BindValueChanged ( paused = >
{
updateGameplayState ( ) ;
updateSampleDisabledState ( ) ;
} ) ;
DrawableRuleset . FrameStableClock . IsCatchingUp . BindValueChanged ( _ = > updateSampleDisabledState ( ) ) ;
2020-10-27 13:54:33 +09:00
2020-10-06 22:39:35 +10:30
DrawableRuleset . HasReplayLoaded . BindValueChanged ( _ = > updateGameplayState ( ) ) ;
2020-08-16 17:18:40 +02:00
2019-08-27 18:27:21 +09:00
// bind clock into components that require it
DrawableRuleset . IsPaused . BindTo ( GameplayClockContainer . IsPaused ) ;
2018-04-13 18:19:50 +09:00
2020-11-10 23:32:30 +09:00
DrawableRuleset . NewResult + = r = >
2019-12-19 20:03:14 +09:00
{
HealthProcessor . ApplyResult ( r ) ;
ScoreProcessor . ApplyResult ( r ) ;
2020-05-03 23:55:44 +09:00
gameplayBeatmap . ApplyResult ( r ) ;
2019-12-19 20:03:14 +09:00
} ;
2020-11-10 23:32:30 +09:00
DrawableRuleset . RevertResult + = r = >
2019-12-19 20:03:14 +09:00
{
HealthProcessor . RevertResult ( r ) ;
ScoreProcessor . RevertResult ( r ) ;
} ;
2019-12-11 17:25:06 +09:00
2019-12-19 20:03:14 +09:00
// Bind the judgement processors to ourselves
2020-04-19 05:58:22 +03:00
ScoreProcessor . HasCompleted . ValueChanged + = updateCompletionState ;
2019-12-19 20:03:14 +09:00
HealthProcessor . Failed + = onFail ;
2018-04-13 18:19:50 +09:00
2019-08-27 18:27:21 +09:00
foreach ( var mod in Mods . Value . OfType < IApplicableToScoreProcessor > ( ) )
mod . ApplyToScoreProcessor ( ScoreProcessor ) ;
2019-12-19 20:03:14 +09:00
foreach ( var mod in Mods . Value . OfType < IApplicableToHealthProcessor > ( ) )
mod . ApplyToHealthProcessor ( HealthProcessor ) ;
2020-10-11 21:46:55 +09:00
IsBreakTime . BindTo ( breakTracker . IsBreakTime ) ;
2020-10-11 21:51:48 +09:00
IsBreakTime . BindValueChanged ( onBreakTimeChanged , true ) ;
2019-08-27 18:27:21 +09:00
}
2018-04-13 18:19:50 +09:00
2020-10-27 18:56:28 +09:00
protected virtual GameplayClockContainer CreateGameplayClockContainer ( WorkingBeatmap beatmap , double gameplayStart ) = > new GameplayClockContainer ( beatmap , gameplayStart ) ;
2020-09-29 14:09:51 +09:00
private Drawable createUnderlayComponents ( ) = >
DimmableStoryboard = new DimmableStoryboard ( Beatmap . Value . Storyboard ) { RelativeSizeAxes = Axes . Both } ;
2018-04-13 18:19:50 +09:00
2020-09-29 14:09:51 +09:00
private Drawable createGameplayComponents ( WorkingBeatmap working , IBeatmap playableBeatmap ) = > new ScalingContainer ( ScalingMode . Gameplay )
2019-08-27 18:27:21 +09:00
{
2020-09-29 14:09:51 +09:00
Children = new Drawable [ ]
2019-08-26 12:21:49 +09:00
{
2020-09-29 14:09:51 +09:00
DrawableRuleset . With ( r = >
r . FrameStableComponents . Children = new Drawable [ ]
{
ScoreProcessor ,
HealthProcessor ,
2020-11-13 13:35:01 +09:00
new ComboEffects ( ScoreProcessor ) ,
2020-09-29 14:09:51 +09:00
breakTracker = new BreakTracker ( DrawableRuleset . GameplayStartTime , ScoreProcessor )
{
Breaks = working . Beatmap . Breaks
}
} ) ,
}
} ;
2018-04-13 18:19:50 +09:00
2020-12-23 17:39:08 +09:00
private Drawable createOverlayComponents ( WorkingBeatmap working )
2019-08-27 18:27:21 +09:00
{
2020-12-23 17:39:08 +09:00
var container = new Container
2018-04-13 18:19:50 +09:00
{
2020-12-23 17:39:08 +09:00
RelativeSizeAxes = Axes . Both ,
Children = new [ ]
2020-03-27 21:19:49 +01:00
{
2020-12-23 17:39:08 +09:00
DimmableStoryboard . OverlayLayerContainer . CreateProxy ( ) ,
BreakOverlay = new BreakOverlay ( working . Beatmap . BeatmapInfo . LetterboxInBreaks , ScoreProcessor )
2018-04-13 18:19:50 +09:00
{
2020-12-23 17:39:08 +09:00
Clock = DrawableRuleset . FrameStableClock ,
ProcessCustomClock = false ,
Breaks = working . Beatmap . Breaks
2019-05-10 15:51:12 +09:00
} ,
2020-12-23 17:39:08 +09:00
// 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 )
2020-03-06 18:00:17 +09:00
{
2020-12-23 17:39:08 +09:00
HoldToQuit =
{
2021-02-09 16:24:29 +09:00
Action = ( ) = > PerformExit ( true ) ,
2020-12-23 17:39:08 +09:00
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
2020-03-06 18:00:17 +09:00
} ,
2020-12-23 17:39:08 +09:00
skipOverlay = new SkipOverlay ( DrawableRuleset . GameplayStartTime )
2020-11-24 15:41:56 +09:00
{
2021-01-21 17:10:11 -05:00
RequestSkip = performUserRequestedSkip
2020-11-24 15:41:56 +09:00
} ,
2020-12-23 17:39:08 +09:00
FailOverlay = new FailOverlay
2018-04-13 18:19:50 +09:00
{
2020-12-23 17:39:08 +09:00
OnRetry = Restart ,
2021-02-09 16:24:29 +09:00
OnQuit = ( ) = > PerformExit ( true ) ,
2020-12-23 17:39:08 +09:00
} ,
PauseOverlay = new PauseOverlay
{
OnResume = Resume ,
Retries = RestartCount ,
OnRetry = Restart ,
2021-02-09 16:24:29 +09:00
OnQuit = ( ) = > PerformExit ( true ) ,
2020-12-23 17:39:08 +09:00
} ,
new HotkeyExitOverlay
{
Action = ( ) = >
{
if ( ! this . IsCurrentScreen ( ) ) return ;
2018-04-13 18:19:50 +09:00
2020-12-23 17:39:08 +09:00
fadeOut ( true ) ;
2021-02-09 17:28:57 +09:00
PerformExit ( false ) ;
2020-12-23 17:39:08 +09:00
} ,
2018-04-13 18:19:50 +09:00
} ,
2020-12-23 17:39:08 +09:00
failAnimation = new FailAnimation ( DrawableRuleset ) { OnComplete = onFailComplete , } ,
}
} ;
2020-12-24 16:29:51 +09:00
if ( ! Configuration . AllowSkippingIntro )
skipOverlay . Expire ( ) ;
2020-12-23 17:39:08 +09:00
if ( Configuration . AllowRestart )
{
container . Add ( new HotkeyRetryOverlay
2019-06-24 18:15:27 +09:00
{
Action = ( ) = >
{
if ( ! this . IsCurrentScreen ( ) ) return ;
fadeOut ( true ) ;
2020-12-23 17:39:08 +09:00
Restart ( ) ;
2019-06-24 18:15:27 +09:00
} ,
2020-12-23 17:39:08 +09:00
} ) ;
2020-09-29 14:09:51 +09:00
}
2020-12-23 17:39:08 +09:00
return container ;
}
2018-04-13 18:19:50 +09:00
2020-03-06 18:00:17 +09:00
private void onBreakTimeChanged ( ValueChangedEvent < bool > isBreakTime )
2020-02-29 21:07:42 +05:30
{
2020-10-11 21:51:48 +09:00
updateGameplayState ( ) ;
2020-03-06 18:00:17 +09:00
updatePauseOnFocusLostState ( ) ;
HUDOverlay . KeyCounter . IsCounting = ! isBreakTime . NewValue ;
2020-02-29 21:07:42 +05:30
}
2020-10-06 22:39:35 +10:30
private void updateGameplayState ( )
2020-08-03 21:25:45 +02:00
{
2020-10-06 22:39:35 +10:30
bool inGameplay = ! DrawableRuleset . HasReplayLoaded . Value & & ! DrawableRuleset . IsPaused . Value & & ! breakTracker . IsBreakTime . Value ;
OverlayActivationMode . Value = inGameplay ? OverlayActivation . Disabled : OverlayActivation . UserTriggered ;
2020-10-07 17:52:39 +10:30
LocalUserPlaying . Value = inGameplay ;
2020-08-03 21:25:45 +02:00
}
2020-10-27 14:10:12 +09:00
private void updateSampleDisabledState ( )
{
samplePlaybackDisabled . Value = DrawableRuleset . FrameStableClock . IsCatchingUp . Value | | GameplayClockContainer . GameplayClock . IsPaused . Value ;
}
2021-02-05 09:07:59 +03:00
private void updatePauseOnFocusLostState ( )
{
2021-02-22 16:59:35 +03:00
if ( ! PauseOnFocusLost | | ! pausingSupportedByCurrentState | | breakTracker . IsBreakTime . Value )
2021-02-05 09:07:59 +03:00
return ;
if ( gameActive . Value = = false )
2021-02-19 09:35:29 +03:00
{
2021-02-22 10:03:27 +03:00
bool paused = Pause ( ) ;
2021-02-23 13:23:32 +09:00
// if the initial pause could not be satisfied, the pause cooldown may be active.
// reschedule the pause attempt until it can be achieved.
2021-02-22 10:03:27 +03:00
if ( ! paused )
2021-02-19 11:33:26 +03:00
Scheduler . AddOnce ( updatePauseOnFocusLostState ) ;
2021-02-19 09:35:29 +03:00
}
2021-02-05 09:07:59 +03:00
}
2019-12-11 15:45:50 +09:00
2019-12-12 15:58:11 +09:00
private IBeatmap loadPlayableBeatmap ( )
2018-04-13 18:19:50 +09:00
{
2019-12-12 15:58:11 +09:00
IBeatmap playable ;
2019-03-06 20:30:14 +09:00
try
{
2019-12-12 15:58:11 +09:00
if ( Beatmap . Value . Beatmap = = null )
2019-03-06 20:30:14 +09:00
throw new InvalidOperationException ( "Beatmap was not loaded" ) ;
2018-04-13 18:19:50 +09:00
2019-12-12 15:58:11 +09:00
rulesetInfo = Ruleset . Value ? ? Beatmap . Value . BeatmapInfo . Ruleset ;
2019-08-26 12:21:49 +09:00
ruleset = rulesetInfo . CreateInstance ( ) ;
2019-03-06 20:30:14 +09:00
try
{
2019-12-12 15:58:11 +09:00
playable = Beatmap . Value . GetPlayableBeatmap ( ruleset . RulesetInfo , Mods . Value ) ;
2019-03-06 20:30:14 +09:00
}
catch ( BeatmapInvalidForRulesetException )
{
2019-12-12 15:58:11 +09:00
// A playable beatmap may not be creatable with the user's preferred ruleset, so try using the beatmap's default ruleset
rulesetInfo = Beatmap . Value . BeatmapInfo . Ruleset ;
2019-08-26 12:21:49 +09:00
ruleset = rulesetInfo . CreateInstance ( ) ;
2019-12-12 15:58:11 +09:00
playable = Beatmap . Value . GetPlayableBeatmap ( rulesetInfo , Mods . Value ) ;
2018-04-13 18:19:50 +09:00
}
2019-12-12 15:58:11 +09:00
if ( playable . HitObjects . Count = = 0 )
2019-03-06 20:30:14 +09:00
{
Logger . Log ( "Beatmap contains no hit objects!" , level : LogLevel . Error ) ;
return null ;
}
}
catch ( Exception e )
{
2020-09-23 00:30:20 -07:00
Logger . Error ( e , "Could not load beatmap successfully!" ) ;
2019-03-06 20:30:14 +09:00
//couldn't load, hard abort!
return null ;
}
2018-04-21 20:21:09 +03:00
2019-12-12 15:58:11 +09:00
return playable ;
2018-04-13 18:19:50 +09:00
}
2018-07-19 01:18:07 +09:00
2020-12-23 15:51:26 +01:00
/// <summary>
/// Exits the <see cref="Player"/>.
/// </summary>
2021-02-09 17:14:16 +09:00
/// <param name="showDialogFirst">
/// Whether the pause or fail dialog should be shown before performing an exit.
/// If true and a dialog is not yet displayed, the exit will be blocked the the relevant dialog will display instead.
2020-12-23 15:51:26 +01:00
/// </param>
2021-02-09 17:14:16 +09:00
protected void PerformExit ( bool showDialogFirst )
2018-12-13 16:17:24 +09:00
{
2019-06-24 18:15:27 +09:00
// if a restart has been requested, cancel any pending completion (user has shown intent to restart).
2019-08-06 23:05:12 +09:00
completionProgressDelegate ? . Cancel ( ) ;
2018-04-13 18:19:50 +09:00
2021-02-15 15:57:21 +09:00
// there is a chance that the exit was performed after the transition to results has started.
// we want to give the user what they want, so forcefully return to this screen (to proceed with the upwards exit process).
2021-02-09 16:24:29 +09:00
if ( ! this . IsCurrentScreen ( ) )
{
ValidForResume = false ;
this . MakeCurrent ( ) ;
2021-02-15 14:03:41 +09:00
return ;
2021-02-09 16:24:29 +09:00
}
2018-04-13 18:19:50 +09:00
2021-02-19 17:26:54 +09:00
bool pauseOrFailDialogVisible =
PauseOverlay . State . Value = = Visibility . Visible | | FailOverlay . State . Value = = Visibility . Visible ;
2020-12-23 15:51:26 +01:00
2021-02-19 17:26:54 +09:00
if ( showDialogFirst & & ! pauseOrFailDialogVisible )
2021-02-09 16:24:29 +09:00
{
2021-02-15 15:57:21 +09:00
// if the fail animation is currently in progress, accelerate it (it will show the pause dialog on completion).
2021-02-19 17:26:54 +09:00
if ( ValidForResume & & HasFailed )
2021-02-09 16:24:29 +09:00
{
failAnimation . FinishTransforms ( true ) ;
return ;
}
2021-02-20 13:35:25 +09:00
// there's a chance the pausing is not supported in the current state, at which point immediate exit should be preferred.
if ( pausingSupportedByCurrentState )
{
// in the case a dialog needs to be shown, attempt to pause and show it.
// this may fail (see internal checks in Pause()) but the fail cases are temporary, so don't fall through to Exit().
Pause ( ) ;
return ;
}
2021-02-09 16:24:29 +09:00
}
this . Exit ( ) ;
2018-04-13 18:19:50 +09:00
}
2021-01-21 17:10:11 -05:00
private void performUserRequestedSkip ( )
{
// user requested skip
// disable sample playback to stop currently playing samples and perform skip
samplePlaybackDisabled . Value = true ;
GameplayClockContainer . Skip ( ) ;
// return samplePlaybackDisabled.Value to what is defined by the beatmap's current state
updateSampleDisabledState ( ) ;
}
2019-11-01 15:51:45 +09:00
/// <summary>
/// Restart gameplay via a parent <see cref="PlayerLoader"/>.
/// <remarks>This can be called from a child screen in order to trigger the restart process.</remarks>
/// </summary>
2018-04-13 18:19:50 +09:00
public void Restart ( )
{
2020-12-23 17:39:08 +09:00
if ( ! Configuration . AllowRestart )
return ;
2020-10-07 17:40:54 +09:00
// 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 ( ) ;
2018-04-13 18:19:50 +09:00
sampleRestart ? . Play ( ) ;
RestartRequested ? . Invoke ( ) ;
2019-11-01 15:32:06 +09:00
2021-02-09 17:14:16 +09:00
PerformExit ( false ) ;
2018-04-13 18:19:50 +09:00
}
2019-08-06 23:05:12 +09:00
private ScheduledDelegate completionProgressDelegate ;
2021-03-23 15:45:22 +09:00
private Task < ScoreInfo > prepareScoreForDisplayTask ;
2018-04-13 18:19:50 +09:00
2020-04-19 05:58:22 +03:00
private void updateCompletionState ( ValueChangedEvent < bool > completionState )
2018-04-13 18:19:50 +09:00
{
2020-03-19 14:10:54 +09:00
// screen may be in the exiting transition phase.
if ( ! this . IsCurrentScreen ( ) )
return ;
2020-04-19 05:59:56 +03:00
if ( ! completionState . NewValue )
{
completionProgressDelegate ? . Cancel ( ) ;
completionProgressDelegate = null ;
ValidForResume = true ;
return ;
}
2020-04-21 11:51:20 +09:00
if ( completionProgressDelegate ! = null )
throw new InvalidOperationException ( $"{nameof(updateCompletionState)} was fired more than once" ) ;
2018-04-13 18:19:50 +09:00
// Only show the completion screen if the player hasn't failed
2020-04-21 11:51:20 +09:00
if ( HealthProcessor . HasFailed )
2018-04-13 18:19:50 +09:00
return ;
ValidForResume = false ;
2020-12-23 17:39:08 +09:00
if ( ! Configuration . ShowResults ) return ;
2018-04-13 18:19:50 +09:00
2021-03-23 15:45:22 +09:00
prepareScoreForDisplayTask ? ? = Task . Run ( async ( ) = >
2020-12-18 16:51:59 +09:00
{
2020-12-18 18:20:36 +09:00
var score = CreateScore ( ) ;
try
2020-12-18 16:51:59 +09:00
{
2021-03-23 15:45:22 +09:00
await PrepareScoreForResultsAsync ( score ) . ConfigureAwait ( false ) ;
2020-12-18 18:20:36 +09:00
}
catch ( Exception ex )
{
2021-03-23 15:45:22 +09:00
Logger . Error ( ex , "Score preparation failed!" ) ;
2020-12-18 16:51:59 +09:00
}
2020-12-19 03:32:05 +09:00
try
{
2021-03-08 12:57:16 +09:00
await ImportScore ( score ) . ConfigureAwait ( false ) ;
2020-12-19 03:32:05 +09:00
}
catch ( Exception ex )
{
Logger . Error ( ex , "Score import failed!" ) ;
}
return score . ScoreInfo ;
2020-12-18 18:20:36 +09:00
} ) ;
using ( BeginDelayedSequence ( RESULTS_DISPLAY_DELAY ) )
scheduleCompletion ( ) ;
2018-04-13 18:19:50 +09:00
}
2020-12-18 18:20:36 +09:00
private void scheduleCompletion ( ) = > completionProgressDelegate = Schedule ( ( ) = >
{
2021-03-23 15:45:22 +09:00
if ( ! prepareScoreForDisplayTask . IsCompleted )
2020-12-18 18:20:36 +09:00
{
scheduleCompletion ( ) ;
return ;
}
// screen may be in the exiting transition phase.
if ( this . IsCurrentScreen ( ) )
2021-03-23 15:45:22 +09:00
this . Push ( CreateResults ( prepareScoreForDisplayTask . Result ) ) ;
2020-12-18 18:20:36 +09:00
} ) ;
2019-03-18 11:48:11 +09:00
protected override bool OnScroll ( ScrollEvent e ) = > mouseWheelDisabled . Value & & ! GameplayClockContainer . IsPaused . Value ;
#region Fail Logic
protected FailOverlay FailOverlay { get ; private set ; }
2019-06-04 16:13:16 +09:00
private FailAnimation failAnimation ;
2018-04-13 18:19:50 +09:00
private bool onFail ( )
{
2020-05-12 20:08:35 +09:00
if ( ! CheckModsAllowFailure ( ) )
2018-04-13 18:19:50 +09:00
return false ;
2018-10-31 07:03:37 -04:00
HasFailed = true ;
2019-03-18 11:48:11 +09:00
// There is a chance that we could be in a paused state as the ruleset's internal clock (see FrameStabilityContainer)
// could process an extra frame after the GameplayClock is stopped.
// In such cases we want the fail state to precede a user triggered pause.
2019-06-11 14:28:52 +09:00
if ( PauseOverlay . State . Value = = Visibility . Visible )
2019-03-18 11:48:11 +09:00
PauseOverlay . Hide ( ) ;
2019-09-19 01:45:59 +09:00
failAnimation . Start ( ) ;
2019-09-19 17:53:10 +09:00
if ( Mods . Value . OfType < IApplicableFailOverride > ( ) . Any ( m = > m . RestartOnFail ) )
2018-10-14 11:18:52 -04:00
Restart ( ) ;
2018-04-13 18:19:50 +09:00
return true ;
}
2019-06-04 16:13:16 +09:00
// Called back when the transform finishes
private void onFailComplete ( )
{
GameplayClockContainer . Stop ( ) ;
2019-03-18 11:48:11 +09:00
FailOverlay . Retries = RestartCount ;
FailOverlay . Show ( ) ;
2018-04-13 18:19:50 +09:00
}
2019-03-18 11:48:11 +09:00
#endregion
#region Pause Logic
public bool IsResuming { get ; private set ; }
/// <summary>
/// The amount of gameplay time after which a second pause is allowed.
/// </summary>
private const double pause_cooldown = 1000 ;
protected PauseOverlay PauseOverlay { get ; private set ; }
private double? lastPauseActionTime ;
2021-02-19 11:42:30 +03:00
protected bool PauseCooldownActive = >
2021-02-19 09:34:39 +03:00
lastPauseActionTime . HasValue & & GameplayClockContainer . GameplayClock . CurrentTime < lastPauseActionTime + pause_cooldown ;
2021-02-20 13:35:25 +09:00
/// <summary>
/// A set of conditionals which defines whether the current game state and configuration allows for
/// pausing to be attempted via <see cref="Pause"/>. If false, the game should generally exit if a user pause
/// is attempted.
/// </summary>
private bool pausingSupportedByCurrentState = >
2019-03-18 11:48:11 +09:00
// must pass basic screen conditions (beatmap loaded, instance allows pause)
2020-12-23 17:39:08 +09:00
LoadedBeatmapSuccessfully & & Configuration . AllowPause & & ValidForResume
2019-03-18 11:48:11 +09:00
// replays cannot be paused and exit immediately
2019-03-20 15:27:06 +09:00
& & ! DrawableRuleset . HasReplayLoaded . Value
2019-03-18 11:48:11 +09:00
// cannot pause if we are already in a fail state
2021-02-20 13:35:25 +09:00
& & ! HasFailed ;
2019-03-18 11:48:11 +09:00
private bool canResume = >
// cannot resume from a non-paused state
GameplayClockContainer . IsPaused . Value
// cannot resume if we are already in a fail state
& & ! HasFailed
// already resuming
& & ! IsResuming ;
2021-02-22 10:03:27 +03:00
public bool Pause ( )
2019-03-18 11:48:11 +09:00
{
2021-02-22 10:03:27 +03:00
if ( ! pausingSupportedByCurrentState ) return false ;
2021-02-20 13:35:25 +09:00
2021-02-22 10:03:27 +03:00
if ( ! IsResuming & & PauseCooldownActive )
return false ;
2019-03-18 11:48:11 +09:00
2019-10-25 14:57:49 -05:00
if ( IsResuming )
{
DrawableRuleset . CancelResume ( ) ;
2019-11-01 14:43:52 +09:00
IsResuming = false ;
2019-10-25 14:57:49 -05:00
}
2019-03-18 11:48:11 +09:00
GameplayClockContainer . Stop ( ) ;
PauseOverlay . Show ( ) ;
lastPauseActionTime = GameplayClockContainer . GameplayClock . CurrentTime ;
2021-02-22 10:03:27 +03:00
return true ;
2019-03-18 11:48:11 +09:00
}
public void Resume ( )
{
if ( ! canResume ) return ;
IsResuming = true ;
PauseOverlay . Hide ( ) ;
2019-03-18 14:40:53 +09:00
2019-04-07 16:32:55 -03:00
// breaks and time-based conditions may allow instant resume.
2020-03-26 15:28:56 +09:00
if ( breakTracker . IsBreakTime . Value )
2019-03-18 14:40:53 +09:00
completeResume ( ) ;
else
2019-03-20 15:27:06 +09:00
DrawableRuleset . RequestResume ( completeResume ) ;
2019-03-18 14:40:53 +09:00
void completeResume ( )
{
GameplayClockContainer . Start ( ) ;
IsResuming = false ;
}
2019-03-18 11:48:11 +09:00
}
#endregion
#region Screen Logic
2019-01-23 20:52:00 +09:00
public override void OnEntering ( IScreen last )
2018-04-13 18:19:50 +09:00
{
base . OnEntering ( last ) ;
2018-04-20 17:30:27 +09:00
if ( ! LoadedBeatmapSuccessfully )
2018-04-13 18:19:50 +09:00
return ;
2019-01-23 20:52:00 +09:00
Alpha = 0 ;
this
2018-04-13 18:19:50 +09:00
. ScaleTo ( 0.7f )
. ScaleTo ( 1 , 750 , Easing . OutQuint )
. Delay ( 250 )
. FadeIn ( 250 ) ;
2021-01-04 18:32:23 +09:00
ApplyToBackground ( b = >
{
b . EnableUserDim . Value = true ;
b . BlurAmount . Value = 0 ;
// bind component bindables.
b . IsBreakTime . BindTo ( breakTracker . IsBreakTime ) ;
b . StoryboardReplacesBackground . BindTo ( storyboardReplacesBackground ) ;
} ) ;
2018-04-13 18:19:50 +09:00
2020-07-22 12:41:06 +09:00
HUDOverlay . IsBreakTime . BindTo ( breakTracker . IsBreakTime ) ;
2020-03-26 15:28:56 +09:00
DimmableStoryboard . IsBreakTime . BindTo ( breakTracker . IsBreakTime ) ;
2019-12-10 23:06:13 +03:00
2019-07-12 11:50:06 +09:00
DimmableStoryboard . StoryboardReplacesBackground . BindTo ( storyboardReplacesBackground ) ;
2018-04-13 18:19:50 +09:00
2019-02-25 13:15:37 +09:00
storyboardReplacesBackground . Value = Beatmap . Value . Storyboard . ReplacesBackground & & Beatmap . Value . Storyboard . HasDrawable ;
2019-02-18 16:34:11 +09:00
2019-11-25 07:24:29 +00:00
foreach ( var mod in Mods . Value . OfType < IApplicableToPlayer > ( ) )
mod . ApplyToPlayer ( this ) ;
2019-06-29 04:23:59 +03:00
foreach ( var mod in Mods . Value . OfType < IApplicableToHUD > ( ) )
mod . ApplyToHUD ( HUDOverlay ) ;
2020-08-02 21:34:35 +02:00
2020-09-01 18:07:19 +09:00
// Our mods are local copies of the global mods so they need to be re-applied to the track.
// This is done through the music controller (for now), because resetting speed adjustments on the beatmap track also removes adjustments provided by DrawableTrack.
// Todo: In the future, player will receive in a track and will probably not have to worry about this...
musicController . ResetTrackAdjustments ( ) ;
2020-09-01 16:55:10 +09:00
foreach ( var mod in Mods . Value . OfType < IApplicableToTrack > ( ) )
2020-09-01 18:07:19 +09:00
mod . ApplyToTrack ( musicController . CurrentTrack ) ;
2020-09-03 21:56:47 +02:00
2020-10-06 22:39:35 +10:30
updateGameplayState ( ) ;
2020-12-24 15:32:55 +09:00
GameplayClockContainer . FadeInFromZero ( 750 , Easing . OutQuint ) ;
StartGameplay ( ) ;
}
/// <summary>
/// Called to trigger the starting of the gameplay clock and underlying gameplay.
/// This will be called on entering the player screen once. A derived class may block the first call to this to delay the start of gameplay.
/// </summary>
protected virtual void StartGameplay ( )
{
if ( GameplayClockContainer . GameplayClock . IsRunning )
throw new InvalidOperationException ( $"{nameof(StartGameplay)} should not be called when the gameplay clock is already running" ) ;
GameplayClockContainer . Restart ( ) ;
2018-04-13 18:19:50 +09:00
}
2019-01-23 20:52:00 +09:00
public override void OnSuspending ( IScreen next )
2018-04-13 18:19:50 +09:00
{
2020-06-18 23:35:03 +09:00
screenSuspension ? . Expire ( ) ;
2018-04-13 18:19:50 +09:00
fadeOut ( ) ;
base . OnSuspending ( next ) ;
}
2019-01-23 20:52:00 +09:00
public override bool OnExiting ( IScreen next )
2018-04-13 18:19:50 +09:00
{
2020-06-18 23:35:03 +09:00
screenSuspension ? . Expire ( ) ;
2019-08-06 23:05:12 +09:00
if ( completionProgressDelegate ! = null & & ! completionProgressDelegate . Cancelled & & ! completionProgressDelegate . Completed )
2018-07-28 08:34:51 +10:00
{
2019-08-06 23:05:12 +09:00
// proceed to result screen if beatmap already finished playing
2020-03-19 14:10:54 +09:00
completionProgressDelegate . RunTask ( ) ;
2018-07-28 08:34:51 +10:00
return true ;
}
2019-11-01 14:11:18 +09:00
// GameplayClockContainer performs seeks / start / stop operations on the beatmap's track.
// as we are no longer the current screen, we cannot guarantee the track is still usable.
2019-12-23 19:13:36 +09:00
GameplayClockContainer ? . StopUsingBeatmapClock ( ) ;
2019-11-01 14:11:18 +09:00
2020-09-01 18:07:19 +09:00
musicController . ResetTrackAdjustments ( ) ;
2020-09-01 16:55:10 +09:00
2019-03-16 14:20:10 +09:00
fadeOut ( ) ;
return base . OnExiting ( next ) ;
2018-04-13 18:19:50 +09:00
}
2020-12-18 17:47:33 +09:00
/// <summary>
/// Creates the player's <see cref="Score"/>.
/// </summary>
/// <returns>The <see cref="Score"/>.</returns>
2020-12-18 16:51:59 +09:00
protected virtual Score CreateScore ( )
2020-12-18 15:36:24 +09:00
{
2020-12-18 16:51:59 +09:00
var score = new Score
2020-12-18 15:36:24 +09:00
{
2020-12-18 16:51:59 +09:00
ScoreInfo = new ScoreInfo
{
Beatmap = Beatmap . Value . BeatmapInfo ,
Ruleset = rulesetInfo ,
Mods = Mods . Value . ToArray ( ) ,
}
2020-12-18 15:36:24 +09:00
} ;
if ( DrawableRuleset . ReplayScore ! = null )
2020-12-18 16:51:59 +09:00
{
score . ScoreInfo . User = DrawableRuleset . ReplayScore . ScoreInfo ? . User ? ? new GuestUser ( ) ;
score . Replay = DrawableRuleset . ReplayScore . Replay ;
}
2020-12-18 15:36:24 +09:00
else
2020-12-18 16:51:59 +09:00
{
score . ScoreInfo . User = api . LocalUser . Value ;
2020-12-18 18:31:49 +09:00
score . Replay = new Replay { Frames = recordingScore ? . Replay . Frames . ToList ( ) ? ? new List < ReplayFrame > ( ) } ;
2020-12-18 16:51:59 +09:00
}
2020-12-18 15:36:24 +09:00
2020-12-18 16:51:59 +09:00
ScoreProcessor . PopulateScore ( score . ScoreInfo ) ;
2020-12-18 15:36:24 +09:00
return score ;
}
2020-12-18 17:47:33 +09:00
/// <summary>
2020-12-19 03:32:05 +09:00
/// Imports the player's <see cref="Score"/> to the local database.
2020-12-18 17:47:33 +09:00
/// </summary>
2020-12-19 03:32:05 +09:00
/// <param name="score">The <see cref="Score"/> to import.</param>
/// <returns>The imported score.</returns>
2020-12-19 13:58:56 +09:00
protected virtual Task ImportScore ( Score score )
2020-03-29 22:51:28 +09:00
{
2020-12-18 16:51:59 +09:00
// Replays are already populated and present in the game's database, so should not be re-imported.
2020-03-29 22:51:28 +09:00
if ( DrawableRuleset . ReplayScore ! = null )
2020-12-19 13:58:56 +09:00
return Task . CompletedTask ;
2020-03-29 22:51:28 +09:00
2020-12-18 16:51:59 +09:00
LegacyByteArrayReader replayReader ;
2020-03-29 22:51:28 +09:00
2020-12-18 16:51:59 +09:00
using ( var stream = new MemoryStream ( ) )
2020-03-29 22:51:28 +09:00
{
2020-12-18 16:51:59 +09:00
new LegacyScoreEncoder ( score , gameplayBeatmap . PlayableBeatmap ) . Encode ( stream ) ;
replayReader = new LegacyByteArrayReader ( stream . ToArray ( ) , "replay.osr" ) ;
2020-03-29 22:51:28 +09:00
}
2020-12-19 13:58:56 +09:00
return scoreManager . Import ( score . ScoreInfo , replayReader ) ;
2020-03-29 22:51:28 +09:00
}
2020-12-19 03:32:05 +09:00
/// <summary>
2021-03-23 15:45:22 +09:00
/// Prepare the <see cref="Score"/> for display at results.
2020-12-19 03:32:05 +09:00
/// </summary>
2021-03-23 15:45:22 +09:00
/// <param name="score">The <see cref="Score"/> to prepare.</param>
/// <returns>A task that prepares the provided score. On completion, the score is assumed to be ready for display.</returns>
protected virtual Task PrepareScoreForResultsAsync ( Score score ) = > Task . CompletedTask ;
2020-12-19 03:32:05 +09:00
2020-12-18 17:47:33 +09:00
/// <summary>
/// Creates the <see cref="ResultsScreen"/> for a <see cref="ScoreInfo"/>.
/// </summary>
/// <param name="score">The <see cref="ScoreInfo"/> to be displayed in the results screen.</param>
/// <returns>The <see cref="ResultsScreen"/>.</returns>
2020-12-18 15:36:24 +09:00
protected virtual ResultsScreen CreateResults ( ScoreInfo score ) = > new SoloResultsScreen ( score , true ) ;
2018-08-02 19:08:23 +09:00
private void fadeOut ( bool instant = false )
2018-04-13 18:19:50 +09:00
{
2018-08-02 19:08:23 +09:00
float fadeOutDuration = instant ? 0 : 250 ;
2019-01-23 20:52:00 +09:00
this . FadeOut ( fadeOutDuration ) ;
2018-04-13 18:19:50 +09:00
2021-01-04 18:32:23 +09:00
ApplyToBackground ( b = > b . EnableUserDim . Value = false ) ;
2019-02-25 13:15:37 +09:00
storyboardReplacesBackground . Value = false ;
2018-04-13 18:19:50 +09:00
}
2019-03-18 11:48:11 +09:00
#endregion
2020-10-14 19:39:48 +09:00
IBindable < bool > ISamplePlaybackDisabler . SamplePlaybackDisabled = > samplePlaybackDisabled ;
2018-04-13 18:19:50 +09:00
}
}