Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c5b6b05801 |
@@ -72,24 +72,34 @@ func join():
|
|||||||
print("Client started")
|
print("Client started")
|
||||||
connect_ui.hide()
|
connect_ui.hide()
|
||||||
|
|
||||||
# Ensure game window has keyboard focus for input
|
# Force window focus for keyboard input (Windows GUI apps need this)
|
||||||
get_window().grab_focus()
|
_ensure_input_focus()
|
||||||
|
|
||||||
# Only start manually if NetworkEvents is not handling it (e.g. multiplayer-simple)
|
# Only start manually if NetworkEvents is not handling it (e.g. multiplayer-simple)
|
||||||
if not NetworkEvents.enabled:
|
if not NetworkEvents.enabled:
|
||||||
NetworkTime.start()
|
NetworkTime.start()
|
||||||
|
|
||||||
|
func _ensure_input_focus() -> void:
|
||||||
|
## Force the game window to have keyboard focus and captured mouse.
|
||||||
|
## On Windows GUI exports, the window may not hold keyboard focus after
|
||||||
|
## the connection UI is dismissed, causing Input.get_axis() to return 0.
|
||||||
|
OS.move_to_foreground()
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
# Deferred retry after window settles
|
||||||
|
get_window().call_deferred("grab_focus")
|
||||||
|
Input.call_deferred("set_mouse_mode", Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
# Hide and show UI as appropriate
|
# Hide and show UI as appropriate
|
||||||
# These handlers are necessary, since the game could have started via
|
# These handlers are necessary, since the game could have started via
|
||||||
# autoconnect, or any other method
|
# autoconnect, or any other method
|
||||||
NetworkEvents.on_client_start.connect(func(__):
|
NetworkEvents.on_client_start.connect(func(__):
|
||||||
connect_ui.hide()
|
connect_ui.hide()
|
||||||
get_window().grab_focus()
|
_ensure_input_focus()
|
||||||
)
|
)
|
||||||
NetworkEvents.on_server_start.connect(func():
|
NetworkEvents.on_server_start.connect(func():
|
||||||
connect_ui.hide()
|
connect_ui.hide()
|
||||||
get_window().grab_focus()
|
_ensure_input_focus()
|
||||||
)
|
)
|
||||||
NetworkEvents.on_client_stop.connect(func(): connect_ui.show())
|
NetworkEvents.on_client_stop.connect(func(): connect_ui.show())
|
||||||
NetworkEvents.on_server_stop.connect(func(): connect_ui.show())
|
NetworkEvents.on_server_stop.connect(func(): connect_ui.show())
|
||||||
|
|||||||
Reference in New Issue
Block a user