Show if items can be placed in a slot when hovering (#1480)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ using Content.Client.GameObjects.EntitySystems;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.GameObjects.EntitySystems;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
@@ -30,6 +31,7 @@ namespace Content.Client.UserInterface
|
||||
[Dependency] private readonly IGameTiming _gameTiming;
|
||||
[Dependency] private readonly IInputManager _inputManager;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
[Dependency] private readonly IEntityManager _entityManager;
|
||||
[Dependency] private readonly IEyeManager _eyeManager;
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
#pragma warning restore 0649
|
||||
@@ -45,6 +47,7 @@ namespace Content.Client.UserInterface
|
||||
{
|
||||
if (!entity.TryGetComponent(out ISpriteComponent sprite))
|
||||
return false;
|
||||
button.EntityHover = false;
|
||||
button.SpriteView.Sprite = sprite;
|
||||
button.StorageButton.Visible = entity.HasComponent<ClientStorageComponent>();
|
||||
}
|
||||
@@ -124,5 +127,31 @@ namespace Content.Client.UserInterface
|
||||
cooldownDisplay.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void HoverInSlot(ItemSlotButton button, IEntity entity, bool fits)
|
||||
{
|
||||
if (entity == null || !button.MouseIsHovering)
|
||||
{
|
||||
button.SpriteView.Sprite?.Owner.Delete();
|
||||
button.SpriteView.Sprite = null;
|
||||
button.StorageButton.Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entity.HasComponent<SpriteComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Set green / red overlay at 50% transparency
|
||||
var hoverEntity = _entityManager.SpawnEntity("hoverentity", MapCoordinates.Nullspace);
|
||||
var hoverSprite = hoverEntity.GetComponent<SpriteComponent>();
|
||||
hoverSprite.CopyFrom(entity.GetComponent<SpriteComponent>());
|
||||
hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127);
|
||||
|
||||
button.EntityHover = true;
|
||||
button.SpriteView.Sprite = hoverSprite;
|
||||
button.StorageButton.Visible = entity.HasComponent<ClientStorageComponent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user