1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 09:03:01 +08:00

Make Room.DifficultyRange non-bindable

This commit is contained in:
Dan Balasescu 2024-11-13 22:33:49 +09:00
parent 487a010b12
commit c4f8fd1832
No known key found for this signature in database
5 changed files with 46 additions and 23 deletions

View File

@ -20,7 +20,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
SelectedRoom.Value = new Room(); SelectedRoom.Value = new Room();
Child = new StarRatingRangeDisplay Child = new StarRatingRangeDisplay(SelectedRoom.Value)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre

View File

@ -164,6 +164,15 @@ namespace osu.Game.Online.Rooms
set => SetField(ref playlistItemStats, value); set => SetField(ref playlistItemStats, value);
} }
/// <summary>
/// Describes the range of difficulty of the room.
/// </summary>
public RoomDifficultyRange? DifficultyRange
{
get => difficultyRange;
set => SetField(ref difficultyRange, value);
}
/// <summary> /// <summary>
/// The playlist queueing mode. Only valid for multiplayer rooms. /// The playlist queueing mode. Only valid for multiplayer rooms.
/// </summary> /// </summary>
@ -270,6 +279,9 @@ namespace osu.Game.Online.Rooms
[JsonProperty("playlist_item_stats")] [JsonProperty("playlist_item_stats")]
private RoomPlaylistItemStats? playlistItemStats; private RoomPlaylistItemStats? playlistItemStats;
[JsonProperty("difficulty_range")]
private RoomDifficultyRange? difficultyRange;
[JsonConverter(typeof(SnakeCaseStringEnumConverter))] [JsonConverter(typeof(SnakeCaseStringEnumConverter))]
[JsonProperty("type")] [JsonProperty("type")]
private MatchType type; private MatchType type;
@ -300,10 +312,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("difficulty_range")]
[Cached]
public readonly Bindable<RoomDifficultyRange> DifficultyRange = new Bindable<RoomDifficultyRange>();
[Cached] [Cached]
[JsonProperty("current_user_score")] [JsonProperty("current_user_score")]
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>(); public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
@ -340,7 +348,7 @@ namespace osu.Game.Online.Rooms
UserScore.Value = other.UserScore.Value; UserScore.Value = other.UserScore.Value;
QueueMode = other.QueueMode; QueueMode = other.QueueMode;
AutoStartDuration = other.AutoStartDuration; AutoStartDuration = other.AutoStartDuration;
DifficultyRange.Value = other.DifficultyRange.Value; DifficultyRange = other.DifficultyRange;
PlaylistItemStats = other.PlaylistItemStats; PlaylistItemStats = other.PlaylistItemStats;
CurrentPlaylistItem = other.CurrentPlaylistItem; CurrentPlaylistItem = other.CurrentPlaylistItem;
AutoSkip = other.AutoSkip; AutoSkip = other.AutoSkip;

View File

@ -1,9 +1,8 @@
// 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.
#nullable disable
using System; using System;
using System.ComponentModel;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -13,22 +12,27 @@ using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osuTK; using osuTK;
using Container = osu.Framework.Graphics.Containers.Container;
namespace osu.Game.Screens.OnlinePlay.Components namespace osu.Game.Screens.OnlinePlay.Components
{ {
public partial class StarRatingRangeDisplay : OnlinePlayComposite public partial class StarRatingRangeDisplay : OnlinePlayComposite
{ {
private readonly Room room;
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; } = null!;
private StarRatingDisplay minDisplay; private StarRatingDisplay minDisplay = null!;
private Drawable minBackground; private Drawable minBackground = null!;
private StarRatingDisplay maxDisplay; private StarRatingDisplay maxDisplay = null!;
private Drawable maxBackground; private Drawable maxBackground = null!;
public StarRatingRangeDisplay() public StarRatingRangeDisplay(Room room)
{ {
this.room = room;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
} }
@ -76,8 +80,16 @@ namespace osu.Game.Screens.OnlinePlay.Components
{ {
base.LoadComplete(); base.LoadComplete();
DifficultyRange.BindValueChanged(_ => updateRange()); Playlist.BindCollectionChanged((_, _) => updateRange());
Playlist.BindCollectionChanged((_, _) => updateRange(), true);
room.PropertyChanged += onRoomPropertyChanged;
updateRange();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.DifficultyRange))
updateRange();
} }
private void updateRange() private void updateRange()
@ -85,11 +97,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
StarDifficulty minDifficulty; StarDifficulty minDifficulty;
StarDifficulty maxDifficulty; StarDifficulty maxDifficulty;
if (DifficultyRange.Value != null && Playlist.Count == 0) if (room.DifficultyRange != null && Playlist.Count == 0)
{ {
// When Playlist is empty (in lounge) we take retrieved range // When Playlist is empty (in lounge) we take retrieved range
minDifficulty = new StarDifficulty(DifficultyRange.Value.Min, 0); minDifficulty = new StarDifficulty(room.DifficultyRange.Min, 0);
maxDifficulty = new StarDifficulty(DifficultyRange.Value.Max, 0); maxDifficulty = new StarDifficulty(room.DifficultyRange.Max, 0);
} }
else else
{ {
@ -107,5 +119,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
minBackground.Colour = colours.ForStarDifficulty(minDifficulty.Stars); minBackground.Colour = colours.ForStarDifficulty(minDifficulty.Stars);
maxBackground.Colour = colours.ForStarDifficulty(maxDifficulty.Stars); maxBackground.Colour = colours.ForStarDifficulty(maxDifficulty.Stars);
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
} }
} }

View File

@ -360,7 +360,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
}, },
new StarRatingRangeDisplay new StarRatingRangeDisplay(Room)
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,

View File

@ -17,9 +17,6 @@ namespace osu.Game.Screens.OnlinePlay
[Resolved(typeof(Room))] [Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; } = null!; protected BindableList<PlaylistItem> Playlist { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<Room.RoomDifficultyRange> DifficultyRange { get; private set; } = null!;
[Resolved(typeof(Room))] [Resolved(typeof(Room))]
protected BindableList<APIUser> RecentParticipants { get; private set; } = null!; protected BindableList<APIUser> RecentParticipants { get; private set; } = null!;