diff --git a/game/scenes/Interaction/dialog_trigger_area.gd b/game/scenes/Interaction/dialog_trigger_area.gd index 7f8a802..5e35942 100644 --- a/game/scenes/Interaction/dialog_trigger_area.gd +++ b/game/scenes/Interaction/dialog_trigger_area.gd @@ -5,6 +5,7 @@ extends Area3D @export_multiline var dialog_text := "" @export var auto_popup := false @export_enum("Every Entry", "Once") var auto_popup_mode := 0 +@export var auto_popup_close_on_exit := false var _has_triggered := false @@ -24,9 +25,15 @@ func _on_body_entered(body: Node) -> void: if not (target_group == StringName() or body.is_in_group(target_group)): return if auto_popup: + if DialogSystem and DialogSystem.has_method("is_dialog_open") and DialogSystem.is_dialog_open(): + if not (DialogSystem.has_method("is_dialog_open_from") and DialogSystem.is_dialog_open_from(self)): + return if auto_popup_mode == 1 and _has_triggered: return _has_triggered = true + if DialogSystem and auto_popup_close_on_exit and DialogSystem.has_method("show_text_from"): + DialogSystem.show_text_from(self, dialog_text) + return if DialogSystem and DialogSystem.has_method("show_text"): DialogSystem.show_text(dialog_text) return @@ -35,7 +42,15 @@ func _on_body_entered(body: Node) -> void: func _on_body_exited(body: Node) -> void: + if not (target_group == StringName() or body.is_in_group(target_group)): + return if auto_popup: + if auto_popup_close_on_exit and DialogSystem: + if DialogSystem.has_method("close_if_source"): + DialogSystem.close_if_source(self) + elif DialogSystem.has_method("close_if_text"): + DialogSystem.close_if_text(dialog_text) + return return if target_group == StringName() or body.is_in_group(target_group): DialogSystem.unregister_interactable(self) diff --git a/game/scenes/Levels/level.tscn b/game/scenes/Levels/level.tscn index 61ccee3..bed486b 100644 --- a/game/scenes/Levels/level.tscn +++ b/game/scenes/Levels/level.tscn @@ -236,6 +236,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4, 0, -6.5) script = ExtResource("6_dialog") dialog_text = "Auto dialog trigger" auto_popup = true +auto_popup_close_on_exit = true [node name="CollisionShape3D" type="CollisionShape3D" parent="AutoDialogZone"] shape = SubResource("SphereShape3D_dialog_zone") diff --git a/game/scenes/UI/dialog_system.gd b/game/scenes/UI/dialog_system.gd index bb98b54..7ddbfab 100644 --- a/game/scenes/UI/dialog_system.gd +++ b/game/scenes/UI/dialog_system.gd @@ -3,6 +3,7 @@ extends CanvasLayer var _interactables: Array[Node] = [] var _active_interactable: Node = null var _dialog_visible := false +var _dialog_source: Node = null var _prompt_label: Label var _dialog_panel: PanelContainer @@ -38,8 +39,6 @@ func unregister_interactable(interactable: Node) -> void: if interactable == null: return _interactables.erase(interactable) - if _active_interactable == interactable and _dialog_visible: - _set_dialog_visible(false) _refresh_active_interactable() @@ -47,20 +46,27 @@ func _refresh_active_interactable() -> void: while _interactables.size() > 0 and not is_instance_valid(_interactables[_interactables.size() - 1]): _interactables.pop_back() _active_interactable = _interactables[_interactables.size() - 1] if _interactables.size() > 0 else null - if _dialog_visible and _active_interactable != null: - _dialog_label.text = _get_dialog_text(_active_interactable) _update_prompt_visibility() func _open_dialog_for(interactable: Node) -> void: if _dialog_label: _dialog_label.text = _get_dialog_text(interactable) + _dialog_source = interactable _set_dialog_visible(true) func show_text(text: String) -> void: if _dialog_label: _dialog_label.text = text + _dialog_source = null + _set_dialog_visible(true) + + +func show_text_from(source: Node, text: String) -> void: + if _dialog_label: + _dialog_label.text = text + _dialog_source = source _set_dialog_visible(true) @@ -74,8 +80,26 @@ func close_if_text(expected_text: String) -> void: _set_dialog_visible(false) +func is_dialog_open() -> bool: + return _dialog_visible + + +func is_dialog_open_from(source: Node) -> bool: + return _dialog_visible and _dialog_source == source + + +func close_if_source(source: Node) -> void: + if not _dialog_visible: + return + if _dialog_source != source: + return + _set_dialog_visible(false) + + func _set_dialog_visible(dialog_open: bool) -> void: _dialog_visible = dialog_open + if not _dialog_visible: + _dialog_source = null if _dialog_panel: _dialog_panel.visible = _dialog_visible _update_prompt_visibility()