2019-01-24 16:43:03 +08:00
|
|
|
|
// 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
|
|
|
|
|
2022-10-13 01:04:45 +08:00
|
|
|
|
using System;
|
2022-03-30 06:06:35 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-10-13 01:04:45 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
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;
|
2022-10-13 01:04:45 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2022-10-13 01:04:45 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-06-02 19:32:52 +08:00
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Notifications;
|
2022-10-13 01:04:45 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2021-01-05 15:17:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-05-04 13:04:30 +08:00
|
|
|
|
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;
|
2019-04-13 04:54:35 +08:00
|
|
|
|
using osu.Game.Users;
|
2022-03-30 06:06:35 +08:00
|
|
|
|
using osu.Game.Utils;
|
2018-12-12 12:21:44 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class PlaySongSelect : SongSelect
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2022-09-13 18:55:57 +08:00
|
|
|
|
private OsuScreen? playerLoader;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-06-02 22:01:01 +08:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2022-09-13 18:55:57 +08:00
|
|
|
|
private INotificationOverlay? notifications { get; set; }
|
2020-06-02 19:32:52 +08:00
|
|
|
|
|
2019-02-14 12:28:21 +08:00
|
|
|
|
public override bool AllowExternalScreenChange => true;
|
|
|
|
|
|
2022-10-13 01:04:45 +08:00
|
|
|
|
public override Func<BeatmapInfo, MenuItem>[] CustomMenuItems =>
|
|
|
|
|
new Func<BeatmapInfo, MenuItem>[]
|
|
|
|
|
{
|
|
|
|
|
b => new OsuMenuItem("Play", MenuItemType.Highlighted, () => FinaliseSelection(b)),
|
|
|
|
|
b => new OsuMenuItem(CommonStrings.ButtonsEdit, MenuItemType.Standard, () => Edit(b))
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-12 15:33:15 +08:00
|
|
|
|
protected override UserActivity InitialActivity => new UserActivity.ChoosingBeatmap();
|
2019-04-13 04:54:35 +08:00
|
|
|
|
|
2022-09-13 18:55:57 +08:00
|
|
|
|
private PlayBeatmapDetailArea playBeatmapDetailArea = null!;
|
|
|
|
|
|
2018-12-12 12:21:44 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-11-02 05:50:38 +08:00
|
|
|
|
BeatmapOptions.AddButton(@"Edit", @"beatmap", FontAwesome.Solid.PencilAlt, colours.Yellow, () => Edit());
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 13:04:30 +08:00
|
|
|
|
protected void PresentScore(ScoreInfo score) =>
|
2021-10-04 16:35:53 +08:00
|
|
|
|
FinaliseSelection(score.BeatmapInfo, score.Ruleset, () => this.Push(new SoloResultsScreen(score, false)));
|
2020-05-04 13:04:30 +08:00
|
|
|
|
|
2022-09-13 16:49:53 +08:00
|
|
|
|
protected override BeatmapDetailArea CreateBeatmapDetailArea()
|
|
|
|
|
{
|
2022-09-13 18:55:57 +08:00
|
|
|
|
playBeatmapDetailArea = new PlayBeatmapDetailArea
|
2022-09-13 16:49:53 +08:00
|
|
|
|
{
|
|
|
|
|
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:
|
2020-03-24 02:25:40 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 18:55:57 +08:00
|
|
|
|
private IReadOnlyList<Mod>? modsAtGameplayStart;
|
2022-03-30 06:06:35 +08:00
|
|
|
|
|
2022-09-13 18:55:57 +08:00
|
|
|
|
private ModAutoplay? getAutoplayMod() => Ruleset.Value.CreateInstance().GetAutoplayMod();
|
2022-03-30 06:06:35 +08:00
|
|
|
|
|
2018-05-30 14:44:35 +08:00
|
|
|
|
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
|
|
|
|
|
2022-03-30 06:06:35 +08:00
|
|
|
|
modsAtGameplayStart = Mods.Value;
|
|
|
|
|
|
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();
|
2020-06-01 23:41:04 +08:00
|
|
|
|
|
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-01 23:41:04 +08:00
|
|
|
|
{
|
2023-01-16 07:17:26 +08:00
|
|
|
|
Text = "The current ruleset doesn't have an autoplay mod available!"
|
2020-06-02 19:32:52 +08:00
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 06:06:35 +08:00
|
|
|
|
var mods = Mods.Value.Append(autoInstance).ToArray();
|
2021-01-05 15:17:42 +08:00
|
|
|
|
|
2022-03-30 06:06:35 +08:00
|
|
|
|
if (!ModUtils.CheckCompatibleSet(mods, out var invalid))
|
|
|
|
|
mods = mods.Except(invalid).Append(autoInstance).ToArray();
|
|
|
|
|
|
|
|
|
|
Mods.Value = mods;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-12 12:21:44 +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()
|
|
|
|
|
{
|
2022-09-16 17:15:17 +08:00
|
|
|
|
Player player;
|
|
|
|
|
|
2022-03-29 15:45:21 +08:00
|
|
|
|
var replayGeneratingMod = Mods.Value.OfType<ICreateReplayData>().FirstOrDefault();
|
|
|
|
|
|
2021-06-01 13:22:16 +08:00
|
|
|
|
if (replayGeneratingMod != null)
|
2022-09-19 23:06:02 +08:00
|
|
|
|
{
|
|
|
|
|
player = new ReplayPlayer((beatmap, mods) => replayGeneratingMod.CreateScoreFromReplayData(beatmap, mods))
|
|
|
|
|
{
|
|
|
|
|
LeaderboardScores = { BindTarget = playBeatmapDetailArea.Leaderboard.Scores }
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-09-16 17:15:17 +08:00
|
|
|
|
else
|
2022-09-19 23:06:02 +08:00
|
|
|
|
{
|
|
|
|
|
player = new SoloPlayer
|
|
|
|
|
{
|
|
|
|
|
LeaderboardScores = { BindTarget = playBeatmapDetailArea.Leaderboard.Scores }
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-09-16 17:15:17 +08:00
|
|
|
|
|
|
|
|
|
return player;
|
2021-05-25 17:37:04 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2022-03-30 06:06:35 +08:00
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
2022-03-30 06:06:35 +08:00
|
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
|
base.OnResuming(e);
|
2022-03-30 06:06:35 +08:00
|
|
|
|
|
|
|
|
|
if (playerLoader != null)
|
|
|
|
|
{
|
|
|
|
|
Mods.Value = modsAtGameplayStart;
|
|
|
|
|
playerLoader = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|