2024-03-02 23:40:04 +03:00
|
|
|
using Content.Client.Audio;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.GameTicking.Managers;
|
|
|
|
|
using Content.Client.LateJoin;
|
|
|
|
|
using Content.Client.Lobby.UI;
|
2023-08-02 05:36:27 -04:00
|
|
|
using Content.Client.Message;
|
2022-10-17 15:13:41 -07:00
|
|
|
using Content.Client.UserInterface.Systems.Chat;
|
2021-02-16 15:07:17 +01:00
|
|
|
using Content.Client.Voting;
|
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.ResourceManagement;
|
|
|
|
|
using Robust.Client.UserInterface;
|
2020-02-26 16:42:12 +01:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
using Robust.Shared.Timing;
|
2022-10-12 01:16:23 -07:00
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
|
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 IEntityManager _entityManager = default!;
|
2023-10-29 15:29:30 +11:00
|
|
|
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = 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-10-13 20:43:40 +02:00
|
|
|
private ClientGameTicker _gameTicker = default!;
|
2024-03-02 23:40:04 +03:00
|
|
|
private ContentAudioSystem _contentAudioSystem = default!;
|
2021-10-13 20:43:40 +02:00
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
protected override Type? LinkedScreenType { get; } = typeof(LobbyGui);
|
2024-05-12 09:18:21 +10:00
|
|
|
public LobbyGui? Lobby;
|
2022-10-17 15:13:41 -07:00
|
|
|
|
2022-09-04 16:17:05 -07:00
|
|
|
protected override void Startup()
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2022-10-17 23:45:32 -07:00
|
|
|
if (_userInterfaceManager.ActiveScreen == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby = (LobbyGui) _userInterfaceManager.ActiveScreen;
|
2022-10-17 23:45:32 -07:00
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
var chatController = _userInterfaceManager.GetUIController<ChatUIController>();
|
2022-10-17 02:44:23 +11:00
|
|
|
_gameTicker = _entityManager.System<ClientGameTicker>();
|
2024-03-02 23:40:04 +03:00
|
|
|
_contentAudioSystem = _entityManager.System<ContentAudioSystem>();
|
|
|
|
|
_contentAudioSystem.LobbySoundtrackChanged += UpdateLobbySoundtrackInfo;
|
2020-12-02 08:45:07 +00:00
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
chatController.SetMainChat(true);
|
2021-09-02 09:39:19 +10:00
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
_voteManager.SetPopupContainer(Lobby.VoteContainer);
|
|
|
|
|
LayoutContainer.SetAnchorPreset(Lobby, LayoutContainer.LayoutPreset.Wide);
|
|
|
|
|
Lobby.ServerName.Text = _baseClient.GameInfo?.ServerName; //The eye of refactor gazes upon you...
|
2020-02-26 16:42:12 +01:00
|
|
|
UpdateLobbyUi();
|
|
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby.CharacterPreview.CharacterSetupButton.OnPressed += OnSetupPressed;
|
|
|
|
|
Lobby.ReadyButton.OnPressed += OnReadyPressed;
|
|
|
|
|
Lobby.ReadyButton.OnToggled += OnReadyToggled;
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2021-10-13 20:43:40 +02:00
|
|
|
_gameTicker.InfoBlobUpdated += UpdateLobbyUi;
|
|
|
|
|
_gameTicker.LobbyStatusUpdated += LobbyStatusUpdated;
|
|
|
|
|
_gameTicker.LobbyLateJoinStatusUpdated += LobbyLateJoinStatusUpdated;
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 16:17:05 -07:00
|
|
|
protected override void Shutdown()
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2022-10-17 15:13:41 -07:00
|
|
|
var chatController = _userInterfaceManager.GetUIController<ChatUIController>();
|
|
|
|
|
chatController.SetMainChat(false);
|
2021-10-13 20:43:40 +02:00
|
|
|
_gameTicker.InfoBlobUpdated -= UpdateLobbyUi;
|
|
|
|
|
_gameTicker.LobbyStatusUpdated -= LobbyStatusUpdated;
|
|
|
|
|
_gameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated;
|
2024-03-02 23:40:04 +03:00
|
|
|
_contentAudioSystem.LobbySoundtrackChanged -= UpdateLobbySoundtrackInfo;
|
2021-09-02 09:39:19 +10:00
|
|
|
|
2023-04-12 17:39:43 +10:00
|
|
|
_voteManager.ClearPopupContainer();
|
2023-04-02 01:00:48 +11:00
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.CharacterPreview.CharacterSetupButton.OnPressed -= OnSetupPressed;
|
|
|
|
|
Lobby!.ReadyButton.OnPressed -= OnReadyPressed;
|
|
|
|
|
Lobby!.ReadyButton.OnToggled -= OnReadyToggled;
|
2022-10-17 23:45:32 -07:00
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby = null;
|
|
|
|
|
}
|
2022-10-17 23:45:32 -07:00
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
public void SwitchState(LobbyGui.LobbyGuiState state)
|
|
|
|
|
{
|
|
|
|
|
// Yeah I hate this but LobbyState contains all the badness for now.
|
|
|
|
|
Lobby?.SwitchState(state);
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-10-17 23:45:32 -07:00
|
|
|
private void OnSetupPressed(BaseButton.ButtonEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
SetReady(false);
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby?.SwitchState(LobbyGui.LobbyGuiState.CharacterSetup);
|
2022-10-17 23:45:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnReadyPressed(BaseButton.ButtonEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!_gameTicker.IsGameStarted)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new LateJoinGui().OpenCentered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnReadyToggled(BaseButton.ButtonToggledEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
SetReady(args.Pressed);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
public override void FrameUpdate(FrameEventArgs e)
|
|
|
|
|
{
|
2022-10-17 02:44:23 +11:00
|
|
|
if (_gameTicker.IsGameStarted)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.StartTime.Text = string.Empty;
|
2022-10-22 14:52:34 -07:00
|
|
|
var roundTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan);
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.StationTime.Text = Loc.GetString("lobby-state-player-status-round-time", ("hours", roundTime.Hours), ("minutes", roundTime.Minutes));
|
2020-02-26 16:42:12 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.StationTime.Text = Loc.GetString("lobby-state-player-status-round-not-started");
|
2020-02-26 16:42:12 +01:00
|
|
|
string text;
|
2020-06-21 22:05:47 +02:00
|
|
|
|
2022-10-17 02:44:23 +11: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
|
|
|
}
|
2023-04-23 13:14:25 +10:00
|
|
|
else if (_gameTicker.StartTime < _gameTiming.CurTime)
|
2023-03-22 20:29:55 +11:00
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.StartTime.Text = Loc.GetString("lobby-state-soon");
|
2023-04-23 13:14:25 +10:00
|
|
|
return;
|
2023-03-22 20:29:55 +11:00
|
|
|
}
|
2020-06-21 22:05:47 +02:00
|
|
|
else
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2022-10-17 02:44:23 +11: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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.StartTime.Text = Loc.GetString("lobby-state-round-start-countdown-text", ("timeLeft", text));
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-18 14:52:59 +02:00
|
|
|
private void LobbyStatusUpdated()
|
|
|
|
|
{
|
2022-03-13 19:33:19 -07:00
|
|
|
UpdateLobbyBackground();
|
2020-08-18 14:52:59 +02:00
|
|
|
UpdateLobbyUi();
|
|
|
|
|
}
|
2020-02-26 16:42:12 +01:00
|
|
|
|
2020-08-20 16:20:48 +02:00
|
|
|
private void LobbyLateJoinStatusUpdated()
|
|
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.ReadyButton.Disabled = _gameTicker.DisallowedLateJoin;
|
2020-08-20 16:20:48 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
private void UpdateLobbyUi()
|
|
|
|
|
{
|
2022-10-17 02:44:23 +11:00
|
|
|
if (_gameTicker.IsGameStarted)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.ReadyButton.Text = Loc.GetString("lobby-state-ready-button-join-state");
|
|
|
|
|
Lobby!.ReadyButton.ToggleMode = false;
|
|
|
|
|
Lobby!.ReadyButton.Pressed = false;
|
|
|
|
|
Lobby!.ObserveButton.Disabled = false;
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.StartTime.Text = string.Empty;
|
|
|
|
|
Lobby!.ReadyButton.Text = Loc.GetString(Lobby!.ReadyButton.Pressed ? "lobby-state-player-status-ready": "lobby-state-player-status-not-ready");
|
|
|
|
|
Lobby!.ReadyButton.ToggleMode = true;
|
|
|
|
|
Lobby!.ReadyButton.Disabled = false;
|
|
|
|
|
Lobby!.ReadyButton.Pressed = _gameTicker.AreWeReady;
|
|
|
|
|
Lobby!.ObserveButton.Disabled = true;
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-10-17 02:44:23 +11:00
|
|
|
if (_gameTicker.ServerInfoBlob != null)
|
2021-03-10 14:48:29 +01:00
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.ServerInfo.SetInfoBlob(_gameTicker.ServerInfoBlob);
|
2021-03-10 14:48:29 +01:00
|
|
|
}
|
2024-03-02 23:40:04 +03:00
|
|
|
}
|
2023-08-02 05:36:27 -04:00
|
|
|
|
2024-03-02 23:40:04 +03:00
|
|
|
private void UpdateLobbySoundtrackInfo(LobbySoundtrackChangedEvent ev)
|
|
|
|
|
{
|
|
|
|
|
if (ev.SoundtrackFilename == null)
|
2023-08-02 05:36:27 -04:00
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.LobbySong.SetMarkup(Loc.GetString("lobby-state-song-no-song-text"));
|
2023-08-02 05:36:27 -04:00
|
|
|
}
|
2024-03-02 23:40:04 +03:00
|
|
|
else if (
|
|
|
|
|
ev.SoundtrackFilename != null
|
|
|
|
|
&& _resourceCache.TryGetResource<AudioResource>(ev.SoundtrackFilename, out var lobbySongResource)
|
|
|
|
|
)
|
2023-08-02 05:36:27 -04:00
|
|
|
{
|
|
|
|
|
var lobbyStream = lobbySongResource.AudioStream;
|
|
|
|
|
|
2024-03-02 23:40:04 +03:00
|
|
|
var title = string.IsNullOrEmpty(lobbyStream.Title)
|
|
|
|
|
? Loc.GetString("lobby-state-song-unknown-title")
|
|
|
|
|
: lobbyStream.Title;
|
2023-08-02 05:36:27 -04:00
|
|
|
|
2024-03-02 23:40:04 +03:00
|
|
|
var artist = string.IsNullOrEmpty(lobbyStream.Artist)
|
|
|
|
|
? Loc.GetString("lobby-state-song-unknown-artist")
|
|
|
|
|
: lobbyStream.Artist;
|
2023-08-02 05:36:27 -04:00
|
|
|
|
|
|
|
|
var markup = Loc.GetString("lobby-state-song-text",
|
|
|
|
|
("songTitle", title),
|
|
|
|
|
("songArtist", artist));
|
|
|
|
|
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.LobbySong.SetMarkup(markup);
|
2023-08-02 05:36:27 -04:00
|
|
|
}
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-13 19:33:19 -07:00
|
|
|
private void UpdateLobbyBackground()
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2022-03-13 19:33:19 -07:00
|
|
|
if (_gameTicker.LobbyBackground != null)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.Background.Texture = _resourceCache.GetResource<TextureResource>(_gameTicker.LobbyBackground );
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
2022-03-13 19:33:19 -07:00
|
|
|
else
|
|
|
|
|
{
|
2024-05-12 09:18:21 +10:00
|
|
|
Lobby!.Background.Texture = null;
|
2022-03-13 19:33:19 -07:00
|
|
|
}
|
|
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetReady(bool newReady)
|
|
|
|
|
{
|
2022-10-17 02:44:23 +11:00
|
|
|
if (_gameTicker.IsGameStarted)
|
2020-02-26 16:42:12 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand($"toggleready {newReady}");
|
2020-02-26 16:42:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|