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;
|
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!;
|
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,
|
|
|
|
|
InputCmdHandler.FromDelegate(s => HandleOpenCharacterMenu()))
|
|
|
|
|
.Register<CharacterInterfaceSystem>();
|
2021-06-18 01:49:18 -07:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<CharacterInterfaceComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
|
|
|
|
|
SubscribeLocalEvent<CharacterInterfaceComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
|
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
|
|
|
}
|
|
|
|
|
|
2019-07-20 13:11:42 +02:00
|
|
|
private void HandleOpenCharacterMenu()
|
2019-07-17 21:37:58 +02:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
if (_playerManager.LocalPlayer?.ControlledEntity == null
|
2021-06-09 22:19:39 +02:00
|
|
|
|| !_playerManager.LocalPlayer.ControlledEntity.TryGetComponent(out CharacterInterfaceComponent? characterInterface))
|
2019-07-17 21:37:58 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var menu = characterInterface.Window;
|
|
|
|
|
|
2019-07-19 11:15:33 +02:00
|
|
|
if (menu == null)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void _setOpenValue(SS14Window menu, bool value)
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
_gameHud.CharacterButtonDown = true;
|
|
|
|
|
menu.OpenCentered();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_gameHud.CharacterButtonDown = false;
|
|
|
|
|
menu.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|