Added OpenStorage trigger on ActivateItemInWorld

When ActivateItemInWorld is pressed when hovering over a InventoryButton and the InventorySlot contains a storage item, it will open the StorageGUI.
This commit is contained in:
ShadowCommander
2019-08-07 15:56:22 -07:00
parent 8c59d2e3b9
commit 7753ae7c3a
10 changed files with 90 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
using Content.Client.UserInterface;
using Content.Client.UserInterface;
using Robust.Client.Console;
using Robust.Client.Interfaces.Input;
using Robust.Client.Interfaces.Placement;
@@ -49,9 +49,8 @@ namespace Content.Client
_escapeMenu.OnClose += () => _gameHud.EscapeButtonDown = false;
var escapeMenuCommand = InputCmdHandler.FromDelegate(Enabled);
_inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu, escapeMenuCommand);
_inputManager.SetInputCommand(EngineKeyFunctions.EscapeMenu,
InputCmdHandler.FromDelegate(s => Enabled()));
}
else if (obj.OldState is GameScreen)
{
@@ -63,7 +62,7 @@ namespace Content.Client
}
}
private void Enabled(ICommonSession session)
private void Enabled()
{
if (_escapeMenu.IsOpen)
{

View File

@@ -127,18 +127,18 @@ namespace Content.Client.GameObjects
_sprite?.LayerSetVisible(slot, false);
}
public void SendUnequipMessage(Slots slot)
{
var unequipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Unequip);
SendNetworkMessage(unequipmessage);
}
public void SendEquipMessage(Slots slot)
{
var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Equip);
SendNetworkMessage(equipmessage);
}
public void SendUseMessage(Slots slot)
{
var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Use);
SendNetworkMessage(equipmessage);
}
public void SendOpenStorageUIMessage(Slots slot)
{
SendNetworkMessage(new OpenSlotStorageUIMessage(slot));

View File

@@ -97,7 +97,7 @@ namespace Content.Client.GameObjects
foreach (var button in buttons)
{
button.SpriteView.Sprite = sprite;
button.OnPressed = RemoveFromInventory;
button.OnPressed = HandleInventoryKeybind;
button.StorageButton.Visible = hasInventory;
}
}

View File

@@ -27,7 +27,8 @@ namespace Content.Client.GameObjects
AddChild(Button = new TextureButton
{
TextureNormal = texture,
Scale = (2, 2)
Scale = (2, 2),
NonFocusKeybinds = true
});
Button.OnPressed += e => OnPressed?.Invoke(e);
@@ -44,7 +45,8 @@ namespace Content.Client.GameObjects
Scale = (0.75f, 0.75f),
SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
SizeFlagsVertical = SizeFlags.ShrinkEnd,
Visible = false
Visible = false,
NonFocusKeybinds = true
});
StorageButton.OnPressed += e => OnStoragePressed?.Invoke(e);

View File

@@ -1,6 +1,7 @@
using System;
using System;
using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.Input;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Interfaces.GameObjects;
@@ -60,24 +61,44 @@ namespace Content.Client.GameObjects
{
}
protected void RemoveFromInventory(BaseButton.ButtonEventArgs args)
protected void HandleInventoryKeybind(BaseButton.ButtonEventArgs args)
{
args.Button.Pressed = false;
var control = (InventoryButton) args.Button.Parent;
Owner.SendUnequipMessage(control.Slot);
if (args.Event.Function == ContentKeyFunctions.ActivateItemInWorld)
{
OpenStorage(args);
}
else if (args.Event.CanFocus)
{
UseItemOnInventory(args);
}
}
protected void AddToInventory(BaseButton.ButtonEventArgs args)
{
if (!args.Event.CanFocus)
{
return;
}
args.Button.Pressed = false;
var control = (InventoryButton) args.Button.Parent;
Owner.SendEquipMessage(control.Slot);
}
protected void UseItemOnInventory(BaseButton.ButtonEventArgs args)
{
args.Button.Pressed = false;
var control = (InventoryButton)args.Button.Parent;
Owner.SendUseMessage(control.Slot);
}
protected void OpenStorage(BaseButton.ButtonEventArgs args)
{
if (!args.Event.CanFocus && args.Event.Function != ContentKeyFunctions.ActivateItemInWorld)
{
return;
}
args.Button.Pressed = false;
var control = (InventoryButton)args.Button.Parent;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using Content.Client.Utility;
using Content.Shared.Input;
using Robust.Client.Graphics;

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.Interfaces.Player;
@@ -19,6 +20,10 @@ namespace Content.Server.GameObjects
[RegisterComponent]
public class InventoryComponent : SharedInventoryComponent
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
[ViewVariables]
private readonly Dictionary<Slots, ContainerSlot> SlotContainers = new Dictionary<Slots, ContainerSlot>();
@@ -223,11 +228,13 @@ namespace Content.Server.GameObjects
/// <param name="msg"></param>
private void HandleInventoryMessage(ClientInventoryMessage msg)
{
if (msg.Updatetype == ClientInventoryUpdate.Equip)
switch (msg.Updatetype)
{
case ClientInventoryUpdate.Equip:
{
var hands = Owner.GetComponent<HandsComponent>();
var activehand = hands.GetActiveHand;
if (activehand != null && activehand.Owner.TryGetComponent(out ClothingComponent clothing))
var activeHand = hands.GetActiveHand;
if (activeHand != null && activeHand.Owner.TryGetComponent(out ClothingComponent clothing))
{
hands.Drop(hands.ActiveIndex);
if (!Equip(msg.Inventoryslot, clothing))
@@ -235,15 +242,27 @@ namespace Content.Server.GameObjects
hands.PutInHand(clothing);
}
}
break;
}
else if (msg.Updatetype == ClientInventoryUpdate.Unequip)
case ClientInventoryUpdate.Use:
{
var interactionSystem = _entitySystemManager.GetEntitySystem<InteractionSystem>();
var hands = Owner.GetComponent<HandsComponent>();
var activehand = hands.GetActiveHand;
var itemcontainedinslot = GetSlotItem(msg.Inventoryslot);
if (activehand == null && itemcontainedinslot != null && Unequip(msg.Inventoryslot))
var activeHand = hands.GetActiveHand;
var itemContainedInSlot = GetSlotItem(msg.Inventoryslot);
if (itemContainedInSlot != null)
{
hands.PutInHand(itemcontainedinslot);
if (activeHand != null)
{
interactionSystem.Interaction(Owner, activeHand.Owner, itemContainedInSlot.Owner,
new Robust.Shared.Map.GridCoordinates());
}
else if (Unequip(msg.Inventoryslot))
{
hands.PutInHand(itemContainedInSlot);
}
}
break;
}
}
}

View File

@@ -472,12 +472,19 @@ namespace Content.Server.GameObjects
var playerEntity = session.AttachedEntity;
var used = GetActiveHand?.Owner;
if (playerEntity == Owner && used != null && slot.ContainedEntity != null)
if (playerEntity == Owner && slot.ContainedEntity != null)
{
var interactionSystem = _entitySystemManager.GetEntitySystem<InteractionSystem>();
if (used != null)
{
interactionSystem.Interaction(Owner, used, slot.ContainedEntity,
GridCoordinates.Nullspace);
}
else
{
interactionSystem.Interaction(Owner, slot.ContainedEntity);
}
}
break;
}

View File

@@ -75,7 +75,7 @@ namespace Content.Shared.GameObjects
public enum ClientInventoryUpdate
{
Equip = 0,
Unequip = 1
Use = 1
}
}