Files
OldThink/Content.Client/UserInterface/ItemSlotButton.cs

86 lines
2.5 KiB
C#
Raw Normal View History

using System;
2020-05-23 11:26:59 +02:00
using Content.Client.UserInterface;
2020-05-05 23:59:31 +02:00
using Content.Shared.Input;
using Robust.Client.Graphics;
2020-05-05 23:59:31 +02:00
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.Maths;
namespace Content.Client.GameObjects
{
public sealed class ItemSlotButton : MarginContainer
{
2020-05-05 23:59:31 +02:00
public TextureRect Button { get; }
public SpriteView SpriteView { get; }
public BaseButton StorageButton { get; }
2020-05-23 11:26:59 +02:00
public CooldownGraphic CooldownDisplay { get; }
2020-05-05 23:59:31 +02:00
public Action<GUIBoundKeyEventArgs> OnPressed { get; set; }
public Action<GUIBoundKeyEventArgs> OnStoragePressed { get; set; }
public ItemSlotButton(Texture texture, Texture storageTexture)
{
CustomMinimumSize = (64, 64);
2020-05-05 23:59:31 +02:00
AddChild(Button = new TextureRect
{
2020-05-05 23:59:31 +02:00
Texture = texture,
TextureScale = (2, 2),
MouseFilter = MouseFilterMode.Stop
});
2020-05-05 23:59:31 +02:00
Button.OnKeyBindDown += OnButtonPressed;
AddChild(SpriteView = new SpriteView
{
Scale = (2, 2),
OverrideDirection = Direction.South
});
AddChild(StorageButton = new TextureButton
{
TextureNormal = storageTexture,
Scale = (0.75f, 0.75f),
SizeFlagsHorizontal = SizeFlags.ShrinkEnd,
SizeFlagsVertical = SizeFlags.ShrinkEnd,
Visible = false,
});
2020-05-05 23:59:31 +02:00
StorageButton.OnKeyBindDown += args =>
{
if (args.Function != EngineKeyFunctions.UIClick)
{
OnButtonPressed(args);
}
};
StorageButton.OnPressed += OnStorageButtonPressed;
2020-05-23 11:26:59 +02:00
AddChild(CooldownDisplay = new CooldownGraphic
{
2020-05-23 11:26:59 +02:00
SizeFlagsHorizontal = SizeFlags.Fill,
SizeFlagsVertical = SizeFlags.Fill,
Visible = false,
});
}
2020-05-05 23:59:31 +02:00
private void OnButtonPressed(GUIBoundKeyEventArgs args)
{
OnPressed?.Invoke(args);
}
private void OnStorageButtonPressed(BaseButton.ButtonEventArgs args)
{
2020-05-05 23:59:31 +02:00
if (args.Event.Function == EngineKeyFunctions.UIClick)
{
2020-05-05 23:59:31 +02:00
OnStoragePressed?.Invoke(args.Event);
}
else
{
2020-05-05 23:59:31 +02:00
OnPressed?.Invoke(args.Event);
}
}
}
}