Add a new InfoSystem that sends SharedInfo from the server to client when requested. Currently, only the rule header and rule text is sent. Previously, the rule header and rule text was bundled in the client, which means that the client would only display rules that it was built with, even if the server has different rules. This allows servers all running the same build to send different rules. This could be useful, for example, for servers running the official builds to send different rulesets without a client rebuild.
94 lines
2.7 KiB
C#
94 lines
2.7 KiB
C#
using Content.Client.Lobby;
|
|
using Content.Client.Viewport;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Info;
|
|
using Robust.Client.Console;
|
|
using Robust.Client.State;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Network;
|
|
|
|
namespace Content.Client.Info;
|
|
|
|
public sealed class RulesManager : SharedRulesManager
|
|
{
|
|
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
|
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
|
[Dependency] private readonly IStateManager _stateManager = default!;
|
|
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
|
[Dependency] private readonly INetManager _netManager = default!;
|
|
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
|
|
|
|
private InfoSection rulesSection = new InfoSection("", "", false);
|
|
private bool _shouldShowRules;
|
|
|
|
public void Initialize()
|
|
{
|
|
_netManager.RegisterNetMessage<ShouldShowRulesPopupMessage>(OnShouldShowRules);
|
|
_netManager.RegisterNetMessage<ShowRulesPopupMessage>(OnShowRulesPopupMessage);
|
|
_netManager.RegisterNetMessage<RulesAcceptedMessage>();
|
|
_stateManager.OnStateChanged += OnStateChanged;
|
|
}
|
|
|
|
private void OnShouldShowRules(ShouldShowRulesPopupMessage message)
|
|
{
|
|
_shouldShowRules = true;
|
|
}
|
|
|
|
private void OnShowRulesPopupMessage(ShowRulesPopupMessage message)
|
|
{
|
|
ShowRules(message.PopupTime);
|
|
}
|
|
|
|
private void OnStateChanged(StateChangedEventArgs args)
|
|
{
|
|
if (args.NewState is not (GameScreen or LobbyState))
|
|
return;
|
|
|
|
if (!_shouldShowRules)
|
|
return;
|
|
|
|
_shouldShowRules = false;
|
|
|
|
ShowRules(_configManager.GetCVar(CCVars.RulesWaitTime));
|
|
}
|
|
|
|
private void ShowRules(float time)
|
|
{
|
|
var rulesPopup = new RulesPopup
|
|
{
|
|
Timer = time
|
|
};
|
|
rulesPopup.OnQuitPressed += OnQuitPressed;
|
|
rulesPopup.OnAcceptPressed += OnAcceptPressed;
|
|
_userInterfaceManager.RootControl.AddChild(rulesPopup);
|
|
}
|
|
|
|
private void OnQuitPressed()
|
|
{
|
|
_consoleHost.ExecuteCommand("quit");
|
|
}
|
|
|
|
private void OnAcceptPressed()
|
|
{
|
|
var message = _netManager.CreateNetMessage<RulesAcceptedMessage>();
|
|
_netManager.ClientSendMessage(message);
|
|
}
|
|
|
|
public void UpdateRules()
|
|
{
|
|
var rules = _sysMan.GetEntitySystem<InfoSystem>().Rules;
|
|
rulesSection.SetText(rules.Title, rules.Text, true);
|
|
}
|
|
|
|
public Control RulesSection()
|
|
{
|
|
if (rulesSection.Disposed)
|
|
{
|
|
rulesSection = new InfoSection("", "", false);
|
|
}
|
|
UpdateRules();
|
|
return rulesSection;
|
|
}
|
|
}
|