1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Make Room.Duration & Room.StartDate & Room.EndDate non-bindable

This commit is contained in:
Dan Balasescu 2024-11-13 20:20:14 +09:00
parent 89de4f0f87
commit 0ceaafe731
No known key found for this signature in database
25 changed files with 186 additions and 125 deletions

View File

@ -49,7 +49,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AllowedMods = [new APIMod(new OsuModDoubleTime())]
}
},
EndDate = { Value = DateTimeOffset.Now.AddHours(12) },
EndDate = DateTimeOffset.Now.AddHours(12),
Category = RoomCategory.DailyChallenge
};
@ -72,7 +72,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AllowedMods = [new APIMod(new OsuModDoubleTime())]
}
},
EndDate = { Value = DateTimeOffset.Now.AddHours(12) },
EndDate = DateTimeOffset.Now.AddHours(12),
Category = RoomCategory.DailyChallenge
};
@ -101,7 +101,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AllowedMods = [new APIMod(new OsuModDoubleTime())]
}
},
EndDate = { Value = DateTimeOffset.Now.AddHours(12) },
EndDate = DateTimeOffset.Now.AddHours(12),
Category = RoomCategory.DailyChallenge
};

View File

@ -98,7 +98,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
Origin = Anchor.Centre,
Children = new Drawable[]
{
new DailyChallengeTimeRemainingRing(),
new DailyChallengeTimeRemainingRing(room.Value),
breakdown = new DailyChallengeScoreBreakdown(),
}
}
@ -125,8 +125,8 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AddSliderStep("update time remaining", 0f, 1f, 0f, progress =>
{
var startedTimeAgo = TimeSpan.FromHours(24) * progress;
room.Value.StartDate.Value = DateTimeOffset.Now - startedTimeAgo;
room.Value.EndDate.Value = room.Value.StartDate.Value.Value.AddDays(1);
room.Value.StartDate = DateTimeOffset.Now - startedTimeAgo;
room.Value.EndDate = room.Value.StartDate.Value.AddDays(1);
});
AddStep("add normal score", () =>
{

View File

@ -78,8 +78,8 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AllowedMods = [new APIMod(new OsuModDoubleTime())]
}
},
StartDate = { Value = DateTimeOffset.Now },
EndDate = { Value = DateTimeOffset.Now.AddHours(24) },
StartDate = DateTimeOffset.Now,
EndDate = DateTimeOffset.Now.AddHours(24),
Category = RoomCategory.DailyChallenge
}));
});

View File

@ -38,7 +38,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4,
},
ring = new DailyChallengeTimeRemainingRing
ring = new DailyChallengeTimeRemainingRing(room.Value)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
@ -59,29 +59,29 @@ namespace osu.Game.Tests.Visual.DailyChallenge
AddStep("just started", () =>
{
room.Value.StartDate.Value = DateTimeOffset.Now.AddMinutes(-1);
room.Value.EndDate.Value = room.Value.StartDate.Value.Value.AddDays(1);
room.Value.StartDate = DateTimeOffset.Now.AddMinutes(-1);
room.Value.EndDate = room.Value.StartDate.Value.AddDays(1);
});
AddStep("midway through", () =>
{
room.Value.StartDate.Value = DateTimeOffset.Now.AddHours(-12);
room.Value.EndDate.Value = room.Value.StartDate.Value.Value.AddDays(1);
room.Value.StartDate = DateTimeOffset.Now.AddHours(-12);
room.Value.EndDate = room.Value.StartDate.Value.AddDays(1);
});
AddStep("nearing end", () =>
{
room.Value.StartDate.Value = DateTimeOffset.Now.AddDays(-1).AddMinutes(8);
room.Value.EndDate.Value = room.Value.StartDate.Value.Value.AddDays(1);
room.Value.StartDate = DateTimeOffset.Now.AddDays(-1).AddMinutes(8);
room.Value.EndDate = room.Value.StartDate.Value.AddDays(1);
});
AddStep("already ended", () =>
{
room.Value.StartDate.Value = DateTimeOffset.Now.AddDays(-2);
room.Value.EndDate.Value = room.Value.StartDate.Value.Value.AddDays(1);
room.Value.StartDate = DateTimeOffset.Now.AddDays(-2);
room.Value.EndDate = room.Value.StartDate.Value.AddDays(1);
});
AddSliderStep("manual progress", 0f, 1f, 0f, progress =>
{
var startedTimeAgo = TimeSpan.FromHours(24) * progress;
room.Value.StartDate.Value = DateTimeOffset.Now - startedTimeAgo;
room.Value.EndDate.Value = room.Value.StartDate.Value.Value.AddDays(1);
room.Value.StartDate = DateTimeOffset.Now - startedTimeAgo;
room.Value.EndDate = room.Value.StartDate.Value.AddDays(1);
});
}
}

View File

@ -48,8 +48,8 @@ namespace osu.Game.Tests.Visual.Menus
{
new PlaylistItem(beatmap)
},
StartDate = { Value = DateTimeOffset.Now.AddMinutes(-30) },
EndDate = { Value = DateTimeOffset.Now.AddSeconds(60) }
StartDate = DateTimeOffset.Now.AddMinutes(-30),
EndDate = DateTimeOffset.Now.AddSeconds(60)
});
return true;

View File

@ -77,7 +77,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Name = "Multiplayer room",
Status = new RoomStatusOpen(),
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
EndDate = DateTimeOffset.Now.AddDays(1),
Type = MatchType.HeadToHead,
Playlist = { item1 },
CurrentPlaylistItem = item1
@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Name = "Private room",
Status = new RoomStatusOpenPrivate(),
Password = "*",
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
EndDate = DateTimeOffset.Now.AddDays(1),
Type = MatchType.HeadToHead,
Playlist = { item3 },
CurrentPlaylistItem = item3
@ -96,7 +96,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Name = "Playlist room with multiple beatmaps",
Status = new RoomStatusPlaying(),
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
EndDate = DateTimeOffset.Now.AddDays(1),
Playlist = { item1, item2 },
CurrentPlaylistItem = item1
}),
@ -104,7 +104,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Name = "Finished room",
Status = new RoomStatusEnded(),
EndDate = { Value = DateTimeOffset.Now },
EndDate = DateTimeOffset.Now,
}),
createLoungeRoom(new Room
{

View File

@ -84,7 +84,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddStep("create room", () => settings.ApplyButton.Action.Invoke());
AddAssert("has correct name", () => createdRoom.Name == expected_name);
AddAssert("has correct duration", () => createdRoom.Duration.Value == expectedDuration);
AddAssert("has correct duration", () => createdRoom.Duration == expectedDuration);
}
[Test]

View File

@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual.Playlists
room.Name = "my awesome room";
room.Host = API.LocalUser.Value;
room.RecentParticipants.Add(room.Host);
room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
room.EndDate = DateTimeOffset.Now.AddMinutes(5);
room.Playlist.Add(new PlaylistItem(importedBeatmap.Beatmaps.First())
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID
@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual.Playlists
room.MaxAttempts.Value = 5;
room.Host = API.LocalUser.Value;
room.RecentParticipants.Add(room.Host);
room.EndDate.Value = DateTimeOffset.Now.AddMinutes(5);
room.EndDate = DateTimeOffset.Now.AddMinutes(5);
room.Playlist.Add(new PlaylistItem(importedBeatmap.Beatmaps.First())
{
RulesetID = new OsuRuleset().RulesetInfo.OnlineID

View File

@ -58,8 +58,8 @@ namespace osu.Game.Tests.Visual.UserInterface
{
new PlaylistItem(beatmap)
},
StartDate = { Value = DateTimeOffset.Now.AddMinutes(-5) },
EndDate = { Value = DateTimeOffset.Now.AddSeconds(30) }
StartDate = DateTimeOffset.Now.AddMinutes(-5),
EndDate = DateTimeOffset.Now.AddSeconds(30)
});
return true;
@ -136,8 +136,8 @@ namespace osu.Game.Tests.Visual.UserInterface
{
new PlaylistItem(beatmap)
},
StartDate = { Value = DateTimeOffset.Now.AddMinutes(-50) },
EndDate = { Value = DateTimeOffset.Now.AddSeconds(30) }
StartDate = DateTimeOffset.Now.AddMinutes(-50),
EndDate = DateTimeOffset.Now.AddSeconds(30)
});
return true;

View File

@ -206,7 +206,7 @@ namespace osu.Game.Online.Multiplayer
APIRoom.CurrentPlaylistItem = APIRoom.Playlist.Single(item => item.ID == joinedRoom.Settings.PlaylistItemId);
// The server will null out the end date upon the host joining the room, but the null value is never communicated to the client.
APIRoom.EndDate.Value = null;
APIRoom.EndDate = null;
Debug.Assert(LocalUser != null);
addUserToAPIRoom(LocalUser);

View File

