CatStation/Content.Client/GameTicking/Managers/TitleWindowManager.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

43 lines
1.6 KiB
C#

using Content.Shared.CCVar;
using Robust.Client;
using Robust.Client.Graphics;
using Robust.Shared;
using Robust.Shared.Configuration;
namespace Content.Client.GameTicking.Managers;
public sealed partial class TitleWindowManager
{
[Dependency] private IBaseClient _client = default!;
[Dependency] private IClyde _clyde = default!;
[Dependency] private IConfigurationManager _cfg = default!;
[Dependency] private IGameController _gameController = default!;
public void Initialize()
{
_cfg.OnValueChanged(CVars.GameHostName, _ => OnHostnameChange(), true);
_cfg.OnValueChanged(CCVars.GameHostnameInTitlebar, _ => OnHostnameChange(), true);
_client.RunLevelChanged += (_, _) => OnHostnameChange();
}
private void OnHostnameChange()
{
var defaultWindowTitle = _gameController.GameTitle();
// When the client starts connecting, it will be using either the default hostname, or whatever hostname
// is set in its config file (aka the last server they connected to) until it receives the latest cvars.
// If they are not connected then we will not show anything other than the usual window title.
if (_client.RunLevel != ClientRunLevel.InGame)
{
_clyde.SetWindowTitle(defaultWindowTitle);
return;
}
_clyde.SetWindowTitle(
_cfg.GetCVar(CCVars.GameHostnameInTitlebar)
? _cfg.GetCVar(CVars.GameHostName) + " - " + defaultWindowTitle
: defaultWindowTitle);
}
// You thought I would remove the :3 from this code? You were wrong.
}