1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 17:27:39 +08:00
osu-lazer/osu.Game/Screens/Select/PlaySongSelect.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
5.1 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;
using System.Collections.Generic;
using System.Linq;
2017-03-14 18:38:06 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
2020-03-02 18:40:32 +08:00
using osu.Framework.Input.Events;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
2017-03-14 18:38:06 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
2023-01-14 04:11:25 +08:00
using osu.Game.Localisation;
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;
using osu.Game.Screens.Play;
2020-03-17 16:43:16 +08:00
using osu.Game.Screens.Ranking;
using osu.Game.Users;
using osu.Game.Utils;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select
{
public partial class PlaySongSelect : SongSelect
{
private OsuScreen? playerLoader;
2018-04-13 17:19:50 +08:00
[Resolved]
private INotificationOverlay? notifications { get; set; }
2020-06-02 19:32:52 +08:00
public override bool AllowExternalScreenChange => true;
public override Func<BeatmapInfo, MenuItem>[] CustomMenuItems =>
new Func<BeatmapInfo, MenuItem>[]
{
b => new OsuMenuItem("Play", MenuItemType.Highlighted, () => FinaliseSelection(b)),
2023-01-16 08:09:04 +08:00
b => new OsuMenuItem(Resources.Localisation.Web.CommonStrings.ButtonsEdit, MenuItemType.Standard, () => Edit(b))
};
protected override UserActivity InitialActivity => new UserActivity.ChoosingBeatmap();
private PlayBeatmapDetailArea playBeatmapDetailArea = null!;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2017-03-14 21:51:26 +08:00
{
BeatmapOptions.AddButton(@"Edit", @"beatmap", FontAwesome.Solid.PencilAlt, colours.Yellow, () => Edit());
}
2018-04-13 17:19:50 +08:00
protected void PresentScore(ScoreInfo score) =>
FinaliseSelection(score.BeatmapInfo, score.Ruleset, () => this.Push(new SoloResultsScreen(score, false)));
protected override BeatmapDetailArea CreateBeatmapDetailArea()
{
playBeatmapDetailArea = new PlayBeatmapDetailArea
{
Leaderboard =
{
ScoreSelected = PresentScore
}
};
return playBeatmapDetailArea;
}
2020-02-12 18:52:47 +08:00
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);
}
private IReadOnlyList<Mod>? modsAtGameplayStart;
private ModAutoplay? getAutoplayMod() => Ruleset.Value.CreateInstance().GetAutoplayMod();
protected override bool OnStart()
{
2021-05-25 17:37:04 +08:00
if (playerLoader != null) return false;
2018-04-13 17:19:50 +08:00
modsAtGameplayStart = Mods.Value;
2017-12-15 11:08:11 +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
{
2023-01-14 04:11:25 +08:00
Text = NotificationsStrings.NoAutoplayMod
2020-06-02 19:32:52 +08:00
});
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;
2017-12-15 11:08:11 +08:00
}
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));
return true;
2021-05-25 17:37:04 +08:00
Player createPlayer()
{
Player player;
var replayGeneratingMod = Mods.Value.OfType<ICreateReplayData>().FirstOrDefault();
if (replayGeneratingMod != null)
{
player = new ReplayPlayer((beatmap, mods) => replayGeneratingMod.CreateScoreFromReplayData(beatmap, mods))
{
LeaderboardScores = { BindTarget = playBeatmapDetailArea.Leaderboard.Scores }
};
}
else
{
player = new SoloPlayer
{
LeaderboardScores = { BindTarget = playBeatmapDetailArea.Leaderboard.Scores }
};
}
return player;
2021-05-25 17:37:04 +08:00
}
}
public override void OnResuming(ScreenTransitionEvent e)
{
base.OnResuming(e);
if (playerLoader != null)
{
Mods.Value = modsAtGameplayStart;
playerLoader = null;
}
}
}
}