@ -44,7 +44,7 @@ namespace osu.Game.Online.Rooms
// API doesn't populate status so let's do it here.
foreach (var room in Response)
{
if (room.EndDate.Value != null && DateTimeOffset.Now >= room.EndDate.Value)
if (room.EndDate != null && DateTimeOffset.Now >= room.EndDate)
room.Status = new RoomStatusEnded();
else if (room.HasPassword)
room.Status = new RoomStatusOpenPrivate();

View File

@ -86,6 +86,39 @@ namespace osu.Game.Online.Rooms
set => SetField(ref category, value);
}
/// <summary>
/// The duration for which the room will be open. Will be <c>null</c> after the room is created.
/// </summary>
/// <remarks>
/// To check the room end time, use <see cref="EndDate"/>.
/// </remarks>
public TimeSpan? Duration
{
get => duration == null ? null : TimeSpan.FromMinutes(duration.Value);
set => SetField(ref duration, value == null ? null : (int)value.Value.TotalMinutes);
}
/// <summary>
/// The date at which the room was opened. Will be <c>null</c> while the room has not yet been created.
/// </summary>
public DateTimeOffset? StartDate
{
get => startDate;
set => SetField(ref startDate, value);
}
/// <summary>
/// The date at which the room will be closed.
/// </summary>
/// <remarks>
/// To set the room duration, use <see cref="Duration"/>.
/// </remarks>
public DateTimeOffset? EndDate
{
get => endDate;
set => SetField(ref endDate, value);
}
/// <summary>
/// The maximum number of users allowed in the room.
/// </summary>
@ -189,6 +222,15 @@ namespace osu.Game.Online.Rooms
[JsonConverter(typeof(SnakeCaseStringEnumConverter))]
private RoomCategory category;
[JsonProperty("duration")]
private int? duration;
[JsonProperty("starts_at")]
private DateTimeOffset? startDate;
[JsonProperty("ends_at")]
private DateTimeOffset? endDate;
// Not yet serialised (not implemented).
private int? maxParticipants;
@ -245,36 +287,6 @@ namespace osu.Game.Online.Rooms
[JsonProperty("recent_participants")]
public readonly BindableList<APIUser> RecentParticipants = new BindableList<APIUser>();
#region Properties only used for room creation request
[Cached]
public readonly Bindable<TimeSpan?> Duration = new Bindable<TimeSpan?>();
[JsonProperty("duration")]
private int? duration
{
get => (int?)Duration.Value?.TotalMinutes;
set
{
if (value == null)
Duration.Value = null;
else
Duration.Value = TimeSpan.FromMinutes(value.Value);
}
}
#endregion
// Only supports retrieval for now
[Cached]
[JsonProperty("starts_at")]
public readonly Bindable<DateTimeOffset?> StartDate = new Bindable<DateTimeOffset?>();
// Only supports retrieval for now
[Cached]
[JsonProperty("ends_at")]
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)]
private int? maxAttempts
@ -307,7 +319,7 @@ namespace osu.Game.Online.Rooms
Type = other.Type;
MaxParticipants = other.MaxParticipants;
ParticipantCount = other.ParticipantCount;
EndDate.Value = other.EndDate.Value;
EndDate = other.EndDate;
UserScore.Value = other.UserScore.Value;
QueueMode = other.QueueMode;
AutoStartDuration = other.AutoStartDuration;

View File

