mirror of
https://github.com/ppy/osu.git
synced 2026-06-13 13:14:50 +08:00
114 lines
3.2 KiB
C#
114 lines
3.2 KiB
C#
// 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.Linq;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Screens;
|
|
using osu.Game.Localisation;
|
|
using osu.Game.Overlays;
|
|
using osu.Game.Overlays.Notifications;
|
|
using osu.Game.Rulesets.Mods;
|
|
using osu.Game.Screens.Play;
|
|
using osu.Game.Utils;
|
|
|
|
namespace osu.Game.Screens.SelectV2
|
|
{
|
|
public partial class SoloSongSelect : SongSelect
|
|
{
|
|
private PlayerLoader? playerLoader;
|
|
private IReadOnlyList<Mod>? modsAtGameplayStart;
|
|
|
|
[Resolved]
|
|
private INotificationOverlay? notifications { get; set; }
|
|
|
|
public override bool EditingAllowed => true;
|
|
|
|
protected override bool OnStart()
|
|
{
|
|
if (playerLoader != null) return false;
|
|
|
|
modsAtGameplayStart = Mods.Value;
|
|
|
|
// Ctrl+Enter should start map with autoplay enabled.
|
|
if (GetContainingInputManager()?.CurrentState?.Keyboard.ControlPressed == true)
|
|
{
|
|
var autoInstance = getAutoplayMod();
|
|
|
|
if (autoInstance == null)
|
|
{
|
|
notifications?.Post(new SimpleNotification
|
|
{
|
|
Text = NotificationsStrings.NoAutoplayMod
|
|
});
|
|
return false;
|
|
}
|
|
|
|
var mods = Mods.Value.Append(autoInstance).ToArray();
|
|
|
|
if (!ModUtils.CheckCompatibleSet(mods, out var invalid))
|
|
mods = mods.Except(invalid).Append(autoInstance).ToArray();
|
|
|
|
Mods.Value = mods;
|
|
}
|
|
|
|
this.Push(playerLoader = new PlayerLoader(createPlayer));
|
|
return true;
|
|
|
|
Player createPlayer()
|
|
{
|
|
Player player;
|
|
|
|
var replayGeneratingMod = Mods.Value.OfType<ICreateReplayData>().FirstOrDefault();
|
|
|
|
if (replayGeneratingMod != null)
|
|
{
|
|
player = new ReplayPlayer((beatmap, mods) => replayGeneratingMod.CreateScoreFromReplayData(beatmap, mods));
|
|
}
|
|
else
|
|
{
|
|
player = new SoloPlayer();
|
|
}
|
|
|
|
return player;
|
|
}
|
|
}
|
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
|
{
|
|
base.OnResuming(e);
|
|
revertMods();
|
|
}
|
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
|
{
|
|
if (base.OnExiting(e))
|
|
return true;
|
|
|
|
revertMods();
|
|
return false;
|
|
}
|
|
|
|
private ModAutoplay? getAutoplayMod() => Ruleset.Value.CreateInstance().GetAutoplayMod();
|
|
|
|
private void revertMods()
|
|
{
|
|
if (playerLoader == null) return;
|
|
|
|
Mods.Value = modsAtGameplayStart;
|
|
playerLoader = null;
|
|
}
|
|
|
|
private partial class PlayerLoader : Play.PlayerLoader
|
|
{
|
|
public override bool ShowFooter => true;
|
|
|
|
public PlayerLoader(Func<Player> createPlayer)
|
|
: base(createPlayer)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|