Display remaining attempts for playlist rooms with room-level attempt limits

This commit is contained in:
Dean Herbert 2021-02-16 13:32:14 +09:00
parent 335af04764
commit 02417697e9
5 changed files with 65 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 @@ private RoomCategory category
[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 @@ public void CopyFrom(Room other)
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,7 +1,9 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
@ -39,12 +41,27 @@ protected override void LoadComplete()
{
base.LoadComplete();
MaxAttempts.BindValueChanged(attempts =>
MaxAttempts.BindValueChanged(_ => updateAttempts());
UserScore.BindValueChanged(_ => updateAttempts(), true);
}
private void updateAttempts()
{
if (MaxAttempts.Value != null)
{
attemptDisplay.Text = attempts.NewValue == null
? string.Empty
: $"Maximum attempts: {attempts.NewValue:N0}";
}, true);
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 @@ public class OnlinePlayComposite : CompositeDrawable
[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; }