mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 18:32:56 +08:00
Display remaining attempts for playlist rooms with room-level attempt limits
This commit is contained in:
parent
335af04764
commit
02417697e9
19
osu.Game/Online/Rooms/ItemAttemptsCount.cs
Normal file
19
osu.Game/Online/Rooms/ItemAttemptsCount.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
16
osu.Game/Online/Rooms/PlaylistAggregateScore.cs
Normal file
16
osu.Game/Online/Rooms/PlaylistAggregateScore.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -72,6 +72,10 @@ namespace osu.Game.Online.Rooms
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public readonly Bindable<int?> MaxParticipants = new Bindable<int?>();
|
public readonly Bindable<int?> MaxParticipants = new Bindable<int?>();
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
[JsonProperty("current_user_score")]
|
||||||
|
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
[JsonProperty("recent_participants")]
|
[JsonProperty("recent_participants")]
|
||||||
public readonly BindableList<User> RecentParticipants = new BindableList<User>();
|
public readonly BindableList<User> RecentParticipants = new BindableList<User>();
|
||||||
@ -144,6 +148,7 @@ namespace osu.Game.Online.Rooms
|
|||||||
MaxParticipants.Value = other.MaxParticipants.Value;
|
MaxParticipants.Value = other.MaxParticipants.Value;
|
||||||
ParticipantCount.Value = other.ParticipantCount.Value;
|
ParticipantCount.Value = other.ParticipantCount.Value;
|
||||||
EndDate.Value = other.EndDate.Value;
|
EndDate.Value = other.EndDate.Value;
|
||||||
|
UserScore.Value = other.UserScore.Value;
|
||||||
|
|
||||||
if (EndDate.Value != null && DateTimeOffset.Now >= EndDate.Value)
|
if (EndDate.Value != null && DateTimeOffset.Now >= EndDate.Value)
|
||||||
Status.Value = new RoomStatusEnded();
|
Status.Value = new RoomStatusEnded();
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
@ -39,12 +41,27 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
{
|
{
|
||||||
base.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
|
attemptDisplay.Text = $"Maximum attempts: {MaxAttempts.Value:N0}";
|
||||||
? string.Empty
|
|
||||||
: $"Maximum attempts: {attempts.NewValue:N0}";
|
if (UserScore.Value != null)
|
||||||
}, true);
|
{
|
||||||
|
int remaining = MaxAttempts.Value.Value - UserScore.Value.PlaylistItemAttempts.Sum(a => a.Attempts);
|
||||||
|
attemptDisplay.Text += $" ({remaining} remaining)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
attemptDisplay.Text = string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,9 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
[Resolved(typeof(Room))]
|
[Resolved(typeof(Room))]
|
||||||
protected Bindable<int?> MaxAttempts { get; private set; }
|
protected Bindable<int?> MaxAttempts { get; private set; }
|
||||||
|
|
||||||
|
[Resolved(typeof(Room))]
|
||||||
|
public Bindable<PlaylistAggregateScore> UserScore { get; private set; }
|
||||||
|
|
||||||
[Resolved(typeof(Room))]
|
[Resolved(typeof(Room))]
|
||||||
protected Bindable<DateTimeOffset?> EndDate { get; private set; }
|
protected Bindable<DateTimeOffset?> EndDate { get; private set; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user