diff --git a/addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd b/addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd index cf642ed..141a7c5 100644 --- a/addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd +++ b/addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd @@ -51,8 +51,6 @@ func _update_icon(): func _process(delta: float) -> void: _time_until_next_check -= delta - print(input_icon.using_gamepad) - if _time_until_next_check < 0: _time_until_next_check = 0.2 diff --git a/project.godot b/project.godot index e8a557b..a1b0395 100644 --- a/project.godot +++ b/project.godot @@ -34,10 +34,25 @@ enabled=PackedStringArray("res://addons/godot_super-wakatime/plugin.cfg", "res:/ [gui] +theme/custom="uid://dtc7h6gpwpend" theme/custom_font="uid://n1nd5m2kwexu" [input] +ui_select={ +"deadzone": 0.5, +"events": [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":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null) +] +} +ui_up={ +"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":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) +] +} turn_left={ "deadzone": 0.2, "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":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) @@ -146,6 +161,13 @@ limbo_console_search_history={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":82,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +dialogue_continue={ +"deadzone": 0.2, +"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":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null) +] +} [physics] diff --git a/scenes/dialogue_select_button.tscn b/scenes/dialogue_select_button.tscn new file mode 100644 index 0000000..e2ac0ab --- /dev/null +++ b/scenes/dialogue_select_button.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=3 format=3 uid="uid://dhcfrsf726k68"] + +[ext_resource type="Theme" uid="uid://dtc7h6gpwpend" path="res://scenes/ui.tres" id="1_m4r5t"] +[ext_resource type="Script" uid="uid://dco3p5546nyhx" path="res://scripts/dialogue_select_button.gd" id="2_27vbl"] + +[node name="DialogueSelectButton" type="Button"] +theme = ExtResource("1_m4r5t") +text = "test" +script = ExtResource("2_27vbl") + +[connection signal="pressed" from="." to="." method="_on_pressed"] diff --git a/scenes/ground.tscn b/scenes/ground.tscn index 06bf8f6..192ded5 100644 --- a/scenes/ground.tscn +++ b/scenes/ground.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=42 format=4 uid="uid://by43ihcec8e8q"] +[gd_scene load_steps=45 format=4 uid="uid://by43ihcec8e8q"] [ext_resource type="Script" uid="uid://b2sw6ymaf4t0s" path="res://scripts/game_ground.gd" id="1_6ra5r"] [ext_resource type="AudioStream" uid="uid://dgv01wy8r7ej2" path="res://sounds/uglyburger.mp3" id="2_5vwr8"] @@ -12,12 +12,14 @@ [ext_resource type="Texture2D" uid="uid://c8csobncvu3f0" path="res://textures/galactamart_worker.png" id="7_2c1ag"] [ext_resource type="Texture2D" uid="uid://cj5sjx1jhrah6" path="res://textures/wall_side_tile_center.png" id="7_26mqe"] [ext_resource type="Shader" uid="uid://d3hoh7ec2w8q7" path="res://scripts/outline.gdshader" id="7_vuhkc"] +[ext_resource type="Script" uid="uid://cireshybqi5oq" path="res://scripts/galactamart_worker.gd" id="8_e3s4u"] [ext_resource type="Shader" uid="uid://bk7q00br1ms30" path="res://scripts/retro.gdshader" id="9_257nh"] [ext_resource type="Script" uid="uid://dxkb8v7w4daw1" path="res://scripts/interact_area.gd" id="10_26mqe"] [ext_resource type="Script" uid="uid://khas1kkt2t3k" path="res://scripts/exit_ship.gd" id="14_257nh"] [ext_resource type="Texture2D" uid="uid://b047lku56vtve" path="res://textures/galacta_counter.png" id="15_vuhkc"] [ext_resource type="Texture2D" uid="uid://dauoebs801ngm" path="res://addons/super_awesome_input_icons/textures/keyboard/question.png" id="16_e3s4u"] [ext_resource type="Script" uid="uid://b2maxk5g6yb0i" path="res://addons/super_awesome_input_icons/classes/input_icon_texture_rect.gd" id="16_hby33"] +[ext_resource type="PackedScene" uid="uid://dhcfrsf726k68" path="res://scenes/dialogue_select_button.tscn" id="19_qqas2"] [sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_gysiw"] light_mode = 1 @@ -175,8 +177,8 @@ height = 48.0 [sub_resource type="RectangleShape2D" id="RectangleShape2D_gysiw"] size = Vector2(40, 40) -[sub_resource type="LabelSettings" id="LabelSettings_c2suo"] -font_size = 48 +[sub_resource type="LabelSettings" id="LabelSettings_e3s4u"] +font_size = 32 outline_size = 4 outline_color = Color(0, 0, 0, 1) @@ -188,6 +190,11 @@ shader_parameter/pattern = 0 shader_parameter/inside = false shader_parameter/add_margins = true +[sub_resource type="LabelSettings" id="LabelSettings_c2suo"] +font_size = 48 +outline_size = 4 +outline_color = Color(0, 0, 0, 1) + [sub_resource type="ShaderMaterial" id="ShaderMaterial_ypt7u"] shader = ExtResource("9_257nh") shader_parameter/shake = 0.002000000095 @@ -222,6 +229,7 @@ tile_set = SubResource("TileSet_gysiw") [node name="GalactamartWorker" type="CharacterBody2D" parent="."] position = Vector2(-115, -894) +script = ExtResource("8_e3s4u") [node name="Sprite" type="AnimatedSprite2D" parent="GalactamartWorker"] scale = Vector2(-2, 2) @@ -237,6 +245,12 @@ interact_text = "TALK" [node name="CollisionShape" type="CollisionShape2D" parent="GalactamartWorker/InteractArea"] shape = SubResource("CircleShape2D_vuhkc") +[node name="Camera" type="Camera2D" parent="GalactamartWorker"] +position = Vector2(99, 0) +enabled = false +zoom = Vector2(2, 2) +position_smoothing_enabled = true + [node name="GalactaCounter" type="StaticBody2D" parent="."] position = Vector2(-64, -883) scale = Vector2(2, 2) @@ -290,6 +304,38 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +[node name="Dialogue" type="HFlowContainer" parent="UI/Control"] +custom_minimum_size = Vector2(640, 0) +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -46.0 +grow_horizontal = 2 +grow_vertical = 0 +alignment = 1 + +[node name="Label" type="Label" parent="UI/Control/Dialogue"] +layout_mode = 2 +text = "How may I help you?" +label_settings = SubResource("LabelSettings_e3s4u") +horizontal_alignment = 1 +vertical_alignment = 2 + +[node name="InputIcon" type="VFlowContainer" parent="UI/Control/Dialogue"] +layout_mode = 2 +alignment = 1 + +[node name="InputIcon" type="TextureRect" parent="UI/Control/Dialogue/InputIcon"] +material = SubResource("ShaderMaterial_jo68p") +custom_minimum_size = Vector2(32, 32) +layout_mode = 2 +texture = ExtResource("16_e3s4u") +expand_mode = 2 +script = ExtResource("16_hby33") +action_name = "dialogue_continue" + [node name="BoostText" type="Label" parent="UI/Control"] layout_mode = 0 offset_right = 40.0 @@ -336,6 +382,49 @@ layout_mode = 2 text = "TO INTERACT" label_settings = SubResource("LabelSettings_c2suo") +[node name="DialogueOptions" type="VBoxContainer" parent="UI/Control"] +custom_minimum_size = Vector2(128, 0) +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.7 +anchor_top = 0.5 +anchor_right = 0.9 +anchor_bottom = 0.5 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/separation = 8 + +[node name="HFlowContainer" type="HFlowContainer" parent="UI/Control/DialogueOptions"] +layout_mode = 2 +alignment = 1 + +[node name="InputIconTextureRect2" type="TextureRect" parent="UI/Control/DialogueOptions/HFlowContainer"] +custom_minimum_size = Vector2(32, 32) +layout_mode = 2 +expand_mode = 1 +script = ExtResource("16_hby33") +action_name = "ui_up" +metadata/_custom_type_script = "uid://b2maxk5g6yb0i" + +[node name="InputIconTextureRect3" type="TextureRect" parent="UI/Control/DialogueOptions/HFlowContainer"] +custom_minimum_size = Vector2(32, 32) +layout_mode = 2 +expand_mode = 1 +script = ExtResource("16_hby33") +action_name = "ui_down" +metadata/_custom_type_script = "uid://b2maxk5g6yb0i" + +[node name="InputIconTextureRect" type="TextureRect" parent="UI/Control/DialogueOptions/HFlowContainer"] +custom_minimum_size = Vector2(32, 32) +layout_mode = 2 +expand_mode = 1 +script = ExtResource("16_hby33") +action_name = "dialogue_continue" +metadata/_custom_type_script = "uid://b2maxk5g6yb0i" + +[node name="Button" parent="UI/Control/DialogueOptions" instance=ExtResource("19_qqas2")] +layout_mode = 2 + [node name="Shader" type="ColorRect" parent="UI"] material = SubResource("ShaderMaterial_ypt7u") anchors_preset = 15 @@ -343,6 +432,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 color = Color(1, 1, 1, 0) [node name="WorldEnvironment" type="WorldEnvironment" parent="."] diff --git a/scenes/ui.tres b/scenes/ui.tres new file mode 100644 index 0000000..93fa420 --- /dev/null +++ b/scenes/ui.tres @@ -0,0 +1,43 @@ +[gd_resource type="Theme" load_steps=4 format=3 uid="uid://dtc7h6gpwpend"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_mq06m"] +bg_color = Color(0, 0, 0, 1) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +border_color = Color(1, 1, 1, 1) +corner_detail = 1 +expand_margin_left = 2.0 +expand_margin_top = 2.0 +expand_margin_right = 2.0 +expand_margin_bottom = 2.0 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ue5e3"] +bg_color = Color(0, 0, 0, 1) +corner_detail = 1 +expand_margin_left = 2.0 +expand_margin_top = 2.0 +expand_margin_right = 2.0 +expand_margin_bottom = 2.0 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_oei2i"] +bg_color = Color(1, 1, 1, 1) +corner_detail = 1 +expand_margin_left = 2.0 +expand_margin_top = 2.0 +expand_margin_right = 2.0 +expand_margin_bottom = 2.0 + +[resource] +Button/colors/font_color = Color(0, 0, 0, 1) +Button/colors/font_focus_color = Color(1, 1, 1, 1) +Button/colors/font_hover_color = Color(1, 1, 1, 1) +Button/colors/font_hover_pressed_color = Color(0, 0, 0, 1) +Button/colors/font_pressed_color = Color(1, 1, 1, 1) +Button/font_sizes/font_size = 24 +Button/styles/focus = SubResource("StyleBoxFlat_mq06m") +Button/styles/hover = SubResource("StyleBoxFlat_mq06m") +Button/styles/hover_pressed = SubResource("StyleBoxFlat_ue5e3") +Button/styles/normal = SubResource("StyleBoxFlat_oei2i") +Button/styles/pressed = SubResource("StyleBoxFlat_ue5e3") diff --git a/scripts/dialogue_select_button.gd b/scripts/dialogue_select_button.gd new file mode 100644 index 0000000..c796868 --- /dev/null +++ b/scripts/dialogue_select_button.gd @@ -0,0 +1,11 @@ +extends Button + +var game = null + + +func _on_pressed() -> void: + get_tree().quit() + +func _input(event: InputEvent) -> void: + if has_focus() and (event.is_action_pressed("interact") or event.is_action_pressed("dialogue_continue")): + _on_pressed() diff --git a/scripts/dialogue_select_button.gd.uid b/scripts/dialogue_select_button.gd.uid new file mode 100644 index 0000000..9e3434a --- /dev/null +++ b/scripts/dialogue_select_button.gd.uid @@ -0,0 +1 @@ +uid://dco3p5546nyhx diff --git a/scripts/exit_ship.gd b/scripts/exit_ship.gd index 07b2bf2..0780681 100644 --- a/scripts/exit_ship.gd +++ b/scripts/exit_ship.gd @@ -1,4 +1,4 @@ extends Sprite2D -func _interact() -> void: +func _interact(_player: Node2D) -> void: get_tree().change_scene_to_file("res://scenes/game.tscn") diff --git a/scripts/galactamart_worker.gd b/scripts/galactamart_worker.gd new file mode 100644 index 0000000..c2ac373 --- /dev/null +++ b/scripts/galactamart_worker.gd @@ -0,0 +1,20 @@ +extends CharacterBody2D + +@onready var game = get_parent() + +func _interact(player: Node2D) -> void: + player.get_node("Camera").enabled = false + $Camera.enabled = true + $InteractArea.monitoring = false + + player.busy = true + + await game.dialogue("How may I help you?") + + await game.make_choice({ + "refuel": "Refuel ship", + "buy": "Buy items", + "exit": "Exit" + }) + + return diff --git a/scripts/galactamart_worker.gd.uid b/scripts/galactamart_worker.gd.uid new file mode 100644 index 0000000..eb8e565 --- /dev/null +++ b/scripts/galactamart_worker.gd.uid @@ -0,0 +1 @@ +uid://cireshybqi5oq diff --git a/scripts/game_ground.gd b/scripts/game_ground.gd index f4d2e1d..2515e18 100644 --- a/scripts/game_ground.gd +++ b/scripts/game_ground.gd @@ -1,9 +1,11 @@ extends Node2D var current_interaction_area = null +signal dialogue_continue +signal choice_made func _ready() -> void: - print(Input.get_joy_name(0)) + $UI/Control/Dialogue.visible = false func _process(delta: float) -> void: if current_interaction_area: @@ -11,6 +13,68 @@ func _process(delta: float) -> void: $UI/Control/Interact/End.text = "TO " + (current_interaction_area.interact_text) if Input.is_action_just_pressed("interact"): - if "_interact" in current_interaction_area.get_parent(): current_interaction_area.get_parent()._interact() + if "_interact" in current_interaction_area.get_parent(): current_interaction_area.get_parent()._interact($PlayerGround) else: $UI/Control/Interact.visible = false + +func dialogue(text: String) -> void: + $UI/Control/Dialogue/InputIcon.visible = false + $UI/Control/Dialogue.visible = true + + var displayed_text = "" + + var i = 0 + while i < text.length(): + displayed_text = displayed_text + text[i] + + $UI/Control/Dialogue/Label.text = displayed_text + + await get_tree().create_timer(0.05).timeout + + i += 1 + + $UI/Control/Dialogue/InputIcon.visible = true + + await dialogue_continue + + $UI/Control/Dialogue.visible = false + + return + +func make_choice(options: Dictionary = {}) -> void: + $UI/Control/DialogueOptions.visible = true + + $UI/Control/DialogueOptions/Button.grab_focus() + + var dialogue_select_button_scene = preload("res://scenes/dialogue_select_button.tscn") + + for n in $UI/Control/DialogueOptions.get_children(): if n.is_class("Button"): n.free() + + var first_button = null + var last_button = null + + for n in options.keys(): + var dialogue_select_button = dialogue_select_button_scene.instantiate() + + dialogue_select_button.name = n + dialogue_select_button.text = options[n] + + $UI/Control/DialogueOptions.add_child(dialogue_select_button) + + if !first_button: first_button = dialogue_select_button + last_button = dialogue_select_button + + first_button.focus_neighbor_top = NodePath(last_button.get_path()) + + last_button.focus_neighbor_bottom = NodePath(first_button.get_path()) + + first_button.grab_focus() + + await dialogue_continue + + return + +func _input(event: InputEvent) -> void: + if event.is_action_pressed("dialogue_continue"): + + dialogue_continue.emit() diff --git a/scripts/interact_area.gd b/scripts/interact_area.gd index da4a96c..7830aa7 100644 --- a/scripts/interact_area.gd +++ b/scripts/interact_area.gd @@ -7,8 +7,6 @@ func _ready() -> void: game = owner if game.owner != null: game = game.owner - - print(game) func _on_body_entered(body: Node2D) -> void: if body.get_name() == "PlayerGround": diff --git a/scripts/player_ground.gd b/scripts/player_ground.gd index eae2c49..9c826f4 100644 --- a/scripts/player_ground.gd +++ b/scripts/player_ground.gd @@ -1,5 +1,8 @@ extends CharacterBody2D +## Is the player busy in an interaction? +var busy = false + func _ready() -> void: $Sprite.play() @@ -7,7 +10,10 @@ func _process(delta: float) -> void: var horizontial_movement = Input.get_axis("ground_left", "ground_right") var vertical_movement = Input.get_axis("ground_up", "ground_down") - velocity = Vector2(256 * horizontial_movement, 256 * vertical_movement) + if busy: + velocity = Vector2() + else: + velocity = Vector2(256 * horizontial_movement, 256 * vertical_movement) if horizontial_movement > 0.1: $Sprite.scale.x = -2 if horizontial_movement < -0.1: