Fixed HandsGui and added an icon to access worn inventories (#279)

* Fixed HandsGui children so that HandsGui is clickable

* Added TextureButton for opening Storage items

* Update ClientInventoryComponent.cs

Fixed HandleComponentState so that it only updates the inventory when there are changes.

* Implemented storage button on Inventory

Adds a small button on the bottom right of Storage items when inside the inventory. When the button is pressed it opens the Storage UI.
This commit is contained in:
ShadowCommander
2019-07-31 16:38:24 -07:00
committed by Pieter-Jan Briers
parent 1d9d01b355
commit 151d3a3672
8 changed files with 84 additions and 21 deletions

View File

@@ -1,7 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.GameObjects.Components.Clothing;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.Components.Storage;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
@@ -77,15 +80,12 @@ namespace Content.Client.GameObjects
foreach (var (slot, entityUid) in cast.Entities)
{
if (_slots.ContainsKey(slot))
{
_slots.Remove(slot);
_clearSlot(slot);
}
var entity = Owner.EntityManager.GetEntity(entityUid);
if (!_slots.ContainsKey(slot) || _slots[slot] != entity)
{
_slots[slot] = entity;
_setSlot(slot, entity);
}
doneSlots.Add(slot);
}
@@ -139,6 +139,11 @@ namespace Content.Client.GameObjects
SendNetworkMessage(equipmessage);
}
public void SendOpenStorageUIMessage(Slots slot)
{
SendNetworkMessage(new OpenSlotStorageUIMessage(slot));
}
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null,
IComponent component = null)
{

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Client.GameObjects.Components.Storage;
using Content.Client.Utility;
using JetBrains.Annotations;
using Robust.Client.Interfaces.GameObjects.Components;
@@ -52,9 +53,11 @@ namespace Content.Client.GameObjects
void AddButton(out InventoryButton variable, Slots slot, string textureName)
{
var texture = _resourceCache.GetTexture($"/Textures/UserInterface/Inventory/{textureName}.png");
variable = new InventoryButton(slot, texture)
var storageTexture = _resourceCache.GetTexture($"/Textures/UserInterface/Inventory/back.png");
variable = new InventoryButton(slot, texture, storageTexture)
{
OnPressed = AddToInventory
OnPressed = AddToInventory,
OnStoragePressed = OpenStorage
};
_inventoryButtons[slot].Add(variable);
}
@@ -89,11 +92,13 @@ namespace Content.Client.GameObjects
}
entity.TryGetComponent(out ISpriteComponent sprite);
var hasInventory = entity.HasComponent<ClientStorageComponent>();
foreach (var button in buttons)
{
button.SpriteView.Sprite = sprite;
button.OnPressed = RemoveFromInventory;
button.StorageButton.Visible = hasInventory;
}
}
@@ -110,6 +115,7 @@ namespace Content.Client.GameObjects
{
button.SpriteView.Sprite = null;
button.OnPressed = AddToInventory;
button.StorageButton.Visible = false;
}
}
@@ -152,7 +158,8 @@ namespace Content.Client.GameObjects
void AddButton(Slots slot, string textureName, Vector2 position)
{
var texture = resourceCache.GetTexture($"/Textures/UserInterface/Inventory/{textureName}.png");
var button = new InventoryButton(slot, texture)
var storageTexture = resourceCache.GetTexture($"/Textures/UserInterface/Inventory/back.png");
var button = new InventoryButton(slot, texture, storageTexture)
{
Position = position
};

View File

@@ -1,4 +1,4 @@
using System;
using System;
using Content.Shared.GameObjects.Components.Inventory;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
@@ -13,10 +13,12 @@ namespace Content.Client.GameObjects
public BaseButton Button { get; }
public SpriteView SpriteView { get; }
public BaseButton StorageButton { get; }
public Action<BaseButton.ButtonEventArgs> OnPressed { get; set; }
public Action<BaseButton.ButtonEventArgs> OnStoragePressed { get; set; }
public InventoryButton(EquipmentSlotDefines.Slots slot, Texture texture)
public InventoryButton(EquipmentSlotDefines.Slots slot, Texture texture, Texture storageTexture)
{
Slot = slot;
@@ -25,7 +27,7 @@ namespace Content.Client.GameObjects
AddChild(Button = new TextureButton
{
TextureNormal = texture,
Scale = (2, 2),
Scale = (2, 2)
});
Button.OnPressed += e => OnPressed?.Invoke(e);
@@ -35,6 +37,17 @@ namespace Content.Client.GameObjects
MouseFilter = MouseFilterMode.Ignore,
Scale = (2, 2)
});
AddChild(StorageButton = new TextureButton
{
TextureNormal = storageTexture,
Scale = (0.75f, 0.75f),
SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
SizeFlagsVertical = SizeFlags.ShrinkEnd,
Visible = false
});
StorageButton.OnPressed += e => OnStoragePressed?.Invoke(e);
}
}
}

