49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class HoverableNode : Node2D
|
|
{
|
|
[Signal]
|
|
public delegate void HoverEventHandler(HoverableNode THIS, bool IS_HOVERED);
|
|
[Signal]
|
|
public delegate void ClickEventHandler(HoverableNode THIS, int CLICK_TYPE);
|
|
|
|
public bool _hovered;
|
|
public Area2D _bounds;
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
_bounds = GetNode<Area2D>("HoverBounds");
|
|
_bounds.MouseEntered += OnMouseEntered;
|
|
_bounds.MouseExited += OnMouseExited;
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (_hovered)
|
|
{
|
|
if (Input.IsActionJustReleased("lmb"))
|
|
{
|
|
EmitSignal(SignalName.Click, this, 0);
|
|
}
|
|
if (Input.IsActionJustReleased("rmb"))
|
|
{
|
|
EmitSignal(SignalName.Click, this, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual void OnMouseEntered()
|
|
{
|
|
_hovered = true;
|
|
EmitSignal(SignalName.Hover, this,_hovered);
|
|
}
|
|
|
|
public virtual void OnMouseExited()
|
|
{
|
|
_hovered = false;
|
|
EmitSignal(SignalName.Hover, this, _hovered);
|
|
}
|
|
}
|