decisions decisions decisions
This commit is contained in:
57
src/Gameplay/Nodules/Components/GrowArea.cs
Normal file
57
src/Gameplay/Nodules/Components/GrowArea.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Godot;
|
||||
using Slimepire.Core;
|
||||
|
||||
namespace Slimepire.Gameplay.Nodules.Components;
|
||||
|
||||
[SceneTree]
|
||||
public partial class GrowArea : Area2D
|
||||
{
|
||||
private bool _mouseInsideClickArea;
|
||||
private bool _clickedInside;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
MouseEntered += ClickAreaOnMouseEntered;
|
||||
MouseExited += ClickAreaOnMouseExited;
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseEntered()
|
||||
{
|
||||
_mouseInsideClickArea = true;
|
||||
}
|
||||
|
||||
private void ClickAreaOnMouseExited()
|
||||
{
|
||||
_mouseInsideClickArea = false;
|
||||
|
||||
// ghost == null check probably unnecessary
|
||||
if (_clickedInside && !NoduleManager.Instance.Building)
|
||||
{
|
||||
NoduleManager.Instance.Building = true;
|
||||
_clickedInside = false;
|
||||
|
||||
var ghost = Instantiator.Instantiate<BuildGhost>();
|
||||
ghost.Position = Position;
|
||||
|
||||
// TODO: Make it better... EntityRoot oder vllt. NoduleRoot
|
||||
// Oder einfach den Baum auch als Baum in der Scene darstellen?
|
||||
GetTree().Root.AddChild(ghost);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
using (@event)
|
||||
{
|
||||
if (
|
||||
@event is InputEventMouseButton { ButtonIndex: MouseButton.Left }
|
||||
&& @event.IsPressed()
|
||||
&& _mouseInsideClickArea
|
||||
)
|
||||
{
|
||||
_clickedInside = true;
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user