Improve hands & pulling (#4389)

This commit is contained in:
Pieter-Jan Briers
2021-07-31 03:14:00 +02:00
committed by GitHub
parent 73e4946e27
commit 632e72b817
33 changed files with 945 additions and 612 deletions

View File

@@ -1,18 +1,24 @@
using System;
using Content.Client.Cooldown;
using Content.Client.Items.Managers;
using Content.Client.Stylesheets;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.Input;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Items.UI
{
public class ItemSlotButton : Control
public class ItemSlotButton : Control, IEntityEventSubscriber
{
private const string HighlightShader = "SelectionOutlineInrange";
[Dependency] private readonly IItemSlotManager _itemSlotManager = default!;
public EntityUid Entity { get; set; }
public TextureRect Button { get; }
public SpriteView SpriteView { get; }
public SpriteView HoverSpriteView { get; }
@@ -32,6 +38,8 @@ namespace Content.Client.Items.UI
public ItemSlotButton(Texture texture, Texture storageTexture, string textureName)
{
IoCManager.InjectDependencies(this);
MinSize = (64, 64);
TextureName = textureName;
@@ -101,6 +109,31 @@ namespace Content.Client.Items.UI
});
}
protected override void EnteredTree()
{
base.EnteredTree();
_itemSlotManager.EntityHighlightedUpdated += HandleEntitySlotHighlighted;
UpdateSlotHighlighted();
}
protected override void ExitedTree()
{
base.ExitedTree();
_itemSlotManager.EntityHighlightedUpdated -= HandleEntitySlotHighlighted;
}
private void HandleEntitySlotHighlighted(EntitySlotHighlightedEventArgs entitySlotHighlightedEventArgs)
{
UpdateSlotHighlighted();
}
public void UpdateSlotHighlighted()
{
Highlight(_itemSlotManager.IsHighlighted(Entity));
}
public void ClearHover()
{
if (EntityHover)

View File

@@ -8,7 +8,9 @@ using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using static Content.Client.IoC.StaticIoC;
@@ -18,6 +20,8 @@ namespace Content.Client.Items.UI
{
public class ItemStatusPanel : Control
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[ViewVariables]
private readonly List<(IItemStatus, Control)> _activeStatusComponents = new();
@@ -33,6 +37,8 @@ namespace Content.Client.Items.UI
public ItemStatusPanel(Texture texture, StyleBox.Margin cutout, StyleBox.Margin flat, Label.AlignMode textAlign)
{
IoCManager.InjectDependencies(this);
var panel = new StyleBoxTexture
{
Texture = texture
@@ -117,6 +123,13 @@ namespace Content.Client.Items.UI
return new ItemStatusPanel(ResC.GetTexture(texture), cutOut, flat, textAlign);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
UpdateItemName();
}
public void Update(IEntity? entity)
{
if (entity == null)
@@ -131,12 +144,29 @@ namespace Content.Client.Items.UI
{
_entity = entity;
BuildNewEntityStatus();
_itemNameLabel.Text = entity.Name;
UpdateItemName();
}
_panel.Visible = true;
}
private void UpdateItemName()
{
if (_entity == null)
return;
if (_entity.TryGetComponent(out HandVirtualPullComponent? virtualPull)
&& _entityManager.TryGetEntity(virtualPull.PulledEntity, out var pulledEnt))
{
_itemNameLabel.Text = pulledEnt.Name;
}
else
{
_itemNameLabel.Text = _entity.Name;
}
}
private void ClearOldStatus()
{
_statusContents.RemoveAllChildren();
@@ -162,6 +192,14 @@ namespace Content.Client.Items.UI
_activeStatusComponents.Add((statusComponent, control));
}
var collectMsg = new ItemStatusCollectMessage();
_entity.EntityManager.EventBus.RaiseLocalEvent(_entity.Uid, collectMsg);
foreach (var control in collectMsg.Controls)
{
_statusContents.AddChild(control);
}
}
}
}