1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 20:07:26 +08:00
osu-lazer/osu.Game/Screens/Select/MatchSongSelect.cs

92 lines
2.6 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.Linq;
2018-12-25 16:17:51 +08:00
using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2019-01-31 17:16:28 +08:00
using osu.Framework.Graphics;
2019-01-23 19:52:00 +08:00
using osu.Framework.Screens;
using osu.Game.Beatmaps;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms;
2021-01-20 19:59:28 +08:00
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.OnlinePlay;
using osu.Game.Screens.OnlinePlay.Components;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select
{
public class MatchSongSelect : SongSelect, IOnlinePlaySubScreen
2018-04-13 17:19:50 +08:00
{
public Action<PlaylistItem> Selected;
public string ShortTitle => "song selection";
2018-12-25 16:17:51 +08:00
public override string Title => ShortTitle.Humanize();
public override bool AllowEditing => false;
2020-02-13 17:48:28 +08:00
[Resolved(typeof(Room), nameof(Room.Playlist))]
protected BindableList<PlaylistItem> Playlist { get; private set; }
[Resolved]
private BeatmapManager beatmaps { get; set; }
2019-01-31 17:16:28 +08:00
public MatchSongSelect()
{
Padding = new MarginPadding { Horizontal = HORIZONTAL_OVERFLOW_PADDING };
}
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new MatchBeatmapDetailArea
{
CreateNewItem = createNewItem
};
2020-02-12 18:52:47 +08:00
protected override bool OnStart()
2018-04-13 17:19:50 +08:00
{
switch (Playlist.Count)
{
case 0:
createNewItem();
break;
case 1:
populateItemFromCurrent(Playlist.Single());
break;
}
this.Exit();
2018-04-13 17:19:50 +08:00
return true;
}
2019-02-01 14:42:15 +08:00
private void createNewItem()
2019-02-01 14:42:15 +08:00
{
PlaylistItem item = new PlaylistItem
{
ID = Playlist.Count == 0 ? 0 : Playlist.Max(p => p.ID) + 1
};
populateItemFromCurrent(item);
Playlist.Add(item);
2019-02-01 14:42:15 +08:00
}
private void populateItemFromCurrent(PlaylistItem item)
{
item.Beatmap.Value = Beatmap.Value.BeatmapInfo;
item.Ruleset.Value = Ruleset.Value;
item.RequiredMods.Clear();
item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy()));
}
2021-01-20 19:59:28 +08:00
protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay
{
IsValidMod = isValidMod
};
2021-01-20 19:59:28 +08:00
private bool isValidMod(Mod mod) => !(mod is ModAutoplay) && (mod as MultiMod)?.Mods.Any(mm => mm is ModAutoplay) != true;
2018-04-13 17:19:50 +08:00
}
}