@ -155,7 +155,7 @@ namespace osu.Game.Screens.Menu
Room = room;
cover.OnlineInfo = TooltipContent = room.Playlist.FirstOrDefault()?.Beatmap.BeatmapSet as APIBeatmapSet;
if (room.StartDate.Value != null && room.RoomID != lastDailyChallengeRoomID)
if (room.StartDate != null && room.RoomID != lastDailyChallengeRoomID)
{
lastDailyChallengeRoomID = room.RoomID;
@ -163,7 +163,7 @@ namespace osu.Game.Screens.Menu
statics.SetValue(Static.DailyChallengeIntroPlayed, false);
// we only want to notify the user if the new challenge just went live.
if (Math.Abs((DateTimeOffset.Now - room.StartDate.Value!.Value).TotalSeconds) < 1800)
if (Math.Abs((DateTimeOffset.Now - room.StartDate.Value).TotalSeconds) < 1800)
notificationOverlay?.Post(new NewDailyChallengeNotification(room));
}
@ -179,7 +179,7 @@ namespace osu.Game.Screens.Menu
if (Room == null)
return;
var remaining = (Room.EndDate.Value - DateTimeOffset.Now) ?? TimeSpan.Zero;
var remaining = (Room.EndDate - DateTimeOffset.Now) ?? TimeSpan.Zero;
if (remaining <= TimeSpan.Zero)
{

View File

@ -228,7 +228,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
Origin = Anchor.Centre,
Children = new Drawable[]
{
new DailyChallengeTimeRemainingRing(),
new DailyChallengeTimeRemainingRing(room),
breakdown = new DailyChallengeScoreBreakdown(),
totals = new DailyChallengeTotalsDisplay(),
}
@ -301,7 +301,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
Spacing = new Vector2(10),
Children = new Drawable[]
{
new PlaylistsReadyButton
new PlaylistsReadyButton(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -10,6 +11,7 @@ using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osuTK;
@ -17,8 +19,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{
public partial class DailyChallengeTimeRemainingRing : OnlinePlayComposite
{
private CircularProgress progress = null!;
private OsuSpriteText timeText = null!;
private readonly Room room;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
@ -26,6 +27,14 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
[Resolved]
private OsuColour colours { get; set; } = null!;
private CircularProgress progress = null!;
private OsuSpriteText timeText = null!;
public DailyChallengeTimeRemainingRing(Room room)
{
this.room = room;
}
[BackgroundDependencyLoader]
private void load()
{
@ -90,12 +99,23 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{
base.LoadComplete();
StartDate.BindValueChanged(_ => Scheduler.AddOnce(updateState));
EndDate.BindValueChanged(_ => Scheduler.AddOnce(updateState));
room.PropertyChanged += onRoomPropertyChanged;
updateState();
FinishTransforms(true);
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(Room.StartDate):
case nameof(Room.EndDate):
Scheduler.AddOnce(updateState);
break;
}
}
private ScheduledDelegate? scheduledUpdate;
private void updateState()
@ -105,7 +125,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
const float transition_duration = 300;
if (StartDate.Value == null || EndDate.Value == null || EndDate.Value < DateTimeOffset.Now)
if (room.StartDate == null || room.EndDate == null || room.EndDate < DateTimeOffset.Now)
{
timeText.Text = TimeSpan.Zero.ToString(@"hh\:mm\:ss");
progress.Progress = 0;
@ -114,8 +134,8 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
return;
}
var roomDuration = EndDate.Value.Value - StartDate.Value.Value;
var remaining = EndDate.Value.Value - DateTimeOffset.Now;
var roomDuration = room.EndDate.Value - room.StartDate.Value;
var remaining = room.EndDate.Value - DateTimeOffset.Now;
timeText.Text = remaining.ToString(@"hh\:mm\:ss");
progress.Progress = remaining.TotalSeconds / roomDuration.TotalSeconds;
@ -138,5 +158,11 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
scheduledUpdate = Scheduler.AddDelayed(updateState, 1000);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
}
}

View File

@ -169,7 +169,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft
},
endDateInfo = new EndDateInfo
endDateInfo = new EndDateInfo(Room)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,

View File

@ -2,49 +2,68 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public partial class EndDateInfo : OnlinePlayComposite
{
public EndDateInfo()
private readonly Room room;
public EndDateInfo(Room room)
{
this.room = room;
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new EndDatePart
InternalChild = new EndDatePart(room)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12),
EndDate = { BindTarget = EndDate }
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12)
};
}
private partial class EndDatePart : DrawableDate
{
public readonly IBindable<DateTimeOffset?> EndDate = new Bindable<DateTimeOffset?>();
private readonly Room room;
public EndDatePart()
public EndDatePart(Room room)
: base(DateTimeOffset.UtcNow)
{
EndDate.BindValueChanged(date =>
{
// If null, set a very large future date to prevent unnecessary schedules.
Date = date.NewValue ?? DateTimeOffset.Now.AddYears(1);
}, true);
this.room = room;
}
protected override void LoadComplete()
{
base.LoadComplete();
room.PropertyChanged += onRoomPropertyChanged;
updateEndDate();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.EndDate))
updateEndDate();
}
private void updateEndDate()
{
// If null, set a very large future date to prevent unnecessary schedules.
Date = room.EndDate ?? DateTimeOffset.Now.AddYears(1);
}
protected override string Format()
{
if (EndDate.Value == null)
if (room.EndDate == null)
return string.Empty;
var diffToNow = Date.Subtract(DateTimeOffset.Now);
@ -60,6 +79,12 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
return $"Closing {base.Format()}";
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
}
}
}

View File

@ -34,7 +34,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
TextFlow.Colour = Colour4.Black;
Pill.Background.Alpha = 1;
EndDate.BindValueChanged(_ => updateDisplay());
room.PropertyChanged += onRoomPropertyChanged;
updateDisplay();
@ -43,8 +42,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.Status))
updateDisplay();
switch (e.PropertyName)
{
case nameof(Room.Status):
case nameof(Room.EndDate):
updateDisplay();
break;
}
}
private void updateDisplay()

