2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.HUD;
|
2021-10-24 23:43:49 -07:00
|
|
|
using Content.Client.Items.Components;
|
2019-07-20 13:11:42 +02:00
|
|
|
using Content.Shared.Input;
|
2021-10-24 23:43:49 -07:00
|
|
|
using Content.Shared.Inventory;
|
2021-11-07 22:17:35 -07:00
|
|
|
using Content.Shared.Movement.EntitySystems;
|
2021-10-24 23:43:49 -07:00
|
|
|
using Content.Shared.Slippery;
|
2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-06-18 01:49:18 -07:00
|
|
|
using Robust.Client.GameObjects;
|
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-20 13:11:42 +02:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Inventory
|
2019-07-20 13:11:42 +02:00
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
[UsedImplicitly]
|
2019-07-20 13:11:42 +02:00
|
|
|
public sealed class ClientInventorySystem : EntitySystem
|
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IGameHud _gameHud = default!;
|
2019-07-20 13:11:42 +02:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2020-05-31 14:32:05 -07:00
|
|
|
CommandBinds.Builder
|
|
|
|
|
.Bind(ContentKeyFunctions.OpenInventoryMenu,
|
2021-03-10 14:48:29 +01:00
|
|
|
InputCmdHandler.FromDelegate(_ => HandleOpenInventoryMenu()))
|
2020-05-31 14:32:05 -07:00
|
|
|
.Register<ClientInventorySystem>();
|
2021-06-18 01:49:18 -07:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ClientInventoryComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
|
|
|
|
|
SubscribeLocalEvent<ClientInventoryComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
|
2021-10-24 23:43:49 -07:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ClientInventoryComponent, SlipAttemptEvent>(OnSlipAttemptEvent);
|
2021-11-07 22:17:35 -07:00
|
|
|
SubscribeLocalEvent<ClientInventoryComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
2021-10-24 23:43:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// jesus christ, this is duplicated to server/client, should really just be shared..
|
|
|
|
|
private void OnSlipAttemptEvent(EntityUid uid, ClientInventoryComponent component, SlipAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (component.TryGetSlot(EquipmentSlotDefines.Slots.SHOES, out IEntity? shoes))
|
|
|
|
|
{
|
|
|
|
|
RaiseLocalEvent(shoes.Uid, args, false);
|
|
|
|
|
}
|
2020-05-31 14:32:05 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-07 22:17:35 -07:00
|
|
|
private void OnRefreshMovespeed(EntityUid uid, ClientInventoryComponent component, RefreshMovementSpeedModifiersEvent args)
|
|
|
|
|
{
|
|
|
|
|
foreach (var (_, ent) in component.AllSlots)
|
|
|
|
|
{
|
|
|
|
|
if (ent != null)
|
|
|
|
|
{
|
|
|
|
|
RaiseLocalEvent(ent.Uid, args, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 14:32:05 -07:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
CommandBinds.Unregister<ClientInventorySystem>();
|
|
|
|
|
base.Shutdown();
|
2019-07-20 13:11:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleOpenInventoryMenu()
|
|
|
|
|
{
|
2021-03-26 10:23:12 -05:00
|
|
|
_gameHud.InventoryButtonDown = !_gameHud.InventoryButtonDown;
|
2019-07-20 13:11:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|