2025-06-24 11:42:39 +00:00
|
|
|
|
extends CanvasLayer
|
2025-01-16 12:24:21 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
2025-01-16 12:24:21 +00:00
|
|
|
|
|
|
|
|
|
func _ready():
|
2025-06-27 14:52:46 +00:00
|
|
|
|
layer = GlobalConfig.CANVAS_LAYER_UX_PANEL
|
2025-06-24 10:40:43 +00:00
|
|
|
|
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-01-21 12:41:24 +00:00
|
|
|
|
|
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]
|
2025-06-10 04:04:24 +00:00
|
|
|
|
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)
|
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")
|
|
|
|
|
):
|
2025-06-27 14:52:46 +00:00
|
|
|
|
quit()
|
2025-06-24 19:36:07 +00:00
|
|
|
|
|
|
|
|
|
|
2025-06-27 14:52:46 +00:00
|
|
|
|
func quit() -> void:
|
|
|
|
|
SceneManager.toggle_pause_counter(false)
|
|
|
|
|
queue_free()
|