xiandie/scene/popup/prop_inspector.gd

124 lines
3.6 KiB
GDScript

@tool
class_name PropInspector extends CanvasLayer
enum { STATUS_HIDDEN, STATUS_INSPECTING_PROP, STATUS_INSPECTING_COVER, STATUS_INSPECTING_NOTES }
# must be connected to
signal quit
@onready var texture_rect = %TextureRect as TextureRect
@onready var content_label = %ContentLabel as Label
@onready var tip_label = %TipLabel as Label
var tip_cover = "Q: 退出 E: 阅读"
var tip_notes = "Q: 退出 E: 收起"
var texture_cover: Texture2D
var texture_notes: Texture2D
var status := STATUS_HIDDEN
var blinking_tween: Tween
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
visible = false
layer = GlobalConfig.CANVAS_LAYER_PROP_INSPECTOR
texture_rect.modulate.a = 0.0
content_label.modulate.a = 0.0
tip_label.modulate.a = 0.0
tip_label.text = tip_cover
func _hide():
status = STATUS_HIDDEN
var tween = create_tween()
tween.tween_property(texture_rect, "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)
SceneManager.release_player()
func _post_hide():
texture_rect.texture = null
texture_cover = null
texture_notes = null
content_label.text = ""
tip_label.text = tip_cover
visible = false
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))
func pop_standard_inspection(cover_texture, notes_texture, inspection_note):
if status != STATUS_HIDDEN:
_hide()
status = STATUS_INSPECTING_COVER
visible = true
texture_rect.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(texture_rect, "modulate:a", 1.0, 0.15)
tip_label.text = tip_cover
_blink_label()
func pop_prop_inspection(cover_texture):
if status != STATUS_HIDDEN:
_hide()
if not cover_texture:
push_error("PropInspector: cover_texture is not set")
return
status = STATUS_INSPECTING_PROP
visible = true
texture_rect.texture = cover_texture
texture_cover = cover_texture
texture_notes = null
content_label.text = ""
tip_label.text = ""
SceneManager.freeze_player(0)
var tween = create_tween()
tween.tween_property(texture_rect, "modulate:a", 1.0, 0.15)
func _unhandled_input(event: InputEvent) -> void:
if status == STATUS_HIDDEN:
return
if event.is_action_pressed("cancel"):
get_viewport().set_input_as_handled()
_hide()
quit.emit()
if event.is_action_pressed("interact"):
get_viewport().set_input_as_handled()
# STATUS_INSPECTING_COVER 与 STATUS_INSPECTING_NOTES 之间互相切换
if status == STATUS_INSPECTING_COVER:
# inspect notes
status = STATUS_INSPECTING_NOTES
texture_rect.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
texture_rect.texture = texture_cover
tip_label.text = tip_cover
create_tween().tween_property(content_label, "modulate:a", 0.0, 0.2)
# STATUS_INSPECTING_PROP 直接退出
elif status == STATUS_INSPECTING_PROP:
_hide()
quit.emit()