1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:47:27 +08:00

Fix lounge screen content not matching current room playlist item

This commit is contained in:
Bartłomiej Dach 2021-12-20 13:19:00 +01:00
parent a59583ee09
commit a5a9922f81
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
5 changed files with 11 additions and 13 deletions

View File

@ -19,7 +19,7 @@ namespace osu.Game.Tests.OnlinePlay
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
};
var nextItem = items.GetNextItem();
var nextItem = items.GetCurrentItem();
Assert.That(nextItem, Is.EqualTo(items[0]));
}
@ -34,7 +34,7 @@ namespace osu.Game.Tests.OnlinePlay
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
};
var nextItem = items.GetNextItem();
var nextItem = items.GetCurrentItem();
Assert.That(nextItem, Is.EqualTo(items[1]));
}
@ -49,7 +49,7 @@ namespace osu.Game.Tests.OnlinePlay
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3 },
};
var nextItem = items.GetNextItem();
var nextItem = items.GetCurrentItem();
Assert.That(nextItem, Is.EqualTo(items[2]));
}
@ -64,7 +64,7 @@ namespace osu.Game.Tests.OnlinePlay
new PlaylistItem { ID = 3, BeatmapID = 1003, PlaylistOrder = 3, Expired = true },
};
var nextItem = items.GetNextItem();
var nextItem = items.GetCurrentItem();
Assert.That(nextItem, Is.Null);
}

View File

@ -14,10 +14,10 @@ namespace osu.Game.Online.Rooms
public static class PlaylistExtensions
{
/// <summary>
/// Returns the next <see cref="PlaylistItem"/> to be played from the supplied <paramref name="playlist"/>,
/// Returns the first non-expired <see cref="PlaylistItem"/> in playlist order from the supplied <paramref name="playlist"/>,
/// or <see langword="null"/> if all items are expired.
/// </summary>
public static PlaylistItem? GetNextItem(this IEnumerable<PlaylistItem> playlist) =>
public static PlaylistItem? GetCurrentItem(this IEnumerable<PlaylistItem> playlist) =>
playlist.OrderBy(item => item.PlaylistOrder).FirstOrDefault(item => !item.Expired);
public static string GetTotalDuration(this BindableList<PlaylistItem> playlist) =>

View File

@ -1,10 +1,10 @@
// 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.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay.Components
{
@ -30,7 +30,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
private void updateBeatmap()
{
sprite.Beatmap.Value = Playlist.FirstOrDefault()?.Beatmap.Value;
sprite.Beatmap.Value = Playlist.GetCurrentItem()?.Beatmap.Value;
}
protected virtual UpdateableBeatmapBackgroundSprite CreateBackgroundSprite() => new UpdateableBeatmapBackgroundSprite(BeatmapSetCoverType) { RelativeSizeAxes = Axes.Both };

View File

@ -3,7 +3,6 @@
#nullable enable
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Screens;
using osu.Game.Online.Rooms;
@ -20,7 +19,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
public LoungeBackgroundScreen()
{
SelectedRoom.BindValueChanged(onSelectedRoomChanged);
playlist.BindCollectionChanged((_, __) => PlaylistItem = playlist.FirstOrDefault());
playlist.BindCollectionChanged((_, __) => PlaylistItem = playlist.GetCurrentItem());
}
private void onSelectedRoomChanged(ValueChangedEvent<Room> room)

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
@ -73,7 +72,7 @@ namespace osu.Game.Screens.OnlinePlay
private IBindable<PlaylistItem> subScreenSelectedItem { get; set; }
/// <summary>
/// The currently selected item in the <see cref="RoomSubScreen"/>, or the last item from <see cref="Playlist"/>
/// The currently selected item in the <see cref="RoomSubScreen"/>, or the current item from <see cref="Playlist"/>
/// if this <see cref="OnlinePlayComposite"/> is not within a <see cref="RoomSubScreen"/>.
/// </summary>
protected readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
@ -88,7 +87,7 @@ namespace osu.Game.Screens.OnlinePlay
protected virtual void UpdateSelectedItem()
=> SelectedItem.Value = RoomID.Value == null || subScreenSelectedItem == null
? Playlist.LastOrDefault()
? Playlist.GetCurrentItem()
: subScreenSelectedItem.Value;
}
}