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

@@ -30,6 +30,9 @@ namespace Content.Client.GameObjects.Components.Actor
/// <summary>
/// Window to hold each of the character interfaces
/// </summary>
/// <remarks>
/// Null if it would otherwise be empty.
/// </remarks>
public SS14Window Window { get; private set; }
/// <summary>
@@ -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<ICharacterUI>();
var uiComponents = Owner.GetAllComponents<ICharacterUI>().ToList();
if (uiComponents.Count == 0)
{
return;
}
Window = new CharacterWindow(uiComponents);
Window.OnClose += () => _gameHud.CharacterButtonDown = false;
}
@@ -52,20 +60,23 @@ namespace Content.Client.GameObjects.Components.Actor
{
base.OnRemove();
Window.Dispose();
Window?.Dispose();
Window = null;
var inputMgr = IoCManager.Resolve<IInputManager>();
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:
case PlayerAttachedMsg _:
if (Window != null)
{
_gameHud.CharacterButtonVisible = true;
_gameHud.CharacterButtonToggled = b =>
{
@@ -78,10 +89,16 @@ namespace Content.Client.GameObjects.Components.Actor
Window.Close();
}
};
}
break;
case PlayerDetachedMsg playerDetachedMsg:
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<ICharacterUI> windowComponents)
public CharacterWindow(List<ICharacterUI> 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);
}

View File

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