From f46fc5612f2b78968353d87b91429fc5fb7cc9e1 Mon Sep 17 00:00:00 2001 From: root <> Date: Sat, 5 Oct 2024 08:51:38 -0700 Subject: [PATCH] Started work on contract selection, needs to be finished --- project.godot | 5 +++++ scenes/contract.tscn | 34 +++++++++++++++++++++------------- scenes/contract_giver.tscn | 23 +++++++++++++---------- scripts/contract.gd | 20 ++++++++++++++++++++ scripts/interactable.gd | 4 ++++ scripts/player.gd | 2 ++ 6 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 scripts/contract.gd diff --git a/project.godot b/project.godot index 6a0a820..5dc5a56 100644 --- a/project.godot +++ b/project.godot @@ -50,6 +50,11 @@ right={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +interact={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +] +} [rendering] diff --git a/scenes/contract.tscn b/scenes/contract.tscn index 97ed179..84a5378 100644 --- a/scenes/contract.tscn +++ b/scenes/contract.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=5 format=3 uid="uid://cn41xqc3lwaxy"] +[gd_scene load_steps=6 format=3 uid="uid://cn41xqc3lwaxy"] +[ext_resource type="Script" path="res://scripts/contract.gd" id="1_esxg1"] [ext_resource type="Texture2D" uid="uid://bnqe06njx2agc" path="res://sprites/contract.png" id="1_jwp1o"] [ext_resource type="Theme" uid="uid://d0ir0t347wqv7" path="res://etc/default_theme.tres" id="1_m2twt"] [ext_resource type="PackedScene" uid="uid://dpwqurhly8osd" path="res://scenes/interactible_manager.tscn" id="3_khqae"] @@ -7,17 +8,21 @@ [sub_resource type="CircleShape2D" id="CircleShape2D_mxuxo"] radius = 217.993 -[node name="Contract" type="Area2D"] +[node name="Contract" type="Area2D" node_paths=PackedStringArray("DestinationLabel", "InteractibleManager")] +script = ExtResource("1_esxg1") +Destination = "20th Burnaby" +DestinationLabel = NodePath("Control/LabelPanel/Label") +InteractibleManager = NodePath("InteractibleManager") -[node name="LabelPanel" type="Panel" parent="."] +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_top = -308.485 +offset_right = 40.0 +offset_bottom = -268.485 + +[node name="LabelPanel" type="PanelContainer" parent="Control"] z_index = 10 -offset_left = -313.0 -offset_top = -342.0 -offset_right = 369.0 -offset_bottom = -242.0 -theme = ExtResource("1_m2twt") - -[node name="Label" type="Label" parent="LabelPanel"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -25,10 +30,13 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 theme = ExtResource("1_m2twt") -text = "20th Burnaby Lane - $300" + +[node name="Label" type="Label" parent="Control/LabelPanel"] +layout_mode = 2 +theme = ExtResource("1_m2twt") +text = "20th Burnaby" horizontal_alignment = 1 vertical_alignment = 1 -clip_text = true uppercase = true metadata/_edit_lock_ = true @@ -39,7 +47,7 @@ texture = ExtResource("1_jwp1o") shape = SubResource("CircleShape2D_mxuxo") [node name="InteractibleManager" parent="." node_paths=PackedStringArray("ItemShown") instance=ExtResource("3_khqae")] -ItemShown = NodePath("../LabelPanel") +ItemShown = NodePath("../Control/LabelPanel") [connection signal="body_entered" from="." to="InteractibleManager" method="_on_body_entered"] [connection signal="body_exited" from="." to="InteractibleManager" method="_on_body_exited"] diff --git a/scenes/contract_giver.tscn b/scenes/contract_giver.tscn index 0bcc77c..3ba2e3b 100644 --- a/scenes/contract_giver.tscn +++ b/scenes/contract_giver.tscn @@ -17,15 +17,14 @@ size = Vector2(409, 181) texture = ExtResource("1_awtl7") metadata/_edit_lock_ = true -[node name="LabelPanel" type="Panel" parent="."] -z_index = 10 -offset_left = -313.0 -offset_top = -342.0 -offset_right = 369.0 -offset_bottom = -242.0 -theme = ExtResource("2_v5tdy") +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_top = -256.34 +offset_bottom = -256.34 -[node name="Label" type="Label" parent="LabelPanel"] +[node name="LabelPanel" type="PanelContainer" parent="Control"] +z_index = 10 layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -33,10 +32,13 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 theme = ExtResource("2_v5tdy") + +[node name="Label" type="Label" parent="Control/LabelPanel"] +layout_mode = 2 +theme = ExtResource("2_v5tdy") text = "HeLLO DEAR EMPLOYEE" horizontal_alignment = 1 vertical_alignment = 1 -clip_text = true uppercase = true metadata/_edit_lock_ = true @@ -54,6 +56,7 @@ metadata/_edit_lock_ = true [node name="Contract" parent="." instance=ExtResource("2_kh0dp")] position = Vector2(-498, 747) +Destination = "1263 30th Ave SE Courier Way" [node name="Contract2" parent="." instance=ExtResource("2_kh0dp")] position = Vector2(113, 753) @@ -62,7 +65,7 @@ position = Vector2(113, 753) position = Vector2(710, 753) [node name="InteractibleManager" parent="." node_paths=PackedStringArray("ItemShown") instance=ExtResource("4_1m1bm")] -ItemShown = NodePath("../LabelPanel") +ItemShown = NodePath("../Control/LabelPanel") [connection signal="body_entered" from="." to="InteractibleManager" method="_on_body_entered"] [connection signal="body_exited" from="." to="InteractibleManager" method="_on_body_exited"] diff --git a/scripts/contract.gd b/scripts/contract.gd new file mode 100644 index 0000000..6b82d3b --- /dev/null +++ b/scripts/contract.gd @@ -0,0 +1,20 @@ +extends Area2D + +@export var Destination : String +@export var DestinationLabel : Label + +@export var InteractibleManager : Node + +var Player : Node2D + + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + DestinationLabel.text = Destination + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + if Input.is_action_pressed("interact") and InteractibleManager.selected: + Player.ActiveContract = Destination diff --git a/scripts/interactable.gd b/scripts/interactable.gd index a00e74f..6e0e28d 100644 --- a/scripts/interactable.gd +++ b/scripts/interactable.gd @@ -2,6 +2,8 @@ extends Node @export var ItemShown : Control +var selected = false + # Called when the node enters the scene tree for the first time. func _ready() -> void: ItemShown.hide() @@ -16,7 +18,9 @@ func _process(delta: float) -> void: func _on_body_entered(body: Node2D) -> void: if body.is_in_group("player"): ItemShown.show() + selected = true func _on_body_exited(body: Node2D) -> void: if body.is_in_group("player"): ItemShown.hide() + selected = false diff --git a/scripts/player.gd b/scripts/player.gd index 680efbc..4120c42 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -6,6 +6,8 @@ extends CharacterBody2D @export var Sprite : Sprite2D var SpriteTurningSpeed = 5 +var ActiveContract : Node2D + # Called when the node enters the scene tree for the first time. func _ready() -> void: