2025-01-21 12:41:24 +00:00
|
|
|
|
extends Panel
|
2025-01-16 12:24:21 +00:00
|
|
|
|
|
2025-03-12 07:53:12 +00:00
|
|
|
|
@onready var buttons_vbox = %ButtonsVBox as VBoxContainer
|
|
|
|
|
@onready var texture_rect = %TextureRect as TextureRect
|
|
|
|
|
@onready var content_text_edit = %Content as TextEdit
|
|
|
|
|
|
2025-01-16 12:24:21 +00:00
|
|
|
|
|
|
|
|
|
func _ready():
|
2025-01-21 12:41:24 +00:00
|
|
|
|
get_parent().layer = GlobalConfig.CANVAS_LAYER_BAG
|
2025-03-12 07:53:12 +00:00
|
|
|
|
# SceneManager.lock_player()
|
2025-01-21 12:41:24 +00:00
|
|
|
|
get_tree().paused = true
|
2025-03-12 07:53:12 +00:00
|
|
|
|
_load_item_buttons()
|
2025-04-20 13:35:13 +00:00
|
|
|
|
$OpenBagSfx.play()
|
2025-03-12 07:53:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _load_item_buttons() -> void:
|
|
|
|
|
# 移除 texture_rect 的纹理与 content_text_edit 的内容
|
|
|
|
|
texture_rect.texture = null
|
|
|
|
|
content_text_edit.text = ""
|
|
|
|
|
# 移除所有子节点
|
|
|
|
|
for child in buttons_vbox.get_children():
|
|
|
|
|
buttons_vbox.remove_child(child)
|
|
|
|
|
child.queue_free()
|
|
|
|
|
# 从 prop_hud 中读取
|
|
|
|
|
var hud = SceneManager.get_prop_hud()
|
|
|
|
|
if not hud:
|
|
|
|
|
printerr("PropHud node not found")
|
|
|
|
|
return
|
|
|
|
|
# prop keys
|
|
|
|
|
var inventory = hud.inventory
|
|
|
|
|
for prop_key in inventory.important_items:
|
|
|
|
|
var button = preload("res://scene/prop/prop_bag_button.tscn").instantiate()
|
|
|
|
|
button.text = tr(prop_key)
|
|
|
|
|
button.pressed.connect(_display_item.bind(prop_key, button))
|
|
|
|
|
buttons_vbox.add_child(button)
|
|
|
|
|
# 如果已读,消除 icon(默认都有 icon)
|
|
|
|
|
if not inventory.unviewed_important_items.has(prop_key):
|
|
|
|
|
button.icon = null
|
|
|
|
|
# # 选中第一个
|
|
|
|
|
# if buttons_vbox.get_child_count() > 0:
|
|
|
|
|
# (buttons_vbox.get_child(0) as Button).pres
|
|
|
|
|
# # _display_item(inventory.important_items[0])
|
|
|
|
|
|
2025-01-21 12:41:24 +00:00
|
|
|
|
|
|
|
|
|
|
2025-03-12 07:53:12 +00:00
|
|
|
|
func _display_item(prop_key, button):
|
|
|
|
|
var hud = SceneManager.get_prop_hud()
|
|
|
|
|
if not hud:
|
|
|
|
|
printerr("PropHud node not found")
|
|
|
|
|
return
|
|
|
|
|
# 标记为已读:消除 icon + 写入 inventory
|
|
|
|
|
if hud.inventory.unviewed_important_items.has(prop_key):
|
|
|
|
|
hud.inventory.unviewed_important_items.erase(prop_key)
|
|
|
|
|
button.icon = null
|
|
|
|
|
# prop keys
|
|
|
|
|
var item_data = hud.items_dict[prop_key]
|
|
|
|
|
var content = hud.important_items_dict[prop_key]
|
|
|
|
|
content_text_edit.text = content
|
|
|
|
|
texture_rect.texture = load(item_data.texture_path)
|
2025-01-21 12:41:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
2025-03-20 10:00:53 +00:00
|
|
|
|
# bag 界面接受所有输入事件
|
|
|
|
|
get_viewport().set_input_as_handled()
|
2025-01-21 12:41:24 +00:00
|
|
|
|
if (
|
|
|
|
|
event.is_action_pressed("bag")
|
|
|
|
|
or event.is_action_pressed("cancel")
|
|
|
|
|
or event.is_action_pressed("escape")
|
|
|
|
|
):
|
|
|
|
|
get_tree().paused = false
|
2025-03-12 07:53:12 +00:00
|
|
|
|
# SceneManager.unlock_player()
|
2025-04-20 13:35:13 +00:00
|
|
|
|
var close_stream = preload("res://asset/audio/sfx/交互/收起背包.wav")
|
|
|
|
|
AudioManager.play_sfx(close_stream)
|
2025-01-21 12:41:24 +00:00
|
|
|
|
queue_free()
|