2020-01-17 06:43:20 -08:00
|
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Client.Cooldown;
|
2021-12-30 22:56:10 +01:00
|
|
|
|
using Content.Client.HUD;
|
2021-07-31 03:14:00 +02:00
|
|
|
|
using Content.Client.Items.Managers;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Client.Stylesheets;
|
2021-12-03 11:43:03 +01:00
|
|
|
|
using Robust.Client.GameObjects;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
using Robust.Client.Graphics;
|
2020-05-05 23:59:31 +02:00
|
|
|
|
using Robust.Client.UserInterface;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2021-12-30 22:56:10 +01:00
|
|
|
|
using Robust.Client.Utility;
|
2021-07-31 03:14:00 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
using Robust.Shared.Input;
|
2021-07-31 03:14:00 +02:00
|
|
|
|
using Robust.Shared.IoC;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
using Robust.Shared.Maths;
|
2021-12-30 22:56:10 +01:00
|
|
|
|
using Robust.Shared.Utility;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Items.UI
|
2020-01-17 06:43:20 -08:00
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
[Virtual]
|
2021-07-31 03:14:00 +02:00
|
|
|
|
public class ItemSlotButton : Control, IEntityEventSubscriber
|
2020-01-17 06:43:20 -08:00
|
|
|
|
{
|
2020-12-13 14:28:20 -08:00
|
|
|
|
private const string HighlightShader = "SelectionOutlineInrange";
|
|
|
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
|
[Dependency] private readonly IItemSlotManager _itemSlotManager = default!;
|
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
|
public EntityUid? Entity { get; set; }
|
2020-05-05 23:59:31 +02:00
|
|
|
|
public TextureRect Button { get; }
|
2020-01-17 06:43:20 -08:00
|
|
|
|
public SpriteView SpriteView { get; }
|
2020-07-26 17:57:48 +02:00
|
|
|
|
public SpriteView HoverSpriteView { get; }
|
2021-04-11 17:43:53 -05:00
|
|
|
|
public TextureButton StorageButton { get; }
|
2020-05-23 11:26:59 +02:00
|
|
|
|
public CooldownGraphic CooldownDisplay { get; }
|
2020-01-17 06:43:20 -08:00
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public Action<GUIBoundKeyEventArgs>? OnPressed { get; set; }
|
|
|
|
|
|
public Action<GUIBoundKeyEventArgs>? OnStoragePressed { get; set; }
|
|
|
|
|
|
public Action<GUIMouseHoverEventArgs>? OnHover { get; set; }
|
2020-07-26 07:25:38 -05:00
|
|
|
|
|
2020-07-26 17:57:48 +02:00
|
|
|
|
public bool EntityHover => HoverSpriteView.Sprite != null;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public bool MouseIsHovering;
|
2021-01-20 00:32:44 -08:00
|
|
|
|
|
|
|
|
|
|
private readonly PanelContainer _highlightRect;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
|
private string _textureName;
|
|
|
|
|
|
private string _storageTextureName;
|
2021-04-11 17:43:53 -05:00
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
|
public ItemSlotButton(int size, string textureName, string storageTextureName, IGameHud gameHud)
|
2020-01-17 06:43:20 -08:00
|
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
|
_textureName = textureName;
|
|
|
|
|
|
_storageTextureName = storageTextureName;
|
2021-07-31 03:14:00 +02:00
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
|
MinSize = (size, size);
|
2021-04-11 17:43:53 -05:00
|
|
|
|
|
2020-05-05 23:59:31 +02:00
|
|
|
|
AddChild(Button = new TextureRect
|
2020-01-17 06:43:20 -08:00
|
|
|
|
{
|
2020-05-05 23:59:31 +02:00
|
|
|
|
TextureScale = (2, 2),
|
|
|
|
|
|
MouseFilter = MouseFilterMode.Stop
|
2020-01-17 06:43:20 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
2021-01-20 00:32:44 -08:00
|
|
|
|
AddChild(_highlightRect = new PanelContainer
|
|
|
|
|
|
{
|
|
|
|
|
|
StyleClasses = { StyleNano.StyleClassHandSlotHighlight },
|
2021-02-21 12:38:56 +01:00
|
|
|
|
MinSize = (32, 32),
|
2021-01-20 00:32:44 -08:00
|
|
|
|
Visible = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-05-05 23:59:31 +02:00
|
|
|
|
Button.OnKeyBindDown += OnButtonPressed;
|
2020-01-17 06:43:20 -08:00
|
|
|
|
|
|
|
|
|
|
AddChild(SpriteView = new SpriteView
|
|
|
|
|
|
{
|
|
|
|
|
|
Scale = (2, 2),
|
|
|
|
|
|
OverrideDirection = Direction.South
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-07-26 17:57:48 +02:00
|
|
|
|
AddChild(HoverSpriteView = new SpriteView
|
|
|
|
|
|
{
|
|
|
|
|
|
Scale = (2, 2),
|
|
|
|
|
|
OverrideDirection = Direction.South
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
AddChild(StorageButton = new TextureButton
|
|
|
|
|
|
{
|
|
|
|
|
|
Scale = (0.75f, 0.75f),
|
2021-02-21 12:38:56 +01:00
|
|
|
|
HorizontalAlignment = HAlignment.Right,
|
|
|
|
|
|
VerticalAlignment = VAlignment.Bottom,
|
2020-01-17 06:43:20 -08:00
|
|
|
|
Visible = false,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2020-05-05 23:59:31 +02:00
|
|
|
|
StorageButton.OnKeyBindDown += args =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Function != EngineKeyFunctions.UIClick)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnButtonPressed(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-01-17 06:43:20 -08:00
|
|
|
|
StorageButton.OnPressed += OnStorageButtonPressed;
|
|
|
|
|
|
|
2020-07-26 07:25:38 -05:00
|
|
|
|
Button.OnMouseEntered += _ =>
|
|
|
|
|
|
{
|
|
|
|
|
|
MouseIsHovering = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
Button.OnMouseEntered += OnButtonHover;
|
|
|
|
|
|
|
|
|
|
|
|
Button.OnMouseExited += _ =>
|
|
|
|
|
|
{
|
|
|
|
|
|
MouseIsHovering = false;
|
2020-07-26 17:57:48 +02:00
|
|
|
|
ClearHover();
|
2020-07-26 07:25:38 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
2020-05-23 11:26:59 +02:00
|
|
|
|
AddChild(CooldownDisplay = new CooldownGraphic
|
2020-01-17 06:43:20 -08:00
|
|
|
|
{
|
|
|
|
|
|
Visible = false,
|
|
|
|
|
|
});
|
2021-12-30 22:56:10 +01:00
|
|
|
|
|
|
|
|
|
|
RefreshTextures(gameHud);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RefreshTextures(IGameHud gameHud)
|
|
|
|
|
|
{
|
|
|
|
|
|
Button.Texture = gameHud.GetHudTexture(_textureName);
|
|
|
|
|
|
StorageButton.TextureNormal = gameHud.GetHudTexture(_storageTextureName);
|
2020-01-17 06:43:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-31 03:14:00 +02:00
|
|
|
|
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));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 17:57:48 +02:00
|
|
|
|
public void ClearHover()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (EntityHover)
|
|
|
|
|
|
{
|
2021-12-03 11:43:03 +01:00
|
|
|
|
ISpriteComponent? tempQualifier = HoverSpriteView.Sprite;
|
|
|
|
|
|
if (tempQualifier != null)
|
|
|
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
|
IoCManager.Resolve<IEntityManager>().DeleteEntity(tempQualifier.Owner);
|
2021-12-03 11:43:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 17:57:48 +02:00
|
|
|
|
HoverSpriteView.Sprite = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-20 00:32:44 -08:00
|
|
|
|
public virtual void Highlight(bool highlight)
|
2020-12-13 14:28:20 -08:00
|
|
|
|
{
|
2021-01-20 00:32:44 -08:00
|
|
|
|
if (highlight)
|
2020-12-13 14:28:20 -08:00
|
|
|
|
{
|
2021-01-20 00:32:44 -08:00
|
|
|
|
_highlightRect.Visible = true;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-01-20 00:32:44 -08:00
|
|
|
|
_highlightRect.Visible = false;
|
2020-12-13 14:28:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-05 23:59:31 +02:00
|
|
|
|
private void OnButtonPressed(GUIBoundKeyEventArgs args)
|
2020-01-17 06:43:20 -08:00
|
|
|
|
{
|
|
|
|
|
|
OnPressed?.Invoke(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnStorageButtonPressed(BaseButton.ButtonEventArgs args)
|
|
|
|
|
|
{
|
2020-05-05 23:59:31 +02:00
|
|
|
|
if (args.Event.Function == EngineKeyFunctions.UIClick)
|
2020-01-17 06:43:20 -08:00
|
|
|
|
{
|
2020-05-05 23:59:31 +02:00
|
|
|
|
OnStoragePressed?.Invoke(args.Event);
|
2020-01-17 06:43:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-05-05 23:59:31 +02:00
|
|
|
|
OnPressed?.Invoke(args.Event);
|
2020-01-17 06:43:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-07-26 07:25:38 -05:00
|
|
|
|
|
|
|
|
|
|
private void OnButtonHover(GUIMouseHoverEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnHover?.Invoke(args);
|
|
|
|
|
|
}
|
2020-01-17 06:43:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|