2021-12-11 15:12:55 -08:00
|
|
|
using System.Linq;
|
|
|
|
|
using Content.Client.CharacterInfo.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.HUD;
|
2019-07-17 21:37:58 +02:00
|
|
|
using Content.Shared.Input;
|
2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-06-18 01:49:18 -07:00
|
|
|
using Robust.Client.GameObjects;
|
2021-12-11 15:12:55 -08:00
|
|
|
using Robust.Client.Input;
|
2019-07-17 21:37:58 +02:00
|
|
|
using Robust.Client.Player;
|
|
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-05-31 14:32:05 -07:00
|
|
|
using Robust.Shared.Input.Binding;
|
2019-07-17 21:37:58 +02:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.CharacterInterface
|
2019-07-17 21:37:58 +02:00
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
[UsedImplicitly]
|
2019-07-17 21:37:58 +02:00
|
|
|
public sealed class CharacterInterfaceSystem : EntitySystem
|
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IGameHud _gameHud = default!;
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
2021-12-11 15:12:55 -08:00
|
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
2019-07-17 21:37:58 +02:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2020-05-31 14:32:05 -07:00
|
|
|
CommandBinds.Builder
|
|
|
|
|
.Bind(ContentKeyFunctions.OpenCharacterMenu,
|
2021-12-11 15:12:55 -08:00
|
|
|
InputCmdHandler.FromDelegate(_ => HandleOpenCharacterMenu()))
|
2020-05-31 14:32:05 -07:00
|
|
|
.Register<CharacterInterfaceSystem>();
|
2021-06-18 01:49:18 -07:00
|
|
|
|
2021-12-11 15:12:55 -08:00
|
|
|
SubscribeLocalEvent<CharacterInterfaceComponent, ComponentInit>(OnComponentInit);
|
|
|
|
|
SubscribeLocalEvent<CharacterInterfaceComponent, ComponentRemove>(OnComponentRemove);
|
|
|
|
|
SubscribeLocalEvent<CharacterInterfaceComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
|
|
|
|
SubscribeLocalEvent<CharacterInterfaceComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
2020-05-31 14:32:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
CommandBinds.Unregister<CharacterInterfaceSystem>();
|
|
|
|
|
base.Shutdown();
|
2019-07-17 21:37:58 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-11 15:12:55 -08:00
|
|
|
private void OnComponentInit(EntityUid uid, CharacterInterfaceComponent comp, ComponentInit args)
|
2019-07-17 21:37:58 +02:00
|
|
|
{
|
2021-12-11 15:12:55 -08:00
|
|
|
//Use all the character ui interfaced components to create the character window
|
|
|
|
|
comp.UIComponents = EntityManager.GetComponents<ICharacterUI>(uid).ToList();
|
|
|
|
|
if (comp.UIComponents.Count == 0)
|
2019-07-17 21:37:58 +02:00
|
|
|
return;
|
2021-12-11 15:12:55 -08:00
|
|
|
|
2021-12-20 22:30:12 -03:00
|
|
|
comp.Window = new CharacterInterfaceComponent.CharacterWindow(comp.UIComponents)
|
|
|
|
|
{
|
|
|
|
|
SetSize = (545, 400)
|
|
|
|
|
};
|
2022-01-21 01:38:35 -08:00
|
|
|
|
2021-12-11 15:12:55 -08:00
|
|
|
comp.Window.OnClose += () => _gameHud.CharacterButtonDown = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnComponentRemove(EntityUid uid, CharacterInterfaceComponent comp, ComponentRemove args)
|
|
|
|
|
{
|
|
|
|
|
if (comp.UIComponents != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var component in comp.UIComponents)
|
|
|
|
|
{
|
|
|
|
|
// Make sure these don't get deleted when the window is disposed.
|
|
|
|
|
component.Scene.Orphan();
|
|
|
|
|
}
|
2019-07-17 21:37:58 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-11 15:12:55 -08:00
|
|
|
comp.UIComponents = null;
|
2019-07-17 21:37:58 +02:00
|
|
|
|
2021-12-11 15:12:55 -08:00
|
|
|
comp.Window?.Close();
|
|
|
|
|
comp.Window = null;
|
|
|
|
|
|
|
|
|
|
_inputManager.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPlayerAttached(EntityUid uid, CharacterInterfaceComponent comp, PlayerAttachedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (comp.Window == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_gameHud.CharacterButtonVisible = true;
|
|
|
|
|
_gameHud.CharacterButtonToggled = b =>
|
2019-07-19 11:15:33 +02:00
|
|
|
{
|
2021-12-11 15:12:55 -08:00
|
|
|
if (b)
|
|
|
|
|
comp.Window.OpenCentered();
|
|
|
|
|
else
|
|
|
|
|
comp.Window.Close();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPlayerDetached(EntityUid uid, CharacterInterfaceComponent comp, PlayerDetachedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (comp.Window == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_gameHud.CharacterButtonVisible = false;
|
|
|
|
|
comp.Window.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleOpenCharacterMenu()
|
|
|
|
|
{
|
|
|
|
|
if (_playerManager.LocalPlayer?.ControlledEntity == null
|
|
|
|
|
|| !EntityManager.TryGetComponent(_playerManager.LocalPlayer.ControlledEntity, out CharacterInterfaceComponent? characterInterface))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var menu = characterInterface.Window;
|
|
|
|
|
if (menu == null)
|
2019-07-19 11:15:33 +02:00
|
|
|
return;
|
|
|
|
|
|
2019-07-18 22:49:49 +02:00
|
|
|
if (menu.IsOpen)
|
2019-07-17 21:37:58 +02:00
|
|
|
{
|
|
|
|
|
if (menu.IsAtFront())
|
|
|
|
|
_setOpenValue(menu, false);
|
|
|
|
|
else
|
|
|
|
|
menu.MoveToFront();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_setOpenValue(menu, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-21 01:38:35 -08:00
|
|
|
private void _setOpenValue(DefaultWindow menu, bool value)
|
2019-07-17 21:37:58 +02:00
|
|
|
{
|
2021-12-11 15:12:55 -08:00
|
|
|
_gameHud.CharacterButtonDown = value;
|
2019-07-17 21:37:58 +02:00
|
|
|
if (value)
|
|
|
|
|
menu.OpenCentered();
|
|
|
|
|
else
|
|
|
|
|
menu.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|