diff --git a/dialog/main.json b/dialog/main.json new file mode 100644 index 0000000..67f8b33 --- /dev/null +++ b/dialog/main.json @@ -0,0 +1,7 @@ +{ + "cupcake":[ + "this is a test string...", + "It looks delicious!", + "Eat it when its an finished item!" + ] +} \ No newline at end of file diff --git a/project.godot b/project.godot index 8f4dc51..e497f8f 100644 --- a/project.godot +++ b/project.godot @@ -18,6 +18,7 @@ config/icon="res://icon.svg" [autoload] Essential="*res://src/essential.cs" +SignalBus="*res://src/signal_bus.cs" [display] @@ -80,3 +81,8 @@ hotkey_fullscreen={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194342,"physical_keycode":0,"unicode":0,"echo":false,"script":null) ] } + +[layer_names] + +2d_physics/layer_1="World" +2d_physics/layer_2="Dialog" diff --git a/scenes/gui/dialog_object_area.tscn b/scenes/gui/dialog_object_area.tscn new file mode 100644 index 0000000..2c3c018 --- /dev/null +++ b/scenes/gui/dialog_object_area.tscn @@ -0,0 +1,14 @@ +[gd_scene load_steps=2 format=3 uid="uid://d14pjtkh0xmrk"] + +[ext_resource type="Script" path="res://src/scene-scripts/gui/dialog_object_area.cs" id="1_ttc4e"] + +[node name="dialog_area" type="Area2D"] +process_mode = 2 +collision_layer = 0 +collision_mask = 2 +script = ExtResource("1_ttc4e") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +[connection signal="area_entered" from="." to="." method="onAreaEntered"] +[connection signal="area_exited" from="." to="." method="onAreaExited"] diff --git a/scenes/player.tscn b/scenes/player.tscn index 7921336..8728d86 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://ujfhvssvbgpg"] +[gd_scene load_steps=6 format=3 uid="uid://ujfhvssvbgpg"] [ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"] [ext_resource type="Texture2D" uid="uid://ciidukjv5k6oa" path="res://assets/textures/debug/banana.png" id="2_1l1co"] @@ -15,6 +15,9 @@ animations = [{ radius = 21.0 height = 66.0 +[sub_resource type="RectangleShape2D" id="RectangleShape2D_f1ppa"] +size = Vector2(108, 119) + [node name="player" type="CharacterBody2D"] script = ExtResource("1_qehox") @@ -26,3 +29,11 @@ shape = SubResource("CapsuleShape2D_38v5o") [node name="Camera2D" type="Camera2D" parent="."] current = true + +[node name="DialogInteractArea" type="Area2D" parent="."] +collision_layer = 2 +collision_mask = 0 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="DialogInteractArea"] +position = Vector2(0, -0.5) +shape = SubResource("RectangleShape2D_f1ppa") diff --git a/src/scene-scripts/gui/dialog_object_area.cs b/src/scene-scripts/gui/dialog_object_area.cs new file mode 100644 index 0000000..1cdcb52 --- /dev/null +++ b/src/scene-scripts/gui/dialog_object_area.cs @@ -0,0 +1,26 @@ +using Godot; +using System; +using System.Runtime.CompilerServices; + +public partial class dialog_object_area : Area2D +{ + [Export] + public string dialogKey = ""; + public bool areaActive = false; + + public override void _Input(InputEvent @event) + { + if(areaActive && @event.IsActionPressed("ui_accept")) + { + EmitSignal("DialogDisplayEventHandler", dialogKey); + } + } + public void onAreaEntered() + { + areaActive = true; + } + public void onAreaExited() + { + areaActive = false; + } +} diff --git a/src/signal_bus.cs b/src/signal_bus.cs new file mode 100644 index 0000000..efd3804 --- /dev/null +++ b/src/signal_bus.cs @@ -0,0 +1,8 @@ +using Godot; +using System; + +public partial class signal_bus : Node +{ + [Signal] + public delegate void DialogDisplayEventHandler(string textKey); +}