Fix in-game multiplayer session switching

This commit is contained in:
Alexander Sellite 2026-08-14 22:48:59 -04:00
parent 2526b5578b
commit 8c2f8715b0
5 changed files with 341 additions and 16 deletions

View file

@ -2,6 +2,7 @@ class_name JoinGamePage
extends Control
signal join_requested(endpoint: String)
signal join_confirmation_requested(endpoint: String)
signal back_requested
enum Mode {
@ -63,6 +64,8 @@ var _editing_entry_id: String = ""
var _name_entry_active: bool = false
var _delete_armed: bool = false
var _connection_error_latched: bool = false
var _pending_confirmation_endpoint: String = ""
var _pending_confirmation_room: Dictionary = {}
func _ready() -> void:
@ -189,6 +192,11 @@ func open_page(preserved_endpoint: String = "") -> void:
func close_page() -> void:
cancel_pending_join_confirmation()
hide_for_join_confirmation()
func hide_for_join_confirmation() -> void:
_clear_edit_state()
_discovery_refresh_timer.stop()
hide()
@ -206,6 +214,28 @@ func set_status(message: String) -> void:
_set_status(_friendly_connection_message(message), true)
func cancel_pending_join_confirmation() -> void:
_pending_confirmation_endpoint = ""
_pending_confirmation_room.clear()
func confirm_pending_join() -> bool:
if _pending_confirmation_endpoint.is_empty():
_set_status("No server is waiting to be joined.", true)
return false
var endpoint_text: String = _pending_confirmation_endpoint
var room: Dictionary = _pending_confirmation_room.duplicate(true)
cancel_pending_join_confirmation()
if not room.is_empty():
if _discovery == null or not _discovery.prepare_public_join(room):
_set_status("Could not prepare the public connection.", true)
return false
return true
_set_status("Connecting…")
join_requested.emit(endpoint_text)
return true
func _set_mode(mode: Mode, clear_connection_error: bool = true) -> void:
if clear_connection_error:
_connection_error_latched = false
@ -236,6 +266,7 @@ func _request_join() -> void:
]:
_network_session.reset_failure()
var endpoint_text: String = _address.text
var discovery_room: Dictionary = {}
if _mode == Mode.DISCOVER:
var room: Dictionary = _selected_discovery_room()
if _discovery != null and _discovery.is_own_room(room):
@ -244,15 +275,26 @@ func _request_join() -> void:
if _discovery_room_is_full(room):
_set_status("That room is full.", true)
return
if _discovery == null or not _discovery.prepare_public_join(room):
if _discovery == null:
_set_status("Could not prepare the public connection.", true)
return
return
endpoint_text = _discovery.room_endpoint(room)
discovery_room = room.duplicate(true)
elif _mode != Mode.DIRECT and _selected_entry != null:
endpoint_text = _selected_entry.normalized_endpoint
var endpoint: ConnectionEndpoint = EndpointParser.parse(endpoint_text)
if not endpoint.is_valid():
_set_status(endpoint.error_message, true)
return
if _gameplay_context:
_pending_confirmation_endpoint = endpoint.normalized_display
_pending_confirmation_room = discovery_room
join_confirmation_requested.emit(endpoint.normalized_display)
return
if not discovery_room.is_empty():
if not _discovery.prepare_public_join(discovery_room):
_set_status("Could not prepare the public connection.", true)
return
_set_status("Connecting…")
_address.text = endpoint.normalized_display
join_requested.emit(endpoint.normalized_display)

View file

@ -73,7 +73,7 @@ var _action_in_progress: bool = false
var _root_transition_active: bool = false
var _root_transition_generation: int = 0
var _closing_menu: bool = false
var _pending_join_endpoint: String = ""
var _confirmation_returns_to_join_game: bool = false
func _ready() -> void:
@ -92,7 +92,10 @@ func _ready() -> void:
_settings_panel.navigation_transition_started.connect(
_emit_transition_flurry
)
_join_game_page.join_requested.connect(_on_join_game_requested)
_join_game_page.join_requested.connect(_on_confirmed_join_requested)
_join_game_page.join_confirmation_requested.connect(
_on_join_confirmation_requested
)
_join_game_page.back_requested.connect(_close_join_game)
_confirmation_page.hide_page()
resized.connect(_update_responsive_pause_stage)
@ -139,6 +142,7 @@ func open_menu() -> void:
_join_game_page.close_page()
_confirmation_page.hide_page()
_confirmation_action = ConfirmationAction.NONE
_confirmation_returns_to_join_game = false
_action_in_progress = false
_root_page.hide_page()
show()
@ -238,20 +242,29 @@ func _close_join_game() -> void:
_begin_root_entry(true)
func _on_join_game_requested(endpoint: String) -> void:
func _on_join_confirmation_requested(_endpoint: String) -> void:
if _action_in_progress or _root_transition_active:
_join_game_page.cancel_pending_join_confirmation()
return
_pending_join_endpoint = endpoint
_open_confirmation(
ConfirmationAction.JOIN_ANOTHER,
"join another game?",
_confirmation_action = ConfirmationAction.JOIN_ANOTHER
_confirmation_returns_to_join_game = true
_confirmation_page.configure(
(
"your progression will be saved first. "
+ "current players will be disconnected if you are hosting."
"join another game?\n\n"
+ "your progression will be saved first. current players will be "
+ "disconnected if you are hosting."
),
"save and join",
false
"cancel",
BubbleConfirmationPageType.InitialFocus.CONFIRM,
)
_join_game_page.hide_for_join_confirmation()
_emit_transition_flurry()
_show_confirmation()
func _on_confirmed_join_requested(endpoint: String) -> void:
join_game_requested.emit(endpoint)
func report_network_error(message: String) -> void:
@ -340,6 +353,7 @@ func _open_confirmation(
) -> void:
if _action_in_progress or _root_transition_active:
return
_confirmation_returns_to_join_game = false
_confirmation_action = action
_confirmation_page.configure(
"%s\n\n%s" % [title, message],
@ -380,6 +394,11 @@ func _close_confirmation() -> void:
func _finish_confirmation_cancel() -> void:
if _confirmation_returns_to_join_game:
_confirmation_returns_to_join_game = false
_join_game_page.cancel_pending_join_confirmation()
_join_game_page.open_page()
return
_begin_root_entry(true)
@ -414,9 +433,9 @@ func _finish_confirmation_accept(action: ConfirmationAction) -> void:
ConfirmationAction.QUIT_ANYWAY:
quit_requested.emit()
ConfirmationAction.JOIN_ANOTHER:
_join_game_page.close_page()
join_game_requested.emit(_pending_join_endpoint)
_pending_join_endpoint = ""
_confirmation_returns_to_join_game = false
_join_game_page.open_page()
_join_game_page.confirm_pending_join()
_:
_action_in_progress = false
_begin_root_entry(false)
@ -507,6 +526,7 @@ func _finish_close(reason: CloseReason, restore_controls: bool) -> void:
_root_page.hide_page()
_confirmation_page.hide_page()
_confirmation_action = ConfirmationAction.NONE
_confirmation_returns_to_join_game = false
_action_in_progress = false
_transition_flurry.clear_flurries()
hide()