xiandie/scene/prop/prop_bag.gd

72 lines
2.1 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Panel
@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
# SceneManager.lock_player()
get_tree().paused = true
_load_item_buttons()
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])
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
# SceneManager.unlock_player()
queue_free()