почин диалогов, пратиклы от выстлеров
This commit is contained in:
@@ -6,60 +6,56 @@ extends StaticBody3D
|
||||
{"name": "Сталкер", "text": "Да вот, теперь и подсказки работают как надо!"}
|
||||
]
|
||||
|
||||
# Укажи здесь точный путь к .tscn файлу твоей сцены диалога
|
||||
const DIALOGUE_UI_FILE = preload("res://addons/dialoge/dialogue_ui.tscn")
|
||||
|
||||
var is_player_inside: bool = false
|
||||
var ui_node: Node = null
|
||||
var is_dialogue_active: bool = false
|
||||
var ui_instance: Node = null
|
||||
var detect_area: Area3D = null
|
||||
|
||||
func _ready() -> void:
|
||||
detect_area = $DetectArea
|
||||
if detect_area:
|
||||
print("[NPC] Зона DetectArea найдена. Мониторинг подсказок включен.")
|
||||
detect_area = get_node_or_null("DetectArea")
|
||||
if detect_area == null:
|
||||
detect_area = find_child("DetectArea", true, false)
|
||||
|
||||
# Спавним диалог ОДИН РАЗ при старте карты, чтобы он не багался при переспавне
|
||||
if ui_instance == null:
|
||||
ui_instance = DIALOGUE_UI_FILE.instantiate()
|
||||
get_tree().get_root().add_child.call_deferred(ui_instance)
|
||||
if "layer" in ui_instance: ui_instance.layer = 135
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if detect_area == null:
|
||||
return
|
||||
if detect_area == null: return
|
||||
|
||||
# Опрашиваем зону на наличие игрока
|
||||
var overlapping_bodies = detect_area.get_overlapping_bodies()
|
||||
var found_player_this_frame = false
|
||||
|
||||
for body in overlapping_bodies:
|
||||
var weapon_manager = body.find_child("WeaponManager", true, false)
|
||||
if weapon_manager == null and body.get_parent():
|
||||
weapon_manager = body.get_parent().find_child("WeaponManager", true, false)
|
||||
|
||||
if weapon_manager != null or "Player" in body.name or "Character" in body.name:
|
||||
if "Player" in body.name or "Character" in body.name or body.find_child("WeaponManager", true, false) != null:
|
||||
found_player_this_frame = true
|
||||
break
|
||||
|
||||
# Игрок ТОЛЬКО ЧТО ЗАШЕЛ в зону NPC
|
||||
# Игрок ЗАШЕЛ в зону NPC
|
||||
if found_player_this_frame and not is_player_inside:
|
||||
is_player_inside = true
|
||||
|
||||
# Ищем узел интерфейса на сцене
|
||||
ui_node = get_tree().current_scene.find_child("DialogueUI", true, false)
|
||||
if ui_node == null:
|
||||
ui_node = get_tree().current_scene.find_child("dialogue_ui", true, false)
|
||||
if ui_instance and not is_dialogue_active:
|
||||
if ui_instance.has_method("show_prompt"):
|
||||
ui_instance.show_prompt()
|
||||
|
||||
# ВКЛЮЧАЕМ ПОДСКАЗКУ «Нажмите E»
|
||||
if ui_node and ui_node.has_method("show_prompt"):
|
||||
ui_node.show_prompt()
|
||||
|
||||
# Игрок ТОЛЬКО ЧТО ВЫШЕЛ из зоны NPC
|
||||
# Игрок ВЫШЕЛ из зоны NPC
|
||||
elif not found_player_this_frame and is_player_inside:
|
||||
is_player_inside = false
|
||||
|
||||
# ПРЯЧЕМ ПОДСКАЗКУ «Нажмите E»
|
||||
if ui_node and ui_node.has_method("hide_prompt"):
|
||||
ui_node.hide_prompt()
|
||||
if ui_node and ui_node.has_method("end_dialogue"):
|
||||
ui_node.end_dialogue()
|
||||
is_dialogue_active = false
|
||||
if ui_instance:
|
||||
if ui_instance.has_method("hide_prompt"): ui_instance.hide_prompt()
|
||||
if ui_instance.has_method("end_dialogue"): ui_instance.end_dialogue()
|
||||
|
||||
# Проверка нажатия кнопки для старта диалога
|
||||
if is_player_inside:
|
||||
if Input.is_key_pressed(KEY_E):
|
||||
if ui_node and ui_node.has_method("start_dialogue"):
|
||||
# Прячем подсказку, так как диалог уже начался
|
||||
if ui_node.has_method("hide_prompt"):
|
||||
ui_node.hide_prompt()
|
||||
ui_node.start_dialogue(dialogue_data)
|
||||
# Старт диалога по кнопке E
|
||||
if is_player_inside and not is_dialogue_active:
|
||||
if Input.is_key_pressed(KEY_E) or Input.is_action_just_pressed("interact"):
|
||||
is_dialogue_active = true
|
||||
if ui_instance:
|
||||
if ui_instance.has_method("hide_prompt"): ui_instance.hide_prompt()
|
||||
if ui_instance.has_method("start_dialogue"):
|
||||
ui_instance.start_dialogue(dialogue_data)
|
||||
|
||||
Reference in New Issue
Block a user