Fixed field creation bug
This commit is contained in:
@@ -61,6 +61,7 @@ offset_right = 200.0
|
|||||||
offset_bottom = -1.0
|
offset_bottom = -1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
mouse_filter = 2
|
||||||
|
|
||||||
[node name="BackgroundContainer" type="Control" parent="Inventory/SlotsContainer/SlotsMover"]
|
[node name="BackgroundContainer" type="Control" parent="Inventory/SlotsContainer/SlotsMover"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
@@ -76,8 +77,8 @@ layout_mode = 1
|
|||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 437.0
|
offset_left = 435.0
|
||||||
offset_right = 341.0
|
offset_right = 339.0
|
||||||
offset_bottom = 30.0
|
offset_bottom = 30.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
@@ -90,8 +91,8 @@ layout_mode = 1
|
|||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = -357.0
|
offset_left = -356.0
|
||||||
offset_right = -453.0
|
offset_right = -452.0
|
||||||
offset_bottom = 30.0
|
offset_bottom = 30.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|||||||
@@ -2093,7 +2093,7 @@ position = Vector2(0, -374)
|
|||||||
[node name="Animated Sprites" type="AnimatedSprite2D" parent="CharacterBody2D/visuals"]
|
[node name="Animated Sprites" type="AnimatedSprite2D" parent="CharacterBody2D/visuals"]
|
||||||
position = Vector2(0, 450)
|
position = Vector2(0, 450)
|
||||||
sprite_frames = SubResource("SpriteFrames_4yiyq")
|
sprite_frames = SubResource("SpriteFrames_4yiyq")
|
||||||
animation = &"side walking wateringcan"
|
animation = &"front walking backpack"
|
||||||
offset = Vector2(0, -450)
|
offset = Vector2(0, -450)
|
||||||
|
|
||||||
[node name="Hoe" type="Sprite2D" parent="CharacterBody2D/visuals"]
|
[node name="Hoe" type="Sprite2D" parent="CharacterBody2D/visuals"]
|
||||||
|
|||||||
@@ -1085,8 +1085,7 @@ script = ExtResource("40_w3jkj")
|
|||||||
[connection signal="SuccessfulPickUp" from="YSorted/RakeGenericPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
[connection signal="SuccessfulPickUp" from="YSorted/RakeGenericPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
||||||
[connection signal="Interacted" from="YSorted/Farm visuals/Static/EnterHouseInteraction" to="." method="LoadScene"]
|
[connection signal="Interacted" from="YSorted/Farm visuals/Static/EnterHouseInteraction" to="." method="LoadScene"]
|
||||||
[connection signal="FieldCreated" from="YSorted/Farm visuals/FieldParent" to="Audio/SFX/Farming SFX" method="PlayOneShot"]
|
[connection signal="FieldCreated" from="YSorted/Farm visuals/FieldParent" to="Audio/SFX/Farming SFX" method="PlayOneShot"]
|
||||||
[connection signal="mouse_entered" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseEnteredAllowedArea"]
|
[connection signal="input_event" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Vesna/FarmingControls" method="InputEventPressedOn"]
|
||||||
[connection signal="mouse_exited" from="YSorted/Farm visuals/FieldParent/Area2D" to="YSorted/Farm visuals/FieldParent" method="MouseExitedAllowedArea"]
|
|
||||||
[connection signal="finished" from="Audio/Background Music Ramp up" to="Audio/Background Music loop" method="PlayFromOffset"]
|
[connection signal="finished" from="Audio/Background Music Ramp up" to="Audio/Background Music loop" method="PlayFromOffset"]
|
||||||
|
|
||||||
[editable path="YSorted/Vesna"]
|
[editable path="YSorted/Vesna"]
|
||||||
|
|||||||
@@ -52,23 +52,64 @@ public partial class FarmingControls2D : Node2D
|
|||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
|
||||||
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
|
||||||
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
|
|
||||||
|
|
||||||
if (@event.IsActionPressed("click") && _toolId == 0)
|
|
||||||
{
|
|
||||||
MakeField(adjustedPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (@event.IsActionPressed("click")
|
if (@event.IsActionPressed("click")
|
||||||
&& _toolId == WateringCanState.WATERING_CAN_ID
|
&& _toolId == WateringCanState.WATERING_CAN_ID
|
||||||
&& WateringCanState.GetFillState() > 0)
|
&& WateringCanState.GetFillState() > 0)
|
||||||
{
|
{
|
||||||
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||||
WaterTheField(adjustedPosition);
|
WaterTheField(adjustedPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Vector2I GetAdjustedMousePosition()
|
||||||
|
{
|
||||||
|
Vector2 mousePosition = _camera.GetGlobalMousePosition();
|
||||||
|
Vector2I mousePositionInteger = (Vector2I) mousePosition;
|
||||||
|
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 (!inputEvent.IsActionPressed("click"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (inputEvent is InputEventMouseButton inputEventMouseButton)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
GD.Print("Current tool id: " + _toolId );
|
||||||
|
if (_toolId == 0)
|
||||||
|
{
|
||||||
|
GD.Print("Trying to create field." );
|
||||||
|
Vector2I adjustedPosition = GetAdjustedMousePosition();
|
||||||
|
MakeField(adjustedPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region WATERING
|
#region WATERING
|
||||||
public void FillWateringCan()
|
public void FillWateringCan()
|
||||||
{
|
{
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,27 +7,24 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
|||||||
public partial class FieldService2D : Node2D
|
public partial class FieldService2D : Node2D
|
||||||
{
|
{
|
||||||
[Export] private Dictionary<Vector2I, FieldBehaviour2D> fields = new Dictionary<Vector2I, FieldBehaviour2D>();
|
[Export] private Dictionary<Vector2I, FieldBehaviour2D> fields = new Dictionary<Vector2I, FieldBehaviour2D>();
|
||||||
|
|
||||||
private bool _fieldAllowed = false;
|
[Export] private Area2D _allowedArea;
|
||||||
|
|
||||||
[Signal] public delegate void FieldCreatedEventHandler();
|
[Signal] public delegate void FieldCreatedEventHandler();
|
||||||
|
|
||||||
//Validate
|
|
||||||
|
|
||||||
public void MouseEnteredAllowedArea()
|
|
||||||
{
|
|
||||||
_fieldAllowed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MouseExitedAllowedArea()
|
|
||||||
{
|
|
||||||
_fieldAllowed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool FieldAllowed()
|
/*
|
||||||
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
return _fieldAllowed;
|
var spaceState = GetWorld2D().DirectSpaceState;
|
||||||
|
// use global coordinates, not local to node
|
||||||
|
var query = PhysicsRayQueryParameters2D.Create(GetGlobalMousePosition(), new Vector3(0,0,-1),
|
||||||
|
CollisionMask, [GetRid()]);
|
||||||
|
var result = spaceState.IntersectRay(query);
|
||||||
|
if (result.Count > 0)
|
||||||
|
GD.Print("Hit at point: ", result["position"]);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
public bool TryAddEntry(Vector2I key, FieldBehaviour2D field)
|
public bool TryAddEntry(Vector2I key, FieldBehaviour2D field)
|
||||||
|
|||||||
Reference in New Issue
Block a user