diff --git a/README.md b/README.md index f80dd1d8..81afef80 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ - [DialogueManager 使用与维护说明](https://docs.qq.com/doc/DWG5vaEZ1Qk9EdVVw) - [GIF 插件](https://godotengine.org/asset-library/asset/2255) +- [Godot Steam](https://godotsteam.com/) ### ProAnimatedSprite2D diff --git a/asset/art/ui/hud/placeholder.png b/asset/art/ui/hud/placeholder.png new file mode 100644 index 00000000..4ca07b49 Binary files /dev/null and b/asset/art/ui/hud/placeholder.png differ diff --git a/asset/art/ui/hud/placeholder.png.import b/asset/art/ui/hud/placeholder.png.import new file mode 100644 index 00000000..2fa98ae4 --- /dev/null +++ b/asset/art/ui/hud/placeholder.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://djrfdhywg7uu2" +path="res://.godot/imported/placeholder.png-22c8dde7cbbf528a6f9217bc6eb37522.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://asset/art/ui/hud/placeholder.png" +dest_files=["res://.godot/imported/placeholder.png-22c8dde7cbbf528a6f9217bc6eb37522.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project.godot b/project.godot index 792df5d9..6479b6c0 100644 --- a/project.godot +++ b/project.godot @@ -145,11 +145,6 @@ prop_right={ , Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":16,"position":Vector2(427, 48),"global_position":Vector2(446, 139),"factor":0.0300018,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } -prop_select={ -"deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null) -] -} toggle_journal={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) diff --git a/scene/prop/prop_hud.gd b/scene/prop/prop_hud.gd index 8a080375..48ba4b28 100644 --- a/scene/prop/prop_hud.gd +++ b/scene/prop/prop_hud.gd @@ -1,4 +1,4 @@ -@tool +# @tool class_name PropHud extends Control signal current_item_changed(prop_key: String) @@ -26,19 +26,19 @@ signal current_item_changed(prop_key: String) @export var selected := false: set(value): selected = value - # if is_node_ready(): - # %Mark.visible = value - # mark.modulate.a = 1.0 @onready var sfx_click = %SfxClick as Sfx @onready var left_btn = %LeftButton as TextureButton @onready var right_btn = %RightButton as TextureButton -@onready var panel = %HudPanel as TextureButton -@onready var prop = %Prop as TextureRect -@onready var prop_container = %PropContainer as Container -@onready var mark = %Mark as TextureRect @onready var title_label = %TitleLabel as Label +@onready var hud_rect = %HudRect as NinePatchRect +@onready var props_scroll = %PropScrollContainer as ScrollContainer +@onready var props_hbox = %PropsHBox as HBoxContainer +var prop_containers = [] #CenterContainer +const PROP_CONTAINER_X = 130.0 +const PROP_CONTROL_X = 110.0 + var items_dict := {} # 从配置文件加载 prop items var item_config_res = preload("res://asset/dialogue/item_description.dialogue") @@ -55,8 +55,14 @@ var container_tween: Tween func _ready() -> void: if Engine.is_editor_hint(): return + # read prop containers,第一个为 head 跳过, 最后一个为 tail 跳过 + for id in range(props_hbox.get_child_count() - 2): + var container = props_hbox.get_child(id + 1) + prop_containers.append(container) + container.get_child(0).get_child(0).pressed.connect(_on_prop_pressed.bind(id)) _load_items() _load_from_archive() + props_scroll.scroll_horizontal = PROP_CONTAINER_X focus_exited.connect(_on_focus_exited) # 存档更新时,从存档加载 prop ArchiveManager.archive_loaded.connect(_load_from_archive) @@ -69,9 +75,6 @@ func _ready() -> void: # connect signals left_btn.pressed.connect(on_left_pressed) right_btn.pressed.connect(on_right_pressed) - panel.pressed.connect(_on_panel_pressed) - # %Mark.visible = selected - # mark.modulate.a = 0.8 title_label.modulate.a = 0.0 # _toggle_btn_ability(false) left_btn.modulate.a = 0.5 @@ -114,6 +117,7 @@ func _load_items(): func _load_from_archive() -> void: if ArchiveManager.archive: inventory = ArchiveManager.archive.prop_inventory + _align_container_size() _load_texture_cache() _update_prop_display_with_texture() @@ -134,11 +138,14 @@ func _load_texture_cache() -> void: continue var path = items_dict[key].texture_path if not path: + var placeholder = preload("res://asset/art/ui/hud/placeholder.png") + cached_inventory_textures[key] = placeholder + print("Cache load prop placeholder key=", key) continue var texture = load(path) as Texture2D if texture: if GlobalConfig.DEBUG: - print("Cache load prop texture:", path) + print("Cache load prop texture key=", key) cached_inventory_textures[key] = texture # wrap index inventory.current_index = wrapi(inventory.current_index, 0, inventory.enabled_items.size()) @@ -147,19 +154,31 @@ func _load_texture_cache() -> void: func _update_prop_display_with_texture(): if not inventory: return + var prop = prop_containers[0].get_child(0).get_child(0) as TextureButton + # 在没有道具时,展示空手 placeholder if inventory.enabled_items.size() == 0: - prop.texture = null + prop.texture_normal = preload("res://asset/art/ui/hud/placeholder.png") + prop.size = Vector2(PROP_CONTROL_X, PROP_CONTROL_X) + prop.scale = Vector2(1.0, 1.0) + title_label.text = tr("prop_空手") return - var item = items_dict[inventory.current_item_key()] - if not item: - prop.texture = null - push_error("PropItem is null! index=" + str(inventory.current_index)) - return - if item.key in cached_inventory_textures: - prop.texture = cached_inventory_textures[item.key] - else: - prop.texture = null - title_label.text = tr(item.key) + for i in range(prop_containers.size()): + var id = wrapi(inventory.current_index + i, 0, inventory.enabled_items.size()) + var item = items_dict[inventory.enabled_items[id]] + prop = prop_containers[i].get_child(0).get_child(0) as TextureButton + if i == 0: + title_label.text = tr(item.key) + if item.key in cached_inventory_textures: + prop.texture_normal = cached_inventory_textures[item.key] + var t_size = prop.texture_normal.get_size() + var max_x = max(t_size.x, t_size.y) + var p_scale = min(PROP_CONTROL_X / t_size.x, PROP_CONTROL_X / t_size.y) + prop.scale = Vector2(p_scale, p_scale) + prop.size = Vector2(max_x, max_x) + else: + printerr("PropHUD: Texture not found! key=", item.key) + prop.texture_normal = null + props_scroll.scroll_horizontal = PROP_CONTAINER_X func on_left_pressed() -> void: @@ -189,22 +208,46 @@ func _tween_container(left_to_right := true) -> void: container_tween.kill() container_tween = create_tween() if left_to_right: - container_tween.tween_property(prop_container, "offset_left", 0.0, 0.3).from(-200.0) - prop_container.offset_right = 0.0 + props_scroll.scroll_horizontal = 2 * PROP_CONTAINER_X else: - container_tween.tween_property(prop_container, "offset_right", 0.0, 0.3).from(200.0) - prop_container.offset_left = 0.0 + props_scroll.scroll_horizontal = 0.0 + # 通过 Head 与 Tail 占位符,实现滚动效果;否则会导致卡在边界上,无法滚动 + container_tween.tween_property(props_scroll, "scroll_horizontal", PROP_CONTAINER_X, 0.2) -func _on_panel_pressed() -> void: +func _on_prop_pressed(id := 0) -> void: if locked: return sfx_click.play() + if GlobalConfig.DEBUG: + print("PropHUD Panel pressed.") if not selected: focus_mode = FOCUS_ALL grab_focus() selected = true - _mouse_moved_on_listening() + inventory.current_index += id + _update_prop_display_with_texture() + _mouse_moved_on_listening(true) + + +var tween_scroll: Tween + + +func _toggle_scroll(fold := true) -> void: + if tween_scroll and tween_scroll.is_running(): + tween_scroll.kill() + if fold: + tween_scroll = create_tween() + tween_scroll.tween_property(props_scroll, "custom_minimum_size:x", PROP_CONTAINER_X, 0.5) + tween_scroll.parallel().tween_property( + hud_rect, "custom_minimum_size:x", PROP_CONTAINER_X + 10., 0.5 + ) + else: + # 保持最小宽度 + var x_size = max(1, prop_containers.size()) * PROP_CONTAINER_X + tween_scroll = create_tween() + tween_scroll.tween_property(props_scroll, "custom_minimum_size:x", x_size, 0.5) + tween_scroll.parallel().tween_property(hud_rect, "custom_minimum_size:x", x_size + 10., 0.5) func _on_mouse_entered() -> void: @@ -218,15 +261,18 @@ func _on_mouse_exited() -> void: listen_mouse = false -func _mouse_moved_on_listening() -> void: +func _mouse_moved_on_listening(unfold_scroll := false) -> void: + if unfold_scroll: + _toggle_scroll(false) if not displaying: - toggle_details(true) + _toggle_details(true) return timer.start(display_time) func _on_timer_timeout() -> void: - toggle_details(false) + _toggle_details(false) + _toggle_scroll(true) func _unhandled_input(event: InputEvent) -> void: @@ -238,9 +284,6 @@ func _unhandled_input(event: InputEvent) -> void: elif event.is_action_pressed("prop_right"): on_right_pressed() get_viewport().set_input_as_handled() - elif event.is_action_pressed("prop_select"): - _on_panel_pressed() - get_viewport().set_input_as_handled() func _input(event: InputEvent) -> void: @@ -250,7 +293,7 @@ func _input(event: InputEvent) -> void: _mouse_moved_on_listening() -func toggle_details(display := true) -> void: +func _toggle_details(display := true) -> void: if display_tween and display_tween.is_running(): display_tween.kill() display_tween = create_tween() @@ -260,15 +303,9 @@ func toggle_details(display := true) -> void: display_tween.parallel().tween_property(title_label, "modulate:a", 1.0, 0.3) display_tween.parallel().tween_property(left_btn, "modulate:a", 1.0, 0.3) display_tween.parallel().tween_property(right_btn, "modulate:a", 1.0, 0.3) - # display_tween.parallel().tween_property(mark, "modulate:a", 1.0, 0.3) - # display_tween.parallel().tween_property(mark, "scale", Vector2(1.1, 1.1), 0.3).set_trans( - # Tween.TRANS_CUBIC - # ) - # display_tween.tween_property(mark, "scale", Vector2.ONE, 0.2).set_trans(Tween.TRANS_CUBIC) timer.start(display_time) else: displaying = false - # display_tween.tween_property(mark, "modulate:a", 0.8, 0.6) display_tween.parallel().tween_property(title_label, "modulate:a", 0.0, 0.6) display_tween.parallel().tween_property(left_btn, "modulate:a", 0.5, 0.5) display_tween.parallel().tween_property(right_btn, "modulate:a", 0.5, 0.5) @@ -288,6 +325,7 @@ func enable_prop_item(prop_key: String) -> void: push_error("PropItem not found! key=" + prop_key) return inventory.enable_item(prop_key) + _align_container_size() _load_texture_cache() _update_prop_display_with_texture() if GlobalConfig.DEBUG: @@ -308,10 +346,52 @@ func disable_prop_item(prop_key: String) -> void: if not inventory or not prop_key: return inventory.disable_item(prop_key) + _align_container_size() _load_texture_cache() _update_prop_display_with_texture() +func _align_container_size() -> void: + # 判断是否需要添加新的 prop container + while inventory.enabled_items.size() > prop_containers.size(): + append_prop_container() + # 判断是否需要删除 prop container,最少保留一个 + while inventory.enabled_items.size() < prop_containers.size() and prop_containers.size() > 1: + remove_prop_container() + if displaying: + _mouse_moved_on_listening() + # 如果正在展示,则更新 scroll 长度 + if displaying and props_scroll.custom_minimum_size.x > PROP_CONTAINER_X: + _toggle_scroll(false) + + +func append_prop_container() -> void: + var container = CenterContainer.new() + container.custom_minimum_size = Vector2(PROP_CONTAINER_X, PROP_CONTAINER_X) + container.set_anchors_preset(Control.PRESET_FULL_RECT) + prop_containers.append(container) + var control = Control.new() + control.custom_minimum_size = Vector2(PROP_CONTROL_X, PROP_CONTROL_X) + control.set_anchors_preset(Control.PRESET_FULL_RECT) + container.add_child(control) + var prop = TextureButton.new() + prop.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED + control.add_child(prop) + # 添加到 hbox: container -> control -> prop + props_hbox.add_child(container) + # 放在 Tail 占位符 之前 + props_hbox.move_child(container, -2) + prop.pressed.connect(_on_prop_pressed.bind(prop_containers.size() - 1)) + + +func remove_prop_container() -> void: + if prop_containers.size() <= 1: + return + var container = prop_containers.pop_back() + props_hbox.remove_child(container) + container.queue_free() + + var shake_tween @@ -331,6 +411,7 @@ func on_toggle_invalid_prop(): var origin_pos = Vector2.ZERO var count = int(duration * fps) var delta_t = 1.0 / fps + var prop = prop_containers[0].get_child(0) prop.modulate = Color(1.0, 0.6, 0.6, 1.0) for i in range(count): var offset = Vector2(randf_range(-delta, delta), randf_range(-delta, delta)) * exp(-i) @@ -341,4 +422,5 @@ func on_toggle_invalid_prop(): func _reset_prop_modulate(): + var prop = prop_containers[0].get_child(0) prop.modulate = Color(1.0, 1.0, 1.0, 1.0) diff --git a/scene/prop/prop_hud.tscn b/scene/prop/prop_hud.tscn index 3fe72b50..1f1de8cb 100644 --- a/scene/prop/prop_hud.tscn +++ b/scene/prop/prop_hud.tscn @@ -1,15 +1,20 @@ -[gd_scene load_steps=10 format=3 uid="uid://dc778gsjfr3ky"] +[gd_scene load_steps=12 format=3 uid="uid://dc778gsjfr3ky"] [ext_resource type="Script" path="res://scene/prop/prop_hud.gd" id="1_bbv0a"] [ext_resource type="Texture2D" uid="uid://dok08tovej18w" path="res://asset/art/ui/hud/normal_left.png" id="2_bjc2b"] [ext_resource type="PackedScene" uid="uid://c85t6stvytvjn" path="res://scene/entity/general/sfx.tscn" id="2_g6c03"] [ext_resource type="Texture2D" uid="uid://c45k7ncg6xhpv" path="res://asset/art/ui/hud/pressed_left.png" id="3_fca7p"] [ext_resource type="Texture2D" uid="uid://c2jq2neda32ix" path="res://asset/art/ui/hud/Prop.png" id="5_6tt77"] -[ext_resource type="Texture2D" uid="uid://b6mchcvq5d6jf" path="res://asset/art/prop/c02/1012钥匙物品.png" id="8_l2cwd"] -[ext_resource type="Texture2D" uid="uid://bhm71jo5k07qy" path="res://asset/art/ui/hud/red_hand.png" id="9_0crjo"] +[ext_resource type="Texture2D" uid="uid://0uwun1mo726u" path="res://asset/art/prop/c02/绳子物品.png" id="6_0m706"] +[ext_resource type="FontFile" uid="uid://dr8bp6p7byb37" path="res://asset/font/字体/方正楷体简体.TTF" id="10_mye4q"] [ext_resource type="Texture2D" uid="uid://c1ogeaa836kry" path="res://asset/art/ui/hud/normal_right.png" id="10_vkaik"] +[ext_resource type="Script" path="res://scene/prop/test_hbox.gd" id="11_008sv"] [ext_resource type="Texture2D" uid="uid://d03la4d2swk0k" path="res://asset/art/ui/hud/pressed_right.png" id="11_a512b"] +[sub_resource type="LabelSettings" id="LabelSettings_830v8"] +font = ExtResource("10_mye4q") +font_size = 36 + [node name="PropHUD" type="Control"] process_mode = 3 custom_minimum_size = Vector2(600, 500) @@ -23,94 +28,108 @@ scale = Vector2(0.3, 0.3) script = ExtResource("1_bbv0a") [node name="VBoxContainer" type="VBoxContainer" parent="."] -layout_mode = 0 -offset_right = 40.0 -offset_bottom = 40.0 +layout_mode = 1 +offset_right = 214.0 +offset_bottom = 193.0 [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] layout_mode = 2 +size_flags_horizontal = 0 [node name="SfxClick" parent="VBoxContainer/HBoxContainer" instance=ExtResource("2_g6c03")] unique_name_in_owner = true [node name="LeftMargin" type="MarginContainer" parent="VBoxContainer/HBoxContainer"] layout_mode = 2 +size_flags_horizontal = 0 theme_override_constants/margin_left = 8 [node name="LeftButton" type="TextureButton" parent="VBoxContainer/HBoxContainer/LeftMargin"] unique_name_in_owner = true +visible = false layout_mode = 2 size_flags_vertical = 4 texture_normal = ExtResource("2_bjc2b") texture_pressed = ExtResource("3_fca7p") stretch_mode = 5 -[node name="HudPanel" type="TextureButton" parent="VBoxContainer/HBoxContainer"] +[node name="HudRect" type="NinePatchRect" parent="VBoxContainer/HBoxContainer"] unique_name_in_owner = true -custom_minimum_size = Vector2(32, 32) +custom_minimum_size = Vector2(140, 140) layout_mode = 2 +size_flags_horizontal = 0 size_flags_vertical = 4 -texture_normal = ExtResource("5_6tt77") +texture = ExtResource("5_6tt77") +region_rect = Rect2(0, 1, 139, 139) +patch_margin_left = 6 +patch_margin_top = 6 +patch_margin_right = 6 +patch_margin_bottom = 6 + +[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/HBoxContainer/HudRect"] +layout_mode = 1 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +offset_top = -70.0 +offset_right = 140.0 +offset_bottom = 70.0 +grow_vertical = 2 +theme_override_constants/margin_left = 5 +theme_override_constants/margin_top = 5 +theme_override_constants/margin_right = 5 +theme_override_constants/margin_bottom = 5 + +[node name="PropScrollContainer" type="ScrollContainer" parent="VBoxContainer/HBoxContainer/HudRect/MarginContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(130, 130) +layout_mode = 2 +size_flags_horizontal = 0 +size_flags_vertical = 4 +mouse_filter = 2 +scroll_horizontal = 130 +horizontal_scroll_mode = 3 +vertical_scroll_mode = 0 + +[node name="PropsHBox" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/HudRect/MarginContainer/PropScrollContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 0 +theme_override_constants/separation = 0 + +[node name="Head" type="Control" parent="VBoxContainer/HBoxContainer/HudRect/MarginContainer/PropScrollContainer/PropsHBox"] +custom_minimum_size = Vector2(130, 130) +layout_mode = 2 + +[node name="PropContainer" type="CenterContainer" parent="VBoxContainer/HBoxContainer/HudRect/MarginContainer/PropScrollContainer/PropsHBox"] +custom_minimum_size = Vector2(130, 130) +layout_mode = 2 +size_flags_horizontal = 4 + +[node name="Control" type="Control" parent="VBoxContainer/HBoxContainer/HudRect/MarginContainer/PropScrollContainer/PropsHBox/PropContainer"] +custom_minimum_size = Vector2(110, 110) +layout_mode = 2 + +[node name="Prop" type="TextureButton" parent="VBoxContainer/HBoxContainer/HudRect/MarginContainer/PropScrollContainer/PropsHBox/PropContainer/Control"] +layout_mode = 0 +offset_right = 146.0 +offset_bottom = 146.0 +scale = Vector2(0.75, 0.75) +texture_normal = ExtResource("6_0m706") stretch_mode = 5 -[node name="Container" type="Control" parent="VBoxContainer/HBoxContainer/HudPanel"] -clip_contents = true +[node name="Tail" type="Control" parent="VBoxContainer/HBoxContainer/HudRect/MarginContainer/PropScrollContainer/PropsHBox"] custom_minimum_size = Vector2(130, 130) -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -65.0 -offset_top = -65.0 -offset_right = 65.0 -offset_bottom = 65.0 -grow_horizontal = 2 -grow_vertical = 2 -mouse_filter = 1 - -[node name="PropContainer" type="CenterContainer" parent="VBoxContainer/HBoxContainer/HudPanel/Container"] -unique_name_in_owner = true -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -55.5 -offset_top = -20.5 -offset_right = 55.5 -offset_bottom = 20.5 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="Prop" type="TextureRect" parent="VBoxContainer/HBoxContainer/HudPanel/Container/PropContainer"] -unique_name_in_owner = true layout_mode = 2 -texture = ExtResource("8_l2cwd") - -[node name="Mark" type="TextureRect" parent="VBoxContainer/HBoxContainer/HudPanel"] -unique_name_in_owner = true -visible = false -layout_mode = 1 -anchors_preset = 3 -anchor_left = 1.0 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -67.0 -offset_top = -87.0 -grow_horizontal = 0 -grow_vertical = 0 -texture = ExtResource("9_0crjo") [node name="RightMargin" type="MarginContainer" parent="VBoxContainer/HBoxContainer"] layout_mode = 2 +size_flags_horizontal = 0 theme_override_constants/margin_right = 8 [node name="RightButton" type="TextureButton" parent="VBoxContainer/HBoxContainer/RightMargin"] unique_name_in_owner = true +visible = false layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 4 @@ -118,13 +137,36 @@ texture_normal = ExtResource("10_vkaik") texture_pressed = ExtResource("11_a512b") stretch_mode = 5 -[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"] +[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer"] +custom_minimum_size = Vector2(170, 0) layout_mode = 2 +size_flags_horizontal = 0 +mouse_filter = 2 theme_override_constants/margin_top = 8 -[node name="TitleLabel" type="Label" parent="VBoxContainer/MarginContainer"] +[node name="TitleLabel" type="Label" parent="VBoxContainer/MarginContainer2"] unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 4 -theme_override_font_sizes/font_size = 42 text = "1012钥匙" +label_settings = SubResource("LabelSettings_830v8") + +[node name="TestHBox" type="HBoxContainer" parent="."] +visible = false +layout_mode = 0 +offset_left = 450.0 +offset_top = 476.667 +offset_right = 490.0 +offset_bottom = 516.667 +mouse_filter = 2 +script = ExtResource("11_008sv") + +[node name="AddButton" type="Button" parent="TestHBox"] +layout_mode = 2 +theme_override_font_sizes/font_size = 42 +text = "add_item" + +[node name="RemoveButton" type="Button" parent="TestHBox"] +layout_mode = 2 +theme_override_font_sizes/font_size = 42 +text = "remove_item" diff --git a/scene/prop/prop_inventory_resource.gd b/scene/prop/prop_inventory_resource.gd index 9e47c9f1..b3d5c216 100644 --- a/scene/prop/prop_inventory_resource.gd +++ b/scene/prop/prop_inventory_resource.gd @@ -9,7 +9,10 @@ signal current_item_changed(prop_key: String) if current_index != val: val = wrapi(val, 0, enabled_items.size()) current_index = val - current_item_changed.emit(enabled_items[current_index]) + if enabled_items.size() > 0: + current_item_changed.emit(enabled_items[current_index]) + else: + current_item_changed.emit("") func current_item_key(): @@ -26,9 +29,6 @@ func enable_item(prop_key: String) -> void: func disable_item(prop_key: String) -> void: - if prop_key == "prop_空手": - printerr("Cannot disable prop_空手") - return # if enabled_items.has(prop_key): enabled_items.erase(prop_key) # wrap index diff --git a/scene/prop/test_hbox.gd b/scene/prop/test_hbox.gd new file mode 100644 index 00000000..33d85943 --- /dev/null +++ b/scene/prop/test_hbox.gd @@ -0,0 +1,27 @@ +extends HBoxContainer + +var items := ["prop_令牌", "prop_令牌", "prop_信碎片1", "prop_火柴", "prop_绳子", "prop_1012钥匙", "prop_老虎钳"] +var id := 0 + + +func _ready() -> void: + if not GlobalConfig.DEBUG or get_parent().get_parent().name != "root": + queue_free() + else: + visible = true + $AddButton.pressed.connect(_on_add_button_pressed) + $RemoveButton.pressed.connect(_on_remove_button_pressed) + + +func _on_add_button_pressed() -> void: + if id == items.size(): + return + get_parent().enable_prop_item(items[id]) + id += 1 + + +func _on_remove_button_pressed() -> void: + if id == 0: + return + id -= 1 + get_parent().disable_prop_item(items[id])