Merge branch 'demo'
This commit is contained in:
commit
1f86933a31
@ -7,7 +7,7 @@ class_name Closeup2D
|
|||||||
signal exit(arg)
|
signal exit(arg)
|
||||||
|
|
||||||
@export var packed_scene: PackedScene
|
@export var packed_scene: PackedScene
|
||||||
@export var quit_closeup_on_escape := true
|
@export var quit_closeup_on_cancel := true
|
||||||
@export_tool_button("新建特写场景") var create_closeup_scene = _create_scene_with_script
|
@export_tool_button("新建特写场景") var create_closeup_scene = _create_scene_with_script
|
||||||
|
|
||||||
var current_child: Node
|
var current_child: Node
|
||||||
@ -52,10 +52,7 @@ func _exit(arg = null):
|
|||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if not current_child:
|
if not current_child:
|
||||||
return
|
return
|
||||||
if (
|
if quit_closeup_on_cancel and event.is_action_pressed("cancel"):
|
||||||
quit_closeup_on_escape
|
|
||||||
and (event.is_action_pressed("cancel") or event.is_action_pressed("escape"))
|
|
||||||
):
|
|
||||||
get_viewport().set_input_as_handled()
|
get_viewport().set_input_as_handled()
|
||||||
_exit()
|
_exit()
|
||||||
# 在有特写界面时,阻塞 interact 输入
|
# 在有特写界面时,阻塞 interact 输入
|
||||||
@ -73,7 +70,9 @@ var script_root_dir = "res://scene/ground/script/"
|
|||||||
|
|
||||||
func _create_scene_with_script():
|
func _create_scene_with_script():
|
||||||
if packed_scene:
|
if packed_scene:
|
||||||
print_rich("[color=orange][Closeup2D] packed_scene already exists, skip creating new scene and script.")
|
print_rich(
|
||||||
|
"[color=orange][Closeup2D] packed_scene already exists, skip creating new scene and script."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
var script = script_template.duplicate(true) as Script
|
var script = script_template.duplicate(true) as Script
|
||||||
var new_packed_scene = PackedScene.new()
|
var new_packed_scene = PackedScene.new()
|
||||||
|
@ -44,7 +44,7 @@ autoplay = "小蝶探头"
|
|||||||
|
|
||||||
[node name="Closeup鬼差探头" parent="Ground/DeployLayer" index="3" instance=ExtResource("8_2jx0x")]
|
[node name="Closeup鬼差探头" parent="Ground/DeployLayer" index="3" instance=ExtResource("8_2jx0x")]
|
||||||
packed_scene = ExtResource("5_dnd0r")
|
packed_scene = ExtResource("5_dnd0r")
|
||||||
quit_closeup_on_escape = false
|
quit_closeup_on_cancel = false
|
||||||
|
|
||||||
[node name="Light" parent="Ground/AmbientLayer" index="0" instance=ExtResource("5_rw4mf")]
|
[node name="Light" parent="Ground/AmbientLayer" index="0" instance=ExtResource("5_rw4mf")]
|
||||||
position = Vector2(123, -20)
|
position = Vector2(123, -20)
|
||||||
|
@ -176,7 +176,7 @@ hook_method = "wood_puppet"
|
|||||||
[node name="Closeup拿人偶后记忆闪回" parent="Ground/DeployLayer" index="5" instance=ExtResource("10_2yvhw")]
|
[node name="Closeup拿人偶后记忆闪回" parent="Ground/DeployLayer" index="5" instance=ExtResource("10_2yvhw")]
|
||||||
position = Vector2(-108, -168)
|
position = Vector2(-108, -168)
|
||||||
packed_scene = ExtResource("10_7mq0m")
|
packed_scene = ExtResource("10_7mq0m")
|
||||||
quit_closeup_on_escape = false
|
quit_closeup_on_cancel = false
|
||||||
action_key = 3
|
action_key = 3
|
||||||
first_interact_os_key = "c02_一楼戏台"
|
first_interact_os_key = "c02_一楼戏台"
|
||||||
|
|
||||||
|
@ -1165,7 +1165,7 @@ frame_progress = 0.121203
|
|||||||
[node name="Closeup弹珠游戏" parent="Ground/DeployLayer" index="15" instance=ExtResource("11_owxx3")]
|
[node name="Closeup弹珠游戏" parent="Ground/DeployLayer" index="15" instance=ExtResource("11_owxx3")]
|
||||||
position = Vector2(322, -269)
|
position = Vector2(322, -269)
|
||||||
packed_scene = ExtResource("12_intre")
|
packed_scene = ExtResource("12_intre")
|
||||||
quit_closeup_on_escape = false
|
quit_closeup_on_cancel = false
|
||||||
|
|
||||||
[node name="Closeup水盆" parent="Ground/DeployLayer" index="16" instance=ExtResource("11_owxx3")]
|
[node name="Closeup水盆" parent="Ground/DeployLayer" index="16" instance=ExtResource("11_owxx3")]
|
||||||
position = Vector2(289, 16)
|
position = Vector2(289, 16)
|
||||||
@ -1175,7 +1175,7 @@ first_interact_os_key = "c02_二楼水盆"
|
|||||||
[node name="Closeup谢幕演出" parent="Ground/DeployLayer" index="17" instance=ExtResource("11_owxx3")]
|
[node name="Closeup谢幕演出" parent="Ground/DeployLayer" index="17" instance=ExtResource("11_owxx3")]
|
||||||
position = Vector2(518, -272)
|
position = Vector2(518, -272)
|
||||||
packed_scene = ExtResource("25_m28ab")
|
packed_scene = ExtResource("25_m28ab")
|
||||||
quit_closeup_on_escape = false
|
quit_closeup_on_cancel = false
|
||||||
action_key = 3
|
action_key = 3
|
||||||
|
|
||||||
[node name="c02_final" type="Node2D" parent="Ground/DeployLayer" index="18"]
|
[node name="c02_final" type="Node2D" parent="Ground/DeployLayer" index="18"]
|
||||||
|
@ -70,7 +70,7 @@ var quitting = false
|
|||||||
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("escape") or event.is_action_pressed("cancel"):
|
if event.is_action_pressed("cancel"):
|
||||||
if quitting:
|
if quitting:
|
||||||
# 禁止手动退出,需要 exit.emit(true)
|
# 禁止手动退出,需要 exit.emit(true)
|
||||||
get_viewport().set_input_as_handled()
|
get_viewport().set_input_as_handled()
|
||||||
|
@ -324,7 +324,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
else:
|
else:
|
||||||
# hud 无效shaking
|
# hud 无效shaking
|
||||||
hud.on_toggle_invalid_prop()
|
hud.on_toggle_invalid_prop()
|
||||||
elif event.is_action_pressed("escape"):
|
elif event.is_action_pressed("cancel"):
|
||||||
get_viewport().set_input_as_handled()
|
get_viewport().set_input_as_handled()
|
||||||
exit.emit(false)
|
exit.emit(false)
|
||||||
|
|
||||||
|
@ -166,9 +166,8 @@ func _move_button(delta: int) -> void:
|
|||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if not visible:
|
if not visible:
|
||||||
return
|
return
|
||||||
# 阻止输入事件传递给其他节点
|
if event.is_action_pressed("cancel"):
|
||||||
get_viewport().set_input_as_handled()
|
get_viewport().set_input_as_handled()
|
||||||
if event.is_action_pressed("cancel") or event.is_action_pressed("escape"):
|
|
||||||
var success = ArchiveManager.archive.bayinhe_mode == "finished"
|
var success = ArchiveManager.archive.bayinhe_mode == "finished"
|
||||||
exit.emit(success)
|
exit.emit(success)
|
||||||
visible = false
|
visible = false
|
||||||
@ -178,12 +177,16 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
if ArchiveManager.archive.bayinhe_mode == "closed":
|
if ArchiveManager.archive.bayinhe_mode == "closed":
|
||||||
# move button
|
# move button
|
||||||
if event.is_action_pressed("up"):
|
if event.is_action_pressed("up"):
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
_move_button(1)
|
_move_button(1)
|
||||||
elif event.is_action_pressed("down"):
|
elif event.is_action_pressed("down"):
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
_move_button(-1)
|
_move_button(-1)
|
||||||
elif event.is_action_pressed("left"):
|
elif event.is_action_pressed("left"):
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
current_selected_btn = clampi(current_selected_btn - 1, 0, 8)
|
current_selected_btn = clampi(current_selected_btn - 1, 0, 8)
|
||||||
elif event.is_action_pressed("right"):
|
elif event.is_action_pressed("right"):
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
current_selected_btn = clampi(current_selected_btn + 1, 0, 8)
|
current_selected_btn = clampi(current_selected_btn + 1, 0, 8)
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,11 +156,8 @@ func _post_success():
|
|||||||
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("escape") or event.is_action_pressed("bag"):
|
|
||||||
return
|
|
||||||
# block all input except "escape" or "bag"
|
|
||||||
get_viewport().set_input_as_handled()
|
|
||||||
if event.is_action_pressed("cancel"):
|
if event.is_action_pressed("cancel"):
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
if game_finished:
|
if game_finished:
|
||||||
success.emit()
|
success.emit()
|
||||||
else:
|
else:
|
||||||
@ -194,6 +191,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
_rotate_part()
|
_rotate_part()
|
||||||
handled = true
|
handled = true
|
||||||
if handled:
|
if handled:
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
$SfxMove.play()
|
$SfxMove.play()
|
||||||
_display_selected()
|
_display_selected()
|
||||||
_check_answer()
|
_check_answer()
|
||||||
|
@ -85,14 +85,14 @@ func _ready() -> void:
|
|||||||
display_prop.gui_input.connect(_on_prop_gui_input.bind(-1))
|
display_prop.gui_input.connect(_on_prop_gui_input.bind(-1))
|
||||||
_load_items_config_to_dict("ImportantPropItems")
|
_load_items_config_to_dict("ImportantPropItems")
|
||||||
_load_items_config_to_dict("PropItems")
|
_load_items_config_to_dict("PropItems")
|
||||||
_load_from_archive()
|
_reload_cache_and_realign_display()
|
||||||
selecting_bg.modulate.a = 0.0
|
selecting_bg.modulate.a = 0.0
|
||||||
prop_scroll.scroll_horizontal = PROP_CONTAINER_X
|
prop_scroll.scroll_horizontal = PROP_CONTAINER_X
|
||||||
props_bag_scroll.scroll_horizontal = 0.0
|
props_bag_scroll.scroll_horizontal = 0.0
|
||||||
props_bag_scroll.custom_minimum_size.x = 0.0
|
props_bag_scroll.custom_minimum_size.x = 0.0
|
||||||
# focus_exited.connect(_on_focus_exited)
|
# focus_exited.connect(_on_focus_exited)
|
||||||
# 存档更新时,从存档加载 prop
|
# 存档更新时,从存档加载 prop
|
||||||
ArchiveManager.archive_loaded.connect(_load_from_archive)
|
ArchiveManager.archive_loaded.connect(_reload_cache_and_realign_display)
|
||||||
# tween timer
|
# tween timer
|
||||||
timer.wait_time = display_time
|
timer.wait_time = display_time
|
||||||
timer.one_shot = true
|
timer.one_shot = true
|
||||||
@ -158,11 +158,11 @@ func _load_items_config_to_dict(title: String):
|
|||||||
# return content
|
# return content
|
||||||
|
|
||||||
|
|
||||||
func _load_from_archive() -> void:
|
func _reload_cache_and_realign_display() -> void:
|
||||||
if ArchiveManager.archive:
|
if ArchiveManager.archive:
|
||||||
inventory = ArchiveManager.archive.prop_inventory
|
inventory = ArchiveManager.archive.prop_inventory
|
||||||
_align_container_size()
|
|
||||||
_load_texture_cache()
|
_load_texture_cache()
|
||||||
|
_align_container_size()
|
||||||
_update_prop_display_with_texture()
|
_update_prop_display_with_texture()
|
||||||
|
|
||||||
|
|
||||||
@ -171,9 +171,7 @@ func checkout_inventory(character: String) -> void:
|
|||||||
printerr("PropHud checkout_inventory: No inventory found.")
|
printerr("PropHud checkout_inventory: No inventory found.")
|
||||||
return
|
return
|
||||||
inventory.checkout(character)
|
inventory.checkout(character)
|
||||||
_align_container_size()
|
_reload_cache_and_realign_display()
|
||||||
_load_texture_cache()
|
|
||||||
_update_prop_display_with_texture()
|
|
||||||
|
|
||||||
|
|
||||||
func hide_hud():
|
func hide_hud():
|
||||||
@ -201,6 +199,9 @@ func _load_texture_cache() -> void:
|
|||||||
# 以 items_dict 为准,如果 enabled_items 中的 key 不存在,则删除
|
# 以 items_dict 为准,如果 enabled_items 中的 key 不存在,则删除
|
||||||
if not key in items_dict:
|
if not key in items_dict:
|
||||||
inventory.disable_item(key)
|
inventory.disable_item(key)
|
||||||
|
printerr(
|
||||||
|
"PropHud _load_texture_cache: key not found in items_dict:", key, ". remove item."
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
var path = items_dict[key].texture_path
|
var path = items_dict[key].texture_path
|
||||||
if not path:
|
if not path:
|
||||||
@ -262,7 +263,15 @@ func _display_texture_by_key(button, key) -> void:
|
|||||||
button.texture_normal = null
|
button.texture_normal = null
|
||||||
return
|
return
|
||||||
var item = items_dict[key]
|
var item = items_dict[key]
|
||||||
button.texture_normal = cached_inventory_textures[item.key]
|
var texture = cached_inventory_textures.get(item.key)
|
||||||
|
if not texture:
|
||||||
|
if item.texture_path:
|
||||||
|
texture = load(item.texture_path) as Texture2D
|
||||||
|
if not texture:
|
||||||
|
printerr("PropHud _display_texture_by_key: No texture found for item:", item)
|
||||||
|
else:
|
||||||
|
cached_inventory_textures[item.key] = texture
|
||||||
|
button.texture_normal = texture
|
||||||
var t_size = button.texture_normal.get_size()
|
var t_size = button.texture_normal.get_size()
|
||||||
var max_x = max(t_size.x, t_size.y)
|
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)
|
var p_scale = min(PROP_CONTROL_X / t_size.x, PROP_CONTROL_X / t_size.y)
|
||||||
@ -480,9 +489,7 @@ func enable_prop_item(prop_key: String, inspect := true) -> void:
|
|||||||
push_error("PropItem not found! key=" + prop_key)
|
push_error("PropItem not found! key=" + prop_key)
|
||||||
return
|
return
|
||||||
inventory.enable_item(prop_key)
|
inventory.enable_item(prop_key)
|
||||||
_align_container_size()
|
_reload_cache_and_realign_display()
|
||||||
_load_texture_cache()
|
|
||||||
_update_prop_display_with_texture()
|
|
||||||
if GlobalConfig.DEBUG:
|
if GlobalConfig.DEBUG:
|
||||||
print("PropHUD Enable prop item:", prop_key)
|
print("PropHUD Enable prop item:", prop_key)
|
||||||
if inspect:
|
if inspect:
|
||||||
@ -519,9 +526,7 @@ func disable_prop_item(prop_key: String) -> void:
|
|||||||
if not inventory or not prop_key:
|
if not inventory or not prop_key:
|
||||||
return
|
return
|
||||||
inventory.disable_item(prop_key)
|
inventory.disable_item(prop_key)
|
||||||
_align_container_size()
|
_reload_cache_and_realign_display()
|
||||||
_load_texture_cache()
|
|
||||||
_update_prop_display_with_texture()
|
|
||||||
|
|
||||||
|
|
||||||
func _align_container_size() -> void:
|
func _align_container_size() -> void:
|
||||||
|
@ -66,7 +66,7 @@ func disable_item(prop_key: String) -> void:
|
|||||||
# if enabled_items.has(prop_key):
|
# if enabled_items.has(prop_key):
|
||||||
enabled_items.erase(prop_key)
|
enabled_items.erase(prop_key)
|
||||||
# wrap index
|
# wrap index
|
||||||
current_index = wrapi(current_index, 0, enabled_items.size())
|
current_index = clampi(current_index, 0, enabled_items.size())
|
||||||
|
|
||||||
|
|
||||||
# return true if the index changed
|
# return true if the index changed
|
||||||
|
Loading…
Reference in New Issue
Block a user