2021-04-20 18:39:39 -05:00
|
|
|
using System;
|
2020-09-13 14:23:52 +02:00
|
|
|
using System.Linq;
|
2021-07-20 10:29:09 +02:00
|
|
|
using Content.Client.Chat;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Chat.Managers;
|
|
|
|
|
using Content.Client.EscapeMenu.UI;
|
|
|
|
|
using Content.Client.GameTicking.Managers;
|
|
|
|
|
using Content.Client.LateJoin;
|
|
|
|
|
using Content.Client.Lobby.UI;
|
|
|
|
|
using Content.Client.Preferences;
|
|
|
|
|
using Content.Client.Preferences.UI;
|
2021-02-16 15:07:17 +01:00
|
|
|
using Content.Client.Voting;
|
2021-06-20 10:09:24 +02:00
|
|
|
using Content.Shared.GameTicking;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client;
|
2020-02-26 16:42:12 +01:00
|
|
|
using Robust.Client.Console;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Input;
|
2020-02-26 16:42:12 +01:00
|
|
|
using Robust.Client.Player;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.ResourceManagement;
|
|
|
|
|
using Robust.Client.UserInterface;
|
2020-02-26 16:42:12 +01:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-02-26 16:42:12 +01:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Lobby
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class LobbyState : Robust.Client.State.State
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IBaseClient _baseClient = default!;
|
2021-02-01 16:49:43 -08:00
|
|
|
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
|
|
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
|
|
|
|
[Dependency] private readonly IClientPreferencesManager _preferencesManager = default!;
|
2021-01-11 09:03:58 +01:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2021-02-16 15:07:17 +01:00
|
|
|
[Dependency] private readonly IVoteManager _voteManager = default!;
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2021-09-02 09:39:19 +10:00
|
|
|
[ViewVariables] private CharacterSetupGui? _characterSetup;
|
|
|
|
|
[ViewVariables] private LobbyGui? _lobby;
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2021-10-13 20:43:40 +02:00
|
|
|
private ClientGameTicker _gameTicker = default!;
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
public override void Startup()
|
|
|
|
|
{
|
2021-10-13 20:43:40 +02:00
|
|
|
_gameTicker = EntitySystem.Get<ClientGameTicker>();
|
2020-02-26 16:42:12 +01:00
|
|
|
_characterSetup = new CharacterSetupGui(_entityManager, _resourceCache, _preferencesManager,
|
|
|
|
|
_prototypeManager);
|
|
|
|
|
LayoutContainer.SetAnchorPreset(_characterSetup, LayoutContainer.LayoutPreset.Wide);
|
2020-12-02 08:45:07 +00:00
|
|
|
|
2021-09-02 09:39:19 +10:00
|
|
|
_lobby = new LobbyGui(_entityManager, _preferencesManager);
|
|
|
|
|
_userInterfaceManager.StateRoot.AddChild(_lobby);
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_characterSetup.CloseButton.OnPressed += _ =>
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
|
|
|
|
_userInterfaceManager.StateRoot.AddChild(_lobby);
|
|
|
|
|
_userInterfaceManager.StateRoot.RemoveChild(_characterSetup);
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_characterSetup.SaveButton.OnPressed += _ =>
|
2020-12-02 08:45:07 +00:00
|
|
|
{
|
|
|
|
|
_characterSetup.Save();
|
2021-03-10 14:48:29 +01:00
|
|
|
_lobby?.CharacterPreview.UpdateUI();
|
2020-12-02 08:45:07 +00:00
|
|
|
};
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
LayoutContainer.SetAnchorPreset(_lobby, LayoutContainer.LayoutPreset.Wide);
|
|
|
|
|
|
|
|
|
|
_chatManager.SetChatBox(_lobby.Chat);
|
2021-02-16 15:07:17 +01:00
|
|
|
_voteManager.SetPopupContainer(_lobby.VoteContainer);
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_lobby.ServerName.Text = _baseClient.GameInfo?.ServerName;
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2021-07-20 10:29:09 +02:00
|
|
|
ChatInput.SetupChatInputHandlers(_inputManager, _lobby.Chat);
|
2021-01-06 03:05:06 +01:00
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
UpdateLobbyUi();
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_lobby.CharacterPreview.CharacterSetupButton.OnPressed += _ =>
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
|
|
|
|
SetReady(false);
|
|
|
|
|
_userInterfaceManager.StateRoot.RemoveChild(_lobby);
|
|
|
|
|
_userInterfaceManager.StateRoot.AddChild(_characterSetup);
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_lobby.ReadyButton.OnPressed += _ =>
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2021-10-13 20:43:40 +02:00
|
|
|
if (!_gameTicker.IsGameStarted)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 08:27:55 -05:00
|
|
|
new LateJoinGui().OpenCentered();
|
2020-02-26 16:42:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_lobby.ReadyButton.OnToggled += args =>
|
|
|
|
|
{
|
|
|
|
|
SetReady(args.Pressed);
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_lobby.LeaveButton.OnPressed += _ => _consoleHost.ExecuteCommand("disconnect");
|
|
|
|
|
_lobby.OptionsButton.OnPressed += _ => new OptionsMenu().Open();
|
2020-02-26 16:42:12 +01:00
|
|
|
|
|
|
|
|
UpdatePlayerList();
|
|
|
|
|
|
|
|
|
|
_playerManager.PlayerListUpdated += PlayerManagerOnPlayerListUpdated;
|
2021-10-13 20:43:40 +02:00
|
|
|
_gameTicker.InfoBlobUpdated += UpdateLobbyUi;
|
|
|
|
|
_gameTicker.LobbyStatusUpdated += LobbyStatusUpdated;
|
|
|
|
|
_gameTicker.LobbyReadyUpdated += LobbyReadyUpdated;
|
|
|
|
|
_gameTicker.LobbyLateJoinStatusUpdated += LobbyLateJoinStatusUpdated;
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
_playerManager.PlayerListUpdated -= PlayerManagerOnPlayerListUpdated;
|
2021-10-13 20:43:40 +02:00
|
|
|
_gameTicker.InfoBlobUpdated -= UpdateLobbyUi;
|
|
|
|
|
_gameTicker.LobbyStatusUpdated -= LobbyStatusUpdated;
|
|
|
|
|
_gameTicker.LobbyReadyUpdated -= LobbyReadyUpdated;
|
|
|
|
|
_gameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated;
|
2021-09-02 09:39:19 +10:00
|
|
|
|
|
|
|
|
_lobby?.Dispose();
|
|
|
|
|
_characterSetup?.Dispose();
|
|
|
|
|
_lobby = null;
|
|
|
|
|
_characterSetup = null;
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void FrameUpdate(FrameEventArgs e)
|
|
|
|
|
{
|
2021-09-02 09:39:19 +10:00
|
|
|
if (_lobby == null) return;
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
|
|
|
|
if (gameTicker.IsGameStarted)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
_lobby.StartTime.Text = string.Empty;
|
2020-02-26 16:42:12 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string text;
|
2020-06-21 22:05:47 +02:00
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
if (gameTicker.Paused)
|
2020-06-21 22:05:47 +02:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
text = Loc.GetString("lobby-state-paused");
|
2020-06-21 22:05:47 +02:00
|
|
|
}
|
|
|
|
|
else
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2021-06-20 10:09:24 +02:00
|
|
|
var difference = gameTicker.StartTime - _gameTiming.CurTime;
|
2021-01-11 09:03:58 +01:00
|
|
|
var seconds = difference.TotalSeconds;
|
|
|
|
|
if (seconds < 0)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
text = Loc.GetString(seconds < -5 ? "lobby-state-right-now-question" : "lobby-state-right-now-confirmation");
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-11-25 13:30:36 -06:00
|
|
|
text = $"{difference.Minutes}:{difference.Seconds:D2}";
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
_lobby.StartTime.Text = Loc.GetString("lobby-state-round-start-countdown-text", ("timeLeft", text));
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private void PlayerManagerOnPlayerListUpdated(object? sender, EventArgs e)
|
2020-08-18 14:52:59 +02:00
|
|
|
{
|
2021-06-20 10:09:24 +02:00
|
|
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
2020-08-18 14:52:59 +02:00
|
|
|
// Remove disconnected sessions from the Ready Dict
|
2021-06-20 10:09:24 +02:00
|
|
|
foreach (var p in gameTicker.Status)
|
2020-08-18 14:52:59 +02:00
|
|
|
{
|
|
|
|
|
if (!_playerManager.SessionsDict.TryGetValue(p.Key, out _))
|
|
|
|
|
{
|
2020-08-21 11:24:06 +02:00
|
|
|
// This is a shitty fix. Observers can rejoin because they are already in the game.
|
|
|
|
|
// So we don't delete them, but keep them if they decide to rejoin
|
2021-06-20 10:09:24 +02:00
|
|
|
if (p.Value != LobbyPlayerStatus.Observer)
|
|
|
|
|
gameTicker.Status.Remove(p.Key);
|
2020-08-18 14:52:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-11 09:03:58 +01:00
|
|
|
|
2020-08-18 14:52:59 +02:00
|
|
|
UpdatePlayerList();
|
|
|
|
|
}
|
2021-01-11 09:03:58 +01:00
|
|
|
|
2020-08-18 14:52:59 +02:00
|
|
|
private void LobbyReadyUpdated() => UpdatePlayerList();
|
|
|
|
|
|
|
|
|
|
private void LobbyStatusUpdated()
|
|
|
|
|
{
|
|
|
|
|
UpdatePlayerList();
|
|
|
|
|
UpdateLobbyUi();
|
|
|
|
|
}
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2020-08-20 16:20:48 +02:00
|
|
|
private void LobbyLateJoinStatusUpdated()
|
|
|
|
|
{
|
2021-09-02 09:39:19 +10:00
|
|
|
if (_lobby == null) return;
|
2021-06-20 10:09:24 +02:00
|
|
|
_lobby.ReadyButton.Disabled = EntitySystem.Get<ClientGameTicker>().DisallowedLateJoin;
|
2020-08-20 16:20:48 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
private void UpdateLobbyUi()
|
|
|
|
|
{
|
2021-09-02 09:39:19 +10:00
|
|
|
if (_lobby == null) return;
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
|
|
|
|
|
|
|
|
|
if (gameTicker.IsGameStarted)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
_lobby.ReadyButton.Text = Loc.GetString("lobby-state-ready-button-join-state");
|
2020-02-26 16:42:12 +01:00
|
|
|
_lobby.ReadyButton.ToggleMode = false;
|
|
|
|
|
_lobby.ReadyButton.Pressed = false;
|
2021-12-21 21:23:29 +01:00
|
|
|
_lobby.ObserveButton.Disabled = false;
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
_lobby.StartTime.Text = string.Empty;
|
|
|
|
|
_lobby.ReadyButton.Text = Loc.GetString("lobby-state-ready-button-ready-up-state");
|
2020-02-26 16:42:12 +01:00
|
|
|
_lobby.ReadyButton.ToggleMode = true;
|
2020-08-20 16:20:48 +02:00
|
|
|
_lobby.ReadyButton.Disabled = false;
|
2021-06-20 10:09:24 +02:00
|
|
|
_lobby.ReadyButton.Pressed = gameTicker.AreWeReady;
|
2021-12-21 21:23:29 +01:00
|
|
|
_lobby.ObserveButton.Disabled = true;
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
if (gameTicker.ServerInfoBlob != null)
|
2021-03-10 14:48:29 +01:00
|
|
|
{
|
2021-06-20 10:09:24 +02:00
|
|
|
_lobby.ServerInfo.SetInfoBlob(gameTicker.ServerInfoBlob);
|
2021-03-10 14:48:29 +01:00
|
|
|
}
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePlayerList()
|
|
|
|
|
{
|
2021-09-02 09:39:19 +10:00
|
|
|
if (_lobby == null) return;
|
2020-08-24 12:11:53 +02:00
|
|
|
_lobby.OnlinePlayerList.Clear();
|
2021-06-20 10:09:24 +02:00
|
|
|
var gameTicker = EntitySystem.Get<ClientGameTicker>();
|
2020-02-26 16:42:12 +01:00
|
|
|
|
|
|
|
|
foreach (var session in _playerManager.Sessions.OrderBy(s => s.Name))
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
var readyState = string.Empty;
|
2020-08-18 14:52:59 +02:00
|
|
|
// Don't show ready state if we're ingame
|
2021-06-20 10:09:24 +02:00
|
|
|
if (!gameTicker.IsGameStarted)
|
2020-08-18 14:52:59 +02:00
|
|
|
{
|
2021-06-20 10:09:24 +02:00
|
|
|
LobbyPlayerStatus status;
|
2021-03-10 14:48:29 +01:00
|
|
|
if (session.UserId == _playerManager.LocalPlayer?.UserId)
|
2021-06-20 10:09:24 +02:00
|
|
|
status = gameTicker.AreWeReady ? LobbyPlayerStatus.Ready : LobbyPlayerStatus.NotReady;
|
2020-08-18 14:52:59 +02:00
|
|
|
else
|
2021-06-20 10:09:24 +02:00
|
|
|
gameTicker.Status.TryGetValue(session.UserId, out status);
|
2020-08-21 11:24:06 +02:00
|
|
|
|
|
|
|
|
readyState = status switch
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
LobbyPlayerStatus.NotReady => Loc.GetString("lobby-state-player-status-not-ready"),
|
|
|
|
|
LobbyPlayerStatus.Ready => Loc.GetString("lobby-state-player-status-ready"),
|
|
|
|
|
LobbyPlayerStatus.Observer => Loc.GetString("lobby-state-player-status-observer"),
|
|
|
|
|
_ => string.Empty,
|
2020-08-21 11:24:06 +02:00
|
|
|
};
|
2020-08-18 14:52:59 +02:00
|
|
|
}
|
2021-01-11 09:03:58 +01:00
|
|
|
|
2020-08-24 12:11:53 +02:00
|
|
|
_lobby.OnlinePlayerList.AddItem(session.Name, readyState);
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetReady(bool newReady)
|
|
|
|
|
{
|
2021-06-20 10:09:24 +02:00
|
|
|
if (EntitySystem.Get<ClientGameTicker>().IsGameStarted)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand($"toggleready {newReady}");
|
2020-08-18 14:52:59 +02:00
|
|
|
UpdatePlayerList();
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|