1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 02:52:54 +08:00

Make Room.PlaylistItemStats non-bindable

This commit is contained in:
Dan Balasescu 2024-11-13 22:29:45 +09:00
parent 80b3e330a6
commit 487a010b12
No known key found for this signature in database
6 changed files with 43 additions and 15 deletions

View File

@ -155,6 +155,15 @@ namespace osu.Game.Online.Rooms
set => SetField(ref maxAttempts, value); set => SetField(ref maxAttempts, value);
} }
/// <summary>
/// Describes the items in the playlist.
/// </summary>
public RoomPlaylistItemStats? PlaylistItemStats
{
get => playlistItemStats;
set => SetField(ref playlistItemStats, value);
}
/// <summary> /// <summary>
/// The playlist queueing mode. Only valid for multiplayer rooms. /// The playlist queueing mode. Only valid for multiplayer rooms.
/// </summary> /// </summary>
@ -258,6 +267,9 @@ namespace osu.Game.Online.Rooms
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
private int? maxAttempts; private int? maxAttempts;
[JsonProperty("playlist_item_stats")]
private RoomPlaylistItemStats? playlistItemStats;
[JsonConverter(typeof(SnakeCaseStringEnumConverter))] [JsonConverter(typeof(SnakeCaseStringEnumConverter))]
[JsonProperty("type")] [JsonProperty("type")]
private MatchType type; private MatchType type;
@ -288,10 +300,6 @@ namespace osu.Game.Online.Rooms
[JsonProperty("playlist")] [JsonProperty("playlist")]
public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>(); public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>();
[JsonProperty("playlist_item_stats")]
[Cached]
public readonly Bindable<RoomPlaylistItemStats> PlaylistItemStats = new Bindable<RoomPlaylistItemStats>();
[JsonProperty("difficulty_range")] [JsonProperty("difficulty_range")]
[Cached] [Cached]
public readonly Bindable<RoomDifficultyRange> DifficultyRange = new Bindable<RoomDifficultyRange>(); public readonly Bindable<RoomDifficultyRange> DifficultyRange = new Bindable<RoomDifficultyRange>();
@ -333,7 +341,7 @@ namespace osu.Game.Online.Rooms
QueueMode = other.QueueMode; QueueMode = other.QueueMode;
AutoStartDuration = other.AutoStartDuration; AutoStartDuration = other.AutoStartDuration;
DifficultyRange.Value = other.DifficultyRange.Value; DifficultyRange.Value = other.DifficultyRange.Value;
PlaylistItemStats.Value = other.PlaylistItemStats.Value; PlaylistItemStats = other.PlaylistItemStats;
CurrentPlaylistItem = other.CurrentPlaylistItem; CurrentPlaylistItem = other.CurrentPlaylistItem;
AutoSkip = other.AutoSkip; AutoSkip = other.AutoSkip;

View File

@ -355,7 +355,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
pills.AddRange(new Drawable[] pills.AddRange(new Drawable[]
{ {
new PlaylistCountPill new PlaylistCountPill(Room)
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,

View File

@ -1,10 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.ComponentModel;
using System.Linq; using System.Linq;
using Humanizer; using Humanizer;
using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Extensions.LocalisationExtensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{ {
@ -13,26 +15,47 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
/// </summary> /// </summary>
public partial class PlaylistCountPill : OnlinePlayPill public partial class PlaylistCountPill : OnlinePlayPill
{ {
private readonly Room room;
public PlaylistCountPill(Room room)
{
this.room = room;
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
PlaylistItemStats.BindValueChanged(_ => updateCount()); Playlist.BindCollectionChanged((_, _) => updateCount());
Playlist.BindCollectionChanged((_, _) => updateCount(), true);
room.PropertyChanged += onRoomPropertyChanged;
updateCount();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.PlaylistItemStats))
updateCount();
} }
private void updateCount() private void updateCount()
{ {
int activeItems = Playlist.Count > 0 || PlaylistItemStats.Value == null int activeItems = Playlist.Count > 0 || room.PlaylistItemStats == null
// For now, use the playlist as the source of truth if it has any items. // For now, use the playlist as the source of truth if it has any items.
// This allows the count to display correctly on the room screen (after joining a room). // This allows the count to display correctly on the room screen (after joining a room).
? Playlist.Count(i => !i.Expired) ? Playlist.Count(i => !i.Expired)
: PlaylistItemStats.Value.CountActive; : room.PlaylistItemStats.CountActive;
TextFlow.Clear(); TextFlow.Clear();
TextFlow.AddText(activeItems.ToLocalisableString(), s => s.Font = s.Font.With(weight: FontWeight.Bold)); TextFlow.AddText(activeItems.ToLocalisableString(), s => s.Font = s.Font.With(weight: FontWeight.Bold));
TextFlow.AddText(" "); TextFlow.AddText(" ");
TextFlow.AddText("Beatmap".ToQuantity(activeItems, ShowQuantityAs.None)); TextFlow.AddText("Beatmap".ToQuantity(activeItems, ShowQuantityAs.None));
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
} }
} }

View File

@ -79,7 +79,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{ {
bool matchingFilter = true; bool matchingFilter = true;
matchingFilter &= criteria.Ruleset == null || r.Room.PlaylistItemStats.Value?.RulesetIDs.Any(id => id == criteria.Ruleset.OnlineID) != false; matchingFilter &= criteria.Ruleset == null || r.Room.PlaylistItemStats?.RulesetIDs.Any(id => id == criteria.Ruleset.OnlineID) != false;
if (!string.IsNullOrEmpty(criteria.SearchString)) if (!string.IsNullOrEmpty(criteria.SearchString))
{ {

View File

@ -14,9 +14,6 @@ namespace osu.Game.Screens.OnlinePlay
/// </summary> /// </summary>
public partial class OnlinePlayComposite : CompositeDrawable public partial class OnlinePlayComposite : CompositeDrawable
{ {
[Resolved(typeof(Room))]
protected Bindable<Room.RoomPlaylistItemStats> PlaylistItemStats { get; private set; } = null!;
[Resolved(typeof(Room))] [Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; } = null!; protected BindableList<PlaylistItem> Playlist { get; private set; } = null!;

View File

@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
if (ruleset != null) if (ruleset != null)
{ {
room.PlaylistItemStats.Value = new Room.RoomPlaylistItemStats room.PlaylistItemStats = new Room.RoomPlaylistItemStats
{ {
RulesetIDs = new[] { ruleset.OnlineID }, RulesetIDs = new[] { ruleset.OnlineID },
}; };