diff --git a/Content.Client/Administration/ClientAdminManager.cs b/Content.Client/Administration/ClientAdminManager.cs index 0f66a2df98..03f51039e7 100644 --- a/Content.Client/Administration/ClientAdminManager.cs +++ b/Content.Client/Administration/ClientAdminManager.cs @@ -7,8 +7,6 @@ using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Network; -#nullable enable - namespace Content.Client.Administration { public class ClientAdminManager : IClientAdminManager, IClientConGroupImplementation, IPostInjectInit diff --git a/Content.Client/Administration/IClientAdminManager.cs b/Content.Client/Administration/IClientAdminManager.cs index ed04f1d7e0..69f66757d3 100644 --- a/Content.Client/Administration/IClientAdminManager.cs +++ b/Content.Client/Administration/IClientAdminManager.cs @@ -1,8 +1,6 @@ using System; using Content.Shared.Administration; -#nullable enable - namespace Content.Client.Administration { /// diff --git a/Content.Client/Animations/ReusableAnimations.cs b/Content.Client/Animations/ReusableAnimations.cs index 24564cef62..2cb7c67c43 100644 --- a/Content.Client/Animations/ReusableAnimations.cs +++ b/Content.Client/Animations/ReusableAnimations.cs @@ -1,32 +1,31 @@ +using System; using Robust.Client.Animations; using Robust.Client.GameObjects; using Robust.Shared.Animations; +using Robust.Shared.GameObjects; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; -using System; -using Robust.Shared.GameObjects; namespace Content.Client.Animations { public static class ReusableAnimations { - public static void AnimateEntityPickup(IEntity entity, EntityCoordinates initialPosition, Vector2 finalPosition) { var animatableClone = entity.EntityManager.SpawnEntity("clientsideclone", initialPosition); animatableClone.Name = entity.Name; - if(!entity.TryGetComponent(out SpriteComponent sprite0)) + if (!entity.TryGetComponent(out SpriteComponent? sprite0)) { - Logger.Error($"Entity ({0}) couldn't be animated for pickup since it doesn't have a {1}!", entity.Name, nameof(SpriteComponent)); + Logger.Error("Entity ({0}) couldn't be animated for pickup since it doesn't have a {1}!", entity.Name, nameof(SpriteComponent)); return; } var sprite = animatableClone.GetComponent(); sprite.CopyFrom(sprite0); var animations = animatableClone.GetComponent(); - animations.AnimationCompleted += (s) => { + animations.AnimationCompleted += (_) => { animatableClone.Delete(); }; @@ -42,13 +41,12 @@ namespace Content.Client.Animations InterpolationMode = AnimationInterpolationMode.Linear, KeyFrames = { - new AnimationTrackComponentProperty.KeyFrame(initialPosition.Position, 0), - new AnimationTrackComponentProperty.KeyFrame(finalPosition, 0.125f) + new AnimationTrackProperty.KeyFrame(initialPosition.Position, 0), + new AnimationTrackProperty.KeyFrame(finalPosition, 0.125f) } } } }, "fancy_pickup_anim"); } - } } diff --git a/Content.Client/Arcade/BlockGameMenu.cs b/Content.Client/Arcade/BlockGameMenu.cs index 4438c96595..040f398fdb 100644 --- a/Content.Client/Arcade/BlockGameMenu.cs +++ b/Content.Client/Arcade/BlockGameMenu.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text; using Content.Client.GameObjects.Components.Arcade; @@ -29,27 +29,27 @@ namespace Content.Client.Arcade private readonly PanelContainer _mainPanel; private VBoxContainer _gameRootContainer; - private GridContainer _gameGrid; - private GridContainer _nextBlockGrid; - private GridContainer _holdBlockGrid; - private Label _pointsLabel; - private Label _levelLabel; - private Button _pauseButton; + private GridContainer _gameGrid = default!; + private GridContainer _nextBlockGrid = default!; + private GridContainer _holdBlockGrid = default!; + private readonly Label _pointsLabel; + private readonly Label _levelLabel; + private readonly Button _pauseButton; - private PanelContainer _menuRootContainer; - private Button _unpauseButton; - private Control _unpauseButtonMargin; - private Button _newGameButton; - private Button _scoreBoardButton; + private readonly PanelContainer _menuRootContainer; + private readonly Button _unpauseButton; + private readonly Control _unpauseButtonMargin; + private readonly Button _newGameButton; + private readonly Button _scoreBoardButton; - private PanelContainer _gameOverRootContainer; - private Label _finalScoreLabel; - private Button _finalNewGameButton; + private readonly PanelContainer _gameOverRootContainer; + private readonly Label _finalScoreLabel; + private readonly Button _finalNewGameButton; - private PanelContainer _highscoresRootContainer; - private Label _localHighscoresLabel; - private Label _globalHighscoresLabel; - private Button _highscoreBackButton; + private readonly PanelContainer _highscoresRootContainer; + private readonly Label _localHighscoresLabel; + private readonly Label _globalHighscoresLabel; + private readonly Button _highscoreBackButton; private bool _isPlayer = false; private bool _gameOver = false; @@ -64,23 +64,193 @@ namespace Content.Client.Arcade _mainPanel = new PanelContainer(); - SetupGameMenu(backgroundTexture); + #region Game Menu + // building the game container + _gameRootContainer = new VBoxContainer(); + + _levelLabel = new Label + { + Align = Label.AlignMode.Center, + HorizontalExpand = true + }; + _gameRootContainer.AddChild(_levelLabel); + _gameRootContainer.AddChild(new Control + { + MinSize = new Vector2(1,5) + }); + + _pointsLabel = new Label + { + Align = Label.AlignMode.Center, + HorizontalExpand = true + }; + _gameRootContainer.AddChild(_pointsLabel); + _gameRootContainer.AddChild(new Control + { + MinSize = new Vector2(1,10) + }); + + var gameBox = new HBoxContainer(); + gameBox.AddChild(SetupHoldBox(backgroundTexture)); + gameBox.AddChild(new Control + { + MinSize = new Vector2(10,1) + }); + gameBox.AddChild(SetupGameGrid(backgroundTexture)); + gameBox.AddChild(new Control + { + MinSize = new Vector2(10,1) + }); + gameBox.AddChild(SetupNextBox(backgroundTexture)); + + _gameRootContainer.AddChild(gameBox); + + _gameRootContainer.AddChild(new Control + { + MinSize = new Vector2(1,10) + }); + + _pauseButton = new Button + { + Text = Loc.GetString("Pause"), + TextAlign = Label.AlignMode.Center + }; + _pauseButton.OnPressed += (e) => TryPause(); + _gameRootContainer.AddChild(_pauseButton); + #endregion + _mainPanel.AddChild(_gameRootContainer); - SetupPauseMenu(backgroundTexture); + #region Pause Menu + var pauseRootBack = new StyleBoxTexture + { + Texture = backgroundTexture, + Modulate = OverlayShadowColor + }; + pauseRootBack.SetPatchMargin(StyleBox.Margin.All, 10); + _menuRootContainer = new PanelContainer + { + PanelOverride = pauseRootBack, + VerticalAlignment = VAlignment.Center, + HorizontalAlignment = HAlignment.Center + }; - SetupGameoverScreen(backgroundTexture); + var pauseInnerBack = new StyleBoxTexture + { + Texture = backgroundTexture, + Modulate = OverlayBackgroundColor + }; + pauseInnerBack.SetPatchMargin(StyleBox.Margin.All, 10); + var pauseMenuInnerPanel = new PanelContainer + { + PanelOverride = pauseInnerBack, + VerticalAlignment = VAlignment.Center, + HorizontalAlignment = HAlignment.Center + }; - SetupHighScoreScreen(backgroundTexture); + _menuRootContainer.AddChild(pauseMenuInnerPanel); - Contents.AddChild(_mainPanel); + var pauseMenuContainer = new VBoxContainer + { + HorizontalAlignment = HAlignment.Center, + VerticalAlignment = VAlignment.Center + }; - CanKeyboardFocus = true; - } + _newGameButton = new Button + { + Text = Loc.GetString("New Game"), + TextAlign = Label.AlignMode.Center + }; + _newGameButton.OnPressed += (e) => + { + _owner.SendAction(BlockGamePlayerAction.NewGame); + }; + pauseMenuContainer.AddChild(_newGameButton); + pauseMenuContainer.AddChild(new Control{MinSize = new Vector2(1,10)}); + + _scoreBoardButton = new Button + { + Text = Loc.GetString("Scoreboard"), + TextAlign = Label.AlignMode.Center + }; + _scoreBoardButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.ShowHighscores); + pauseMenuContainer.AddChild(_scoreBoardButton); + _unpauseButtonMargin = new Control {MinSize = new Vector2(1, 10), Visible = false}; + pauseMenuContainer.AddChild(_unpauseButtonMargin); + + _unpauseButton = new Button + { + Text = Loc.GetString("Unpause"), + TextAlign = Label.AlignMode.Center, + Visible = false + }; + _unpauseButton.OnPressed += (e) => + { + _owner.SendAction(BlockGamePlayerAction.Unpause); + }; + pauseMenuContainer.AddChild(_unpauseButton); + + pauseMenuInnerPanel.AddChild(pauseMenuContainer); + #endregion + + #region Gameover Screen + var gameOverRootBack = new StyleBoxTexture + { + Texture = backgroundTexture, + Modulate = OverlayShadowColor + }; + gameOverRootBack.SetPatchMargin(StyleBox.Margin.All, 10); + _gameOverRootContainer = new PanelContainer + { + PanelOverride = gameOverRootBack, + VerticalAlignment = VAlignment.Center, + HorizontalAlignment = HAlignment.Center + }; + + var gameOverInnerBack = new StyleBoxTexture + { + Texture = backgroundTexture, + Modulate = OverlayBackgroundColor + }; + gameOverInnerBack.SetPatchMargin(StyleBox.Margin.All, 10); + var gameOverMenuInnerPanel = new PanelContainer + { + PanelOverride = gameOverInnerBack, + VerticalAlignment = VAlignment.Center, + HorizontalAlignment = HAlignment.Center + }; + + _gameOverRootContainer.AddChild(gameOverMenuInnerPanel); + + var gameOverMenuContainer = new VBoxContainer + { + HorizontalAlignment = HAlignment.Center, + VerticalAlignment = VAlignment.Center + }; + + gameOverMenuContainer.AddChild(new Label{Text = Loc.GetString("Gameover!"),Align = Label.AlignMode.Center}); + gameOverMenuContainer.AddChild(new Control{MinSize = new Vector2(1,10)}); - private void SetupHighScoreScreen(Texture backgroundTexture) - { + _finalScoreLabel = new Label{Align = Label.AlignMode.Center}; + gameOverMenuContainer.AddChild(_finalScoreLabel); + gameOverMenuContainer.AddChild(new Control{MinSize = new Vector2(1,10)}); + + _finalNewGameButton = new Button + { + Text = Loc.GetString("New Game"), + TextAlign = Label.AlignMode.Center + }; + _finalNewGameButton.OnPressed += (e) => + { + _owner.SendAction(BlockGamePlayerAction.NewGame); + }; + gameOverMenuContainer.AddChild(_finalNewGameButton); + + gameOverMenuInnerPanel.AddChild(gameOverMenuContainer); + #endregion + + #region High Score Screen var rootBack = new StyleBoxTexture { Texture = backgroundTexture, @@ -143,138 +313,11 @@ namespace Content.Client.Arcade menuContainer.AddChild(_highscoreBackButton); menuInnerPanel.AddChild(menuContainer); - } + #endregion - private void SetupGameoverScreen(Texture backgroundTexture) - { - var rootBack = new StyleBoxTexture - { - Texture = backgroundTexture, - Modulate = OverlayShadowColor - }; - rootBack.SetPatchMargin(StyleBox.Margin.All, 10); - _gameOverRootContainer = new PanelContainer - { - PanelOverride = rootBack, - VerticalAlignment = VAlignment.Center, - HorizontalAlignment = HAlignment.Center - }; + Contents.AddChild(_mainPanel); - var innerBack = new StyleBoxTexture - { - Texture = backgroundTexture, - Modulate = OverlayBackgroundColor - }; - innerBack.SetPatchMargin(StyleBox.Margin.All, 10); - var menuInnerPanel = new PanelContainer - { - PanelOverride = innerBack, - VerticalAlignment = VAlignment.Center, - HorizontalAlignment = HAlignment.Center - }; - - _gameOverRootContainer.AddChild(menuInnerPanel); - - var menuContainer = new VBoxContainer - { - HorizontalAlignment = HAlignment.Center, - VerticalAlignment = VAlignment.Center - }; - - menuContainer.AddChild(new Label{Text = Loc.GetString("Gameover!"),Align = Label.AlignMode.Center}); - menuContainer.AddChild(new Control{MinSize = new Vector2(1,10)}); - - - _finalScoreLabel = new Label{Align = Label.AlignMode.Center}; - menuContainer.AddChild(_finalScoreLabel); - menuContainer.AddChild(new Control{MinSize = new Vector2(1,10)}); - - _finalNewGameButton = new Button - { - Text = Loc.GetString("New Game"), - TextAlign = Label.AlignMode.Center - }; - _finalNewGameButton.OnPressed += (e) => - { - _owner.SendAction(BlockGamePlayerAction.NewGame); - }; - menuContainer.AddChild(_finalNewGameButton); - - menuInnerPanel.AddChild(menuContainer); - } - - private void SetupPauseMenu(Texture backgroundTexture) - { - var rootBack = new StyleBoxTexture - { - Texture = backgroundTexture, - Modulate = OverlayShadowColor - }; - rootBack.SetPatchMargin(StyleBox.Margin.All, 10); - _menuRootContainer = new PanelContainer - { - PanelOverride = rootBack, - VerticalAlignment = VAlignment.Center, - HorizontalAlignment = HAlignment.Center - }; - - var innerBack = new StyleBoxTexture - { - Texture = backgroundTexture, - Modulate = OverlayBackgroundColor - }; - innerBack.SetPatchMargin(StyleBox.Margin.All, 10); - var menuInnerPanel = new PanelContainer - { - PanelOverride = innerBack, - VerticalAlignment = VAlignment.Center, - HorizontalAlignment = HAlignment.Center - }; - - _menuRootContainer.AddChild(menuInnerPanel); - - - var menuContainer = new VBoxContainer - { - HorizontalAlignment = HAlignment.Center, - VerticalAlignment = VAlignment.Center - }; - - _newGameButton = new Button - { - Text = Loc.GetString("New Game"), - TextAlign = Label.AlignMode.Center - }; - _newGameButton.OnPressed += (e) => - { - _owner.SendAction(BlockGamePlayerAction.NewGame); - }; - menuContainer.AddChild(_newGameButton); - menuContainer.AddChild(new Control{MinSize = new Vector2(1,10)}); - - _scoreBoardButton = new Button - { - Text = Loc.GetString("Scoreboard"), - TextAlign = Label.AlignMode.Center - }; - _scoreBoardButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.ShowHighscores); - menuContainer.AddChild(_scoreBoardButton); - _unpauseButtonMargin = new Control {MinSize = new Vector2(1, 10), Visible = false}; - menuContainer.AddChild(_unpauseButtonMargin); - - _unpauseButton = new Button - { - Text = Loc.GetString("Unpause"), - TextAlign = Label.AlignMode.Center, - Visible = false - }; - _unpauseButton.OnPressed += (e) => - { - _owner.SendAction(BlockGamePlayerAction.Unpause); - }; - menuContainer.AddChild(_unpauseButton); - - menuInnerPanel.AddChild(menuContainer); + CanKeyboardFocus = true; } public void SetUsability(bool isPlayer) @@ -293,62 +336,6 @@ namespace Content.Client.Arcade _highscoreBackButton.Disabled = !_isPlayer; } - private void SetupGameMenu(Texture backgroundTexture) - { - // building the game container - _gameRootContainer = new VBoxContainer(); - - _levelLabel = new Label - { - Align = Label.AlignMode.Center, - HorizontalExpand = true - }; - _gameRootContainer.AddChild(_levelLabel); - _gameRootContainer.AddChild(new Control - { - MinSize = new Vector2(1,5) - }); - - _pointsLabel = new Label - { - Align = Label.AlignMode.Center, - HorizontalExpand = true - }; - _gameRootContainer.AddChild(_pointsLabel); - _gameRootContainer.AddChild(new Control - { - MinSize = new Vector2(1,10) - }); - - var gameBox = new HBoxContainer(); - gameBox.AddChild(SetupHoldBox(backgroundTexture)); - gameBox.AddChild(new Control - { - MinSize = new Vector2(10,1) - }); - gameBox.AddChild(SetupGameGrid(backgroundTexture)); - gameBox.AddChild(new Control - { - MinSize = new Vector2(10,1) - }); - gameBox.AddChild(SetupNextBox(backgroundTexture)); - - _gameRootContainer.AddChild(gameBox); - - _gameRootContainer.AddChild(new Control - { - MinSize = new Vector2(1,10) - }); - - _pauseButton = new Button - { - Text = Loc.GetString("Pause"), - TextAlign = Label.AlignMode.Center - }; - _pauseButton.OnPressed += (e) => TryPause(); - _gameRootContainer.AddChild(_pauseButton); - } - private Control SetupGameGrid(Texture panelTex) { _gameGrid = new GridContainer @@ -541,17 +528,16 @@ namespace Content.Client.Arcade { var localHighscoreText = new StringBuilder(Loc.GetString("Station\n")); var globalHighscoreText = new StringBuilder(Loc.GetString("Nanotrasen:\n")); - for (int i = 0; i < 5; i++) - { - if (localHighscores.Count > i) - localHighscoreText.AppendLine(Loc.GetString("#{0}: {1} - {2}", i + 1, localHighscores[i].Name, localHighscores[i].Score)); - else - localHighscoreText.AppendLine(Loc.GetString("#{0}: ??? - 0", i + 1)); - if (globalHighscores.Count > i) - globalHighscoreText.AppendLine(Loc.GetString("#{0}: {1} - {2}", i + 1, globalHighscores[i].Name, globalHighscores[i].Score)); - else - globalHighscoreText.AppendLine(Loc.GetString("#{0}: ??? - 0", i + 1)); + for (var i = 0; i < 5; i++) + { + localHighscoreText.AppendLine(localHighscores.Count > i + ? Loc.GetString("#{0}: {1} - {2}", i + 1, localHighscores[i].Name, localHighscores[i].Score) + : Loc.GetString("#{0}: ??? - 0", i + 1)); + + globalHighscoreText.AppendLine(globalHighscores.Count > i + ? Loc.GetString("#{0}: {1} - {2}", i + 1, globalHighscores[i].Name, globalHighscores[i].Score) + : Loc.GetString("#{0}: ??? - 0", i + 1)); } _localHighscoresLabel.Text = localHighscoreText.ToString(); diff --git a/Content.Client/Chat/ChatBox.cs b/Content.Client/Chat/ChatBox.cs index b4f3e9ad52..031362868c 100644 --- a/Content.Client/Chat/ChatBox.cs +++ b/Content.Client/Chat/ChatBox.cs @@ -28,7 +28,7 @@ namespace Content.Client.Chat /// /// Default formatting string for the ClientChatConsole. /// - public string DefaultChatFormat { get; set; } + public string DefaultChatFormat { get; set; } = string.Empty; public bool ReleaseFocusOnEnter { get; set; } = true; @@ -136,9 +136,9 @@ namespace Content.Client.Chat } } - public event TextSubmitHandler TextSubmitted; + public event TextSubmitHandler? TextSubmitted; - public event FilterToggledHandler FilterToggled; + public event FilterToggledHandler? FilterToggled; public void AddLine(string message, ChatChannel channel, Color color) { diff --git a/Content.Client/Chat/ChatManager.cs b/Content.Client/Chat/ChatManager.cs index c370a951f0..dbb5331da0 100644 --- a/Content.Client/Chat/ChatManager.cs +++ b/Content.Client/Chat/ChatManager.cs @@ -18,8 +18,6 @@ using Robust.Shared.Network; using Robust.Shared.Timing; using Robust.Shared.Utility; -#nullable enable - namespace Content.Client.Chat { internal sealed class ChatManager : IChatManager, IPostInjectInit diff --git a/Content.Client/ClickMapManager.cs b/Content.Client/ClickMapManager.cs index fc10f807cf..0e4d68e9ab 100644 --- a/Content.Client/ClickMapManager.cs +++ b/Content.Client/ClickMapManager.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Text; diff --git a/Content.Client/ClientModuleTestingCallbacks.cs b/Content.Client/ClientModuleTestingCallbacks.cs index 8b3d85a49c..528f0d056b 100644 --- a/Content.Client/ClientModuleTestingCallbacks.cs +++ b/Content.Client/ClientModuleTestingCallbacks.cs @@ -5,6 +5,6 @@ namespace Content.Client { public sealed class ClientModuleTestingCallbacks : SharedModuleTestingCallbacks { - public Action ClientBeforeIoC { get; set; } + public Action? ClientBeforeIoC { get; set; } } } diff --git a/Content.Client/ClientNotifyManager.cs b/Content.Client/ClientNotifyManager.cs index d9c32ab9fa..5bbe778b29 100644 --- a/Content.Client/ClientNotifyManager.cs +++ b/Content.Client/ClientNotifyManager.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using Content.Client.Interfaces; diff --git a/Content.Client/ClientPreferencesManager.cs b/Content.Client/ClientPreferencesManager.cs index 9dd2ce7fd0..0a0530ddd0 100644 --- a/Content.Client/ClientPreferencesManager.cs +++ b/Content.Client/ClientPreferencesManager.cs @@ -19,9 +19,10 @@ namespace Content.Client { [Dependency] private readonly IClientNetManager _netManager = default!; - public event Action OnServerDataLoaded; - public GameSettings Settings { get; private set; } - public PlayerPreferences Preferences { get; private set; } + public event Action? OnServerDataLoaded; + + public GameSettings Settings { get; private set; } = default!; + public PlayerPreferences Preferences { get; private set; } = default!; public void Initialize() { diff --git a/Content.Client/Commands/DebugCommands.cs b/Content.Client/Commands/DebugCommands.cs index 0523cfb521..09b8ee3a72 100644 --- a/Content.Client/Commands/DebugCommands.cs +++ b/Content.Client/Commands/DebugCommands.cs @@ -58,7 +58,7 @@ namespace Content.Client.Commands foreach (var component in components) { - if (component.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (component.Owner.TryGetComponent(out ISpriteComponent? sprite)) { sprite.DrawDepth = (int) DrawDepth.Overlays; } diff --git a/Content.Client/Commands/HideMechanismsCommand.cs b/Content.Client/Commands/HideMechanismsCommand.cs index 3dd9c0db45..d0bec6b29d 100644 --- a/Content.Client/Commands/HideMechanismsCommand.cs +++ b/Content.Client/Commands/HideMechanismsCommand.cs @@ -21,7 +21,7 @@ namespace Content.Client.Commands foreach (var mechanism in mechanisms) { - if (!mechanism.Owner.TryGetComponent(out SpriteComponent sprite)) + if (!mechanism.Owner.TryGetComponent(out SpriteComponent? sprite)) { continue; } diff --git a/Content.Client/Commands/ShowMechanismsCommand.cs b/Content.Client/Commands/ShowMechanismsCommand.cs index b289dbb49d..f1762079c1 100644 --- a/Content.Client/Commands/ShowMechanismsCommand.cs +++ b/Content.Client/Commands/ShowMechanismsCommand.cs @@ -23,7 +23,7 @@ namespace Content.Client.Commands foreach (var mechanism in mechanisms) { - if (mechanism.Owner.TryGetComponent(out SpriteComponent sprite)) + if (mechanism.Owner.TryGetComponent(out SpriteComponent? sprite)) { sprite.ContainerOccluded = false; } diff --git a/Content.Client/Construction/ConstructionMenu.xaml.cs b/Content.Client/Construction/ConstructionMenu.xaml.cs index 889e652ba7..0d3922adfc 100644 --- a/Content.Client/Construction/ConstructionMenu.xaml.cs +++ b/Content.Client/Construction/ConstructionMenu.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using Robust.Client.AutoGenerated; using Robust.Client.Graphics; using Robust.Client.UserInterface.Controls; diff --git a/Content.Client/Construction/ConstructionPlacementHijack.cs b/Content.Client/Construction/ConstructionPlacementHijack.cs index bd08e1a7a4..3c8a8b96cf 100644 --- a/Content.Client/Construction/ConstructionPlacementHijack.cs +++ b/Content.Client/Construction/ConstructionPlacementHijack.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using Content.Client.GameObjects.Components.Construction; using Content.Client.GameObjects.EntitySystems; using Content.Shared.Construction; @@ -41,7 +40,7 @@ namespace Content.Client.Construction { if (entity.TryGetComponent(out ConstructionGhostComponent? ghost)) { - _constructionSystem.ClearGhost(ghost.GhostID); + _constructionSystem.ClearGhost(ghost.GhostId); } return true; } diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index b18a998bc1..45520c5a3a 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -9,6 +9,7 @@ ..\bin\Content.Client\ Exe nullable + enable diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 61bdc03b9f..23eb13d10e 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -3,6 +3,7 @@ using Content.Client.Administration; using Content.Client.Changelog; using Content.Client.Eui; using Content.Client.GameObjects.Components.Actor; +using Content.Client.Graphics.Overlays; using Content.Client.Input; using Content.Client.Interfaces; using Content.Client.Interfaces.Chat; @@ -14,9 +15,9 @@ using Content.Client.StationEvents; using Content.Client.UserInterface; using Content.Client.UserInterface.AdminMenu; using Content.Client.UserInterface.Stylesheets; -using Content.Client.Graphics.Overlays; using Content.Client.Voting; using Content.Shared.Actions; +using Content.Shared.Alert; using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.Components.Cargo; using Content.Shared.GameObjects.Components.Chemistry.ChemMaster; @@ -27,7 +28,6 @@ using Content.Shared.GameObjects.Components.Power.AME; using Content.Shared.GameObjects.Components.Research; using Content.Shared.GameObjects.Components.VendingMachines; using Content.Shared.Kitchen; -using Content.Shared.Alert; using Robust.Client; using Robust.Client.Graphics; using Robust.Client.Input; @@ -105,7 +105,7 @@ namespace Content.Client _escapeMenuOwner.Initialize(); - _baseClient.PlayerJoinedServer += (sender, args) => + _baseClient.PlayerJoinedServer += (_, _) => { IoCManager.Resolve().CreateNewMapEntity(MapId.Nullspace); }; @@ -116,10 +116,13 @@ namespace Content.Client /// /// /// - public void SubscribePlayerAttachmentEvents(object sender, EventArgs args) + public void SubscribePlayerAttachmentEvents(object? sender, EventArgs args) { - _playerManager.LocalPlayer.EntityAttached += AttachPlayerToEntity; - _playerManager.LocalPlayer.EntityDetached += DetachPlayerFromEntity; + if (_playerManager.LocalPlayer != null) + { + _playerManager.LocalPlayer.EntityAttached += AttachPlayerToEntity; + _playerManager.LocalPlayer.EntityDetached += DetachPlayerFromEntity; + } } /// @@ -171,7 +174,7 @@ namespace Content.Client IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); - _baseClient.RunLevelChanged += (sender, args) => + _baseClient.RunLevelChanged += (_, args) => { if (args.NewLevel == ClientRunLevel.Initialize) { diff --git a/Content.Client/EscapeMenuOwner.cs b/Content.Client/EscapeMenuOwner.cs index 856a3902ef..18dee675c8 100644 --- a/Content.Client/EscapeMenuOwner.cs +++ b/Content.Client/EscapeMenuOwner.cs @@ -16,7 +16,7 @@ namespace Content.Client [Dependency] private readonly IStateManager _stateManager = default!; [Dependency] private readonly IGameHud _gameHud = default!; - private EscapeMenu _escapeMenu; + private EscapeMenu? _escapeMenu; public void Initialize() { @@ -35,12 +35,12 @@ namespace Content.Client _escapeMenu.OnClose += () => _gameHud.EscapeButtonDown = false; _inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, - InputCmdHandler.FromDelegate(s => Enabled())); + InputCmdHandler.FromDelegate(_ => Enabled())); } else if (obj.OldState is GameScreenBase) { // Switched FROM GameScreen. - _escapeMenu.Dispose(); + _escapeMenu?.Dispose(); _escapeMenu = null; _inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, null); @@ -49,7 +49,7 @@ namespace Content.Client private void Enabled() { - if (_escapeMenu.IsOpen) + if (_escapeMenu != null && _escapeMenu.IsOpen) { if (_escapeMenu.IsAtFront()) { @@ -71,12 +71,12 @@ namespace Content.Client if (value) { _gameHud.EscapeButtonDown = true; - _escapeMenu.OpenCentered(); + _escapeMenu?.OpenCentered(); } else { _gameHud.EscapeButtonDown = false; - _escapeMenu.Close(); + _escapeMenu?.Close(); } } } diff --git a/Content.Client/Eui/BaseEui.cs b/Content.Client/Eui/BaseEui.cs index e3224ae710..8d23378cc3 100644 --- a/Content.Client/Eui/BaseEui.cs +++ b/Content.Client/Eui/BaseEui.cs @@ -3,8 +3,6 @@ using Content.Shared.Network.NetMessages; using Robust.Shared.IoC; using Robust.Shared.Network; -#nullable enable - namespace Content.Client.Eui { public abstract class BaseEui diff --git a/Content.Client/Eui/EuiManager.cs b/Content.Client/Eui/EuiManager.cs index ae7dc24fbb..8ba649a9c3 100644 --- a/Content.Client/Eui/EuiManager.cs +++ b/Content.Client/Eui/EuiManager.cs @@ -5,8 +5,6 @@ using Robust.Shared.IoC; using Robust.Shared.Network; using Robust.Shared.Reflection; -#nullable enable - namespace Content.Client.Eui { public sealed class EuiManager diff --git a/Content.Client/GameObjects/Components/Access/IdCardConsoleBoundUserInterface.cs b/Content.Client/GameObjects/Components/Access/IdCardConsoleBoundUserInterface.cs index 435c7da488..9084895c5b 100644 --- a/Content.Client/GameObjects/Components/Access/IdCardConsoleBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Access/IdCardConsoleBoundUserInterface.cs @@ -15,14 +15,13 @@ namespace Content.Client.GameObjects.Components.Access { } - private IdCardConsoleWindow _window; + private IdCardConsoleWindow? _window; protected override void Open() { base.Open(); - _window = new IdCardConsoleWindow(this, _prototypeManager); - _window.Title = Owner.Owner.Name; + _window = new IdCardConsoleWindow(this, _prototypeManager) {Title = Owner.Owner.Name}; _window.OnClose += Close; _window.OpenCentered(); } @@ -31,7 +30,7 @@ namespace Content.Client.GameObjects.Components.Access { base.UpdateState(state); var castState = (IdCardConsoleBoundUserInterfaceState) state; - _window.UpdateState(castState); + _window?.UpdateState(castState); } public void ButtonPressed(UiButton button) diff --git a/Content.Client/GameObjects/Components/Access/IdCardConsoleWindow.cs b/Content.Client/GameObjects/Components/Access/IdCardConsoleWindow.cs index 3df9f54340..9c6e68bf5e 100644 --- a/Content.Client/GameObjects/Components/Access/IdCardConsoleWindow.cs +++ b/Content.Client/GameObjects/Components/Access/IdCardConsoleWindow.cs @@ -31,8 +31,8 @@ namespace Content.Client.GameObjects.Components.Access private readonly Dictionary _accessButtons = new(); - private string _lastFullName; - private string _lastJobTitle; + private string? _lastFullName; + private string? _lastJobTitle; public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, IPrototypeManager prototypeManager) { @@ -165,7 +165,7 @@ namespace Content.Client.GameObjects.Components.Access _fullNameLineEdit.Editable = interfaceEnabled; if (!fullNameDirty) { - _fullNameLineEdit.Text = state.TargetIdFullName; + _fullNameLineEdit.Text = state.TargetIdFullName ?? ""; } _fullNameSaveButton.Disabled = !interfaceEnabled || !fullNameDirty; @@ -174,7 +174,7 @@ namespace Content.Client.GameObjects.Components.Access _jobTitleLineEdit.Editable = interfaceEnabled; if (!jobTitleDirty) { - _jobTitleLineEdit.Text = state.TargetIdJobTitle; + _jobTitleLineEdit.Text = state.TargetIdJobTitle ?? ""; } _jobTitleSaveButton.Disabled = !interfaceEnabled || !jobTitleDirty; @@ -184,7 +184,7 @@ namespace Content.Client.GameObjects.Components.Access button.Disabled = !interfaceEnabled; if (interfaceEnabled) { - button.Pressed = state.TargetIdAccessList.Contains(accessName); + button.Pressed = state.TargetIdAccessList?.Contains(accessName) ?? false; } } diff --git a/Content.Client/GameObjects/Components/ActionBlocking/CuffableComponent.cs b/Content.Client/GameObjects/Components/ActionBlocking/CuffableComponent.cs index 554c4cec34..ee9360a037 100644 --- a/Content.Client/GameObjects/Components/ActionBlocking/CuffableComponent.cs +++ b/Content.Client/GameObjects/Components/ActionBlocking/CuffableComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.ActionBlocking; +using Content.Shared.GameObjects.Components.ActionBlocking; using Content.Shared.Preferences.Appearance; using Robust.Client.GameObjects; using Robust.Client.Graphics; diff --git a/Content.Client/GameObjects/Components/ActionBlocking/HandcuffComponent.cs b/Content.Client/GameObjects/Components/ActionBlocking/HandcuffComponent.cs index 9cee1ac181..f96335ffc3 100644 --- a/Content.Client/GameObjects/Components/ActionBlocking/HandcuffComponent.cs +++ b/Content.Client/GameObjects/Components/ActionBlocking/HandcuffComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.ActionBlocking; +using Content.Shared.GameObjects.Components.ActionBlocking; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Actor/CharacterInfoComponent.cs b/Content.Client/GameObjects/Components/Actor/CharacterInfoComponent.cs index dc0a4c4cb6..3ae0720475 100644 --- a/Content.Client/GameObjects/Components/Actor/CharacterInfoComponent.cs +++ b/Content.Client/GameObjects/Components/Actor/CharacterInfoComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Client.GameObjects.Components.Mobs; using Content.Client.UserInterface; using Content.Client.UserInterface.Stylesheets; @@ -91,7 +90,7 @@ namespace Content.Client.GameObjects.Components.Actor } }); - AddChild(new Placeholder(resourceCache) + AddChild(new Placeholder() { PlaceholderText = Loc.GetString("Health & status effects") }); @@ -104,7 +103,7 @@ namespace Content.Client.GameObjects.Components.Actor ObjectivesContainer = new VBoxContainer(); AddChild(ObjectivesContainer); - AddChild(new Placeholder(resourceCache) + AddChild(new Placeholder() { PlaceholderText = Loc.GetString("Antagonist Roles") }); diff --git a/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs b/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs index d00d8cf6b7..e80daab6e5 100644 --- a/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs +++ b/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs @@ -29,9 +29,9 @@ namespace Content.Client.GameObjects.Components.Actor /// /// Null if it would otherwise be empty. /// - public SS14Window Window { get; private set; } + public CharacterWindow? Window { get; private set; } - private List _uiComponents; + private List? _uiComponents; /// /// Create the window with all character UIs and bind it to a keypress @@ -58,10 +58,13 @@ namespace Content.Client.GameObjects.Components.Actor { base.OnRemove(); - foreach (var component in _uiComponents) + if (_uiComponents != null) { - // Make sure these don't get deleted when the window is disposed. - component.Scene.Orphan(); + foreach (var component in _uiComponents) + { + // Make sure these don't get deleted when the window is disposed. + component.Scene.Orphan(); + } } _uiComponents = null; @@ -73,7 +76,7 @@ namespace Content.Client.GameObjects.Components.Actor inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null); } - public override void HandleMessage(ComponentMessage message, IComponent component) + public override void HandleMessage(ComponentMessage message, IComponent? component) { base.HandleMessage(message, component); diff --git a/Content.Client/GameObjects/Components/Arcade/BlockGameBoundUserInterface.cs b/Content.Client/GameObjects/Components/Arcade/BlockGameBoundUserInterface.cs index 1cbf2b1c7e..68e795eda8 100644 --- a/Content.Client/GameObjects/Components/Arcade/BlockGameBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Arcade/BlockGameBoundUserInterface.cs @@ -1,6 +1,5 @@ using Content.Client.Arcade; using Content.Shared.Arcade; -using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; @@ -8,9 +7,9 @@ namespace Content.Client.GameObjects.Components.Arcade { public class BlockGameBoundUserInterface : BoundUserInterface { - private BlockGameMenu _menu; + private BlockGameMenu? _menu; - public BlockGameBoundUserInterface([NotNull] ClientUserInterfaceComponent owner, [NotNull] object uiKey) : base(owner, uiKey) + public BlockGameBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } diff --git a/Content.Client/GameObjects/Components/Arcade/SpaceVillainArcadeBoundUserInterface.cs b/Content.Client/GameObjects/Components/Arcade/SpaceVillainArcadeBoundUserInterface.cs index 48ca2f4f7c..41475f45b2 100644 --- a/Content.Client/GameObjects/Components/Arcade/SpaceVillainArcadeBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Arcade/SpaceVillainArcadeBoundUserInterface.cs @@ -1,26 +1,25 @@ using Content.Client.Arcade; -using Content.Shared.GameObjects.Components.Arcade; -using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.ViewVariables; +using static Content.Shared.GameObjects.Components.Arcade.SharedSpaceVillainArcadeComponent; namespace Content.Client.GameObjects.Components.Arcade { public class SpaceVillainArcadeBoundUserInterface : BoundUserInterface { - [ViewVariables] private SpaceVillainArcadeMenu _menu; + [ViewVariables] private SpaceVillainArcadeMenu? _menu; //public SharedSpaceVillainArcadeComponent SpaceVillainArcade; - public SpaceVillainArcadeBoundUserInterface([NotNull] ClientUserInterfaceComponent owner, [NotNull] object uiKey) : base(owner, uiKey) + public SpaceVillainArcadeBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - SendAction(SharedSpaceVillainArcadeComponent.PlayerAction.RequestData); + SendAction(PlayerAction.RequestData); } - public void SendAction(SharedSpaceVillainArcadeComponent.PlayerAction action) + public void SendAction(PlayerAction action) { - SendMessage(new SharedSpaceVillainArcadeComponent.SpaceVillainArcadePlayerActionMessage(action)); + SendMessage(new SpaceVillainArcadePlayerActionMessage(action)); } protected override void Open() @@ -42,16 +41,14 @@ namespace Content.Client.GameObjects.Components.Arcade protected override void ReceiveMessage(BoundUserInterfaceMessage message) { - if(message is SharedSpaceVillainArcadeComponent.SpaceVillainArcadeDataUpdateMessage msg) _menu.UpdateInfo(msg); + if (message is SpaceVillainArcadeDataUpdateMessage msg) _menu?.UpdateInfo(msg); } protected override void Dispose(bool disposing) { base.Dispose(disposing); - if (!disposing) - return; - _menu?.Dispose(); + if (disposing) _menu?.Dispose(); } } } diff --git a/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs index 1a8da1956c..9a190686ba 100644 --- a/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/FireVisualizer.cs @@ -3,8 +3,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Atmos { @@ -13,12 +11,15 @@ namespace Content.Client.GameObjects.Components.Atmos { [DataField("fireStackAlternateState")] private int _fireStackAlternateState = 3; + [DataField("normalState")] - private string _normalState; + private string? _normalState; + [DataField("alternateState")] - private string _alternateState; + private string? _alternateState; + [DataField("sprite")] - private string _sprite; + private string? _sprite; public override void InitializeEntity(IEntity entity) { @@ -49,7 +50,11 @@ namespace Content.Client.GameObjects.Components.Atmos { var sprite = component.Owner.GetComponent(); - sprite.LayerSetRSI(FireVisualLayers.Fire, _sprite); + if (_sprite != null) + { + sprite.LayerSetRSI(FireVisualLayers.Fire, _sprite); + } + sprite.LayerSetVisible(FireVisualLayers.Fire, onFire); if(fireStacks > _fireStackAlternateState && !string.IsNullOrEmpty(_alternateState)) diff --git a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerBoundUserInterface.cs b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerBoundUserInterface.cs index 3214e07971..98d07f1ef9 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerBoundUserInterface.cs @@ -10,13 +10,13 @@ namespace Content.Client.GameObjects.Components.Atmos { } - private GasAnalyzerWindow _menu; + private GasAnalyzerWindow? _menu; protected override void Open() { base.Open(); - _menu = new GasAnalyzerWindow(this); + _menu = new GasAnalyzerWindow(this); _menu.OnClose += Close; _menu.OpenCentered(); } @@ -24,7 +24,8 @@ namespace Content.Client.GameObjects.Components.Atmos protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _menu.Populate((GasAnalyzerBoundUserInterfaceState) state); + + _menu?.Populate((GasAnalyzerBoundUserInterfaceState) state); } public void Refresh() @@ -35,10 +36,8 @@ namespace Content.Client.GameObjects.Components.Atmos protected override void Dispose(bool disposing) { base.Dispose(disposing); - if (!disposing) - return; - _menu?.Dispose(); + if (disposing) _menu?.Dispose(); } } } diff --git a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs index 12c4e15082..1a74adb679 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs @@ -1,5 +1,4 @@ -using System; -using Content.Client.UserInterface.Stylesheets; +using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.GameObjects.Components; using Robust.Client.UserInterface; @@ -22,7 +21,7 @@ namespace Content.Client.GameObjects.Components.Atmos return new StatusControl(this); } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { if (curState is not GasAnalyzerComponentState state) return; @@ -55,15 +54,17 @@ namespace Content.Client.GameObjects.Components.Atmos } _parent._uiUpdateNeeded = false; + var color = _parent.Danger switch { GasAnalyzerDanger.Warning => "orange", GasAnalyzerDanger.Hazard => "red", _ => "green", }; + _label.SetMarkup(Loc.GetString("Pressure: [color={0}]{1}[/color]", color, - Enum.GetName(typeof(GasAnalyzerDanger), _parent.Danger))); + _parent.Danger)); } } } diff --git a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs index c642fa86af..61e5e55426 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs @@ -2,8 +2,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Atmos { @@ -11,9 +9,9 @@ namespace Content.Client.GameObjects.Components.Atmos public class GasAnalyzerVisualizer : AppearanceVisualizer { [DataField("state_off")] - private string _stateOff; + private string? _stateOff; [DataField("state_working")] - private string _stateWorking; + private string? _stateWorking; public override void OnChangeData(AppearanceComponent component) { @@ -24,7 +22,7 @@ namespace Content.Client.GameObjects.Components.Atmos return; } - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } @@ -39,8 +37,6 @@ namespace Content.Client.GameObjects.Components.Atmos case GasAnalyzerVisualState.Working: sprite.LayerSetState(0, _stateWorking); break; - default: - break; } } } diff --git a/Content.Client/GameObjects/Components/Atmos/GasCanisterBoundUserInterface.cs b/Content.Client/GameObjects/Components/Atmos/GasCanisterBoundUserInterface.cs index ac13290e9e..ef612c0342 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasCanisterBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasCanisterBoundUserInterface.cs @@ -1,6 +1,5 @@ -#nullable enable +using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; -using Content.Shared.GameObjects.Components.Atmos; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Localization; diff --git a/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs index b513445401..2fc18cd9b9 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasCanisterVisualizer.cs @@ -2,15 +2,14 @@ using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Atmos { public class GasCanisterVisualizer : AppearanceVisualizer { [DataField("stateConnected")] - private string _stateConnected; + private string? _stateConnected; + [DataField("pressureStates")] private string[] _statePressure = new string[] {"", "", "", ""}; @@ -20,11 +19,14 @@ namespace Content.Client.GameObjects.Components.Atmos var sprite = entity.GetComponent(); - sprite.LayerMapSet(Layers.ConnectedToPort, sprite.AddLayerState(_stateConnected)); - sprite.LayerSetVisible(Layers.ConnectedToPort, false); + if (_stateConnected != null) + { + sprite.LayerMapSet(Layers.ConnectedToPort, sprite.AddLayerState(_stateConnected)); + sprite.LayerSetVisible(Layers.ConnectedToPort, false); - sprite.LayerMapSet(Layers.PressureLight, sprite.AddLayerState(_stateConnected)); - sprite.LayerSetShader(Layers.PressureLight, "unshaded"); + sprite.LayerMapSet(Layers.PressureLight, sprite.AddLayerState(_stateConnected)); + sprite.LayerSetShader(Layers.PressureLight, "unshaded"); + } } public override void OnChangeData(AppearanceComponent component) @@ -36,7 +38,7 @@ namespace Content.Client.GameObjects.Components.Atmos return; } - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/Atmos/GasCanisterWindow.cs b/Content.Client/GameObjects/Components/Atmos/GasCanisterWindow.cs index 50e630db19..7c5ed69956 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasCanisterWindow.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasCanisterWindow.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.Linq; +using Content.Shared.GameObjects.Components.Atmos; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Localization; using Robust.Shared.Maths; -using Content.Shared.GameObjects.Components.Atmos; namespace Content.Client.GameObjects.Components.Atmos { @@ -49,7 +49,7 @@ namespace Content.Client.GameObjects.Components.Atmos Children = { new Label(){ Text = Loc.GetString("Label: ") }, - (LabelInput = new LineEdit() { Text = Name, Editable = false, + (LabelInput = new LineEdit() { Text = Name ?? "", Editable = false, MinSize = new Vector2(200, 30)}), (EditLabelBtn = new Button()), } diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs index 938c9d209f..b6cee19c6c 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/GasFilterVisualizer.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Atmos; using JetBrains.Annotations; using Robust.Client.GameObjects; diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs index 2e14e86eb1..e57ebf5ca4 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/PumpVisualizer.cs @@ -16,7 +16,7 @@ namespace Content.Client.GameObjects.Components.Atmos.Piping { base.InitializeEntity(entity); - if (!entity.TryGetComponent(out ISpriteComponent sprite)) return; + if (!entity.TryGetComponent(out ISpriteComponent? sprite)) return; sprite.LayerMapReserveBlank(Layer.PumpEnabled); var pumpEnabledLayer = sprite.LayerMapGet(Layer.PumpEnabled); @@ -27,7 +27,7 @@ namespace Content.Client.GameObjects.Components.Atmos.Piping { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) return; + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; if (!component.TryGetData(PumpVisuals.VisualState, out PumpVisualState pumpVisualState)) return; var pumpEnabledLayer = sprite.LayerMapGet(Layer.PumpEnabled); diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs index 488d742950..815fd6cee5 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/SiphonVisualizer.cs @@ -16,7 +16,7 @@ namespace Content.Client.GameObjects.Components.Atmos.Piping { base.InitializeEntity(entity); - if (!entity.TryGetComponent(out ISpriteComponent sprite)) return; + if (!entity.TryGetComponent(out ISpriteComponent? sprite)) return; sprite.LayerMapReserveBlank(Layer.SiphonEnabled); var layer = sprite.LayerMapGet(Layer.SiphonEnabled); @@ -27,7 +27,7 @@ namespace Content.Client.GameObjects.Components.Atmos.Piping { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) return; + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; if (!component.TryGetData(SiphonVisuals.VisualState, out SiphonVisualState siphonVisualState)) return; var layer = sprite.LayerMapGet(Layer.SiphonEnabled); diff --git a/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs index 3d8790bb62..8603544152 100644 --- a/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/Piping/VentVisualizer.cs @@ -16,7 +16,7 @@ namespace Content.Client.GameObjects.Components.Atmos.Piping { base.InitializeEntity(entity); - if (!entity.TryGetComponent(out ISpriteComponent sprite)) return; + if (!entity.TryGetComponent(out ISpriteComponent? sprite)) return; sprite.LayerMapReserveBlank(Layer.VentEnabled); var layer = sprite.LayerMapGet(Layer.VentEnabled); @@ -27,7 +27,7 @@ namespace Content.Client.GameObjects.Components.Atmos.Piping { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) return; + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) return; if (!component.TryGetData(VentVisuals.VisualState, out VentVisualState ventVisualState)) return; var layer = sprite.LayerMapGet(Layer.VentEnabled); diff --git a/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs index 48d2c9431b..96217df375 100644 --- a/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs +++ b/Content.Client/GameObjects/Components/Atmos/VaporVisualizer.cs @@ -20,7 +20,7 @@ namespace Content.Client.GameObjects.Components.Atmos [DataField("animation_state")] private string _state = "chempuff"; - private Animation VaporFlick; + private Animation VaporFlick = default!; void ISerializationHooks.AfterDeserialization() { diff --git a/Content.Client/GameObjects/Components/Body/BodyComponent.cs b/Content.Client/GameObjects/Components/Body/BodyComponent.cs index 737a6cb78b..0687f213b1 100644 --- a/Content.Client/GameObjects/Components/Body/BodyComponent.cs +++ b/Content.Client/GameObjects/Components/Body/BodyComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Body; +using Content.Shared.GameObjects.Components.Body; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Body/Mechanism/MechanismComponent.cs b/Content.Client/GameObjects/Components/Body/Mechanism/MechanismComponent.cs index 191ee99c96..72f7e114d8 100644 --- a/Content.Client/GameObjects/Components/Body/Mechanism/MechanismComponent.cs +++ b/Content.Client/GameObjects/Components/Body/Mechanism/MechanismComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Body.Mechanism; +using Content.Shared.GameObjects.Components.Body.Mechanism; using Robust.Shared.GameObjects; namespace Content.Client.GameObjects.Components.Body.Mechanism diff --git a/Content.Client/GameObjects/Components/Body/Part/BodyPartComponent.cs b/Content.Client/GameObjects/Components/Body/Part/BodyPartComponent.cs index 4dc2156248..718e70c669 100644 --- a/Content.Client/GameObjects/Components/Body/Part/BodyPartComponent.cs +++ b/Content.Client/GameObjects/Components/Body/Part/BodyPartComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Body.Part; +using Content.Shared.GameObjects.Components.Body.Part; using Robust.Shared.GameObjects; namespace Content.Client.GameObjects.Components.Body.Part diff --git a/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerBoundUserInterface.cs b/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerBoundUserInterface.cs index 269750561a..178a9d727a 100644 --- a/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerBoundUserInterface.cs @@ -11,10 +11,10 @@ namespace Content.Client.GameObjects.Components.Body.Scanner public class BodyScannerBoundUserInterface : BoundUserInterface { [ViewVariables] - private BodyScannerDisplay _display; + private BodyScannerDisplay? _display; [ViewVariables] - private IEntity _entity; + private IEntity? _entity; public BodyScannerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } @@ -40,7 +40,7 @@ namespace Content.Client.GameObjects.Components.Body.Scanner throw new ArgumentException($"Received an invalid entity with id {scannerState.Uid} for body scanner with id {Owner.Owner.Uid} at {Owner.Owner.Transform.MapPosition}"); } - _display.UpdateDisplay(_entity); + _display?.UpdateDisplay(_entity); } protected override void Dispose(bool disposing) diff --git a/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerDisplay.cs b/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerDisplay.cs index 1d26c69c37..4efe1a96f3 100644 --- a/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerDisplay.cs +++ b/Content.Client/GameObjects/Components/Body/Scanner/BodyScannerDisplay.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Linq; +using System.Linq; using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Body.Mechanism; using Content.Shared.GameObjects.Components.Body.Part; diff --git a/Content.Client/GameObjects/Components/Body/Surgery/SurgeryBoundUserInterface.cs b/Content.Client/GameObjects/Components/Body/Surgery/SurgeryBoundUserInterface.cs index 44d6162343..46ed53c954 100644 --- a/Content.Client/GameObjects/Components/Body/Surgery/SurgeryBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Body/Surgery/SurgeryBoundUserInterface.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Body.Surgery; +using Content.Shared.GameObjects.Components.Body.Surgery; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Body/Surgery/SurgeryWindow.cs b/Content.Client/GameObjects/Components/Body/Surgery/SurgeryWindow.cs index 4b428007c8..4940e0463f 100644 --- a/Content.Client/GameObjects/Components/Body/Surgery/SurgeryWindow.cs +++ b/Content.Client/GameObjects/Components/Body/Surgery/SurgeryWindow.cs @@ -13,7 +13,7 @@ namespace Content.Client.GameObjects.Components.Body.Surgery public delegate void OptionSelectedCallback(int selectedOptionData); private readonly VBoxContainer _optionsBox; - private OptionSelectedCallback _optionSelectedCallback; + private OptionSelectedCallback? _optionSelectedCallback; public SurgeryWindow() { @@ -65,7 +65,7 @@ namespace Content.Client.GameObjects.Components.Body.Surgery { if (args.Button.Parent is SurgeryButton surgery) { - _optionSelectedCallback(surgery.CallbackData); + _optionSelectedCallback?.Invoke(surgery.CallbackData); } } } diff --git a/Content.Client/GameObjects/Components/Buckle/BuckleVisualizer.cs b/Content.Client/GameObjects/Components/Buckle/BuckleVisualizer.cs index 6f10052a65..adfc5369d0 100644 --- a/Content.Client/GameObjects/Components/Buckle/BuckleVisualizer.cs +++ b/Content.Client/GameObjects/Components/Buckle/BuckleVisualizer.cs @@ -32,7 +32,7 @@ namespace Content.Client.GameObjects.Components.Buckle { var sprite = component.Owner.GetComponent(); - if (!sprite.Owner.TryGetComponent(out AnimationPlayerComponent animation)) + if (!sprite.Owner.TryGetComponent(out AnimationPlayerComponent? animation)) { sprite.Rotation = rotation; return; diff --git a/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs b/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs index 14f7295bbf..8ffac19330 100644 --- a/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Cargo/CargoConsoleBoundUserInterface.cs @@ -2,35 +2,43 @@ using Content.Shared.GameObjects.Components.Cargo; using Content.Shared.Prototypes.Cargo; using Robust.Client.GameObjects; -using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; using Robust.Shared.ViewVariables; +using static Content.Shared.GameObjects.Components.Cargo.SharedCargoConsoleComponent; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.GameObjects.Components.Cargo { public class CargoConsoleBoundUserInterface : BoundUserInterface { [ViewVariables] - private CargoConsoleMenu _menu; - [ViewVariables] - private CargoConsoleOrderMenu _orderMenu; + private CargoConsoleMenu? _menu; [ViewVariables] - public GalacticMarketComponent Market { get; private set; } + private CargoConsoleOrderMenu? _orderMenu; + [ViewVariables] - public CargoOrderDatabaseComponent Orders { get; private set; } + public GalacticMarketComponent? Market { get; private set; } + + [ViewVariables] + public CargoOrderDatabaseComponent? Orders { get; private set; } + [ViewVariables] public bool RequestOnly { get; private set; } + [ViewVariables] public int BankId { get; private set; } + [ViewVariables] - public string BankName { get; private set; } + public string? BankName { get; private set; } + [ViewVariables] public int BankBalance { get; private set; } + [ViewVariables] public (int CurrentCapacity, int MaxCapacity) ShuttleCapacity { get; private set; } - private CargoProductPrototype _product; + private CargoProductPrototype? _product; public CargoConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { @@ -40,8 +48,8 @@ namespace Content.Client.GameObjects.Components.Cargo { base.Open(); - if (!Owner.Owner.TryGetComponent(out GalacticMarketComponent market) - || !Owner.Owner.TryGetComponent(out CargoOrderDatabaseComponent orders)) return; + if (!Owner.Owner.TryGetComponent(out GalacticMarketComponent? market) || + !Owner.Owner.TryGetComponent(out CargoOrderDatabaseComponent? orders)) return; Market = market; Orders = orders; @@ -57,23 +65,23 @@ namespace Content.Client.GameObjects.Components.Cargo Market.OnDatabaseUpdated += _menu.PopulateCategories; Orders.OnDatabaseUpdated += _menu.PopulateOrders; - _menu.CallShuttleButton.OnPressed += (args) => + _menu.CallShuttleButton.OnPressed += (_) => { - SendMessage(new SharedCargoConsoleComponent.CargoConsoleShuttleMessage()); + SendMessage(new CargoConsoleShuttleMessage()); }; _menu.OnItemSelected += (args) => { if (args.Button.Parent is not CargoProductRow row) return; _product = row.Product; - _orderMenu.Requester.Text = null; - _orderMenu.Reason.Text = null; + _orderMenu.Requester.Text = ""; + _orderMenu.Reason.Text = ""; _orderMenu.Amount.Value = 1; _orderMenu.OpenCentered(); }; _menu.OnOrderApproved += ApproveOrder; _menu.OnOrderCanceled += RemoveOrder; - _orderMenu.SubmitButton.OnPressed += (args) => + _orderMenu.SubmitButton.OnPressed += (_) => { AddOrder(); _orderMenu.Close(); @@ -92,47 +100,63 @@ namespace Content.Client.GameObjects.Components.Cargo if (RequestOnly != cState.RequestOnly) { RequestOnly = cState.RequestOnly; - _menu.UpdateRequestOnly(); + _menu?.UpdateRequestOnly(); } BankId = cState.BankId; BankName = cState.BankName; BankBalance = cState.BankBalance; ShuttleCapacity = cState.ShuttleCapacity; - _menu.UpdateCargoCapacity(); - _menu.UpdateBankData(); + _menu?.UpdateCargoCapacity(); + _menu?.UpdateBankData(); } protected override void Dispose(bool disposing) { base.Dispose(disposing); + if (!disposing) return; - Market.OnDatabaseUpdated -= _menu.PopulateProducts; - Market.OnDatabaseUpdated -= _menu.PopulateCategories; - Orders.OnDatabaseUpdated -= _menu.PopulateOrders; + + if (Market != null && _menu != null) + { + Market.OnDatabaseUpdated -= _menu.PopulateProducts; + Market.OnDatabaseUpdated -= _menu.PopulateCategories; + } + + if (Orders != null && _menu != null) + { + Orders.OnDatabaseUpdated -= _menu.PopulateOrders; + } + _menu?.Dispose(); _orderMenu?.Dispose(); } - internal void AddOrder() + private void AddOrder() { - SendMessage(new SharedCargoConsoleComponent.CargoConsoleAddOrderMessage(_orderMenu.Requester.Text, - _orderMenu.Reason.Text, _product.ID, _orderMenu.Amount.Value)); + SendMessage(new CargoConsoleAddOrderMessage( + _orderMenu?.Requester.Text ?? "", + _orderMenu?.Reason.Text ?? "", + _product?.ID ?? "", + _orderMenu?.Amount.Value ?? 0)); } - internal void RemoveOrder(BaseButton.ButtonEventArgs args) + private void RemoveOrder(ButtonEventArgs args) { - if (args.Button.Parent.Parent is not CargoOrderRow row) + if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null) return; - SendMessage(new SharedCargoConsoleComponent.CargoConsoleRemoveOrderMessage(row.Order.OrderNumber)); + + SendMessage(new CargoConsoleRemoveOrderMessage(row.Order.OrderNumber)); } - internal void ApproveOrder(BaseButton.ButtonEventArgs args) + private void ApproveOrder(ButtonEventArgs args) { - if (args.Button.Parent.Parent is not CargoOrderRow row) + if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null) return; + if (ShuttleCapacity.CurrentCapacity == ShuttleCapacity.MaxCapacity) return; - SendMessage(new SharedCargoConsoleComponent.CargoConsoleApproveOrderMessage(row.Order.OrderNumber)); + + SendMessage(new CargoConsoleApproveOrderMessage(row.Order.OrderNumber)); _menu?.UpdateCargoCapacity(); } } diff --git a/Content.Client/GameObjects/Components/Cargo/CargoOrderDatabaseComponent.cs b/Content.Client/GameObjects/Components/Cargo/CargoOrderDatabaseComponent.cs index 413a01f7e8..d0f8963deb 100644 --- a/Content.Client/GameObjects/Components/Cargo/CargoOrderDatabaseComponent.cs +++ b/Content.Client/GameObjects/Components/Cargo/CargoOrderDatabaseComponent.cs @@ -15,7 +15,7 @@ namespace Content.Client.GameObjects.Components.Cargo /// /// Event called when the database is updated. /// - public event Action OnDatabaseUpdated; + public event Action? OnDatabaseUpdated; // TODO add account selector menu @@ -37,7 +37,7 @@ namespace Content.Client.GameObjects.Components.Cargo _orders.Add(order); } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); if (curState is not CargoOrderDatabaseState state) diff --git a/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs b/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs index 25eb0f1efa..0f3293af4e 100644 --- a/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs +++ b/Content.Client/GameObjects/Components/Cargo/GalacticMarketComponent.cs @@ -15,9 +15,9 @@ namespace Content.Client.GameObjects.Components.Cargo /// /// Event called when the database is updated. /// - public event Action OnDatabaseUpdated; + public event Action? OnDatabaseUpdated; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); if (curState is not GalacticMarketState state) @@ -25,7 +25,7 @@ namespace Content.Client.GameObjects.Components.Cargo _productIds.Clear(); foreach (var productId in state.Products) { - if (!_prototypeManager.TryIndex(productId, out CargoProductPrototype product)) + if (!_prototypeManager.TryIndex(productId, out CargoProductPrototype? product)) continue; _products.Add(product); } diff --git a/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterBoundUserInterface.cs b/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterBoundUserInterface.cs index c3ef2f0855..fa8e504b06 100644 --- a/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterBoundUserInterface.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Chemistry.ReagentDispenser; using JetBrains.Annotations; using Robust.Client.GameObjects; diff --git a/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterWindow.cs b/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterWindow.cs index a688359017..b88537ef2b 100644 --- a/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterWindow.cs +++ b/Content.Client/GameObjects/Components/Chemistry/ChemMaster/ChemMasterWindow.cs @@ -13,6 +13,7 @@ using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Prototypes; using static Content.Shared.GameObjects.Components.Chemistry.ChemMaster.SharedChemMasterComponent; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.GameObjects.Components.Chemistry.ChemMaster { @@ -38,7 +39,7 @@ namespace Content.Client.GameObjects.Components.Chemistry.ChemMaster public bool BufferModeTransfer = true; - public event Action OnChemButtonPressed; + public event Action? OnChemButtonPressed; public HBoxContainer PillInfo { get; set; } public HBoxContainer BottleInfo { get; set; } @@ -331,7 +332,7 @@ namespace Content.Client.GameObjects.Components.Chemistry.ChemMaster { var name = Loc.GetString("Unknown reagent"); //Try to the prototype for the given reagent. This gives us it's name. - if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto)) + if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto)) { name = proto.Name; } @@ -386,7 +387,7 @@ namespace Content.Client.GameObjects.Components.Chemistry.ChemMaster { var name = Loc.GetString("Unknown reagent"); //Try to the prototype for the given reagent. This gives us it's name. - if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto)) + if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto)) { name = proto.Name; } diff --git a/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs b/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs index bc78ab2b32..662a55f629 100644 --- a/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs +++ b/Content.Client/GameObjects/Components/Chemistry/FoamVisualizer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using Content.Shared.GameObjects.Components.Chemistry; using JetBrains.Annotations; using Robust.Client.Animations; diff --git a/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs b/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs index 979d371e62..2d1ff9cdb5 100644 --- a/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs +++ b/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs @@ -9,8 +9,6 @@ using Robust.Shared.Localization; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; -#nullable enable - namespace Content.Client.GameObjects.Components.Chemistry { [RegisterComponent] diff --git a/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs b/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs index 3a35e7f266..ca9f99dbaf 100644 --- a/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs +++ b/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs @@ -27,7 +27,7 @@ namespace Content.Client.GameObjects.Components.Chemistry void IItemStatus.DestroyControl(Control control) { } //Handle net updates - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { if (curState is not InjectorComponentState state) { diff --git a/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserBoundUserInterface.cs b/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserBoundUserInterface.cs index 1131010509..6f6b70b04e 100644 --- a/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserBoundUserInterface.cs @@ -16,12 +16,11 @@ namespace Content.Client.GameObjects.Components.Chemistry.ReagentDispenser [UsedImplicitly] public class ReagentDispenserBoundUserInterface : BoundUserInterface { - private ReagentDispenserWindow _window; - private ReagentDispenserBoundUserInterfaceState _lastState; + private ReagentDispenserWindow? _window; + private ReagentDispenserBoundUserInterfaceState? _lastState; public ReagentDispenserBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - } /// @@ -80,8 +79,14 @@ namespace Content.Client.GameObjects.Components.Chemistry.ReagentDispenser /// A list of the reagents which can be dispensed. private void UpdateReagentsList(List inventory) { + if (_window == null) + { + return; + } + _window.UpdateReagentsList(inventory); - for (int i = 0; i < _window.ChemicalList.Children.Count(); i++) + + for (var i = 0; i < _window.ChemicalList.Children.Count(); i++) { var button = (Button)_window.ChemicalList.Children.ElementAt(i); var i1 = i; diff --git a/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserWindow.cs b/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserWindow.cs index 773a54238b..e0e5930aa7 100644 --- a/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserWindow.cs +++ b/Content.Client/GameObjects/Components/Chemistry/ReagentDispenser/ReagentDispenserWindow.cs @@ -157,7 +157,7 @@ namespace Content.Client.GameObjects.Components.Chemistry.ReagentDispenser foreach (var entry in inventory) { - if (_prototypeManager.TryIndex(entry.ID, out ReagentPrototype proto)) + if (_prototypeManager.TryIndex(entry.ID, out ReagentPrototype? proto)) { ChemicalList.AddChild(new Button {Text = proto.Name}); } @@ -253,8 +253,7 @@ namespace Content.Client.GameObjects.Components.Chemistry.ReagentDispenser /// /// State data for the dispenser. /// Prototype id of the reagent whose dispense button is currently being mouse hovered. - public void UpdateContainerInfo(ReagentDispenserBoundUserInterfaceState state, - string highlightedReagentId = null) + public void UpdateContainerInfo(ReagentDispenserBoundUserInterfaceState state, string highlightedReagentId = "") { ContainerInfo.Children.Clear(); @@ -286,7 +285,7 @@ namespace Content.Client.GameObjects.Components.Chemistry.ReagentDispenser { var name = Loc.GetString("Unknown reagent"); //Try to the prototype for the given reagent. This gives us it's name. - if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto)) + if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype? proto)) { name = proto.Name; } diff --git a/Content.Client/GameObjects/Components/Chemistry/SmokeVisualizer.cs b/Content.Client/GameObjects/Components/Chemistry/SmokeVisualizer.cs index c6b45de4e0..a39b8494f4 100644 --- a/Content.Client/GameObjects/Components/Chemistry/SmokeVisualizer.cs +++ b/Content.Client/GameObjects/Components/Chemistry/SmokeVisualizer.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Chemistry; +using Content.Shared.GameObjects.Components.Chemistry; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Maths; diff --git a/Content.Client/GameObjects/Components/Chemistry/SolutionContainerComponent.cs b/Content.Client/GameObjects/Components/Chemistry/SolutionContainerComponent.cs index cb1e8e61d1..d635cb3c78 100644 --- a/Content.Client/GameObjects/Components/Chemistry/SolutionContainerComponent.cs +++ b/Content.Client/GameObjects/Components/Chemistry/SolutionContainerComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Chemistry; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/ClickableComponent.cs b/Content.Client/GameObjects/Components/ClickableComponent.cs index c9a695df18..a1f104b989 100644 --- a/Content.Client/GameObjects/Components/ClickableComponent.cs +++ b/Content.Client/GameObjects/Components/ClickableComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using Robust.Client.GameObjects; using Robust.Client.Graphics; diff --git a/Content.Client/GameObjects/Components/CloningPod/CloningPodBoundUserInterface.cs b/Content.Client/GameObjects/Components/CloningPod/CloningPodBoundUserInterface.cs index 6efcbf6936..6d5376f90c 100644 --- a/Content.Client/GameObjects/Components/CloningPod/CloningPodBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/CloningPod/CloningPodBoundUserInterface.cs @@ -13,7 +13,7 @@ namespace Content.Client.GameObjects.Components.CloningPod { } - private CloningPodWindow _window; + private CloningPodWindow? _window; protected override void Open() { @@ -39,7 +39,8 @@ namespace Content.Client.GameObjects.Components.CloningPod protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _window.Populate((CloningPodBoundUserInterfaceState) state); + + _window?.Populate((CloningPodBoundUserInterfaceState) state); } protected override void Dispose(bool disposing) diff --git a/Content.Client/GameObjects/Components/CloningPod/CloningPodWindow.cs b/Content.Client/GameObjects/Components/CloningPod/CloningPodWindow.cs index 9be78d069b..b64f123a2b 100644 --- a/Content.Client/GameObjects/Components/CloningPod/CloningPodWindow.cs +++ b/Content.Client/GameObjects/Components/CloningPod/CloningPodWindow.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; diff --git a/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs b/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs index fcd17cb0f0..9ae32a580d 100644 --- a/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs +++ b/Content.Client/GameObjects/Components/Clothing/ClothingComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Client.GameObjects.Components.HUD.Inventory; +using Content.Client.GameObjects.Components.HUD.Inventory; using Content.Client.GameObjects.Components.Items; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Inventory; @@ -70,6 +69,12 @@ namespace Content.Client.GameObjects.Components.Clothing } var rsi = GetRSI(); + + if (rsi == null) + { + return null; + } + var prefix = ClothingEquippedPrefix ?? EquippedPrefix; var stateId = prefix != null ? $"{prefix}-equipped-{slot}" : $"equipped-{slot}"; if (rsi.TryGetState(stateId, out _)) diff --git a/Content.Client/GameObjects/Components/Command/CommunicationsConsoleBoundUserInterface.cs b/Content.Client/GameObjects/Components/Command/CommunicationsConsoleBoundUserInterface.cs index 70320c19c1..210aabd491 100644 --- a/Content.Client/GameObjects/Components/Command/CommunicationsConsoleBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Command/CommunicationsConsoleBoundUserInterface.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using Content.Client.Command; using Content.Shared.GameObjects.Components.Command; using Robust.Client.GameObjects; diff --git a/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs b/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs index d5c15f6c36..58760b27bf 100644 --- a/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Configuration/ConfigurationBoundUserInterface.cs @@ -4,17 +4,17 @@ using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using static Content.Shared.GameObjects.Components.SharedConfigurationComponent; -namespace Content.Client.GameObjects.Components.Wires +namespace Content.Client.GameObjects.Components.Configuration { public class ConfigurationBoundUserInterface : BoundUserInterface { - public Regex Validation { get; internal set; } + public Regex? Validation { get; internal set; } public ConfigurationBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } - private ConfigurationMenu _menu; + private ConfigurationMenu? _menu; protected override void Open() { @@ -28,12 +28,19 @@ namespace Content.Client.GameObjects.Components.Wires protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _menu.Populate(state as ConfigurationBoundUserInterfaceState); + + if (state is not ConfigurationBoundUserInterfaceState configurationState) + { + return; + } + + _menu?.Populate(configurationState); } protected override void ReceiveMessage(BoundUserInterfaceMessage message) { base.ReceiveMessage(message); + if (message is ValidationUpdateMessage msg) { Validation = new Regex(msg.ValidationString, RegexOptions.Compiled); @@ -49,8 +56,11 @@ namespace Content.Client.GameObjects.Components.Wires { base.Dispose(disposing); - _menu.OnClose -= Close; - _menu.Close(); + if (disposing && _menu != null) + { + _menu.OnClose -= Close; + _menu.Close(); + } } } } diff --git a/Content.Client/GameObjects/Components/Configuration/ConfigurationMenu.cs b/Content.Client/GameObjects/Components/Configuration/ConfigurationMenu.cs index 22886b426b..ea5acde10b 100644 --- a/Content.Client/GameObjects/Components/Configuration/ConfigurationMenu.cs +++ b/Content.Client/GameObjects/Components/Configuration/ConfigurationMenu.cs @@ -7,7 +7,7 @@ using Robust.Shared.Maths; using static Content.Shared.GameObjects.Components.SharedConfigurationComponent; using static Robust.Client.UserInterface.Controls.BaseButton; -namespace Content.Client.GameObjects.Components.Wires +namespace Content.Client.GameObjects.Components.Configuration { public class ConfigurationMenu : SS14Window { diff --git a/Content.Client/GameObjects/Components/Construction/ConstructionGhostComponent.cs b/Content.Client/GameObjects/Components/Construction/ConstructionGhostComponent.cs index 9563a63bfd..0505bac60e 100644 --- a/Content.Client/GameObjects/Components/Construction/ConstructionGhostComponent.cs +++ b/Content.Client/GameObjects/Components/Construction/ConstructionGhostComponent.cs @@ -16,14 +16,16 @@ namespace Content.Client.GameObjects.Components.Construction public override string Name => "ConstructionGhost"; - [ViewVariables] public ConstructionPrototype Prototype { get; set; } - [ViewVariables] public int GhostID { get; set; } + [ViewVariables] public ConstructionPrototype? Prototype { get; set; } + [ViewVariables] public int GhostId { get; set; } void IExamine.Examine(FormattedMessage message, bool inDetailsRange) { + if (Prototype == null) return; + message.AddMarkup(Loc.GetString("Building: [color=cyan]{0}[/color]\n", Prototype.Name)); - if (!_prototypeManager.TryIndex(Prototype.Graph, out ConstructionGraphPrototype graph)) return; + if (!_prototypeManager.TryIndex(Prototype.Graph, out ConstructionGraphPrototype? graph)) return; var startNode = graph.Nodes[Prototype.StartNode]; var path = graph.Path(Prototype.StartNode, Prototype.TargetNode); var edge = startNode.GetEdge(path[0].Name); diff --git a/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs b/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs index c1ebda2be2..c660da39e9 100644 --- a/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs +++ b/Content.Client/GameObjects/Components/Conveyor/ConveyorVisualizer.cs @@ -4,8 +4,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Conveyor { @@ -13,15 +11,17 @@ namespace Content.Client.GameObjects.Components.Conveyor public class ConveyorVisualizer : AppearanceVisualizer { [DataField("state_running")] - private string _stateRunning; + private string? _stateRunning; + [DataField("state_stopped")] - private string _stateStopped; + private string? _stateStopped; + [DataField("state_reversed")] - private string _stateReversed; + private string? _stateReversed; private void ChangeState(AppearanceComponent appearance) { - if (!appearance.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs b/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs index df0e390060..8b589ee881 100644 --- a/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs +++ b/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs @@ -3,8 +3,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Conveyor { @@ -12,15 +10,17 @@ namespace Content.Client.GameObjects.Components.Conveyor public class TwoWayLeverVisualizer : AppearanceVisualizer { [DataField("state_forward")] - private string _stateForward; + private string? _stateForward; + [DataField("state_off")] - private string _stateOff; + private string? _stateOff; + [DataField("state_reversed")] - private string _stateReversed; + private string? _stateReversed; private void ChangeState(AppearanceComponent appearance) { - if (!appearance.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/Crayon/CrayonBoundUserInterface.cs b/Content.Client/GameObjects/Components/Crayon/CrayonBoundUserInterface.cs index 131d556752..3f7170a82f 100644 --- a/Content.Client/GameObjects/Components/Crayon/CrayonBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Crayon/CrayonBoundUserInterface.cs @@ -1,9 +1,9 @@ -using Content.Shared.GameObjects.Components; -using Robust.Shared.IoC; -using Robust.Shared.Prototypes; -using System.Linq; +using System.Linq; +using Content.Shared.GameObjects.Components; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Prototypes; namespace Content.Client.GameObjects.Components.Crayon { @@ -13,7 +13,7 @@ namespace Content.Client.GameObjects.Components.Crayon { } - private CrayonWindow _menu; + private CrayonWindow? _menu; protected override void Open() { @@ -31,7 +31,8 @@ namespace Content.Client.GameObjects.Components.Crayon protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _menu.UpdateState((CrayonBoundUserInterfaceState) state); + + _menu?.UpdateState((CrayonBoundUserInterfaceState) state); } public void Select(string state) @@ -43,7 +44,10 @@ namespace Content.Client.GameObjects.Components.Crayon { base.Dispose(disposing); - _menu.Close(); + if (disposing) + { + _menu?.Close(); + } } } } diff --git a/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs b/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs index a58f67e691..5559b22633 100644 --- a/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs +++ b/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs @@ -24,7 +24,7 @@ namespace Content.Client.GameObjects.Components.Crayon return new StatusControl(this); } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { if (curState is not CrayonComponentState state) return; diff --git a/Content.Client/GameObjects/Components/Crayon/CrayonWindow.cs b/Content.Client/GameObjects/Components/Crayon/CrayonWindow.cs index b7d8c22aeb..abf6b806d8 100644 --- a/Content.Client/GameObjects/Components/Crayon/CrayonWindow.cs +++ b/Content.Client/GameObjects/Components/Crayon/CrayonWindow.cs @@ -1,4 +1,5 @@ -using Content.Client.UserInterface.Stylesheets; +using System.Collections.Generic; +using Content.Client.UserInterface.Stylesheets; using Content.Shared.GameObjects.Components; using Robust.Client.Graphics; using Robust.Client.UserInterface.Controls; @@ -7,7 +8,7 @@ using Robust.Client.Utility; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Utility; -using System.Collections.Generic; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.GameObjects.Components.Crayon { @@ -16,8 +17,8 @@ namespace Content.Client.GameObjects.Components.Crayon public CrayonBoundUserInterface Owner { get; } private readonly LineEdit _search; private readonly GridContainer _grid; - private Dictionary _decals; - private string _selected; + private Dictionary? _decals; + private string? _selected; private Color _color; public CrayonWindow(CrayonBoundUserInterface owner) @@ -30,7 +31,7 @@ namespace Content.Client.GameObjects.Components.Crayon Contents.AddChild(vbox); _search = new LineEdit(); - _search.OnTextChanged += (e) => RefreshList(); + _search.OnTextChanged += (_) => RefreshList(); vbox.AddChild(_search); _grid = new GridContainer() @@ -68,7 +69,7 @@ namespace Content.Client.GameObjects.Components.Crayon ToolTip = decal, Modulate = _color }; - button.OnPressed += Button_OnPressed; + button.OnPressed += ButtonOnPressed; if (_selected == decal) { var panelContainer = new PanelContainer() @@ -91,11 +92,14 @@ namespace Content.Client.GameObjects.Components.Crayon } } - private void Button_OnPressed(BaseButton.ButtonEventArgs obj) + private void ButtonOnPressed(ButtonEventArgs obj) { - Owner.Select(obj.Button.Name); - _selected = obj.Button.Name; - RefreshList(); + if (obj.Button.Name != null) + { + Owner.Select(obj.Button.Name); + _selected = obj.Button.Name; + RefreshList(); + } } public void UpdateState(CrayonBoundUserInterfaceState state) diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalMailingUnitBoundUserInterface.cs b/Content.Client/GameObjects/Components/Disposal/DisposalMailingUnitBoundUserInterface.cs index b93fa1f5b5..c250bd010c 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalMailingUnitBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalMailingUnitBoundUserInterface.cs @@ -1,5 +1,4 @@ -#nullable enable -using JetBrains.Annotations; +using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalRouterBoundUserInterface.cs b/Content.Client/GameObjects/Components/Disposal/DisposalRouterBoundUserInterface.cs index 0e53a88ba5..6738859638 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalRouterBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalRouterBoundUserInterface.cs @@ -1,5 +1,4 @@ -#nullable enable -using JetBrains.Annotations; +using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using static Content.Shared.GameObjects.Components.Disposal.SharedDisposalRouterComponent; diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalTaggerBoundUserInterface.cs b/Content.Client/GameObjects/Components/Disposal/DisposalTaggerBoundUserInterface.cs index 174957f16f..a17c96eafc 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalTaggerBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalTaggerBoundUserInterface.cs @@ -1,5 +1,4 @@ -#nullable enable -using JetBrains.Annotations; +using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using static Content.Shared.GameObjects.Components.Disposal.SharedDisposalTaggerComponent; diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalUnitBoundUserInterface.cs b/Content.Client/GameObjects/Components/Disposal/DisposalUnitBoundUserInterface.cs index bd18504c77..ff44d4497b 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalUnitBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalUnitBoundUserInterface.cs @@ -1,5 +1,4 @@ -#nullable enable -using JetBrains.Annotations; +using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using static Content.Shared.GameObjects.Components.Disposal.SharedDisposalUnitComponent; diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs b/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs index 3376101ef5..42b45f06fa 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalUnitVisualizer.cs @@ -15,36 +15,36 @@ namespace Content.Client.GameObjects.Components.Disposal private const string AnimationKey = "disposal_unit_animation"; [DataField("state_anchored", required: true)] - private string _stateAnchored; + private string? _stateAnchored; [DataField("state_unanchored", required: true)] - private string _stateUnAnchored; + private string? _stateUnAnchored; [DataField("state_charging", required: true)] - private string _stateCharging; + private string? _stateCharging; [DataField("overlay_charging", required: true)] - private string _overlayCharging; + private string? _overlayCharging; [DataField("overlay_ready", required: true)] - private string _overlayReady; + private string? _overlayReady; [DataField("overlay_full", required: true)] - private string _overlayFull; + private string? _overlayFull; [DataField("overlay_engaged", required: true)] - private string _overlayEngaged; + private string? _overlayEngaged; [DataField("state_flush", required: true)] - private string _stateFlush; + private string? _stateFlush; [DataField("flush_sound", required: true)] - private string _flushSound; + private string? _flushSound; [DataField("flush_time", required: true)] private float _flushTime; - private Animation _flushAnimation; + private Animation _flushAnimation = default!; void ISerializationHooks.AfterDeserialization() { @@ -57,7 +57,11 @@ namespace Content.Client.GameObjects.Components.Disposal var sound = new AnimationTrackPlaySound(); _flushAnimation.AnimationTracks.Add(sound); - sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_flushSound, 0)); + + if (_flushSound != null) + { + sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_flushSound, 0)); + } } private void ChangeState(AppearanceComponent appearance) @@ -67,7 +71,7 @@ namespace Content.Client.GameObjects.Components.Disposal return; } - if (!appearance.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs b/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs index 8a22bb0acd..8766d5443f 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalVisualizer.cs @@ -4,8 +4,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Disposal { @@ -13,15 +11,17 @@ namespace Content.Client.GameObjects.Components.Disposal public class DisposalVisualizer : AppearanceVisualizer { [DataField("state_free")] - private string _stateFree; + private string? _stateFree; + [DataField("state_anchored")] - private string _stateAnchored; + private string? _stateAnchored; + [DataField("state_broken")] - private string _stateBroken; + private string? _stateBroken; private void ChangeState(AppearanceComponent appearance) { - if (!appearance.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/DoAfterComponent.cs b/Content.Client/GameObjects/Components/DoAfterComponent.cs index 23e54c217a..040a0519a1 100644 --- a/Content.Client/GameObjects/Components/DoAfterComponent.cs +++ b/Content.Client/GameObjects/Components/DoAfterComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using Content.Client.GameObjects.EntitySystems.DoAfter; diff --git a/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs b/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs index 50898879f9..baffdd0c9c 100644 --- a/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs +++ b/Content.Client/GameObjects/Components/Doors/AirlockVisualizer.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using Content.Client.GameObjects.Components.Wires; using Content.Shared.Audio; diff --git a/Content.Client/GameObjects/Components/Doors/ClientDoorComponent.cs b/Content.Client/GameObjects/Components/Doors/ClientDoorComponent.cs index f24db36a46..e79894deda 100644 --- a/Content.Client/GameObjects/Components/Doors/ClientDoorComponent.cs +++ b/Content.Client/GameObjects/Components/Doors/ClientDoorComponent.cs @@ -1,9 +1,7 @@ -#nullable enable +using System; using Content.Shared.GameObjects.Components.Doors; using JetBrains.Annotations; using Robust.Shared.GameObjects; -using Robust.Shared.ViewVariables; -using System; namespace Content.Client.GameObjects.Components.Doors { diff --git a/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs b/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs index 6b2e8e5e86..42bf052cb4 100644 --- a/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs +++ b/Content.Client/GameObjects/Components/Explosion/ClusterFlashVisualizer.cs @@ -2,8 +2,6 @@ using Content.Shared.GameObjects.Components.Explosion; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Explosion { @@ -12,7 +10,7 @@ namespace Content.Client.GameObjects.Components.Explosion public class ClusterFlashVisualizer : AppearanceVisualizer { [DataField("state")] - private string _state; + private string? _state; public override void OnChangeData(AppearanceComponent component) { diff --git a/Content.Client/GameObjects/Components/FlashLightVisualizer.cs b/Content.Client/GameObjects/Components/FlashLightVisualizer.cs index fe83d50377..28e3397d52 100644 --- a/Content.Client/GameObjects/Components/FlashLightVisualizer.cs +++ b/Content.Client/GameObjects/Components/FlashLightVisualizer.cs @@ -53,9 +53,8 @@ namespace Content.Client.GameObjects.Components } }; - private Action _radiatingCallback; - private Action _blinkingCallback; - + private Action? _radiatingCallback; + private Action? _blinkingCallback; public override void OnChangeData(AppearanceComponent component) { diff --git a/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs b/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs index ca8fcb4d76..30ef0922b3 100644 --- a/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs +++ b/Content.Client/GameObjects/Components/Fluids/SprayVisualizer.cs @@ -2,8 +2,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Fluids { @@ -11,9 +9,9 @@ namespace Content.Client.GameObjects.Components.Fluids public class SprayVisualizer : AppearanceVisualizer { [DataField("safety_on_state")] - private string _safetyOnState; + private string? _safetyOnState; [DataField("safety_off_state")] - private string _safetyOffState; + private string? _safetyOffState; public override void OnChangeData(AppearanceComponent component) { diff --git a/Content.Client/GameObjects/Components/Gravity/GravityGeneratorBoundUserInterface.cs b/Content.Client/GameObjects/Components/Gravity/GravityGeneratorBoundUserInterface.cs index 0888d4eed3..d9f9f5e636 100644 --- a/Content.Client/GameObjects/Components/Gravity/GravityGeneratorBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Gravity/GravityGeneratorBoundUserInterface.cs @@ -1,4 +1,5 @@ using Content.Shared.GameObjects.Components.Gravity; +using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; @@ -9,9 +10,10 @@ using Robust.Shared.Maths; namespace Content.Client.GameObjects.Components.Gravity { - public class GravityGeneratorBoundUserInterface: BoundUserInterface + [UsedImplicitly] + public class GravityGeneratorBoundUserInterface : BoundUserInterface { - private GravityGeneratorWindow _window; + private GravityGeneratorWindow? _window; public bool IsOn; @@ -28,7 +30,7 @@ namespace Content.Client.GameObjects.Components.Gravity _window = new GravityGeneratorWindow(this); - _window.Switch.OnPressed += (args) => + _window.Switch.OnPressed += (_) => { SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(!IsOn)); SendMessage(new SharedGravityGeneratorComponent.GeneratorStatusRequestMessage()); @@ -43,7 +45,7 @@ namespace Content.Client.GameObjects.Components.Gravity var castState = (SharedGravityGeneratorComponent.GeneratorState) state; IsOn = castState.On; - _window.UpdateButton(); + _window?.UpdateButton(); } protected override void Dispose(bool disposing) @@ -63,11 +65,11 @@ namespace Content.Client.GameObjects.Components.Gravity public GravityGeneratorBoundUserInterface Owner; - public GravityGeneratorWindow(GravityGeneratorBoundUserInterface gravityGeneratorInterface = null) + public GravityGeneratorWindow(GravityGeneratorBoundUserInterface ui) { IoCManager.InjectDependencies(this); - Owner = gravityGeneratorInterface; + Owner = ui; Title = Loc.GetString("Gravity Generator Control"); diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs index 1937dd4f2b..4588465624 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/ClientInventoryComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Client.GameObjects.Components.Clothing; @@ -268,7 +267,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory } } - public bool TryGetSlot(Slots slot, out IEntity? item) + public bool TryGetSlot(Slots slot, [NotNullWhen(true)] out IEntity? item) { return _slots.TryGetValue(slot, out item); } diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs b/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs index b224855a50..cd5f49d430 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/HumanInventoryInterfaceController.cs @@ -25,13 +25,13 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory private readonly Dictionary> _inventoryButtons = new(); - private ItemSlotButton _hudButtonPocket1; - private ItemSlotButton _hudButtonPocket2; - private ItemSlotButton _hudButtonBelt; - private ItemSlotButton _hudButtonBack; - private ItemSlotButton _hudButtonId; - private Control _rightQuickButtonsContainer; - private Control _leftQuickButtonsContainer; + private ItemSlotButton _hudButtonPocket1 = default!; + private ItemSlotButton _hudButtonPocket2 = default!; + private ItemSlotButton _hudButtonBelt = default!; + private ItemSlotButton _hudButtonBack = default!; + private ItemSlotButton _hudButtonId = default!; + private Control _rightQuickButtonsContainer = default!; + private Control _leftQuickButtonsContainer = default!; public HumanInventoryInterfaceController(ClientInventoryComponent owner) : base(owner) { @@ -47,7 +47,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory { button.OnPressed = (e) => AddToInventory(e, slot); button.OnStoragePressed = (e) => OpenStorage(e, slot); - button.OnHover = (e) => RequestItemHover(slot); + button.OnHover = (_) => RequestItemHover(slot); _inventoryButtons.Add(slot, new List {button}); } @@ -59,7 +59,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory { OnPressed = (e) => AddToInventory(e, slot), OnStoragePressed = (e) => OpenStorage(e, slot), - OnHover = (e) => RequestItemHover(slot) + OnHover = (_) => RequestItemHover(slot) }; _inventoryButtons[slot].Add(variable); } @@ -93,8 +93,8 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory }; } - public override SS14Window Window => _window; - private HumanInventoryWindow _window; + public override SS14Window? Window => _window; + private HumanInventoryWindow? _window; public override IEnumerable GetItemSlotButtons(Slots slot) { @@ -152,7 +152,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory protected override void HandleInventoryKeybind(GUIBoundKeyEventArgs args, Slots slot) { - if (!_inventoryButtons.TryGetValue(slot, out var buttons)) + if (!_inventoryButtons.ContainsKey(slot)) return; if (!Owner.TryGetSlot(slot, out var item)) return; diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs index cecafb262d..265f74547e 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/InventoryInterfaceController.cs @@ -22,10 +22,9 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory public virtual void Initialize() { - } - public abstract SS14Window Window { get; } + public abstract SS14Window? Window { get; } protected ClientInventoryComponent Owner { get; } public virtual void PlayerAttached() @@ -35,11 +34,11 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory { if (b) { - Window.Open(); + Window?.Open(); } else { - Window.Close(); + Window?.Close(); } }; } @@ -47,7 +46,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory public virtual void PlayerDetached() { GameHud.InventoryButtonVisible = false; - Window.Close(); + Window?.Close(); } public virtual void Dispose() diff --git a/Content.Client/GameObjects/Components/HUD/Inventory/StrippableBoundUserInterface.cs b/Content.Client/GameObjects/Components/HUD/Inventory/StrippableBoundUserInterface.cs index e6f3987c33..8179307890 100644 --- a/Content.Client/GameObjects/Components/HUD/Inventory/StrippableBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/HUD/Inventory/StrippableBoundUserInterface.cs @@ -13,12 +13,12 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory [UsedImplicitly] public class StrippableBoundUserInterface : BoundUserInterface { - public Dictionary Inventory { get; private set; } - public Dictionary Hands { get; private set; } - public Dictionary Handcuffs { get; private set; } + public Dictionary? Inventory { get; private set; } + public Dictionary? Hands { get; private set; } + public Dictionary? Handcuffs { get; private set; } [ViewVariables] - private StrippingMenu _strippingMenu; + private StrippingMenu? _strippingMenu; public StrippableBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { @@ -41,7 +41,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory if (!disposing) return; - _strippingMenu.Dispose(); + _strippingMenu?.Dispose(); } private void UpdateMenu() diff --git a/Content.Client/GameObjects/Components/HandheldLightComponent.cs b/Content.Client/GameObjects/Components/HandheldLightComponent.cs index bc80ed66e2..cf2af86113 100644 --- a/Content.Client/GameObjects/Components/HandheldLightComponent.cs +++ b/Content.Client/GameObjects/Components/HandheldLightComponent.cs @@ -21,7 +21,7 @@ namespace Content.Client.GameObjects.Components return new StatusControl(this); } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); @@ -40,12 +40,12 @@ namespace Content.Client.GameObjects.Components private float _timer; - private static readonly StyleBoxFlat _styleBoxLit = new() + private static readonly StyleBoxFlat StyleBoxLit = new() { BackgroundColor = Color.Green }; - private static readonly StyleBoxFlat _styleBoxUnlit = new() + private static readonly StyleBoxFlat StyleBoxUnlit = new() { BackgroundColor = Color.Black }; @@ -88,22 +88,22 @@ namespace Content.Client.GameObjects.Components { if (level == 0) { - _sections[0].PanelOverride = _styleBoxUnlit; + _sections[0].PanelOverride = StyleBoxUnlit; } else if (level == 1) { // Flash the last light. - _sections[0].PanelOverride = _timer > TimerCycle / 2 ? _styleBoxLit : _styleBoxUnlit; + _sections[0].PanelOverride = _timer > TimerCycle / 2 ? StyleBoxLit : StyleBoxUnlit; } else { - _sections[0].PanelOverride = _styleBoxLit; + _sections[0].PanelOverride = StyleBoxLit; } continue; } - _sections[i].PanelOverride = level >= i + 2 ? _styleBoxLit : _styleBoxUnlit; + _sections[i].PanelOverride = level >= i + 2 ? StyleBoxLit : StyleBoxUnlit; } } } diff --git a/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs b/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs index 6e66500268..606e39fa86 100644 --- a/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs +++ b/Content.Client/GameObjects/Components/IconSmoothing/IconSmoothComponent.cs @@ -6,8 +6,6 @@ using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using static Robust.Client.GameObjects.SpriteComponent; @@ -27,28 +25,28 @@ namespace Content.Client.GameObjects.Components.IconSmoothing [RegisterComponent] public class IconSmoothComponent : Component { - [DataField("key")] - private string _smoothKey = default; - [DataField("base")] - private string _stateBase = ""; [DataField("mode")] private IconSmoothingMode _mode = IconSmoothingMode.Corners; public override string Name => "IconSmooth"; - internal ISpriteComponent Sprite { get; private set; } - internal SnapGridComponent SnapGrid { get; private set; } + internal ISpriteComponent? Sprite { get; private set; } + + internal SnapGridComponent? SnapGrid { get; private set; } + private (GridId, Vector2i) _lastPosition; /// /// We will smooth with other objects with the same key. /// - public string SmoothKey => _smoothKey; + [field: DataField("key")] + public string? SmoothKey { get; } /// /// Prepended to the RSI state. /// - public string StateBase => _stateBase; + [field: DataField("base")] + public string StateBase { get; } = string.Empty; /// /// Mode that controls how the icon should be selected. @@ -73,12 +71,18 @@ namespace Content.Client.GameObjects.Components.IconSmoothing { base.Startup(); - SnapGrid.OnPositionChanged += SnapGridOnPositionChanged; - // ensures lastposition initial value is populated on spawn. Just calling - // the hook here would cause a dirty event to fire needlessly - _lastPosition = (Owner.Transform.GridID, SnapGrid.Position); - Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner,null, SnapGrid.Offset, Mode)); - if (Mode == IconSmoothingMode.Corners) + if (SnapGrid != null) + { + SnapGrid.OnPositionChanged += SnapGridOnPositionChanged; + + // ensures lastposition initial value is populated on spawn. Just calling + // the hook here would cause a dirty event to fire needlessly + _lastPosition = (Owner.Transform.GridID, SnapGrid.Position); + + Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner,null, SnapGrid.Offset, Mode)); + } + + if (Sprite != null && Mode == IconSmoothingMode.Corners) { var state0 = $"{StateBase}0"; Sprite.LayerMapSet(CornerLayers.SE, Sprite.AddLayerState(state0)); @@ -111,6 +115,11 @@ namespace Content.Client.GameObjects.Components.IconSmoothing private void CalculateNewSpriteCardinal() { + if (SnapGrid == null || Sprite == null) + { + return; + } + var dirs = CardinalConnectDirs.None; if (MatchingEntity(SnapGrid.GetInDir(Direction.North))) @@ -127,6 +136,11 @@ namespace Content.Client.GameObjects.Components.IconSmoothing private void CalculateNewSpriteCorners() { + if (Sprite == null) + { + return; + } + var (cornerNE, cornerNW, cornerSW, cornerSE) = CalculateCornerFill(); Sprite.LayerSetState(CornerLayers.NE, $"{StateBase}{(int) cornerNE}"); @@ -137,6 +151,11 @@ namespace Content.Client.GameObjects.Components.IconSmoothing protected (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill() { + if (SnapGrid == null) + { + return (CornerFill.None, CornerFill.None, CornerFill.None, CornerFill.None); + } + var n = MatchingEntity(SnapGrid.GetInDir(Direction.North)); var ne = MatchingEntity(SnapGrid.GetInDir(Direction.NorthEast)); var e = MatchingEntity(SnapGrid.GetInDir(Direction.East)); @@ -215,14 +234,20 @@ namespace Content.Client.GameObjects.Components.IconSmoothing { base.Shutdown(); - SnapGrid.OnPositionChanged -= SnapGridOnPositionChanged; - Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, SnapGrid.Offset, Mode)); + if (SnapGrid != null) + { + SnapGrid.OnPositionChanged -= SnapGridOnPositionChanged; + Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, SnapGrid.Offset, Mode)); + } } private void SnapGridOnPositionChanged() { - Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, SnapGrid.Offset, Mode)); - _lastPosition = (Owner.Transform.GridID, SnapGrid.Position); + if (SnapGrid != null) + { + Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, SnapGrid.Offset, Mode)); + _lastPosition = (Owner.Transform.GridID, SnapGrid.Position); + } } [System.Diagnostics.Contracts.Pure] @@ -230,7 +255,7 @@ namespace Content.Client.GameObjects.Components.IconSmoothing { foreach (var entity in candidates) { - if (!entity.TryGetComponent(out IconSmoothComponent other)) + if (!entity.TryGetComponent(out IconSmoothComponent? other)) { continue; } diff --git a/Content.Client/GameObjects/Components/Instruments/InstrumentBoundUserInterface.cs b/Content.Client/GameObjects/Components/Instruments/InstrumentBoundUserInterface.cs index 7eb3ef5c00..2246810c84 100644 --- a/Content.Client/GameObjects/Components/Instruments/InstrumentBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Instruments/InstrumentBoundUserInterface.cs @@ -7,9 +7,9 @@ namespace Content.Client.GameObjects.Components.Instruments public class InstrumentBoundUserInterface : BoundUserInterface { [ViewVariables] - private InstrumentMenu _instrumentMenu; + private InstrumentMenu? _instrumentMenu; - public InstrumentComponent Instrument { get; set; } + public InstrumentComponent? Instrument { get; set; } public InstrumentBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { diff --git a/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs b/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs index 5c9c563459..bfbef85d58 100644 --- a/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs +++ b/Content.Client/GameObjects/Components/Instruments/InstrumentComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs index e64f2fae2b..6bc7651194 100644 --- a/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs @@ -5,8 +5,6 @@ using Content.Shared.GameObjects.Components.Interactable; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -27,7 +25,7 @@ namespace Content.Client.GameObjects.Components.Interactable public override string Name => "MultiTool"; public override uint? NetID => ContentNetIDs.MULTITOOLS; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs index 02bcc6af53..df4043dbcf 100644 --- a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs @@ -7,7 +7,6 @@ using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; using Robust.Shared.Localization; -using Robust.Shared.Serialization; using Robust.Shared.Timing; using Robust.Shared.ViewVariables; @@ -26,7 +25,7 @@ namespace Content.Client.GameObjects.Components.Interactable [ViewVariables] public bool Activated { get; private set; } [ViewVariables] public override ToolQuality Qualities => _behavior; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/InteractionOutlineComponent.cs b/Content.Client/GameObjects/Components/InteractionOutlineComponent.cs index 8a4463dd55..d192de5a97 100644 --- a/Content.Client/GameObjects/Components/InteractionOutlineComponent.cs +++ b/Content.Client/GameObjects/Components/InteractionOutlineComponent.cs @@ -16,8 +16,8 @@ namespace Content.Client.GameObjects.Components public override string Name => "InteractionOutline"; - private ShaderInstance _selectionShaderInstance; - private ShaderInstance _selectionShaderInRangeInstance; + private ShaderInstance? _selectionShaderInstance; + private ShaderInstance? _selectionShaderInRangeInstance; /// public override void Initialize() @@ -30,7 +30,7 @@ namespace Content.Client.GameObjects.Components public void OnMouseEnter(bool inInteractionRange) { - if (Owner.TryGetComponent(out ISpriteComponent sprite)) + if (Owner.TryGetComponent(out ISpriteComponent? sprite)) { sprite.PostShader = inInteractionRange ? _selectionShaderInRangeInstance : _selectionShaderInstance; sprite.RenderOrder = Owner.EntityManager.CurrentTick.Value; @@ -39,7 +39,7 @@ namespace Content.Client.GameObjects.Components public void OnMouseLeave() { - if (Owner.TryGetComponent(out ISpriteComponent sprite)) + if (Owner.TryGetComponent(out ISpriteComponent? sprite)) { sprite.PostShader = null; sprite.RenderOrder = 0; @@ -48,7 +48,7 @@ namespace Content.Client.GameObjects.Components public void UpdateInRange(bool inInteractionRange) { - if (Owner.TryGetComponent(out ISpriteComponent sprite)) + if (Owner.TryGetComponent(out ISpriteComponent? sprite)) { sprite.PostShader = inInteractionRange ? _selectionShaderInRangeInstance : _selectionShaderInstance; } diff --git a/Content.Client/GameObjects/Components/Items/HandsComponent.cs b/Content.Client/GameObjects/Components/Items/HandsComponent.cs index 546f5170c0..b272174a85 100644 --- a/Content.Client/GameObjects/Components/Items/HandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/HandsComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; diff --git a/Content.Client/GameObjects/Components/Items/ItemComponent.cs b/Content.Client/GameObjects/Components/Items/ItemComponent.cs index e448f7bf51..c25833cb07 100644 --- a/Content.Client/GameObjects/Components/Items/ItemComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ItemComponent.cs @@ -8,8 +8,6 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Maths; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; @@ -27,38 +25,43 @@ namespace Content.Client.GameObjects.Components.Items [ViewVariables] [DataField("sprite")] - protected ResourcePath RsiPath; + protected ResourcePath? RsiPath; [ViewVariables(VVAccess.ReadWrite)] [DataField("color")] protected Color Color = Color.White; [DataField("HeldPrefix")] - private string _equippedPrefix; + private string? _equippedPrefix; [ViewVariables(VVAccess.ReadWrite)] - public string EquippedPrefix + public string? EquippedPrefix { get => _equippedPrefix; set { _equippedPrefix = value; - if (!Owner.TryGetContainer(out IContainer container)) return; - if(container.Owner.TryGetComponent(out HandsComponent hands)) + + if (!Owner.TryGetContainer(out var container)) + return; + + if (container.Owner.TryGetComponent(out HandsComponent? hands)) hands.RefreshInHands(); } } public (RSI rsi, RSI.StateId stateId, Color color)? GetInHandStateInfo(HandLocation hand) { - if (RsiPath == null) + var rsi = GetRSI(); + + if (rsi == null) { return null; } var handName = hand.ToString().ToLowerInvariant(); - var rsi = GetRSI(); var stateId = EquippedPrefix != null ? $"{EquippedPrefix}-inhand-{handName}" : $"inhand-{handName}"; + if (rsi.TryGetState(stateId, out _)) { return (rsi, stateId, Color); @@ -67,18 +70,22 @@ namespace Content.Client.GameObjects.Components.Items return null; } - protected RSI GetRSI() + protected RSI? GetRSI() { + if (RsiPath == null) + { + return null; + } + return _resourceCache.GetResource(SharedSpriteComponent.TextureRoot / RsiPath).RSI; } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { - if(curState == null) + if (curState is not ItemComponentState state) return; - var itemComponentState = (ItemComponentState)curState; - EquippedPrefix = itemComponentState.EquippedPrefix; + EquippedPrefix = state.EquippedPrefix; } bool IDraggable.CanDrop(CanDropEventArgs args) diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs index dfe1efb6a7..60445684e7 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs @@ -13,6 +13,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Prototypes; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.GameObjects.Components.Kitchen { @@ -22,7 +23,7 @@ namespace Content.Client.GameObjects.Components.Kitchen [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - private MicrowaveMenu _menu; + private MicrowaveMenu? _menu; private readonly Dictionary _solids = new(); private readonly Dictionary _reagents =new(); @@ -38,8 +39,8 @@ namespace Content.Client.GameObjects.Components.Kitchen _menu = new MicrowaveMenu(this); _menu.OpenCentered(); _menu.OnClose += Close; - _menu.StartButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage()); - _menu.EjectButton.OnPressed += args => SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage()); + _menu.StartButton.OnPressed += _ => SendMessage(new SharedMicrowaveComponent.MicrowaveStartCookMessage()); + _menu.EjectButton.OnPressed += _ => SendMessage(new SharedMicrowaveComponent.MicrowaveEjectMessage()); _menu.IngredientsList.OnItemSelected += args => { SendMessage(new SharedMicrowaveComponent.MicrowaveEjectSolidIndexedMessage(_solids[args.ItemIndex])); @@ -55,20 +56,20 @@ namespace Content.Client.GameObjects.Components.Kitchen _menu.OnCookTimeSelected += (args,buttonIndex) => { var actualButton = (MicrowaveMenu.MicrowaveCookTimeButton) args.Button ; - var newTime = actualButton.CookTime; SendMessage(new SharedMicrowaveComponent.MicrowaveSelectCookTimeMessage(buttonIndex,actualButton.CookTime)); }; - } protected override void Dispose(bool disposing) { base.Dispose(disposing); + if (!disposing) { return; } - _solids?.Clear(); + + _solids.Clear(); _menu?.Dispose(); } @@ -80,24 +81,34 @@ namespace Content.Client.GameObjects.Components.Kitchen { return; } - _menu.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy); + + _menu?.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy); RefreshContentsDisplay(cState.ReagentQuantities, cState.ContainedSolids); - var currentlySelectedTimeButton = (Button) _menu.CookTimeButtonVbox.GetChild(cState.ActiveButtonIndex); - currentlySelectedTimeButton.Pressed = true; - var label = cState.ActiveButtonIndex <= 0 ? Loc.GetString("INSTANT") : cState.CurrentCookTime.ToString(); - _menu._cookTimeInfoLabel.Text = $"{Loc.GetString("COOK TIME")}: {label}"; + + if (_menu != null) + { + var currentlySelectedTimeButton = (Button) _menu.CookTimeButtonVbox.GetChild(cState.ActiveButtonIndex); + currentlySelectedTimeButton.Pressed = true; + var label = cState.ActiveButtonIndex <= 0 ? Loc.GetString("INSTANT") : cState.CurrentCookTime.ToString(); + _menu._cookTimeInfoLabel.Text = $"{Loc.GetString("COOK TIME")}: {label}"; + } } private void RefreshContentsDisplay(Solution.ReagentQuantity[] reagents, EntityUid[] containedSolids) { _reagents.Clear(); + + if (_menu == null) return; + _menu.IngredientsListReagents.Clear(); for (var i = 0; i < reagents.Length; i++) { - _prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype proto); - var reagentAdded = _menu.IngredientsListReagents.AddItem($"{reagents[i].Quantity} {proto.Name}"); - var reagentIndex = _menu.IngredientsListReagents.IndexOf(reagentAdded); - _reagents.Add(reagentIndex, reagents[i]); + if (_prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype? proto)) + { + var reagentAdded = _menu.IngredientsListReagents.AddItem($"{reagents[i].Quantity} {proto.Name}"); + var reagentIndex = _menu.IngredientsListReagents.IndexOf(reagentAdded); + _reagents.Add(reagentIndex, reagents[i]); + } } _solids.Clear(); @@ -108,31 +119,34 @@ namespace Content.Client.GameObjects.Components.Kitchen { return; } + if (entity.Deleted) { continue; } - Texture texture; - if (entity.TryGetComponent(out IconComponent iconComponent)) + Texture? texture; + if (entity.TryGetComponent(out IconComponent? iconComponent)) { texture = iconComponent.Icon?.Default; - }else if (entity.TryGetComponent(out SpriteComponent spriteComponent)) + } + else if (entity.TryGetComponent(out SpriteComponent? spriteComponent)) { texture = spriteComponent.Icon?.Default; - }else{continue;} + } + else + { + continue; + } var solidItem = _menu.IngredientsList.AddItem(entity.Name, texture); var solidIndex = _menu.IngredientsList.IndexOf(solidItem); _solids.Add(solidIndex, containedSolids[j]); - } - } public class MicrowaveMenu : SS14Window { - public class MicrowaveCookTimeButton : Button { public uint CookTime; @@ -141,7 +155,7 @@ namespace Content.Client.GameObjects.Components.Kitchen private MicrowaveBoundUserInterface Owner { get; set; } - public event Action OnCookTimeSelected; + public event Action? OnCookTimeSelected; public Button StartButton { get; } public Button EjectButton { get; } @@ -149,19 +163,19 @@ namespace Content.Client.GameObjects.Components.Kitchen public PanelContainer TimerFacePlate { get; } public ButtonGroup CookTimeButtonGroup { get; } + public VBoxContainer CookTimeButtonVbox { get; } private VBoxContainer ButtonGridContainer { get; } private PanelContainer DisableCookingPanelOverlay { get; } - public ItemList IngredientsList { get; } public ItemList IngredientsListReagents { get; } public Label _cookTimeInfoLabel { get; } - public MicrowaveMenu(MicrowaveBoundUserInterface owner = null) + public MicrowaveMenu(MicrowaveBoundUserInterface owner) { SetSize = MinSize = (512, 256); @@ -246,7 +260,6 @@ namespace Content.Client.GameObjects.Components.Kitchen Align = BoxContainer.AlignMode.Center, }; - var index = 0; for (var i = 0; i <= 6; i++) { @@ -270,7 +283,6 @@ namespace Content.Client.GameObjects.Components.Kitchen var cookTimeOneSecondButton = (Button) CookTimeButtonVbox.GetChild(0); cookTimeOneSecondButton.Pressed = true; - _cookTimeInfoLabel = new Label { Text = Loc.GetString("COOK TIME: 1"), diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs index 92a30d8795..a862a5eea5 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Client.GameObjects.Components.Sound; +using Content.Client.GameObjects.Components.Sound; using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.Components.Sound; using Content.Shared.Kitchen; diff --git a/Content.Client/GameObjects/Components/Kitchen/ReagentGrinderBoundUserInterface.cs b/Content.Client/GameObjects/Components/Kitchen/ReagentGrinderBoundUserInterface.cs index f9c17cae51..b4d034618d 100644 --- a/Content.Client/GameObjects/Components/Kitchen/ReagentGrinderBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Kitchen/ReagentGrinderBoundUserInterface.cs @@ -1,15 +1,16 @@ using System.Collections.Generic; +using Content.Shared.Chemistry; +using Content.Shared.Kitchen; +using Robust.Client.GameObjects; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; -using Content.Shared.Kitchen; -using Robust.Shared.GameObjects; -using Content.Shared.Chemistry; -using Robust.Shared.IoC; using Robust.Shared.Prototypes; -using Robust.Client.GameObjects; +using static Content.Shared.Chemistry.Solution; namespace Content.Client.GameObjects.Components.Kitchen { @@ -18,14 +19,16 @@ namespace Content.Client.GameObjects.Components.Kitchen [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - private GrinderMenu _menu; - private Dictionary _chamberVisualContents = new(); - private Dictionary _beakerVisualContents = new(); + private GrinderMenu? _menu; + private readonly Dictionary _chamberVisualContents = new(); + private readonly Dictionary _beakerVisualContents = new(); + public ReagentGrinderBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } protected override void Open() { base.Open(); + _menu = new GrinderMenu(this); _menu.OpenCentered(); _menu.OnClose += Close; @@ -64,6 +67,12 @@ namespace Content.Client.GameObjects.Components.Kitchen { return; } + + if (_menu == null) + { + return; + } + _menu.BeakerContentBox.EjectButton.Disabled = !cState.HasBeakerIn; _menu.ChamberContentBox.EjectButton.Disabled = cState.ChamberContents.Length <= 0; _menu.GrindButton.Disabled = !cState.CanGrind || !cState.Powered; @@ -74,6 +83,12 @@ namespace Content.Client.GameObjects.Components.Kitchen protected override void ReceiveMessage(BoundUserInterfaceMessage message) { base.ReceiveMessage(message); + + if (_menu == null) + { + return; + } + switch (message) { case SharedReagentGrinderComponent.ReagentGrinderWorkStartedMessage workStarted: @@ -95,10 +110,16 @@ namespace Content.Client.GameObjects.Components.Kitchen } } - private void RefreshContentsDisplay(IList reagents, IReadOnlyList containedSolids, bool isBeakerAttached) + private void RefreshContentsDisplay(IList? reagents, IReadOnlyList containedSolids, bool isBeakerAttached) { //Refresh chamber contents _chamberVisualContents.Clear(); + + if (_menu == null) + { + return; + } + _menu.ChamberContentBox.BoxContents.Clear(); foreach (var uid in containedSolids) { @@ -131,8 +152,8 @@ namespace Content.Client.GameObjects.Components.Kitchen { for (var i = 0; i < reagents.Count; i++) { - var goodIndex = _prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype proto); - var reagentName = goodIndex ? Loc.GetString($"{reagents[i].Quantity} {proto.Name}") : Loc.GetString("???"); + var goodIndex = _prototypeManager.TryIndex(reagents[i].ReagentId, out ReagentPrototype? proto); + var reagentName = goodIndex ? Loc.GetString($"{reagents[i].Quantity} {proto!.Name}") : Loc.GetString("???"); var reagentAdded = _menu.BeakerContentBox.BoxContents.AddItem(reagentName); var reagentIndex = _menu.BeakerContentBox.BoxContents.IndexOf(reagentAdded); _beakerVisualContents.Add(reagentIndex, reagents[i]); @@ -167,7 +188,8 @@ namespace Content.Client.GameObjects.Components.Kitchen public sealed class LabelledContentBox : VBoxContainer { - public string LabelText { get; set; } + public string? LabelText { get; set; } + public ItemList BoxContents { get; set; } public Button EjectButton { get; set; } @@ -176,7 +198,6 @@ namespace Content.Client.GameObjects.Components.Kitchen public LabelledContentBox(string labelText, string buttonText) { - _label = new Label { Text = labelText, @@ -211,7 +232,7 @@ namespace Content.Client.GameObjects.Components.Kitchen } } - public GrinderMenu(ReagentGrinderBoundUserInterface owner = null) + public GrinderMenu(ReagentGrinderBoundUserInterface owner) { SetSize = MinSize = (512, 256); Owner = owner; diff --git a/Content.Client/GameObjects/Components/LightBehaviourComponent.cs b/Content.Client/GameObjects/Components/LightBehaviourComponent.cs index 8dd9c2d20d..4256d9c14d 100644 --- a/Content.Client/GameObjects/Components/LightBehaviourComponent.cs +++ b/Content.Client/GameObjects/Components/LightBehaviourComponent.cs @@ -26,6 +26,8 @@ namespace Content.Client.GameObjects.Components [ImplicitDataDefinitionForInheritors] public abstract class LightBehaviourAnimationTrack : AnimationTrackProperty { + [Dependency] protected readonly IRobustRandom RobustRandom = default!; + [DataField("id")] [ViewVariables] public string ID { get; set; } = string.Empty; [DataField("property")] @@ -55,19 +57,17 @@ namespace Content.Client.GameObjects.Components public AnimationInterpolationMode InterpolateMode { get; set; } = AnimationInterpolationMode.Linear; [ViewVariables] protected float MaxTime { get; set; } - protected PointLightComponent Light; - protected IRobustRandom RobustRandom; private float _maxTime = default; + private IEntity _parent = default!; - public void Initialize(PointLightComponent light) + public void Initialize(IEntity parent) { - Light = light; - RobustRandom = IoCManager.Resolve(); + _parent = parent; - if (Enabled) + if (Enabled && _parent.TryGetComponent(out PointLightComponent? light)) { - Light.Enabled = true; + light.Enabled = true; } OnInitialize(); @@ -75,7 +75,10 @@ namespace Content.Client.GameObjects.Components public void UpdatePlaybackValues(Animation owner) { - Light.Enabled = true; + if (_parent.TryGetComponent(out PointLightComponent? light)) + { + light.Enabled = true; + } if (MinDuration > 0) { @@ -103,13 +106,9 @@ namespace Content.Client.GameObjects.Components throw new InvalidOperationException("Property parameter is null! Check the prototype!"); } - if (Light is IAnimationProperties properties) + if (_parent.TryGetComponent(out PointLightComponent? light)) { - properties.SetAnimatableProperty(Property, value); - } - else - { - AnimationHelper.SetAnimatableProperty(Light, Property, value); + AnimationHelper.SetAnimatableProperty(light, Property, value); } } @@ -219,10 +218,10 @@ namespace Content.Client.GameObjects.Components [UsedImplicitly] public class RandomizeBehaviour : LightBehaviourAnimationTrack { - private object _randomValue1; - private object _randomValue2; - private object _randomValue3; - private object _randomValue4; + private object? _randomValue1; + private object _randomValue2 = default!; + private object _randomValue3 = default!; + private object _randomValue4 = default!; public override void OnInitialize() { @@ -235,7 +234,7 @@ namespace Content.Client.GameObjects.Components { if (Property == "Enabled") // special case for boolean, we randomize it { - ApplyProperty(RobustRandom.NextDouble() < 0.5 ? true : false); + ApplyProperty(RobustRandom.NextDouble() < 0.5); return; } @@ -266,7 +265,7 @@ namespace Content.Client.GameObjects.Components ApplyProperty(InterpolateLinear(_randomValue3, _randomValue4, interpolateValue)); break; case AnimationInterpolationMode.Cubic: - ApplyProperty(InterpolateCubic(_randomValue1, _randomValue2, _randomValue3, _randomValue4, interpolateValue)); + ApplyProperty(InterpolateCubic(_randomValue1!, _randomValue2, _randomValue3, _randomValue4, interpolateValue)); break; default: case AnimationInterpolationMode.Nearest: @@ -377,8 +376,6 @@ namespace Content.Client.GameObjects.Components private Angle _originalRotation; private Color _originalColor; private bool _originalEnabled; - private PointLightComponent _lightComponent; - private AnimationPlayerComponent _animationPlayer; void ISerializationHooks.AfterDeserialization() { @@ -388,7 +385,7 @@ namespace Content.Client.GameObjects.Components { var animation = new Animation() { - AnimationTracks = { behaviour } + AnimationTracks = {behaviour} }; _animations.Add(new AnimationContainer(key, animation, behaviour)); @@ -401,12 +398,16 @@ namespace Content.Client.GameObjects.Components base.Startup(); CopyLightSettings(); - _animationPlayer = Owner.EnsureComponent(); - _animationPlayer.AnimationCompleted += OnAnimationCompleted; + Owner.EnsureComponentWarn(); + + if (Owner.TryGetComponent(out AnimationPlayerComponent? animation)) + { + animation.AnimationCompleted += OnAnimationCompleted; + } foreach (var container in _animations) { - container.LightBehaviour.Initialize(_lightComponent); + container.LightBehaviour.Initialize(Owner); } // we need to initialize all behaviours before starting any @@ -423,10 +424,19 @@ namespace Content.Client.GameObjects.Components { var container = _animations.FirstOrDefault(x => x.FullKey == key); + if (container == null) + { + return; + } + if (container.LightBehaviour.IsLooped) { container.LightBehaviour.UpdatePlaybackValues(container.Animation); - _animationPlayer.Play(container.Animation, container.FullKey); + + if (Owner.TryGetComponent(out AnimationPlayerComponent? animation)) + { + animation.Play(container.Animation, container.FullKey); + } } } @@ -435,13 +445,13 @@ namespace Content.Client.GameObjects.Components /// private void CopyLightSettings() { - if (Owner.TryGetComponent(out _lightComponent)) + if (Owner.TryGetComponent(out PointLightComponent? light)) { - _originalColor = _lightComponent.Color; - _originalEnabled = _lightComponent.Enabled; - _originalEnergy = _lightComponent.Energy; - _originalRadius = _lightComponent.Radius; - _originalRotation = _lightComponent.Rotation; + _originalColor = light.Color; + _originalEnabled = light.Enabled; + _originalEnergy = light.Energy; + _originalRadius = light.Radius; + _originalRotation = light.Rotation; } else { @@ -456,14 +466,19 @@ namespace Content.Client.GameObjects.Components /// public void StartLightBehaviour(string id = "") { + if (!Owner.TryGetComponent(out AnimationPlayerComponent? animation)) + { + return; + } + foreach (var container in _animations) { if (container.LightBehaviour.ID == id || id == string.Empty) { - if (!_animationPlayer.HasRunningAnimation(KeyPrefix + container.Key)) + if (!animation.HasRunningAnimation(KeyPrefix + container.Key)) { container.LightBehaviour.UpdatePlaybackValues(container.Animation); - _animationPlayer.Play(container.Animation, KeyPrefix + container.Key); + animation.Play(container.Animation, KeyPrefix + container.Key); } } } @@ -479,15 +494,20 @@ namespace Content.Client.GameObjects.Components /// Should the light have its original settings applied? public void StopLightBehaviour(string id = "", bool removeBehaviour = false, bool resetToOriginalSettings = false) { + if (!Owner.TryGetComponent(out AnimationPlayerComponent? animation)) + { + return; + } + var toRemove = new List(); foreach (var container in _animations) { if (container.LightBehaviour.ID == id || id == string.Empty) { - if (_animationPlayer.HasRunningAnimation(KeyPrefix + container.Key)) + if (animation.HasRunningAnimation(KeyPrefix + container.Key)) { - _animationPlayer.Stop(KeyPrefix + container.Key); + animation.Stop(KeyPrefix + container.Key); } if (removeBehaviour) @@ -502,13 +522,13 @@ namespace Content.Client.GameObjects.Components _animations.Remove(container); } - if (resetToOriginalSettings) + if (resetToOriginalSettings && Owner.TryGetComponent(out PointLightComponent? light)) { - _lightComponent.Color = _originalColor; - _lightComponent.Enabled = _originalEnabled; - _lightComponent.Energy = _originalEnergy; - _lightComponent.Radius = _originalRadius; - _lightComponent.Rotation = _originalRotation; + light.Color = _originalColor; + light.Enabled = _originalEnabled; + light.Energy = _originalEnergy; + light.Radius = _originalRadius; + light.Rotation = _originalRotation; } } @@ -517,7 +537,7 @@ namespace Content.Client.GameObjects.Components /// public void AddNewLightBehaviour(LightBehaviourAnimationTrack behaviour, bool playImmediately = true) { - int key = 0; + var key = 0; while (_animations.Any(x => x.Key == key)) { @@ -526,10 +546,11 @@ namespace Content.Client.GameObjects.Components var animation = new Animation() { - AnimationTracks = { behaviour } + AnimationTracks = {behaviour} }; - behaviour.Initialize(_lightComponent); + behaviour.Initialize(Owner); + var container = new AnimationContainer(key, animation, behaviour); _animations.Add(container); diff --git a/Content.Client/GameObjects/Components/LowWallComponent.cs b/Content.Client/GameObjects/Components/LowWallComponent.cs index 7a292c7a49..7c40805c7f 100644 --- a/Content.Client/GameObjects/Components/LowWallComponent.cs +++ b/Content.Client/GameObjects/Components/LowWallComponent.cs @@ -28,9 +28,10 @@ namespace Content.Client.GameObjects.Components public CornerFill LastCornerSW { get; private set; } public CornerFill LastCornerNW { get; private set; } + [ViewVariables] private IEntity? _overlayEntity; + [ViewVariables] - private IEntity _overlayEntity; - private ISpriteComponent _overlaySprite; + private ISpriteComponent? _overlaySprite; protected override void Startup() { @@ -57,13 +58,18 @@ namespace Content.Client.GameObjects.Components { base.Shutdown(); - _overlayEntity.Delete(); + _overlayEntity?.Delete(); } internal override void CalculateNewSprite() { base.CalculateNewSprite(); + if (Sprite == null || SnapGrid == null || _overlaySprite == null) + { + return; + } + var (n, nl) = MatchingWall(SnapGrid.GetInDir(Direction.North)); var (ne, nel) = MatchingWall(SnapGrid.GetInDir(Direction.NorthEast)); var (e, el) = MatchingWall(SnapGrid.GetInDir(Direction.East)); @@ -190,7 +196,7 @@ namespace Content.Client.GameObjects.Components foreach (var entity in SnapGrid.GetLocal()) { - if (entity.TryGetComponent(out WindowComponent window)) + if (entity.TryGetComponent(out WindowComponent? window)) { window.UpdateSprite(); } @@ -202,7 +208,7 @@ namespace Content.Client.GameObjects.Components { foreach (var entity in candidates) { - if (!entity.TryGetComponent(out IconSmoothComponent other)) + if (!entity.TryGetComponent(out IconSmoothComponent? other)) { continue; } diff --git a/Content.Client/GameObjects/Components/MagbootsComponent.cs b/Content.Client/GameObjects/Components/MagbootsComponent.cs index 4beda719cc..afbaeb62ad 100644 --- a/Content.Client/GameObjects/Components/MagbootsComponent.cs +++ b/Content.Client/GameObjects/Components/MagbootsComponent.cs @@ -1,8 +1,6 @@ using Content.Shared.GameObjects.Components; using Robust.Shared.GameObjects; -#nullable enable - namespace Content.Client.GameObjects.Components { [RegisterComponent] diff --git a/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs b/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs index 67205ea9f4..fea4b46bbb 100644 --- a/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs @@ -19,7 +19,7 @@ namespace Content.Client.GameObjects.Components [UsedImplicitly] public class MagicMirrorBoundUserInterface : BoundUserInterface { - private MagicMirrorWindow _window; + private MagicMirrorWindow? _window; public MagicMirrorBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { @@ -39,7 +39,7 @@ namespace Content.Client.GameObjects.Components switch (message) { case MagicMirrorInitialDataMessage initialData: - _window.SetInitialData(initialData); + _window?.SetInitialData(initialData); break; } } @@ -66,7 +66,7 @@ namespace Content.Client.GameObjects.Components if (disposing) { - _window.Dispose(); + _window?.Dispose(); } } } @@ -78,7 +78,7 @@ namespace Content.Client.GameObjects.Components private byte _colorValue; private bool _ignoreEvents; - public event Action OnValueChanged; + public event Action? OnValueChanged; public byte ColorValue { @@ -170,8 +170,8 @@ namespace Content.Client.GameObjects.Components public class HairStylePicker : Control { - public event Action OnHairColorPicked; - public event Action OnHairStylePicked; + public event Action? OnHairColorPicked; + public event Action? OnHairStylePicked; protected readonly ItemList Items; @@ -257,7 +257,12 @@ namespace Content.Client.GameObjects.Components private void ItemSelected(ItemList.ItemListSelectedEventArgs args) { - OnHairStylePicked?.Invoke(Items[args.ItemIndex].Text); + var hairColor = Items[args.ItemIndex].Text; + + if (hairColor != null) + { + OnHairStylePicked?.Invoke(hairColor); + } } // ColorSlider @@ -265,7 +270,7 @@ namespace Content.Client.GameObjects.Components public class EyeColorPicker : Control { - public event Action OnEyeColorPicked; + public event Action? OnEyeColorPicked; private readonly ColorSlider _colorSliderR; private readonly ColorSlider _colorSliderG; diff --git a/Content.Client/GameObjects/Components/Markers/MarkerComponent.cs b/Content.Client/GameObjects/Components/Markers/MarkerComponent.cs index e9849aca4d..9ad1922129 100644 --- a/Content.Client/GameObjects/Components/Markers/MarkerComponent.cs +++ b/Content.Client/GameObjects/Components/Markers/MarkerComponent.cs @@ -20,7 +20,7 @@ namespace Content.Client.GameObjects.Components.Markers { var system = EntitySystem.Get(); - if (Owner.TryGetComponent(out ISpriteComponent sprite)) + if (Owner.TryGetComponent(out ISpriteComponent? sprite)) { sprite.Visible = system.MarkersVisible; } diff --git a/Content.Client/GameObjects/Components/MedicalScanner/MedicalScannerBoundUserInterface.cs b/Content.Client/GameObjects/Components/MedicalScanner/MedicalScannerBoundUserInterface.cs index 7f33d106a9..e8b2a8fe09 100644 --- a/Content.Client/GameObjects/Components/MedicalScanner/MedicalScannerBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/MedicalScanner/MedicalScannerBoundUserInterface.cs @@ -8,12 +8,12 @@ namespace Content.Client.GameObjects.Components.MedicalScanner [UsedImplicitly] public class MedicalScannerBoundUserInterface : BoundUserInterface { + private MedicalScannerWindow? _window; + public MedicalScannerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } - private MedicalScannerWindow _window; - protected override void Open() { base.Open(); @@ -29,7 +29,8 @@ namespace Content.Client.GameObjects.Components.MedicalScanner protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _window.Populate((MedicalScannerBoundUserInterfaceState) state); + + _window?.Populate((MedicalScannerBoundUserInterfaceState) state); } protected override void Dispose(bool disposing) @@ -37,7 +38,8 @@ namespace Content.Client.GameObjects.Components.MedicalScanner base.Dispose(disposing); if (!disposing) return; - _window.Dispose(); + + _window?.Dispose(); } } } diff --git a/Content.Client/GameObjects/Components/Mobs/Actions/ActionAssignment.cs b/Content.Client/GameObjects/Components/Mobs/Actions/ActionAssignment.cs index 2146d5e90b..f9793c19b4 100644 --- a/Content.Client/GameObjects/Components/Mobs/Actions/ActionAssignment.cs +++ b/Content.Client/GameObjects/Components/Mobs/Actions/ActionAssignment.cs @@ -65,7 +65,7 @@ namespace Content.Client.GameObjects.Components.Mobs.Actions return _actionType == other._actionType && _itemActionType == other._itemActionType && Equals(_item, other._item); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is ActionAssignment other && Equals(other); } diff --git a/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs b/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs index 362cd24d2d..c01df83129 100644 --- a/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using Content.Shared.GameObjects.Components.Mobs; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Mobs/ClientActionsComponent.cs b/Content.Client/GameObjects/Components/Mobs/ClientActionsComponent.cs index d76b101988..6939080c66 100644 --- a/Content.Client/GameObjects/Components/Mobs/ClientActionsComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/ClientActionsComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using Content.Client.GameObjects.Components.HUD.Inventory; using Content.Client.GameObjects.Components.Items; using Content.Client.GameObjects.Components.Mobs.Actions; diff --git a/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs b/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs index 975945dc43..16f4f914ad 100644 --- a/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/ClientAlertsComponent.cs @@ -7,13 +7,13 @@ using Content.Shared.GameObjects.Components.Mobs; using Robust.Client.GameObjects; using Robust.Client.Player; using Robust.Client.UserInterface; -using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; using Robust.Shared.Input; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Prototypes; using Robust.Shared.ViewVariables; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.GameObjects.Components.Mobs { @@ -24,8 +24,8 @@ namespace Content.Client.GameObjects.Components.Mobs { [Dependency] private readonly IPlayerManager _playerManager = default!; - private AlertsUI _ui; - private AlertOrderPrototype _alertOrder; + private AlertsUI? _ui; + private AlertOrderPrototype? _alertOrder; [ViewVariables] private readonly Dictionary _alertControls @@ -43,7 +43,7 @@ namespace Content.Client.GameObjects.Components.Mobs PlayerDetached(); } - public override void HandleMessage(ComponentMessage message, IComponent component) + public override void HandleMessage(ComponentMessage message, IComponent? component) { base.HandleMessage(message, component); switch (message) @@ -57,7 +57,7 @@ namespace Content.Client.GameObjects.Components.Mobs } } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); @@ -207,12 +207,17 @@ namespace Content.Client.GameObjects.Components.Mobs return alertControl; } - private void AlertControlOnPressed(BaseButton.ButtonEventArgs args) + private void AlertControlOnPressed(ButtonEventArgs args) { - AlertPressed(args, args.Button as AlertControl); + if (args.Button is not AlertControl control) + { + return; + } + + AlertPressed(args, control); } - private void AlertPressed(BaseButton.ButtonEventArgs args, AlertControl alert) + private void AlertPressed(ButtonEventArgs args, AlertControl alert) { if (args.Event.Function != EngineKeyFunctions.UIClick) { diff --git a/Content.Client/GameObjects/Components/Mobs/CombatModeComponent.cs b/Content.Client/GameObjects/Components/Mobs/CombatModeComponent.cs index f24a42878d..0f055eb452 100644 --- a/Content.Client/GameObjects/Components/Mobs/CombatModeComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/CombatModeComponent.cs @@ -34,7 +34,7 @@ namespace Content.Client.GameObjects.Components.Mobs } } - public override void HandleMessage(ComponentMessage message, IComponent component) + public override void HandleMessage(ComponentMessage message, IComponent? component) { base.HandleMessage(message, component); @@ -53,7 +53,7 @@ namespace Content.Client.GameObjects.Components.Mobs private void UpdateHud() { - if (Owner != _playerManager.LocalPlayer.ControlledEntity) + if (Owner != _playerManager.LocalPlayer?.ControlledEntity) { return; } diff --git a/Content.Client/GameObjects/Components/Mobs/HumanoidAppearanceComponent.cs b/Content.Client/GameObjects/Components/Mobs/HumanoidAppearanceComponent.cs index 9abd1a4b49..2d0bbe9689 100644 --- a/Content.Client/GameObjects/Components/Mobs/HumanoidAppearanceComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/HumanoidAppearanceComponent.cs @@ -1,4 +1,4 @@ -using Content.Client.GameObjects.Components.ActionBlocking; +using Content.Client.GameObjects.Components.ActionBlocking; using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Body.Part; using Content.Shared.GameObjects.Components.Mobs; @@ -42,16 +42,16 @@ namespace Content.Client.GameObjects.Components.Mobs private void UpdateLooks() { if (Appearance is null || - !Owner.TryGetComponent(out SpriteComponent sprite)) + !Owner.TryGetComponent(out SpriteComponent? sprite)) { return; } - if (Owner.TryGetComponent(out IBody body)) + if (Owner.TryGetComponent(out IBody? body)) { foreach (var part in body.Parts.Values) { - if (!part.Owner.TryGetComponent(out SpriteComponent partSprite)) + if (!part.Owner.TryGetComponent(out SpriteComponent? partSprite)) { continue; } @@ -94,12 +94,12 @@ namespace Content.Client.GameObjects.Components.Mobs public void BodyPartAdded(BodyPartAddedEventArgs args) { - if (!Owner.TryGetComponent(out SpriteComponent sprite)) + if (!Owner.TryGetComponent(out SpriteComponent? sprite)) { return; } - if (!args.Part.Owner.TryGetComponent(out SpriteComponent partSprite)) + if (!args.Part.Owner.TryGetComponent(out SpriteComponent? partSprite)) { return; } @@ -117,12 +117,12 @@ namespace Content.Client.GameObjects.Components.Mobs public void BodyPartRemoved(BodyPartRemovedEventArgs args) { - if (!Owner.TryGetComponent(out SpriteComponent sprite)) + if (!Owner.TryGetComponent(out SpriteComponent? sprite)) { return; } - if (!args.Part.Owner.TryGetComponent(out SpriteComponent partSprite)) + if (!args.Part.Owner.TryGetComponent(out SpriteComponent? partSprite)) { return; } diff --git a/Content.Client/GameObjects/Components/Mobs/MeleeLungeComponent.cs b/Content.Client/GameObjects/Components/Mobs/MeleeLungeComponent.cs index 2e9cb29e48..089a2d6c01 100644 --- a/Content.Client/GameObjects/Components/Mobs/MeleeLungeComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/MeleeLungeComponent.cs @@ -38,7 +38,7 @@ namespace Content.Client.GameObjects.Components.Mobs offset *= (ResetTime - _time) / ResetTime; } - if (Owner.TryGetComponent(out ISpriteComponent spriteComponent)) + if (Owner.TryGetComponent(out ISpriteComponent? spriteComponent)) { spriteComponent.Offset = offset; } diff --git a/Content.Client/GameObjects/Components/Mobs/State/DeadMobState.cs b/Content.Client/GameObjects/Components/Mobs/State/DeadMobState.cs index 46745575a5..434a466a2a 100644 --- a/Content.Client/GameObjects/Components/Mobs/State/DeadMobState.cs +++ b/Content.Client/GameObjects/Components/Mobs/State/DeadMobState.cs @@ -12,14 +12,14 @@ namespace Content.Client.GameObjects.Components.Mobs.State { base.EnterState(entity); - if (entity.TryGetComponent(out AppearanceComponent appearance)) + if (entity.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(DamageStateVisuals.State, DamageState.Dead); } EntitySystem.Get().Down(entity); - if (entity.TryGetComponent(out PhysicsComponent physics)) + if (entity.TryGetComponent(out PhysicsComponent? physics)) { physics.CanCollide = false; } @@ -31,7 +31,7 @@ namespace Content.Client.GameObjects.Components.Mobs.State EntitySystem.Get().Standing(entity); - if (entity.TryGetComponent(out PhysicsComponent physics)) + if (entity.TryGetComponent(out PhysicsComponent? physics)) { physics.CanCollide = true; } diff --git a/Content.Client/GameObjects/Components/Mobs/State/MobStateComponent.cs b/Content.Client/GameObjects/Components/Mobs/State/MobStateComponent.cs index eb29f6a8c3..0f56a0a1cd 100644 --- a/Content.Client/GameObjects/Components/Mobs/State/MobStateComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/State/MobStateComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Mobs.State; +using Content.Shared.GameObjects.Components.Mobs.State; using Robust.Shared.GameObjects; namespace Content.Client.GameObjects.Components.Mobs.State diff --git a/Content.Client/GameObjects/Components/Mobs/State/NormalMobState.cs b/Content.Client/GameObjects/Components/Mobs/State/NormalMobState.cs index 56e2fe7626..c433a0eb96 100644 --- a/Content.Client/GameObjects/Components/Mobs/State/NormalMobState.cs +++ b/Content.Client/GameObjects/Components/Mobs/State/NormalMobState.cs @@ -11,7 +11,7 @@ namespace Content.Client.GameObjects.Components.Mobs.State { base.EnterState(entity); - if (entity.TryGetComponent(out AppearanceComponent appearance)) + if (entity.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(DamageStateVisuals.State, DamageState.Alive); } diff --git a/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs b/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs index 8ad4ee5451..ef4179c019 100644 --- a/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/StunnableComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Movement; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Morgue/BodyBagVisualizer.cs b/Content.Client/GameObjects/Components/Morgue/BodyBagVisualizer.cs index dd449e06c4..591a0c3874 100644 --- a/Content.Client/GameObjects/Components/Morgue/BodyBagVisualizer.cs +++ b/Content.Client/GameObjects/Components/Morgue/BodyBagVisualizer.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Morgue; +using Content.Shared.GameObjects.Components.Morgue; using JetBrains.Annotations; using Robust.Client.GameObjects; diff --git a/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs b/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs index bc6d4ff7b5..3fb7198a1c 100644 --- a/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs +++ b/Content.Client/GameObjects/Components/Morgue/CrematoriumVisualizer.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Morgue; +using Content.Shared.GameObjects.Components.Morgue; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; diff --git a/Content.Client/GameObjects/Components/Movement/ClimbingComponent.cs b/Content.Client/GameObjects/Components/Movement/ClimbingComponent.cs index dc47a7bacc..bd745c04a9 100644 --- a/Content.Client/GameObjects/Components/Movement/ClimbingComponent.cs +++ b/Content.Client/GameObjects/Components/Movement/ClimbingComponent.cs @@ -7,7 +7,7 @@ namespace Content.Client.GameObjects.Components.Movement [ComponentReference(typeof(SharedClimbingComponent))] public class ClimbingComponent : SharedClimbingComponent { - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Movement/SlipperyComponent.cs b/Content.Client/GameObjects/Components/Movement/SlipperyComponent.cs index d4cb93bd7e..636595ca4c 100644 --- a/Content.Client/GameObjects/Components/Movement/SlipperyComponent.cs +++ b/Content.Client/GameObjects/Components/Movement/SlipperyComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Movement; +using Content.Shared.GameObjects.Components.Movement; using Robust.Shared.GameObjects; namespace Content.Client.GameObjects.Components.Movement diff --git a/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs b/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs index ac7a247ce6..7425dd6c3f 100644 --- a/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs +++ b/Content.Client/GameObjects/Components/Nutrition/CreamPiedVisualizer.cs @@ -3,8 +3,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Nutrition { @@ -12,7 +10,7 @@ namespace Content.Client.GameObjects.Components.Nutrition public class CreamPiedVisualizer : AppearanceVisualizer { [DataField("state")] - private string _state; + private string? _state; public override void InitializeEntity(IEntity entity) { diff --git a/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs b/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs index cc17ba9877..a33ea6c4cd 100644 --- a/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs +++ b/Content.Client/GameObjects/Components/Nutrition/DrinkFoodContainerVisualizer2D.cs @@ -1,12 +1,9 @@ using System; -using System.Collections.Generic; using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Nutrition { @@ -14,9 +11,11 @@ namespace Content.Client.GameObjects.Components.Nutrition public sealed class FoodContainerVisualizer : AppearanceVisualizer { [DataField("base_state", required: true)] - private string _baseState; + private string? _baseState; + [DataField("steps", required: true)] private int _steps; + [DataField("mode")] private FoodContainerVisualMode _mode = FoodContainerVisualMode.Rounded; diff --git a/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs b/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs index e96bc5cf6c..f972160b50 100644 --- a/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs +++ b/Content.Client/GameObjects/Components/Nutrition/HungerComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Nutrition; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs b/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs index 01223f7c9a..eb30b7e287 100644 --- a/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs +++ b/Content.Client/GameObjects/Components/Nutrition/ThirstComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Nutrition; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Observer/AcceptCloningWindow.cs b/Content.Client/GameObjects/Components/Observer/AcceptCloningWindow.cs index b7d3a69d27..ebea63ae7f 100644 --- a/Content.Client/GameObjects/Components/Observer/AcceptCloningWindow.cs +++ b/Content.Client/GameObjects/Components/Observer/AcceptCloningWindow.cs @@ -1,5 +1,4 @@ -#nullable enable -using Robust.Client.UserInterface; +using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Localization; diff --git a/Content.Client/GameObjects/Components/Observer/GhostComponent.cs b/Content.Client/GameObjects/Components/Observer/GhostComponent.cs index 6321b8a63b..0cc4be41f6 100644 --- a/Content.Client/GameObjects/Components/Observer/GhostComponent.cs +++ b/Content.Client/GameObjects/Components/Observer/GhostComponent.cs @@ -10,7 +10,6 @@ using Robust.Shared.Network; using Robust.Shared.Players; using Robust.Shared.ViewVariables; -#nullable enable namespace Content.Client.GameObjects.Components.Observer { [RegisterComponent] diff --git a/Content.Client/GameObjects/Components/Observer/GhostRoles/GhostRolesWindow.xaml.cs b/Content.Client/GameObjects/Components/Observer/GhostRoles/GhostRolesWindow.xaml.cs index df3f34d217..f45e7b61ef 100644 --- a/Content.Client/GameObjects/Components/Observer/GhostRoles/GhostRolesWindow.xaml.cs +++ b/Content.Client/GameObjects/Components/Observer/GhostRoles/GhostRolesWindow.xaml.cs @@ -9,7 +9,7 @@ namespace Content.Client.GameObjects.Components.Observer.GhostRoles [GenerateTypedNameReferences] public partial class GhostRolesWindow : SS14Window { - public event Action RoleRequested; + public event Action? RoleRequested; public void ClearEntries() { diff --git a/Content.Client/GameObjects/Components/PDA/PDABoundUserInterface.cs b/Content.Client/GameObjects/Components/PDA/PDABoundUserInterface.cs index 8ea973f6c0..b09dd20018 100644 --- a/Content.Client/GameObjects/Components/PDA/PDABoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/PDA/PDABoundUserInterface.cs @@ -13,7 +13,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Prototypes; -using Robust.Shared.Utility; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.GameObjects.Components.PDA { @@ -23,12 +23,11 @@ namespace Content.Client.GameObjects.Components.PDA [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; - private PDAMenu _menu; - private PDAMenuPopup _failPopup; + private PDAMenu? _menu; + private PDAMenuPopup? _failPopup; public PDABoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - } protected override void Open() @@ -38,17 +37,17 @@ namespace Content.Client.GameObjects.Components.PDA _menu = new PDAMenu(this, _prototypeManager); _menu.OpenToLeft(); _menu.OnClose += Close; - _menu.FlashLightToggleButton.OnToggled += args => + _menu.FlashLightToggleButton.OnToggled += _ => { SendMessage(new PDAToggleFlashlightMessage()); }; - _menu.EjectIDButton.OnPressed += args => + _menu.EjectIDButton.OnPressed += _ => { SendMessage(new PDAEjectIDMessage()); }; - _menu.EjectPenButton.OnPressed += args => + _menu.EjectPenButton.OnPressed += _ => { SendMessage(new PDAEjectPenMessage()); }; @@ -62,9 +61,9 @@ namespace Content.Client.GameObjects.Components.PDA } }; - _menu.OnListingButtonPressed += (args, listing) => + _menu.OnListingButtonPressed += (_, listing) => { - if (_menu.CurrentLoggedInAccount.DataBalance < listing.Price) + if (_menu.CurrentLoggedInAccount?.DataBalance < listing.Price) { _failPopup = new PDAMenuPopup(Loc.GetString("Insufficient funds!")); _userInterfaceManager.ModalRoot.AddChild(_failPopup); @@ -78,7 +77,7 @@ namespace Content.Client.GameObjects.Components.PDA SendMessage(new PDAUplinkBuyListingMessage(listing.ItemId)); }; - _menu.OnCategoryButtonPressed += (args, category) => + _menu.OnCategoryButtonPressed += (_, category) => { _menu.CurrentFilterCategory = category; SendMessage(new PDARequestUpdateInterfaceMessage()); @@ -89,15 +88,23 @@ namespace Content.Client.GameObjects.Components.PDA protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - DebugTools.Assert(state is PDAUBoundUserInterfaceState); + + if (_menu == null) + { + return; + } switch (state) { case PDAUpdateState msg: { _menu.FlashLightToggleButton.Pressed = msg.FlashlightEnabled; - _menu.PDAOwnerLabel.SetMarkup(Loc.GetString("Owner: [color=white]{0}[/color]", - msg.PDAOwnerInfo.ActualOwnerName)); + + if (msg.PDAOwnerInfo.ActualOwnerName != null) + { + _menu.PDAOwnerLabel.SetMarkup(Loc.GetString("Owner: [color=white]{0}[/color]", + msg.PDAOwnerInfo.ActualOwnerName)); + } if (msg.PDAOwnerInfo.JobTitle == null || msg.PDAOwnerInfo.IdOwner == null) { @@ -113,6 +120,7 @@ namespace Content.Client.GameObjects.Components.PDA _menu.EjectIDButton.Visible = msg.PDAOwnerInfo.IdOwner != null; _menu.EjectPenButton.Visible = msg.HasPen; + if (msg.Account != null) { _menu.CurrentLoggedInAccount = msg.Account; @@ -130,6 +138,7 @@ namespace Content.Client.GameObjects.Components.PDA _menu.AddListingGui(item); } } + _menu.MasterTabContainer.SetTabVisible(1, msg.Account != null); break; } @@ -243,8 +252,8 @@ namespace Content.Client.GameObjects.Components.PDA public readonly VBoxContainer CategoryListContainer; public readonly RichTextLabel BalanceInfo; - public event Action OnListingButtonPressed; - public event Action OnCategoryButtonPressed; + public event Action? OnListingButtonPressed; + public event Action? OnCategoryButtonPressed; public UplinkCategory CurrentFilterCategory { @@ -260,16 +269,14 @@ namespace Content.Client.GameObjects.Components.PDA } } - public UplinkAccountData CurrentLoggedInAccount + public UplinkAccountData? CurrentLoggedInAccount { get => _loggedInUplinkAccount; set => _loggedInUplinkAccount = value; } - private UplinkCategory _currentFilter; - private UplinkAccountData _loggedInUplinkAccount; - + private UplinkAccountData? _loggedInUplinkAccount; public PDAMenu(PDABoundUserInterface owner, IPrototypeManager prototypeManager) { @@ -462,7 +469,7 @@ namespace Content.Client.GameObjects.Components.PDA public void AddListingGui(UplinkListingData listing) { - if (!_prototypeManager.TryIndex(listing.ItemId, out EntityPrototype prototype) || listing.Category != CurrentFilterCategory) + if (!_prototypeManager.TryIndex(listing.ItemId, out EntityPrototype? prototype) || listing.Category != CurrentFilterCategory) { return; } @@ -472,7 +479,7 @@ namespace Content.Client.GameObjects.Components.PDA Text = listing.ListingName == string.Empty ? prototype.Name : listing.ListingName, ToolTip = listing.Description == string.Empty ? prototype.Description : listing.Description, HorizontalExpand = true, - Modulate = _loggedInUplinkAccount.DataBalance >= listing.Price + Modulate = _loggedInUplinkAccount?.DataBalance >= listing.Price ? Color.White : Color.Gray.WithAlpha(0.30f) }; @@ -481,7 +488,7 @@ namespace Content.Client.GameObjects.Components.PDA { Text = $"{listing.Price} TC", HorizontalAlignment = HAlignment.Right, - Modulate = _loggedInUplinkAccount.DataBalance >= listing.Price + Modulate = _loggedInUplinkAccount?.DataBalance >= listing.Price ? weightedColor : Color.Gray.WithAlpha(0.30f) }; @@ -511,9 +518,8 @@ namespace Content.Client.GameObjects.Components.PDA } }; - var pdaUplinkListingButton = new PDAUplinkItemButton + var pdaUplinkListingButton = new PDAUplinkItemButton(listing) { - ButtonListing = listing, Children = { listingButtonPanelContainer @@ -531,7 +537,12 @@ namespace Content.Client.GameObjects.Components.PDA private sealed class PDAUplinkItemButton : ContainerButton { - public UplinkListingData ButtonListing; + public PDAUplinkItemButton(UplinkListingData data) + { + ButtonListing = data; + } + + public UplinkListingData ButtonListing { get; } } private sealed class PDAUplinkCategoryButton : Button diff --git a/Content.Client/GameObjects/Components/PDA/PDAComponent.cs b/Content.Client/GameObjects/Components/PDA/PDAComponent.cs index 3e3cace9dd..01e925f0e4 100644 --- a/Content.Client/GameObjects/Components/PDA/PDAComponent.cs +++ b/Content.Client/GameObjects/Components/PDA/PDAComponent.cs @@ -10,7 +10,7 @@ namespace Content.Client.GameObjects.Components.PDA [RegisterComponent] public class PDAComponent : SharedPDAComponent { - public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession session = null) + public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null) { base.HandleNetworkMessage(message, netChannel, session); switch(message) @@ -22,10 +22,7 @@ namespace Content.Client.GameObjects.Components.PDA case PDAUplinkInsufficientFundsMessage _ : SoundSystem.Play(Filter.Local(), "/Audio/Effects/error.ogg", Owner, AudioParams.Default); break; - } } - - } } diff --git a/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs b/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs index f52ab1ad48..d83cfdddb8 100644 --- a/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs +++ b/Content.Client/GameObjects/Components/PDA/PDAVisualizer.cs @@ -3,8 +3,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.PDA { @@ -16,7 +14,7 @@ namespace Content.Client.GameObjects.Components.PDA /// The base PDA sprite state, eg. "pda", "pda-clown" /// [DataField("state")] - private string _state; + private string? _state; private enum PDAVisualLayers : byte { @@ -30,7 +28,11 @@ namespace Content.Client.GameObjects.Components.PDA base.InitializeEntity(entity); var sprite = entity.GetComponent(); - sprite.LayerMapSet(PDAVisualLayers.Base, sprite.AddLayerState(_state)); + if (_state != null) + { + sprite.LayerMapSet(PDAVisualLayers.Base, sprite.AddLayerState(_state)); + } + sprite.LayerMapSet(PDAVisualLayers.Flashlight, sprite.AddLayerState("light_overlay")); sprite.LayerSetShader(PDAVisualLayers.Flashlight, "unshaded"); sprite.LayerMapSet(PDAVisualLayers.IDLight, sprite.AddLayerState("id_overlay")); diff --git a/Content.Client/GameObjects/Components/Paper/PaperBoundUserInterface.cs b/Content.Client/GameObjects/Components/Paper/PaperBoundUserInterface.cs index 88d8a23e69..ab27bc65eb 100644 --- a/Content.Client/GameObjects/Components/Paper/PaperBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Paper/PaperBoundUserInterface.cs @@ -1,15 +1,15 @@ -using Content.Shared.GameObjects.Components; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; +using static Content.Shared.GameObjects.Components.SharedPaperComponent; namespace Content.Client.GameObjects.Components.Paper { [UsedImplicitly] public class PaperBoundUserInterface : BoundUserInterface { - private PaperWindow _window; + private PaperWindow? _window; public PaperBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { @@ -31,15 +31,19 @@ namespace Content.Client.GameObjects.Components.Paper protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _window.Populate((SharedPaperComponent.PaperBoundUserInterfaceState)state); + _window?.Populate((PaperBoundUserInterfaceState) state); } private void Input_OnTextEntered(LineEdit.LineEditEventArgs obj) { - if(!string.IsNullOrEmpty(obj.Text)) + if (!string.IsNullOrEmpty(obj.Text)) { - SendMessage(new SharedPaperComponent.PaperInputText(obj.Text)); - _window.Input.Text = string.Empty; + SendMessage(new PaperInputText(obj.Text)); + + if (_window != null) + { + _window.Input.Text = string.Empty; + } } } } diff --git a/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs b/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs index dc03aa9f97..ee2cbbc589 100644 --- a/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs +++ b/Content.Client/GameObjects/Components/ParticleAcceleratorPartVisualizer.cs @@ -14,16 +14,22 @@ namespace Content.Client.GameObjects.Components public class ParticleAcceleratorPartVisualizer : AppearanceVisualizer, ISerializationHooks { [DataField("baseState", required: true)] - private string _baseState; + private string? _baseState; + private Dictionary _states = new(); void ISerializationHooks.AfterDeserialization() { - _states.Add(ParticleAcceleratorVisualState.Powered, _baseState+"p"); - _states.Add(ParticleAcceleratorVisualState.Level0, _baseState+"p0"); - _states.Add(ParticleAcceleratorVisualState.Level1, _baseState+"p1"); - _states.Add(ParticleAcceleratorVisualState.Level2, _baseState+"p2"); - _states.Add(ParticleAcceleratorVisualState.Level3, _baseState+"p3"); + if (_baseState == null) + { + return; + } + + _states.Add(ParticleAcceleratorVisualState.Powered, _baseState + "p"); + _states.Add(ParticleAcceleratorVisualState.Level0, _baseState + "p0"); + _states.Add(ParticleAcceleratorVisualState.Level1, _baseState + "p1"); + _states.Add(ParticleAcceleratorVisualState.Level2, _baseState + "p2"); + _states.Add(ParticleAcceleratorVisualState.Level3, _baseState + "p3"); } public override void InitializeEntity(IEntity entity) diff --git a/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs b/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs index ff207ce795..ab47a4a048 100644 --- a/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs +++ b/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Maths; diff --git a/Content.Client/GameObjects/Components/Pointing/PointingArrowComponent.cs b/Content.Client/GameObjects/Components/Pointing/PointingArrowComponent.cs index c12776b01c..92ac28a48a 100644 --- a/Content.Client/GameObjects/Components/Pointing/PointingArrowComponent.cs +++ b/Content.Client/GameObjects/Components/Pointing/PointingArrowComponent.cs @@ -12,7 +12,7 @@ namespace Content.Client.GameObjects.Components.Pointing { base.Startup(); - if (Owner.TryGetComponent(out SpriteComponent sprite)) + if (Owner.TryGetComponent(out SpriteComponent? sprite)) { sprite.DrawDepth = (int) DrawDepth.Overlays; } diff --git a/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs b/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs index 4b7cfe3681..19ab52f197 100644 --- a/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs +++ b/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowComponent.cs @@ -12,7 +12,7 @@ namespace Content.Client.GameObjects.Components.Pointing { base.Startup(); - if (Owner.TryGetComponent(out SpriteComponent sprite)) + if (Owner.TryGetComponent(out SpriteComponent? sprite)) { sprite.DrawDepth = (int) DrawDepth.Overlays; } diff --git a/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowVisualizer.cs b/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowVisualizer.cs index 4e5be3ac4d..b326240ea1 100644 --- a/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowVisualizer.cs +++ b/Content.Client/GameObjects/Components/Pointing/RoguePointingArrowVisualizer.cs @@ -30,7 +30,7 @@ namespace Content.Client.GameObjects.Components.Pointing { var sprite = component.Owner.GetComponent(); - if (!sprite.Owner.TryGetComponent(out AnimationPlayerComponent animation)) + if (!sprite.Owner.TryGetComponent(out AnimationPlayerComponent? animation)) { sprite.Rotation = rotation; return; diff --git a/Content.Client/GameObjects/Components/Power/AME/AMEControllerBoundUserInterface.cs b/Content.Client/GameObjects/Components/Power/AME/AMEControllerBoundUserInterface.cs index 20ca74fe12..a7b56e82ff 100644 --- a/Content.Client/GameObjects/Components/Power/AME/AMEControllerBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Power/AME/AMEControllerBoundUserInterface.cs @@ -9,11 +9,10 @@ namespace Content.Client.GameObjects.Components.Power.AME [UsedImplicitly] public class AMEControllerBoundUserInterface : BoundUserInterface { - private AMEWindow _window; + private AMEWindow? _window; public AMEControllerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - } protected override void Open() @@ -31,7 +30,6 @@ namespace Content.Client.GameObjects.Components.Power.AME _window.RefreshPartsButton.OnPressed += _ => ButtonPressed(UiButton.RefreshParts); } - /// /// Update the ui each time new state data is sent from the server. /// @@ -58,7 +56,7 @@ namespace Content.Client.GameObjects.Components.Power.AME if (disposing) { - _window.Dispose(); + _window?.Dispose(); } } } diff --git a/Content.Client/GameObjects/Components/Power/AME/AMEWindow.cs b/Content.Client/GameObjects/Components/Power/AME/AMEWindow.cs index a6b13fc39d..d5c861cea4 100644 --- a/Content.Client/GameObjects/Components/Power/AME/AMEWindow.cs +++ b/Content.Client/GameObjects/Components/Power/AME/AMEWindow.cs @@ -17,7 +17,7 @@ namespace Content.Client.GameObjects.Components.Power.AME public Button IncreaseFuelButton { get; set; } public Button DecreaseFuelButton { get; set; } public Button RefreshPartsButton { get; set; } - public ProgressBar FuelMeter { get; set; } + public ProgressBar? FuelMeter { get; set; } public Label FuelAmount { get; set; } public Label InjectionAmount { get; set; } public Label CoreCount { get; set; } @@ -89,10 +89,8 @@ namespace Content.Client.GameObjects.Components.Power.AME } } }); - } - /// /// This searches recursively through all the children of "parent" /// and sets the Disabled value of any buttons found to "val" @@ -162,7 +160,6 @@ namespace Content.Client.GameObjects.Components.Power.AME CoreCount.Text = $"{castState.CoreCount}"; InjectionAmount.Text = $"{castState.InjectionAmount}"; - } } } diff --git a/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs b/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs index 6a7a77408f..412deaa37d 100644 --- a/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs @@ -14,10 +14,10 @@ namespace Content.Client.GameObjects.Components.Power [UsedImplicitly] public class ApcBoundUserInterface : BoundUserInterface { - private ApcWindow _window; - private BaseButton _breakerButton; - private Label _externalPowerStateLabel; - private ProgressBar _chargeBar; + private ApcWindow? _window; + private BaseButton? _breakerButton; + private Label? _externalPowerStateLabel; + private ProgressBar? _chargeBar; protected override void Open() { @@ -44,33 +44,52 @@ namespace Content.Client.GameObjects.Components.Power var castState = (ApcBoundInterfaceState) state; - _breakerButton.Pressed = castState.MainBreaker; - switch (castState.ApcExternalPower) + if (_breakerButton != null) { - case ApcExternalPowerState.None: - _externalPowerStateLabel.Text = "None"; - _externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone); - break; - case ApcExternalPowerState.Low: - _externalPowerStateLabel.Text = "Low"; - _externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow); - break; - case ApcExternalPowerState.Good: - _externalPowerStateLabel.Text = "Good"; - _externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood); - break; - default: - throw new ArgumentOutOfRangeException(); + _breakerButton.Pressed = castState.MainBreaker; } - _chargeBar.Value = castState.Charge; - UpdateChargeBarColor(castState.Charge); - var chargePercentage = (castState.Charge / _chargeBar.MaxValue) * 100.0f; - _window.ChargePercentage.Text = " " + chargePercentage.ToString("0.00") + "%"; + if (_externalPowerStateLabel != null) + { + switch (castState.ApcExternalPower) + { + case ApcExternalPowerState.None: + _externalPowerStateLabel.Text = "None"; + _externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateNone); + break; + case ApcExternalPowerState.Low: + _externalPowerStateLabel.Text = "Low"; + _externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateLow); + break; + case ApcExternalPowerState.Good: + _externalPowerStateLabel.Text = "Good"; + _externalPowerStateLabel.SetOnlyStyleClass(StyleNano.StyleClassPowerStateGood); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (_chargeBar != null) + { + _chargeBar.Value = castState.Charge; + UpdateChargeBarColor(castState.Charge); + + if (_window != null) + { + var chargePercentage = (castState.Charge / _chargeBar.MaxValue) * 100.0f; + _window.ChargePercentage.Text = " " + chargePercentage.ToString("0.00") + "%"; + } + } } private void UpdateChargeBarColor(float charge) { + if (_chargeBar == null) + { + return; + } + var normalizedCharge = charge / _chargeBar.MaxValue; const float leftHue = 0.0f; // Red @@ -97,10 +116,7 @@ namespace Content.Client.GameObjects.Components.Power } // Check if null first to avoid repeatedly creating this. - if (_chargeBar.ForegroundStyleBoxOverride == null) - { - _chargeBar.ForegroundStyleBoxOverride = new StyleBoxFlat(); - } + _chargeBar.ForegroundStyleBoxOverride ??= new StyleBoxFlat(); var foregroundStyleBoxOverride = (StyleBoxFlat) _chargeBar.ForegroundStyleBoxOverride; foregroundStyleBoxOverride.BackgroundColor = @@ -113,7 +129,7 @@ namespace Content.Client.GameObjects.Components.Power if (disposing) { - _window.Dispose(); + _window?.Dispose(); } } diff --git a/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs b/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs index ba876758f7..ffbcd1fadb 100644 --- a/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs +++ b/Content.Client/GameObjects/Components/Power/PowerCellVisualizer.cs @@ -1,11 +1,8 @@ -using System.Diagnostics; using Content.Shared.GameObjects.Components.Power; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Power { @@ -13,7 +10,7 @@ namespace Content.Client.GameObjects.Components.Power public class PowerCellVisualizer : AppearanceVisualizer { [DataField("prefix")] - private string _prefix; + private string? _prefix; public override void InitializeEntity(IEntity entity) { @@ -21,8 +18,11 @@ namespace Content.Client.GameObjects.Components.Power var sprite = entity.GetComponent(); - sprite.LayerMapSet(Layers.Charge, sprite.AddLayerState($"{_prefix}_100")); - sprite.LayerSetShader(Layers.Charge, "unshaded"); + if (_prefix != null) + { + sprite.LayerMapSet(Layers.Charge, sprite.AddLayerState($"{_prefix}_100")); + sprite.LayerSetShader(Layers.Charge, "unshaded"); + } } public override void OnChangeData(AppearanceComponent component) diff --git a/Content.Client/GameObjects/Components/Power/SolarControlConsoleBoundUserInterface.cs b/Content.Client/GameObjects/Components/Power/SolarControlConsoleBoundUserInterface.cs index efef0ea092..5a2823ceed 100644 --- a/Content.Client/GameObjects/Components/Power/SolarControlConsoleBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Power/SolarControlConsoleBoundUserInterface.cs @@ -16,9 +16,9 @@ namespace Content.Client.GameObjects.Components.Power [UsedImplicitly] public class SolarControlConsoleBoundUserInterface : BoundUserInterface { - [Dependency] private readonly IGameTiming _gameTiming = default; + [Dependency] private readonly IGameTiming _gameTiming = default!; - private SolarControlWindow _window; + private SolarControlWindow? _window; private SolarControlConsoleBoundInterfaceState _lastState = new(0, 0, 0, 0); protected override void Open() @@ -73,6 +73,11 @@ namespace Content.Client.GameObjects.Components.Power { base.UpdateState(state); + if (_window == null) + { + return; + } + SolarControlConsoleBoundInterfaceState scc = (SolarControlConsoleBoundInterfaceState) state; _lastState = scc; _window.NotARadar.UpdateState(scc); @@ -88,7 +93,7 @@ namespace Content.Client.GameObjects.Components.Power if (disposing) { - _window.Dispose(); + _window?.Dispose(); } } @@ -180,27 +185,27 @@ namespace Content.Client.GameObjects.Components.Power protected override void Draw(DrawingHandleScreen handle) { - int point = SizeFull / 2; - Color fakeAA = new Color(0.08f, 0.08f, 0.08f); - Color gridLines = new Color(0.08f, 0.08f, 0.08f); - int panelExtentCutback = 4; - int gridLinesRadial = 8; - int gridLinesEquatorial = 8; + var point = SizeFull / 2; + var fakeAA = new Color(0.08f, 0.08f, 0.08f); + var gridLines = new Color(0.08f, 0.08f, 0.08f); + var panelExtentCutback = 4; + var gridLinesRadial = 8; + var gridLinesEquatorial = 8; // Draw base handle.DrawCircle((point, point), RadiusCircle + 1, fakeAA); handle.DrawCircle((point, point), RadiusCircle, Color.Black); // Draw grid lines - for (int i = 0; i < gridLinesEquatorial; i++) + for (var i = 0; i < gridLinesEquatorial; i++) { handle.DrawCircle((point, point), (RadiusCircle / gridLinesEquatorial) * i, gridLines, false); } - for (int i = 0; i < gridLinesRadial; i++) + for (var i = 0; i < gridLinesRadial; i++) { Angle angle = (Math.PI / gridLinesRadial) * i; - Vector2 aExtent = angle.ToVec() * RadiusCircle; + var aExtent = angle.ToVec() * RadiusCircle; handle.DrawLine((point, point) - aExtent, (point, point) + aExtent, gridLines); } @@ -209,12 +214,12 @@ namespace Content.Client.GameObjects.Components.Power Angle predictedPanelRotation = _lastState.Rotation + (_lastState.AngularVelocity * ((_gameTiming.CurTime - _lastStateTime).TotalSeconds)); - Vector2 extent = predictedPanelRotation.ToVec() * rotMul * RadiusCircle; + var extent = predictedPanelRotation.ToVec() * rotMul * RadiusCircle; Vector2 extentOrtho = (extent.Y, -extent.X); handle.DrawLine((point, point) - extentOrtho, (point, point) + extentOrtho, Color.White); handle.DrawLine((point, point) + (extent / panelExtentCutback), (point, point) + extent - (extent / panelExtentCutback), Color.DarkGray); - Vector2 sunExtent = _lastState.TowardsSun.ToVec() * rotMul * RadiusCircle; + var sunExtent = _lastState.TowardsSun.ToVec() * rotMul * RadiusCircle; handle.DrawLine((point, point) + sunExtent, (point, point), Color.Yellow); } } diff --git a/Content.Client/GameObjects/Components/Projectiles/ProjectileComponent.cs b/Content.Client/GameObjects/Components/Projectiles/ProjectileComponent.cs index 9abf4a557b..d991ca7d97 100644 --- a/Content.Client/GameObjects/Components/Projectiles/ProjectileComponent.cs +++ b/Content.Client/GameObjects/Components/Projectiles/ProjectileComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Projectiles; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs b/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs index 00c5d9035e..30c1311a84 100644 --- a/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs +++ b/Content.Client/GameObjects/Components/RadiationCollectorVisualizer.cs @@ -13,8 +13,8 @@ namespace Content.Client.GameObjects.Components { private const string AnimationKey = "radiationcollector_animation"; - private Animation ActivateAnimation; - private Animation DeactiveAnimation; + private Animation ActivateAnimation = default!; + private Animation DeactiveAnimation = default!; void ISerializationHooks.AfterDeserialization() { @@ -91,6 +91,7 @@ namespace Content.Client.GameObjects.Components } } } + public enum RadiationCollectorVisualLayers : byte { Main diff --git a/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs b/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs index 3001139977..64dd202504 100644 --- a/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs +++ b/Content.Client/GameObjects/Components/Recycling/RecyclerVisualizer.cs @@ -3,8 +3,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Recycling { @@ -12,16 +10,17 @@ namespace Content.Client.GameObjects.Components.Recycling public class RecyclerVisualizer : AppearanceVisualizer { [DataField("state_clean")] - private string _stateClean; + private string? _stateClean; + [DataField("state_bloody")] - private string _stateBloody; + private string? _stateBloody; public override void InitializeEntity(IEntity entity) { base.InitializeEntity(entity); - if (!entity.TryGetComponent(out ISpriteComponent sprite) || - !entity.TryGetComponent(out AppearanceComponent appearance)) + if (!entity.TryGetComponent(out ISpriteComponent? sprite) || + !entity.TryGetComponent(out AppearanceComponent? appearance)) { return; } @@ -36,7 +35,7 @@ namespace Content.Client.GameObjects.Components.Recycling { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs b/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs index fce7793bd4..4ba8bfbd3e 100644 --- a/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs +++ b/Content.Client/GameObjects/Components/ReinforcedWallComponent.cs @@ -1,7 +1,5 @@ using Content.Client.GameObjects.Components.IconSmoothing; using Robust.Shared.GameObjects; -using Robust.Shared.Prototypes; -using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; using static Robust.Client.GameObjects.SpriteComponent; @@ -16,22 +14,25 @@ namespace Content.Client.GameObjects.Components [ViewVariables(VVAccess.ReadWrite)] [DataField("reinforcedBase")] - private string _reinforcedStateBase = default; + private string? _reinforcedStateBase = default; protected override void Startup() { base.Startup(); - var state0 = $"{_reinforcedStateBase}0"; - Sprite.LayerMapSet(ReinforcedCornerLayers.SE, Sprite.AddLayerState(state0)); - Sprite.LayerSetDirOffset(ReinforcedCornerLayers.SE, DirectionOffset.None); - Sprite.LayerMapSet(ReinforcedCornerLayers.NE, Sprite.AddLayerState(state0)); - Sprite.LayerSetDirOffset(ReinforcedCornerLayers.NE, DirectionOffset.CounterClockwise); - Sprite.LayerMapSet(ReinforcedCornerLayers.NW, Sprite.AddLayerState(state0)); - Sprite.LayerSetDirOffset(ReinforcedCornerLayers.NW, DirectionOffset.Flip); - Sprite.LayerMapSet(ReinforcedCornerLayers.SW, Sprite.AddLayerState(state0)); - Sprite.LayerSetDirOffset(ReinforcedCornerLayers.SW, DirectionOffset.Clockwise); - Sprite.LayerMapSet(ReinforcedWallVisualLayers.Deconstruction, Sprite.AddBlankLayer()); + if (Sprite != null) + { + var state0 = $"{_reinforcedStateBase}0"; + Sprite.LayerMapSet(ReinforcedCornerLayers.SE, Sprite.AddLayerState(state0)); + Sprite.LayerSetDirOffset(ReinforcedCornerLayers.SE, DirectionOffset.None); + Sprite.LayerMapSet(ReinforcedCornerLayers.NE, Sprite.AddLayerState(state0)); + Sprite.LayerSetDirOffset(ReinforcedCornerLayers.NE, DirectionOffset.CounterClockwise); + Sprite.LayerMapSet(ReinforcedCornerLayers.NW, Sprite.AddLayerState(state0)); + Sprite.LayerSetDirOffset(ReinforcedCornerLayers.NW, DirectionOffset.Flip); + Sprite.LayerMapSet(ReinforcedCornerLayers.SW, Sprite.AddLayerState(state0)); + Sprite.LayerSetDirOffset(ReinforcedCornerLayers.SW, DirectionOffset.Clockwise); + Sprite.LayerMapSet(ReinforcedWallVisualLayers.Deconstruction, Sprite.AddBlankLayer()); + } } internal override void CalculateNewSprite() @@ -40,10 +41,13 @@ namespace Content.Client.GameObjects.Components var (cornerNE, cornerNW, cornerSW, cornerSE) = CalculateCornerFill(); - Sprite.LayerSetState(ReinforcedCornerLayers.NE, $"{_reinforcedStateBase}{(int) cornerNE}"); - Sprite.LayerSetState(ReinforcedCornerLayers.SE, $"{_reinforcedStateBase}{(int) cornerSE}"); - Sprite.LayerSetState(ReinforcedCornerLayers.SW, $"{_reinforcedStateBase}{(int) cornerSW}"); - Sprite.LayerSetState(ReinforcedCornerLayers.NW, $"{_reinforcedStateBase}{(int) cornerNW}"); + if (Sprite != null) + { + Sprite.LayerSetState(ReinforcedCornerLayers.NE, $"{_reinforcedStateBase}{(int) cornerNE}"); + Sprite.LayerSetState(ReinforcedCornerLayers.SE, $"{_reinforcedStateBase}{(int) cornerSE}"); + Sprite.LayerSetState(ReinforcedCornerLayers.SW, $"{_reinforcedStateBase}{(int) cornerSW}"); + Sprite.LayerSetState(ReinforcedCornerLayers.NW, $"{_reinforcedStateBase}{(int) cornerNW}"); + } } public enum ReinforcedCornerLayers : byte diff --git a/Content.Client/GameObjects/Components/ReinforcedWallVisualizer.cs b/Content.Client/GameObjects/Components/ReinforcedWallVisualizer.cs index d4a5ba4def..ff0ffbd6b3 100644 --- a/Content.Client/GameObjects/Components/ReinforcedWallVisualizer.cs +++ b/Content.Client/GameObjects/Components/ReinforcedWallVisualizer.cs @@ -21,7 +21,7 @@ namespace Content.Client.GameObjects.Components { var entity = component.Owner; - if (!entity.TryGetComponent(out ISpriteComponent sprite)) return; + if (!entity.TryGetComponent(out ISpriteComponent? sprite)) return; if (stage < 0) { diff --git a/Content.Client/GameObjects/Components/Research/LatheBoundUserInterface.cs b/Content.Client/GameObjects/Components/Research/LatheBoundUserInterface.cs index 668021a306..4b8e2d7c71 100644 --- a/Content.Client/GameObjects/Components/Research/LatheBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Research/LatheBoundUserInterface.cs @@ -7,6 +7,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Prototypes; using Robust.Shared.ViewVariables; +using static Content.Shared.GameObjects.Components.Research.SharedLatheComponent; namespace Content.Client.GameObjects.Components.Research { @@ -15,13 +16,13 @@ namespace Content.Client.GameObjects.Components.Research [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [ViewVariables] - private LatheMenu _menu; + private LatheMenu? _menu; [ViewVariables] - private LatheQueueMenu _queueMenu; + private LatheQueueMenu? _queueMenu; - public MaterialStorageComponent Storage { get; private set; } - public SharedLatheComponent Lathe { get; private set; } - public SharedLatheDatabaseComponent Database { get; private set; } + public MaterialStorageComponent? Storage { get; private set; } + public SharedLatheComponent? Lathe { get; private set; } + public SharedLatheDatabaseComponent? Database { get; private set; } [ViewVariables] public Queue QueuedRecipes => _queuedRecipes; @@ -29,41 +30,39 @@ namespace Content.Client.GameObjects.Components.Research public LatheBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - SendMessage(new SharedLatheComponent.LatheSyncRequestMessage()); + SendMessage(new LatheSyncRequestMessage()); } protected override void Open() { base.Open(); - if (!Owner.Owner.TryGetComponent(out MaterialStorageComponent storage) - || !Owner.Owner.TryGetComponent(out SharedLatheComponent lathe) - || !Owner.Owner.TryGetComponent(out SharedLatheDatabaseComponent database)) return; - - + if (!Owner.Owner.TryGetComponent(out MaterialStorageComponent? storage) + || !Owner.Owner.TryGetComponent(out SharedLatheComponent? lathe) + || !Owner.Owner.TryGetComponent(out SharedLatheDatabaseComponent? database)) return; Storage = storage; Lathe = lathe; Database = database; _menu = new LatheMenu(this); - _queueMenu = new LatheQueueMenu { Owner = this }; + _queueMenu = new LatheQueueMenu(this); _menu.OnClose += Close; _menu.Populate(); _menu.PopulateMaterials(); - _menu.QueueButton.OnPressed += (args) => { _queueMenu.OpenCentered(); }; + _menu.QueueButton.OnPressed += (_) => { _queueMenu.OpenCentered(); }; - _menu.ServerConnectButton.OnPressed += (args) => + _menu.ServerConnectButton.OnPressed += (_) => { - SendMessage(new SharedLatheComponent.LatheServerSelectionMessage()); + SendMessage(new LatheServerSelectionMessage()); }; - _menu.ServerSyncButton.OnPressed += (args) => + _menu.ServerSyncButton.OnPressed += (_) => { - SendMessage(new SharedLatheComponent.LatheServerSyncMessage()); + SendMessage(new LatheServerSyncMessage()); }; storage.OnMaterialStorageChanged += _menu.PopulateDisabled; @@ -74,25 +73,25 @@ namespace Content.Client.GameObjects.Components.Research public void Queue(LatheRecipePrototype recipe, int quantity = 1) { - SendMessage(new SharedLatheComponent.LatheQueueRecipeMessage(recipe.ID, quantity)); + SendMessage(new LatheQueueRecipeMessage(recipe.ID, quantity)); } protected override void ReceiveMessage(BoundUserInterfaceMessage message) { switch (message) { - case SharedLatheComponent.LatheProducingRecipeMessage msg: - if (!_prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe)) break; + case LatheProducingRecipeMessage msg: + if (!_prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype? recipe)) break; _queueMenu?.SetInfo(recipe); break; - case SharedLatheComponent.LatheStoppedProducingRecipeMessage _: + case LatheStoppedProducingRecipeMessage _: _queueMenu?.ClearInfo(); break; - case SharedLatheComponent.LatheFullQueueMessage msg: + case LatheFullQueueMessage msg: _queuedRecipes.Clear(); foreach (var id in msg.Recipes) { - if (!_prototypeManager.TryIndex(id, out LatheRecipePrototype recipePrototype)) break; + if (!_prototypeManager.TryIndex(id, out LatheRecipePrototype? recipePrototype)) break; _queuedRecipes.Enqueue(recipePrototype); } _queueMenu?.PopulateList(); diff --git a/Content.Client/GameObjects/Components/Research/LatheDatabaseComponent.cs b/Content.Client/GameObjects/Components/Research/LatheDatabaseComponent.cs index efb1d1d15e..465fb9b6a8 100644 --- a/Content.Client/GameObjects/Components/Research/LatheDatabaseComponent.cs +++ b/Content.Client/GameObjects/Components/Research/LatheDatabaseComponent.cs @@ -12,14 +12,17 @@ namespace Content.Client.GameObjects.Components.Research { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); + if (curState is not LatheDatabaseState state) return; + Clear(); + foreach (var ID in state.Recipes) { - if(!_prototypeManager.TryIndex(ID, out LatheRecipePrototype recipe)) continue; + if (!_prototypeManager.TryIndex(ID, out LatheRecipePrototype? recipe)) continue; AddRecipe(recipe); } } diff --git a/Content.Client/GameObjects/Components/Research/MaterialStorageComponent.cs b/Content.Client/GameObjects/Components/Research/MaterialStorageComponent.cs index 7024ced072..bb609ed6f0 100644 --- a/Content.Client/GameObjects/Components/Research/MaterialStorageComponent.cs +++ b/Content.Client/GameObjects/Components/Research/MaterialStorageComponent.cs @@ -11,9 +11,9 @@ namespace Content.Client.GameObjects.Components.Research { protected override Dictionary Storage { get; set; } = new(); - public event Action OnMaterialStorageChanged; + public event Action? OnMaterialStorageChanged; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); if (curState is not MaterialStorageState state) return; diff --git a/Content.Client/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs b/Content.Client/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs index dad88197b1..dd42799c70 100644 --- a/Content.Client/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs +++ b/Content.Client/GameObjects/Components/Research/ProtolatheDatabaseComponent.cs @@ -16,16 +16,19 @@ namespace Content.Client.GameObjects.Components.Research /// /// Invoked when the database gets updated. /// - public event Action OnDatabaseUpdated; + public event Action? OnDatabaseUpdated; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); + if (curState is not ProtolatheDatabaseState state) return; + Clear(); + foreach (var ID in state.Recipes) { - if(!_prototypeManager.TryIndex(ID, out LatheRecipePrototype recipe)) continue; + if(!_prototypeManager.TryIndex(ID, out LatheRecipePrototype? recipe)) continue; AddRecipe(recipe); } diff --git a/Content.Client/GameObjects/Components/Research/ResearchClientBoundUserInterface.cs b/Content.Client/GameObjects/Components/Research/ResearchClientBoundUserInterface.cs index e84b0241fe..4b021ce686 100644 --- a/Content.Client/GameObjects/Components/Research/ResearchClientBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Research/ResearchClientBoundUserInterface.cs @@ -1,45 +1,42 @@ -using Content.Shared.GameObjects.Components.Research; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using static Content.Shared.GameObjects.Components.Research.SharedResearchClientComponent; namespace Content.Client.GameObjects.Components.Research { public class ResearchClientBoundUserInterface : BoundUserInterface { - private ResearchClientServerSelectionMenu _menu; + private ResearchClientServerSelectionMenu? _menu; public ResearchClientBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - SendMessage(new SharedResearchClientComponent.ResearchClientSyncMessage()); + SendMessage(new ResearchClientSyncMessage()); } protected override void Open() { base.Open(); - _menu = new ResearchClientServerSelectionMenu() { Owner = this }; - + _menu = new ResearchClientServerSelectionMenu(this); _menu.OnClose += Close; - _menu.OpenCentered(); } public void SelectServer(int serverId) { - SendMessage(new SharedResearchClientComponent.ResearchClientServerSelectedMessage(serverId)); + SendMessage(new ResearchClientServerSelectedMessage(serverId)); } public void DeselectServer() { - SendMessage(new SharedResearchClientComponent.ResearchClientServerDeselectedMessage()); + SendMessage(new ResearchClientServerDeselectedMessage()); } protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - if (state is not SharedResearchClientComponent.ResearchClientBoundInterfaceState rState) return; - _menu.Populate(rState.ServerCount, rState.ServerNames, rState.ServerIds, rState.SelectedServerId); - + if (state is not ResearchClientBoundInterfaceState rState) return; + _menu?.Populate(rState.ServerCount, rState.ServerNames, rState.ServerIds, rState.SelectedServerId); } } } diff --git a/Content.Client/GameObjects/Components/Research/ResearchClientServerSelectionMenu.cs b/Content.Client/GameObjects/Components/Research/ResearchClientServerSelectionMenu.cs index 39957f0e03..3b00b70510 100644 --- a/Content.Client/GameObjects/Components/Research/ResearchClientServerSelectionMenu.cs +++ b/Content.Client/GameObjects/Components/Research/ResearchClientServerSelectionMenu.cs @@ -9,18 +9,19 @@ namespace Content.Client.GameObjects.Components.Research public class ResearchClientServerSelectionMenu : SS14Window { private readonly ItemList _servers; - private int _serverCount = 0; + private int _serverCount; private string[] _serverNames = new string[]{}; private int[] _serverIds = new int[]{}; private int _selectedServerId = -1; - public ResearchClientBoundUserInterface Owner { get; set; } + public ResearchClientBoundUserInterface Owner { get; } - public ResearchClientServerSelectionMenu() + public ResearchClientServerSelectionMenu(ResearchClientBoundUserInterface owner) { MinSize = SetSize = (300, 300); IoCManager.InjectDependencies(this); + Owner = owner; Title = Loc.GetString("Research Server Selection"); _servers = new ItemList() {SelectMode = ItemList.ItemListSelectMode.Single}; diff --git a/Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs b/Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs index 9e018b40af..56ac64a206 100644 --- a/Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs @@ -1,69 +1,73 @@ using Content.Client.Research; -using Content.Shared.GameObjects.Components.Research; using Content.Shared.Research; +using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using static Content.Shared.GameObjects.Components.Research.SharedResearchConsoleComponent; namespace Content.Client.GameObjects.Components.Research { + [UsedImplicitly] public class ResearchConsoleBoundUserInterface : BoundUserInterface { - public int Points { get; private set; } = 0; - public int PointsPerSecond { get; private set; } = 0; - private ResearchConsoleMenu _consoleMenu; - private TechnologyDatabaseComponent TechnologyDatabase; - + public int Points { get; private set; } + public int PointsPerSecond { get; private set; } + private ResearchConsoleMenu? _consoleMenu; + private TechnologyDatabaseComponent? _technologyDatabase; public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - SendMessage(new SharedResearchConsoleComponent.ConsoleServerSyncMessage()); + SendMessage(new ConsoleServerSyncMessage()); } protected override void Open() { base.Open(); - if (!Owner.Owner.TryGetComponent(out TechnologyDatabase)) return; + if (!Owner.Owner.TryGetComponent(out _technologyDatabase)) return; _consoleMenu = new ResearchConsoleMenu(this); _consoleMenu.OnClose += Close; - _consoleMenu.ServerSyncButton.OnPressed += (args) => - { - SendMessage(new SharedResearchConsoleComponent.ConsoleServerSyncMessage()); - }; - - _consoleMenu.ServerSelectionButton.OnPressed += (args) => + _consoleMenu.ServerSyncButton.OnPressed += (_) => { - SendMessage(new SharedResearchConsoleComponent.ConsoleServerSelectionMessage()); + SendMessage(new ConsoleServerSyncMessage()); }; - _consoleMenu.UnlockButton.OnPressed += (args) => + _consoleMenu.ServerSelectionButton.OnPressed += (_) => { - SendMessage(new SharedResearchConsoleComponent.ConsoleUnlockTechnologyMessage(_consoleMenu.TechnologySelected.ID)); + SendMessage(new ConsoleServerSelectionMessage()); + }; + + _consoleMenu.UnlockButton.OnPressed += (_) => + { + if (_consoleMenu.TechnologySelected != null) + { + SendMessage(new ConsoleUnlockTechnologyMessage(_consoleMenu.TechnologySelected.ID)); + } }; _consoleMenu.OpenCentered(); - TechnologyDatabase.OnDatabaseUpdated += _consoleMenu.Populate; + _technologyDatabase.OnDatabaseUpdated += _consoleMenu.Populate; } public bool IsTechnologyUnlocked(TechnologyPrototype technology) { - return TechnologyDatabase.IsTechnologyUnlocked(technology); + return _technologyDatabase?.IsTechnologyUnlocked(technology) ?? false; } public bool CanUnlockTechnology(TechnologyPrototype technology) { - return TechnologyDatabase.CanUnlockTechnology(technology); + return _technologyDatabase?.CanUnlockTechnology(technology) ?? false; } protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - var castState = (SharedResearchConsoleComponent.ResearchConsoleBoundInterfaceState)state; + var castState = (ResearchConsoleBoundInterfaceState)state; Points = castState.Points; PointsPerSecond = castState.PointsPerSecond; // We update the user interface here. diff --git a/Content.Client/GameObjects/Components/Research/TechnologyDatabaseComponent.cs b/Content.Client/GameObjects/Components/Research/TechnologyDatabaseComponent.cs index fe4a8ac633..152ffedd7a 100644 --- a/Content.Client/GameObjects/Components/Research/TechnologyDatabaseComponent.cs +++ b/Content.Client/GameObjects/Components/Research/TechnologyDatabaseComponent.cs @@ -13,22 +13,25 @@ namespace Content.Client.GameObjects.Components.Research /// /// Event called when the database is updated. /// - public event Action OnDatabaseUpdated; + public event Action? OnDatabaseUpdated; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); + if (curState is not TechnologyDatabaseState state) return; + _technologies.Clear(); + var protoManager = IoCManager.Resolve(); + foreach (var techID in state.Technologies) { - if (!protoManager.TryIndex(techID, out TechnologyPrototype technology)) continue; + if (!protoManager.TryIndex(techID, out TechnologyPrototype? technology)) continue; _technologies.Add(technology); } OnDatabaseUpdated?.Invoke(); - } } } diff --git a/Content.Client/GameObjects/Components/Rotation/RotationVisualizer.cs b/Content.Client/GameObjects/Components/Rotation/RotationVisualizer.cs index 5295c3bb4e..e835d83cb7 100644 --- a/Content.Client/GameObjects/Components/Rotation/RotationVisualizer.cs +++ b/Content.Client/GameObjects/Components/Rotation/RotationVisualizer.cs @@ -33,7 +33,7 @@ namespace Content.Client.GameObjects.Components.Rotation { var sprite = component.Owner.GetComponent(); - if (!sprite.Owner.TryGetComponent(out AnimationPlayerComponent animation)) + if (!sprite.Owner.TryGetComponent(out AnimationPlayerComponent? animation)) { sprite.Rotation = rotation; return; diff --git a/Content.Client/GameObjects/Components/Singularity/ClientSingularityComponent.cs b/Content.Client/GameObjects/Components/Singularity/ClientSingularityComponent.cs index 2859fea072..69c7ef384d 100644 --- a/Content.Client/GameObjects/Components/Singularity/ClientSingularityComponent.cs +++ b/Content.Client/GameObjects/Components/Singularity/ClientSingularityComponent.cs @@ -1,7 +1,6 @@ using Content.Shared.GameObjects.Components.Singularity; using Robust.Shared.GameObjects; - namespace Content.Client.GameObjects.Components.Singularity { [RegisterComponent] @@ -21,7 +20,7 @@ namespace Content.Client.GameObjects.Components.Singularity } private int _level; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { if (curState is not SingularityComponentState state) { diff --git a/Content.Client/GameObjects/Components/Singularity/ContainmentFieldComponent.cs b/Content.Client/GameObjects/Components/Singularity/ContainmentFieldComponent.cs index db6486117e..603f6516ad 100644 --- a/Content.Client/GameObjects/Components/Singularity/ContainmentFieldComponent.cs +++ b/Content.Client/GameObjects/Components/Singularity/ContainmentFieldComponent.cs @@ -1,16 +1,14 @@ -using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Log; namespace Content.Client.GameObjects.Components.Singularity { - [UsedImplicitly] public class ContainmentFieldComponent : Component { public override string Name => "Containment Field"; - private SpriteComponent _spriteComponent; + private SpriteComponent? _spriteComponent; public override void Initialize() { diff --git a/Content.Client/GameObjects/Components/Singularity/EmitterVisualizer.cs b/Content.Client/GameObjects/Components/Singularity/EmitterVisualizer.cs index f1fd90ab95..9f918f330d 100644 --- a/Content.Client/GameObjects/Components/Singularity/EmitterVisualizer.cs +++ b/Content.Client/GameObjects/Components/Singularity/EmitterVisualizer.cs @@ -15,7 +15,7 @@ namespace Content.Client.GameObjects.Components.Singularity { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs b/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs index 7da6c6878e..4b78bbadc5 100644 --- a/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs +++ b/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs @@ -62,11 +62,11 @@ namespace Content.Client.GameObjects.Components.Sound if (!_audioStreams.ContainsKey(schedule)) { - _audioStreams.Add(schedule,SoundSystem.Play(Filter.Local(), schedule.Filename, Owner, schedule.AudioParams)); + _audioStreams.Add(schedule, SoundSystem.Play(Filter.Local(), schedule.Filename, Owner, schedule.AudioParams)!); } else { - _audioStreams[schedule] = SoundSystem.Play(Filter.Local(), schedule.Filename, Owner, schedule.AudioParams); + _audioStreams[schedule] = SoundSystem.Play(Filter.Local(), schedule.Filename, Owner, schedule.AudioParams)!; } if (schedule.Times == 0) return; @@ -77,7 +77,7 @@ namespace Content.Client.GameObjects.Components.Sound }); } - public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null) + public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) { base.HandleNetworkMessage(message, channel, session); switch (message) diff --git a/Content.Client/GameObjects/Components/StationEvents/RadiationPulseComponent.cs b/Content.Client/GameObjects/Components/StationEvents/RadiationPulseComponent.cs index b56e1075ea..439ab8b5bc 100644 --- a/Content.Client/GameObjects/Components/StationEvents/RadiationPulseComponent.cs +++ b/Content.Client/GameObjects/Components/StationEvents/RadiationPulseComponent.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using Content.Shared.GameObjects.Components; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs index bf328c1963..4d61447945 100644 --- a/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs +++ b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs @@ -29,7 +29,7 @@ namespace Content.Client.GameObjects.Components.Storage private List _storedEntities = new(); private int StorageSizeUsed; private int StorageCapacityMax; - private StorageWindow Window; + private StorageWindow? _window; private SharedBagState _bagState; public override IReadOnlyList StoredEntities => _storedEntities; @@ -46,17 +46,16 @@ namespace Content.Client.GameObjects.Components.Storage { base.OnAdd(); - Window = new StorageWindow() - { StorageEntity = this, Title = Owner.Name }; + _window = new StorageWindow(this) {Title = Owner.Name}; } public override void OnRemove() { - Window.Dispose(); + _window?.Dispose(); base.OnRemove(); } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); @@ -70,7 +69,7 @@ namespace Content.Client.GameObjects.Components.Storage .ToList(); } - public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null) + public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) { base.HandleNetworkMessage(message, channel, session); @@ -105,7 +104,7 @@ namespace Content.Client.GameObjects.Components.Storage _storedEntities = storageState.StoredEntities.Select(id => Owner.EntityManager.GetEntity(id)).ToList(); StorageSizeUsed = storageState.StorageSizeUsed; StorageCapacityMax = storageState.StorageSizeMax; - Window.BuildEntityList(); + _window?.BuildEntityList(); } /// @@ -131,16 +130,17 @@ namespace Content.Client.GameObjects.Components.Storage /// private void ToggleUI() { - if (Window.IsOpen) + if (_window == null) return; - Window.Close(); + if (_window.IsOpen) + _window.Close(); else - Window.Open(); + _window.Open(); } private void CloseUI() { - Window.Close(); + _window?.Close(); } private void ChangeStorageVisualization(SharedBagState state) @@ -185,8 +185,9 @@ namespace Content.Client.GameObjects.Components.Storage private readonly StyleBoxFlat _hoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.35f) }; private readonly StyleBoxFlat _unHoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.0f) }; - public StorageWindow() + public StorageWindow(ClientStorageComponent storageEntity) { + StorageEntity = storageEntity; MinSize = SetSize = (180, 320); Title = "Storage Item"; RectClipContent = true; @@ -205,9 +206,9 @@ namespace Content.Client.GameObjects.Components.Storage containerButton.AddChild(innerContainerButton); containerButton.OnPressed += args => { - var controlledEntity = IoCManager.Resolve().LocalPlayer.ControlledEntity; + var controlledEntity = IoCManager.Resolve().LocalPlayer?.ControlledEntity; - if (controlledEntity.TryGetComponent(out HandsComponent hands)) + if (controlledEntity?.TryGetComponent(out HandsComponent? hands) ?? false) { StorageEntity.SendNetworkMessage(new InsertEntityMessage()); } @@ -288,7 +289,7 @@ namespace Content.Client.GameObjects.Components.Storage button.EntitySize.Text = group.Amount.ToString(); //Gets entity sprite and assigns it to button texture - if (entity.TryGetComponent(out ISpriteComponent sprite)) + if (entity.TryGetComponent(out ISpriteComponent? sprite)) { button.EntitySpriteView.Sprite = sprite; } @@ -314,9 +315,13 @@ namespace Content.Client.GameObjects.Components.Storage /// private void OnItemButtonToggled(BaseButton.ButtonToggledEventArgs args) { - var control = (EntityButton) args.Button.Parent; + if (args.Button.Parent is not EntityButton button) + { + return; + } + args.Button.Pressed = false; - StorageEntity.Interact(control.EntityUid); + StorageEntity.Interact(button.EntityUid); } } @@ -328,7 +333,6 @@ namespace Content.Client.GameObjects.Components.Storage public EntityUid EntityUid { get; set; } public Button ActualButton { get; } public SpriteView EntitySpriteView { get; } - public Control SizeControl { get; } public Label EntityName { get; } public Label EntitySize { get; } diff --git a/Content.Client/GameObjects/Components/Storage/StorableComponent.cs b/Content.Client/GameObjects/Components/Storage/StorableComponent.cs index d5aa2ffb07..6b1b79b6d5 100644 --- a/Content.Client/GameObjects/Components/Storage/StorableComponent.cs +++ b/Content.Client/GameObjects/Components/Storage/StorableComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Storage; +using Content.Shared.GameObjects.Components.Storage; using Robust.Shared.GameObjects; namespace Content.Client.GameObjects.Components.Storage diff --git a/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs b/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs index d58e6eac58..cd576f154b 100644 --- a/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs +++ b/Content.Client/GameObjects/Components/Storage/StorageVisualizer.cs @@ -3,8 +3,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Storage { @@ -12,15 +10,15 @@ namespace Content.Client.GameObjects.Components.Storage public sealed class StorageVisualizer : AppearanceVisualizer { [DataField("state")] - private string _stateBase; + private string? _stateBase; [DataField("state_open")] - private string _stateOpen; + private string? _stateOpen; [DataField("state_closed")] - private string _stateClosed; + private string? _stateClosed; public override void InitializeEntity(IEntity entity) { - if (!entity.TryGetComponent(out ISpriteComponent sprite)) + if (!entity.TryGetComponent(out ISpriteComponent? sprite)) { return; } @@ -35,7 +33,7 @@ namespace Content.Client.GameObjects.Components.Storage { base.OnChangeData(component); - if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) + if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite)) { return; } diff --git a/Content.Client/GameObjects/Components/Strap/StrapComponent.cs b/Content.Client/GameObjects/Components/Strap/StrapComponent.cs index 36e086f560..e4daca1fef 100644 --- a/Content.Client/GameObjects/Components/Strap/StrapComponent.cs +++ b/Content.Client/GameObjects/Components/Strap/StrapComponent.cs @@ -1,5 +1,4 @@ -#nullable enable -using Content.Shared.GameObjects.Components.Strap; +using Content.Shared.GameObjects.Components.Strap; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; diff --git a/Content.Client/GameObjects/Components/SubFloorHideComponent.cs b/Content.Client/GameObjects/Components/SubFloorHideComponent.cs index dfee4d169d..7fbff47bdf 100644 --- a/Content.Client/GameObjects/Components/SubFloorHideComponent.cs +++ b/Content.Client/GameObjects/Components/SubFloorHideComponent.cs @@ -1,5 +1,7 @@ -using Robust.Client.GameObjects; +using System.Diagnostics; +using Robust.Client.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.Utility; namespace Content.Client.GameObjects.Components { @@ -12,7 +14,8 @@ namespace Content.Client.GameObjects.Components [RegisterComponent] public sealed class SubFloorHideComponent : Component { - private SnapGridComponent _snapGridComponent; + [ComponentDependency(nameof(OnAddSnapGrid))] + private SnapGridComponent? _snapGridComponent; /// public override string Name => "SubFloorHide"; @@ -30,7 +33,6 @@ namespace Content.Client.GameObjects.Components { base.Startup(); - _snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged; Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner)); } @@ -39,13 +41,23 @@ namespace Content.Client.GameObjects.Components { base.Shutdown(); - if(Owner.Transform.Running == false) + if (Owner.Transform.Running == false) return; - _snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged; + if (_snapGridComponent != null) + { + _snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged; + } + Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner)); } + private void OnAddSnapGrid() + { + DebugTools.AssertNotNull(_snapGridComponent); + _snapGridComponent!.OnPositionChanged += SnapGridOnPositionChanged; + } + private void SnapGridOnPositionChanged() { Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner)); diff --git a/Content.Client/GameObjects/Components/Suspicion/TraitorOverlay.cs b/Content.Client/GameObjects/Components/Suspicion/TraitorOverlay.cs index 331c56828e..0a94a9c2a4 100644 --- a/Content.Client/GameObjects/Components/Suspicion/TraitorOverlay.cs +++ b/Content.Client/GameObjects/Components/Suspicion/TraitorOverlay.cs @@ -50,7 +50,7 @@ namespace Content.Client.GameObjects.Components.Suspicion var viewport = _eyeManager.GetWorldViewport(); var ent = _playerManager.LocalPlayer?.ControlledEntity; - if (ent == null || ent.TryGetComponent(out SuspicionRoleComponent sus) != true) + if (ent == null || ent.TryGetComponent(out SuspicionRoleComponent? sus) != true) { return; } @@ -63,7 +63,7 @@ namespace Content.Client.GameObjects.Components.Suspicion continue; } - if (!ally.TryGetComponent(out IPhysBody physics)) + if (!ally.TryGetComponent(out IPhysBody? physics)) { continue; } diff --git a/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs b/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs index 3fc4682e9a..d4a4f61e90 100644 --- a/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs +++ b/Content.Client/GameObjects/Components/Trigger/TimerTriggerVisualizer.cs @@ -15,9 +15,9 @@ namespace Content.Client.GameObjects.Components.Trigger private const string AnimationKey = "priming_animation"; [DataField("countdown_sound", required: true)] - private string _countdownSound; + private string? _countdownSound; - private Animation PrimingAnimation; + private Animation PrimingAnimation = default!; void ISerializationHooks.AfterDeserialization() { @@ -28,9 +28,12 @@ namespace Content.Client.GameObjects.Components.Trigger flick.LayerKey = TriggerVisualLayers.Base; flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("primed", 0f)); - var sound = new AnimationTrackPlaySound(); - PrimingAnimation.AnimationTracks.Add(sound); - sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_countdownSound, 0)); + if (_countdownSound != null) + { + var sound = new AnimationTrackPlaySound(); + PrimingAnimation.AnimationTracks.Add(sound); + sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(_countdownSound, 0)); + } } } diff --git a/Content.Client/GameObjects/Components/VendingMachines/VendingMachineBoundUserInterface.cs b/Content.Client/GameObjects/Components/VendingMachines/VendingMachineBoundUserInterface.cs index 42b215d2b9..433de84a1d 100644 --- a/Content.Client/GameObjects/Components/VendingMachines/VendingMachineBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/VendingMachines/VendingMachineBoundUserInterface.cs @@ -3,33 +3,33 @@ using Content.Shared.GameObjects.Components.VendingMachines; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.ViewVariables; +using static Content.Shared.GameObjects.Components.VendingMachines.SharedVendingMachineComponent; namespace Content.Client.GameObjects.Components.VendingMachines { class VendingMachineBoundUserInterface : BoundUserInterface { - [ViewVariables] - private VendingMachineMenu _menu; + [ViewVariables] private VendingMachineMenu? _menu; - public SharedVendingMachineComponent VendingMachine { get; private set; } + public SharedVendingMachineComponent? VendingMachine { get; private set; } public VendingMachineBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { - SendMessage(new SharedVendingMachineComponent.InventorySyncRequestMessage()); + SendMessage(new InventorySyncRequestMessage()); } protected override void Open() { base.Open(); - if(!Owner.Owner.TryGetComponent(out SharedVendingMachineComponent vendingMachine)) + if (!Owner.Owner.TryGetComponent(out SharedVendingMachineComponent? vendingMachine)) { return; } VendingMachine = vendingMachine; - _menu = new VendingMachineMenu() { Owner = this, Title = Owner.Owner.Name }; + _menu = new VendingMachineMenu(this) {Title = Owner.Owner.Name}; _menu.Populate(VendingMachine.Inventory); _menu.OnClose += Close; @@ -38,15 +38,15 @@ namespace Content.Client.GameObjects.Components.VendingMachines public void Eject(string ID) { - SendMessage(new SharedVendingMachineComponent.VendingMachineEjectMessage(ID)); + SendMessage(new VendingMachineEjectMessage(ID)); } protected override void ReceiveMessage(BoundUserInterfaceMessage message) { - switch(message) + switch (message) { - case SharedVendingMachineComponent.VendingMachineInventoryMessage msg: - _menu.Populate(msg.Inventory); + case VendingMachineInventoryMessage msg: + _menu?.Populate(msg.Inventory); break; } } diff --git a/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs b/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs index 0be6539c1f..066bca711a 100644 --- a/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs +++ b/Content.Client/GameObjects/Components/VendingMachines/VendingMachineVisualizer.cs @@ -21,7 +21,7 @@ namespace Content.Client.GameObjects.Components.VendingMachines // but we have no good way of passing that data from the server // to the client at the moment. Rework Visualizers? - private Dictionary _baseStates; + private Dictionary _baseStates = new(); private static readonly Dictionary LayerMap = new() diff --git a/Content.Client/GameObjects/Components/Watercloset/ToiletVisualizer.cs b/Content.Client/GameObjects/Components/Watercloset/ToiletVisualizer.cs index 8daace7ad2..5231c7db44 100644 --- a/Content.Client/GameObjects/Components/Watercloset/ToiletVisualizer.cs +++ b/Content.Client/GameObjects/Components/Watercloset/ToiletVisualizer.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.GameObjects.Components.Watercloset; using Robust.Client.GameObjects; diff --git a/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs b/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs index 86e31dd55f..93f35dc7e3 100644 --- a/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs @@ -25,7 +25,7 @@ namespace Content.Client.GameObjects.Components.Weapons } var playerManager = IoCManager.Resolve(); - if (playerManager?.LocalPlayer != null && playerManager.LocalPlayer.ControlledEntity != Owner) + if (playerManager.LocalPlayer != null && playerManager.LocalPlayer.ControlledEntity != Owner) { return; } diff --git a/Content.Client/GameObjects/Components/Weapons/Melee/MeleeWeaponArcAnimationComponent.cs b/Content.Client/GameObjects/Components/Weapons/Melee/MeleeWeaponArcAnimationComponent.cs index 0e3aa52d51..24cdf263af 100644 --- a/Content.Client/GameObjects/Components/Weapons/Melee/MeleeWeaponArcAnimationComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Melee/MeleeWeaponArcAnimationComponent.cs @@ -11,10 +11,10 @@ namespace Content.Client.GameObjects.Components.Weapons.Melee { public override string Name => "MeleeWeaponArcAnimation"; - private MeleeWeaponAnimationPrototype _meleeWeaponAnimation; + private MeleeWeaponAnimationPrototype? _meleeWeaponAnimation; private float _timer; - private SpriteComponent _sprite; + private SpriteComponent? _sprite; private Angle _baseAngle; public override void Initialize() @@ -27,7 +27,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Melee public void SetData(MeleeWeaponAnimationPrototype prototype, Angle baseAngle, IEntity attacker, bool followAttacker = true) { _meleeWeaponAnimation = prototype; - _sprite.AddLayer(new RSI.StateId(prototype.State)); + _sprite?.AddLayer(new RSI.StateId(prototype.State)); _baseAngle = baseAngle; if(followAttacker) Owner.Transform.AttachParent(attacker); @@ -44,7 +44,11 @@ namespace Content.Client.GameObjects.Components.Weapons.Melee var (r, g, b, a) = Vector4.Clamp(_meleeWeaponAnimation.Color + _meleeWeaponAnimation.ColorDelta * _timer, Vector4.Zero, Vector4.One); - _sprite.Color = new Color(r, g, b, a); + + if (_sprite != null) + { + _sprite.Color = new Color(r, g, b, a); + } switch (_meleeWeaponAnimation.ArcType) { @@ -56,7 +60,11 @@ namespace Content.Client.GameObjects.Components.Weapons.Melee case WeaponArcType.Poke: Owner.Transform.WorldRotation = _baseAngle; - _sprite.Offset -= (0, _meleeWeaponAnimation.Speed * frameTime); + + if (_sprite != null) + { + _sprite.Offset -= (0, _meleeWeaponAnimation.Speed * frameTime); + } break; } diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBatteryBarrelComponent.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBatteryBarrelComponent.cs index 6c0e84f812..0791bf7e4f 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBatteryBarrelComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBatteryBarrelComponent.cs @@ -17,7 +17,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels public override string Name => "BatteryBarrel"; public override uint? NetID => ContentNetIDs.BATTERY_BARREL; - private StatusControl _statusControl; + private StatusControl? _statusControl; /// /// Count of bullets in the magazine. @@ -28,7 +28,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels [ViewVariables] public (int count, int max)? MagazineCount { get; private set; } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBoltActionBarrelComponent.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBoltActionBarrelComponent.cs index 7fcc980ad1..d76cd99f60 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBoltActionBarrelComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientBoltActionBarrelComponent.cs @@ -18,7 +18,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels public override string Name => "BoltActionBarrel"; public override uint? NetID => ContentNetIDs.BOLTACTION_BARREL; - private StatusControl _statusControl; + private StatusControl? _statusControl; /// /// chambered is true when a bullet is chambered @@ -36,7 +36,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels [ViewVariables] public (int count, int max)? MagazineCount { get; private set; } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs index f125a64a18..971dfafc23 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientMagazineBarrelComponent.cs @@ -36,11 +36,11 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels KeyFrames = { new AnimationTrackProperty.KeyFrame(Color.Red, 0.1f), - new AnimationTrackProperty.KeyFrame(null, 0.3f), + new AnimationTrackProperty.KeyFrame(null!, 0.3f), new AnimationTrackProperty.KeyFrame(Color.Red, 0.2f), - new AnimationTrackProperty.KeyFrame(null, 0.3f), + new AnimationTrackProperty.KeyFrame(null!, 0.3f), new AnimationTrackProperty.KeyFrame(Color.Red, 0.2f), - new AnimationTrackProperty.KeyFrame(null, 0.3f), + new AnimationTrackProperty.KeyFrame(null!, 0.3f), } } } @@ -59,11 +59,11 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels KeyFrames = { new AnimationTrackProperty.KeyFrame(Color.Red, 0.0f), - new AnimationTrackProperty.KeyFrame(null, 0.15f), + new AnimationTrackProperty.KeyFrame(null!, 0.15f), new AnimationTrackProperty.KeyFrame(Color.Red, 0.15f), - new AnimationTrackProperty.KeyFrame(null, 0.15f), + new AnimationTrackProperty.KeyFrame(null!, 0.15f), new AnimationTrackProperty.KeyFrame(Color.Red, 0.15f), - new AnimationTrackProperty.KeyFrame(null, 0.15f), + new AnimationTrackProperty.KeyFrame(null!, 0.15f), } } } @@ -72,7 +72,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels public override string Name => "MagazineBarrel"; public override uint? NetID => ContentNetIDs.MAGAZINE_BARREL; - private StatusControl _statusControl; + private StatusControl? _statusControl; /// /// True if a bullet is chambered. @@ -91,7 +91,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels [ViewVariables(VVAccess.ReadWrite)] [DataField("lmg_alarm_animation")] private bool _isLmgAlarmAnimation = default; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); @@ -103,7 +103,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels _statusControl?.Update(); } - public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null) + public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) { base.HandleNetworkMessage(message, channel, session); diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientPumpBarrelComponent.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientPumpBarrelComponent.cs index 9e7b26e623..4d8f7a4af6 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientPumpBarrelComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientPumpBarrelComponent.cs @@ -18,7 +18,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels public override string Name => "PumpBarrel"; public override uint? NetID => ContentNetIDs.PUMP_BARREL; - private StatusControl _statusControl; + private StatusControl? _statusControl; /// /// chambered is true when a bullet is chambered @@ -36,7 +36,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels [ViewVariables] public (int count, int max)? MagazineCount { get; private set; } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientRevolverBarrelComponent.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientRevolverBarrelComponent.cs index 1780006be3..68d603cb7c 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientRevolverBarrelComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/ClientRevolverBarrelComponent.cs @@ -16,7 +16,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels public override string Name => "RevolverBarrel"; public override uint? NetID => ContentNetIDs.REVOLVER_BARREL; - private StatusControl _statusControl; + private StatusControl? _statusControl; /// /// A array that lists the bullet states @@ -25,12 +25,12 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels /// null means no bullet /// [ViewVariables] - public bool?[] Bullets { get; private set; } + public bool?[] Bullets { get; private set; } = new bool?[0]; [ViewVariables] public int CurrentSlot { get; private set; } - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs index 08e72b3add..6c56a0700d 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/Barrels/Visualizers/MagVisualizer.cs @@ -4,8 +4,6 @@ using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; -using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels.Visualizers { @@ -14,7 +12,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged.Barrels.Visualize { private bool _magLoaded; [DataField("magState")] - private string _magState; + private string? _magState; [DataField("steps")] private int _magSteps; [DataField("zeroVisible")] diff --git a/Content.Client/GameObjects/Components/Weapons/Ranged/ClientRangedWeaponComponent.cs b/Content.Client/GameObjects/Components/Weapons/Ranged/ClientRangedWeaponComponent.cs index a20573a78e..2c8627dff8 100644 --- a/Content.Client/GameObjects/Components/Weapons/Ranged/ClientRangedWeaponComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/Ranged/ClientRangedWeaponComponent.cs @@ -20,7 +20,7 @@ namespace Content.Client.GameObjects.Components.Weapons.Ranged { public FireRateSelector FireRateSelector { get; private set; } = FireRateSelector.Safety; - public override void HandleComponentState(ComponentState curState, ComponentState nextState) + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { base.HandleComponentState(curState, nextState); if (curState is not RangedWeaponComponentState rangedState) diff --git a/Content.Client/GameObjects/Components/WindowComponent.cs b/Content.Client/GameObjects/Components/WindowComponent.cs index 3380e0e16e..e7261333a4 100644 --- a/Content.Client/GameObjects/Components/WindowComponent.cs +++ b/Content.Client/GameObjects/Components/WindowComponent.cs @@ -13,9 +13,10 @@ namespace Content.Client.GameObjects.Components public sealed class WindowComponent : SharedWindowComponent { [DataField("base")] - private string _stateBase = default; - private ISpriteComponent _sprite; - private SnapGridComponent _snapGrid; + private string? _stateBase; + + private ISpriteComponent? _sprite; + private SnapGridComponent? _snapGrid; public override void Initialize() { @@ -30,39 +31,49 @@ namespace Content.Client.GameObjects.Components { base.Startup(); - _snapGrid.OnPositionChanged += SnapGridOnPositionChanged; + if (_snapGrid != null) + { + _snapGrid.OnPositionChanged += SnapGridOnPositionChanged; + } + Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new WindowSmoothDirtyEvent(Owner)); - var state0 = $"{_stateBase}0"; - const string cracksRSIPath = "/Textures/Constructible/Structures/Windows/cracks.rsi"; - _sprite.LayerMapSet(CornerLayers.SE, _sprite.AddLayerState(state0)); - _sprite.LayerSetDirOffset(CornerLayers.SE, SpriteComponent.DirectionOffset.None); - _sprite.LayerMapSet(WindowDamageLayers.DamageSE, _sprite.AddLayerState("0_1", cracksRSIPath)); - _sprite.LayerSetVisible(WindowDamageLayers.DamageSE, false); + if (_sprite != null) + { + var state0 = $"{_stateBase}0"; + const string cracksRSIPath = "/Textures/Constructible/Structures/Windows/cracks.rsi"; + _sprite.LayerMapSet(CornerLayers.SE, _sprite.AddLayerState(state0)); + _sprite.LayerSetDirOffset(CornerLayers.SE, SpriteComponent.DirectionOffset.None); + _sprite.LayerMapSet(WindowDamageLayers.DamageSE, _sprite.AddLayerState("0_1", cracksRSIPath)); + _sprite.LayerSetVisible(WindowDamageLayers.DamageSE, false); - _sprite.LayerMapSet(CornerLayers.NE, _sprite.AddLayerState(state0)); - _sprite.LayerSetDirOffset(CornerLayers.NE, SpriteComponent.DirectionOffset.CounterClockwise); - _sprite.LayerMapSet(WindowDamageLayers.DamageNE, _sprite.AddLayerState("0_1", cracksRSIPath)); - _sprite.LayerSetDirOffset(WindowDamageLayers.DamageNE, SpriteComponent.DirectionOffset.CounterClockwise); - _sprite.LayerSetVisible(WindowDamageLayers.DamageNE, false); + _sprite.LayerMapSet(CornerLayers.NE, _sprite.AddLayerState(state0)); + _sprite.LayerSetDirOffset(CornerLayers.NE, SpriteComponent.DirectionOffset.CounterClockwise); + _sprite.LayerMapSet(WindowDamageLayers.DamageNE, _sprite.AddLayerState("0_1", cracksRSIPath)); + _sprite.LayerSetDirOffset(WindowDamageLayers.DamageNE, SpriteComponent.DirectionOffset.CounterClockwise); + _sprite.LayerSetVisible(WindowDamageLayers.DamageNE, false); - _sprite.LayerMapSet(CornerLayers.NW, _sprite.AddLayerState(state0)); - _sprite.LayerSetDirOffset(CornerLayers.NW, SpriteComponent.DirectionOffset.Flip); - _sprite.LayerMapSet(WindowDamageLayers.DamageNW, _sprite.AddLayerState("0_1", cracksRSIPath)); - _sprite.LayerSetDirOffset(WindowDamageLayers.DamageNW, SpriteComponent.DirectionOffset.Flip); - _sprite.LayerSetVisible(WindowDamageLayers.DamageNW, false); + _sprite.LayerMapSet(CornerLayers.NW, _sprite.AddLayerState(state0)); + _sprite.LayerSetDirOffset(CornerLayers.NW, SpriteComponent.DirectionOffset.Flip); + _sprite.LayerMapSet(WindowDamageLayers.DamageNW, _sprite.AddLayerState("0_1", cracksRSIPath)); + _sprite.LayerSetDirOffset(WindowDamageLayers.DamageNW, SpriteComponent.DirectionOffset.Flip); + _sprite.LayerSetVisible(WindowDamageLayers.DamageNW, false); - _sprite.LayerMapSet(CornerLayers.SW, _sprite.AddLayerState(state0)); - _sprite.LayerSetDirOffset(CornerLayers.SW, SpriteComponent.DirectionOffset.Clockwise); - _sprite.LayerMapSet(WindowDamageLayers.DamageSW, _sprite.AddLayerState("0_1", cracksRSIPath)); - _sprite.LayerSetDirOffset(WindowDamageLayers.DamageSW, SpriteComponent.DirectionOffset.Clockwise); - _sprite.LayerSetVisible(WindowDamageLayers.DamageSW, false); + _sprite.LayerMapSet(CornerLayers.SW, _sprite.AddLayerState(state0)); + _sprite.LayerSetDirOffset(CornerLayers.SW, SpriteComponent.DirectionOffset.Clockwise); + _sprite.LayerMapSet(WindowDamageLayers.DamageSW, _sprite.AddLayerState("0_1", cracksRSIPath)); + _sprite.LayerSetDirOffset(WindowDamageLayers.DamageSW, SpriteComponent.DirectionOffset.Clockwise); + _sprite.LayerSetVisible(WindowDamageLayers.DamageSW, false); + } } /// protected override void Shutdown() { - _snapGrid.OnPositionChanged -= SnapGridOnPositionChanged; + if (_snapGrid != null) + { + _snapGrid.OnPositionChanged -= SnapGridOnPositionChanged; + } base.Shutdown(); } @@ -80,17 +91,25 @@ namespace Content.Client.GameObjects.Components return; } - _sprite.LayerSetState(CornerLayers.NE, $"{_stateBase}{(int) lowWall.LastCornerNE}"); - _sprite.LayerSetState(CornerLayers.SE, $"{_stateBase}{(int) lowWall.LastCornerSE}"); - _sprite.LayerSetState(CornerLayers.SW, $"{_stateBase}{(int) lowWall.LastCornerSW}"); - _sprite.LayerSetState(CornerLayers.NW, $"{_stateBase}{(int) lowWall.LastCornerNW}"); + if (_sprite != null) + { + _sprite.LayerSetState(CornerLayers.NE, $"{_stateBase}{(int) lowWall.LastCornerNE}"); + _sprite.LayerSetState(CornerLayers.SE, $"{_stateBase}{(int) lowWall.LastCornerSE}"); + _sprite.LayerSetState(CornerLayers.SW, $"{_stateBase}{(int) lowWall.LastCornerSW}"); + _sprite.LayerSetState(CornerLayers.NW, $"{_stateBase}{(int) lowWall.LastCornerNW}"); + } } - private LowWallComponent FindLowWall() + private LowWallComponent? FindLowWall() { + if (_snapGrid == null) + { + return null; + } + foreach (var entity in _snapGrid.GetLocal()) { - if (entity.TryGetComponent(out LowWallComponent lowWall)) + if (entity.TryGetComponent(out LowWallComponent? lowWall)) { return lowWall; } diff --git a/Content.Client/GameObjects/Components/WindowVisualizer.cs b/Content.Client/GameObjects/Components/WindowVisualizer.cs index bf8ce5c52f..bc790ba1f5 100644 --- a/Content.Client/GameObjects/Components/WindowVisualizer.cs +++ b/Content.Client/GameObjects/Components/WindowVisualizer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using Content.Shared.GameObjects.Components; using Content.Shared.Utility; using JetBrains.Annotations; diff --git a/Content.Client/GameObjects/Components/Wires/WiresBoundUserInterface.cs b/Content.Client/GameObjects/Components/Wires/WiresBoundUserInterface.cs index 248d00c4b0..d4e258a367 100644 --- a/Content.Client/GameObjects/Components/Wires/WiresBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Wires/WiresBoundUserInterface.cs @@ -6,17 +6,17 @@ namespace Content.Client.GameObjects.Components.Wires { public class WiresBoundUserInterface : BoundUserInterface { + private WiresMenu? _menu; + public WiresBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } - private WiresMenu _menu; - protected override void Open() { base.Open(); - _menu = new WiresMenu(this); + _menu = new WiresMenu(this); _menu.OnClose += Close; _menu.OpenCentered(); } @@ -24,7 +24,7 @@ namespace Content.Client.GameObjects.Components.Wires protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _menu.Populate((WiresBoundUserInterfaceState) state); + _menu?.Populate((WiresBoundUserInterfaceState) state); } public void PerformAction(int id, WiresAction action) @@ -38,7 +38,7 @@ namespace Content.Client.GameObjects.Components.Wires if (!disposing) return; - _menu.Dispose(); + _menu?.Dispose(); } } } diff --git a/Content.Client/GameObjects/Components/Wires/WiresMenu.cs b/Content.Client/GameObjects/Components/Wires/WiresMenu.cs index 7a3773bfc4..ca57b29a69 100644 --- a/Content.Client/GameObjects/Components/Wires/WiresMenu.cs +++ b/Content.Client/GameObjects/Components/Wires/WiresMenu.cs @@ -286,8 +286,8 @@ namespace Content.Client.GameObjects.Components.Wires private const string TextureContact = "/Textures/Interface/WireHacking/contact.svg.96dpi.png"; - public event Action WireClicked; - public event Action ContactsClicked; + public event Action? WireClicked; + public event Action? ContactsClicked; public WireControl(WireColor color, WireLetter letter, bool isCut, bool flip, bool mirror, int type, IResourceCache resourceCache) @@ -519,7 +519,7 @@ namespace Content.Client.GameObjects.Components.Wires } }; - Animation animation = null; + Animation? animation = null; switch (data.State) { diff --git a/Content.Client/GameObjects/EntitySystems/AI/ClientPathfindingDebugSystem.cs b/Content.Client/GameObjects/EntitySystems/AI/ClientPathfindingDebugSystem.cs index 1484627b37..14521d29ed 100644 --- a/Content.Client/GameObjects/EntitySystems/AI/ClientPathfindingDebugSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/AI/ClientPathfindingDebugSystem.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Content.Shared.AI; @@ -20,7 +20,7 @@ namespace Content.Client.GameObjects.EntitySystems.AI { private PathfindingDebugMode _modes = PathfindingDebugMode.None; private float _routeDuration = 4.0f; // How long before we remove a route from the overlay - private DebugPathfindingOverlay _overlay; + private DebugPathfindingOverlay? _overlay; public override void Initialize() { @@ -45,7 +45,7 @@ namespace Content.Client.GameObjects.EntitySystems.AI if ((_modes & PathfindingDebugMode.Nodes) != 0 || (_modes & PathfindingDebugMode.Route) != 0) { - _overlay.AStarRoutes.Add(message); + _overlay?.AStarRoutes.Add(message); Timer.Spawn(TimeSpan.FromSeconds(_routeDuration), () => { if (_overlay == null) return; @@ -59,7 +59,7 @@ namespace Content.Client.GameObjects.EntitySystems.AI if ((_modes & PathfindingDebugMode.Nodes) != 0 || (_modes & PathfindingDebugMode.Route) != 0) { - _overlay.JpsRoutes.Add(message); + _overlay?.JpsRoutes.Add(message); Timer.Spawn(TimeSpan.FromSeconds(_routeDuration), () => { if (_overlay == null) return; @@ -70,32 +70,31 @@ namespace Content.Client.GameObjects.EntitySystems.AI private void HandleGraphMessage(SharedAiDebug.PathfindingGraphMessage message) { - EnableOverlay(); - _overlay.UpdateGraph(message.Graph); + EnableOverlay().UpdateGraph(message.Graph); } private void HandleRegionsMessage(SharedAiDebug.ReachableChunkRegionsDebugMessage message) { - EnableOverlay(); - _overlay.UpdateRegions(message.GridId, message.Regions); + EnableOverlay().UpdateRegions(message.GridId, message.Regions); } private void HandleCachedRegionsMessage(SharedAiDebug.ReachableCacheDebugMessage message) { - EnableOverlay(); - _overlay.UpdateCachedRegions(message.GridId, message.Regions, message.Cached); + EnableOverlay().UpdateCachedRegions(message.GridId, message.Regions, message.Cached); } - private void EnableOverlay() + private DebugPathfindingOverlay EnableOverlay() { if (_overlay != null) { - return; + return _overlay; } var overlayManager = IoCManager.Resolve(); _overlay = new DebugPathfindingOverlay {Modes = _modes}; overlayManager.AddOverlay(_overlay); + + return _overlay; } private void DisableOverlay() @@ -125,7 +124,11 @@ namespace Content.Client.GameObjects.EntitySystems.AI { EnableOverlay(); } - _overlay.Modes = _modes; + + if (_overlay != null) + { + _overlay.Modes = _modes; + } if (tooltip == PathfindingDebugMode.Graph) { @@ -153,7 +156,7 @@ namespace Content.Client.GameObjects.EntitySystems.AI { DisableOverlay(); } - else + else if (_overlay != null) { _overlay.Modes = _modes; } diff --git a/Content.Client/GameObjects/EntitySystems/ActionsSystem.cs b/Content.Client/GameObjects/EntitySystems/ActionsSystem.cs index 8078dc8ca8..68f87ed77b 100644 --- a/Content.Client/GameObjects/EntitySystems/ActionsSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ActionsSystem.cs @@ -78,9 +78,9 @@ namespace Content.Client.GameObjects.EntitySystems // delegate to the ActionsUI, simulating a click on it return new((in PointerInputCmdHandler.PointerInputCmdArgs args) => { - var playerEntity = _playerManager.LocalPlayer.ControlledEntity; + var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; if (playerEntity == null || - !playerEntity.TryGetComponent( out var actionsComponent)) return false; + !playerEntity.TryGetComponent(out var actionsComponent)) return false; actionsComponent.HandleHotbarKeybind(slot, args); return true; @@ -92,7 +92,7 @@ namespace Content.Client.GameObjects.EntitySystems // delegate to the ActionsUI, simulating a click on it return new((in PointerInputCmdHandler.PointerInputCmdArgs args) => { - var playerEntity = _playerManager.LocalPlayer.ControlledEntity; + var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; if (playerEntity == null || !playerEntity.TryGetComponent( out var actionsComponent)) return false; @@ -104,7 +104,7 @@ namespace Content.Client.GameObjects.EntitySystems private bool TargetingOnUse(in PointerInputCmdHandler.PointerInputCmdArgs args) { - var playerEntity = _playerManager.LocalPlayer.ControlledEntity; + var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; if (playerEntity == null || !playerEntity.TryGetComponent( out var actionsComponent)) return false; @@ -113,7 +113,7 @@ namespace Content.Client.GameObjects.EntitySystems private void ToggleActionsMenu() { - var playerEntity = _playerManager.LocalPlayer.ControlledEntity; + var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; if (playerEntity == null || !playerEntity.TryGetComponent( out var actionsComponent)) return; diff --git a/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs b/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs index 5c6b4abbaf..e55ad1fcea 100644 --- a/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs @@ -34,8 +34,8 @@ namespace Content.Client.GameObjects.EntitySystems private void HandleOpenCharacterMenu() { - if (_playerManager.LocalPlayer.ControlledEntity == null - || !_playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out CharacterInterface characterInterface)) + if (_playerManager.LocalPlayer?.ControlledEntity == null + || !_playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out CharacterInterface? characterInterface)) { return; } diff --git a/Content.Client/GameObjects/EntitySystems/ClientDoorSystem.cs b/Content.Client/GameObjects/EntitySystems/ClientDoorSystem.cs index 89b3d7f3c8..b5b86592f8 100644 --- a/Content.Client/GameObjects/EntitySystems/ClientDoorSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ClientDoorSystem.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using Content.Client.GameObjects.Components.Doors; diff --git a/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs b/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs index 907a977987..47036a5ed0 100644 --- a/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ClientInventorySystem.cs @@ -22,7 +22,7 @@ namespace Content.Client.GameObjects.EntitySystems CommandBinds.Builder .Bind(ContentKeyFunctions.OpenInventoryMenu, - InputCmdHandler.FromDelegate(s => HandleOpenInventoryMenu())) + InputCmdHandler.FromDelegate(_ => HandleOpenInventoryMenu())) .Register(); } @@ -34,14 +34,16 @@ namespace Content.Client.GameObjects.EntitySystems private void HandleOpenInventoryMenu() { - if (_playerManager.LocalPlayer.ControlledEntity == null - || !_playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out ClientInventoryComponent clientInventory)) + if (_playerManager.LocalPlayer?.ControlledEntity == null + || !_playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out ClientInventoryComponent? clientInventory)) { return; } var menu = clientInventory.InterfaceController.Window; + if (menu == null) return; + if (menu.IsOpen) { if (menu.IsAtFront()) diff --git a/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs b/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs index f71e48a924..0798517a82 100644 --- a/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/CombatModeSystem.cs @@ -40,7 +40,7 @@ namespace Content.Client.GameObjects.EntitySystems base.Shutdown(); } - private void CombatModeToggled(ICommonSession session) + private void CombatModeToggled(ICommonSession? session) { if (_gameTiming.IsFirstTimePredicted) { @@ -51,8 +51,8 @@ namespace Content.Client.GameObjects.EntitySystems public bool IsInCombatMode() { - var entity = _playerManager.LocalPlayer.ControlledEntity; - if (entity == null || !entity.TryGetComponent(out CombatModeComponent combatMode)) + var entity = _playerManager.LocalPlayer?.ControlledEntity; + if (entity == null || !entity.TryGetComponent(out CombatModeComponent? combatMode)) { return false; } diff --git a/Content.Client/GameObjects/EntitySystems/ConstructionSystem.cs b/Content.Client/GameObjects/EntitySystems/ConstructionSystem.cs index 2e429d9927..77dff4b52a 100644 --- a/Content.Client/GameObjects/EntitySystems/ConstructionSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ConstructionSystem.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Content.Client.GameObjects.Components.Construction; using Content.Shared.Construction; @@ -104,7 +104,7 @@ namespace Content.Client.GameObjects.EntitySystems if (!entity.TryGetComponent(out var ghostComp)) return false; - TryStartConstruction(ghostComp.GhostID); + TryStartConstruction(ghostComp.GhostId); return true; } @@ -127,9 +127,9 @@ namespace Content.Client.GameObjects.EntitySystems var ghost = EntityManager.SpawnEntity("constructionghost", loc); var comp = ghost.GetComponent(); comp.Prototype = prototype; - comp.GhostID = _nextId++; + comp.GhostId = _nextId++; ghost.Transform.LocalRotation = dir.ToAngle(); - _ghosts.Add(comp.GhostID, comp); + _ghosts.Add(comp.GhostId, comp); var sprite = ghost.GetComponent(); sprite.Color = new Color(48, 255, 48, 128); sprite.AddBlankLayer(0); // There is no way to actually check if this already exists, so we blindly insert a new one @@ -154,6 +154,12 @@ namespace Content.Client.GameObjects.EntitySystems private void TryStartConstruction(int ghostId) { var ghost = _ghosts[ghostId]; + + if (ghost.Prototype == null) + { + throw new ArgumentException($"Can't start construction for a ghost with no prototype. Ghost id: {ghostId}"); + } + var transform = ghost.Owner.Transform; var msg = new TryStartStructureConstructionMessage(transform.Coordinates, ghost.Prototype.ID, transform.LocalRotation, ghostId); RaiseNetworkEvent(msg); diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterBar.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterBar.cs index 3bd96e5e97..74946ec6b4 100644 --- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterBar.cs +++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterBar.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using Robust.Client.Graphics; using Robust.Client.UserInterface; diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs index ca3beb8a55..60f156a29e 100644 --- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs +++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterGui.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using Content.Client.GameObjects.Components; diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs index 265e0ecc08..d0fde4ba02 100644 --- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs @@ -1,6 +1,4 @@ -#nullable enable -using System.Collections.Generic; -using System.Linq; +using System.Linq; using Content.Client.GameObjects.Components; using Content.Shared.GameObjects.EntitySystems; using JetBrains.Annotations; diff --git a/Content.Client/GameObjects/EntitySystems/DragDropSystem.cs b/Content.Client/GameObjects/EntitySystems/DragDropSystem.cs index 3f18cc4953..f82fefa31d 100644 --- a/Content.Client/GameObjects/EntitySystems/DragDropSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/DragDropSystem.cs @@ -1,6 +1,4 @@ -#nullable enable using System.Collections.Generic; -using System.Linq; using Content.Client.State; using Content.Client.Utility; using Content.Shared.GameObjects.EntitySystemMessages; @@ -262,7 +260,7 @@ namespace Content.Client.GameObjects.EntitySystems private bool OnUseMouseUp(in PointerInputCmdHandler.PointerInputCmdArgs args) { - if (_dragDropHelper.IsDragging == false) + if (_dragDropHelper.IsDragging == false || _dragDropHelper.Dragged == null) { // haven't started the drag yet, quick mouseup, definitely treat it as a normal click by // replaying the original cmd @@ -329,7 +327,7 @@ namespace Content.Client.GameObjects.EntitySystems if (!draggable.CanDrop(dropArgs)) continue; // tell the server about the drop attempt - RaiseNetworkEvent(new DragDropMessage(args.Coordinates, _dragDropHelper.Dragged.Uid, + RaiseNetworkEvent(new DragDropMessage(args.Coordinates, _dragDropHelper.Dragged!.Uid, entity.Uid)); draggable.Drop(dropArgs); diff --git a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs index 79640c0aa3..9c217e98c4 100644 --- a/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/ExamineSystem.cs @@ -27,8 +27,8 @@ namespace Content.Client.GameObjects.EntitySystems public const string StyleClassEntityTooltip = "entity-tooltip"; - private Popup _examineTooltipOpen; - private CancellationTokenSource _requestCancelTokenSource; + private Popup? _examineTooltipOpen; + private CancellationTokenSource? _requestCancelTokenSource; public override void Initialize() { @@ -45,14 +45,14 @@ namespace Content.Client.GameObjects.EntitySystems base.Shutdown(); } - private bool HandleExamine(ICommonSession session, EntityCoordinates coords, EntityUid uid) + private bool HandleExamine(ICommonSession? session, EntityCoordinates coords, EntityUid uid) { if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out var examined)) { return false; } - var playerEntity = _playerManager.LocalPlayer.ControlledEntity; + var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; if (playerEntity == null || !CanExamine(playerEntity, examined)) { @@ -82,7 +82,7 @@ namespace Content.Client.GameObjects.EntitySystems panel.AddChild(vBox); var hBox = new HBoxContainer {SeparationOverride = 5}; vBox.AddChild(hBox); - if (entity.TryGetComponent(out ISpriteComponent sprite)) + if (entity.TryGetComponent(out ISpriteComponent? sprite)) { hBox.AddChild(new SpriteView {Sprite = sprite}); } @@ -101,7 +101,7 @@ namespace Content.Client.GameObjects.EntitySystems FormattedMessage message; if (entity.Uid.IsClientSide()) { - message = GetExamineText(entity, _playerManager.LocalPlayer.ControlledEntity); + message = GetExamineText(entity, _playerManager.LocalPlayer?.ControlledEntity); } else { diff --git a/Content.Client/GameObjects/EntitySystems/IconSmoothSystem.cs b/Content.Client/GameObjects/EntitySystems/IconSmoothSystem.cs index b2c909181f..da24e8d78b 100644 --- a/Content.Client/GameObjects/EntitySystems/IconSmoothSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/IconSmoothSystem.cs @@ -53,7 +53,7 @@ namespace Content.Client.GameObjects.EntitySystems // This is simpler to implement. If you want to optimize it be my guest. var senderEnt = ev.Sender; if (senderEnt.IsValid() && - senderEnt.TryGetComponent(out IconSmoothComponent iconSmooth) + senderEnt.TryGetComponent(out IconSmoothComponent? iconSmooth) && iconSmooth.Running) { var snapGrid = senderEnt.GetComponent(); @@ -114,7 +114,7 @@ namespace Content.Client.GameObjects.EntitySystems // As it stands now, it's totally possible for something to get queued twice. // Generation on the component is set after an update so we can cull updates that happened this generation. if (!entity.IsValid() - || !entity.TryGetComponent(out IconSmoothComponent smoothing) + || !entity.TryGetComponent(out IconSmoothComponent? smoothing) || smoothing.UpdateGeneration == _generation) { return; diff --git a/Content.Client/GameObjects/EntitySystems/InstrumentSystem.cs b/Content.Client/GameObjects/EntitySystems/InstrumentSystem.cs index 221d236d82..407176392d 100644 --- a/Content.Client/GameObjects/EntitySystems/InstrumentSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/InstrumentSystem.cs @@ -11,7 +11,7 @@ namespace Content.Client.GameObjects.EntitySystems [UsedImplicitly] public class InstrumentSystem : EntitySystem { - [Dependency] private readonly IGameTiming _gameTiming = default; + [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; public override void Initialize() diff --git a/Content.Client/GameObjects/EntitySystems/MeleeWeaponSystem.cs b/Content.Client/GameObjects/EntitySystems/MeleeWeaponSystem.cs index 0f5ba1baa7..edd1ad59d6 100644 --- a/Content.Client/GameObjects/EntitySystems/MeleeWeaponSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/MeleeWeaponSystem.cs @@ -38,7 +38,7 @@ namespace Content.Client.GameObjects.EntitySystems private void PlayWeaponArc(PlayMeleeWeaponAnimationMessage msg) { - if (!_prototypeManager.TryIndex(msg.ArcPrototype, out MeleeWeaponAnimationPrototype weaponArc)) + if (!_prototypeManager.TryIndex(msg.ArcPrototype, out MeleeWeaponAnimationPrototype? weaponArc)) { Logger.Error("Tried to play unknown weapon arc prototype '{0}'", msg.ArcPrototype); return; @@ -63,8 +63,10 @@ namespace Content.Client.GameObjects.EntitySystems weaponArcAnimation.SetData(weaponArc, msg.Angle, attacker, msg.ArcFollowAttacker); // Due to ISpriteComponent limitations, weapons that don't use an RSI won't have this effect. - if (EntityManager.TryGetEntity(msg.Source, out var source) && msg.TextureEffect && source.TryGetComponent(out ISpriteComponent sourceSprite) - && sourceSprite.BaseRSI?.Path != null) + if (EntityManager.TryGetEntity(msg.Source, out var source) && + msg.TextureEffect && + source.TryGetComponent(out ISpriteComponent? sourceSprite) && + sourceSprite.BaseRSI?.Path != null) { var sys = Get(); var curTime = _gameTiming.CurTime; @@ -91,7 +93,7 @@ namespace Content.Client.GameObjects.EntitySystems continue; } - if (!hitEntity.TryGetComponent(out ISpriteComponent sprite)) + if (!hitEntity.TryGetComponent(out ISpriteComponent? sprite)) { continue; } diff --git a/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs b/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs index 192dc9c03f..8f5e612a90 100644 --- a/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/RangedWeaponSystem.cs @@ -24,8 +24,8 @@ namespace Content.Client.GameObjects.EntitySystems [Dependency] private readonly IInputManager _inputManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; - private InputSystem _inputSystem; - private CombatModeSystem _combatModeSystem; + private InputSystem _inputSystem = default!; + private CombatModeSystem _combatModeSystem = default!; private bool _blocked; private int _shotCounter; @@ -34,8 +34,8 @@ namespace Content.Client.GameObjects.EntitySystems base.Initialize(); IoCManager.InjectDependencies(this); - _inputSystem = EntitySystemManager.GetEntitySystem(); - _combatModeSystem = EntitySystemManager.GetEntitySystem(); + _inputSystem = Get(); + _combatModeSystem = Get(); } public override void Update(float frameTime) @@ -55,14 +55,14 @@ namespace Content.Client.GameObjects.EntitySystems return; } - var entity = _playerManager.LocalPlayer.ControlledEntity; - if (entity == null || !entity.TryGetComponent(out HandsComponent hands)) + var entity = _playerManager.LocalPlayer?.ControlledEntity; + if (entity == null || !entity.TryGetComponent(out HandsComponent? hands)) { return; } var held = hands.ActiveHand; - if (held == null || !held.TryGetComponent(out ClientRangedWeaponComponent weapon)) + if (held == null || !held.TryGetComponent(out ClientRangedWeaponComponent? weapon)) { _blocked = true; return; diff --git a/Content.Client/GameObjects/EntitySystems/StandingStateSystem.cs b/Content.Client/GameObjects/EntitySystems/StandingStateSystem.cs index 41495c4445..ce15b07fad 100644 --- a/Content.Client/GameObjects/EntitySystems/StandingStateSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/StandingStateSystem.cs @@ -9,7 +9,7 @@ namespace Content.Client.GameObjects.EntitySystems { protected override bool OnDown(IEntity entity, bool playSound = true, bool dropItems = true, bool force = false) { - if (!entity.TryGetComponent(out AppearanceComponent appearance)) + if (!entity.TryGetComponent(out AppearanceComponent? appearance)) { return false; } @@ -27,7 +27,7 @@ namespace Content.Client.GameObjects.EntitySystems protected override bool OnStand(IEntity entity) { - if (!entity.TryGetComponent(out AppearanceComponent appearance)) return false; + if (!entity.TryGetComponent(out AppearanceComponent? appearance)) return false; appearance.TryGetData(RotationVisuals.RotationState, out var oldState); var newState = RotationState.Vertical; diff --git a/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs b/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs index eb090c024a..83a815745b 100644 --- a/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs @@ -65,12 +65,12 @@ namespace Content.Client.GameObjects.EntitySystems UpdateTile(grid, indices); } - private void MapManagerOnTileChanged(object sender, TileChangedEventArgs e) + private void MapManagerOnTileChanged(object? sender, TileChangedEventArgs e) { UpdateTile(_mapManager.GetGrid(e.NewTile.GridIndex), e.NewTile.GridIndices); } - private void MapManagerOnGridChanged(object sender, GridChangedEventArgs e) + private void MapManagerOnGridChanged(object? sender, GridChangedEventArgs e) { foreach (var modified in e.Modified) { @@ -85,19 +85,19 @@ namespace Content.Client.GameObjects.EntitySystems foreach (var snapGridComponent in grid.GetSnapGridCell(position, SnapGridOffset.Center)) { var entity = snapGridComponent.Owner; - if (!entity.TryGetComponent(out SubFloorHideComponent subFloorComponent)) + if (!entity.TryGetComponent(out SubFloorHideComponent? subFloorComponent)) { continue; } var enabled = EnableAll || !subFloorComponent.Running || tileDef.IsSubFloor; - if (entity.TryGetComponent(out ISpriteComponent spriteComponent)) + if (entity.TryGetComponent(out ISpriteComponent? spriteComponent)) { spriteComponent.Visible = enabled; } - if (entity.TryGetComponent(out PhysicsComponent physicsComponent)) + if (entity.TryGetComponent(out PhysicsComponent? physicsComponent)) { physicsComponent.CanCollide = enabled; } diff --git a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs index b72d51d936..6f7f28b0ab 100644 --- a/Content.Client/GameObjects/EntitySystems/VerbSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/VerbSystem.cs @@ -33,12 +33,12 @@ namespace Content.Client.GameObjects.EntitySystems [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; - private ContextMenuPresenter _contextMenuPresenter; - public event EventHandler ToggleContextMenu; - public event EventHandler ToggleContainerVisibility; + public event EventHandler? ToggleContextMenu; + public event EventHandler? ToggleContainerVisibility; - private VerbPopup _currentVerbListRoot; - private VerbPopup _currentGroupList; + private ContextMenuPresenter _contextMenuPresenter = default!; + private VerbPopup? _currentVerbListRoot; + private VerbPopup? _currentGroupList; private EntityUid _currentEntity; // TODO: Move presenter out of the system @@ -132,7 +132,7 @@ namespace Content.Client.GameObjects.EntitySystems var buttons = new Dictionary>(); var groupIcons = new Dictionary(); - var vBox = _currentVerbListRoot.List; + var vBox = _currentVerbListRoot!.List; vBox.DisposeAllChildren(); // Local variable so that scope capture ensures this is the correct value. @@ -147,7 +147,7 @@ namespace Content.Client.GameObjects.EntitySystems groupIcons.Add(data.Category, data.CategoryIcon); } - list.Add(new ListedVerbData(data.Text, !data.Available, data.Key, entity.ToString(), () => + list.Add(new ListedVerbData(data.Text, !data.Available, data.Key, entity.ToString()!, () => { RaiseNetworkEvent(new VerbSystemMessages.UseVerbMessage(curEntity, data.Key)); CloseAllMenus(); @@ -175,7 +175,7 @@ namespace Content.Client.GameObjects.EntitySystems groupIcons.Add(verbData.Category, verbData.CategoryIcon); } - list.Add(new ListedVerbData(verbData.Text, verbData.IsDisabled, verb.ToString(), entity.ToString(), + list.Add(new ListedVerbData(verbData.Text, verbData.IsDisabled, verb.ToString()!, entity.ToString()!, () => verb.Activate(user, component), verbData.Icon)); } @@ -199,8 +199,8 @@ namespace Content.Client.GameObjects.EntitySystems groupIcons.Add(verbData.Category, verbData.CategoryIcon); } - list.Add(new ListedVerbData(verbData.Text, verbData.IsDisabled, globalVerb.ToString(), - entity.ToString(), + list.Add(new ListedVerbData(verbData.Text, verbData.IsDisabled, globalVerb.ToString()!, + entity.ToString()!, () => globalVerb.Activate(user, entity), verbData.Icon)); } @@ -223,9 +223,10 @@ namespace Content.Client.GameObjects.EntitySystems first = false; - groupIcons.TryGetValue(category, out var icon); - - vBox.AddChild(CreateCategoryButton(category, verbs, icon)); + if (groupIcons.TryGetValue(category, out var icon)) + { + vBox.AddChild(CreateCategoryButton(category, verbs, icon)); + } } if (buttons.ContainsKey("")) @@ -321,7 +322,7 @@ namespace Content.Client.GameObjects.EntitySystems private IEntity GetUserEntity() { - return _playerManager.LocalPlayer.ControlledEntity; + return _playerManager.LocalPlayer!.ControlledEntity!; } private sealed class VerbPopup : Popup @@ -343,13 +344,13 @@ namespace Content.Client.GameObjects.EntitySystems private readonly Label _label; private readonly TextureRect _icon; - public Texture Icon + public Texture? Icon { get => _icon.Texture; set => _icon.Texture = value; } - public string Text + public string? Text { get => _label.Text; set => _label.Text = value; @@ -389,19 +390,21 @@ namespace Content.Client.GameObjects.EntitySystems private static readonly TimeSpan HoverDelay = TimeSpan.FromSeconds(0.2); private readonly VerbSystem _system; - public List VerbButtons { get; } + private readonly Label _label; private readonly TextureRect _icon; - private CancellationTokenSource _openCancel; + private CancellationTokenSource? _openCancel; - public string Text + public List VerbButtons { get; } + + public string? Text { get => _label.Text; set => _label.Text = value; } - public Texture Icon + public Texture? Icon { get => _icon.Texture; set => _icon.Texture = value; @@ -509,11 +512,11 @@ namespace Content.Client.GameObjects.EntitySystems public bool Disabled { get; } public string VerbName { get; } public string OwnerName { get; } - public SpriteSpecifier Icon { get; } + public SpriteSpecifier? Icon { get; } public Action Action { get; } public ListedVerbData(string text, bool disabled, string verbName, string ownerName, - Action action, SpriteSpecifier icon) + Action action, SpriteSpecifier? icon) { Text = text; Disabled = disabled; diff --git a/Content.Client/GameTicking/ClientGameTicker.cs b/Content.Client/GameTicking/ClientGameTicker.cs index c324244eb8..16450869fe 100644 --- a/Content.Client/GameTicking/ClientGameTicker.cs +++ b/Content.Client/GameTicking/ClientGameTicker.cs @@ -25,17 +25,17 @@ namespace Content.Client.GameTicking [ViewVariables] public bool AreWeReady { get; private set; } [ViewVariables] public bool IsGameStarted { get; private set; } [ViewVariables] public bool DisallowedLateJoin { get; private set; } - [ViewVariables] public string ServerInfoBlob { get; private set; } + [ViewVariables] public string? ServerInfoBlob { get; private set; } [ViewVariables] public TimeSpan StartTime { get; private set; } [ViewVariables] public bool Paused { get; private set; } - [ViewVariables] public Dictionary Status { get; private set; } + [ViewVariables] public Dictionary Status { get; private set; } = new(); [ViewVariables] public IReadOnlyList JobsAvailable => _jobsAvailable; - public event Action InfoBlobUpdated; - public event Action LobbyStatusUpdated; - public event Action LobbyReadyUpdated; - public event Action LobbyLateJoinStatusUpdated; - public event Action> LobbyJobsAvailableUpdated; + public event Action? InfoBlobUpdated; + public event Action? LobbyStatusUpdated; + public event Action? LobbyReadyUpdated; + public event Action? LobbyLateJoinStatusUpdated; + public event Action>? LobbyJobsAvailableUpdated; public void Initialize() { @@ -121,7 +121,6 @@ namespace Content.Client.GameTicking { //This is not ideal at all, but I don't see an immediately better fit anywhere else. var roundEnd = new RoundEndSummaryWindow(message.GamemodeTitle, message.RoundEndText, message.RoundDuration, message.AllPlayersEndInfo); - } } } diff --git a/Content.Client/Graphics/Overlays/CritOverlay.cs b/Content.Client/Graphics/Overlays/CritOverlay.cs index 75d09b9750..d6fbbb881a 100644 --- a/Content.Client/Graphics/Overlays/CritOverlay.cs +++ b/Content.Client/Graphics/Overlays/CritOverlay.cs @@ -15,7 +15,8 @@ namespace Content.Client.Graphics.Overlays [Dependency] private readonly IPlayerManager _playerManager = default!; public override OverlaySpace Space => OverlaySpace.WorldSpace; - private readonly ShaderInstance _gradientCircleShader, _glowingBorderShader; + private readonly ShaderInstance _gradientCircleShader; + private readonly ShaderInstance? _glowingBorderShader; public CritOverlay() { diff --git a/Content.Client/Graphics/Overlays/FlashOverlay.cs b/Content.Client/Graphics/Overlays/FlashOverlay.cs index e25bbadefa..5316ebe465 100644 --- a/Content.Client/Graphics/Overlays/FlashOverlay.cs +++ b/Content.Client/Graphics/Overlays/FlashOverlay.cs @@ -19,7 +19,7 @@ namespace Content.Client.Graphics.Overlays private readonly ShaderInstance _shader; private double _startTime = -1; private double _lastsFor = 1; - private Texture _screenshotTexture; + private Texture? _screenshotTexture; public FlashOverlay() { diff --git a/Content.Client/Instruments/InstrumentMenu.xaml.cs b/Content.Client/Instruments/InstrumentMenu.xaml.cs index e7a21a76ff..2081b44ef0 100644 --- a/Content.Client/Instruments/InstrumentMenu.xaml.cs +++ b/Content.Client/Instruments/InstrumentMenu.xaml.cs @@ -18,6 +18,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Timing; +using static Robust.Client.UserInterface.Controls.BaseButton; using Range = Robust.Client.UserInterface.Controls.Range; namespace Content.Client.Instruments @@ -37,14 +38,15 @@ namespace Content.Client.Instruments _owner = owner; - _owner.Instrument.OnMidiPlaybackEnded += InstrumentOnMidiPlaybackEnded; - - Title = _owner.Instrument.Owner.Name; - - LoopButton.Disabled = !_owner.Instrument.IsMidiOpen; - LoopButton.Pressed = _owner.Instrument.LoopMidi; - StopButton.Disabled = !_owner.Instrument.IsMidiOpen; - PlaybackSlider.MouseFilter = _owner.Instrument.IsMidiOpen ? MouseFilterMode.Pass : MouseFilterMode.Ignore; + if (_owner.Instrument != null) + { + _owner.Instrument.OnMidiPlaybackEnded += InstrumentOnMidiPlaybackEnded; + Title = _owner.Instrument.Owner.Name; + LoopButton.Disabled = !_owner.Instrument.IsMidiOpen; + LoopButton.Pressed = _owner.Instrument.LoopMidi; + StopButton.Disabled = !_owner.Instrument.IsMidiOpen; + PlaybackSlider.MouseFilter = _owner.Instrument.IsMidiOpen ? MouseFilterMode.Pass : MouseFilterMode.Ignore; + } if (!_midiManager.IsAvailable) { @@ -77,7 +79,7 @@ namespace Content.Client.Instruments PlaybackSlider.MouseFilter = !disabled ? MouseFilterMode.Pass : MouseFilterMode.Ignore; } - private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj) + private async void MidiFileButtonOnOnPressed(ButtonEventArgs obj) { var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi")); await using var file = await _fileDialogManager.OpenFile(filters); @@ -102,7 +104,7 @@ namespace Content.Client.Instruments // While we're waiting, load it into memory. await Task.WhenAll(Timer.Delay(100), file.CopyToAsync(memStream)); - if (!_owner.Instrument.OpenMidi(memStream.GetBuffer().AsSpan(0, (int) memStream.Length))) + if (!_owner.Instrument?.OpenMidi(memStream.GetBuffer().AsSpan(0, (int) memStream.Length)) ?? true) return; MidiPlaybackSetButtonsDisabled(false); @@ -110,7 +112,7 @@ namespace Content.Client.Instruments InputButton.Pressed = false; } - private void MidiInputButtonOnOnToggled(BaseButton.ButtonToggledEventArgs obj) + private void MidiInputButtonOnOnToggled(ButtonToggledEventArgs obj) { if (obj.Pressed) { @@ -118,18 +120,21 @@ namespace Content.Client.Instruments return; MidiStopButtonOnPressed(null); - _owner.Instrument.OpenInput(); + _owner.Instrument?.OpenInput(); } else - _owner.Instrument.CloseInput(); + _owner.Instrument?.CloseInput(); } private bool PlayCheck() { - var instrumentEnt = _owner.Instrument.Owner; var instrument = _owner.Instrument; - _owner.Instrument.Owner.TryGetContainerMan(out var conMan); + if (instrument == null || + !instrument.Owner.TryGetContainerMan(out var conMan)) + { + return false; + } var localPlayer = IoCManager.Resolve().LocalPlayer; @@ -137,36 +142,39 @@ namespace Content.Client.Instruments if (localPlayer?.ControlledEntity == null) return false; // If the instrument is handheld and we're not holding it, we return. - if ((instrument.Handheld && (conMan == null - || conMan.Owner != localPlayer.ControlledEntity))) return false; + if (instrument.Handheld && (conMan.Owner != localPlayer.ControlledEntity)) return false; + + var instrumentEnt = instrument.Owner; // We check that we're in range unobstructed just in case. return localPlayer.InRangeUnobstructed(instrumentEnt, predicate: (e) => e == instrumentEnt || e == localPlayer.ControlledEntity); } - private void MidiStopButtonOnPressed(BaseButton.ButtonEventArgs obj) + private void MidiStopButtonOnPressed(ButtonEventArgs? obj) { MidiPlaybackSetButtonsDisabled(true); - _owner.Instrument.CloseMidi(); + _owner.Instrument?.CloseMidi(); } - private void MidiLoopButtonOnOnToggled(BaseButton.ButtonToggledEventArgs obj) + private void MidiLoopButtonOnOnToggled(ButtonToggledEventArgs obj) { - _owner.Instrument.LoopMidi = obj.Pressed; + if (_owner.Instrument != null) + _owner.Instrument.LoopMidi = obj.Pressed; } private void PlaybackSliderSeek(Range _) { // Do not seek while still grabbing. - if (PlaybackSlider.Grabbed) return; + if (PlaybackSlider.Grabbed || _owner.Instrument == null) return; _owner.Instrument.PlayerTick = (int)Math.Ceiling(PlaybackSlider.Value); } private void PlaybackSliderKeyUp(GUIBoundKeyEventArgs args) { - if (args.Function != EngineKeyFunctions.UIClick) return; + if (args.Function != EngineKeyFunctions.UIClick || _owner.Instrument == null) return; + _owner.Instrument.PlayerTick = (int)Math.Ceiling(PlaybackSlider.Value); } @@ -174,6 +182,8 @@ namespace Content.Client.Instruments { base.Update(args); + if (_owner.Instrument == null) return; + if (!_owner.Instrument.IsMidiOpen) { PlaybackSlider.MaxValue = 1; diff --git a/Content.Client/Interfaces/IClientGameTicker.cs b/Content.Client/Interfaces/IClientGameTicker.cs index f5ebd911af..55fa0c3b98 100644 --- a/Content.Client/Interfaces/IClientGameTicker.cs +++ b/Content.Client/Interfaces/IClientGameTicker.cs @@ -8,7 +8,7 @@ namespace Content.Client.Interfaces public interface IClientGameTicker { bool IsGameStarted { get; } - string ServerInfoBlob { get; } + string? ServerInfoBlob { get; } bool AreWeReady { get; } bool DisallowedLateJoin { get; } TimeSpan StartTime { get; } diff --git a/Content.Client/Interfaces/IClientPreferencesManager.cs b/Content.Client/Interfaces/IClientPreferencesManager.cs index 06fced6678..8fd6b75b17 100644 --- a/Content.Client/Interfaces/IClientPreferencesManager.cs +++ b/Content.Client/Interfaces/IClientPreferencesManager.cs @@ -9,8 +9,8 @@ namespace Content.Client.Interfaces bool ServerDataLoaded => Settings != null; - GameSettings Settings { get; } - PlayerPreferences Preferences { get; } + GameSettings? Settings { get; } + PlayerPreferences? Preferences { get; } void Initialize(); void SelectCharacter(ICharacterProfile profile); void SelectCharacter(int slot); diff --git a/Content.Client/Interfaces/Parallax/IParallaxManager.cs b/Content.Client/Interfaces/Parallax/IParallaxManager.cs index 12b45d6336..d47af0677d 100644 --- a/Content.Client/Interfaces/Parallax/IParallaxManager.cs +++ b/Content.Client/Interfaces/Parallax/IParallaxManager.cs @@ -5,8 +5,8 @@ namespace Content.Client.Interfaces.Parallax { public interface IParallaxManager { - event Action OnTextureLoaded; - Texture ParallaxTexture { get; } + event Action? OnTextureLoaded; + Texture? ParallaxTexture { get; } void LoadParallax(); } } diff --git a/Content.Client/Parallax/ParallaxGenerator.cs b/Content.Client/Parallax/ParallaxGenerator.cs index 794a891a84..ec1b9b8b81 100644 --- a/Content.Client/Parallax/ParallaxGenerator.cs +++ b/Content.Client/Parallax/ParallaxGenerator.cs @@ -18,7 +18,7 @@ namespace Content.Client.Parallax { private readonly List Layers = new(); - public static Image GenerateParallax(TomlTable config, Size size, ISawmill sawmill, List> debugLayerDump) + public static Image GenerateParallax(TomlTable config, Size size, ISawmill sawmill, List>? debugLayerDump) { sawmill.Debug("Generating parallax!"); var generator = new ParallaxGenerator(); diff --git a/Content.Client/Parallax/ParallaxManager.cs b/Content.Client/Parallax/ParallaxManager.cs index 1b12c9a3e0..a84ec87675 100644 --- a/Content.Client/Parallax/ParallaxManager.cs +++ b/Content.Client/Parallax/ParallaxManager.cs @@ -29,8 +29,8 @@ namespace Content.Client.Parallax private static readonly ResourcePath ParallaxPath = new("/parallax_cache.png"); private static readonly ResourcePath ParallaxConfigOld = new("/parallax_config_old"); - public event Action OnTextureLoaded; - public Texture ParallaxTexture { get; private set; } + public event Action? OnTextureLoaded; + public Texture? ParallaxTexture { get; private set; } public async void LoadParallax() { @@ -75,7 +75,7 @@ namespace Content.Client.Parallax table = Toml.ReadString(contents); } - List> debugImages = null; + List>? debugImages = null; if (debugParallax) { debugImages = new List>(); @@ -94,7 +94,7 @@ namespace Content.Client.Parallax image.SaveAsPng(stream); } - if (debugParallax) + if (debugParallax && debugImages != null) { var i = 0; foreach (var debugImage in debugImages) diff --git a/Content.Client/Parallax/ParallaxOverlay.cs b/Content.Client/Parallax/ParallaxOverlay.cs index 01d49e3bc7..e3c41019b0 100644 --- a/Content.Client/Parallax/ParallaxOverlay.cs +++ b/Content.Client/Parallax/ParallaxOverlay.cs @@ -16,7 +16,7 @@ namespace Content.Client.Parallax private const float Slowness = 0.5f; - private Texture _parallaxTexture; + private Texture? _parallaxTexture; public override OverlaySpace Space => OverlaySpace.ScreenSpaceBelowWorld; private readonly ShaderInstance _shader; diff --git a/Content.Client/Placement/Modes/WallmountLight.cs b/Content.Client/Placement/Modes/WallmountLight.cs index 319dcb7bb3..5c9567c259 100644 --- a/Content.Client/Placement/Modes/WallmountLight.cs +++ b/Content.Client/Placement/Modes/WallmountLight.cs @@ -1,4 +1,3 @@ -#nullable enable using Robust.Client.Placement; using Robust.Shared.Map; using Robust.Shared.Maths; diff --git a/Content.Client/Research/LatheMenu.cs b/Content.Client/Research/LatheMenu.cs index 3b05afe2f0..c299bba910 100644 --- a/Content.Client/Research/LatheMenu.cs +++ b/Content.Client/Research/LatheMenu.cs @@ -7,7 +7,6 @@ using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Client.Utility; using Robust.Shared.IoC; -using Robust.Shared.Maths; using Robust.Shared.Prototypes; namespace Content.Client.Research @@ -24,11 +23,11 @@ namespace Content.Client.Research public Button ServerConnectButton; public Button ServerSyncButton; - public LatheBoundUserInterface Owner { get; set; } + public LatheBoundUserInterface Owner { get; } private readonly List _shownRecipes = new(); - public LatheMenu(LatheBoundUserInterface owner = null) + public LatheMenu(LatheBoundUserInterface owner) { SetSize = MinSize = (300, 450); IoCManager.InjectDependencies(this); @@ -126,7 +125,7 @@ namespace Content.Client.Research }; hBoxButtons.AddChild(spacer); - if (Owner?.Database is ProtolatheDatabaseComponent database) + if (Owner.Database is ProtolatheDatabaseComponent database) { hBoxButtons.AddChild(ServerConnectButton); hBoxButtons.AddChild(ServerSyncButton); @@ -157,9 +156,11 @@ namespace Content.Client.Research { _materials.Clear(); + if (Owner.Storage == null) return; + foreach (var (id, amount) in Owner.Storage) { - if (!_prototypeManager.TryIndex(id, out MaterialPrototype materialPrototype)) continue; + if (!_prototypeManager.TryIndex(id, out MaterialPrototype? materialPrototype)) continue; var material = materialPrototype; _materials.AddItem($"{material.Name} {amount} cm³", material.Icon.Frame0(), false); } @@ -175,7 +176,7 @@ namespace Content.Client.Research for (var i = 0; i < _shownRecipes.Count; i++) { var prototype = _shownRecipes[i]; - _items[i].Disabled = !Owner.Lathe.CanProduce(prototype, quantity); + _items[i].Disabled = !Owner.Lathe?.CanProduce(prototype, quantity) ?? true; } } @@ -206,6 +207,8 @@ namespace Content.Client.Research { _shownRecipes.Clear(); + if (Owner.Database == null) return; + foreach (var prototype in Owner.Database) { if (_searchBar.Text.Trim().Length != 0) diff --git a/Content.Client/Research/LatheQueueMenu.cs b/Content.Client/Research/LatheQueueMenu.cs index d8ddf981d2..d0cb71e0e3 100644 --- a/Content.Client/Research/LatheQueueMenu.cs +++ b/Content.Client/Research/LatheQueueMenu.cs @@ -19,8 +19,9 @@ namespace Content.Client.Research private readonly Label _description; private readonly TextureRect _icon; - public LatheQueueMenu() + public LatheQueueMenu(LatheBoundUserInterface owner) { + Owner = owner; SetSize = MinSize = (300, 450); Title = Loc.GetString("Lathe Queue"); diff --git a/Content.Client/Research/ResearchConsoleMenu.cs b/Content.Client/Research/ResearchConsoleMenu.cs index 2db8b37769..e4a479b502 100644 --- a/Content.Client/Research/ResearchConsoleMenu.cs +++ b/Content.Client/Research/ResearchConsoleMenu.cs @@ -7,14 +7,13 @@ using Robust.Client.UserInterface.CustomControls; using Robust.Client.Utility; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Maths; using Robust.Shared.Prototypes; namespace Content.Client.Research { public class ResearchConsoleMenu : SS14Window { - public ResearchConsoleBoundUserInterface Owner { get; set; } + public ResearchConsoleBoundUserInterface Owner { get; } private readonly List _unlockedTechnologyPrototypes = new(); private readonly List _unlockableTechnologyPrototypes = new(); @@ -34,9 +33,9 @@ namespace Content.Client.Research public Button ServerSelectionButton { get; private set; } public Button ServerSyncButton { get; private set; } - public TechnologyPrototype TechnologySelected; + public TechnologyPrototype? TechnologySelected; - public ResearchConsoleMenu(ResearchConsoleBoundUserInterface owner = null) + public ResearchConsoleMenu(ResearchConsoleBoundUserInterface owner) { SetSize = MinSize = (800, 400); @@ -274,7 +273,7 @@ namespace Content.Client.Research for (var i = 0; i < TechnologySelected.RequiredTechnologies.Count; i++) { var requiredId = TechnologySelected.RequiredTechnologies[i]; - if (!prototypeMan.TryIndex(requiredId, out TechnologyPrototype prototype)) continue; + if (!prototypeMan.TryIndex(requiredId, out TechnologyPrototype? prototype)) continue; if (i == 0) _technologyRequirements.Text = Loc.GetString("Requires") + $": {prototype.Name}"; else diff --git a/Content.Client/Sandbox/SandboxManager.cs b/Content.Client/Sandbox/SandboxManager.cs index a540917131..ec6c0edeac 100644 --- a/Content.Client/Sandbox/SandboxManager.cs +++ b/Content.Client/Sandbox/SandboxManager.cs @@ -117,11 +117,11 @@ namespace Content.Client.Sandbox public bool SandboxAllowed { get; private set; } - public event Action AllowedChanged; + public event Action? AllowedChanged; - private SandboxWindow _window; - private EntitySpawnWindow _spawnWindow; - private TileSpawnWindow _tilesSpawnWindow; + private SandboxWindow? _window; + private EntitySpawnWindow? _spawnWindow; + private TileSpawnWindow? _tilesSpawnWindow; private bool _sandboxWindowToggled; public void Initialize() diff --git a/Content.Client/ScreenshotHook.cs b/Content.Client/ScreenshotHook.cs index 7b17913cf3..56fc7560f3 100644 --- a/Content.Client/ScreenshotHook.cs +++ b/Content.Client/ScreenshotHook.cs @@ -17,9 +17,9 @@ namespace Content.Client { private static readonly ResourcePath BaseScreenshotPath = new("/Screenshots"); - [Dependency] private readonly IInputManager _inputManager = default; - [Dependency] private readonly IClyde _clyde = default; - [Dependency] private readonly IResourceManager _resourceManager = default; + [Dependency] private readonly IInputManager _inputManager = default!; + [Dependency] private readonly IClyde _clyde = default!; + [Dependency] private readonly IResourceManager _resourceManager = default!; public void Initialize() { diff --git a/Content.Client/State/GameScreen.cs b/Content.Client/State/GameScreen.cs index fcccc3693b..6aae189100 100644 --- a/Content.Client/State/GameScreen.cs +++ b/Content.Client/State/GameScreen.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Client.Administration; using Content.Client.Chat; using Content.Client.Construction; diff --git a/Content.Client/State/GameScreenBase.cs b/Content.Client/State/GameScreenBase.cs index f01c6f46a0..d9ce1acac9 100644 --- a/Content.Client/State/GameScreenBase.cs +++ b/Content.Client/State/GameScreenBase.cs @@ -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(); diff --git a/Content.Client/State/LauncherConnecting.cs b/Content.Client/State/LauncherConnecting.cs index 61c3cc19a0..51ff4cc735 100644 --- a/Content.Client/State/LauncherConnecting.cs +++ b/Content.Client/State/LauncherConnecting.cs @@ -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 diff --git a/Content.Client/State/LobbyState.cs b/Content.Client/State/LobbyState.cs index 231a48576c..df15cb7553 100644 --- a/Content.Client/State/LobbyState.cs +++ b/Content.Client/State/LobbyState.cs @@ -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); diff --git a/Content.Client/State/MainMenu.cs b/Content.Client/State/MainMenu.cs index 34b3c93647..b12619f72c 100644 --- a/Content.Client/State/MainMenu.cs +++ b/Content.Client/State/MainMenu.cs @@ -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(); diff --git a/Content.Client/StationEvents/IStationEventManager.cs b/Content.Client/StationEvents/IStationEventManager.cs index 24046ea357..ba1ddf9e4a 100644 --- a/Content.Client/StationEvents/IStationEventManager.cs +++ b/Content.Client/StationEvents/IStationEventManager.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; namespace Content.Client.StationEvents diff --git a/Content.Client/StationEvents/RadiationPulseOverlay.cs b/Content.Client/StationEvents/RadiationPulseOverlay.cs index ecb4905f6d..679c8c3ba4 100644 --- a/Content.Client/StationEvents/RadiationPulseOverlay.cs +++ b/Content.Client/StationEvents/RadiationPulseOverlay.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/Content.Client/StationEvents/StationEventManager.cs b/Content.Client/StationEvents/StationEventManager.cs index 3f9815aa61..d34af8dd82 100644 --- a/Content.Client/StationEvents/StationEventManager.cs +++ b/Content.Client/StationEvents/StationEventManager.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using Content.Shared.Network.NetMessages; using Robust.Shared.IoC; diff --git a/Content.Client/UserInterface/ActionAlertTooltip.cs b/Content.Client/UserInterface/ActionAlertTooltip.cs index de5e4fa0bc..a411c81c3a 100644 --- a/Content.Client/UserInterface/ActionAlertTooltip.cs +++ b/Content.Client/UserInterface/ActionAlertTooltip.cs @@ -1,6 +1,4 @@ -#nullable enable - -using System; +using System; using Content.Client.UserInterface.Stylesheets; using Robust.Client.UserInterface.Controls; using Robust.Shared.IoC; diff --git a/Content.Client/UserInterface/ActionMenu.cs b/Content.Client/UserInterface/ActionMenu.cs index 2cdbb6fa65..30d4413a70 100644 --- a/Content.Client/UserInterface/ActionMenu.cs +++ b/Content.Client/UserInterface/ActionMenu.cs @@ -18,6 +18,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Timing; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.UserInterface { @@ -45,7 +46,7 @@ namespace Content.Client.UserInterface public bool IsDragging => _dragDropHelper.IsDragging; // parallel list of actions currently selectable in itemList - private BaseActionPrototype[] _actionList; + private BaseActionPrototype[] _actionList = new BaseActionPrototype[0]; private readonly ActionManager _actionManager; private readonly ClientActionsComponent _actionsComponent; @@ -87,7 +88,7 @@ namespace Content.Client.UserInterface (_filterButton = new MultiselectOptionButton() { Label = Loc.GetString("Filter") - }), + }) } }, (_clearButton = new Button @@ -155,7 +156,7 @@ namespace Content.Client.UserInterface _gameHud.ActionsButtonDown = true; foreach (var actionMenuControl in _resultsGrid.Children) { - var actionMenuItem = (actionMenuControl as ActionMenuItem); + var actionMenuItem = (ActionMenuItem) actionMenuControl; actionMenuItem.OnButtonDown += OnItemButtonDown; actionMenuItem.OnButtonUp += OnItemButtonUp; actionMenuItem.OnPressed += OnItemPressed; @@ -172,7 +173,7 @@ namespace Content.Client.UserInterface _gameHud.ActionsButtonDown = false; foreach (var actionMenuControl in _resultsGrid.Children) { - var actionMenuItem = (actionMenuControl as ActionMenuItem); + var actionMenuItem = (ActionMenuItem) actionMenuControl; actionMenuItem.OnButtonDown -= OnItemButtonDown; actionMenuItem.OnButtonUp -= OnItemButtonUp; actionMenuItem.OnPressed -= OnItemPressed; @@ -195,7 +196,7 @@ namespace Content.Client.UserInterface private bool OnBeginActionDrag() { - _dragShadow.Texture = _dragDropHelper.Dragged.Action.Icon.Frame0(); + _dragShadow.Texture = _dragDropHelper.Dragged!.Action.Icon.Frame0(); // don't make visible until frameupdate, otherwise it'll flicker LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled - (32, 32)); return true; @@ -215,13 +216,18 @@ namespace Content.Client.UserInterface _dragShadow.Visible = false; } - private void OnItemButtonDown(BaseButton.ButtonEventArgs args) + private void OnItemButtonDown(ButtonEventArgs args) { - if (args.Event.Function != EngineKeyFunctions.UIClick) return; - _dragDropHelper.MouseDown(args.Button as ActionMenuItem); + if (args.Event.Function != EngineKeyFunctions.UIClick || + args.Button is not ActionMenuItem action) + { + return; + } + + _dragDropHelper.MouseDown(action); } - private void OnItemButtonUp(BaseButton.ButtonEventArgs args) + private void OnItemButtonUp(ButtonEventArgs args) { // note the buttonup only fires on the control that was originally // pressed to initiate the drag, NOT the one we are currently hovering @@ -288,7 +294,7 @@ namespace Content.Client.UserInterface _dragDropHelper.EndDrag(); } - private void OnItemPressed(BaseButton.ButtonEventArgs args) + private void OnItemPressed(ButtonEventArgs args) { if (args.Button is not ActionMenuItem actionMenuItem) return; switch (actionMenuItem.Action) @@ -307,7 +313,7 @@ namespace Content.Client.UserInterface _actionsUI.UpdateUI(); } - private void OnClearButtonPressed(BaseButton.ButtonEventArgs args) + private void OnClearButtonPressed(ButtonEventArgs args) { _searchBar.Clear(); _filterButton.DeselectAll(); diff --git a/Content.Client/UserInterface/ActionMenuItem.cs b/Content.Client/UserInterface/ActionMenuItem.cs index 40bf8f83ae..f3d6e7b365 100644 --- a/Content.Client/UserInterface/ActionMenuItem.cs +++ b/Content.Client/UserInterface/ActionMenuItem.cs @@ -1,6 +1,4 @@ -#nullable enable - -using System; +using System; using Content.Client.UserInterface.Stylesheets; using Content.Shared.Actions; using Robust.Client.UserInterface; diff --git a/Content.Client/UserInterface/ActionsUI.cs b/Content.Client/UserInterface/ActionsUI.cs index 59b1a982bd..9f7768b878 100644 --- a/Content.Client/UserInterface/ActionsUI.cs +++ b/Content.Client/UserInterface/ActionsUI.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using Content.Client.GameObjects.Components.Mobs; using Content.Client.GameObjects.Components.Mobs.Actions; using Content.Client.UserInterface.Controls; @@ -531,7 +530,7 @@ namespace Content.Client.UserInterface private bool OnBeginActionDrag() { // only initiate the drag if the slot has an action in it - if (Locked || DragDropHelper.Dragged.Action == null) return false; + if (Locked || DragDropHelper.Dragged?.Action == null) return false; _dragShadow.Texture = DragDropHelper.Dragged.Action.Icon.Frame0(); LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled - (32, 32)); @@ -542,7 +541,7 @@ namespace Content.Client.UserInterface private bool OnContinueActionDrag(float frameTime) { // stop if there's no action in the slot - if (Locked || DragDropHelper.Dragged.Action == null) return false; + if (Locked || DragDropHelper.Dragged?.Action == null) return false; // keep dragged entity centered under mouse LayoutContainer.SetPosition(_dragShadow, UserInterfaceManager.MousePositionScaled - (32, 32)); diff --git a/Content.Client/UserInterface/AdminMenu/AdminMenuManager.cs b/Content.Client/UserInterface/AdminMenu/AdminMenuManager.cs index 1d6363baa4..ec113b3877 100644 --- a/Content.Client/UserInterface/AdminMenu/AdminMenuManager.cs +++ b/Content.Client/UserInterface/AdminMenu/AdminMenuManager.cs @@ -19,8 +19,8 @@ namespace Content.Client.UserInterface.AdminMenu [Dependency] private readonly IClientAdminManager _clientAdminManager = default!; [Dependency] private readonly IClientConGroupController _clientConGroupController = default!; - private AdminMenuWindow _window; - private List _commandWindows; + private AdminMenuWindow? _window; + private List _commandWindows = new(); public void Initialize() { @@ -29,10 +29,10 @@ namespace Content.Client.UserInterface.AdminMenu _commandWindows = new List(); // Reset the AdminMenu Window on disconnect - _netManager.Disconnect += (sender, channel) => ResetWindow(); + _netManager.Disconnect += (_, _) => ResetWindow(); _inputManager.SetInputCommand(ContentKeyFunctions.OpenAdminMenu, - InputCmdHandler.FromDelegate(session => Toggle())); + InputCmdHandler.FromDelegate(_ => Toggle())); _clientAdminManager.AdminStatusUpdated += () => { @@ -68,7 +68,7 @@ namespace Content.Client.UserInterface.AdminMenu private void HandlePlayerListMessage(AdminMenuPlayerListMessage msg) { - _window.RefreshPlayerList(msg.NamesToPlayers); + _window?.RefreshPlayerList(msg.NamesToPlayers); } public void ResetWindow() diff --git a/Content.Client/UserInterface/AdminMenu/SetOutfit/SetOutfitMenu.xaml.cs b/Content.Client/UserInterface/AdminMenu/SetOutfit/SetOutfitMenu.xaml.cs index 4a22d467f0..0ddc345139 100644 --- a/Content.Client/UserInterface/AdminMenu/SetOutfit/SetOutfitMenu.xaml.cs +++ b/Content.Client/UserInterface/AdminMenu/SetOutfit/SetOutfitMenu.xaml.cs @@ -1,4 +1,3 @@ -#nullable enable using Content.Shared.Roles; using Robust.Client.AutoGenerated; using Robust.Client.Console; diff --git a/Content.Client/UserInterface/Atmos/GasTank/GasTankBoundUserInterface.cs b/Content.Client/UserInterface/Atmos/GasTank/GasTankBoundUserInterface.cs index f3f5c980e2..7968075018 100644 --- a/Content.Client/UserInterface/Atmos/GasTank/GasTankBoundUserInterface.cs +++ b/Content.Client/UserInterface/Atmos/GasTank/GasTankBoundUserInterface.cs @@ -14,7 +14,7 @@ namespace Content.Client.UserInterface.Atmos.GasTank { } - private GasTankWindow _window; + private GasTankWindow? _window; public void SetOutputPressure(in float value) { @@ -37,14 +37,15 @@ namespace Content.Client.UserInterface.Atmos.GasTank protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - _window.UpdateState((GasTankBoundUserInterfaceState) state); + + _window?.UpdateState((GasTankBoundUserInterfaceState) state); } protected override void Dispose(bool disposing) { base.Dispose(disposing); - _window.Close(); + _window?.Close(); } } } diff --git a/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs b/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs index acd34ab97b..be51f5c8a7 100644 --- a/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs +++ b/Content.Client/UserInterface/Cargo/CargoConsoleMenu.cs @@ -10,6 +10,7 @@ using Robust.Client.Utility; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; +using static Robust.Client.UserInterface.Controls.BaseButton; namespace Content.Client.UserInterface.Cargo { @@ -17,9 +18,9 @@ namespace Content.Client.UserInterface.Cargo { public CargoConsoleBoundUserInterface Owner { get; private set; } - public event Action OnItemSelected; - public event Action OnOrderApproved; - public event Action OnOrderCanceled; + public event Action? OnItemSelected; + public event Action? OnOrderApproved; + public event Action? OnOrderCanceled; private readonly List _categoryStrings = new(); @@ -36,7 +37,7 @@ namespace Content.Client.UserInterface.Cargo public Button CallShuttleButton { get; set; } public Button PermissionsButton { get; set; } - private string _category = null; + private string? _category = null; public CargoConsoleMenu(CargoConsoleBoundUserInterface owner) { @@ -197,7 +198,7 @@ namespace Content.Client.UserInterface.Cargo _categories.OnItemSelected += OnCategoryItemSelected; } - private void OnCallShuttleButtonPressed(BaseButton.ButtonEventArgs args) + private void OnCallShuttleButtonPressed(ButtonEventArgs args) { } @@ -228,6 +229,11 @@ namespace Content.Client.UserInterface.Cargo { Products.RemoveAllChildren(); + if (Owner.Market == null) + { + return; + } + var search = _searchBar.Text.Trim().ToLowerInvariant(); foreach (var prototype in Owner.Market.Products) { @@ -260,6 +266,11 @@ namespace Content.Client.UserInterface.Cargo _categoryStrings.Clear(); _categories.Clear(); + if (Owner.Market == null) + { + return; + } + _categoryStrings.Add(Loc.GetString("All")); var search = _searchBar.Text.Trim().ToLowerInvariant(); @@ -284,13 +295,25 @@ namespace Content.Client.UserInterface.Cargo { _orders.RemoveAllChildren(); _requests.RemoveAllChildren(); + + if (Owner.Orders == null || Owner.Market == null) + { + return; + } + foreach (var order in Owner.Orders.Orders) { - var row = new CargoOrderRow(); - row.Order = order; - row.Icon.Texture = Owner.Market.GetProduct(order.ProductId).Icon.Frame0(); - row.ProductName.Text = $"{Owner.Market.GetProduct(order.ProductId).Name} (x{order.Amount}) by {order.Requester}"; - row.Description.Text = $"Reasons: {order.Reason}"; + var row = new CargoOrderRow + { + Order = order, + Icon = {Texture = Owner.Market.GetProduct(order.ProductId)?.Icon.Frame0()}, + ProductName = + { + Text = + $"{Owner.Market.GetProduct(order.ProductId)?.Name} (x{order.Amount}) by {order.Requester}" + }, + Description = {Text = $"Reasons: {order.Reason}"} + }; row.Cancel.OnPressed += (args) => { OnOrderCanceled?.Invoke(args); }; if (order.Approved) { @@ -342,7 +365,7 @@ namespace Content.Client.UserInterface.Cargo internal class CargoProductRow : PanelContainer { - public CargoProductPrototype Product { get; set; } + public CargoProductPrototype? Product { get; set; } public TextureRect Icon { get; private set; } public Button MainButton { get; private set; } public Label ProductName { get; private set; } @@ -395,7 +418,7 @@ namespace Content.Client.UserInterface.Cargo internal class CargoOrderRow : PanelContainer { - public CargoOrderData Order { get; set; } + public CargoOrderData? Order { get; set; } public TextureRect Icon { get; private set; } public Label ProductName { get; private set; } public Label Description { get; private set; } diff --git a/Content.Client/UserInterface/Cargo/GalacticBankSelectionMenu.cs b/Content.Client/UserInterface/Cargo/GalacticBankSelectionMenu.cs index e4179617f2..26ce03c35f 100644 --- a/Content.Client/UserInterface/Cargo/GalacticBankSelectionMenu.cs +++ b/Content.Client/UserInterface/Cargo/GalacticBankSelectionMenu.cs @@ -1,24 +1,20 @@ - -using Content.Client.GameObjects.Components.Cargo; +using Content.Client.GameObjects.Components.Cargo; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.IoC; using Robust.Shared.Localization; -using Robust.Shared.Maths; namespace Content.Client.UserInterface.Cargo { public class GalacticBankSelectionMenu : SS14Window { private readonly ItemList _accounts; - private int _accountCount = 0; + private int _accountCount; private string[] _accountNames = new string[] { }; private int[] _accountIds = new int[] { }; private int _selectedAccountId = -1; - public CargoConsoleBoundUserInterface Owner; - - public GalacticBankSelectionMenu() + public GalacticBankSelectionMenu(CargoConsoleBoundUserInterface owner) { MinSize = SetSize = (300, 300); IoCManager.InjectDependencies(this); diff --git a/Content.Client/UserInterface/CharacterSetupGui.cs b/Content.Client/UserInterface/CharacterSetupGui.cs index 3b04b74440..e0917d43a8 100644 --- a/Content.Client/UserInterface/CharacterSetupGui.cs +++ b/Content.Client/UserInterface/CharacterSetupGui.cs @@ -173,9 +173,9 @@ namespace Content.Client.UserInterface } _createNewCharacterButton.ToolTip = - $"A maximum of {_preferencesManager.Settings.MaxCharacterSlots} characters are allowed."; + $"A maximum of {_preferencesManager.Settings!.MaxCharacterSlots} characters are allowed."; - foreach (var (slot, character) in _preferencesManager.Preferences.Characters) + foreach (var (slot, character) in _preferencesManager.Preferences!.Characters) { if (character is null) { @@ -228,7 +228,7 @@ namespace Content.Client.UserInterface LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid); } - var isSelectedCharacter = profile == preferencesManager.Preferences.SelectedCharacter; + var isSelectedCharacter = profile == preferencesManager.Preferences?.SelectedCharacter; if (isSelectedCharacter) Pressed = true; @@ -260,9 +260,9 @@ namespace Content.Client.UserInterface Text = "Delete", Visible = !isSelectedCharacter, }; - deleteButton.OnPressed += args => + deleteButton.OnPressed += _ => { - Parent.RemoveChild(this); + Parent?.RemoveChild(this); preferencesManager.DeleteCharacter(profile); }; @@ -288,7 +288,7 @@ namespace Content.Client.UserInterface return; _previewDummy.Delete(); - _previewDummy = null; + _previewDummy = null!; } } } diff --git a/Content.Client/UserInterface/Controls/ActionSlot.cs b/Content.Client/UserInterface/Controls/ActionSlot.cs index d9d941ade9..7a2d3bca70 100644 --- a/Content.Client/UserInterface/Controls/ActionSlot.cs +++ b/Content.Client/UserInterface/Controls/ActionSlot.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using Content.Client.GameObjects.Components.Mobs; using Content.Client.UserInterface.Stylesheets; using Content.Shared.Actions; diff --git a/Content.Client/UserInterface/Controls/AlertControl.cs b/Content.Client/UserInterface/Controls/AlertControl.cs index c4243e8363..a7a7e3b92e 100644 --- a/Content.Client/UserInterface/Controls/AlertControl.cs +++ b/Content.Client/UserInterface/Controls/AlertControl.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using Content.Shared.Alert; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; diff --git a/Content.Client/UserInterface/CreditsWindow.cs b/Content.Client/UserInterface/CreditsWindow.cs index af4624b6ab..7b53ef0796 100644 --- a/Content.Client/UserInterface/CreditsWindow.cs +++ b/Content.Client/UserInterface/CreditsWindow.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/Content.Client/UserInterface/EscapeMenu.xaml.cs b/Content.Client/UserInterface/EscapeMenu.xaml.cs index c6278f4b22..3d21a5bb60 100644 --- a/Content.Client/UserInterface/EscapeMenu.xaml.cs +++ b/Content.Client/UserInterface/EscapeMenu.xaml.cs @@ -11,7 +11,7 @@ namespace Content.Client.UserInterface { private readonly IClientConsoleHost _consoleHost; - private OptionsMenu optionsMenu; + private readonly OptionsMenu _optionsMenu; public EscapeMenu(IClientConsoleHost consoleHost) { @@ -19,7 +19,7 @@ namespace Content.Client.UserInterface RobustXamlLoader.Load(this); - optionsMenu = new OptionsMenu(); + _optionsMenu = new OptionsMenu(); OptionsButton.OnPressed += OnOptionsButtonClicked; QuitButton.OnPressed += OnQuitButtonClicked; @@ -40,15 +40,16 @@ namespace Content.Client.UserInterface private void OnOptionsButtonClicked(BaseButton.ButtonEventArgs args) { - optionsMenu.OpenCentered(); + _optionsMenu.OpenCentered(); } protected override void Dispose(bool disposing) { base.Dispose(disposing); + if (disposing) { - optionsMenu.Dispose(); + _optionsMenu.Dispose(); } } } diff --git a/Content.Client/UserInterface/GameHud.cs b/Content.Client/UserInterface/GameHud.cs index ed16bde928..7857327b89 100644 --- a/Content.Client/UserInterface/GameHud.cs +++ b/Content.Client/UserInterface/GameHud.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Diagnostics.CodeAnalysis; using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.GameObjects.Components.Mobs; @@ -6,6 +7,7 @@ using Content.Shared.Input; using Robust.Client.Graphics; using Robust.Client.Input; using Robust.Client.ResourceManagement; +using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.Input; using Robust.Shared.Input.Binding; @@ -28,37 +30,37 @@ namespace Content.Client.UserInterface // Escape top button. bool EscapeButtonDown { get; set; } - Action EscapeButtonToggled { get; set; } + Action? EscapeButtonToggled { get; set; } // Character top button. bool CharacterButtonDown { get; set; } bool CharacterButtonVisible { get; set; } - Action CharacterButtonToggled { get; set; } + Action? CharacterButtonToggled { get; set; } // Inventory top button. bool InventoryButtonDown { get; set; } bool InventoryButtonVisible { get; set; } - Action InventoryButtonToggled { get; set; } + Action? InventoryButtonToggled { get; set; } // Crafting top button. bool CraftingButtonDown { get; set; } bool CraftingButtonVisible { get; set; } - Action CraftingButtonToggled { get; set; } + Action? CraftingButtonToggled { get; set; } // Actions top button. bool ActionsButtonDown { get; set; } bool ActionsButtonVisible { get; set; } - Action ActionsButtonToggled { get; set; } + Action? ActionsButtonToggled { get; set; } // Admin top button. bool AdminButtonDown { get; set; } bool AdminButtonVisible { get; set; } - Action AdminButtonToggled { get; set; } + Action? AdminButtonToggled { get; set; } // Sandbox top button. bool SandboxButtonDown { get; set; } bool SandboxButtonVisible { get; set; } - Action SandboxButtonToggled { get; set; } + Action? SandboxButtonToggled { get; set; } Control HandsContainer { get; } Control SuspicionContainer { get; } @@ -68,8 +70,8 @@ namespace Content.Client.UserInterface bool CombatPanelVisible { get; set; } bool CombatModeActive { get; set; } TargetingZone TargetingZone { get; set; } - Action OnCombatModeChanged { get; set; } - Action OnTargetingZoneChanged { get; set; } + Action? OnCombatModeChanged { get; set; } + Action? OnTargetingZoneChanged { get; set; } Control VoteContainer { get; } @@ -81,28 +83,28 @@ namespace Content.Client.UserInterface internal sealed class GameHud : IGameHud { - private HBoxContainer _topButtonsContainer; - private TopButton _buttonEscapeMenu; - private TopButton _buttonInfo; - private TopButton _buttonCharacterMenu; - private TopButton _buttonInventoryMenu; - private TopButton _buttonCraftingMenu; - private TopButton _buttonActionsMenu; - private TopButton _buttonAdminMenu; - private TopButton _buttonSandboxMenu; - private InfoWindow _infoWindow; - private TargetingDoll _targetingDoll; - private Button _combatModeButton; - private VBoxContainer _combatPanelContainer; - private VBoxContainer _topNotificationContainer; + private HBoxContainer _topButtonsContainer = default!; + private TopButton _buttonEscapeMenu = default!; + private TopButton _buttonInfo = default!; + private TopButton _buttonCharacterMenu = default!; + private TopButton _buttonInventoryMenu = default!; + private TopButton _buttonCraftingMenu = default!; + private TopButton _buttonActionsMenu = default!; + private TopButton _buttonAdminMenu = default!; + private TopButton _buttonSandboxMenu = default!; + private InfoWindow _infoWindow = default!; + private TargetingDoll _targetingDoll = default!; + private Button _combatModeButton = default!; + private VBoxContainer _combatPanelContainer = default!; + private VBoxContainer _topNotificationContainer = default!; [Dependency] private readonly IResourceCache _resourceCache = default!; [Dependency] private readonly IInputManager _inputManager = default!; - public Control HandsContainer { get; private set; } - public Control SuspicionContainer { get; private set; } - public Control RightInventoryQuickButtonContainer { get; private set; } - public Control LeftInventoryQuickButtonContainer { get; private set; } + public Control HandsContainer { get; private set; } = default!; + public Control SuspicionContainer { get; private set; } = default!; + public Control RightInventoryQuickButtonContainer { get; private set; } = default!; + public Control LeftInventoryQuickButtonContainer { get; private set; } = default!; public bool CombatPanelVisible { @@ -122,8 +124,8 @@ namespace Content.Client.UserInterface set => _targetingDoll.ActiveZone = value; } - public Action OnCombatModeChanged { get; set; } - public Action OnTargetingZoneChanged { get; set; } + public Action? OnCombatModeChanged { get; set; } + public Action? OnTargetingZoneChanged { get; set; } public void AddTopNotification(TopNotification notification) { @@ -369,7 +371,7 @@ namespace Content.Client.UserInterface } } - public Control RootControl { get; private set; } + public Control RootControl { get; private set; } = default!; public bool EscapeButtonDown { @@ -377,7 +379,7 @@ namespace Content.Client.UserInterface set => _buttonEscapeMenu.Pressed = value; } - public Action EscapeButtonToggled { get; set; } + public Action? EscapeButtonToggled { get; set; } public bool CharacterButtonDown { @@ -391,7 +393,7 @@ namespace Content.Client.UserInterface set => _buttonCharacterMenu.Visible = value; } - public Action CharacterButtonToggled { get; set; } + public Action? CharacterButtonToggled { get; set; } public bool InventoryButtonDown { @@ -405,7 +407,7 @@ namespace Content.Client.UserInterface set => _buttonInventoryMenu.Visible = value; } - public Action InventoryButtonToggled { get; set; } + public Action? InventoryButtonToggled { get; set; } public bool CraftingButtonDown { @@ -419,7 +421,7 @@ namespace Content.Client.UserInterface set => _buttonCraftingMenu.Visible = value; } - public Action CraftingButtonToggled { get; set; } + public Action? CraftingButtonToggled { get; set; } public bool ActionsButtonDown { @@ -433,7 +435,7 @@ namespace Content.Client.UserInterface set => _buttonActionsMenu.Visible = value; } - public Action ActionsButtonToggled { get; set; } + public Action? ActionsButtonToggled { get; set; } public bool AdminButtonDown { @@ -447,7 +449,7 @@ namespace Content.Client.UserInterface set => _buttonAdminMenu.Visible = value; } - public Action AdminButtonToggled { get; set; } + public Action? AdminButtonToggled { get; set; } public bool SandboxButtonDown { @@ -461,9 +463,9 @@ namespace Content.Client.UserInterface set => _buttonSandboxMenu.Visible = value; } - public Action SandboxButtonToggled { get; set; } + public Action? SandboxButtonToggled { get; set; } - public Control VoteContainer { get; private set; } + public Control VoteContainer { get; private set; } = default!; public sealed class TopButton : ContainerButton { @@ -547,7 +549,7 @@ namespace Content.Client.UserInterface return TryGetShortKeyName(keyFunction, out var name) ? Loc.GetString(name) : " "; } - private bool TryGetShortKeyName(BoundKeyFunction keyFunction, out string name) + private bool TryGetShortKeyName(BoundKeyFunction keyFunction, [NotNullWhen(true)] out string? name) { if (_inputManager.TryGetKeyBinding(keyFunction, out var binding)) { @@ -632,7 +634,7 @@ namespace Content.Client.UserInterface return false; } - private string DefaultShortKeyName(BoundKeyFunction keyFunction) + private string? DefaultShortKeyName(BoundKeyFunction keyFunction) { var name = FormattedMessage.EscapeText(_inputManager.GetKeyFunctionButtonString(keyFunction)); return name.Length > 3 ? null : name; diff --git a/Content.Client/UserInterface/HandsGui.cs b/Content.Client/UserInterface/HandsGui.cs index 734b0f0336..b90ff28dfa 100644 --- a/Content.Client/UserInterface/HandsGui.cs +++ b/Content.Client/UserInterface/HandsGui.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Client.GameObjects.Components.Items; using Content.Client.Utility; @@ -125,7 +126,7 @@ namespace Content.Client.UserInterface /// /// /// true if successful and false if failure - private bool TryGetHands(out HandsComponent hands) + private bool TryGetHands([NotNullWhen(true)] out HandsComponent? hands) { hands = default; diff --git a/Content.Client/UserInterface/HumanoidProfileEditor.Random.cs b/Content.Client/UserInterface/HumanoidProfileEditor.Random.cs index ffc5e1d1fe..87a7883a57 100644 --- a/Content.Client/UserInterface/HumanoidProfileEditor.Random.cs +++ b/Content.Client/UserInterface/HumanoidProfileEditor.Random.cs @@ -25,6 +25,7 @@ namespace Content.Client.UserInterface private void RandomizeName() { + if (Profile == null) return; var firstName = _random.Pick(Profile.Sex.FirstNames(_prototypeManager).Values); var lastName = _random.Pick(_prototypeManager.Index("names_last")); SetName($"{firstName} {lastName}"); diff --git a/Content.Client/UserInterface/HumanoidProfileEditor.cs b/Content.Client/UserInterface/HumanoidProfileEditor.cs index 954262b103..1c2df31e34 100644 --- a/Content.Client/UserInterface/HumanoidProfileEditor.cs +++ b/Content.Client/UserInterface/HumanoidProfileEditor.cs @@ -13,9 +13,9 @@ using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.Utility; +using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Enums; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -61,8 +61,9 @@ namespace Content.Client.UserInterface private bool _isDirty; public int CharacterSlot; - public HumanoidCharacterProfile Profile; - public event Action OnProfileChanged; + public HumanoidCharacterProfile? Profile; + + public event Action? OnProfileChanged; public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IPrototypeManager prototypeManager, IEntityManager entityManager) @@ -175,7 +176,7 @@ namespace Content.Client.UserInterface _sexMaleButton.OnPressed += args => { SetSex(Sex.Male); - if (Profile.Gender == Gender.Female) + if (Profile?.Gender == Gender.Female) { SetGender(Gender.Male); UpdateGenderControls(); @@ -187,10 +188,11 @@ namespace Content.Client.UserInterface Text = Loc.GetString("Female"), Group = sexButtonGroup }; - _sexFemaleButton.OnPressed += args => + _sexFemaleButton.OnPressed += _ => { SetSex(Sex.Female); - if (Profile.Gender == Gender.Male) + + if (Profile?.Gender == Gender.Male) { SetGender(Gender.Female); UpdateGenderControls(); @@ -419,7 +421,7 @@ namespace Content.Client.UserInterface { _preferenceUnavailableButton.SelectId(args.Id); - Profile = Profile.WithPreferenceUnavailable((PreferenceUnavailableMode) args.Id); + Profile = Profile?.WithPreferenceUnavailable((PreferenceUnavailableMode) args.Id); IsDirty = true; }; @@ -474,7 +476,7 @@ namespace Content.Client.UserInterface selector.PriorityChanged += priority => { - Profile = Profile.WithJobPriority(job.ID, priority); + Profile = Profile?.WithJobPriority(job.ID, priority); IsDirty = true; foreach (var jobSelector in _jobPriorities) @@ -491,7 +493,7 @@ namespace Content.Client.UserInterface if (jobSelector.Job != selector.Job && jobSelector.Priority == JobPriority.High) { jobSelector.Priority = JobPriority.Medium; - Profile = Profile.WithJobPriority(jobSelector.Job.ID, JobPriority.Medium); + Profile = Profile?.WithJobPriority(jobSelector.Job.ID, JobPriority.Medium); } } } @@ -539,7 +541,7 @@ namespace Content.Client.UserInterface selector.PreferenceChanged += preference => { - Profile = Profile.WithAntagPreference(antag.ID, preference); + Profile = Profile?.WithAntagPreference(antag.ID, preference); IsDirty = true; }; } @@ -664,7 +666,7 @@ namespace Content.Client.UserInterface private void LoadServerData() { - Profile = (HumanoidCharacterProfile) _preferencesManager.Preferences.SelectedCharacter; + Profile = (HumanoidCharacterProfile) _preferencesManager.Preferences!.SelectedCharacter; CharacterSlot = _preferencesManager.Preferences.SelectedCharacterIndex; UpdateControls(); } @@ -708,8 +710,12 @@ namespace Content.Client.UserInterface public void Save() { IsDirty = false; - _preferencesManager.UpdateCharacter(Profile, CharacterSlot); - OnProfileChanged?.Invoke(Profile, CharacterSlot); + + if (Profile != null) + { + _preferencesManager.UpdateCharacter(Profile, CharacterSlot); + OnProfileChanged?.Invoke(Profile, CharacterSlot); + } } private bool IsDirty @@ -733,17 +739,17 @@ namespace Content.Client.UserInterface private void UpdateNameEdit() { - _nameEdit.Text = Profile.Name; + _nameEdit.Text = Profile?.Name ?? ""; } private void UpdateAgeEdit() { - _ageEdit.Text = Profile.Age.ToString(); + _ageEdit.Text = Profile?.Age.ToString() ?? ""; } private void UpdateSexControls() { - if (Profile.Sex == Sex.Male) + if (Profile?.Sex == Sex.Male) _sexMaleButton.Pressed = true; else _sexFemaleButton.Pressed = true; @@ -751,21 +757,41 @@ namespace Content.Client.UserInterface private void UpdateGenderControls() { + if (Profile == null) + { + return; + } + _genderButton.SelectId((int) Profile.Gender); } private void UpdateClothingControls() { + if (Profile == null) + { + return; + } + _clothingButton.SelectId((int) Profile.Clothing); } private void UpdateBackpackControls() { + if (Profile == null) + { + return; + } + _backpackButton.SelectId((int) Profile.Backpack); } private void UpdateHairPickers() { + if (Profile == null) + { + return; + } + _hairPicker.SetData( Profile.Appearance.HairColor, Profile.Appearance.HairStyleName); @@ -776,6 +802,11 @@ namespace Content.Client.UserInterface private void UpdateEyePickers() { + if (Profile == null) + { + return; + } + _eyesPicker.SetData(Profile.Appearance.EyeColor); } @@ -819,7 +850,7 @@ namespace Content.Client.UserInterface { var jobId = prioritySelector.Job.ID; - var priority = Profile.JobPriorities.GetValueOrDefault(jobId, JobPriority.Never); + var priority = Profile?.JobPriorities.GetValueOrDefault(jobId, JobPriority.Never) ?? JobPriority.Never; prioritySelector.Priority = priority; } @@ -836,17 +867,18 @@ namespace Content.Client.UserInterface set => _optionButton.SelectByValue((int) value); } - public event Action PriorityChanged; + public event Action? PriorityChanged; public JobPrioritySelector(JobPrototype job) { Job = job; - _optionButton = new RadioOptions(RadioOptionsLayout.Horizontal); - - _optionButton.FirstButtonStyle = StyleBase.ButtonOpenRight; - _optionButton.ButtonStyle = StyleBase.ButtonOpenBoth; - _optionButton.LastButtonStyle = StyleBase.ButtonOpenLeft; + _optionButton = new RadioOptions(RadioOptionsLayout.Horizontal) + { + FirstButtonStyle = StyleBase.ButtonOpenRight, + ButtonStyle = StyleBase.ButtonOpenBoth, + LastButtonStyle = StyleBase.ButtonOpenLeft + }; // Text, Value _optionButton.AddItem(Loc.GetString("High"), (int) JobPriority.High); @@ -890,8 +922,7 @@ namespace Content.Client.UserInterface foreach (var preferenceSelector in _antagPreferences) { var antagId = preferenceSelector.Antag.ID; - - var preference = Profile.AntagPreferences.Contains(antagId); + var preference = Profile?.AntagPreferences.Contains(antagId) ?? false; preferenceSelector.Preference = preference; } @@ -908,7 +939,7 @@ namespace Content.Client.UserInterface set => _checkBox.Pressed = value; } - public event Action PreferenceChanged; + public event Action? PreferenceChanged; public AntagPreferenceSelector(AntagPrototype antag) { diff --git a/Content.Client/UserInterface/IItemSlotManager.cs b/Content.Client/UserInterface/IItemSlotManager.cs index d61952364b..62495a50d1 100644 --- a/Content.Client/UserInterface/IItemSlotManager.cs +++ b/Content.Client/UserInterface/IItemSlotManager.cs @@ -5,9 +5,9 @@ namespace Content.Client.UserInterface { public interface IItemSlotManager { - bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item); - void UpdateCooldown(ItemSlotButton cooldownTexture, IEntity entity); - bool SetItemSlot(ItemSlotButton button, IEntity entity); - void HoverInSlot(ItemSlotButton button, IEntity entity, bool fits); + bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity? item); + void UpdateCooldown(ItemSlotButton? cooldownTexture, IEntity? entity); + bool SetItemSlot(ItemSlotButton button, IEntity? entity); + void HoverInSlot(ItemSlotButton button, IEntity? entity, bool fits); } } diff --git a/Content.Client/UserInterface/ItemSlotButton.cs b/Content.Client/UserInterface/ItemSlotButton.cs index d9ce11e04a..4985e8f8f3 100644 --- a/Content.Client/UserInterface/ItemSlotButton.cs +++ b/Content.Client/UserInterface/ItemSlotButton.cs @@ -18,12 +18,12 @@ namespace Content.Client.UserInterface public BaseButton StorageButton { get; } public CooldownGraphic CooldownDisplay { get; } - public Action OnPressed { get; set; } - public Action OnStoragePressed { get; set; } - public Action OnHover { get; set; } + public Action? OnPressed { get; set; } + public Action? OnStoragePressed { get; set; } + public Action? OnHover { get; set; } public bool EntityHover => HoverSpriteView.Sprite != null; - public bool MouseIsHovering = false; + public bool MouseIsHovering; private readonly PanelContainer _highlightRect; diff --git a/Content.Client/UserInterface/ItemSlotManager.cs b/Content.Client/UserInterface/ItemSlotManager.cs index ad6725b1eb..437d5036e7 100644 --- a/Content.Client/UserInterface/ItemSlotManager.cs +++ b/Content.Client/UserInterface/ItemSlotManager.cs @@ -27,7 +27,7 @@ namespace Content.Client.UserInterface [Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IMapManager _mapManager = default!; - public bool SetItemSlot(ItemSlotButton button, IEntity entity) + public bool SetItemSlot(ItemSlotButton button, IEntity? entity) { if (entity == null) { @@ -36,7 +36,7 @@ namespace Content.Client.UserInterface } else { - if (!entity.TryGetComponent(out ISpriteComponent sprite)) + if (!entity.TryGetComponent(out ISpriteComponent? sprite)) return false; button.ClearHover(); @@ -46,7 +46,7 @@ namespace Content.Client.UserInterface return true; } - public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item) + public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity? item) { if (item == null) return false; @@ -92,40 +92,36 @@ namespace Content.Client.UserInterface return true; } - public void UpdateCooldown(ItemSlotButton button, IEntity entity) + public void UpdateCooldown(ItemSlotButton? button, IEntity? entity) { - var cooldownDisplay = button.CooldownDisplay; + var cooldownDisplay = button?.CooldownDisplay; - if (entity != null - && entity.TryGetComponent(out ItemCooldownComponent cooldown) - && cooldown.CooldownStart.HasValue - && cooldown.CooldownEnd.HasValue) + if (cooldownDisplay == null) { - var start = cooldown.CooldownStart.Value; - var end = cooldown.CooldownEnd.Value; - - var length = (end - start).TotalSeconds; - var progress = (_gameTiming.CurTime - start).TotalSeconds / length; - var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5); - - cooldownDisplay.Progress = MathHelper.Clamp((float)ratio, -1, 1); - - if (ratio > -1f) - { - cooldownDisplay.Visible = true; - } - else - { - cooldownDisplay.Visible = false; - } + return; } - else + + if (entity == null || + !entity.TryGetComponent(out ItemCooldownComponent? cooldown) || + !cooldown.CooldownStart.HasValue || + !cooldown.CooldownEnd.HasValue) { cooldownDisplay.Visible = false; + return; } + + var start = cooldown.CooldownStart.Value; + var end = cooldown.CooldownEnd.Value; + + var length = (end - start).TotalSeconds; + var progress = (_gameTiming.CurTime - start).TotalSeconds / length; + var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5); + + cooldownDisplay.Progress = MathHelper.Clamp((float) ratio, -1, 1); + cooldownDisplay.Visible = ratio > -1f; } - public void HoverInSlot(ItemSlotButton button, IEntity entity, bool fits) + public void HoverInSlot(ItemSlotButton button, IEntity? entity, bool fits) { if (entity == null || !button.MouseIsHovering) { diff --git a/Content.Client/UserInterface/ItemStatusPanel.cs b/Content.Client/UserInterface/ItemStatusPanel.cs index a7e0c1d495..fca20149d3 100644 --- a/Content.Client/UserInterface/ItemStatusPanel.cs +++ b/Content.Client/UserInterface/ItemStatusPanel.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using Content.Client.GameObjects.Components; diff --git a/Content.Client/UserInterface/LateJoinGui.cs b/Content.Client/UserInterface/LateJoinGui.cs index 8daffbad8e..77009b2b66 100644 --- a/Content.Client/UserInterface/LateJoinGui.cs +++ b/Content.Client/UserInterface/LateJoinGui.cs @@ -24,7 +24,7 @@ namespace Content.Client.UserInterface [Dependency] private readonly IClientConsoleHost _consoleHost = default!; [Dependency] private readonly IClientGameTicker _gameTicker = default!; - public event Action SelectedId; + public event Action? SelectedId; private readonly Dictionary _jobButtons = new(); private readonly Dictionary _jobCategories = new(); @@ -96,10 +96,7 @@ namespace Content.Client.UserInterface jobList.AddChild(category); } - var jobButton = new JobButton - { - JobId = job.ID - }; + var jobButton = new JobButton(job.ID); var jobSelector = new HBoxContainer { @@ -176,9 +173,11 @@ namespace Content.Client.UserInterface class JobButton : ContainerButton { - public string JobId { get; set; } - public JobButton() + public string JobId { get; } + + public JobButton(string jobId) { + JobId = jobId; AddStyleClass(StyleClassButton); } } diff --git a/Content.Client/UserInterface/LobbyCharacterPreviewPanel.cs b/Content.Client/UserInterface/LobbyCharacterPreviewPanel.cs index f01055a7b8..ae2f3b9079 100644 --- a/Content.Client/UserInterface/LobbyCharacterPreviewPanel.cs +++ b/Content.Client/UserInterface/LobbyCharacterPreviewPanel.cs @@ -6,7 +6,6 @@ using Content.Shared.GameTicking; using Content.Shared.Preferences; using Content.Shared.Roles; using Robust.Client.GameObjects; -using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.GameObjects; @@ -15,6 +14,7 @@ using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Prototypes; +using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; namespace Content.Client.UserInterface { @@ -87,7 +87,7 @@ namespace Content.Client.UserInterface if (!disposing) return; _previewDummy.Delete(); - _previewDummy = null; + _previewDummy = null!; } private static SpriteView MakeSpriteView(IEntity entity, Direction direction) @@ -111,7 +111,7 @@ namespace Content.Client.UserInterface { _loaded.Visible = true; _unloaded.Visible = false; - if (_preferencesManager.Preferences.SelectedCharacter is not HumanoidCharacterProfile selectedCharacter) + if (_preferencesManager.Preferences?.SelectedCharacter is not HumanoidCharacterProfile selectedCharacter) { _summaryLabel.Text = string.Empty; } @@ -129,25 +129,29 @@ namespace Content.Client.UserInterface public static void GiveDummyJobClothes(IEntity dummy, HumanoidCharacterProfile profile) { var protoMan = IoCManager.Resolve(); - var entityMan = IoCManager.Resolve(); var inventory = dummy.GetComponent(); var highPriorityJob = profile.JobPriorities.FirstOrDefault(p => p.Value == JobPriority.High).Key; var job = protoMan.Index(highPriorityJob ?? SharedGameTicker.OverflowJob); - var gear = protoMan.Index(job.StartingGear); inventory.ClearAllSlotVisuals(); - foreach (var slot in AllSlots) + if (job.StartingGear != null) { - var itemType = gear.GetGear(slot, profile); - if (itemType != "") + var entityMan = IoCManager.Resolve(); + var gear = protoMan.Index(job.StartingGear); + + foreach (var slot in AllSlots) { - var item = entityMan.SpawnEntity(itemType, MapCoordinates.Nullspace); - inventory.SetSlotVisuals(slot, item); - item.Delete(); + var itemType = gear.GetGear(slot, profile); + if (itemType != "") + { + var item = entityMan.SpawnEntity(itemType, MapCoordinates.Nullspace); + inventory.SetSlotVisuals(slot, item); + item.Delete(); + } } } } diff --git a/Content.Client/UserInterface/NanoHeading.cs b/Content.Client/UserInterface/NanoHeading.cs index baf08ae0ed..636f265879 100644 --- a/Content.Client/UserInterface/NanoHeading.cs +++ b/Content.Client/UserInterface/NanoHeading.cs @@ -23,7 +23,7 @@ namespace Content.Client.UserInterface HorizontalAlignment = HAlignment.Left; } - public string Text + public string? Text { get => _label.Text; set => _label.Text = value; diff --git a/Content.Client/UserInterface/OptionsMenu.Graphics.cs b/Content.Client/UserInterface/OptionsMenu.Graphics.cs index cbeb9b95cb..124debbd78 100644 --- a/Content.Client/UserInterface/OptionsMenu.Graphics.cs +++ b/Content.Client/UserInterface/OptionsMenu.Graphics.cs @@ -97,7 +97,7 @@ namespace Content.Client.UserInterface } }); - contents.AddChild(new Placeholder(resourceCache) + contents.AddChild(new Placeholder() { VerticalExpand = true, PlaceholderText = Loc.GetString("ui-options-placeholder-viewport") diff --git a/Content.Client/UserInterface/OptionsMenu.KeyRebind.cs b/Content.Client/UserInterface/OptionsMenu.KeyRebind.cs index 73265a7b2a..5bd58a2f32 100644 --- a/Content.Client/UserInterface/OptionsMenu.KeyRebind.cs +++ b/Content.Client/UserInterface/OptionsMenu.KeyRebind.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using Content.Client.UserInterface.Stylesheets; using Content.Shared.Input; diff --git a/Content.Client/UserInterface/OptionsMenu.cs b/Content.Client/UserInterface/OptionsMenu.cs index 87152626a7..8bf5eee596 100644 --- a/Content.Client/UserInterface/OptionsMenu.cs +++ b/Content.Client/UserInterface/OptionsMenu.cs @@ -6,8 +6,6 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Maths; -#nullable enable - namespace Content.Client.UserInterface { public sealed partial class OptionsMenu : SS14Window diff --git a/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorBoundUserInterface.cs b/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorBoundUserInterface.cs index 3191291bfd..b1dd582314 100644 --- a/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorBoundUserInterface.cs +++ b/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorBoundUserInterface.cs @@ -1,15 +1,14 @@ using Content.Shared.GameObjects.Components; -using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; -namespace Content.Client.ParticleAccelerator +namespace Content.Client.UserInterface.ParticleAccelerator { public class ParticleAcceleratorBoundUserInterface : BoundUserInterface { - private ParticleAcceleratorControlMenu _menu; + private ParticleAcceleratorControlMenu? _menu; - public ParticleAcceleratorBoundUserInterface([NotNull] ClientUserInterfaceComponent owner, [NotNull] object uiKey) : base(owner, uiKey) + public ParticleAcceleratorBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) { } @@ -39,14 +38,14 @@ namespace Content.Client.ParticleAccelerator protected override void UpdateState(BoundUserInterfaceState state) { - _menu.DataUpdate((ParticleAcceleratorUIState) state); + _menu?.DataUpdate((ParticleAcceleratorUIState) state); } protected override void Dispose(bool disposing) { base.Dispose(disposing); - _menu.Close(); + _menu?.Close(); } } } diff --git a/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorControlMenu.cs b/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorControlMenu.cs index 119a6ab4dd..9148ef4eb9 100644 --- a/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorControlMenu.cs +++ b/Content.Client/UserInterface/ParticleAccelerator/ParticleAcceleratorControlMenu.cs @@ -1,5 +1,4 @@ using System; -using Content.Client.UserInterface; using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.GameObjects.Components; @@ -16,7 +15,7 @@ using Robust.Shared.Noise; using Robust.Shared.Prototypes; using Robust.Shared.Timing; -namespace Content.Client.ParticleAccelerator +namespace Content.Client.UserInterface.ParticleAccelerator { public sealed class ParticleAcceleratorControlMenu : BaseWindow { @@ -101,11 +100,7 @@ namespace Content.Client.ParticleAccelerator MouseFilter = MouseFilterMode.Pass }); - _stateSpinBox = new SpinBox - { - Value = 0, - }; - _stateSpinBox.IsValid = StrengthSpinBoxValid; + _stateSpinBox = new SpinBox {Value = 0, IsValid = StrengthSpinBoxValid,}; _stateSpinBox.InitDefaultButtons(); _stateSpinBox.ValueChanged += PowerStateChanged; _stateSpinBox.LineEditDisabled = true; @@ -336,7 +331,7 @@ namespace Content.Client.ParticleAccelerator return (n >= 0 && n <= 4 && !_blockSpinBox); } - private void PowerStateChanged(object sender, ValueChangedEventArgs e) + private void PowerStateChanged(object? sender, ValueChangedEventArgs e) { ParticleAcceleratorPowerState newState; switch (e.Value) diff --git a/Content.Client/UserInterface/Permissions/PermissionsEui.cs b/Content.Client/UserInterface/Permissions/PermissionsEui.cs index 2988352950..1f979fec7a 100644 --- a/Content.Client/UserInterface/Permissions/PermissionsEui.cs +++ b/Content.Client/UserInterface/Permissions/PermissionsEui.cs @@ -15,8 +15,6 @@ using Robust.Shared.Maths; using Robust.Shared.Utility; using static Content.Shared.Administration.PermissionsEuiMsg; -#nullable enable - namespace Content.Client.UserInterface.Permissions { [UsedImplicitly] diff --git a/Content.Client/UserInterface/Placeholder.cs b/Content.Client/UserInterface/Placeholder.cs index adef4ac728..cff69edcc6 100644 --- a/Content.Client/UserInterface/Placeholder.cs +++ b/Content.Client/UserInterface/Placeholder.cs @@ -1,4 +1,3 @@ -using Robust.Client.ResourceManagement; using Robust.Client.UserInterface.Controls; namespace Content.Client.UserInterface @@ -9,13 +8,13 @@ namespace Content.Client.UserInterface private readonly Label _label; - public string PlaceholderText + public string? PlaceholderText { get => _label.Text; set => _label.Text = value; } - public Placeholder(IResourceCache _resourceCache) + public Placeholder() { _label = new Label { diff --git a/Content.Client/UserInterface/StripeBack.cs b/Content.Client/UserInterface/StripeBack.cs index 2f5d965364..c049176cfa 100644 --- a/Content.Client/UserInterface/StripeBack.cs +++ b/Content.Client/UserInterface/StripeBack.cs @@ -116,9 +116,9 @@ namespace Content.Client.UserInterface GetActualStyleBox()?.Draw(handle, centerBox); } - private StyleBox GetActualStyleBox() + private StyleBox? GetActualStyleBox() { - return TryGetStyleProperty(StylePropertyBackground, out StyleBox box) ? box : null; + return TryGetStyleProperty(StylePropertyBackground, out StyleBox? box) ? box : null; } } } diff --git a/Content.Client/UserInterface/Stylesheets/StylesheetManager.cs b/Content.Client/UserInterface/Stylesheets/StylesheetManager.cs index 60f0eb4978..f4aabf15b7 100644 --- a/Content.Client/UserInterface/Stylesheets/StylesheetManager.cs +++ b/Content.Client/UserInterface/Stylesheets/StylesheetManager.cs @@ -9,8 +9,8 @@ namespace Content.Client.UserInterface.Stylesheets [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; [Dependency] private readonly IResourceCache _resourceCache = default!; - public Stylesheet SheetNano { get; private set; } - public Stylesheet SheetSpace { get; private set; } + public Stylesheet SheetNano { get; private set; } = default!; + public Stylesheet SheetSpace { get; private set; } = default!; public void Initialize() { diff --git a/Content.Client/UserInterface/Suspicion/SuspicionGui.xaml.cs b/Content.Client/UserInterface/Suspicion/SuspicionGui.xaml.cs index 290bd95775..d0c19e40d1 100644 --- a/Content.Client/UserInterface/Suspicion/SuspicionGui.xaml.cs +++ b/Content.Client/UserInterface/Suspicion/SuspicionGui.xaml.cs @@ -16,8 +16,6 @@ using Robust.Shared.Maths; using Robust.Shared.Timing; using static Robust.Client.UserInterface.Controls.BaseButton; -#nullable enable - namespace Content.Client.UserInterface.Suspicion { [GenerateTypedNameReferences] diff --git a/Content.Client/UserInterface/TargetingDoll.cs b/Content.Client/UserInterface/TargetingDoll.cs index db138e3d8b..ebaa682d1c 100644 --- a/Content.Client/UserInterface/TargetingDoll.cs +++ b/Content.Client/UserInterface/TargetingDoll.cs @@ -36,7 +36,7 @@ namespace Content.Client.UserInterface } } - public event Action OnZoneChanged; + public event Action? OnZoneChanged; public TargetingDoll(IResourceCache resourceCache) { diff --git a/Content.Client/Utility/DragDropHelper.cs b/Content.Client/Utility/DragDropHelper.cs index 46c44827b3..d116a9a29f 100644 --- a/Content.Client/Utility/DragDropHelper.cs +++ b/Content.Client/Utility/DragDropHelper.cs @@ -45,7 +45,7 @@ namespace Content.Client.Utility /// /// Current thing being dragged or which mouse button is being held down on. /// - public T Dragged { get; private set; } + public T? Dragged { get; private set; } // screen pos where the mouse down began for the drag private Vector2 _mouseDownScreenPos; diff --git a/Content.Client/Utility/UnobstructedExtensions.cs b/Content.Client/Utility/UnobstructedExtensions.cs index 1fe327078d..b918682501 100644 --- a/Content.Client/Utility/UnobstructedExtensions.cs +++ b/Content.Client/Utility/UnobstructedExtensions.cs @@ -18,7 +18,7 @@ namespace Content.Client.Utility IEntity other, float range = InteractionRange, CollisionGroup collisionMask = CollisionGroup.Impassable, - Ignored predicate = null, + Ignored? predicate = null, bool ignoreInsideBlocker = false, bool popup = false) { @@ -33,7 +33,7 @@ namespace Content.Client.Utility IComponent other, float range = InteractionRange, CollisionGroup collisionMask = CollisionGroup.Impassable, - Ignored predicate = null, + Ignored? predicate = null, bool ignoreInsideBlocker = false, bool popup = false) { @@ -45,7 +45,7 @@ namespace Content.Client.Utility IContainer other, float range = InteractionRange, CollisionGroup collisionMask = CollisionGroup.Impassable, - Ignored predicate = null, + Ignored? predicate = null, bool ignoreInsideBlocker = false, bool popup = false) { @@ -57,7 +57,7 @@ namespace Content.Client.Utility EntityCoordinates other, float range = InteractionRange, CollisionGroup collisionMask = CollisionGroup.Impassable, - Ignored predicate = null, + Ignored? predicate = null, bool ignoreInsideBlocker = false, bool popup = false) { @@ -73,7 +73,7 @@ namespace Content.Client.Utility MapCoordinates other, float range = InteractionRange, CollisionGroup collisionMask = CollisionGroup.Impassable, - Ignored predicate = null, + Ignored? predicate = null, bool ignoreInsideBlocker = false, bool popup = false) { diff --git a/Content.Client/VendingMachines/VendingMachineMenu.cs b/Content.Client/VendingMachines/VendingMachineMenu.cs index 2becd88f38..47702164ea 100644 --- a/Content.Client/VendingMachines/VendingMachineMenu.cs +++ b/Content.Client/VendingMachines/VendingMachineMenu.cs @@ -6,7 +6,6 @@ using Robust.Client.ResourceManagement; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.IoC; -using Robust.Shared.Maths; using Robust.Shared.Prototypes; using static Content.Shared.GameObjects.Components.VendingMachines.SharedVendingMachineComponent; @@ -18,15 +17,17 @@ namespace Content.Client.VendingMachines [Dependency] private readonly IPrototypeManager _prototypeManager = default!; private readonly ItemList _items; - private List _cachedInventory; + private List _cachedInventory = new(); - public VendingMachineBoundUserInterface Owner { get; set; } + public VendingMachineBoundUserInterface Owner { get; } - public VendingMachineMenu() + public VendingMachineMenu(VendingMachineBoundUserInterface owner) { SetSize = MinSize = (300, 450); IoCManager.InjectDependencies(this); + Owner = owner; + _items = new ItemList() { SizeFlagsStretchRatio = 8, @@ -45,10 +46,10 @@ namespace Content.Client.VendingMachines { var itemName = _prototypeManager.Index(entry.ID).Name; - Texture icon = null; - if(_prototypeManager.TryIndex(entry.ID, out EntityPrototype prototype)) + Texture? icon = null; + if(_prototypeManager.TryIndex(entry.ID, out EntityPrototype? prototype)) { - icon = SpriteComponent.GetPrototypeIcon(prototype, _resourceCache)?.Default; + icon = SpriteComponent.GetPrototypeIcon(prototype, _resourceCache).Default; } _items.AddItem($"{itemName} ({entry.Amount} left)", icon); } diff --git a/Content.Shared/GameObjects/Components/Research/SharedResearchConsoleComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedResearchConsoleComponent.cs index 427d57a942..6633d327dd 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedResearchConsoleComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedResearchConsoleComponent.cs @@ -20,6 +20,7 @@ namespace Content.Shared.GameObjects.Components.Research public class ConsoleUnlockTechnologyMessage : BoundUserInterfaceMessage { public string Id; + public ConsoleUnlockTechnologyMessage(string id) { Id = id; diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs index 681ee10333..da4c6ba971 100644 --- a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -164,10 +164,15 @@ namespace Content.Shared.GameObjects.EntitySystems return InRangeUnOccluded(originPos, otherPos, range, predicate, ignoreInsideBlocker); } - public static FormattedMessage GetExamineText(IEntity entity, IEntity examiner) + public static FormattedMessage GetExamineText(IEntity entity, IEntity? examiner) { var message = new FormattedMessage(); + if (examiner == null) + { + return message; + } + var doNewline = false; //Add an entity description if one is declared