using Content.Client.Audio; using Content.Client.GameTicking.Managers; using Content.Client.LateJoin; using Content.Client.Lobby.UI; using Content.Client.Message; using Content.Client.ReadyManifest; using Content.Client.UserInterface.Systems.Chat; using Content.Client.Voting; using Content.Shared.CCVar; using Robust.Client; using Robust.Client.Console; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.Configuration; using Robust.Shared.Timing; namespace Content.Client.Lobby { public sealed class LobbyState : Robust.Client.State.State { [Dependency] private readonly IBaseClient _baseClient = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IClientConsoleHost _consoleHost = default!; [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IResourceCache _resourceCache = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IVoteManager _voteManager = default!; private ISawmill _sawmill = default!; private ClientGameTicker _gameTicker = default!; private ContentAudioSystem _contentAudioSystem = default!; private ReadyManifestSystem _readyManifest = default!; protected override Type? LinkedScreenType { get; } = typeof(LobbyGui); public LobbyGui? Lobby; protected override void Startup() { if (_userInterfaceManager.ActiveScreen == null) return; Lobby = (LobbyGui) _userInterfaceManager.ActiveScreen; var chatController = _userInterfaceManager.GetUIController(); _gameTicker = _entityManager.System(); _contentAudioSystem = _entityManager.System(); _contentAudioSystem.LobbySoundtrackChanged += UpdateLobbySoundtrackInfo; _sawmill = Logger.GetSawmill("lobby"); _readyManifest = _entityManager.EntitySysManager.GetEntitySystem(); chatController.SetMainChat(true); _voteManager.SetPopupContainer(Lobby.VoteContainer); LayoutContainer.SetAnchorPreset(Lobby, LayoutContainer.LayoutPreset.Wide); var width = _cfg.GetCVar(CCVars.ServerLobbyRightPanelWidth); Lobby.RightSide.SetWidth = width; UpdateLobbyUi(); // Lobby.CharacterPreview.CharacterSetupButton.OnPressed += OnSetupPressed; //WD EDIT Lobby.ManifestButton.OnPressed += OnManifestPressed; Lobby.ReadyButton.OnPressed += OnReadyPressed; Lobby.ReadyButton.OnToggled += OnReadyToggled; Lobby.CharacterSetupButton.OnPressed += OnSetupPressed; _gameTicker.InfoBlobUpdated += UpdateLobbyUi; _gameTicker.LobbyStatusUpdated += LobbyStatusUpdated; _gameTicker.LobbyLateJoinStatusUpdated += LobbyLateJoinStatusUpdated; } protected override void Shutdown() { var chatController = _userInterfaceManager.GetUIController(); chatController.SetMainChat(false); _gameTicker.InfoBlobUpdated -= UpdateLobbyUi; _gameTicker.LobbyStatusUpdated -= LobbyStatusUpdated; _gameTicker.LobbyLateJoinStatusUpdated -= LobbyLateJoinStatusUpdated; _contentAudioSystem.LobbySoundtrackChanged -= UpdateLobbySoundtrackInfo; _voteManager.ClearPopupContainer(); if (Lobby is null) return; Lobby.CharacterSetupButton.OnPressed -= OnSetupPressed; Lobby.ManifestButton.OnPressed -= OnManifestPressed; Lobby.ReadyButton.OnPressed -= OnReadyPressed; Lobby.ReadyButton.OnToggled -= OnReadyToggled; Lobby = null; } public void SwitchState(LobbyGui.LobbyGuiState state) { // Yeah I hate this but LobbyState contains all the badness for now Lobby?.SwitchState(state); } private void OnSetupPressed(BaseButton.ButtonEventArgs args) { SetReady(false); Lobby?.SwitchState(LobbyGui.LobbyGuiState.CharacterSetup); } private void OnReadyPressed(BaseButton.ButtonEventArgs args) { if (!_gameTicker.IsGameStarted) return; new LateJoinGui().OpenCentered(); } private void OnReadyToggled(BaseButton.ButtonToggledEventArgs args) { SetReady(args.Pressed); } private void OnManifestPressed(BaseButton.ButtonEventArgs args) { _readyManifest.RequestReadyManifest(); } public override void FrameUpdate(FrameEventArgs e) { if (_gameTicker.IsGameStarted) { Lobby!.StartTime.Text = string.Empty; var roundTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan); Lobby!.StationTime.Text = Loc.GetString("lobby-state-player-status-round-time", ("hours", roundTime.Hours), ("minutes", roundTime.Minutes)); return; } Lobby!.StationTime.Text = Loc.GetString("lobby-state-player-status-round-not-started"); string text; if (_gameTicker.Paused) text = Loc.GetString("lobby-state-paused"); else if (_gameTicker.StartTime < _gameTiming.CurTime) { Lobby!.StartTime.Text = Loc.GetString("lobby-state-soon"); return; } else { var difference = _gameTicker.StartTime - _gameTiming.CurTime; var seconds = difference.TotalSeconds; if (seconds < 0) { text = Loc.GetString(seconds < -5 ? "lobby-state-right-now-question" : "lobby-state-right-now-confirmation"); } else if (difference.TotalHours >= 1) { text = $"{Math.Floor(difference.TotalHours)}:{difference.Minutes:D2}:{difference.Seconds:D2}"; } else { text = $"{difference.Minutes}:{difference.Seconds:D2}"; } } Lobby!.StartTime.Text = Loc.GetString("lobby-state-round-start-countdown-text", ("timeLeft", text)); } private void LobbyStatusUpdated() { UpdateLobbyBackground(); UpdateLobbyUi(); } private void LobbyLateJoinStatusUpdated() { Lobby!.ReadyButton.Disabled = _gameTicker.DisallowedLateJoin; } private void UpdateLobbyUi() { if (_gameTicker.IsGameStarted) { Lobby!.ReadyButton.ButtonText = Loc.GetString("lobby-state-ready-button-join-state"); Lobby!.ReadyButton.ToggleMode = false; Lobby!.ReadyButton.Pressed = false; Lobby!.ObserveButton.Disabled = false; Lobby!.ManifestButton.Disabled = true; } else { Lobby!.ReadyButton.ButtonText = Loc.GetString(Lobby!.ReadyButton.Pressed ? "lobby-state-player-status-ready" : "lobby-state-player-status-not-ready"); Lobby!.StartTime.Text = string.Empty; Lobby!.ReadyButton.ToggleMode = true; Lobby!.ReadyButton.Disabled = false; Lobby!.ReadyButton.Pressed = _gameTicker.AreWeReady; Lobby!.ManifestButton.Disabled = false; Lobby!.ObserveButton.Disabled = true; } if (_gameTicker.ServerInfoBlob != null) Lobby!.ServerInfo.SetInfoBlob(_gameTicker.ServerInfoBlob); Lobby!.LabelName.SetMarkup("[font=\"Bedstead\" size=20] White Dream [/font]"); // WD EDIT //Lobby!.ChangelogLabel.SetMarkup(Loc.GetString("ui-lobby-changelog")); // WD EDIT } private void UpdateLobbySoundtrackInfo(LobbySoundtrackChangedEvent ev) { if (ev.SoundtrackFilename == null) Lobby!.LobbySong.SetMarkup(Loc.GetString("lobby-state-song-no-song-text")); else if (ev.SoundtrackFilename != null && _resourceCache.TryGetResource(ev.SoundtrackFilename, out var lobbySongResource)) { var lobbyStream = lobbySongResource.AudioStream; var title = string.IsNullOrEmpty(lobbyStream.Title) ? Loc.GetString("lobby-state-song-unknown-title") : lobbyStream.Title; var artist = string.IsNullOrEmpty(lobbyStream.Artist) ? Loc.GetString("lobby-state-song-unknown-artist") : lobbyStream.Artist; var markup = Loc.GetString("lobby-state-song-text", ("songTitle", title), ("songArtist", artist)); Lobby!.LobbySong.SetMarkup(markup); } } private void UpdateLobbyBackground() { if (_gameTicker.AnimatedLobbyScreen != null) // WD EDIT { Lobby!.Background.SetRSI(_resourceCache.GetResource(_gameTicker.AnimatedLobbyScreen.Path).RSI); // WD EDIT var lobbyBackground = _gameTicker.AnimatedLobbyScreen; // WD EDIT var name = string.IsNullOrEmpty(lobbyBackground.Name) ? Loc.GetString("lobby-state-background-unknown-title") : lobbyBackground.Name; var artist = string.IsNullOrEmpty(lobbyBackground.Artist) ? Loc.GetString("lobby-state-background-unknown-artist") : lobbyBackground.Artist; var markup = Loc.GetString("lobby-state-background-text", ("backgroundName", name), ("backgroundArtist", artist)); Lobby!.LobbyBackground.SetMarkup(markup); return; } _sawmill.Warning("_gameTicker.LobbyBackground was null! No lobby background selected."); Lobby!.Background.SetRSI(null); // WWDP EDIT Lobby!.LobbyBackground.SetMarkup(Loc.GetString("lobby-state-background-no-background-text")); } private void SetReady(bool newReady) { if (_gameTicker.IsGameStarted) return; _consoleHost.ExecuteCommand($"toggleready {newReady}"); } // Removed some function for icon. If needed then get it from git version // WD EDIT END } }