mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Make Room.MaxAttempts
non-bindable
This commit is contained in:
parent
0ceaafe731
commit
6c84e425f8
@ -84,7 +84,7 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
setupAndCreateRoom(room =>
|
||||
{
|
||||
room.Name = "my awesome room";
|
||||
room.MaxAttempts.Value = 5;
|
||||
room.MaxAttempts = 5;
|
||||
room.Host = API.LocalUser.Value;
|
||||
room.RecentParticipants.Add(room.Host);
|
||||
room.EndDate = DateTimeOffset.Now.AddMinutes(5);
|
||||
|
@ -146,6 +146,15 @@ namespace osu.Game.Online.Rooms
|
||||
set => SetField(ref type, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of attempts on the playlist. Only valid for playlist rooms.
|
||||
/// </summary>
|
||||
public int? MaxAttempts
|
||||
{
|
||||
get => maxAttempts;
|
||||
set => SetField(ref maxAttempts, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The playlist queueing mode. Only valid for multiplayer rooms.
|
||||
/// </summary>
|
||||
@ -237,6 +246,9 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("participant_count")]
|
||||
private int participantCount;
|
||||
|
||||
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
private int? maxAttempts;
|
||||
|
||||
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
|
||||
[JsonProperty("type")]
|
||||
private MatchType type;
|
||||
@ -276,9 +288,6 @@ namespace osu.Game.Online.Rooms
|
||||
[Cached]
|
||||
public readonly Bindable<RoomDifficultyRange> DifficultyRange = new Bindable<RoomDifficultyRange>();
|
||||
|
||||
[Cached]
|
||||
public readonly Bindable<int?> MaxAttempts = new Bindable<int?>();
|
||||
|
||||
[Cached]
|
||||
[JsonProperty("current_user_score")]
|
||||
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
|
||||
@ -287,14 +296,6 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("recent_participants")]
|
||||
public readonly BindableList<APIUser> RecentParticipants = new BindableList<APIUser>();
|
||||
|
||||
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
|
||||
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
private int? maxAttempts
|
||||
{
|
||||
get => MaxAttempts.Value;
|
||||
set => MaxAttempts.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies values from another <see cref="Room"/> into this one.
|
||||
/// </summary>
|
||||
|
@ -1,26 +1,28 @@
|
||||
// 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.ComponentModel;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
public partial class RoomLocalUserInfo : OnlinePlayComposite
|
||||
{
|
||||
private OsuSpriteText attemptDisplay;
|
||||
private readonly Room room;
|
||||
private OsuSpriteText attemptDisplay = null!;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
private OsuColour colours { get; set; } = null!;
|
||||
|
||||
public RoomLocalUserInfo()
|
||||
public RoomLocalUserInfo(Room room)
|
||||
{
|
||||
this.room = room;
|
||||
AutoSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
@ -45,19 +47,27 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
MaxAttempts.BindValueChanged(_ => updateAttempts());
|
||||
UserScore.BindValueChanged(_ => updateAttempts(), true);
|
||||
UserScore.BindValueChanged(_ => updateAttempts());
|
||||
|
||||
room.PropertyChanged += onRoomPropertyChanged;
|
||||
updateAttempts();
|
||||
}
|
||||
|
||||
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Room.MaxAttempts))
|
||||
updateAttempts();
|
||||
}
|
||||
|
||||
private void updateAttempts()
|
||||
{
|
||||
if (MaxAttempts.Value != null)
|
||||
if (room.MaxAttempts != null)
|
||||
{
|
||||
attemptDisplay.Text = $"Maximum attempts: {MaxAttempts.Value:N0}";
|
||||
attemptDisplay.Text = $"Maximum attempts: {room.MaxAttempts:N0}";
|
||||
|
||||
if (UserScore.Value != null)
|
||||
{
|
||||
int remaining = MaxAttempts.Value.Value - UserScore.Value.PlaylistItemAttempts.Sum(a => a.Attempts);
|
||||
int remaining = room.MaxAttempts.Value - UserScore.Value.PlaylistItemAttempts.Sum(a => a.Attempts);
|
||||
attemptDisplay.Text += $" ({remaining} remaining)";
|
||||
|
||||
if (remaining == 0)
|
||||
@ -69,5 +79,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
attemptDisplay.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
room.PropertyChanged -= onRoomPropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
[Resolved(typeof(Room))]
|
||||
protected BindableList<APIUser> RecentParticipants { get; private set; } = null!;
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<int?> MaxAttempts { get; private set; } = null!;
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
public Bindable<PlaylistAggregateScore> UserScore { get; private set; } = null!;
|
||||
}
|
||||
|
@ -15,9 +15,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
public partial class PlaylistsReadyButton : ReadyButton
|
||||
{
|
||||
[Resolved(typeof(Room), nameof(Room.MaxAttempts))]
|
||||
private Bindable<int?> maxAttempts { get; set; } = null!;
|
||||
|
||||
[Resolved(typeof(Room), nameof(Room.UserScore))]
|
||||
private Bindable<PlaylistAggregateScore> userScore { get; set; } = null!;
|
||||
|
||||
@ -46,10 +43,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
userScore.BindValueChanged(aggregate =>
|
||||
{
|
||||
if (maxAttempts.Value == null)
|
||||
if (room.MaxAttempts == null)
|
||||
return;
|
||||
|
||||
int remaining = maxAttempts.Value.Value - aggregate.NewValue.PlaylistItemAttempts.Sum(a => a.Attempts);
|
||||
int remaining = room.MaxAttempts.Value - aggregate.NewValue.PlaylistItemAttempts.Sum(a => a.Attempts);
|
||||
|
||||
hasRemainingAttempts = remaining > 0;
|
||||
});
|
||||
|
@ -316,8 +316,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
loadingLayer = new LoadingLayer(true)
|
||||
};
|
||||
|
||||
MaxAttempts.BindValueChanged(count => MaxAttemptsField.Text = count.NewValue?.ToString(), true);
|
||||
|
||||
DurationField.Current.BindValueChanged(duration =>
|
||||
{
|
||||
if (hasValidDuration)
|
||||
@ -346,6 +344,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
updateRoomAvailability();
|
||||
updateRoomMaxParticipants();
|
||||
updateRoomDuration();
|
||||
updateRoomMaxAttempts();
|
||||
}
|
||||
|
||||
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
@ -367,6 +366,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
case nameof(Room.Duration):
|
||||
updateRoomDuration();
|
||||
break;
|
||||
|
||||
case nameof(Room.MaxAttempts):
|
||||
updateRoomMaxAttempts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -382,6 +385,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
private void updateRoomDuration()
|
||||
=> DurationField.Current.Value = room.Duration ?? TimeSpan.FromMinutes(30);
|
||||
|
||||
private void updateRoomMaxAttempts()
|
||||
=> MaxAttemptsField.Text = room.MaxAttempts?.ToString();
|
||||
|
||||
private void populateDurations(ValueChangedEvent<APIUser> user)
|
||||
{
|
||||
// roughly correct (see https://github.com/Humanizr/Humanizer/blob/18167e56c082449cc4fe805b8429e3127a7b7f93/readme.md?plain=1#L427)
|
||||
@ -431,13 +437,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
room.Name = NameField.Text;
|
||||
room.Availability = AvailabilityPicker.Current.Value;
|
||||
room.MaxParticipants = int.TryParse(MaxParticipantsField.Text, out int max) ? max : null;
|
||||
|
||||
if (int.TryParse(MaxAttemptsField.Text, out max))
|
||||
MaxAttempts.Value = max;
|
||||
else
|
||||
MaxAttempts.Value = null;
|
||||
|
||||
room.MaxParticipants = int.TryParse(MaxParticipantsField.Text, out int maxParticipants) ? maxParticipants : null;
|
||||
room.MaxAttempts = int.TryParse(MaxAttemptsField.Text, out int maxAttempts) ? maxAttempts : null;
|
||||
room.Duration = DurationField.Current.Value;
|
||||
|
||||
loadingLayer.Show();
|
||||
|
@ -60,16 +60,24 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
base.LoadComplete();
|
||||
|
||||
isIdle.BindValueChanged(_ => updatePollingRate(), true);
|
||||
Room.MaxAttempts.BindValueChanged(_ => progressSection.Alpha = Room.MaxAttempts.Value != null ? 1 : 0, true);
|
||||
|
||||
Room.PropertyChanged += onRoomPropertyChanged;
|
||||
updateSetupState();
|
||||
updateRoomMaxAttempts();
|
||||
}
|
||||
|
||||
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Room.RoomID))
|
||||
updateSetupState();
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(Room.RoomID):
|
||||
updateSetupState();
|
||||
break;
|
||||
|
||||
case nameof(Room.MaxAttempts):
|
||||
updateRoomMaxAttempts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSetupState()
|
||||
@ -82,6 +90,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRoomMaxAttempts()
|
||||
=> progressSection.Alpha = Room.MaxAttempts != null ? 1 : 0;
|
||||
|
||||
protected override Drawable CreateMainContent() => new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -193,7 +204,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OverlinedHeader("Progress"),
|
||||
new RoomLocalUserInfo(),
|
||||
new RoomLocalUserInfo(Room),
|
||||
}
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user