1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 21:03:08 +08:00
osu-lazer/osu.Game/Screens/Select/MatchSongSelect.cs

86 lines
2.4 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;
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;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets.Mods;
2018-12-10 18:20:41 +08:00
using osu.Game.Screens.Multi;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select
{
2018-12-26 19:05:57 +08:00
public class MatchSongSelect : SongSelect, IMultiplayerSubScreen
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();
[Resolved(typeof(Room))]
protected Bindable<PlaylistItem> CurrentItem { get; private set; }
[Resolved]
2019-02-28 16:02:45 +08:00
private Bindable<IEnumerable<Mod>> selectedMods { get; 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 bool OnStart()
2018-04-13 17:19:50 +08:00
{
var item = new PlaylistItem
{
Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = Ruleset.Value,
RulesetID = Ruleset.Value.ID ?? 0
};
item.RequiredMods.AddRange(SelectedMods.Value);
Selected?.Invoke(item);
2019-01-23 19:52:00 +08:00
if (this.IsCurrentScreen())
this.Exit();
2018-04-13 17:19:50 +08:00
return true;
}
2019-02-01 14:42:15 +08:00
public override bool OnExiting(IScreen next)
{
if (base.OnExiting(next))
return true;
if (CurrentItem.Value != null)
{
Ruleset.Value = CurrentItem.Value.Ruleset;
Beatmap.Value = beatmaps.GetWorkingBeatmap(CurrentItem.Value.Beatmap);
Beatmap.Value.Mods.Value = selectedMods.Value = CurrentItem.Value.RequiredMods ?? Enumerable.Empty<Mod>();
}
2019-02-01 14:42:15 +08:00
Beatmap.Disabled = true;
Ruleset.Disabled = true;
return false;
2019-02-01 14:42:15 +08:00
}
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
Beatmap.Disabled = false;
Ruleset.Disabled = false;
}
2018-04-13 17:19:50 +08:00
}
}