From 396d884ff0154cae18b7f7e4c25e6cf4cd6b0ad7 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 15 Nov 2024 13:09:38 +0100 Subject: [PATCH] Improved conversations and input blocking. --- objects/actionable.gd | 4 ---- objects/player.gd | 5 +++-- project.godot | 1 + quests/builder_missing_tool_quest.gd | 20 -------------------- root_ui.gd | 2 ++ scenes/game.gd | 1 - systems/InteractionSystem.gd | 26 ++++++++++++++++++++++++++ ui/dialogue/balloon.gd | 1 + 8 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 systems/InteractionSystem.gd diff --git a/objects/actionable.gd b/objects/actionable.gd index edfb1cf..82c80bb 100644 --- a/objects/actionable.gd +++ b/objects/actionable.gd @@ -1,8 +1,6 @@ class_name ConversationActionable extends Area3D -signal conversation_started - @export var dialogue_start: String = "start" @export var related_quest_path: NodePath @@ -25,5 +23,3 @@ func action() -> void: balloon.start(quest_dialogue_resource, dialogue_start, quest_states) else: balloon.start(default_dialogue_resource, dialogue_start, quest_states) - - conversation_started.emit() diff --git a/objects/player.gd b/objects/player.gd index f2b3b74..98fb41a 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -56,7 +56,9 @@ func _physics_process(delta): if not is_on_floor(): velocity.y -= gravity * delta - if not is_input_blocked: + if is_input_blocked: + velocity = Vector3.ZERO + else: _handle_input() move_and_slide() @@ -68,7 +70,6 @@ func _physics_process(delta): _target_look_direction = Vector3(velocity.x, 0, velocity.z).normalized() _current_look_direction = basis.z - #_target_look_direction = _current_look_direction update_look_direction(delta) diff --git a/project.godot b/project.godot index 25c7954..603e31b 100644 --- a/project.godot +++ b/project.godot @@ -18,6 +18,7 @@ config/icon="res://icon.svg" [autoload] DialogueManager="*res://addons/dialogue_manager/dialogue_manager.gd" +InteractionSystem="*res://systems/InteractionSystem.gd" [dialogue_manager] diff --git a/quests/builder_missing_tool_quest.gd b/quests/builder_missing_tool_quest.gd index a0e88d6..a5846ea 100644 --- a/quests/builder_missing_tool_quest.gd +++ b/quests/builder_missing_tool_quest.gd @@ -9,32 +9,12 @@ extends QuestBase @onready var merchant: NonPlayerCharacter = %Merchant var _bridge_transform:Transform3D = Transform3D.IDENTITY -var _merchant_conversation_actionable:ConversationActionable = null - -signal wrench_delivered func _ready(): super._ready() _bridge_transform = bridge.global_transform bridge.global_transform = Transform3D.IDENTITY.translated(Vector3.UP * -1000) - - _merchant_conversation_actionable = merchant.find_child("Conversation", true, false) - assert(_merchant_conversation_actionable != null) - _merchant_conversation_actionable.conversation_started.connect(on_dialogue_started) - -func on_dialogue_started() -> void: - _player.is_input_blocked = true - -func on_dialogue_ended(_dialog_resource: DialogueResource) -> void: - _player.is_input_blocked = false - - if is_completed: - return - - if is_hammer_delivered and not is_bridge_built: - wrench_delivered.emit() - func _process(_delta): if is_hammer_delivered: diff --git a/root_ui.gd b/root_ui.gd index 9b0bfa1..a7735e3 100644 --- a/root_ui.gd +++ b/root_ui.gd @@ -49,6 +49,8 @@ func load_scene(scene_resource:PackedScene): _game_build_system = scene.find_child("BuildSystem", true, false) as BuildSystem + var player:Player = scene.find_child("Player", true, false) + InteractionSystem.player = player func save_game(): var player:Player = scene.find_child("Player", true, false) diff --git a/scenes/game.gd b/scenes/game.gd index 32bd685..e46b9c0 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -12,7 +12,6 @@ var _player_camera_offset:Vector3 = Vector3.ZERO func _ready(): _player_camera_offset = camera.global_position - player.global_position + Vector3.UP * 1 - # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): if build_system.is_active and build_system.build_item != null: diff --git a/systems/InteractionSystem.gd b/systems/InteractionSystem.gd new file mode 100644 index 0000000..14f9efd --- /dev/null +++ b/systems/InteractionSystem.gd @@ -0,0 +1,26 @@ +extends Node + +signal conversation_started +signal conversation_stopped + +var is_conversation_active:bool = false +var player:Player = null + +func _ready(): + if not DialogueManager.is_connected("dialogue_ended", InteractionSystem.stop_conversation): + DialogueManager.connect("dialogue_ended", InteractionSystem.stop_conversation) + +func start_conversation(resource: DialogueResource) -> void: + is_conversation_active = true + print ("Conversation started") + emit_signal("conversation_started") + if player: + player.is_input_blocked = true + +func stop_conversation(resource: DialogueResource) -> void: + is_conversation_active = false + print ("Conversation stopped") + emit_signal("conversation_stopped") + + if player: + player.is_input_blocked = false diff --git a/ui/dialogue/balloon.gd b/ui/dialogue/balloon.gd index 3e58f44..8aa0e45 100644 --- a/ui/dialogue/balloon.gd +++ b/ui/dialogue/balloon.gd @@ -104,6 +104,7 @@ func start(dialogue_resource: DialogueResource, title: String, extra_game_states temporary_game_states = [self] + extra_game_states is_waiting_for_input = false resource = dialogue_resource + InteractionSystem.start_conversation(dialogue_resource) self.dialogue_line = await resource.get_next_dialogue_line(title, temporary_game_states)