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:
Moses
2020-07-26 07:25:38 -05:00
committed by GitHub
parent bab1345b87
commit 8e08c64fcf
9 changed files with 135 additions and 4 deletions

View File

@@ -9,5 +9,6 @@ namespace Content.Client.UserInterface
bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item);
void UpdateCooldown(ItemSlotButton cooldownTexture, IEntity entity);
bool SetItemSlot(ItemSlotButton button, IEntity entity);
void HoverInSlot(ItemSlotButton button, IEntity entity, bool fits);
}
}

View File

@@ -17,6 +17,10 @@ namespace Content.Client.UserInterface
public Action<GUIBoundKeyEventArgs> OnPressed { get; set; }
public Action<GUIBoundKeyEventArgs> OnStoragePressed { get; set; }
public Action<GUIMouseHoverEventArgs> OnHover { get; set; }
public bool EntityHover { get; set; } = false;
public bool MouseIsHovering = false;
public ItemSlotButton(Texture texture, Texture storageTexture)
{
@@ -56,6 +60,24 @@ namespace Content.Client.UserInterface
StorageButton.OnPressed += OnStorageButtonPressed;
Button.OnMouseEntered += _ =>
{
MouseIsHovering = true;
};
Button.OnMouseEntered += OnButtonHover;
Button.OnMouseExited += _ =>
{
MouseIsHovering = false;
if (EntityHover)
{
SpriteView.Sprite?.Owner.Delete();
EntityHover = false;
SpriteView.Sprite = null;
StorageButton.Visible = false;
}
};
AddChild(CooldownDisplay = new CooldownGraphic
{
SizeFlagsHorizontal = SizeFlags.Fill,
@@ -80,5 +102,10 @@ namespace Content.Client.UserInterface
OnPressed?.Invoke(args.Event);
}
}
private void OnButtonHover(GUIMouseHoverEventArgs args)
{
OnHover?.Invoke(args);
}
}
}

View File

@@ -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>();
}
}
}