1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +08:00

Make room duration/endsat nullable

This commit is contained in:
smoogipoo 2020-12-21 16:18:39 +09:00
parent c37840b37c
commit a59124dd93
6 changed files with 34 additions and 15 deletions

View File

@ -22,22 +22,28 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
new DrawableRoom(new Room
{
Name = { Value = "Room 1" },
Name = { Value = "Open - ending in 1 day" },
Status = { Value = new RoomStatusOpen() },
EndDate = { Value = DateTimeOffset.Now.AddDays(1) }
}) { MatchingFilter = true },
new DrawableRoom(new Room
{
Name = { Value = "Room 2" },
Name = { Value = "Playing - ending in 1 day" },
Status = { Value = new RoomStatusPlaying() },
EndDate = { Value = DateTimeOffset.Now.AddDays(1) }
}) { MatchingFilter = true },
new DrawableRoom(new Room
{
Name = { Value = "Room 3" },
Name = { Value = "Ended" },
Status = { Value = new RoomStatusEnded() },
EndDate = { Value = DateTimeOffset.Now }
}) { MatchingFilter = true },
new DrawableRoom(new Room
{
Name = { Value = "Open (realtime)" },
Status = { Value = new RoomStatusOpen() },
Category = { Value = RoomCategory.Realtime }
}) { MatchingFilter = true },
}
};
}

View File

@ -40,7 +40,7 @@ namespace osu.Game.Online.Multiplayer
[Cached]
[JsonIgnore]
public readonly Bindable<TimeSpan> Duration = new Bindable<TimeSpan>(TimeSpan.FromMinutes(30));
public readonly Bindable<TimeSpan?> Duration = new Bindable<TimeSpan?>();
[Cached]
[JsonIgnore]
@ -78,16 +78,22 @@ namespace osu.Game.Online.Multiplayer
}
[JsonProperty("duration")]
private int duration
private int? duration
{
get => (int)Duration.Value.TotalMinutes;
set => Duration.Value = TimeSpan.FromMinutes(value);
get => (int?)Duration.Value?.TotalMinutes;
set
{
if (value == null)
Duration.Value = null;
else
Duration.Value = TimeSpan.FromMinutes(value.Value);
}
}
// Only supports retrieval for now
[Cached]
[JsonProperty("ends_at")]
public readonly Bindable<DateTimeOffset> EndDate = new Bindable<DateTimeOffset>();
public readonly Bindable<DateTimeOffset?> EndDate = new Bindable<DateTimeOffset?>();
// Todo: Find a better way to do this (https://github.com/ppy/osu-framework/issues/1930)
[JsonProperty("max_attempts", DefaultValueHandling = DefaultValueHandling.Ignore)]

View File

@ -48,16 +48,23 @@ namespace osu.Game.Screens.Multi.Components
private class EndDatePart : DrawableDate
{
public readonly IBindable<DateTimeOffset> EndDate = new Bindable<DateTimeOffset>();
public readonly IBindable<DateTimeOffset?> EndDate = new Bindable<DateTimeOffset?>();
public EndDatePart()
: base(DateTimeOffset.UtcNow)
{
EndDate.BindValueChanged(date => Date = date.NewValue);
EndDate.BindValueChanged(date =>
{
// If null, set a very large future date to prevent unnecessary schedules.
Date = date.NewValue ?? DateTimeOffset.Now.AddYears(1);
}, true);
}
protected override string Format()
{
if (EndDate.Value == null)
return string.Empty;
var diffToNow = Date.Subtract(DateTimeOffset.Now);
if (diffToNow.TotalSeconds < -5)

View File

@ -325,7 +325,7 @@ namespace osu.Game.Screens.Multi.Match.Components
Availability.BindValueChanged(availability => AvailabilityPicker.Current.Value = availability.NewValue, true);
Type.BindValueChanged(type => TypePicker.Current.Value = type.NewValue, true);
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
Duration.BindValueChanged(duration => DurationField.Current.Value = duration.NewValue, true);
Duration.BindValueChanged(duration => DurationField.Current.Value = duration.NewValue ?? TimeSpan.FromMinutes(30), true);
playlist.Items.BindTo(Playlist);
Playlist.BindCollectionChanged(onPlaylistChanged, true);

View File

@ -40,12 +40,12 @@ namespace osu.Game.Screens.Multi
protected Bindable<int?> MaxParticipants { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<DateTimeOffset> EndDate { get; private set; }
protected Bindable<DateTimeOffset?> EndDate { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<RoomAvailability> Availability { get; private set; }
[Resolved(typeof(Room))]
protected Bindable<TimeSpan> Duration { get; private set; }
protected Bindable<TimeSpan?> Duration { get; private set; }
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Game.Screens.Multi.Timeshift
public class TimeshiftReadyButton : ReadyButton
{
[Resolved(typeof(Room), nameof(Room.EndDate))]
private Bindable<DateTimeOffset> endDate { get; set; }
private Bindable<DateTimeOffset?> endDate { get; set; }
public TimeshiftReadyButton()
{
@ -32,7 +32,7 @@ namespace osu.Game.Screens.Multi.Timeshift
{
base.Update();
Enabled.Value = DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(GameBeatmap.Value.Track.Length) < endDate.Value;
Enabled.Value = endDate.Value != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(GameBeatmap.Value.Track.Length) < endDate.Value;
}
}
}