mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 11:42:55 +08:00
Send time remaining in countdowns instead
This commit is contained in:
parent
d4ad4ac9db
commit
f7c0047206
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using MessagePack;
|
using MessagePack;
|
||||||
|
using osu.Game.Online.Multiplayer.Countdown;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
{
|
{
|
||||||
@ -16,9 +17,12 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
public abstract class MultiplayerCountdown
|
public abstract class MultiplayerCountdown
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time at which the countdown will end.
|
/// The amount of time remaining in the countdown.
|
||||||
/// </summary>
|
/// </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)]
|
[Key(0)]
|
||||||
public DateTimeOffset EndTime { get; set; }
|
public TimeSpan TimeRemaining { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,16 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
onRoomUpdated();
|
onRoomUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MultiplayerCountdown countdown;
|
||||||
|
private DateTimeOffset countdownReceivedTime;
|
||||||
private ScheduledDelegate countdownUpdateDelegate;
|
private ScheduledDelegate countdownUpdateDelegate;
|
||||||
|
|
||||||
private void onRoomUpdated()
|
private void onRoomUpdated()
|
||||||
{
|
{
|
||||||
updateButtonText();
|
if (countdown == null && room?.Countdown != null)
|
||||||
updateButtonColour();
|
countdownReceivedTime = DateTimeOffset.Now;
|
||||||
|
|
||||||
|
countdown = room?.Countdown;
|
||||||
|
|
||||||
if (room?.Countdown != null)
|
if (room?.Countdown != null)
|
||||||
countdownUpdateDelegate ??= Scheduler.AddDelayed(updateButtonText, 1000, true);
|
countdownUpdateDelegate ??= Scheduler.AddDelayed(updateButtonText, 1000, true);
|
||||||
@ -48,6 +52,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
countdownUpdateDelegate?.Cancel();
|
countdownUpdateDelegate?.Cancel();
|
||||||
countdownUpdateDelegate = null;
|
countdownUpdateDelegate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateButtonText();
|
||||||
|
updateButtonColour();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateButtonText()
|
private void updateButtonText()
|
||||||
@ -64,9 +71,17 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
int countTotal = room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
int countTotal = room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
||||||
string countText = $"({countReady} / {countTotal} ready)";
|
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)
|
switch (localUser?.State)
|
||||||
{
|
{
|
||||||
|
@ -315,7 +315,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
var stopSource = countdownStopSource = new CancellationTokenSource();
|
var stopSource = countdownStopSource = new CancellationTokenSource();
|
||||||
var finishSource = countdownFinishSource = new CancellationTokenSource();
|
var finishSource = countdownFinishSource = new CancellationTokenSource();
|
||||||
var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(stopSource.Token, finishSource.Token);
|
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;
|
Task lastCountdownTask = countdownTask;
|
||||||
countdownTask = start();
|
countdownTask = start();
|
||||||
|
Loading…
Reference in New Issue
Block a user