|
|
|
@ -51,21 +51,62 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
public override void _Input(InputEvent @event)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (@event.IsActionPressed("click")
|
|
|
|
|
|
|
|
&& _toolId == WateringCanState.WATERING_CAN_ID
|
|
|
|
|
|
|
|
&& WateringCanState.GetFillState() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
|
|
|
|
|
|
|
WaterTheField(adjustedPosition);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Vector2I GetAdjustedMousePosition()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
|
|
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
|
|
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
|
|
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
|
|
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
|
|
|
|
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
|
|
|
|
|
|
|
|
return adjustedPosition;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Called by the allowed farming area collision area 2d.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="node"></param>
|
|
|
|
|
|
|
|
/// <param name="inputEvent"></param>
|
|
|
|
|
|
|
|
/// <param name="shapeIndex"></param>
|
|
|
|
|
|
|
|
public void InputEventPressedOn(Node node, InputEvent inputEvent, int shapeIndex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!inputEvent.IsPressed())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GD.Print("Input Event is not pressed." );
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (@event.IsActionPressed("click") && _toolId == 0)
|
|
|
|
if (!inputEvent.IsActionPressed("click"))
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inputEvent is InputEventMouseButton inputEventMouseButton)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MakeField(adjustedPosition);
|
|
|
|
GD.Print("Input Event is InputEventMouseButton." );
|
|
|
|
|
|
|
|
if (!inputEventMouseButton.Pressed)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GD.Print("Input Event Mouse Button is not pressed." );
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
GD.Print("Other Input Event registered." );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (@event.IsActionPressed("click")
|
|
|
|
GD.Print("Current tool id: " + _toolId );
|
|
|
|
&& _toolId == WateringCanState.WATERING_CAN_ID
|
|
|
|
if (_toolId == 0)
|
|
|
|
&& WateringCanState.GetFillState() > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
WaterTheField(adjustedPosition);
|
|
|
|
GD.Print("Trying to create field." );
|
|
|
|
|
|
|
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
|
|
|
|
|
|
|
MakeField(adjustedPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -98,10 +139,6 @@ public partial class FarmingControls2D : Node2D
|
|
|
|
if(FieldService == null || _fieldPrefab == null)
|
|
|
|
if(FieldService == null || _fieldPrefab == null)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// only try to instantiate a field if you're in the allowed area
|
|
|
|
|
|
|
|
if (!FieldService.FieldAllowed())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// only instantiate a field if there isn't one already.
|
|
|
|
// only instantiate a field if there isn't one already.
|
|
|
|
if(FieldService.Get(fieldPosition) == null)
|
|
|
|
if(FieldService.Get(fieldPosition) == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|