2020-01-17 06:43:20 -08:00
|
|
|
|
using Content.Client.GameObjects;
|
2018-04-22 06:11:38 -05:00
|
|
|
|
using Content.Client.Interfaces.GameObjects;
|
2019-07-20 16:01:01 +02:00
|
|
|
|
using Content.Client.Utility;
|
2019-08-04 16:03:51 -07:00
|
|
|
|
using Content.Shared.Input;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Client.Interfaces.GameObjects.Components;
|
|
|
|
|
|
using Robust.Client.Interfaces.ResourceManagement;
|
|
|
|
|
|
using Robust.Client.Player;
|
|
|
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2020-05-10 22:48:14 -07:00
|
|
|
|
using Robust.Shared.Input;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
2019-11-12 01:43:11 +01:00
|
|
|
|
using Robust.Shared.Timing;
|
2017-09-30 16:56:19 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.UserInterface
|
|
|
|
|
|
{
|
2018-05-13 11:54:21 +02:00
|
|
|
|
public class HandsGui : Control
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2020-01-09 00:27:52 +01:00
|
|
|
|
private const string HandNameLeft = "left";
|
|
|
|
|
|
private const string HandNameRight = "right";
|
|
|
|
|
|
|
2019-07-20 16:01:01 +02:00
|
|
|
|
#pragma warning disable 0649
|
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager;
|
|
|
|
|
|
[Dependency] private readonly IResourceCache _resourceCache;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
[Dependency] private readonly IItemSlotManager _itemSlotManager;
|
2019-07-20 16:01:01 +02:00
|
|
|
|
#pragma warning restore 0649
|
2018-11-21 20:58:11 +01:00
|
|
|
|
|
2020-01-17 18:41:47 -08:00
|
|
|
|
private IEntity _leftHand;
|
|
|
|
|
|
private IEntity _rightHand;
|
2017-09-30 16:56:19 +02:00
|
|
|
|
|
2019-08-14 22:04:35 +02:00
|
|
|
|
private readonly TextureRect ActiveHandRect;
|
2019-03-15 19:07:29 +01:00
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
private readonly ItemSlotButton _leftButton;
|
|
|
|
|
|
private readonly ItemSlotButton _rightButton;
|
2019-12-05 16:00:03 +01:00
|
|
|
|
|
2020-01-09 00:27:52 +01:00
|
|
|
|
private readonly ItemStatusPanel _rightStatusPanel;
|
|
|
|
|
|
private readonly ItemStatusPanel _leftStatusPanel;
|
|
|
|
|
|
|
2019-08-14 22:04:35 +02:00
|
|
|
|
public HandsGui()
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2019-07-20 16:01:01 +02:00
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
var textureHandLeft = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/hand_l.png");
|
|
|
|
|
|
var textureHandRight = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/hand_r.png");
|
|
|
|
|
|
var textureHandActive = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/hand_active.png");
|
|
|
|
|
|
var storageTexture = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/back.png");
|
2019-11-12 01:43:11 +01:00
|
|
|
|
|
2020-01-09 00:27:52 +01:00
|
|
|
|
_rightStatusPanel = new ItemStatusPanel(true);
|
|
|
|
|
|
_leftStatusPanel = new ItemStatusPanel(false);
|
|
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
_leftButton = new ItemSlotButton(textureHandLeft, storageTexture);
|
|
|
|
|
|
_rightButton = new ItemSlotButton(textureHandRight, storageTexture);
|
2019-12-05 16:00:03 +01:00
|
|
|
|
var hBox = new HBoxContainer
|
|
|
|
|
|
{
|
|
|
|
|
|
SeparationOverride = 0,
|
2020-02-20 01:21:23 -08:00
|
|
|
|
Children = {_rightStatusPanel, _rightButton, _leftButton, _leftStatusPanel}
|
2019-12-05 16:00:03 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
AddChild(hBox);
|
|
|
|
|
|
|
2020-05-05 23:59:31 +02:00
|
|
|
|
_leftButton.OnPressed += args => HandKeyBindDown(args, HandNameLeft);
|
|
|
|
|
|
_leftButton.OnStoragePressed += args => _OnStoragePressed(args, HandNameLeft);
|
|
|
|
|
|
_rightButton.OnPressed += args => HandKeyBindDown(args, HandNameRight);
|
|
|
|
|
|
_rightButton.OnStoragePressed += args => _OnStoragePressed(args, HandNameRight);
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
// Active hand
|
|
|
|
|
|
_leftButton.AddChild(ActiveHandRect = new TextureRect
|
2019-07-20 16:01:01 +02:00
|
|
|
|
{
|
2020-01-17 06:43:20 -08:00
|
|
|
|
Texture = textureHandActive,
|
2019-07-20 16:01:01 +02:00
|
|
|
|
TextureScale = (2, 2)
|
|
|
|
|
|
});
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-22 06:11:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the hands component controling this gui, returns true if successful and false if failure
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="hands"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private bool TryGetHands(out IHandsComponent hands)
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2019-07-20 16:01:01 +02:00
|
|
|
|
hands = default;
|
2017-09-30 16:56:19 +02:00
|
|
|
|
|
2019-07-20 16:01:01 +02:00
|
|
|
|
var entity = _playerManager?.LocalPlayer?.ControlledEntity;
|
|
|
|
|
|
return entity != null && entity.TryGetComponent(out hands);
|
2018-04-22 06:11:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateHandIcons()
|
|
|
|
|
|
{
|
2018-09-19 18:54:04 +02:00
|
|
|
|
if (Parent == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-11-21 20:58:11 +01:00
|
|
|
|
|
2018-04-22 06:11:38 -05:00
|
|
|
|
UpdateDraw();
|
|
|
|
|
|
|
2019-03-15 19:07:29 +01:00
|
|
|
|
if (!TryGetHands(out var hands))
|
2018-04-22 06:11:38 -05:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-01-09 00:27:52 +01:00
|
|
|
|
var left = hands.GetEntity(HandNameLeft);
|
|
|
|
|
|
var right = hands.GetEntity(HandNameRight);
|
2017-09-30 16:56:19 +02:00
|
|
|
|
|
2019-12-05 16:00:03 +01:00
|
|
|
|
ActiveHandRect.Parent.RemoveChild(ActiveHandRect);
|
2020-01-17 06:43:20 -08:00
|
|
|
|
var parent = hands.ActiveIndex == HandNameLeft ? _leftButton : _rightButton;
|
2019-12-05 16:00:03 +01:00
|
|
|
|
parent.AddChild(ActiveHandRect);
|
2020-01-09 00:27:52 +01:00
|
|
|
|
ActiveHandRect.SetPositionInParent(1);
|
2019-07-20 16:01:01 +02:00
|
|
|
|
|
2020-01-17 18:41:47 -08:00
|
|
|
|
if (left != _leftHand)
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2020-01-17 18:41:47 -08:00
|
|
|
|
_leftHand = left;
|
|
|
|
|
|
_itemSlotManager.SetItemSlot(_leftButton, _leftHand);
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-17 18:41:47 -08:00
|
|
|
|
if (right != _rightHand)
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2020-01-17 18:41:47 -08:00
|
|
|
|
_rightHand = right;
|
|
|
|
|
|
_itemSlotManager.SetItemSlot(_rightButton, _rightHand);
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
private void HandKeyBindDown(GUIBoundKeyEventArgs args, string handIndex)
|
2018-04-22 06:11:38 -05:00
|
|
|
|
{
|
2018-11-21 20:58:11 +01:00
|
|
|
|
if (!TryGetHands(out var hands))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
if (args.Function == ContentKeyFunctions.MouseMiddle)
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2020-01-17 06:43:20 -08:00
|
|
|
|
hands.SendChangeHand(handIndex);
|
2020-05-11 11:19:41 +02:00
|
|
|
|
args.Handle();
|
2020-01-17 06:43:20 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2018-04-22 06:11:38 -05:00
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
var entity = hands.GetEntity(handIndex);
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
|
{
|
2020-05-10 22:48:14 -07:00
|
|
|
|
if (args.Function == EngineKeyFunctions.UIClick && hands.ActiveIndex != handIndex)
|
2018-11-21 20:58:11 +01:00
|
|
|
|
{
|
2020-01-17 06:43:20 -08:00
|
|
|
|
hands.SendChangeHand(handIndex);
|
2020-05-11 11:19:41 +02:00
|
|
|
|
args.Handle();
|
2018-11-21 20:58:11 +01:00
|
|
|
|
}
|
2020-01-17 06:43:20 -08:00
|
|
|
|
return;
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
2020-01-17 06:43:20 -08:00
|
|
|
|
|
|
|
|
|
|
if (_itemSlotManager.OnButtonPressed(args, entity))
|
2020-05-11 11:19:41 +02:00
|
|
|
|
{
|
|
|
|
|
|
args.Handle();
|
2020-01-17 06:43:20 -08:00
|
|
|
|
return;
|
2020-05-11 11:19:41 +02:00
|
|
|
|
}
|
2020-01-17 06:43:20 -08:00
|
|
|
|
|
2020-05-10 22:48:14 -07:00
|
|
|
|
if (args.Function == EngineKeyFunctions.UIClick)
|
2017-09-30 16:56:19 +02:00
|
|
|
|
{
|
2020-01-17 06:43:20 -08:00
|
|
|
|
if (hands.ActiveIndex == handIndex)
|
2018-04-22 06:11:38 -05:00
|
|
|
|
{
|
2020-01-17 06:43:20 -08:00
|
|
|
|
hands.UseActiveHand();
|
2018-04-22 06:11:38 -05:00
|
|
|
|
}
|
2020-01-17 06:43:20 -08:00
|
|
|
|
else
|
2018-04-22 06:11:38 -05:00
|
|
|
|
{
|
2020-01-17 06:43:20 -08:00
|
|
|
|
hands.AttackByInHand(handIndex);
|
2018-04-22 06:11:38 -05:00
|
|
|
|
}
|
2020-05-11 11:19:41 +02:00
|
|
|
|
args.Handle();
|
2020-01-17 06:43:20 -08:00
|
|
|
|
return;
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-12 01:43:11 +01:00
|
|
|
|
|
2020-01-17 18:41:47 -08:00
|
|
|
|
private void _OnStoragePressed(GUIBoundKeyEventArgs args, string handIndex)
|
|
|
|
|
|
{
|
2020-05-10 22:48:14 -07:00
|
|
|
|
if (args.Function != EngineKeyFunctions.UIClick)
|
2020-01-17 18:41:47 -08:00
|
|
|
|
return;
|
|
|
|
|
|
if (!TryGetHands(out var hands))
|
|
|
|
|
|
return;
|
|
|
|
|
|
hands.ActivateItemInHand(handIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-12 01:43:11 +01:00
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.FrameUpdate(args);
|
|
|
|
|
|
|
2020-01-17 18:41:47 -08:00
|
|
|
|
_itemSlotManager.UpdateCooldown(_leftButton, _leftHand);
|
|
|
|
|
|
_itemSlotManager.UpdateCooldown(_rightButton, _rightHand);
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
2020-01-17 18:41:47 -08:00
|
|
|
|
_rightStatusPanel.Update(_rightHand);
|
|
|
|
|
|
_leftStatusPanel.Update(_leftHand);
|
2019-11-12 01:43:11 +01:00
|
|
|
|
}
|
2017-09-30 16:56:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|