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.
64 lines
1.5 KiB
64 lines
1.5 KiB
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; // TODO: remove
|
|
[Export] private bool _showLabel = true;
|
|
[Export] private int _id = -1; // TODO: remove
|
|
|
|
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
|
|
[Signal] public delegate void InteractedEventHandler();
|
|
|
|
public bool IsActive { get; set; } = true;
|
|
|
|
public void OnPlayerEntered(Node2D player)
|
|
{
|
|
if (!IsActive)
|
|
return;
|
|
|
|
if(_showLabel)
|
|
_label.Show();
|
|
}
|
|
|
|
public void OnPlayerExited(Node2D player)
|
|
{
|
|
if (!IsActive)
|
|
return;
|
|
|
|
_label.Hide();
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (!IsActive)
|
|
return;
|
|
|
|
if (@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies())
|
|
{
|
|
_label.Hide();
|
|
EmitSignal(SignalName.InteractedTool, _id);
|
|
EmitSignal(SignalName.Interacted);
|
|
}
|
|
}
|
|
|
|
public void SetSpriteActiveState(bool success, int id) // TODO: remove
|
|
{
|
|
if(!IsActive)
|
|
return;
|
|
|
|
if (_id == id)
|
|
{
|
|
_sprites.SwitchState(!success);
|
|
}
|
|
}
|
|
|
|
public void ToggleActive()
|
|
{
|
|
IsActive = !IsActive;
|
|
_label.Hide();
|
|
}
|
|
} |