Use IGameTiming for lobby timing instead of DateTime.

Fixes #1681
This commit is contained in:
Pieter-Jan Briers
2021-01-11 09:03:58 +01:00
parent b36d22128a
commit 374b100a5e
5 changed files with 31 additions and 29 deletions

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using Content.Client.Interfaces;
using Content.Client.State;
using Content.Client.UserInterface;
using Content.Shared;
using Content.Shared.GameTicking;
using Content.Shared.Network.NetMessages;
using Robust.Client.Interfaces.Graphics;
@@ -11,6 +10,7 @@ using Robust.Client.Interfaces.State;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Network;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
@@ -28,7 +28,7 @@ namespace Content.Client.GameTicking
[ViewVariables] public bool IsGameStarted { get; private set; }
[ViewVariables] public bool DisallowedLateJoin { get; private set; }
[ViewVariables] public string ServerInfoBlob { get; private set; }
[ViewVariables] public DateTime StartTime { get; private set; }
[ViewVariables] public TimeSpan StartTime { get; private set; }
[ViewVariables] public bool Paused { get; private set; }
[ViewVariables] public Dictionary<NetUserId, PlayerStatus> Status { get; private set; }
[ViewVariables] public IReadOnlyList<string> JobsAvailable => _jobsAvailable;

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Robust.Shared.Network;
using Robust.Shared.Timing;
using static Content.Shared.GameTicking.SharedGameTicker;
namespace Content.Client.Interfaces
@@ -11,7 +12,7 @@ namespace Content.Client.Interfaces
string ServerInfoBlob { get; }
bool AreWeReady { get; }
bool DisallowedLateJoin { get; }
DateTime StartTime { get; }
TimeSpan StartTime { get; }
bool Paused { get; }
Dictionary<NetUserId, PlayerStatus> Status { get; }
IReadOnlyList<string> JobsAvailable { get; }

View File

@@ -13,6 +13,7 @@ using Robust.Client.Player;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input.Binding;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
@@ -35,6 +36,7 @@ namespace Content.Client.State
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IClientPreferencesManager _preferencesManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[ViewVariables] private CharacterSetupGui _characterSetup;
[ViewVariables] private LobbyGui _lobby;
@@ -144,10 +146,11 @@ namespace Content.Client.State
}
else
{
var difference = _clientGameTicker.StartTime - DateTime.UtcNow;
if (difference.Ticks < 0)
var difference = _clientGameTicker.StartTime - _gameTiming.CurTime;
var seconds = difference.TotalSeconds;
if (seconds < 0)
{
if (difference.TotalSeconds < -5)
if (seconds < -5)
{
text = Loc.GetString("Right Now?");
}
@@ -158,7 +161,7 @@ namespace Content.Client.State
}
else
{
text = $"{(int) Math.Floor(difference.TotalMinutes)}:{difference.Seconds:D2}";
text = $"{(int) Math.Floor(difference.TotalMinutes / 60)}:{difference.Seconds:D2}";
}
}
@@ -178,8 +181,10 @@ namespace Content.Client.State
_clientGameTicker.Status.Remove(p.Key);
}
}
UpdatePlayerList();
}
private void LobbyReadyUpdated() => UpdatePlayerList();
private void LobbyStatusUpdated()
@@ -224,8 +229,6 @@ namespace Content.Client.State
foreach (var session in _playerManager.Sessions.OrderBy(s => s.Name))
{
var readyState = "";
// Don't show ready state if we're ingame
if (!_clientGameTicker.IsGameStarted)
@@ -244,6 +247,7 @@ namespace Content.Client.State
_ => "",
};
}
_lobby.OnlinePlayerList.AddItem(session.Name, readyState);
}
}