xiandie/scene/ux/bag/prop_bag.gd

81 lines
2.4 KiB
GDScript3
Raw Normal View History

2025-06-24 11:42:39 +00:00
extends CanvasLayer
2025-03-12 07:53:12 +00:00
@onready var buttons_vbox = %ButtonsVBox as VBoxContainer
2025-06-27 14:52:46 +00:00
@onready var texture_bg = %TextureBG as TextureRect
2025-03-12 07:53:12 +00:00
@onready var texture_rect = %TextureRect as TextureRect
@onready var content_text_edit = %Content as TextEdit
func _ready():
2025-06-27 14:52:46 +00:00
layer = GlobalConfig.CANVAS_LAYER_UX_PANEL
SceneManager.toggle_pause_counter(true)
2025-03-12 07:53:12 +00:00
_load_item_buttons()
2025-06-27 14:52:46 +00:00
# fisplay first item
var hud = SceneManager.get_prop_hud()
if hud and hud.inventory.important_items.size() > 0:
_display_item(hud.inventory.important_items[0])
else:
texture_bg.visible = false
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:
2025-06-27 14:52:46 +00:00
var button = preload("uid://wxd25ec3cqyy").instantiate()
2025-03-12 07:53:12 +00:00
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-06-27 14:52:46 +00:00
func _display_item(prop_key, button = null):
2025-03-12 07:53:12 +00:00
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)
2025-06-27 14:52:46 +00:00
if button:
button.icon = null
2025-03-12 07:53:12 +00:00
# prop keys
var item_data = hud.items_dict[prop_key]
var content = hud.items_description_dict[prop_key]
2025-03-12 07:53:12 +00:00
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")
):
2025-06-27 14:52:46 +00:00
quit()
2025-06-27 14:52:46 +00:00
func quit() -> void:
SceneManager.toggle_pause_counter(false)
queue_free()