Improve item slot hover.

1. Use a separate SpriteView for the hover entity to avoid any bookkeeping issues
2. don't set storagebutton visibility.
This commit is contained in:
Pieter-Jan Briers
2020-07-26 17:57:48 +02:00
parent 60a2a400e0
commit 804f287ee3
2 changed files with 22 additions and 15 deletions

View File

@@ -12,6 +12,7 @@ namespace Content.Client.UserInterface
{
public TextureRect Button { get; }
public SpriteView SpriteView { get; }
public SpriteView HoverSpriteView { get; }
public BaseButton StorageButton { get; }
public CooldownGraphic CooldownDisplay { get; }
@@ -19,7 +20,7 @@ namespace Content.Client.UserInterface
public Action<GUIBoundKeyEventArgs> OnStoragePressed { get; set; }
public Action<GUIMouseHoverEventArgs> OnHover { get; set; }
public bool EntityHover { get; set; } = false;
public bool EntityHover => HoverSpriteView.Sprite != null;
public bool MouseIsHovering = false;
public ItemSlotButton(Texture texture, Texture storageTexture)
@@ -41,6 +42,12 @@ namespace Content.Client.UserInterface
OverrideDirection = Direction.South
});
AddChild(HoverSpriteView = new SpriteView
{
Scale = (2, 2),
OverrideDirection = Direction.South
});
AddChild(StorageButton = new TextureButton
{
TextureNormal = storageTexture,
@@ -69,13 +76,7 @@ namespace Content.Client.UserInterface
Button.OnMouseExited += _ =>
{
MouseIsHovering = false;
if (EntityHover)
{
SpriteView.Sprite?.Owner.Delete();
EntityHover = false;
SpriteView.Sprite = null;
StorageButton.Visible = false;
}
ClearHover();
};
AddChild(CooldownDisplay = new CooldownGraphic
@@ -86,6 +87,15 @@ namespace Content.Client.UserInterface
});
}
public void ClearHover()
{
if (EntityHover)
{
HoverSpriteView.Sprite?.Owner.Delete();
HoverSpriteView.Sprite = null;
}
}
private void OnButtonPressed(GUIBoundKeyEventArgs args)
{
OnPressed?.Invoke(args);