View File

@ -341,8 +341,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
r.RoomID = null;
// Null out dates because end date is not supported client-side and the settings overlay will populate a duration.
r.EndDate.Value = null;
r.Duration.Value = null;
r.EndDate = null;
r.Duration = null;
Open(r);

View File

@ -1,7 +1,6 @@
// 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;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
@ -32,14 +31,5 @@ namespace osu.Game.Screens.OnlinePlay
[Resolved(typeof(Room))]
public Bindable<PlaylistAggregateScore> UserScore { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<DateTimeOffset?> StartDate { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<DateTimeOffset?> EndDate { get; private set; } = null!;
[Resolved(typeof(Room))]
protected Bindable<TimeSpan?> Duration { get; private set; } = null!;
}
}

View File

@ -1,8 +1,6 @@
// 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;
using System.Linq;
using osu.Framework.Allocation;
@ -17,20 +15,20 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{
public partial class PlaylistsReadyButton : ReadyButton
{
[Resolved(typeof(Room), nameof(Room.EndDate))]
private Bindable<DateTimeOffset?> endDate { get; set; }
[Resolved(typeof(Room), nameof(Room.MaxAttempts))]
private Bindable<int?> maxAttempts { get; set; }
private Bindable<int?> maxAttempts { get; set; } = null!;
[Resolved(typeof(Room), nameof(Room.UserScore))]
private Bindable<PlaylistAggregateScore> userScore { get; set; }
private Bindable<PlaylistAggregateScore> userScore { get; set; } = null!;
[Resolved]
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
private IBindable<WorkingBeatmap> gameBeatmap { get; set; } = null!;
public PlaylistsReadyButton()
private readonly Room room;
public PlaylistsReadyButton(Room room)
{
this.room = room;
Text = "Start";
}
@ -80,6 +78,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
private bool enoughTimeLeft =>
// This should probably consider the length of the currently selected item, rather than a constant 30 seconds.
endDate.Value != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < endDate.Value;
room.EndDate != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < room.EndDate;
}
}

View File

@ -1,26 +1,25 @@
// 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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.Rooms;
using osuTK;
namespace osu.Game.Screens.OnlinePlay.Playlists
{
public partial class PlaylistsRoomFooter : CompositeDrawable
{
public Action OnStart;
public Action? OnStart;
public PlaylistsRoomFooter()
public PlaylistsRoomFooter(Room room)
{
RelativeSizeAxes = Axes.Both;
InternalChildren = new[]
{
new PlaylistsReadyButton
new PlaylistsReadyButton(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -317,7 +317,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
};
MaxAttempts.BindValueChanged(count => MaxAttemptsField.Text = count.NewValue?.ToString(), true);
Duration.BindValueChanged(duration => DurationField.Current.Value = duration.NewValue ?? TimeSpan.FromMinutes(30), true);
DurationField.Current.BindValueChanged(duration =>
{
@ -346,6 +345,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
updateRoomName();
updateRoomAvailability();
updateRoomMaxParticipants();
updateRoomDuration();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
@ -363,6 +363,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
case nameof(Room.MaxParticipants):
updateRoomMaxParticipants();
break;
case nameof(Room.Duration):
updateRoomDuration();
break;
}
}
@ -375,6 +379,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
private void updateRoomMaxParticipants()
=> MaxParticipantsField.Text = room.MaxParticipants?.ToString();
private void updateRoomDuration()
=> DurationField.Current.Value = room.Duration ?? TimeSpan.FromMinutes(30);
private void populateDurations(ValueChangedEvent<APIUser> user)
{
// roughly correct (see https://github.com/Humanizr/Humanizer/blob/18167e56c082449cc4fe805b8429e3127a7b7f93/readme.md?plain=1#L427)
@ -431,7 +438,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
else
MaxAttempts.Value = null;
Duration.Value = DurationField.Current.Value;
room.Duration = DurationField.Current.Value;
loadingLayer.Show();
manager?.CreateRoom(room, onSuccess, onError);

View File

@ -234,7 +234,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
}
};
protected override Drawable CreateFooter() => new PlaylistsRoomFooter
protected override Drawable CreateFooter() => new PlaylistsRoomFooter(Room)
{
OnStart = StartPlay
};

View File

@ -34,7 +34,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
RoomID = -currentRoomId,
Name = $@"Room {currentRoomId}",
Host = new APIUser { Username = @"Host" },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
Duration = TimeSpan.FromSeconds(10),
Category = withSpotlightRooms && i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal,
};