2024-12-30 13:19:10 +00:00
|
|
|
|
@tool
|
|
|
|
|
class_name PropInspector extends CanvasLayer
|
|
|
|
|
|
2025-01-13 08:09:57 +00:00
|
|
|
|
enum { STATUS_HIDDEN, STATUS_INSPECTING_PROP, STATUS_INSPECTING_COVER, STATUS_INSPECTING_NOTES }
|
2024-12-30 13:19:10 +00:00
|
|
|
|
|
|
|
|
|
# must be connected to
|
2025-01-21 10:08:16 +00:00
|
|
|
|
signal quit_and_hidden
|
2024-12-30 13:19:10 +00:00
|
|
|
|
|
2025-01-30 12:04:02 +00:00
|
|
|
|
@onready var notes_bg = %NotesBG as TextureRect
|
2025-01-20 13:45:47 +00:00
|
|
|
|
@onready var prop_bg = %PropBG as TextureRect
|
|
|
|
|
@onready var origin_texture = %OriginPropTexture as TextureRect
|
|
|
|
|
@onready var full_texture = %FullTexture as TextureRect
|
2024-12-30 13:19:10 +00:00
|
|
|
|
@onready var content_label = %ContentLabel as Label
|
|
|
|
|
@onready var tip_label = %TipLabel as Label
|
|
|
|
|
|
2025-01-20 13:45:47 +00:00
|
|
|
|
var tip_cover = "Q: " + tr("ui_退出") + " " + "E: " + tr("ui_阅读")
|
|
|
|
|
var tip_notes = "Q: " + tr("ui_退出") + " " + "E: " + tr("ui_收起")
|
2024-12-30 13:19:10 +00:00
|
|
|
|
var texture_cover: Texture2D
|
|
|
|
|
var texture_notes: Texture2D
|
|
|
|
|
|
|
|
|
|
var status := STATUS_HIDDEN
|
2025-01-13 08:09:57 +00:00
|
|
|
|
var blinking_tween: Tween
|
2024-12-30 13:19:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2025-01-20 13:45:47 +00:00
|
|
|
|
tip_label.text = tip_cover
|
|
|
|
|
if Engine.is_editor_hint():
|
|
|
|
|
return
|
2025-01-07 10:54:50 +00:00
|
|
|
|
visible = false
|
2024-12-30 13:19:10 +00:00
|
|
|
|
layer = GlobalConfig.CANVAS_LAYER_PROP_INSPECTOR
|
2025-01-20 13:45:47 +00:00
|
|
|
|
origin_texture.modulate.a = 0.0
|
|
|
|
|
prop_bg.modulate.a = 0.0
|
|
|
|
|
full_texture.modulate.a = 0.0
|
2024-12-30 13:19:10 +00:00
|
|
|
|
content_label.modulate.a = 0.0
|
|
|
|
|
tip_label.modulate.a = 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _hide():
|
2025-06-13 08:03:19 +00:00
|
|
|
|
if status == STATUS_HIDDEN:
|
|
|
|
|
return
|
2024-12-30 13:19:10 +00:00
|
|
|
|
status = STATUS_HIDDEN
|
|
|
|
|
var tween = create_tween()
|
2025-01-20 13:45:47 +00:00
|
|
|
|
tween.tween_property(origin_texture, "modulate:a", 0.0, 0.3)
|
|
|
|
|
tween.parallel().tween_property(full_texture, "modulate:a", 0.0, 0.3)
|
2024-12-30 13:19:10 +00:00
|
|
|
|
tween.parallel().tween_property(content_label, "modulate:a", 0.0, 0.15)
|
|
|
|
|
if blinking_tween and blinking_tween.is_running():
|
|
|
|
|
blinking_tween.stop()
|
|
|
|
|
tween.parallel().tween_property(tip_label, "modulate:a", 0.0, 0.15)
|
|
|
|
|
tween.tween_callback(_post_hide)
|
2025-01-10 07:43:55 +00:00
|
|
|
|
SceneManager.release_player()
|
2024-12-30 13:19:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _post_hide():
|
2025-01-20 13:45:47 +00:00
|
|
|
|
origin_texture.texture = null
|
|
|
|
|
full_texture.texture = null
|
2024-12-30 13:19:10 +00:00
|
|
|
|
texture_cover = null
|
|
|
|
|
texture_notes = null
|
|
|
|
|
content_label.text = ""
|
|
|
|
|
tip_label.text = tip_cover
|
2025-01-30 12:04:02 +00:00
|
|
|
|
notes_bg.visible = false
|
2025-01-07 10:54:50 +00:00
|
|
|
|
visible = false
|
2025-01-21 10:08:16 +00:00
|
|
|
|
quit_and_hidden.emit()
|
2024-12-30 13:19:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _blink_label(init := true):
|
|
|
|
|
if status == STATUS_HIDDEN:
|
|
|
|
|
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))
|
|
|
|
|
|
2025-06-13 08:03:19 +00:00
|
|
|
|
|
2025-06-08 14:20:26 +00:00
|
|
|
|
# 如果没有 notes_texture,自动使用黑色遮罩
|
2025-06-21 05:10:55 +00:00
|
|
|
|
func pop_standard_inspection(
|
|
|
|
|
cover_texture, notes_texture, inspection_note, centered := false, wide := false
|
|
|
|
|
):
|
2025-01-30 12:04:02 +00:00
|
|
|
|
if centered:
|
|
|
|
|
content_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
|
|
|
else:
|
|
|
|
|
content_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
2025-01-13 08:09:57 +00:00
|
|
|
|
if status != STATUS_HIDDEN:
|
|
|
|
|
_hide()
|
2024-12-30 13:19:10 +00:00
|
|
|
|
status = STATUS_INSPECTING_COVER
|
2025-01-07 10:54:50 +00:00
|
|
|
|
visible = true
|
2025-01-20 13:45:47 +00:00
|
|
|
|
full_texture.texture = cover_texture
|
2024-12-30 13:19:10 +00:00
|
|
|
|
texture_cover = cover_texture
|
|
|
|
|
texture_notes = notes_texture
|
2025-06-15 05:11:41 +00:00
|
|
|
|
if wide:
|
|
|
|
|
content_label.custom_minimum_size.x = 250
|
|
|
|
|
else:
|
|
|
|
|
content_label.custom_minimum_size.x = 150
|
|
|
|
|
# # shrink back
|
|
|
|
|
# content_label.size.x = 150
|
|
|
|
|
content_label.text = inspection_note.replace("<br>", "\n").strip_edges()
|
2025-01-03 08:07:35 +00:00
|
|
|
|
SceneManager.freeze_player(0)
|
2024-12-30 13:19:10 +00:00
|
|
|
|
var tween = create_tween()
|
2025-01-20 13:45:47 +00:00
|
|
|
|
tween.tween_property(full_texture, "modulate:a", 1.0, 0.15)
|
2025-01-13 08:09:57 +00:00
|
|
|
|
tip_label.text = tip_cover
|
2024-12-30 13:19:10 +00:00
|
|
|
|
_blink_label()
|
|
|
|
|
|
|
|
|
|
|
2025-06-21 05:10:55 +00:00
|
|
|
|
var balloon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func pop_prop_inspection(
|
|
|
|
|
prop_key: String, cover_texture: Texture2D, use_default_bg: bool, display_words_only: bool
|
|
|
|
|
):
|
|
|
|
|
if status != STATUS_HIDDEN and status != STATUS_INSPECTING_PROP:
|
2025-01-13 08:09:57 +00:00
|
|
|
|
_hide()
|
|
|
|
|
if not cover_texture:
|
|
|
|
|
push_error("PropInspector: cover_texture is not set")
|
|
|
|
|
return
|
|
|
|
|
status = STATUS_INSPECTING_PROP
|
|
|
|
|
visible = true
|
2025-01-20 13:45:47 +00:00
|
|
|
|
var tween = create_tween()
|
|
|
|
|
if use_default_bg:
|
|
|
|
|
prop_bg.visible = true
|
|
|
|
|
origin_texture.texture = cover_texture
|
|
|
|
|
full_texture.texture = null
|
|
|
|
|
tween.tween_property(origin_texture, "modulate:a", 1.0, 0.15)
|
|
|
|
|
tween.tween_property(prop_bg, "modulate:a", 1.0, 0.15)
|
|
|
|
|
else:
|
|
|
|
|
origin_texture.texture = null
|
|
|
|
|
full_texture.texture = cover_texture
|
|
|
|
|
tween.tween_property(full_texture, "modulate:a", 1.0, 0.15)
|
2025-01-13 08:09:57 +00:00
|
|
|
|
content_label.text = ""
|
|
|
|
|
tip_label.text = ""
|
2025-01-21 10:08:16 +00:00
|
|
|
|
|
|
|
|
|
# 显示道具获得提示
|
2025-03-17 14:12:53 +00:00
|
|
|
|
if prop_key:
|
2025-02-19 13:30:29 +00:00
|
|
|
|
var obtain_str = tr("ui_获得")
|
2025-03-17 14:12:53 +00:00
|
|
|
|
var prop_title = tr(prop_key)
|
2025-06-21 05:10:55 +00:00
|
|
|
|
var text = "~ title\n"
|
|
|
|
|
if not display_words_only:
|
|
|
|
|
text += obtain_str + ": " + prop_title + "[#item]\n"
|
2025-06-13 08:03:19 +00:00
|
|
|
|
# 道具的一句话说明
|
2025-06-21 05:10:55 +00:00
|
|
|
|
text += tr(prop_key + "_说明").replace("<br>", "\n").strip_edges() + "\n"
|
2025-06-13 08:03:19 +00:00
|
|
|
|
text += "=> END"
|
2025-06-21 05:10:55 +00:00
|
|
|
|
var current_prop_res = DialogueManager.create_resource_from_text(text)
|
|
|
|
|
# 手动跳过的同时显示下一句
|
|
|
|
|
if is_instance_valid(balloon):
|
|
|
|
|
balloon.queue_free()
|
|
|
|
|
else:
|
|
|
|
|
DialogueManager.dialogue_ended.connect(
|
|
|
|
|
_on_inspecting_prop_words_ended, CONNECT_ONE_SHOT
|
|
|
|
|
)
|
|
|
|
|
balloon = preload("res://scene/dialog/balloon.tscn").instantiate()
|
|
|
|
|
DialogueManager.show_dialogue_balloon_scene(balloon, current_prop_res, "title")
|
2025-01-13 08:09:57 +00:00
|
|
|
|
SceneManager.freeze_player(0)
|
|
|
|
|
|
|
|
|
|
|
2025-06-21 05:10:55 +00:00
|
|
|
|
func _on_inspecting_prop_words_ended(_res):
|
2025-06-15 05:11:41 +00:00
|
|
|
|
_hide()
|
|
|
|
|
|
|
|
|
|
|
2025-06-13 08:03:19 +00:00
|
|
|
|
func _show_prop_words(line_id: String):
|
|
|
|
|
# 如果手动退出 ballon,同时退出 prop inspector
|
|
|
|
|
if line_id == "3":
|
|
|
|
|
_hide()
|
2025-06-21 05:10:55 +00:00
|
|
|
|
|
2025-06-13 08:03:19 +00:00
|
|
|
|
|
2025-01-07 10:54:50 +00:00
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
2024-12-30 13:19:10 +00:00
|
|
|
|
if status == STATUS_HIDDEN:
|
|
|
|
|
return
|
|
|
|
|
if event.is_action_pressed("cancel"):
|
2025-01-07 10:54:50 +00:00
|
|
|
|
get_viewport().set_input_as_handled()
|
2025-01-13 08:09:57 +00:00
|
|
|
|
_hide()
|
2024-12-30 13:19:10 +00:00
|
|
|
|
if event.is_action_pressed("interact"):
|
2025-01-07 10:54:50 +00:00
|
|
|
|
get_viewport().set_input_as_handled()
|
2025-01-13 08:09:57 +00:00
|
|
|
|
# STATUS_INSPECTING_COVER 与 STATUS_INSPECTING_NOTES 之间互相切换
|
2024-12-30 13:19:10 +00:00
|
|
|
|
if status == STATUS_INSPECTING_COVER:
|
|
|
|
|
# inspect notes
|
|
|
|
|
status = STATUS_INSPECTING_NOTES
|
2025-01-30 12:04:02 +00:00
|
|
|
|
if not texture_notes:
|
|
|
|
|
notes_bg.visible = true
|
|
|
|
|
else:
|
|
|
|
|
full_texture.texture = texture_notes
|
2024-12-30 13:19:10 +00:00
|
|
|
|
tip_label.text = tip_notes
|
|
|
|
|
create_tween().tween_property(content_label, "modulate:a", 1.0, 0.2)
|
|
|
|
|
elif status == STATUS_INSPECTING_NOTES:
|
|
|
|
|
# inspect cover
|
|
|
|
|
status = STATUS_INSPECTING_COVER
|
2025-01-30 12:04:02 +00:00
|
|
|
|
notes_bg.visible = false
|
2025-01-20 13:45:47 +00:00
|
|
|
|
full_texture.texture = texture_cover
|
2024-12-30 13:19:10 +00:00
|
|
|
|
tip_label.text = tip_cover
|
|
|
|
|
create_tween().tween_property(content_label, "modulate:a", 0.0, 0.2)
|
2025-01-13 08:09:57 +00:00
|
|
|
|
elif status == STATUS_INSPECTING_PROP:
|
2025-06-15 05:11:41 +00:00
|
|
|
|
# # STATUS_INSPECTING_PROP 直接退出
|
|
|
|
|
# # 因为 input 优先被 ballon 获得,然后被 inspector 获得
|
|
|
|
|
# # 所以此时必然没有 ballon 存在
|
2025-01-13 08:09:57 +00:00
|
|
|
|
_hide()
|