Co-op pass: host-disconnect handling, spectate, late-join wave sync
- Clients now handle the host closing the arena: bank winnings if still alive (retire), reset the HUD, and return to the camp menu instead of being stranded in a dead world - Death in co-op offers Spectate when a teammate is still fighting: closes the results overlay and watches the run; the escape menu gains a "Back to Camp" option for dead spectators to leave later - Late joiners receive the current wave number on connect so their HUD doesn't sit on "Prepare..." until the next wave starts
This commit is contained in:
@@ -54,14 +54,19 @@ func toggle_menu():
|
||||
if player and player.is_multiplayer_authority():
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
## Retiring is only possible while alive with an active run
|
||||
## Alive with an active run: retire (bank winnings).
|
||||
## Dead but spectating a live session: plain trip home (settlement already done).
|
||||
func _update_retire_button():
|
||||
if not _retire_button:
|
||||
return
|
||||
var can_retire = GameState.run_active and player and not player.is_dead
|
||||
_retire_button.visible = can_retire
|
||||
if can_retire:
|
||||
if GameState.run_active and player and not player.is_dead:
|
||||
_retire_button.visible = true
|
||||
_retire_button.text = "Retire to Camp (+%dg)" % GameState.run_gold
|
||||
elif multiplayer.multiplayer_peer != null and player and player.is_dead:
|
||||
_retire_button.visible = true
|
||||
_retire_button.text = "Back to Camp"
|
||||
else:
|
||||
_retire_button.visible = false
|
||||
|
||||
## Called when Resume button is clicked
|
||||
func _on_resume_pressed():
|
||||
|
||||
@@ -80,6 +80,15 @@ func _ready():
|
||||
|
||||
_add_spacer(vbox, 16)
|
||||
|
||||
# Spectate option - only when a teammate is still fighting
|
||||
if _teammates_still_alive():
|
||||
var spectate_button = Button.new()
|
||||
spectate_button.text = "Spectate"
|
||||
spectate_button.custom_minimum_size = Vector2(0, 44)
|
||||
spectate_button.pressed.connect(_on_spectate_pressed)
|
||||
vbox.add_child(spectate_button)
|
||||
_add_spacer(vbox, 6)
|
||||
|
||||
# Return button
|
||||
var return_button = Button.new()
|
||||
return_button.text = "Return to Camp"
|
||||
@@ -90,6 +99,25 @@ func _ready():
|
||||
# Make sure the mouse is usable on the overlay
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
## Any other living player in the arena?
|
||||
func _teammates_still_alive() -> bool:
|
||||
if multiplayer.multiplayer_peer == null:
|
||||
return false
|
||||
var level = get_tree().get_current_scene()
|
||||
if not level or not level.has_node("PlayersContainer"):
|
||||
return false
|
||||
var my_id = multiplayer.get_unique_id()
|
||||
for p in level.get_node("PlayersContainer").get_children():
|
||||
if p is Character and not p.is_dead and str(p.name).to_int() != my_id:
|
||||
return true
|
||||
return false
|
||||
|
||||
## Close the overlay and watch the run play out (escape menu can leave later).
|
||||
## For the host this also keeps the server alive for everyone else.
|
||||
func _on_spectate_pressed():
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
queue_free()
|
||||
|
||||
func _add_header(parent: Control, text: String):
|
||||
var label = Label.new()
|
||||
label.text = text
|
||||
|
||||
Reference in New Issue
Block a user