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 @@ public override void SetUpSteps()
{
SelectedRoom.Value = new Room();
Child = new StarRatingRangeDisplay
Child = new StarRatingRangeDisplay(SelectedRoom.Value)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre

View File

@ -164,6 +164,15 @@ public RoomPlaylistItemStats? PlaylistItemStats
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>
/// The playlist queueing mode. Only valid for multiplayer rooms.
/// </summary>
@ -270,6 +279,9 @@ public RoomAvailability Availability
[JsonProperty("playlist_item_stats")]
private RoomPlaylistItemStats? playlistItemStats;
[JsonProperty("difficulty_range")]
private RoomDifficultyRange? difficultyRange;
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
[JsonProperty("type")]
private MatchType type;
@ -300,10 +312,6 @@ public RoomAvailability Availability
[JsonProperty("playlist")]
public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>();
[JsonProperty("difficulty_range")]
[Cached]
public readonly Bindable<RoomDifficultyRange> DifficultyRange = new Bindable<RoomDifficultyRange>();
[Cached]
[JsonProperty("current_user_score")]
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
@ -340,7 +348,7 @@ public void CopyFrom(Room other)
UserScore.Value = other.UserScore.Value;
QueueMode = other.QueueMode;
AutoStartDuration = other.AutoStartDuration;
DifficultyRange.Value = other.DifficultyRange.Value;
DifficultyRange = other.DifficultyRange;
PlaylistItemStats = other.PlaylistItemStats;
CurrentPlaylistItem = other.CurrentPlaylistItem;
AutoSkip = other.AutoSkip;

View File

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

View File

@ -17,9 +17,6 @@ public partial class OnlinePlayComposite : CompositeDrawable
[Resolved(typeof(Room))]
protected BindableList<PlaylistItem> Playlist { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<Room.RoomDifficultyRange> DifficultyRange { get; private set; } = null!;
[Resolved(typeof(Room))]
protected BindableList<APIUser> RecentParticipants { get; private set; } = null!;