Do not show character interface for observers.

This commit is contained in:
Pieter-Jan Briers
2019-07-19 11:15:33 +02:00
parent 14d538997e
commit c0717ed6a3
2 changed files with 42 additions and 20 deletions

View File

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

View File

@@ -36,6 +36,11 @@ namespace Content.Client.GameObjects.EntitySystems
var menu = characterInterface.Window; var menu = characterInterface.Window;
if (menu == null)
{
return;
}
if (menu.IsOpen) if (menu.IsOpen)
{ {
if (menu.IsAtFront()) if (menu.IsAtFront())