2021-11-10 23:11:25 +01:00
|
|
|
// 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.
|
|
|
|
|
2022-11-17 12:32:35 +09:00
|
|
|
using System.Linq;
|
2021-11-11 15:45:10 +01:00
|
|
|
using osu.Framework.Allocation;
|
2021-11-11 15:25:58 +01:00
|
|
|
using osu.Framework.Screens;
|
2021-11-12 12:50:38 +01:00
|
|
|
using osu.Game.Beatmaps;
|
2021-11-11 15:45:10 +01:00
|
|
|
using osu.Game.Overlays;
|
2021-11-10 23:11:25 +01:00
|
|
|
using osu.Game.Screens.Play;
|
2023-02-12 13:04:12 -08:00
|
|
|
using osu.Game.Users;
|
2021-11-10 23:11:25 +01:00
|
|
|
|
2021-11-12 12:07:38 +01:00
|
|
|
namespace osu.Game.Screens.Edit.GameplayTest
|
2021-11-10 23:11:25 +01:00
|
|
|
{
|
2022-11-24 14:32:20 +09:00
|
|
|
public partial class EditorPlayer : Player
|
2021-11-10 23:11:25 +01:00
|
|
|
{
|
2021-11-12 13:12:25 +01:00
|
|
|
private readonly Editor editor;
|
2021-11-12 12:50:38 +01:00
|
|
|
private readonly EditorState editorState;
|
|
|
|
|
2023-02-12 13:04:12 -08:00
|
|
|
protected override UserActivity InitialActivity => new UserActivity.TestingBeatmap(Beatmap.Value.BeatmapInfo, Ruleset.Value);
|
|
|
|
|
2021-11-12 12:50:38 +01:00
|
|
|
[Resolved]
|
2022-11-16 17:54:49 +09:00
|
|
|
private MusicController musicController { get; set; } = null!;
|
|
|
|
|
2021-11-12 13:12:25 +01:00
|
|
|
public EditorPlayer(Editor editor)
|
2021-11-10 23:11:25 +01:00
|
|
|
: base(new PlayerConfiguration { ShowResults = false })
|
|
|
|
{
|
2021-11-12 13:12:25 +01:00
|
|
|
this.editor = editor;
|
|
|
|
editorState = editor.GetState();
|
2021-11-10 23:11:25 +01:00
|
|
|
}
|
|
|
|
|
2021-11-12 12:50:38 +01:00
|
|
|
protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
|
2022-08-22 14:11:06 +09:00
|
|
|
{
|
|
|
|
var masterGameplayClockContainer = new MasterGameplayClockContainer(beatmap, gameplayStart);
|
2022-11-17 12:32:35 +09:00
|
|
|
|
|
|
|
// Only reset the time to the current point if the editor is later than the normal start time (and the first object).
|
|
|
|
// This allows more sane test playing from the start of the beatmap (ie. correctly adding lead-in time).
|
|
|
|
if (editorState.Time > gameplayStart && editorState.Time > DrawableRuleset.Objects.FirstOrDefault()?.StartTime)
|
|
|
|
masterGameplayClockContainer.Reset(editorState.Time);
|
|
|
|
|
2022-08-22 14:11:06 +09:00
|
|
|
return masterGameplayClockContainer;
|
|
|
|
}
|
2021-11-11 15:45:10 +01:00
|
|
|
|
2021-11-11 15:25:58 +01:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
ScoreProcessor.HasCompleted.BindValueChanged(completed =>
|
|
|
|
{
|
|
|
|
if (completed.NewValue)
|
2022-07-14 00:58:32 +09:00
|
|
|
{
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
if (this.IsCurrentScreen())
|
|
|
|
this.Exit();
|
|
|
|
}, RESULTS_DISPLAY_DELAY);
|
|
|
|
}
|
2021-11-11 15:25:58 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-10 23:11:25 +01:00
|
|
|
protected override void PrepareReplay()
|
|
|
|
{
|
|
|
|
// don't record replays.
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool CheckModsAllowFailure() => false; // never fail.
|
2021-11-11 15:45:10 +01:00
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2021-11-12 13:51:02 +01:00
|
|
|
{
|
2022-04-22 00:52:44 +09:00
|
|
|
base.OnEntering(e);
|
2021-11-12 13:51:02 +01:00
|
|
|
|
|
|
|
// finish alpha transforms on entering to avoid gameplay starting in a half-hidden state.
|
|
|
|
// the finish calls are purposefully not propagated to children to avoid messing up their state.
|
|
|
|
FinishTransforms();
|
|
|
|
GameplayClockContainer.FinishTransforms(false, nameof(Alpha));
|
|
|
|
}
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-11-11 15:45:10 +01:00
|
|
|
{
|
|
|
|
musicController.Stop();
|
2021-11-12 13:12:25 +01:00
|
|
|
|
|
|
|
editor.RestoreState(editorState);
|
2022-04-22 00:52:44 +09:00
|
|
|
return base.OnExiting(e);
|
2021-11-11 15:45:10 +01:00
|
|
|
}
|
2021-11-10 23:11:25 +01:00
|
|
|
}
|
|
|
|
}
|