From fc32baa0718e2771a70a63056b79515f091767af Mon Sep 17 00:00:00 2001 From: Conor Edmonds Date: Thu, 25 Jun 2026 18:11:43 -0400 Subject: [PATCH] switching up some more clicking --- HoverableNode.cs | 10 +++++----- Peg.cs | 19 ------------------- PegController.cs | 40 ++++++++++++++++++++++------------------ Tower.cs | 7 ++++--- hostile_peg.tscn | 20 ++++++++++++++------ hoverable_node.tscn | 4 ++-- main.tscn | 2 +- peg.tscn | 5 +++++ tower.tscn | 8 ++++---- 9 files changed, 57 insertions(+), 58 deletions(-) diff --git a/HoverableNode.cs b/HoverableNode.cs index 9b201cb..f663ac2 100644 --- a/HoverableNode.cs +++ b/HoverableNode.cs @@ -18,18 +18,18 @@ public partial class HoverableNode : Node2D _bounds.MouseEntered += OnMouseEntered; _bounds.MouseExited += OnMouseExited; } - - public override void _Input(InputEvent @event) + public override void _Process(double delta) { + base._Process(delta); if (_hovered) { - if (Input.IsActionJustReleased("lmb")) + if (Input.IsActionJustPressed("leftClick")) { EmitSignal(SignalName.Click, this, 0); } - if (Input.IsActionJustReleased("rmb")) + if (Input.IsActionJustPressed("rightClick")) { - EmitSignal(SignalName.Click, this, 1); + EmitSignal(SignalName.Click, this, 2); } } } diff --git a/Peg.cs b/Peg.cs index 50f2277..dd7ce47 100644 --- a/Peg.cs +++ b/Peg.cs @@ -7,10 +7,6 @@ public partial class Peg : HoverableNode { [Signal] public delegate void DeathEventHandler(Peg THIS); - [Signal] - public delegate void ClickedEventHandler(Peg THIS); - [Signal] - public delegate void RightClickedEventHandler(Peg THIS); public bool _track = false, _warp = false; public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _attackCost = 1; public Dictionary _priorities = new() @@ -29,21 +25,6 @@ public partial class Peg : HoverableNode base._Ready(); _attack = GetNode("Attack"); } - public override void _Process(double delta) - { - base._Process(delta); - if (_hovered) - { - if (Input.IsActionJustPressed("leftClick")) - { - EmitSignal(SignalName.Clicked, this); - } - if (Input.IsActionJustPressed("rightClick")) - { - EmitSignal(SignalName.RightClicked, this); - } - } - } public void Attack() { // _attack.Visible = true; diff --git a/PegController.cs b/PegController.cs index 1360a8f..7414fab 100644 --- a/PegController.cs +++ b/PegController.cs @@ -20,8 +20,7 @@ public partial class PegController : TurnController { HostilePeg newHostilePeg = _hostilePegScene.Instantiate(); newHostilePeg.Death += HandlePegRemoval; - newHostilePeg.Clicked += HandlePegClick; - newHostilePeg.RightClicked += HandlePegRightClick; + newHostilePeg.Click += HandlePegClick; newHostilePeg._stamina = Globals._rng.Next(2,4+1); newHostilePeg.Modulate = new Color(newHostilePeg._stamina == 2 ? "#FF0000" : newHostilePeg._stamina == 3 ? "#00FF00" : "#0000FF"); @@ -39,8 +38,7 @@ public partial class PegController : TurnController { HostilePeg newHostilePeg = _hostilePegScene.Instantiate(); newHostilePeg.Death += HandlePegRemoval; - newHostilePeg.Clicked += HandlePegClick; - newHostilePeg.RightClicked += HandlePegRightClick; + newHostilePeg.Click += HandlePegClick; newHostilePeg._stamina = Globals._rng.Next(2,4+1); newHostilePeg._hitRange = Globals._rng.Next(1,2+1); @@ -95,25 +93,31 @@ public partial class PegController : TurnController } - public void HandlePegClick(Peg PEG) + public void HandlePegClick(Node CLICKED_NODE, int CLICK_TYPE) { - if (PEG._staminaRemaining <= 0){ + if (CLICKED_NODE is not Peg peg) + { return; } - TileMapLayer pathLayer = _playArea.GetNode("PathLayer"); - List newPath = PEG.GetBestPath(); - - - pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4)); - for (int i = 0; i < newPath.Count; i++) + if (CLICK_TYPE == 0) { - pathLayer.SetCell(newPath[i],0,Vector2I.One); - } - } + if (peg._staminaRemaining <= 0){ + return; + } + TileMapLayer pathLayer = _playArea.GetNode("PathLayer"); + List newPath = peg.GetBestPath(); - public void HandlePegRightClick(Peg PEG) - { - HandlePegRemoval(PEG); + + pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4)); + for (int i = 0; i < newPath.Count; i++) + { + pathLayer.SetCell(newPath[i],0,Vector2I.One); + } + } + else if (CLICK_TYPE == 2) + { + HandlePegRemoval(peg); + } } public void HandlePegPathing(Peg PEG) diff --git a/Tower.cs b/Tower.cs index afced0a..ec9b524 100644 --- a/Tower.cs +++ b/Tower.cs @@ -3,9 +3,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; -public partial class Tower : Sprite2D +public partial class Tower : HoverableNode { - public bool _hovered, _aiming; + public bool _aiming; public int _launchSpeed = 1000, _arcIterations = 50; public Vector2 _aimOffset, _arcEnd; public List _arc = new(); @@ -16,9 +16,9 @@ public partial class Tower : Sprite2D { base._Ready(); - _area = GetNode("Area"); _offset = GetNode("Offset"); _attackSpawn = GetNode("AttackSpawn"); + // Click += HandleClick; } public override void _Process(double delta) { @@ -56,6 +56,7 @@ public partial class Tower : Sprite2D } } } + } public float CalculateLaunchAngle(Vector2 START, Vector2 END, int MAX_ITERATIONS = 20) diff --git a/hostile_peg.tscn b/hostile_peg.tscn index 1bf68b1..dbe872d 100644 --- a/hostile_peg.tscn +++ b/hostile_peg.tscn @@ -1,8 +1,8 @@ [gd_scene format=3 uid="uid://drt7w0eqp13tu"] -[ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://HostilePeg.cs" id="1_4gyqm"] -[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="1_7k104"] -[ext_resource type="Texture2D" uid="uid://m4wfj36twmqy" path="res://Art/attack.png" id="3_qi2p4"] +[ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://HostilePeg.cs" id="1_nc8fp"] +[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_0icqg"] +[ext_resource type="Texture2D" uid="uid://m4wfj36twmqy" path="res://Art/attack.png" id="3_en3ow"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"] bounce = 0.5 @@ -10,10 +10,13 @@ bounce = 0.5 [sub_resource type="CircleShape2D" id="CircleShape2D_4gyqm"] radius = 12.5 +[sub_resource type="CircleShape2D" id="CircleShape2D_6w6fg"] +radius = 12.5 + [node name="HostilePeg" type="StaticBody2D" unique_id=1417697759] input_pickable = true physics_material_override = SubResource("PhysicsMaterial_7k104") -script = ExtResource("1_4gyqm") +script = ExtResource("1_nc8fp") [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1762191899] shape = SubResource("CircleShape2D_4gyqm") @@ -21,12 +24,17 @@ shape = SubResource("CircleShape2D_4gyqm") [node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605] texture_filter = 1 scale = Vector2(0.5, 0.5) -texture = ExtResource("1_7k104") +texture = ExtResource("2_0icqg") [node name="Attack" type="Sprite2D" parent="." unique_id=1776738311] visible = false texture_filter = 1 -texture = ExtResource("3_qi2p4") +texture = ExtResource("3_en3ow") + +[node name="HoverBounds" type="Area2D" parent="." unique_id=937525982] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=2142666816] +shape = SubResource("CircleShape2D_6w6fg") [connection signal="mouse_entered" from="." to="." method="OnMouseEntered"] [connection signal="mouse_exited" from="." to="." method="OnMouseExited"] diff --git a/hoverable_node.tscn b/hoverable_node.tscn index 97bcdc4..8848f54 100644 --- a/hoverable_node.tscn +++ b/hoverable_node.tscn @@ -5,6 +5,6 @@ [node name="HoverableNode" type="Node2D" unique_id=946672764] script = ExtResource("1_14v3m") -[node name="Bounds" type="Area2D" parent="." unique_id=783465962] +[node name="HoverBounds" type="Area2D" parent="." unique_id=783465962] -[node name="CollisionShape2D" type="CollisionShape2D" parent="Bounds" unique_id=585114419] +[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=585114419] diff --git a/main.tscn b/main.tscn index fc5769f..6348e46 100644 --- a/main.tscn +++ b/main.tscn @@ -12,7 +12,7 @@ script = ExtResource("1_ig7tw") [node name="PlayArea" parent="." unique_id=1123610167 instance=ExtResource("2_1bvp3")] position = Vector2(360, 180) -[node name="EnemyController" parent="." unique_id=1894449838 instance=ExtResource("4_1bvp3")] +[node name="PegController" parent="." unique_id=1894449838 instance=ExtResource("4_1bvp3")] [node name="PlayerController" parent="." unique_id=364781168 instance=ExtResource("4_lquwl")] diff --git a/peg.tscn b/peg.tscn index 5d1b747..ddaa58f 100644 --- a/peg.tscn +++ b/peg.tscn @@ -28,5 +28,10 @@ visible = false texture_filter = 1 texture = ExtResource("3_inmy4") +[node name="HoverBounds" type="Area2D" parent="." unique_id=2086452813] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=252175102] +shape = SubResource("CircleShape2D_4gyqm") + [connection signal="mouse_entered" from="." to="." method="OnMouseEntered"] [connection signal="mouse_exited" from="." to="." method="OnMouseExited"] diff --git a/tower.tscn b/tower.tscn index bfcc8bd..69c1288 100644 --- a/tower.tscn +++ b/tower.tscn @@ -11,9 +11,9 @@ self_modulate = Color(0, 0, 0, 1) texture = ExtResource("1_vedim") script = ExtResource("1_k1sas") -[node name="Area" type="Area2D" parent="." unique_id=620986087] +[node name="HoverBounds" type="Area2D" parent="." unique_id=620986087] -[node name="Bounds" type="CollisionShape2D" parent="Area" unique_id=1639875880] +[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=1639875880] position = Vector2(0, 0.5) shape = SubResource("RectangleShape2D_vedim") debug_color = Color(0.6411928, 0.52469516, 0, 0.41960785) @@ -24,5 +24,5 @@ position = Vector2(25, -50) [node name="AttackSpawn" type="Marker2D" parent="." unique_id=715904909] position = Vector2(0, -24) -[connection signal="mouse_entered" from="Area" to="." method="OnMouseEntered"] -[connection signal="mouse_exited" from="Area" to="." method="OnMouseExited"] +[connection signal="mouse_entered" from="HoverBounds" to="." method="OnMouseEntered"] +[connection signal="mouse_exited" from="HoverBounds" to="." method="OnMouseExited"]