xiandie/scene/prop/prop_bag.gd

75 lines
2.2 KiB
GDScript3
Raw Normal View History

extends Panel
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
func _ready():
get_parent().layer = GlobalConfig.CANVAS_LAYER_BAG
2025-03-12 07:53:12 +00:00
# SceneManager.lock_player()
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-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)
func _unhandled_input(event: InputEvent) -> void:
# bag 界面接受所有输入事件
get_viewport().set_input_as_handled()
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)
queue_free()