1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 13:47:24 +08:00
osu-lazer/osu.Game/Screens/Select/PlaySongSelect.cs

123 lines
4.0 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
2020-03-02 18:40:32 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Framework.Screens;
using osu.Game.Graphics;
2020-06-02 19:32:52 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Play;
2020-03-17 16:43:16 +08:00
using osu.Game.Screens.Ranking;
using osu.Game.Users;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select
{
public class PlaySongSelect : SongSelect
{
private bool removeAutoModOnResume;
2021-05-25 17:37:04 +08:00
private OsuScreen playerLoader;
2018-04-13 17:19:50 +08:00
2020-06-02 22:01:01 +08:00
[Resolved(CanBeNull = true)]
2020-06-02 19:32:52 +08:00
private NotificationOverlay notifications { get; set; }
public override bool AllowExternalScreenChange => true;
protected override UserActivity InitialActivity => new UserActivity.ChoosingBeatmap();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2018-04-13 17:19:50 +08:00
{
BeatmapOptions.AddButton(@"Edit", @"beatmap", FontAwesome.Solid.PencilAlt, colours.Yellow, () => Edit());
2020-02-12 18:52:47 +08:00
((PlayBeatmapDetailArea)BeatmapDetails).Leaderboard.ScoreSelected += PresentScore;
2018-04-13 17:19:50 +08:00
}
protected void PresentScore(ScoreInfo score) =>
FinaliseSelection(score.BeatmapInfo, score.Ruleset, () => this.Push(new SoloResultsScreen(score, false)));
2020-02-12 18:52:47 +08:00
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea();
private ModAutoplay getAutoplayMod() => Ruleset.Value.CreateInstance().GetAutoplayMod();
2019-01-23 19:52:00 +08:00
public override void OnResuming(IScreen last)
2018-04-13 17:19:50 +08:00
{
base.OnResuming(last);
2021-05-25 17:37:04 +08:00
playerLoader = null;
2018-04-13 17:19:50 +08:00
if (removeAutoModOnResume)
{
var autoType = getAutoplayMod()?.GetType();
if (autoType != null)
Mods.Value = Mods.Value.Where(m => m.GetType() != autoType).ToArray();
2018-04-13 17:19:50 +08:00
removeAutoModOnResume = false;
}
}
2020-03-02 18:40:32 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
{
switch (e.Key)
{
case Key.Enter:
case Key.KeypadEnter:
2020-03-02 18:40:32 +08:00
// this is a special hard-coded case; we can't rely on OnPressed (of SongSelect) as GlobalActionContainer is
// matching with exact modifier consideration (so Ctrl+Enter would be ignored).
FinaliseSelection();
return true;
}
return base.OnKeyDown(e);
}
protected override bool OnStart()
2018-04-13 17:19:50 +08:00
{
2021-05-25 17:37:04 +08:00
if (playerLoader != null) return false;
2018-04-13 17:19:50 +08:00
// Ctrl+Enter should start map with autoplay enabled.
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
{
2021-05-25 17:37:04 +08:00
var autoInstance = getAutoplayMod();
2021-05-25 17:37:04 +08:00
if (autoInstance == null)
2020-06-02 19:32:52 +08:00
{
2020-06-02 22:01:01 +08:00
notifications?.Post(new SimpleNotification
{
2020-06-02 19:32:52 +08:00
Text = "The current ruleset doesn't have an autoplay mod avalaible!"
});
return false;
}
var mods = Mods.Value;
2021-05-25 17:37:04 +08:00
if (mods.All(m => m.GetType() != autoInstance.GetType()))
2020-06-02 19:32:52 +08:00
{
2021-05-25 17:37:04 +08:00
Mods.Value = mods.Append(autoInstance).ToArray();
2020-06-02 19:32:52 +08:00
removeAutoModOnResume = true;
2018-04-13 17:19:50 +08:00
}
}
SampleConfirm?.Play();
2018-04-13 17:19:50 +08:00
2021-05-25 17:37:04 +08:00
this.Push(playerLoader = new PlayerLoader(createPlayer));
2018-04-13 17:19:50 +08:00
return true;
2021-05-25 17:37:04 +08:00
Player createPlayer()
{
var replayGeneratingMod = Mods.Value.OfType<ICreateReplay>().FirstOrDefault();
if (replayGeneratingMod != null)
return new ReplayPlayer((beatmap, mods) => replayGeneratingMod.CreateReplayScore(beatmap, mods));
2021-05-25 17:37:04 +08:00
return new SoloPlayer();
}
2018-04-13 17:19:50 +08:00
}
}
}