forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the window titlebar to show the joined server
Requires space-wizards/RobustToolbox#5475
- Loading branch information
1 parent
f6ceaa7
commit f6c3a32
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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 class TitleWindowManager | ||
{ | ||
[Dependency] private readonly IClyde _clyde = default!; | ||
[Dependency] private readonly IConfigurationManager _cfg = default!; | ||
[Dependency] private readonly IGameController _gameController = default!; | ||
|
||
public void Initialize() | ||
{ | ||
_cfg.OnValueChanged(CVars.GameHostName, OnHostnameChange, true); | ||
_cfg.OnValueChanged(CCVars.HostnameInTitlebar, OnHostnameTitleChange, true); | ||
} | ||
|
||
public void Shutdown() | ||
{ | ||
_cfg.UnsubValueChanged(CVars.GameHostName, OnHostnameChange); | ||
} | ||
|
||
// This may use the last joined server temporarily until the CCVars of the joining server are received. | ||
private void OnHostnameChange(string hostname) | ||
{ | ||
var defaultWindowTitle = _gameController.GameTitle(); | ||
|
||
if (_cfg.GetCVar(CCVars.HostnameInTitlebar)) | ||
// If you really dislike the dash I guess change it here | ||
_clyde.SetWindowTitle(hostname + " - " + defaultWindowTitle); | ||
else | ||
_clyde.SetWindowTitle(defaultWindowTitle); | ||
} | ||
|
||
// Clients by default assume game.hostname_in_titlebar is true (and also that the server hostname is MyServer) | ||
// but we need to clear it as soon as we join and actually receive the CCVar. | ||
// This will ensure we rerun OnHostnameChange and set the correct title bar name. | ||
// We could also initialize this later but uhh I was told to make this a manager and put it into entrypoint. | ||
private void OnHostnameTitleChange(bool colonthree) | ||
{ | ||
OnHostnameChange(_cfg.GetCVar(CVars.GameHostName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters