xiandie/scene/entity/local_inspectable.gd

179 lines
5.2 KiB
GDScript3
Raw Normal View History

2025-01-10 07:43:55 +00:00
@tool
extends Sprite2D
2025-01-12 12:15:18 +00:00
signal start_inspecting
signal quit_inspecting
# @export var entity_config: EntityConfig:
# set(value):
# entity_config = value
enum { STATUS_NORAML, STATUS_TRANSITIONING, STATUS_INSPECTING_COVER, STATUS_INSPECTING_NOTES }
# @export var entity_name: String = ""
@export var content_centered: bool = false
@export var texture_cover: Texture2D
@export_enum("none", "c01", "c02", "c03", "c04", "c05", "c06") var editor_filter := "none":
2025-01-10 07:43:55 +00:00
set(val):
editor_filter = val
2025-01-21 10:52:36 +00:00
if is_node_ready() and Engine.is_editor_hint():
2025-01-10 07:43:55 +00:00
notify_property_list_changed()
var content_key: String = ""
2025-01-08 00:51:09 +00:00
@onready var sign_mark = %Sign as Sign
@onready var area2d = %Area2D as Area2D
@onready var sfx = %Sfx
@onready var container = %Container
@onready var cover_rect = %Cover as TextureRect
@onready var content_label = %ContentLabel as Label
@onready var tip_label = %TipLabel as Label
var tip_cover_hide_notes = "Q: " + tr("ui_退出") + " " + "E: " + tr("ui_阅读")
var tip_cover_without_notes = "Q: " + tr("ui_退出") + " " + "E: " + tr("ui_检阅")
2025-01-10 07:43:55 +00:00
var tip_notes = "Q: " + tr("ui_退出") + " " + "E: " + tr("ui_收起")
static var content_dialogue = (
preload("res://asset/dialogue/inspect_content.dialogue") as DialogueResource
)
var status := STATUS_NORAML
var blinking_tween: Tween
func _ready() -> void:
$InspectLayer.layer = GlobalConfig.CANVAS_LAYER_PROP_INSPECTOR
container.modulate.a = 0.0
2025-05-30 11:05:06 +00:00
content_label.modulate.a = 0.0
2025-01-10 07:43:55 +00:00
content_label.text = _get_tr_content()
tip_label.text = tip_cover_hide_notes
cover_rect.texture = texture_cover
2025-01-13 08:09:57 +00:00
if Engine.is_editor_hint():
return
if content_centered:
content_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
2025-01-13 08:09:57 +00:00
sign_mark.interacted.connect(_on_interacted)
sign_mark.cancel.connect(_on_cancel)
2025-01-10 07:43:55 +00:00
func _get_tr_content():
if content_key == "":
return ""
var inspection_note = ""
# get note content
var line_id = content_dialogue.titles.get(content_key)
while line_id and line_id != "end":
var line = content_dialogue.lines[line_id]
if line.has("text"):
inspection_note += tr(line.get("text")) + "\n"
line_id = line.get("next_id")
return inspection_note
func _on_interacted() -> void:
if STATUS_TRANSITIONING == status:
return
if status == STATUS_NORAML:
sfx.play()
SceneManager.focus_node(self)
SceneManager.get_camera_marker().tween_zoom(2.0)
status = STATUS_TRANSITIONING
var tween = create_tween()
2025-05-30 11:05:06 +00:00
tween.tween_interval(0.8)
tween.tween_property(container, "modulate:a", 1.0, 0.7)
tween.tween_callback(func(): status = STATUS_INSPECTING_COVER)
sign_mark.display_sign = false
SceneManager.freeze_player(0.0, PlayerAnimationConfig.ACTION_LOOKUP_WALL)
cover_rect.texture = texture_cover
if content_key == "":
tip_label.text = tip_cover_without_notes
else:
tip_label.text = tip_cover_hide_notes
_blink_label(true)
2025-01-12 12:15:18 +00:00
start_inspecting.emit()
elif status == STATUS_INSPECTING_COVER:
sfx.play()
status = STATUS_INSPECTING_NOTES
tip_label.text = tip_notes
2025-05-30 11:05:06 +00:00
create_tween().tween_property(content_label, "modulate:a", 1.0, 0.15)
elif status == STATUS_INSPECTING_NOTES:
sfx.play()
status = STATUS_INSPECTING_COVER
if content_key == "":
tip_label.text = tip_cover_without_notes
else:
tip_label.text = tip_cover_hide_notes
2025-05-30 11:05:06 +00:00
create_tween().tween_property(content_label, "modulate:a", 0.0, 0.15)
func _blink_label(init := true):
if status == STATUS_NORAML:
return
blinking_tween = create_tween()
if init:
blinking_tween.tween_property(tip_label, "modulate:a", 0.8, 2.0)
blinking_tween.tween_callback(_blink_label.bind(false))
else:
blinking_tween.tween_property(tip_label, "modulate:a", 0.5, 1.0)
blinking_tween.tween_callback(_blink_label.bind(true))
func _on_cancel(_body = null):
if STATUS_TRANSITIONING == status:
return
2025-01-12 12:15:18 +00:00
if status != STATUS_NORAML:
quit_inspecting.emit()
status = STATUS_TRANSITIONING
var tween = create_tween()
tween.tween_property(container, "modulate:a", 0.0, 0.15)
if blinking_tween and blinking_tween.is_running():
blinking_tween.kill()
tween.parallel().tween_property(tip_label, "modulate:a", 0.0, 0.15)
tween.tween_interval(1.0)
tween.tween_callback(func(): status = STATUS_NORAML)
2025-05-30 11:05:06 +00:00
tween.tween_callback(func(): content_label.modulate.a = 0.0)
SceneManager.focus_player_and_reset_zoom()
2025-01-10 07:43:55 +00:00
SceneManager.release_player()
sign_mark.display_sign = true
2025-01-10 07:43:55 +00:00
func _set(property: StringName, value: Variant) -> bool:
if property == "content_key":
content_key = value
content_label.text = _get_tr_content()
return true
return false
func _get(property: StringName) -> Variant:
if property == "content_key":
return content_key
return null
func _get_property_list() -> Array[Dictionary]:
var titles = ""
# only show notes_ properties in editor
if Engine.is_editor_hint():
var ordered_titles = content_dialogue.get_ordered_titles()
if editor_filter and editor_filter != "none":
var filted_titles = ordered_titles.filter(_filter_property)
if filted_titles.size() > 0:
titles = ",".join(filted_titles)
else:
titles = ",".join(ordered_titles)
2025-01-10 07:43:55 +00:00
return [
{
"name": "content_key",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM_SUGGESTION,
"hint_string": titles
2025-01-10 07:43:55 +00:00
}
]
2025-01-10 07:43:55 +00:00
func _filter_property(property: StringName) -> bool:
return property.find(editor_filter) >= 0