Enable nullability in Content.Client (#3257)
* Enable nullability in Content.Client * Remove #nullable enable * Merge fixes * Remove Debug.Assert * Merge fixes * Fix build * Fix build
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#nullable enable
|
||||
using Content.Client.Administration;
|
||||
using Content.Client.Chat;
|
||||
using Content.Client.Construction;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Content.Client.State
|
||||
|
||||
private IEventBus _eventBus => _entityManager.EventBus;
|
||||
|
||||
private IEntity _lastHoveredEntity;
|
||||
private IEntity? _lastHoveredEntity;
|
||||
|
||||
private bool _outlineEnabled = true;
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Content.Client.State
|
||||
inRange = localPlayer.InRangeUnobstructed(entityToClick, ignoreInsideBlocker: true);
|
||||
}
|
||||
|
||||
InteractionOutlineComponent outline;
|
||||
InteractionOutlineComponent? outline;
|
||||
if(!_outlineEnabled || !ConfigurationManager.GetCVar(CCVars.OutlineEnabled))
|
||||
{
|
||||
if(entityToClick != null && entityToClick.TryGetComponent(out outline))
|
||||
@@ -113,7 +113,7 @@ namespace Content.Client.State
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity GetEntityUnderPosition(MapCoordinates coordinates)
|
||||
public IEntity? GetEntityUnderPosition(MapCoordinates coordinates)
|
||||
{
|
||||
var entitiesUnderPosition = GetEntitiesUnderPosition(coordinates);
|
||||
return entitiesUnderPosition.Count > 0 ? entitiesUnderPosition[0] : null;
|
||||
@@ -226,7 +226,7 @@ namespace Content.Client.State
|
||||
entityToClick?.Uid ?? EntityUid.Invalid);
|
||||
|
||||
// client side command handlers will always be sent the local player session.
|
||||
var session = PlayerManager.LocalPlayer.Session;
|
||||
var session = PlayerManager.LocalPlayer?.Session;
|
||||
if (inputSys.HandleInputCommand(session, func, message))
|
||||
{
|
||||
args.Handle();
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace Content.Client.State
|
||||
[Dependency] private readonly IGameController _gameController = default!;
|
||||
[Dependency] private readonly IBaseClient _baseClient = default!;
|
||||
|
||||
private Control _control;
|
||||
private Label _connectStatus;
|
||||
private Control? _control;
|
||||
private Label? _connectStatus;
|
||||
|
||||
private Control _connectingStatus;
|
||||
private Control _connectFail;
|
||||
private Label _connectFailReason;
|
||||
private Control _disconnected;
|
||||
private Control? _connectingStatus;
|
||||
private Control? _connectFail;
|
||||
private Label? _connectFailReason;
|
||||
private Control? _disconnected;
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
@@ -203,21 +203,24 @@ namespace Content.Client.State
|
||||
LayoutContainer.SetGrowHorizontal(_control, LayoutContainer.GrowDirection.Both);
|
||||
LayoutContainer.SetGrowVertical(_control, LayoutContainer.GrowDirection.Both);
|
||||
|
||||
exitButton.OnPressed += args =>
|
||||
exitButton.OnPressed += _ =>
|
||||
{
|
||||
_gameController.Shutdown("Exit button pressed");
|
||||
};
|
||||
|
||||
void Retry(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
_baseClient.ConnectToServer(_gameController.LaunchState.ConnectEndpoint);
|
||||
SetActivePage(Page.Connecting);
|
||||
if (_gameController.LaunchState.ConnectEndpoint != null)
|
||||
{
|
||||
_baseClient.ConnectToServer(_gameController.LaunchState.ConnectEndpoint);
|
||||
SetActivePage(Page.Connecting);
|
||||
}
|
||||
}
|
||||
|
||||
reconnectButton.OnPressed += Retry;
|
||||
retryButton.OnPressed += Retry;
|
||||
|
||||
_clientNetManager.ConnectFailed += (sender, args) =>
|
||||
_clientNetManager.ConnectFailed += (_, args) =>
|
||||
{
|
||||
_connectFailReason.Text = Loc.GetString("Failed to connect to server:\n{0}", args.Reason);
|
||||
SetActivePage(Page.ConnectFailed);
|
||||
@@ -232,6 +235,8 @@ namespace Content.Client.State
|
||||
|
||||
private void ConnectStateChanged(ClientConnectionState state)
|
||||
{
|
||||
if (_connectStatus == null) return;
|
||||
|
||||
_connectStatus.Text = Loc.GetString(state switch
|
||||
{
|
||||
ClientConnectionState.NotConnecting => "You should not be seeing this",
|
||||
@@ -245,7 +250,7 @@ namespace Content.Client.State
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
_control.Dispose();
|
||||
_control?.Dispose();
|
||||
}
|
||||
|
||||
public void SetDisconnected()
|
||||
@@ -255,9 +260,9 @@ namespace Content.Client.State
|
||||
|
||||
private void SetActivePage(Page page)
|
||||
{
|
||||
_connectingStatus.Visible = page == Page.Connecting;
|
||||
_connectFail.Visible = page == Page.ConnectFailed;
|
||||
_disconnected.Visible = page == Page.Disconnected;
|
||||
if (_connectingStatus != null) _connectingStatus.Visible = page == Page.Connecting;
|
||||
if (_connectFail != null) _connectFail.Visible = page == Page.ConnectFailed;
|
||||
if (_disconnected != null) _disconnected.Visible = page == Page.Disconnected;
|
||||
}
|
||||
|
||||
private enum Page : byte
|
||||
|
||||
@@ -39,8 +39,8 @@ namespace Content.Client.State
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||
|
||||
[ViewVariables] private CharacterSetupGui _characterSetup;
|
||||
[ViewVariables] private LobbyGui _lobby;
|
||||
[ViewVariables] private CharacterSetupGui _characterSetup = default!;
|
||||
[ViewVariables] private LobbyGui _lobby = default!;
|
||||
|
||||
public override void Startup()
|
||||
{
|
||||
@@ -48,16 +48,16 @@ namespace Content.Client.State
|
||||
_prototypeManager);
|
||||
LayoutContainer.SetAnchorPreset(_characterSetup, LayoutContainer.LayoutPreset.Wide);
|
||||
|
||||
_characterSetup.CloseButton.OnPressed += args =>
|
||||
_characterSetup.CloseButton.OnPressed += _ =>
|
||||
{
|
||||
_userInterfaceManager.StateRoot.AddChild(_lobby);
|
||||
_userInterfaceManager.StateRoot.RemoveChild(_characterSetup);
|
||||
};
|
||||
|
||||
_characterSetup.SaveButton.OnPressed += args =>
|
||||
_characterSetup.SaveButton.OnPressed += _ =>
|
||||
{
|
||||
_characterSetup.Save();
|
||||
_lobby.CharacterPreview.UpdateUI();
|
||||
_lobby?.CharacterPreview.UpdateUI();
|
||||
};
|
||||
|
||||
_lobby = new LobbyGui(_entityManager, _preferencesManager);
|
||||
@@ -70,28 +70,28 @@ namespace Content.Client.State
|
||||
|
||||
_lobby.Chat.DefaultChatFormat = "ooc \"{0}\"";
|
||||
|
||||
_lobby.ServerName.Text = _baseClient.GameInfo.ServerName;
|
||||
_lobby.ServerName.Text = _baseClient.GameInfo?.ServerName;
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusChat,
|
||||
InputCmdHandler.FromDelegate(s => GameScreen.FocusChat(_lobby.Chat)));
|
||||
InputCmdHandler.FromDelegate(_ => GameScreen.FocusChat(_lobby.Chat)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusOOC,
|
||||
InputCmdHandler.FromDelegate(s => GameScreen.FocusOOC(_lobby.Chat)));
|
||||
InputCmdHandler.FromDelegate(_ => GameScreen.FocusOOC(_lobby.Chat)));
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.FocusAdminChat,
|
||||
InputCmdHandler.FromDelegate(s => GameScreen.FocusAdminChat(_lobby.Chat)));
|
||||
InputCmdHandler.FromDelegate(_ => GameScreen.FocusAdminChat(_lobby.Chat)));
|
||||
|
||||
UpdateLobbyUi();
|
||||
|
||||
_lobby.CharacterPreview.CharacterSetupButton.OnPressed += args =>
|
||||
_lobby.CharacterPreview.CharacterSetupButton.OnPressed += _ =>
|
||||
{
|
||||
SetReady(false);
|
||||
_userInterfaceManager.StateRoot.RemoveChild(_lobby);
|
||||
_userInterfaceManager.StateRoot.AddChild(_characterSetup);
|
||||
};
|
||||
|
||||
_lobby.ObserveButton.OnPressed += args => _consoleHost.ExecuteCommand("observe");
|
||||
_lobby.ReadyButton.OnPressed += args =>
|
||||
_lobby.ObserveButton.OnPressed += _ => _consoleHost.ExecuteCommand("observe");
|
||||
_lobby.ReadyButton.OnPressed += _ =>
|
||||
{
|
||||
if (!_clientGameTicker.IsGameStarted)
|
||||
{
|
||||
@@ -99,7 +99,6 @@ namespace Content.Client.State
|
||||
}
|
||||
|
||||
new LateJoinGui().OpenCentered();
|
||||
return;
|
||||
};
|
||||
|
||||
_lobby.ReadyButton.OnToggled += args =>
|
||||
@@ -107,8 +106,8 @@ namespace Content.Client.State
|
||||
SetReady(args.Pressed);
|
||||
};
|
||||
|
||||
_lobby.LeaveButton.OnPressed += args => _consoleHost.ExecuteCommand("disconnect");
|
||||
_lobby.OptionsButton.OnPressed += args => new OptionsMenu().Open();
|
||||
_lobby.LeaveButton.OnPressed += _ => _consoleHost.ExecuteCommand("disconnect");
|
||||
_lobby.OptionsButton.OnPressed += _ => new OptionsMenu().Open();
|
||||
|
||||
UpdatePlayerList();
|
||||
|
||||
@@ -153,14 +152,7 @@ namespace Content.Client.State
|
||||
var seconds = difference.TotalSeconds;
|
||||
if (seconds < 0)
|
||||
{
|
||||
if (seconds < -5)
|
||||
{
|
||||
text = Loc.GetString("Right Now?");
|
||||
}
|
||||
else
|
||||
{
|
||||
text = Loc.GetString("Right Now");
|
||||
}
|
||||
text = Loc.GetString(seconds < -5 ? "Right Now?" : "Right Now");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -171,7 +163,7 @@ namespace Content.Client.State
|
||||
_lobby.StartTime.Text = Loc.GetString("Round Starts In: {0}", text);
|
||||
}
|
||||
|
||||
private void PlayerManagerOnPlayerListUpdated(object sender, EventArgs e)
|
||||
private void PlayerManagerOnPlayerListUpdated(object? sender, EventArgs e)
|
||||
{
|
||||
// Remove disconnected sessions from the Ready Dict
|
||||
foreach (var p in _clientGameTicker.Status)
|
||||
@@ -223,7 +215,10 @@ namespace Content.Client.State
|
||||
_lobby.ReadyButton.Pressed = _clientGameTicker.AreWeReady;
|
||||
}
|
||||
|
||||
_lobby.ServerInfo.SetInfoBlob(_clientGameTicker.ServerInfoBlob);
|
||||
if (_clientGameTicker.ServerInfoBlob != null)
|
||||
{
|
||||
_lobby.ServerInfo.SetInfoBlob(_clientGameTicker.ServerInfoBlob);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePlayerList()
|
||||
@@ -236,8 +231,8 @@ namespace Content.Client.State
|
||||
// Don't show ready state if we're ingame
|
||||
if (!_clientGameTicker.IsGameStarted)
|
||||
{
|
||||
var status = PlayerStatus.NotReady;
|
||||
if (session.UserId == _playerManager.LocalPlayer.UserId)
|
||||
PlayerStatus status;
|
||||
if (session.UserId == _playerManager.LocalPlayer?.UserId)
|
||||
status = _clientGameTicker.AreWeReady ? PlayerStatus.Ready : PlayerStatus.NotReady;
|
||||
else
|
||||
_clientGameTicker.Status.TryGetValue(session.UserId, out status);
|
||||
|
||||
@@ -32,8 +32,8 @@ namespace Content.Client.State
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
|
||||
private MainMenuControl _mainMenuControl;
|
||||
private OptionsMenu _optionsMenu;
|
||||
private MainMenuControl _mainMenuControl = default!;
|
||||
private OptionsMenu _optionsMenu = default!;
|
||||
private bool _isConnecting;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
@@ -132,7 +132,7 @@ namespace Content.Client.State
|
||||
}
|
||||
}
|
||||
|
||||
private void RunLevelChanged(object obj, RunLevelChangedEventArgs args)
|
||||
private void RunLevelChanged(object? obj, RunLevelChangedEventArgs args)
|
||||
{
|
||||
if (args.NewLevel == ClientRunLevel.Initialize)
|
||||
{
|
||||
@@ -179,7 +179,7 @@ namespace Content.Client.State
|
||||
}
|
||||
}
|
||||
|
||||
private void _onConnectFailed(object _, NetConnectFailArgs args)
|
||||
private void _onConnectFailed(object? _, NetConnectFailArgs args)
|
||||
{
|
||||
_userInterfaceManager.Popup($"Failed to connect:\n{args.Reason}");
|
||||
_netManager.ConnectFailed -= _onConnectFailed;
|
||||
@@ -200,24 +200,19 @@ namespace Content.Client.State
|
||||
private readonly IResourceCache _resourceCache;
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
|
||||
public LineEdit UserNameBox { get; private set; }
|
||||
public Button JoinPublicServerButton { get; private set; }
|
||||
public LineEdit AddressBox { get; private set; }
|
||||
public Button DirectConnectButton { get; private set; }
|
||||
public Button OptionsButton { get; private set; }
|
||||
public Button QuitButton { get; private set; }
|
||||
public Label VersionLabel { get; private set; }
|
||||
public LineEdit UserNameBox { get; }
|
||||
public Button JoinPublicServerButton { get; }
|
||||
public LineEdit AddressBox { get; }
|
||||
public Button DirectConnectButton { get; }
|
||||
public Button OptionsButton { get; }
|
||||
public Button QuitButton { get; }
|
||||
public Label VersionLabel { get; }
|
||||
|
||||
public MainMenuControl(IResourceCache resCache, IConfigurationManager configMan)
|
||||
{
|
||||
_resourceCache = resCache;
|
||||
_configurationManager = configMan;
|
||||
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
private void PerformLayout()
|
||||
{
|
||||
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
|
||||
|
||||
var layout = new LayoutContainer();
|
||||
|
||||
Reference in New Issue
Block a user