You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
999 B
43 lines
999 B
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
|
|
|
public partial class InteractionArea2D : Node2D
|
|
{
|
|
[Export] private Area2D _area;
|
|
[Export] private Label _label;
|
|
[Export] private SpriteSwitcher2D _sprites;
|
|
[Export] private bool _showLabel = true;
|
|
[Export] private int _id;
|
|
|
|
[Signal]
|
|
public delegate void InteractedEventHandler(int id);
|
|
|
|
public void OnPlayerEntered(Node2D player)
|
|
{
|
|
if(_showLabel)
|
|
_label.Show();
|
|
}
|
|
|
|
public void OnPlayerExited(Node2D player)
|
|
{
|
|
_label.Hide();
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies())
|
|
{
|
|
_label.Hide();
|
|
EmitSignal(SignalName.Interacted, _id);
|
|
}
|
|
}
|
|
|
|
public void SetSpriteActiveState(bool success, int id)
|
|
{
|
|
if (_id == id)
|
|
{
|
|
_sprites.SwitchState(!success);
|
|
}
|
|
}
|
|
} |