1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 21:42:56 +08:00

Send time remaining in countdowns instead

This commit is contained in:
Dan Balasescu 2022-03-23 15:19:43 +09:00
parent d4ad4ac9db
commit f7c0047206
3 changed files with 26 additions and 7 deletions

View File

@ -5,6 +5,7 @@
using System;
using MessagePack;
using osu.Game.Online.Multiplayer.Countdown;
namespace osu.Game.Online.Multiplayer
{
@ -16,9 +17,12 @@ namespace osu.Game.Online.Multiplayer
public abstract class MultiplayerCountdown
{
/// <summary>
/// The time at which the countdown will end.
/// The amount of time remaining in the countdown.
/// </summary>
/// <remarks>
/// This is only sent once from the server upon initial retrieval of the <see cref="MultiplayerRoom"/> or via a <see cref="CountdownChangedEvent"/>.
/// </remarks>
[Key(0)]
public DateTimeOffset EndTime { get; set; }
public TimeSpan TimeRemaining { get; set; }
}
}

View File

@ -34,12 +34,16 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
onRoomUpdated();
}
private MultiplayerCountdown countdown;
private DateTimeOffset countdownReceivedTime;
private ScheduledDelegate countdownUpdateDelegate;
private void onRoomUpdated()
{
updateButtonText();
updateButtonColour();
if (countdown == null && room?.Countdown != null)
countdownReceivedTime = DateTimeOffset.Now;
countdown = room?.Countdown;
if (room?.Countdown != null)
countdownUpdateDelegate ??= Scheduler.AddDelayed(updateButtonText, 1000, true);
@ -48,6 +52,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
countdownUpdateDelegate?.Cancel();
countdownUpdateDelegate = null;
}
updateButtonText();
updateButtonColour();
}
private void updateButtonText()
@ -64,9 +71,17 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
int countTotal = room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
string countText = $"({countReady} / {countTotal} ready)";
if (room.Countdown != null)
if (countdown != null)
{
string countdownText = $"Starting in {room.Countdown.EndTime - DateTimeOffset.Now:mm\\:ss}";
TimeSpan timeElapsed = DateTimeOffset.Now - countdownReceivedTime;
TimeSpan countdownRemaining;
if (timeElapsed > countdown.TimeRemaining)
countdownRemaining = TimeSpan.Zero;
else
countdownRemaining = countdown.TimeRemaining - timeElapsed;
string countdownText = $"Starting in {countdownRemaining:mm\\:ss}";
switch (localUser?.State)
{

View File

@ -315,7 +315,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
var stopSource = countdownStopSource = new CancellationTokenSource();
var finishSource = countdownFinishSource = new CancellationTokenSource();
var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(stopSource.Token, finishSource.Token);
var countdown = new MatchStartCountdown { EndTime = DateTimeOffset.Now + matchCountdownRequest.Delay };
var countdown = new MatchStartCountdown { TimeRemaining = matchCountdownRequest.Delay };
Task lastCountdownTask = countdownTask;
countdownTask = start();