1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 15:33:05 +08:00

Merge pull request #11790 from peppy/playlists-show-remaining-attempts

Display remaining attempts for playlist rooms with room-level attempt limits
This commit is contained in:
Dan Balasescu 2021-02-16 21:10:19 +09:00 committed by GitHub
commit bef0e5cfa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 5 deletions

View File

@ -0,0 +1,19 @@
// 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 Newtonsoft.Json;
namespace osu.Game.Online.Rooms
{
/// <summary>
/// Represents attempts on a specific playlist item.
/// </summary>
public class ItemAttemptsCount
{
[JsonProperty("id")]
public int PlaylistItemID { get; set; }
[JsonProperty("attempts")]
public int Attempts { get; set; }
}
}

View File

@ -0,0 +1,16 @@
// 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 Newtonsoft.Json;
namespace osu.Game.Online.Rooms
{
/// <summary>
/// Represents aggregated score for the local user for a playlist.
/// </summary>
public class PlaylistAggregateScore
{
[JsonProperty("playlist_item_attempts")]
public ItemAttemptsCount[] PlaylistItemAttempts { get; set; }
}
}

View File

@ -72,6 +72,10 @@ namespace osu.Game.Online.Rooms
[JsonIgnore]
public readonly Bindable<int?> MaxParticipants = new Bindable<int?>();
[Cached]
[JsonProperty("current_user_score")]
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
[Cached]
[JsonProperty("recent_participants")]
public readonly BindableList<User> RecentParticipants = new BindableList<User>();
@ -144,6 +148,7 @@ namespace osu.Game.Online.Rooms
MaxParticipants.Value = other.MaxParticipants.Value;
ParticipantCount.Value = other.ParticipantCount.Value;
EndDate.Value = other.EndDate.Value;
UserScore.Value = other.UserScore.Value;
if (EndDate.Value != null && DateTimeOffset.Now >= EndDate.Value)
Status.Value = new RoomStatusEnded();

View File

@ -1,6 +1,7 @@
// 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.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -39,12 +40,26 @@ namespace osu.Game.Screens.OnlinePlay.Components
{
base.LoadComplete();
MaxAttempts.BindValueChanged(attempts =>
MaxAttempts.BindValueChanged(_ => updateAttempts());
UserScore.BindValueChanged(_ => updateAttempts(), true);
}
private void updateAttempts()
{
attemptDisplay.Text = attempts.NewValue == null
? string.Empty
: $"Maximum attempts: {attempts.NewValue:N0}";
}, true);
if (MaxAttempts.Value != null)
{
attemptDisplay.Text = $"Maximum attempts: {MaxAttempts.Value:N0}";
if (UserScore.Value != null)
{
int remaining = MaxAttempts.Value.Value - UserScore.Value.PlaylistItemAttempts.Sum(a => a.Attempts);
attemptDisplay.Text += $" ({remaining} remaining)";
}
}
else
{
attemptDisplay.Text = string.Empty;
}
}
}
}

View File

@ -42,6 +42,9 @@ namespace osu.Game.Screens.OnlinePlay
[Resolved(typeof(Room))]
protected Bindable<int?> MaxAttempts { get; private set; }
[Resolved(typeof(Room))]
public Bindable<PlaylistAggregateScore> UserScore { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<DateTimeOffset?> EndDate { get; private set; }