Remove "current" multiplayer room item

This commit is contained in:
smoogipoo
2020-02-13 18:48:28 +09:00
parent 91edadfe9d
commit 75bef15583
13 changed files with 123 additions and 87 deletions

View File

@ -41,9 +41,6 @@ namespace osu.Game.Screens.Multi.Match
[Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<PlaylistItem> CurrentItem { get; private set; }
[Resolved]
private BeatmapManager beatmapManager { get; set; }
@ -53,6 +50,7 @@ namespace osu.Game.Screens.Multi.Match
[Resolved(CanBeNull = true)]
private OsuGame game { get; set; }
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
private MatchLeaderboard leaderboard;
public MatchSubScreen(Room room)
@ -166,7 +164,16 @@ namespace osu.Game.Screens.Multi.Match
{
base.LoadComplete();
CurrentItem.BindValueChanged(currentItemChanged, true);
Playlist.ItemsAdded += _ => updateSelectedItem();
Playlist.ItemsRemoved += _ => updateSelectedItem();
updateSelectedItem();
}
private void updateSelectedItem()
{
selectedItem.Value = Playlist.FirstOrDefault();
currentItemChanged();
}
public override bool OnExiting(IScreen next)
@ -181,16 +188,18 @@ namespace osu.Game.Screens.Multi.Match
/// <summary>
/// Handles propagation of the current playlist item's content to game-wide mechanisms.
/// </summary>
private void currentItemChanged(ValueChangedEvent<PlaylistItem> e)
private void currentItemChanged()
{
var item = selectedItem.Value;
// Retrieve the corresponding local beatmap, since we can't directly use the playlist's beatmap info
var localBeatmap = e.NewValue?.Beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == e.NewValue.Beatmap.Value.OnlineBeatmapID);
var localBeatmap = item?.Beatmap == null ? null : beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == item.Beatmap.Value.OnlineBeatmapID);
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
Mods.Value = e.NewValue?.RequiredMods?.ToArray() ?? Array.Empty<Mod>();
Mods.Value = item?.RequiredMods?.ToArray() ?? Array.Empty<Mod>();
if (e.NewValue?.Ruleset != null)
Ruleset.Value = e.NewValue.Ruleset.Value;
if (item?.Ruleset != null)
Ruleset.Value = item.Ruleset.Value;
previewTrackManager.StopAnyPlaying(this);
}
@ -203,11 +212,11 @@ namespace osu.Game.Screens.Multi.Match
if (Beatmap.Value != beatmapManager.DefaultBeatmap)
return;
if (CurrentItem.Value == null)
if (selectedItem.Value == null)
return;
// Try to retrieve the corresponding local beatmap
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == CurrentItem.Value.Beatmap.Value.OnlineBeatmapID);
var localBeatmap = beatmapManager.QueryBeatmap(b => b.OnlineBeatmapID == selectedItem.Value.Beatmap.Value.OnlineBeatmapID);
if (localBeatmap != null)
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
@ -224,7 +233,7 @@ namespace osu.Game.Screens.Multi.Match
{
default:
case GameTypeTimeshift _:
multiplayer?.Start(() => new TimeshiftPlayer(CurrentItem.Value)
multiplayer?.Start(() => new TimeshiftPlayer(selectedItem.Value)
{
Exited = () => leaderboard.RefreshScores()
});