Fix: disable ESCGame inputs until signal room_ready is emitted (#582)
* Fix: disable ESCGame inputs until signal room_ready is emitted * fix: add a new function to use in _input() to check for inputs * Apply suggestions from code review Co-authored-by: balloonpopper <5151242+balloonpopper@users.noreply.github.com> Co-authored-by: Duncan Brown <duncan@prometheussoftware.ca>
This commit is contained in:
@@ -38,6 +38,11 @@ export(NodePath) var ui_parent_control_node
|
|||||||
# A reference to the node handling tooltips
|
# A reference to the node handling tooltips
|
||||||
var tooltip_node: Object
|
var tooltip_node: Object
|
||||||
|
|
||||||
|
# Boolean indicating whether the game scene is ready to accept inputs
|
||||||
|
# from the player. This enables using escoria.is_ready_for_inputs() in _input()
|
||||||
|
# function of game.gd script.
|
||||||
|
var room_ready_for_inputs: bool = false
|
||||||
|
|
||||||
|
|
||||||
# Function called when ESCGame enters the scene tree.
|
# Function called when ESCGame enters the scene tree.
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
@@ -52,6 +57,12 @@ func _enter_tree():
|
|||||||
"_on_action_finished"
|
"_on_action_finished"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
escoria.main.connect(
|
||||||
|
"room_ready",
|
||||||
|
self,
|
||||||
|
"_on_room_ready"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Function called when ESCGame exits the scene tree.
|
# Function called when ESCGame exits the scene tree.
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
@@ -447,3 +458,8 @@ func escoria_show_ui():
|
|||||||
"esc_game.gd#escoria_show_ui",
|
"esc_game.gd#escoria_show_ui",
|
||||||
["UI parent Control node not defined!"]
|
["UI parent Control node not defined!"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Manage signal room_deady from main.gd.
|
||||||
|
func _on_room_ready():
|
||||||
|
room_ready_for_inputs = true
|
||||||
|
|||||||
@@ -389,3 +389,14 @@ func _handle_direct_scene_run() -> void:
|
|||||||
if current_scene_root is ESCRoom:
|
if current_scene_root is ESCRoom:
|
||||||
escoria.object_manager.set_current_room(current_scene_root)
|
escoria.object_manager.set_current_room(current_scene_root)
|
||||||
|
|
||||||
|
|
||||||
|
# Used by game.gd to determine whether the game scene is ready to take inputs
|
||||||
|
# from the _input() function. To do so, the current_scene must be set, the game
|
||||||
|
# scene must be set, and the game scene must've been notified that the room
|
||||||
|
# is ready.
|
||||||
|
#
|
||||||
|
# *Returns*
|
||||||
|
# true if game scene is ready for inputs
|
||||||
|
func is_ready_for_inputs() -> bool:
|
||||||
|
return escoria.main.current_scene and escoria.main.current_scene.game \
|
||||||
|
and escoria.main.current_scene.game.room_ready_for_inputs
|
||||||
|
|||||||
@@ -90,10 +90,10 @@ func set_scene_finish() -> void:
|
|||||||
current_scene.visible = true
|
current_scene.visible = true
|
||||||
|
|
||||||
clear_previous_scene()
|
clear_previous_scene()
|
||||||
|
|
||||||
emit_signal("room_ready")
|
emit_signal("room_ready")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Cleanup the previous scene if there was one.
|
# Cleanup the previous scene if there was one.
|
||||||
func clear_previous_scene() -> void:
|
func clear_previous_scene() -> void:
|
||||||
if previous_scene == null:
|
if previous_scene == null:
|
||||||
|
|||||||
@@ -97,10 +97,10 @@ func _exit_tree():
|
|||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if escoria.main.current_scene and escoria.main.current_scene.game:
|
if escoria.is_ready_for_inputs():
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
escoria.main.current_scene.game. \
|
escoria.main.current_scene.game. \
|
||||||
update_tooltip_following_mouse_position(event.position)
|
update_tooltip_following_mouse_position(event.position)
|
||||||
|
|
||||||
|
|
||||||
# https://github.com/godotengine/godot-demo-projects/blob/3.4-585455e/misc/joypads/joypads.gd
|
# https://github.com/godotengine/godot-demo-projects/blob/3.4-585455e/misc/joypads/joypads.gd
|
||||||
|
|||||||
Reference in New Issue
Block a user