View File

@@ -75,5 +75,13 @@ namespace Content.Client.GameObjects
Owner.SendEquipMessage(control.Slot);
}
protected void OpenStorage(BaseButton.ButtonEventArgs args)
{
args.Button.Pressed = false;
var control = (InventoryButton)args.Button.Parent;
Owner.SendOpenStorageUIMessage(control.Slot);
}
}
}

View File

@@ -60,6 +60,7 @@ namespace Content.Client.UserInterface
AddChild(new TextureRect
{
MouseFilter = MouseFilterMode.Ignore,
Texture = TextureHandLeft,
Size = _handL.Size,
Position = _handL.TopLeft,
@@ -68,6 +69,7 @@ namespace Content.Client.UserInterface
AddChild(new TextureRect
{
MouseFilter = MouseFilterMode.Ignore,
Texture = TextureHandRight,
Size = _handR.Size,
Position = _handR.TopLeft,
@@ -76,6 +78,7 @@ namespace Content.Client.UserInterface
AddChild(ActiveHandRect = new TextureRect
{
MouseFilter = MouseFilterMode.Ignore,
Texture = TextureHandActive,
Size = _handL.Size,
Position = _handL.TopLeft,

View File

@@ -263,6 +263,12 @@ namespace Content.Server.GameObjects
if (playerentity == Owner)
HandleInventoryMessage(msg);
break;
case OpenSlotStorageUIMessage msg:
ItemComponent item = GetSlotItem(msg.Slot);
ServerStorageComponent storage;
if (item.Owner.TryGetComponent(out storage))
storage.OpenStorageUI(Owner);
break;
}
}

View File

@@ -34,6 +34,7 @@ namespace Content.Server.GameObjects
[Dependency] private readonly IMapManager _mapManager;
[Dependency] private readonly IPlayerManager _playerManager;
[Dependency] private readonly IEntityManager _entityManager;
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
private Container storage;
@@ -174,12 +175,18 @@ namespace Content.Server.GameObjects
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
_ensureInitialCalculated();
var user_session = eventArgs.User.GetComponent<BasicActorComponent>().playerSession;
OpenStorageUI(eventArgs.User);
return false;
}
public void OpenStorageUI(IEntity Character)
{
_ensureInitialCalculated();
var user_session = Character.GetComponent<BasicActorComponent>().playerSession;
Logger.DebugS("Storage", "Storage (UID {0}) \"used\" by player session (UID {1}).", Owner.Uid, user_session.AttachedEntityUid);
SubscribeSession(user_session);
SendNetworkMessage(new OpenStorageUIMessage(), user_session.ConnectedClient);
UpdateClientInventory(user_session);
return false;
}
/// <summary>
@@ -301,18 +308,17 @@ namespace Content.Server.GameObjects
entity.GetComponent<ITransformComponent>().WorldPosition = ourtransform.WorldPosition;
}
}
}
break;
}
case CloseStorageUIMessage _:
{
var session = _playerManager.GetSessionByChannel(netChannel);
UnsubscribeSession(session);
}
break;
}
}
}
/// <inheritdoc />
void IActivate.Activate(ActivateEventArgs eventArgs)

View File

@@ -78,5 +78,20 @@ namespace Content.Shared.GameObjects
Unequip = 1
}
}
/// <summary>
/// Component message for opening the Storage UI of item in Slot
/// </summary>
[Serializable, NetSerializable]
public class OpenSlotStorageUIMessage : ComponentMessage
{
public Slots Slot;
public OpenSlotStorageUIMessage(Slots slot)
{
Directed = true;
Slot = slot;
}
}
}
}