diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/game.gd | 48 | ||||
-rw-r--r-- | client/menu/communicate/popup_message/popup_message.gd | 11 | ||||
-rw-r--r-- | client/menu/ingame.gd | 39 | ||||
-rw-r--r-- | client/menu/lobby.gd | 42 | ||||
-rw-r--r-- | client/player/controllable_player.gd | 2 |
5 files changed, 67 insertions, 75 deletions
diff --git a/client/game.gd b/client/game.gd index cd678897..7cfab9c9 100644 --- a/client/game.gd +++ b/client/game.gd @@ -21,9 +21,8 @@ extends Node3D signal update_players(players: Dictionary) signal data_updated() signal in_lobby_updated(in_lobby: bool) +signal join_state_updated(state: JoinState) signal text_message(player: int, text: String, timeout_initial: float, timeout_remaining: float) -signal joined() -signal left() signal update_tutorial_running(running: bool) enum SpectatingMode { @@ -31,6 +30,12 @@ enum SpectatingMode { FREE, } +enum JoinState { + SPECTATING, + WAITING, + JOINED, +} + var player_id: int = -1 var item_names: Array = [] var item_index_by_name: Dictionary = {} @@ -42,10 +47,10 @@ var maps: Array = [] var bot_algos: Array var text_message_history: Array[Array] = [] +var join_state: JoinState = JoinState.SPECTATING + var in_lobby := false var is_replay := false -var is_joined := false -var join_sent := false var tutorial_running := false var tutorial_queue := [] var last_position := Vector2(0, 0) @@ -99,9 +104,7 @@ func handle_packet(p): in_lobby_updated.connect(player_instance.onscreen_controls.in_lobby_updated) player_instance.onscreen_controls.in_lobby_updated(in_lobby) camera.target = player_instance.movement_base - is_joined = true - join_sent = false - joined.emit() + set_join_state(JoinState.JOINED) else: player_instance = Player.new(p.id, p.name, p.position, p.character, self) players[p.id] = player_instance @@ -115,8 +118,7 @@ func handle_packet(p): tutorial_queue.erase(player.current_item_message) pinned_items.clear_item(p.id) if p.id == player_id: - is_joined = false - left.emit() + set_join_state(JoinState.SPECTATING) camera.target = $Center if player.hand != null: player.hand.queue_free() @@ -253,8 +255,8 @@ func handle_packet(p): await get_parent()._menu_exit() lobby.visible = in_lobby - if lobby and not join_sent: - join() + if lobby and join_state == JoinState.SPECTATING: + toggle_join() in_lobby_updated.emit(in_lobby) "score": @@ -324,16 +326,20 @@ func handle_packet(p): _: push_error("Unrecognized packet type: %s" % p.type) -func join(): - if join_sent: - push_error("Join was already sent. Tried to join twice.") - return - join_sent = true - mp.send_join(Global.get_profile("username"), Global.get_profile("character")) +func set_join_state(state: JoinState): + join_state = state + join_state_updated.emit(state) -func leave(): - join_sent = false - mp.send_leave(player_id) +func toggle_join(): + match join_state: + JoinState.SPECTATING: + set_join_state(JoinState.WAITING) + mp.send_join(Global.get_profile("username"), Global.get_profile("character")) + JoinState.WAITING: + push_error("Join/Leave action already toggled.") + JoinState.JOINED: + set_join_state(JoinState.WAITING) + mp.send_leave(player_id) func _process(delta): update_center() @@ -360,7 +366,7 @@ func get_tile_interactive(pos: Vector2i) -> bool: func update_center(): - if is_joined: + if join_state != JoinState.SPECTATING: return if Input.get_vector("left", "right", "forwards", "backwards").normalized().length() > .1: spectating_mode = SpectatingMode.FREE 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: diff --git a/client/player/controllable_player.gd b/client/player/controllable_player.gd index 0cabcb64..c88941d7 100644 --- a/client/player/controllable_player.gd +++ b/client/player/controllable_player.gd @@ -43,7 +43,7 @@ func _ready(): add_child(timer) timer.start() timer.connect("timeout", func(): - if game.mp != null and game.join_sent: + if game.mp != null and game.join_state == Game.JoinState.JOINED: game.mp.send_movement(game.player_id, position_, direction, boosting) ) add_child(onscreen_controls) |