1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 06:52:55 +08:00

Make Room.UserScore non-bindable

This commit is contained in:
Dan Balasescu 2024-11-13 22:39:01 +09:00
parent c4f8fd1832
commit dc5337d771
No known key found for this signature in database
4 changed files with 45 additions and 24 deletions

View File

@ -200,6 +200,15 @@ namespace osu.Game.Online.Rooms
set => SetField(ref autoStartDuration, (ushort)value.TotalSeconds);
}
/// <summary>
/// Provides some extra scoring statistics for the local user in the room.
/// </summary>
public PlaylistAggregateScore? UserScore
{
get => userScore;
set => SetField(ref userScore, value);
}
/// <summary>
/// Represents the current item selected within the room.
/// </summary>
@ -296,6 +305,9 @@ namespace osu.Game.Online.Rooms
[JsonProperty("auto_start_duration")]
private ushort autoStartDuration;
[JsonProperty("current_user_score")]
private PlaylistAggregateScore? userScore;
[JsonProperty("current_playlist_item")]
private PlaylistItem? currentPlaylistItem;
@ -312,10 +324,6 @@ namespace osu.Game.Online.Rooms
[JsonProperty("playlist")]
public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>();
[Cached]
[JsonProperty("current_user_score")]
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
[Cached]
[JsonProperty("recent_participants")]
public readonly BindableList<APIUser> RecentParticipants = new BindableList<APIUser>();
@ -345,7 +353,7 @@ namespace osu.Game.Online.Rooms
MaxParticipants = other.MaxParticipants;
ParticipantCount = other.ParticipantCount;
EndDate = other.EndDate;
UserScore.Value = other.UserScore.Value;
UserScore = other.UserScore;
QueueMode = other.QueueMode;
AutoStartDuration = other.AutoStartDuration;
DifficultyRange = other.DifficultyRange;

View File

@ -47,16 +47,19 @@ namespace osu.Game.Screens.OnlinePlay.Components
{
base.LoadComplete();
UserScore.BindValueChanged(_ => updateAttempts());
room.PropertyChanged += onRoomPropertyChanged;
updateAttempts();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.MaxAttempts))
switch (e.PropertyName)
{
case nameof(Room.UserScore):
case nameof(Room.MaxAttempts):
updateAttempts();
break;
}
}
private void updateAttempts()
@ -65,9 +68,9 @@ namespace osu.Game.Screens.OnlinePlay.Components
{
attemptDisplay.Text = $"Maximum attempts: {room.MaxAttempts:N0}";
if (UserScore.Value != null)
if (room.UserScore != null)
{
int remaining = room.MaxAttempts.Value - UserScore.Value.PlaylistItemAttempts.Sum(a => a.Attempts);
int remaining = room.MaxAttempts.Value - room.UserScore.PlaylistItemAttempts.Sum(a => a.Attempts);
attemptDisplay.Text += $" ({remaining} remaining)";
if (remaining == 0)

View File

@ -19,8 +19,5 @@ namespace osu.Game.Screens.OnlinePlay
[Resolved(typeof(Room))]
protected BindableList<APIUser> RecentParticipants { get; private set; } = null!;
[Resolved(typeof(Room))]
public Bindable<PlaylistAggregateScore> UserScore { get; private set; } = null!;
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.ComponentModel;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -15,9 +16,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
public partial class PlaylistsReadyButton : ReadyButton
{
[Resolved(typeof(Room), nameof(Room.UserScore))]
private Bindable<PlaylistAggregateScore> userScore { get; set; } = null!;
[Resolved]
private IBindable<WorkingBeatmap> gameBeatmap { get; set; } = null!;
@ -41,15 +39,24 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
base.LoadComplete();
userScore.BindValueChanged(aggregate =>
room.PropertyChanged += onRoomPropertyChanged;
updateRoomUserScore();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (room.MaxAttempts == null)
if (e.PropertyName == nameof(Room.UserScore))
updateRoomUserScore();
}
private void updateRoomUserScore()
{
if (room.MaxAttempts == null || room.UserScore == null)
return;
int remaining = room.MaxAttempts.Value - aggregate.NewValue.PlaylistItemAttempts.Sum(a => a.Attempts);
int remaining = room.MaxAttempts.Value - room.UserScore.PlaylistItemAttempts.Sum(a => a.Attempts);
hasRemainingAttempts = remaining > 0;
});
}
protected override void Update()
@ -76,5 +83,11 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
private bool enoughTimeLeft =>
// This should probably consider the length of the currently selected item, rather than a constant 30 seconds.
room.EndDate != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < room.EndDate;
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
}
}