xiandie/scene/prop/prop_inspector.gd

152 lines
4.8 KiB
GDScript3
Raw Normal View History

@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 }
# must be connected to
signal quit_and_hidden
@onready var prop_bg = %PropBG as TextureRect
@onready var origin_texture = %OriginPropTexture as TextureRect
@onready var full_texture = %FullTexture as TextureRect
@onready var content_label = %ContentLabel as Label
@onready var tip_label = %TipLabel as Label
var tip_cover = "Q: " + tr("ui_退出") + " " + "E: " + tr("ui_阅读")
var tip_notes = "Q: " + tr("ui_退出") + " " + "E: " + tr("ui_收起")
var texture_cover: Texture2D
var texture_notes: Texture2D
var status := STATUS_HIDDEN
2025-01-13 08:09:57 +00:00
var blinking_tween: Tween
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
tip_label.text = tip_cover
if Engine.is_editor_hint():
return
2025-01-07 10:54:50 +00:00
visible = false
layer = GlobalConfig.CANVAS_LAYER_PROP_INSPECTOR
origin_texture.modulate.a = 0.0
prop_bg.modulate.a = 0.0
full_texture.modulate.a = 0.0
content_label.modulate.a = 0.0
tip_label.modulate.a = 0.0
func _hide():
status = STATUS_HIDDEN
var tween = create_tween()
tween.tween_property(origin_texture, "modulate:a", 0.0, 0.3)
tween.parallel().tween_property(full_texture, "modulate:a", 0.0, 0.3)
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()
func _post_hide():
origin_texture.texture = null
full_texture.texture = null
texture_cover = null
texture_notes = null
content_label.text = ""
tip_label.text = tip_cover
2025-01-07 10:54:50 +00:00
visible = false
quit_and_hidden.emit()
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-01-13 08:09:57 +00:00
func pop_standard_inspection(cover_texture, notes_texture, inspection_note):
if status != STATUS_HIDDEN:
_hide()
status = STATUS_INSPECTING_COVER
2025-01-07 10:54:50 +00:00
visible = true
full_texture.texture = cover_texture
texture_cover = cover_texture
texture_notes = notes_texture
content_label.text = inspection_note
SceneManager.freeze_player(0)
var tween = create_tween()
tween.tween_property(full_texture, "modulate:a", 1.0, 0.15)
2025-01-13 08:09:57 +00:00
tip_label.text = tip_cover
_blink_label()
func pop_prop_inspection(prop_title: String, cover_texture: Texture2D, use_default_bg := false):
2025-01-13 08:09:57 +00:00
if status != STATUS_HIDDEN:
_hide()
if not cover_texture:
push_error("PropInspector: cover_texture is not set")
return
status = STATUS_INSPECTING_PROP
visible = true
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 = ""
# 显示道具获得提示
var obtain_str = tr("ui_获得")
var text = "~ title\n" + obtain_str + ": " + prop_title
text += "[#item][ID:" + prop_title + "]\n=> END"
var prop_res = DialogueManager.create_resource_from_text(text)
var balloon = preload("res://scene/dialog/balloon.tscn").instantiate()
# 手动跳过的同时隐藏
balloon.manually_skipped_line.connect(_hide)
DialogueManager.show_dialogue_balloon_scene(balloon, prop_res, "title")
2025-01-13 08:09:57 +00:00
SceneManager.freeze_player(0)
2025-01-07 10:54:50 +00:00
func _unhandled_input(event: InputEvent) -> void:
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()
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 之间互相切换
if status == STATUS_INSPECTING_COVER:
# inspect notes
status = STATUS_INSPECTING_NOTES
# if not texture_notes:
# prop_bg.visible = true
# else:
# texture_rect.texture = texture_notes
full_texture.texture = texture_notes
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
full_texture.texture = texture_cover
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
# STATUS_INSPECTING_PROP 直接退出
elif status == STATUS_INSPECTING_PROP:
_hide()