using Content.Client.GameObjects.Components.Mobs;
using Content.Shared.Input;
using SS14.Client.Interfaces.Input;
using SS14.Client.UserInterface.CustomControls;
using SS14.Shared.GameObjects;
using SS14.Shared.Input;
using SS14.Shared.IoC;
using SS14.Shared.Utility;
using System.Collections.Generic;
using System.Linq;
namespace Content.Client.GameObjects.Components.Actor
{
///
/// A semi-abstract component which gets added to entities upon attachment and collects all character
/// user interfaces into a single window and keybind for the user
///
public class CharacterInterface : Component
{
public override string Name => "Character Interface Component";
///
/// Stored keybind to open the menu on keypress
///
private InputCmdHandler _openMenuCmdHandler;
///
/// Window to hold each of the character interfaces
///
private SS14Window _window;
///
/// Create the window with all character UIs and bind it to a keypress
///
public override void Initialize()
{
base.Initialize();
//Use all the character ui interfaced components to create the character window
var UIcomponents = Owner.GetAllComponents();
_window = new CharacterWindow(UIcomponents);
//Add to screen the window and hide it
_window.AddToScreen();
_window.Close();
//Toggle window visible/invisible on keypress
_openMenuCmdHandler = InputCmdHandler.FromDelegate(session => {
if (_window.Visible)
{
_window.Close();
}
else
{
_window.Open();
}
});
//Set keybind to open character menu
var inputMgr = IoCManager.Resolve();
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, _openMenuCmdHandler);
}
///
/// Dispose of window and the keypress binding
///
public override void OnRemove()
{
base.OnRemove();
_window.Dispose();
_window = null;
var inputMgr = IoCManager.Resolve();
inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
}
///
/// A window that collects and shows all the individual character user interfaces
///
public class CharacterWindow : SS14Window
{
protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Mobs/CharacterWindow.tscn");
public CharacterWindow(IEnumerable windowcomponents)
{
//TODO: sort window components by priority of window component
foreach(var element in windowcomponents.OrderByDescending(x => x.Priority))
{
Contents.AddChild(element.Scene);
}
HideOnClose = true;
}
}
}
///
/// Determines ordering of the character user interface, small values come sooner
///
public enum UIPriority
{
First = 0,
Species = 100,
Inventory = 200,
Last = 99999
}
}