osu/osu.Game/Screens/Select/PlaySongSelect.cs

96 lines
3.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 09:19:50 +00:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
2020-03-02 10:40:32 +00:00
using osu.Framework.Input.Events;
2018-04-13 09:19:50 +00:00
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Screens.Play;
2020-03-17 08:43:16 +00:00
using osu.Game.Screens.Ranking;
using osu.Game.Users;
using osuTK.Input;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Screens.Select
{
public class PlaySongSelect : SongSelect
{
private bool removeAutoModOnResume;
private OsuScreen player;
2018-04-13 09:19:50 +00:00
public override bool AllowExternalScreenChange => true;
protected override UserActivity InitialActivity => new UserActivity.ChoosingBeatmap();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2018-04-13 09:19:50 +00:00
{
2019-04-02 10:55:24 +00:00
BeatmapOptions.AddButton(@"Edit", @"beatmap", FontAwesome.Solid.PencilAlt, colours.Yellow, () =>
2018-04-13 09:19:50 +00:00
{
ValidForResume = false;
Edit();
}, Key.Number4);
2020-02-12 10:52:47 +00:00
2020-03-17 08:43:16 +00:00
((PlayBeatmapDetailArea)BeatmapDetails).Leaderboard.ScoreSelected += score => this.Push(new ResultsScreen(score));
2018-04-13 09:19:50 +00:00
}
2020-02-12 10:52:47 +00:00
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea();
2019-01-23 11:52:00 +00:00
public override void OnResuming(IScreen last)
2018-04-13 09:19:50 +00:00
{
base.OnResuming(last);
2018-04-13 09:19:50 +00:00
player = null;
if (removeAutoModOnResume)
{
var autoType = Ruleset.Value.CreateInstance().GetAutoplayMod().GetType();
2018-12-06 10:29:18 +00:00
ModSelect.DeselectTypes(new[] { autoType }, true);
2018-04-13 09:19:50 +00:00
removeAutoModOnResume = false;
}
}
2020-03-02 10:40:32 +00:00
protected override bool OnKeyDown(KeyDownEvent e)
{
switch (e.Key)
{
case Key.Enter:
case Key.KeypadEnter:
2020-03-02 10:40:32 +00: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 09:19:50 +00:00
{
if (player != null) return false;
// Ctrl+Enter should start map with autoplay enabled.
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
{
var auto = Ruleset.Value.CreateInstance().GetAutoplayMod();
var autoType = auto.GetType();
2019-04-10 03:03:57 +00:00
var mods = Mods.Value;
2019-04-01 03:16:05 +00:00
2018-04-13 09:19:50 +00:00
if (mods.All(m => m.GetType() != autoType))
{
Mods.Value = mods.Append(auto).ToArray();
2018-04-13 09:19:50 +00:00
removeAutoModOnResume = true;
}
}
SampleConfirm?.Play();
2018-04-13 09:19:50 +00:00
this.Push(player = new PlayerLoader(() => new Player()));
2018-04-13 09:19:50 +00:00
return true;
}
}
}