2021-11-11 06:11:25 +08: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 11:32:35 +08:00
|
|
|
using System.Linq;
|
2021-11-11 22:45:10 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-11-11 22:25:58 +08:00
|
|
|
using osu.Framework.Screens;
|
2021-11-12 19:50:38 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-11-11 22:45:10 +08:00
|
|
|
using osu.Game.Overlays;
|
2021-11-11 06:11:25 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2023-02-13 05:04:12 +08:00
|
|
|
using osu.Game.Users;
|
2021-11-11 06:11:25 +08:00
|
|
|
|
2021-11-12 19:07:38 +08:00
|
|
|
namespace osu.Game.Screens.Edit.GameplayTest
|
2021-11-11 06:11:25 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class EditorPlayer : Player
|
2021-11-11 06:11:25 +08:00
|
|
|
{
|
2021-11-12 20:12:25 +08:00
|
|
|
private readonly Editor editor;
|
2021-11-12 19:50:38 +08:00
|
|
|
private readonly EditorState editorState;
|
|
|
|
|
2024-03-01 20:28:52 +08:00
|
|
|
protected override UserActivity InitialActivity => new UserActivity.TestingBeatmap(Beatmap.Value.BeatmapInfo);
|
2023-02-13 05:04:12 +08:00
|
|
|
|
2021-11-12 19:50:38 +08:00
|
|
|
[Resolved]
|
2022-11-16 16:54:49 +08:00
|
|
|
private MusicController musicController { get; set; } = null!;
|
|
|
|
|
2021-11-12 20:12:25 +08:00
|
|
|
public EditorPlayer(Editor editor)
|
2021-11-11 06:11:25 +08:00
|
|
|
: base(new PlayerConfiguration { ShowResults = false })
|
|
|
|
{
|
2021-11-12 20:12:25 +08:00
|
|
|
this.editor = editor;
|
|
|
|
editorState = editor.GetState();
|
2021-11-11 06:11:25 +08:00
|
|
|
}
|
|
|
|
|
2021-11-12 19:50:38 +08:00
|
|
|
protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
|
2022-08-22 13:11:06 +08:00
|
|
|
{
|
|
|
|
var masterGameplayClockContainer = new MasterGameplayClockContainer(beatmap, gameplayStart);
|
2022-11-17 11:32:35 +08: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 13:11:06 +08:00
|
|
|
return masterGameplayClockContainer;
|
|
|
|
}
|
2021-11-11 22:45:10 +08:00
|
|
|
|
2021-11-11 22:25:58 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
ScoreProcessor.HasCompleted.BindValueChanged(completed =>
|
|
|
|
{
|
|
|
|
if (completed.NewValue)
|
2022-07-13 23:58:32 +08:00
|
|
|
{
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
if (this.IsCurrentScreen())
|
|
|
|
this.Exit();
|
|
|
|
}, RESULTS_DISPLAY_DELAY);
|
|
|
|
}
|
2021-11-11 22:25:58 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-11 06:11:25 +08:00
|
|
|
protected override void PrepareReplay()
|
|
|
|
{
|
|
|
|
// don't record replays.
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool CheckModsAllowFailure() => false; // never fail.
|
2021-11-11 22:45:10 +08:00
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2021-11-12 20:51:02 +08:00
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
base.OnEntering(e);
|
2021-11-12 20:51:02 +08: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-21 23:52:44 +08:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-11-11 22:45:10 +08:00
|
|
|
{
|
|
|
|
musicController.Stop();
|
2021-11-12 20:12:25 +08:00
|
|
|
|
|
|
|
editor.RestoreState(editorState);
|
2022-04-21 23:52:44 +08:00
|
|
|
return base.OnExiting(e);
|
2021-11-11 22:45:10 +08:00
|
|
|
}
|
2021-11-11 06:11:25 +08:00
|
|
|
}
|
|
|
|
}
|