Dialog bug fix/tweaks
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user