1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 20:47:25 +08:00

Merge pull request #25568 from peppy/skin-editor-load-gameplay

Load gameplay immediately on entering the skin editor while at the main menu
This commit is contained in:
Bartłomiej Dach 2023-11-27 12:43:30 +09:00 committed by GitHub
commit 1bd5d334a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 29 deletions

View File

@ -1,7 +1,10 @@
// 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.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -9,12 +12,21 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Components;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;
using osu.Game.Screens.Select;
using osu.Game.Utils;
using osuTK;
namespace osu.Game.Overlays.SkinEditor
@ -31,12 +43,27 @@ namespace osu.Game.Overlays.SkinEditor
private SkinEditor? skinEditor;
[Resolved]
private IPerformFromScreenRunner? performer { get; set; }
[Cached]
public readonly EditorClipboard Clipboard = new EditorClipboard();
[Resolved]
private OsuGame game { get; set; } = null!;
[Resolved]
private MusicController music { get; set; } = null!;
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
[Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
private OsuScreen? lastTargetScreen;
private Vector2 lastDrawSize;
@ -72,6 +99,9 @@ namespace osu.Game.Overlays.SkinEditor
{
globallyDisableBeatmapSkinSetting();
if (lastTargetScreen is MainMenu)
PresentGameplay();
if (skinEditor != null)
{
skinEditor.Show();
@ -105,6 +135,36 @@ namespace osu.Game.Overlays.SkinEditor
globallyReenableBeatmapSkinSetting();
}
public void PresentGameplay()
{
performer?.PerformFromScreen(screen =>
{
// If we're playing the intro, switch away to another beatmap.
if (beatmap.Value.BeatmapSetInfo.Protected)
{
music.NextTrack();
Schedule(PresentGameplay);
return;
}
if (screen is Player)
return;
var replayGeneratingMod = ruleset.Value.CreateInstance().GetAutoplayMod();
IReadOnlyList<Mod> usableMods = mods.Value;
if (replayGeneratingMod != null)
usableMods = usableMods.Append(replayGeneratingMod).ToArray();
if (!ModUtils.CheckCompatibleSet(usableMods, out var invalid))
mods.Value = mods.Value.Except(invalid).ToArray();
if (replayGeneratingMod != null)
screen.Push(new EndlessPlayer((beatmap, mods) => replayGeneratingMod.CreateScoreFromReplayData(beatmap, mods)));
}, new[] { typeof(Player), typeof(PlaySongSelect) });
}
protected override void Update()
{
base.Update();
@ -222,5 +282,25 @@ namespace osu.Game.Overlays.SkinEditor
leasedBeatmapSkins?.Return();
leasedBeatmapSkins = null;
}
private partial class EndlessPlayer : ReplayPlayer
{
public EndlessPlayer(Func<IBeatmap, IReadOnlyList<Mod>, Score> createScore)
: base(createScore, new PlayerConfiguration
{
ShowResults = false,
AutomaticallySkipIntro = true,
})
{
}
protected override void Update()
{
base.Update();
if (GameplayState.HasPassed)
GameplayClockContainer.Seek(0);
}
}
}
}

View File

@ -1,10 +1,7 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -14,12 +11,8 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens;
using osu.Game.Screens.Play;
using osu.Game.Screens.Select;
using osu.Game.Utils;
using osuTK;
namespace osu.Game.Overlays.SkinEditor
@ -36,10 +29,7 @@ namespace osu.Game.Overlays.SkinEditor
private IPerformFromScreenRunner? performer { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
[Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
private SkinEditorOverlay? skinEditorOverlay { get; set; }
public SkinEditorSceneLibrary()
{
@ -96,24 +86,7 @@ namespace osu.Game.Overlays.SkinEditor
Text = SkinEditorStrings.Gameplay,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Action = () => performer?.PerformFromScreen(screen =>
{
if (screen is Player)
return;
var replayGeneratingMod = ruleset.Value.CreateInstance().GetAutoplayMod();
IReadOnlyList<Mod> usableMods = mods.Value;
if (replayGeneratingMod != null)
usableMods = usableMods.Append(replayGeneratingMod).ToArray();
if (!ModUtils.CheckCompatibleSet(usableMods, out var invalid))
mods.Value = mods.Value.Except(invalid).ToArray();
if (replayGeneratingMod != null)
screen.Push(new PlayerLoader(() => new ReplayPlayer((beatmap, mods) => replayGeneratingMod.CreateScoreFromReplayData(beatmap, mods))));
}, new[] { typeof(Player), typeof(PlaySongSelect) })
Action = () => skinEditorOverlay?.PresentGameplay(),
},
}
},