From 8322f6e334cf17cd808c7e363873bab7a69e149c Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Thu, 29 Jun 2023 22:19:58 +0200 Subject: [PATCH 1/3] added dragging cards and post its with mouse input --- src/logic-scenes/board/card.gd | 12 +++ src/logic-scenes/board/card.tscn | 6 +- src/logic-scenes/board/physics-board.tscn | 96 +++++++++++++++-------- src/logic-scenes/board/post-it.gd | 12 +++ src/logic-scenes/board/post-it.tscn | 9 ++- 5 files changed, 95 insertions(+), 40 deletions(-) diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index e11c46d..ba79b64 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -48,6 +48,7 @@ var scale_tween wiggle_intensity = 0 @export var voice_line: AudioStream = null +@export var is_dragable: bool = false func _ready(): _handle_wiggle(0) @@ -88,3 +89,14 @@ func _on_focus_entered(): func _on_focus_exited(): print(self, "is not focused") + +func _on_mouse_entered(): + highlighted = true + +func _on_mouse_exited(): + highlighted = false + +func _on_input_event(viewport, event, shape_idx): + if event is InputEventMouseMotion and Input.is_action_pressed("mouse_left") and is_dragable: + position += event.relative + diff --git a/src/logic-scenes/board/card.tscn b/src/logic-scenes/board/card.tscn index 331e38b..9ca91eb 100644 --- a/src/logic-scenes/board/card.tscn +++ b/src/logic-scenes/board/card.tscn @@ -198,6 +198,6 @@ offset_top = 148.0 offset_right = 140.0 offset_bottom = 188.0 -[node name="CollisionShape2D" type="CollisionShape2D" parent="."] -rotation = 1.5708 -shape = SubResource("CapsuleShape2D_foovg") +[connection signal="input_event" from="." to="." method="_on_input_event"] +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] diff --git a/src/logic-scenes/board/physics-board.tscn b/src/logic-scenes/board/physics-board.tscn index ea0e74a..4b1b0c5 100644 --- a/src/logic-scenes/board/physics-board.tscn +++ b/src/logic-scenes/board/physics-board.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=9 format=3 uid="uid://bnskiyx1sksww"] +[gd_scene load_steps=10 format=3 uid="uid://bnskiyx1sksww"] [ext_resource type="Texture2D" uid="uid://bi3xqdknw5tpe" path="res://logic-scenes/board/board-texture/Cork002_2K_Color.png" id="1_8brxc"] [ext_resource type="Shader" path="res://logic-scenes/board/physics-board.gdshader" id="1_ggnth"] [ext_resource type="Script" path="res://logic-scenes/board/card-board.gd" id="3_8v4c4"] [ext_resource type="PackedScene" uid="uid://dy5rd437h5hsw" path="res://logic-scenes/board/card.tscn" id="3_mg053"] [ext_resource type="PackedScene" uid="uid://bvowj4l8dtceu" path="res://dev-util/board of devs.tscn" id="4_sskx2"] +[ext_resource type="PackedScene" uid="uid://vkcdj8c3ytbq" path="res://logic-scenes/board/post-it.tscn" id="5_048k0"] [ext_resource type="Script" path="res://logic-scenes/board/bouncy-card.gd" id="6_gcxd7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_ttqei"] @@ -15,7 +16,7 @@ shader_parameter/tex = ExtResource("1_8brxc") [sub_resource type="CircleShape2D" id="CircleShape2D_x8rl2"] radius = 154.052 -[node name="Panel" type="PanelContainer"] +[node name="board" type="PanelContainer"] material = SubResource("ShaderMaterial_ttqei") clip_contents = true anchors_preset = 15 @@ -25,46 +26,79 @@ grow_horizontal = 2 grow_vertical = 2 size_flags_horizontal = 6 size_flags_vertical = 6 +mouse_filter = 1 script = ExtResource("3_8v4c4") [node name="HBoxContainer" type="HBoxContainer" parent="."] layout_mode = 2 -[node name="Panel" type="Panel" parent="HBoxContainer"] +[node name="dropzone" type="Panel" parent="HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 +mouse_filter = 1 -[node name="Control" type="Control" parent="HBoxContainer/Panel"] -anchors_preset = 0 -offset_left = 305.0 -offset_top = 463.0 -offset_right = 305.0 -offset_bottom = 463.0 +[node name="card3" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")] +z_as_relative = false +position = Vector2(371, 290) +rotation = 0.00712087 +collision_layer = 2147483649 -[node name="card3" parent="HBoxContainer/Panel/Control" instance=ExtResource("3_mg053")] -offset_left = 0.0 -offset_top = 0.0 -offset_right = 0.0 -offset_bottom = 0.0 +[node name="card" parent="HBoxContainer/dropzone" instance=ExtResource("3_mg053")] +position = Vector2(640, 659) +rotation = 0.0714344 +scale = Vector2(1, 1) +is_dragable = true -[node name="VBoxContainer3" type="VBoxContainer" parent="HBoxContainer"] +[node name="ScrollContainer" type="ScrollContainer" parent="HBoxContainer"] layout_mode = 2 -size_flags_horizontal = 8 - -[node name="CenterContainer" type="ScrollContainer" parent="HBoxContainer/VBoxContainer3"] -layout_mode = 2 -size_flags_vertical = 3 horizontal_scroll_mode = 0 -[node name="post-ancor" type="Panel" parent="HBoxContainer/VBoxContainer3/CenterContainer"] -custom_minimum_size = Vector2(320, 110) +[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer/ScrollContainer"] layout_mode = 2 +[node name="Panel" type="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer"] +custom_minimum_size = Vector2(400, 120) +layout_mode = 2 +mouse_filter = 1 + +[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel" instance=ExtResource("5_048k0")] +z_index = 1 +position = Vector2(105, 57) +is_dragable = true + +[node name="Panel2" type="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer"] +custom_minimum_size = Vector2(400, 120) +layout_mode = 2 +mouse_filter = 1 + +[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel2" instance=ExtResource("5_048k0")] +position = Vector2(105, 57) +is_dragable = true + +[node name="Panel3" type="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer"] +custom_minimum_size = Vector2(400, 120) +layout_mode = 2 +mouse_filter = 1 + +[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel3" instance=ExtResource("5_048k0")] +position = Vector2(105, 57) +is_dragable = true + +[node name="Panel4" type="Panel" parent="HBoxContainer/ScrollContainer/VBoxContainer"] +custom_minimum_size = Vector2(400, 120) +layout_mode = 2 +mouse_filter = 1 + +[node name="post-it" parent="HBoxContainer/ScrollContainer/VBoxContainer/Panel4" instance=ExtResource("5_048k0")] +position = Vector2(105, 57) +is_dragable = true + [node name="board of devs" parent="." instance=ExtResource("4_sskx2")] visible = false layout_mode = 2 [node name="Node2D" type="Node2D" parent="."] +visible = false [node name="RigidBody2D" type="Area2D" parent="Node2D"] position = Vector2(686, 379) @@ -77,10 +111,8 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D/ancor" instance=ExtResource("3_mg053")] -offset_left = 0.0 -offset_top = 0.0 -offset_right = 0.0 -offset_bottom = 0.0 +rotation = -0.0180459 +collision_layer = 2 [node name="RigidBody2D2" type="Area2D" parent="Node2D"] position = Vector2(742, 323) @@ -93,10 +125,8 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D2/ancor" instance=ExtResource("3_mg053")] -offset_left = 0.0 -offset_top = 0.0 -offset_right = 0.0 -offset_bottom = 0.0 +rotation = 0.0612526 +collision_layer = 2 [node name="RigidBody2D3" type="Area2D" parent="Node2D"] position = Vector2(694, 353) @@ -109,7 +139,5 @@ shape = SubResource("CircleShape2D_x8rl2") position = Vector2(-151, -107) [node name="card2" parent="Node2D/RigidBody2D3/ancor" instance=ExtResource("3_mg053")] -offset_left = 0.0 -offset_top = 0.0 -offset_right = 0.0 -offset_bottom = 0.0 +rotation = 0.0528008 +collision_layer = 2 diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index b314d85..b5cad59 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -45,6 +45,7 @@ var modulate_tween wiggle_intensity = 0 @export var voice_line: AudioStream = null +@export var is_dragable: bool = false func _ready() -> void: $Content/Label.text = self.text @@ -64,3 +65,14 @@ func _on_focus_entered(): func _on_focus_exited(): print(self, "is not focused") + +func _on_mouse_entered(): + #owner.grab_highlight(self) + highlighted = true + +func _on_mouse_exited(): + highlighted = false + +func _on_input_event(viewport, event, shape_idx): + if event is InputEventMouseMotion and Input.is_action_pressed("mouse_left") and is_dragable: + position += event.relative diff --git a/src/logic-scenes/board/post-it.tscn b/src/logic-scenes/board/post-it.tscn index c4fc3f2..15f49b0 100644 --- a/src/logic-scenes/board/post-it.tscn +++ b/src/logic-scenes/board/post-it.tscn @@ -102,8 +102,8 @@ animations = [{ [node name="post-it" type="Area2D"] script = ExtResource("1_yvh5n") -text = "Test" highlight_color = Color(1.2, 1.2, 1.2, 1) +is_dragable = null [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(99.5, 0) @@ -116,7 +116,7 @@ shape = SubResource("CapsuleShape2D_ml4q7") position = Vector2(99.5, 0) scale = Vector2(0.65, 0.65) sprite_frames = SubResource("SpriteFrames_2amsi") -frame = 1 +frame = 5 [node name="Label" type="Label" parent="Content"] anchors_preset = 8 @@ -132,6 +132,9 @@ grow_horizontal = 2 grow_vertical = 2 theme = ExtResource("3_hu2as") theme_type_variation = &"card_text" -text = "Test" vertical_alignment = 1 autowrap_mode = 3 + +[connection signal="input_event" from="." to="." method="_on_input_event"] +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] From 1dae8286cf24ba976cbdcde7680cb729aaa2af6c Mon Sep 17 00:00:00 2001 From: Adrian Schmid Date: Thu, 29 Jun 2023 22:29:55 +0200 Subject: [PATCH 2/3] fixed missing collider on cards --- src/logic-scenes/board/card.tscn | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/logic-scenes/board/card.tscn b/src/logic-scenes/board/card.tscn index 9ca91eb..89f6a60 100644 --- a/src/logic-scenes/board/card.tscn +++ b/src/logic-scenes/board/card.tscn @@ -6,6 +6,10 @@ [ext_resource type="Theme" uid="uid://b056fn288p8ha" path="res://logic-scenes/themes/messy.theme" id="3_rktsa"] [ext_resource type="Texture2D" uid="uid://bqilajx05t0eb" path="res://logic-scenes/board/particle_textures/void_nomotion.png" id="4_fwm1k"] +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_foovg"] +radius = 110.0 +height = 336.0 + [sub_resource type="AtlasTexture" id="AtlasTexture_ykk13"] atlas = ExtResource("2_ioijn") region = Rect2(0, 0, 600, 440) @@ -141,19 +145,19 @@ func _process(_delta): self.visible = State.reduce_motion and is_void " -[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_foovg"] -radius = 110.0 -height = 336.0 - [node name="card" type="Area2D"] -rotation = 0.197177 +rotation = -0.0714123 script = ExtResource("1_emip0") +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-0.0713516, 0.997451) +rotation = 1.5708 +shape = SubResource("CapsuleShape2D_foovg") + [node name="BackgroundSprite" type="AnimatedSprite2D" parent="."] clip_children = 2 scale = Vector2(0.6, 0.6) sprite_frames = SubResource("SpriteFrames_ckivt") -frame = 3 script = SubResource("GDScript_8bs16") [node name="GPUParticles2D" type="GPUParticles2D" parent="BackgroundSprite"] From ef93aafd9ef7cb787fbc6d1464b063dac3362d01 Mon Sep 17 00:00:00 2001 From: betalars Date: Fri, 30 Jun 2023 00:53:16 +0200 Subject: [PATCH 3/3] improving parsing and passing of mouse events --- src/logic-scenes/board/card.gd | 15 +++++++++++++-- src/logic-scenes/board/post-it.gd | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index ba79b64..0516a92 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -49,6 +49,7 @@ var scale_tween @export var voice_line: AudioStream = null @export var is_dragable: bool = false +var is_dragged: bool = false func _ready(): _handle_wiggle(0) @@ -91,12 +92,22 @@ func _on_focus_exited(): print(self, "is not focused") func _on_mouse_entered(): - highlighted = true + if not Input.is_action_pressed("mouse_left"): + highlighted = true + if "handle_hover" in owner: + owner.handle_hover(self) func _on_mouse_exited(): highlighted = false func _on_input_event(viewport, event, shape_idx): - if event is InputEventMouseMotion and Input.is_action_pressed("mouse_left") and is_dragable: + if event is InputEventMouseMotion and is_dragged: position += event.relative + + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_LEFT: + if is_dragable: + is_dragged = event.pressed + if "handle_mouse_button" in owner: + owner.handle_mouse_button(self, event) diff --git a/src/logic-scenes/board/post-it.gd b/src/logic-scenes/board/post-it.gd index b5cad59..c9f705c 100644 --- a/src/logic-scenes/board/post-it.gd +++ b/src/logic-scenes/board/post-it.gd @@ -46,6 +46,7 @@ var modulate_tween @export var voice_line: AudioStream = null @export var is_dragable: bool = false +var is_dragged = false func _ready() -> void: $Content/Label.text = self.text @@ -67,12 +68,21 @@ func _on_focus_exited(): print(self, "is not focused") func _on_mouse_entered(): - #owner.grab_highlight(self) - highlighted = true + if not Input.is_action_pressed("mouse_left"): + highlighted = true + if "handle_hover" in owner: + owner.handle_hover(self) func _on_mouse_exited(): highlighted = false func _on_input_event(viewport, event, shape_idx): - if event is InputEventMouseMotion and Input.is_action_pressed("mouse_left") and is_dragable: + if event is InputEventMouseMotion and is_dragged: position += event.relative + + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_LEFT: + if is_dragable: + is_dragged = event.pressed + if "handle_mouse_button" in owner: + owner.handle_mouse_button(self, event)