xiandie/scene/entity/note.gd

126 lines
3.3 KiB
GDScript3
Raw Normal View History

2025-01-10 07:43:55 +00:00
@tool
extends Sprite2D
2025-01-10 07:43:55 +00:00
@export_enum("items", "c01", "c02", "c03", "c04", "c05", "c06") var dialogue := "items":
set(val):
dialogue = val
match dialogue:
"items":
dialogue_res = dialogue_items
"c01":
dialogue_res = dialogue_c01
"c02":
dialogue_res = dialogue_c02
if is_node_ready():
notify_property_list_changed()
var note_key := ""
@export_enum("none", "notes", "c01", "c02", "c03", "c04", "c05", "c06") var editor_filter := "notes":
set(val):
editor_filter = val
if is_node_ready():
notify_property_list_changed()
2025-01-08 00:51:09 +00:00
@onready var sign_mark = %Sign as Sign
@onready var area2d = %Area2D as Area2D
2025-01-10 07:43:55 +00:00
var dialogue_items = preload("res://asset/dialogue/item_description.dialogue")
var dialogue_c01 = preload("res://asset/dialogue/c01.dialogue")
var dialogue_c02 = preload("res://asset/dialogue/c02.dialogue")
2025-01-10 07:43:55 +00:00
var dialogue_res = dialogue_items
var interacting = false
var mutex = Mutex.new()
func _ready() -> void:
area2d.body_entered.connect(_reset)
area2d.body_exited.connect(_on_cancel)
sign_mark.interacted.connect(_on_interacted)
sign_mark.cancel.connect(_on_cancel)
func _on_interacted() -> void:
2025-01-10 07:43:55 +00:00
if interacting:
return
2025-01-10 07:43:55 +00:00
if not note_key:
printerr("Note key is not set")
return
%Sfx.play()
# SceneManager.focus_node(self)
# CameraFocusMarker.tween_zoom(1.1, 1.5)
# DialogueManager.show_dialogue_balloon(dialogue_res, note_key)
# # TODO note viewing animation
# SceneManager.freeze_player(0, "")
# interacting = true
# DialogueManager.dialogue_ended.connect(_on_dialogue_ended, CONNECT_ONE_SHOT)
# var player = SceneManager.get_player()
# DialogueManager.show_dialogue_balloon_scene(player, dialogue_res, note_key)
var lines = []
var current_line = await dialogue_res.get_next_dialogue_line(note_key)
while current_line:
lines.append(current_line)
if current_line.next_id != "end":
current_line = await dialogue_res.get_next_dialogue_line(current_line.next_id)
else:
break
# if current_line.has("text"):
# lines.append(current_line)
# if current_line.has("next_id") and current_line.next_id != "end":
# current_line = dialogue_res.lines[current_line.next_id]
# else:
# break
SceneManager.pop_os(lines)
SceneManager.freeze_player(1.0, "")
2025-01-10 07:43:55 +00:00
func _set(property: StringName, value: Variant) -> bool:
if property == "note_key":
note_key = value
return true
return false
func _get(property: StringName) -> Variant:
if property == "note_key":
return note_key
elif property == "dialogue_res":
return dialogue_res
return null
func _get_property_list() -> Array[Dictionary]:
# only show notes_ properties in editor
var titles = ""
if Engine.is_editor_hint() and editor_filter and editor_filter != "none":
var filted_titles = dialogue_res.titles.keys().filter(_filter_property)
titles = ",".join(filted_titles)
else:
titles = ",".join(dialogue_res.titles.keys())
return [
{
"name": "note_key",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM_SUGGESTION,
"hint_string": titles
}
]
func _filter_property(property: StringName) -> bool:
return property.find(editor_filter) >= 0
# func _on_dialogue_ended(_res):
# interacting = false
# SceneManager.release_player()
# SceneManager.focus_player_and_reset_zoom()
func _on_cancel(_body = null):
2025-01-10 07:43:55 +00:00
interacting = false
func _reset(_body):
2025-01-10 07:43:55 +00:00
interacting = false