diff --git a/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs b/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs
index 426bc27c72..74a99c7669 100644
--- a/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs
+++ b/Content.Client/GameObjects/Components/Actor/CharacterInterface.cs
@@ -28,8 +28,11 @@ namespace Content.Client.GameObjects.Components.Actor
#pragma warning restore 649
///
- /// Window to hold each of the character interfaces
+ /// Window to hold each of the character interfaces
///
+ ///
+ /// Null if it would otherwise be empty.
+ ///
public SS14Window Window { get; private set; }
///
@@ -40,7 +43,12 @@ namespace Content.Client.GameObjects.Components.Actor
base.Initialize();
//Use all the character ui interfaced components to create the character window
- var uiComponents = Owner.GetAllComponents();
+ var uiComponents = Owner.GetAllComponents().ToList();
+ if (uiComponents.Count == 0)
+ {
+ return;
+ }
+
Window = new CharacterWindow(uiComponents);
Window.OnClose += () => _gameHud.CharacterButtonDown = false;
}
@@ -52,36 +60,45 @@ namespace Content.Client.GameObjects.Components.Actor
{
base.OnRemove();
- Window.Dispose();
+ Window?.Dispose();
Window = null;
var inputMgr = IoCManager.Resolve();
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
}
- public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
+ public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null,
+ IComponent component = null)
{
base.HandleMessage(message, netChannel, component);
switch (message)
{
- case PlayerAttachedMsg playerAttachedMsg:
- _gameHud.CharacterButtonVisible = true;
- _gameHud.CharacterButtonToggled = b =>
+ case PlayerAttachedMsg _:
+ if (Window != null)
{
- if (b)
+ _gameHud.CharacterButtonVisible = true;
+ _gameHud.CharacterButtonToggled = b =>
{
- Window.Open();
- }
- else
- {
- Window.Close();
- }
- };
+ if (b)
+ {
+ Window.Open();
+ }
+ else
+ {
+ Window.Close();
+ }
+ };
+ }
+
break;
- case PlayerDetachedMsg playerDetachedMsg:
- _gameHud.CharacterButtonVisible = false;
+ case PlayerDetachedMsg _:
+ if (Window != null)
+ {
+ _gameHud.CharacterButtonVisible = false;
+ }
+
break;
}
}
@@ -93,7 +110,7 @@ namespace Content.Client.GameObjects.Components.Actor
{
private readonly VBoxContainer _contentsVBox;
- public CharacterWindow(IEnumerable windowComponents)
+ public CharacterWindow(List windowComponents)
{
Title = "Character";
Visible = false;
@@ -101,8 +118,8 @@ namespace Content.Client.GameObjects.Components.Actor
_contentsVBox = new VBoxContainer();
Contents.AddChild(_contentsVBox);
- // TODO: sort window components by priority of window component
- foreach (var element in windowComponents.OrderBy(x => x.Priority))
+ windowComponents.Sort((a, b) => ((int) a.Priority).CompareTo((int) b.Priority));
+ foreach (var element in windowComponents)
{
_contentsVBox.AddChild(element.Scene);
}
diff --git a/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs b/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs
index ebf5c89129..76334986d0 100644
--- a/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs
+++ b/Content.Client/GameObjects/EntitySystems/CharacterInterfaceSystem.cs
@@ -36,6 +36,11 @@ namespace Content.Client.GameObjects.EntitySystems
var menu = characterInterface.Window;
+ if (menu == null)
+ {
+ return;
+ }
+
if (menu.IsOpen)
{
if (menu.IsAtFront())