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:
@@ -12,6 +12,7 @@ namespace Content.Client.UserInterface
|
|||||||
{
|
{
|
||||||
public TextureRect Button { get; }
|
public TextureRect Button { get; }
|
||||||
public SpriteView SpriteView { get; }
|
public SpriteView SpriteView { get; }
|
||||||
|
public SpriteView HoverSpriteView { get; }
|
||||||
public BaseButton StorageButton { get; }
|
public BaseButton StorageButton { get; }
|
||||||
public CooldownGraphic CooldownDisplay { get; }
|
public CooldownGraphic CooldownDisplay { get; }
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ namespace Content.Client.UserInterface
|
|||||||
public Action<GUIBoundKeyEventArgs> OnStoragePressed { get; set; }
|
public Action<GUIBoundKeyEventArgs> OnStoragePressed { get; set; }
|
||||||
public Action<GUIMouseHoverEventArgs> OnHover { 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 bool MouseIsHovering = false;
|
||||||
|
|
||||||
public ItemSlotButton(Texture texture, Texture storageTexture)
|
public ItemSlotButton(Texture texture, Texture storageTexture)
|
||||||
@@ -41,6 +42,12 @@ namespace Content.Client.UserInterface
|
|||||||
OverrideDirection = Direction.South
|
OverrideDirection = Direction.South
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddChild(HoverSpriteView = new SpriteView
|
||||||
|
{
|
||||||
|
Scale = (2, 2),
|
||||||
|
OverrideDirection = Direction.South
|
||||||
|
});
|
||||||
|
|
||||||
AddChild(StorageButton = new TextureButton
|
AddChild(StorageButton = new TextureButton
|
||||||
{
|
{
|
||||||
TextureNormal = storageTexture,
|
TextureNormal = storageTexture,
|
||||||
@@ -69,13 +76,7 @@ namespace Content.Client.UserInterface
|
|||||||
Button.OnMouseExited += _ =>
|
Button.OnMouseExited += _ =>
|
||||||
{
|
{
|
||||||
MouseIsHovering = false;
|
MouseIsHovering = false;
|
||||||
if (EntityHover)
|
ClearHover();
|
||||||
{
|
|
||||||
SpriteView.Sprite?.Owner.Delete();
|
|
||||||
EntityHover = false;
|
|
||||||
SpriteView.Sprite = null;
|
|
||||||
StorageButton.Visible = false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AddChild(CooldownDisplay = new CooldownGraphic
|
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)
|
private void OnButtonPressed(GUIBoundKeyEventArgs args)
|
||||||
{
|
{
|
||||||
OnPressed?.Invoke(args);
|
OnPressed?.Invoke(args);
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ namespace Content.Client.UserInterface
|
|||||||
{
|
{
|
||||||
if (!entity.TryGetComponent(out ISpriteComponent sprite))
|
if (!entity.TryGetComponent(out ISpriteComponent sprite))
|
||||||
return false;
|
return false;
|
||||||
button.EntityHover = false;
|
|
||||||
|
button.ClearHover();
|
||||||
button.SpriteView.Sprite = sprite;
|
button.SpriteView.Sprite = sprite;
|
||||||
button.StorageButton.Visible = entity.HasComponent<ClientStorageComponent>();
|
button.StorageButton.Visible = entity.HasComponent<ClientStorageComponent>();
|
||||||
}
|
}
|
||||||
@@ -132,9 +133,7 @@ namespace Content.Client.UserInterface
|
|||||||
{
|
{
|
||||||
if (entity == null || !button.MouseIsHovering)
|
if (entity == null || !button.MouseIsHovering)
|
||||||
{
|
{
|
||||||
button.SpriteView.Sprite?.Owner.Delete();
|
button.ClearHover();
|
||||||
button.SpriteView.Sprite = null;
|
|
||||||
button.StorageButton.Visible = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,9 +148,7 @@ namespace Content.Client.UserInterface
|
|||||||
hoverSprite.CopyFrom(entity.GetComponent<SpriteComponent>());
|
hoverSprite.CopyFrom(entity.GetComponent<SpriteComponent>());
|
||||||
hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127);
|
hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127);
|
||||||
|
|
||||||
button.EntityHover = true;
|
button.HoverSpriteView.Sprite = hoverSprite;
|
||||||
button.SpriteView.Sprite = hoverSprite;
|
|
||||||
button.StorageButton.Visible = entity.HasComponent<ClientStorageComponent>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user