summaryrefslogtreecommitdiff
path: root/client/menu
diff options
context:
space:
mode:
Diffstat (limited to 'client/menu')
-rw-r--r--client/menu/communicate/popup_message/popup_message.gd11
-rw-r--r--client/menu/ingame.gd39
-rw-r--r--client/menu/lobby.gd42
3 files changed, 39 insertions, 53 deletions
diff --git a/client/menu/communicate/popup_message/popup_message.gd b/client/menu/communicate/popup_message/popup_message.gd
index 6c2c2c0e..513d3840 100644
--- a/client/menu/communicate/popup_message/popup_message.gd
+++ b/client/menu/communicate/popup_message/popup_message.gd
@@ -44,15 +44,8 @@ var server_message_position := Vector2.ZERO
var last_server_message_panel_size := Vector2.ZERO
func _ready():
- game.joined.connect(
- func player_joined():
- is_joined = true
- update_state()
- )
- game.left.connect(
- func player_joined():
- is_joined = false
- update_state()
+ game.join_state_updated.connect(func(state: Game.JoinState):
+ is_joined = state == Game.JoinState.JOINED
)
game.update_tutorial_running.connect(
func a(running: bool):
diff --git a/client/menu/ingame.gd b/client/menu/ingame.gd
index 7052f237..ba365f8e 100644
--- a/client/menu/ingame.gd
+++ b/client/menu/ingame.gd
@@ -26,19 +26,16 @@ extends Menu
var opened
func _ready():
opened = Time.get_ticks_msec()
- game.joined.connect(_on_game_joined)
- game.left.connect(_on_game_left)
- update_button_text()
- game.joined.connect(update_lobby_button)
- game.left.connect(update_lobby_button)
+ game.join_state_updated.connect(_on_game_join_state_changed)
+ _on_game_join_state_changed(game.join_state)
update_lobby_button()
super()
func update_lobby_button():
- lobby_button.disabled = game.in_lobby or not game.is_joined
+ lobby_button.disabled = game.in_lobby or game.join_state == Game.JoinState.SPECTATING
if game.in_lobby:
lobby_button.tooltip_text = "Cannot cancel game since no game is running."
- elif not game.is_joined:
+ elif not game.join_state == Game.JoinState.JOINED:
lobby_button.tooltip_text = "You must join in order to be able to cancel the current game."
else:
lobby_button.tooltip_text = ""
@@ -71,21 +68,15 @@ func _on_lobby_pressed():
exit()
func _on_leave_pressed():
- if game.is_joined:
- game.mp.send_leave(game.player_id)
- elif not game.join_sent:
- leave_button.disabled = true
- game.join()
+ game.toggle_join()
-func _on_game_joined():
- leave_button.disabled = false
- update_button_text()
-
-func _on_game_left():
- update_button_text()
-
-func update_button_text():
- if game.is_joined:
- leave_button.text = tr("c.menu.ingame.leave")
- else:
- leave_button.text = tr("c.menu.ingame.join")
+func _on_game_join_state_changed(state: Game.JoinState):
+ match state:
+ Game.JoinState.JOINED:
+ leave_button.disabled = false
+ leave_button.text = tr("c.menu.ingame.leave")
+ Game.JoinState.SPECTATING:
+ leave_button.disabled = false
+ leave_button.text = tr("c.menu.ingame.join")
+ Game.JoinState.WAITING:
+ leave_button.disabled = true
diff --git a/client/menu/lobby.gd b/client/menu/lobby.gd
index 0dca6f4c..d595444e 100644
--- a/client/menu/lobby.gd
+++ b/client/menu/lobby.gd
@@ -52,8 +52,8 @@ func _ready():
game.update_players.connect(update_players)
initialize()
game.data_updated.connect(initialize)
- game.joined.connect(_on_game_joined)
- game.left.connect(_on_game_left)
+ game.join_state_updated.connect(_on_game_join_state_updated)
+ _on_game_join_state_updated(game.join_state)
check_for_music()
func initialize():
@@ -145,18 +145,6 @@ func _input(_event):
elif Input.is_action_just_pressed("next") and not next_map.disabled:
next_map.emit_signal("pressed")
-func _on_game_joined():
- map_selector.show()
- map_list.show()
- bots_container.show()
- start_button.disabled = false
-
-func _on_game_left():
- map_selector.hide()
- map_list.hide()
- bots_container.hide()
- start_button.disabled = true
-
func _on_left_pressed():
selected_map = (selected_map - 1) % map_count
select_map(selected_map)
@@ -177,13 +165,27 @@ func _on_controller_button_pressed():
game.mp.send_chat(game.player_id, start_msg)
Sound.play_music("stop") # TODO: Game music enter
+func _on_game_join_state_updated(state: Game.JoinState):
+ match state:
+ Game.JoinState.JOINED:
+ map_selector.show()
+ map_list.show()
+ bots_container.show()
+ start_button.disabled = false
+ join_spectate.disabled = false
+ join_spectate.text = tr("c.menu.ingame.spectate")
+ Game.JoinState.SPECTATING:
+ map_selector.hide()
+ map_list.hide()
+ bots_container.hide()
+ start_button.disabled = true
+ join_spectate.disabled = false
+ join_spectate.text = tr("c.menu.ingame.join")
+ Game.JoinState.WAITING:
+ join_spectate.disabled = true
+
func _on_join_spectate_pressed():
- if game.is_joined:
- game.leave()
- join_spectate.text = tr("c.menu.ingame.join")
- elif not game.join_sent:
- game.join()
- join_spectate.text = tr("c.menu.ingame.spectate")
+ game.toggle_join()
func check_for_music():
if visible: