Implement StorageButton on HandsGUI and click empty hand to swap… (#517)
Also moved duplicate sprite view code to ItemSlotManager
This commit is contained in:
committed by
Pieter-Jan Briers
parent
9a76c70b37
commit
e0aaab56e3
@@ -1,12 +1,7 @@
|
|||||||
// Only unused on .NET Core due to KeyValuePair.Deconstruct
|
// Only unused on .NET Core due to KeyValuePair.Deconstruct
|
||||||
// ReSharper disable once RedundantUsingDirective
|
// ReSharper disable once RedundantUsingDirective
|
||||||
using Robust.Shared.Utility;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Content.Client.GameObjects.Components.Storage;
|
|
||||||
using Content.Client.Utility;
|
using Content.Client.Utility;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.Interfaces.GameObjects.Components;
|
|
||||||
using Robust.Client.Interfaces.ResourceManagement;
|
using Robust.Client.Interfaces.ResourceManagement;
|
||||||
using Robust.Client.UserInterface;
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
@@ -16,8 +11,8 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
||||||
using Robust.Client.Interfaces.Graphics.ClientEye;
|
|
||||||
using Content.Client.UserInterface;
|
using Content.Client.UserInterface;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Content.Client.GameObjects
|
namespace Content.Client.GameObjects
|
||||||
{
|
{
|
||||||
@@ -29,7 +24,6 @@ namespace Content.Client.GameObjects
|
|||||||
[Dependency] private readonly ILocalizationManager _loc;
|
[Dependency] private readonly ILocalizationManager _loc;
|
||||||
[Dependency] private readonly IResourceCache _resourceCache;
|
[Dependency] private readonly IResourceCache _resourceCache;
|
||||||
[Dependency] private readonly IItemSlotManager _itemSlotManager;
|
[Dependency] private readonly IItemSlotManager _itemSlotManager;
|
||||||
[Dependency] private readonly IEyeManager _eyeManager;
|
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
private readonly Dictionary<Slots, List<ItemSlotButton>> _inventoryButtons
|
private readonly Dictionary<Slots, List<ItemSlotButton>> _inventoryButtons
|
||||||
@@ -98,18 +92,12 @@ namespace Content.Client.GameObjects
|
|||||||
base.AddToSlot(slot, entity);
|
base.AddToSlot(slot, entity);
|
||||||
|
|
||||||
if (!_inventoryButtons.TryGetValue(slot, out var buttons))
|
if (!_inventoryButtons.TryGetValue(slot, out var buttons))
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
entity.TryGetComponent(out ISpriteComponent sprite);
|
|
||||||
var hasInventory = entity.HasComponent<ClientStorageComponent>();
|
|
||||||
|
|
||||||
foreach (var button in buttons)
|
foreach (var button in buttons)
|
||||||
{
|
{
|
||||||
button.SpriteView.Sprite = sprite;
|
_itemSlotManager.SetItemSlot(button, entity);
|
||||||
button.OnPressed = (e) => HandleInventoryKeybind(e, slot);
|
button.OnPressed = (e) => HandleInventoryKeybind(e, slot);
|
||||||
button.StorageButton.Visible = hasInventory;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +120,6 @@ namespace Content.Client.GameObjects
|
|||||||
{
|
{
|
||||||
if (!_inventoryButtons.TryGetValue(slot, out var buttons))
|
if (!_inventoryButtons.TryGetValue(slot, out var buttons))
|
||||||
return;
|
return;
|
||||||
var mousePosWorld = _eyeManager.ScreenToWorld(args.Event.PointerLocation);
|
|
||||||
if (!Owner.TryGetSlot(slot, out var item))
|
if (!Owner.TryGetSlot(slot, out var item))
|
||||||
return;
|
return;
|
||||||
if (_itemSlotManager.OnButtonPressed(args.Event, item))
|
if (_itemSlotManager.OnButtonPressed(args.Event, item))
|
||||||
@@ -143,9 +130,8 @@ namespace Content.Client.GameObjects
|
|||||||
|
|
||||||
private void ClearButton(ItemSlotButton button, Slots slot)
|
private void ClearButton(ItemSlotButton button, Slots slot)
|
||||||
{
|
{
|
||||||
button.SpriteView.Sprite = null;
|
|
||||||
button.OnPressed = (e) => AddToInventory(e, slot);
|
button.OnPressed = (e) => AddToInventory(e, slot);
|
||||||
button.StorageButton.Visible = false;
|
_itemSlotManager.SetItemSlot(button, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PlayerAttached()
|
public override void PlayerAttached()
|
||||||
@@ -161,7 +147,6 @@ namespace Content.Client.GameObjects
|
|||||||
|
|
||||||
_gameHud.InventoryQuickButtonContainer.RemoveChild(_quickButtonsContainer);
|
_gameHud.InventoryQuickButtonContainer.RemoveChild(_quickButtonsContainer);
|
||||||
|
|
||||||
//foreach (var button in _inventoryButtons.Values.SelectMany(l => l))
|
|
||||||
foreach (var (slot, list) in _inventoryButtons)
|
foreach (var (slot, list) in _inventoryButtons)
|
||||||
{
|
{
|
||||||
foreach (var button in list)
|
foreach (var button in list)
|
||||||
|
|||||||
@@ -185,8 +185,15 @@ namespace Content.Client.GameObjects
|
|||||||
{
|
{
|
||||||
if (GetEntity(ActiveIndex) != null)
|
if (GetEntity(ActiveIndex) != null)
|
||||||
{
|
{
|
||||||
SendNetworkMessage(new ActivateInhandMsg());
|
SendNetworkMessage(new UseInHandMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ActivateItemInHand(string handIndex)
|
||||||
|
{
|
||||||
|
if (GetEntity(handIndex) == null)
|
||||||
|
return;
|
||||||
|
SendNetworkMessage(new ActivateInHandMsg(handIndex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ namespace Content.Client.Interfaces.GameObjects
|
|||||||
void SendChangeHand(string index);
|
void SendChangeHand(string index);
|
||||||
void AttackByInHand(string index);
|
void AttackByInHand(string index);
|
||||||
void UseActiveHand();
|
void UseActiveHand();
|
||||||
|
void ActivateItemInHand(string handIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ namespace Content.Client.UserInterface
|
|||||||
[Dependency] private readonly IItemSlotManager _itemSlotManager;
|
[Dependency] private readonly IItemSlotManager _itemSlotManager;
|
||||||
#pragma warning restore 0649
|
#pragma warning restore 0649
|
||||||
|
|
||||||
private IEntity LeftHand;
|
private IEntity _leftHand;
|
||||||
private IEntity RightHand;
|
private IEntity _rightHand;
|
||||||
|
|
||||||
private readonly TextureRect ActiveHandRect;
|
private readonly TextureRect ActiveHandRect;
|
||||||
|
|
||||||
@@ -61,7 +61,9 @@ namespace Content.Client.UserInterface
|
|||||||
AddChild(hBox);
|
AddChild(hBox);
|
||||||
|
|
||||||
_leftButton.OnPressed += args => HandKeyBindDown(args.Event, HandNameLeft);
|
_leftButton.OnPressed += args => HandKeyBindDown(args.Event, HandNameLeft);
|
||||||
|
_leftButton.OnStoragePressed += args => _OnStoragePressed(args.Event, HandNameLeft);
|
||||||
_rightButton.OnPressed += args => HandKeyBindDown(args.Event, HandNameRight);
|
_rightButton.OnPressed += args => HandKeyBindDown(args.Event, HandNameRight);
|
||||||
|
_rightButton.OnStoragePressed += args => _OnStoragePressed(args.Event, HandNameRight);
|
||||||
|
|
||||||
// Active hand
|
// Active hand
|
||||||
_leftButton.AddChild(ActiveHandRect = new TextureRect
|
_leftButton.AddChild(ActiveHandRect = new TextureRect
|
||||||
@@ -105,38 +107,16 @@ namespace Content.Client.UserInterface
|
|||||||
parent.AddChild(ActiveHandRect);
|
parent.AddChild(ActiveHandRect);
|
||||||
ActiveHandRect.SetPositionInParent(1);
|
ActiveHandRect.SetPositionInParent(1);
|
||||||
|
|
||||||
if (left != null)
|
if (left != _leftHand)
|
||||||
{
|
{
|
||||||
if (left != LeftHand)
|
_leftHand = left;
|
||||||
{
|
_itemSlotManager.SetItemSlot(_leftButton, _leftHand);
|
||||||
LeftHand = left;
|
|
||||||
if (LeftHand.TryGetComponent(out ISpriteComponent sprite))
|
|
||||||
{
|
|
||||||
_leftButton.SpriteView.Sprite = sprite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LeftHand = null;
|
|
||||||
_leftButton.SpriteView.Sprite = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (right != null)
|
if (right != _rightHand)
|
||||||
{
|
{
|
||||||
if (right != RightHand)
|
_rightHand = right;
|
||||||
{
|
_itemSlotManager.SetItemSlot(_rightButton, _rightHand);
|
||||||
RightHand = right;
|
|
||||||
if (RightHand.TryGetComponent(out ISpriteComponent sprite))
|
|
||||||
{
|
|
||||||
_rightButton.SpriteView.Sprite = sprite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RightHand = null;
|
|
||||||
_rightButton.SpriteView.Sprite = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,15 +160,24 @@ namespace Content.Client.UserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void _OnStoragePressed(GUIBoundKeyEventArgs args, string handIndex)
|
||||||
|
{
|
||||||
|
if (!args.CanFocus)
|
||||||
|
return;
|
||||||
|
if (!TryGetHands(out var hands))
|
||||||
|
return;
|
||||||
|
hands.ActivateItemInHand(handIndex);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void FrameUpdate(FrameEventArgs args)
|
protected override void FrameUpdate(FrameEventArgs args)
|
||||||
{
|
{
|
||||||
base.FrameUpdate(args);
|
base.FrameUpdate(args);
|
||||||
|
|
||||||
_itemSlotManager.UpdateCooldown(_leftButton, LeftHand);
|
_itemSlotManager.UpdateCooldown(_leftButton, _leftHand);
|
||||||
_itemSlotManager.UpdateCooldown(_rightButton, RightHand);
|
_itemSlotManager.UpdateCooldown(_rightButton, _rightHand);
|
||||||
|
|
||||||
_rightStatusPanel.Update(RightHand);
|
_rightStatusPanel.Update(_rightHand);
|
||||||
_leftStatusPanel.Update(LeftHand);
|
_leftStatusPanel.Update(_leftHand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ namespace Content.Client.UserInterface
|
|||||||
void Initialize();
|
void Initialize();
|
||||||
bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item);
|
bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item);
|
||||||
void UpdateCooldown(ItemSlotButton cooldownTexture, IEntity entity);
|
void UpdateCooldown(ItemSlotButton cooldownTexture, IEntity entity);
|
||||||
|
bool SetItemSlot(ItemSlotButton button, IEntity entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Client.GameObjects;
|
using Content.Client.GameObjects;
|
||||||
|
using Content.Client.GameObjects.Components.Storage;
|
||||||
using Content.Client.GameObjects.EntitySystems;
|
using Content.Client.GameObjects.EntitySystems;
|
||||||
using Content.Client.Utility;
|
using Content.Client.Utility;
|
||||||
using Content.Shared.GameObjects.Components.Items;
|
using Content.Shared.GameObjects.Components.Items;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Robust.Client.GameObjects.EntitySystems;
|
using Robust.Client.GameObjects.EntitySystems;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
|
using Robust.Client.Interfaces.GameObjects.Components;
|
||||||
using Robust.Client.Interfaces.Graphics.ClientEye;
|
using Robust.Client.Interfaces.Graphics.ClientEye;
|
||||||
using Robust.Client.Interfaces.Input;
|
using Robust.Client.Interfaces.Input;
|
||||||
using Robust.Client.Interfaces.ResourceManagement;
|
using Robust.Client.Interfaces.ResourceManagement;
|
||||||
@@ -33,17 +35,34 @@ namespace Content.Client.UserInterface
|
|||||||
|
|
||||||
private const int CooldownLevels = 8;
|
private const int CooldownLevels = 8;
|
||||||
|
|
||||||
private readonly Texture[] TexturesCooldownOverlay = new Texture[CooldownLevels];
|
private readonly Texture[] _texturesCooldownOverlay = new Texture[CooldownLevels];
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < CooldownLevels; i++)
|
for (var i = 0; i < CooldownLevels; i++)
|
||||||
{
|
{
|
||||||
TexturesCooldownOverlay[i] =
|
_texturesCooldownOverlay[i] =
|
||||||
_resourceCache.GetTexture($"/Textures/UserInterface/Inventory/cooldown-{i}.png");
|
_resourceCache.GetTexture($"/Textures/UserInterface/Inventory/cooldown-{i}.png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SetItemSlot(ItemSlotButton button, IEntity entity)
|
||||||
|
{
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
button.SpriteView.Sprite = null;
|
||||||
|
button.StorageButton.Visible = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!entity.TryGetComponent(out ISpriteComponent sprite))
|
||||||
|
return false;
|
||||||
|
button.SpriteView.Sprite = sprite;
|
||||||
|
button.StorageButton.Visible = entity.HasComponent<ClientStorageComponent>();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item)
|
public bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item)
|
||||||
{
|
{
|
||||||
args.Handle();
|
args.Handle();
|
||||||
@@ -107,7 +126,7 @@ namespace Content.Client.UserInterface
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
cooldownTexture.Visible = true;
|
cooldownTexture.Visible = true;
|
||||||
cooldownTexture.Texture = TexturesCooldownOverlay[textureIndex];
|
cooldownTexture.Texture = _texturesCooldownOverlay[textureIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ namespace Content.Server.GameObjects
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActivateInhandMsg msg:
|
case UseInHandMsg msg:
|
||||||
{
|
{
|
||||||
var playerMan = IoCManager.Resolve<IPlayerManager>();
|
var playerMan = IoCManager.Resolve<IPlayerManager>();
|
||||||
var session = playerMan.GetSessionByChannel(netChannel);
|
var session = playerMan.GetSessionByChannel(netChannel);
|
||||||
@@ -511,6 +511,21 @@ namespace Content.Server.GameObjects
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ActivateInHandMsg msg:
|
||||||
|
{
|
||||||
|
var playerMan = IoCManager.Resolve<IPlayerManager>();
|
||||||
|
var session = playerMan.GetSessionByChannel(netChannel);
|
||||||
|
var playerEntity = session.AttachedEntity;
|
||||||
|
var used = GetHand(msg.Index)?.Owner;
|
||||||
|
|
||||||
|
if (playerEntity == Owner && used != null)
|
||||||
|
{
|
||||||
|
var interactionSystem = _entitySystemManager.GetEntitySystem<InteractionSystem>();
|
||||||
|
interactionSystem.TryInteractionActivate(Owner, used);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,6 +281,20 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Activates the Activate behavior of an object
|
||||||
|
/// Verifies that the user is capable of doing the use interaction first
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="used"></param>
|
||||||
|
public void TryInteractionActivate(IEntity user, IEntity used)
|
||||||
|
{
|
||||||
|
if (user != null && used != null && ActionBlockerSystem.CanUse(user))
|
||||||
|
{
|
||||||
|
InteractionActivate(user, used);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void InteractionActivate(IEntity user, IEntity used)
|
private void InteractionActivate(IEntity user, IEntity used)
|
||||||
{
|
{
|
||||||
var activateMsg = new ActivateInWorldMessage(user, used);
|
var activateMsg = new ActivateInWorldMessage(user, used);
|
||||||
|
|||||||
@@ -27,17 +27,32 @@ namespace Content.Shared.GameObjects
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A message that activates the inhand, presumed for now the activation will occur only on the active hand
|
/// A message that calls the use interaction on an item in hand, presumed for now the interaction will occur only on the active hand.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public class ActivateInhandMsg : ComponentMessage
|
public class UseInHandMsg : ComponentMessage
|
||||||
{
|
{
|
||||||
public ActivateInhandMsg()
|
public UseInHandMsg()
|
||||||
{
|
{
|
||||||
Directed = true;
|
Directed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A message that calls the activate interaction on the item in Index.
|
||||||
|
/// </summary>
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public class ActivateInHandMsg : ComponentMessage
|
||||||
|
{
|
||||||
|
public string Index { get; }
|
||||||
|
|
||||||
|
public ActivateInHandMsg(string index)
|
||||||
|
{
|
||||||
|
Directed = true;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public class ClientAttackByInHandMsg : ComponentMessage
|
public class ClientAttackByInHandMsg : ComponentMessage
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user