mirror of
https://github.com/ppy/osu.git
synced 2025-01-18 19:32:55 +08:00
Make Room.PlaylistItemStats
non-bindable
This commit is contained in:
parent
80b3e330a6
commit
487a010b12
@ -155,6 +155,15 @@ namespace osu.Game.Online.Rooms
|
||||
set => SetField(ref maxAttempts, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes the items in the playlist.
|
||||
/// </summary>
|
||||
public RoomPlaylistItemStats? PlaylistItemStats
|
||||
{
|
||||
get => playlistItemStats;
|
||||
set => SetField(ref playlistItemStats, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The playlist queueing mode. Only valid for multiplayer rooms.
|
||||
/// </summary>
|
||||
@ -258,6 +267,9 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
private int? maxAttempts;
|
||||
|
||||
[JsonProperty("playlist_item_stats")]
|
||||
private RoomPlaylistItemStats? playlistItemStats;
|
||||
|
||||
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
|
||||
[JsonProperty("type")]
|
||||
private MatchType type;
|
||||
@ -288,10 +300,6 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("playlist")]
|
||||
public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>();
|
||||
|
||||
[JsonProperty("playlist_item_stats")]
|
||||
[Cached]
|
||||
public readonly Bindable<RoomPlaylistItemStats> PlaylistItemStats = new Bindable<RoomPlaylistItemStats>();
|
||||
|
||||
[JsonProperty("difficulty_range")]
|
||||
[Cached]
|
||||
public readonly Bindable<RoomDifficultyRange> DifficultyRange = new Bindable<RoomDifficultyRange>();
|
||||
@ -333,7 +341,7 @@ namespace osu.Game.Online.Rooms
|
||||
QueueMode = other.QueueMode;
|
||||
AutoStartDuration = other.AutoStartDuration;
|
||||
DifficultyRange.Value = other.DifficultyRange.Value;
|
||||
PlaylistItemStats.Value = other.PlaylistItemStats.Value;
|
||||
PlaylistItemStats = other.PlaylistItemStats;
|
||||
CurrentPlaylistItem = other.CurrentPlaylistItem;
|
||||
AutoSkip = other.AutoSkip;
|
||||
|
||||
|
@ -355,7 +355,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
|
||||
pills.AddRange(new Drawable[]
|
||||
{
|
||||
new PlaylistCountPill
|
||||
new PlaylistCountPill(Room)
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
|
@ -1,10 +1,12 @@
|
||||
// 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.ComponentModel;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
{
|
||||
@ -13,26 +15,47 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
/// </summary>
|
||||
public partial class PlaylistCountPill : OnlinePlayPill
|
||||
{
|
||||
private readonly Room room;
|
||||
|
||||
public PlaylistCountPill(Room room)
|
||||
{
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
PlaylistItemStats.BindValueChanged(_ => updateCount());
|
||||
Playlist.BindCollectionChanged((_, _) => updateCount(), true);
|
||||
Playlist.BindCollectionChanged((_, _) => updateCount());
|
||||
|
||||
room.PropertyChanged += onRoomPropertyChanged;
|
||||
updateCount();
|
||||
}
|
||||
|
||||
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Room.PlaylistItemStats))
|
||||
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.
|
||||
// This allows the count to display correctly on the room screen (after joining a room).
|
||||
? Playlist.Count(i => !i.Expired)
|
||||
: PlaylistItemStats.Value.CountActive;
|
||||
: room.PlaylistItemStats.CountActive;
|
||||
|
||||
TextFlow.Clear();
|
||||
TextFlow.AddText(activeItems.ToLocalisableString(), s => s.Font = s.Font.With(weight: FontWeight.Bold));
|
||||
TextFlow.AddText(" ");
|
||||
TextFlow.AddText("Beatmap".ToQuantity(activeItems, ShowQuantityAs.None));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
room.PropertyChanged -= onRoomPropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
@ -14,9 +14,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
/// </summary>
|
||||
public partial class OnlinePlayComposite : CompositeDrawable
|
||||
{
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<Room.RoomPlaylistItemStats> PlaylistItemStats { get; private set; } = null!;
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
protected BindableList<PlaylistItem> Playlist { get; private set; } = null!;
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
|
||||
if (ruleset != null)
|
||||
{
|
||||
room.PlaylistItemStats.Value = new Room.RoomPlaylistItemStats
|
||||
room.PlaylistItemStats = new Room.RoomPlaylistItemStats
|
||||
{
|
||||
RulesetIDs = new[] { ruleset.OnlineID },
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user