diff --git a/rust/src/cli_parser.rs b/rust/src/cli_parser.rs index d261588..02124bf 100644 --- a/rust/src/cli_parser.rs +++ b/rust/src/cli_parser.rs @@ -111,7 +111,7 @@ impl CliParser { }); if let Some((map_idx, _)) = map { game.bind_mut().forced_map_selection = true; - game.bind_mut().change_map_selection(map_idx as u8, true); + game.bind_mut().change_map_selection(map_idx as u8); } } } diff --git a/rust/src/game/mod.rs b/rust/src/game/mod.rs index e13f168..44ae2fd 100644 --- a/rust/src/game/mod.rs +++ b/rust/src/game/mod.rs @@ -482,7 +482,11 @@ impl Game { }); } - pub fn change_map_selection(&mut self, map_idx: u8, emit: bool) { + pub fn change_map_selection(&mut self, map_idx: u8) { + if self.selected_map_idx == map_idx { + return; + } + godot_print!("change map"); self.selected_map_idx = map_idx; if let Some(map) = self.maps.get(map_idx as usize) { self.selected_map = Some(map); @@ -501,9 +505,7 @@ impl Game { } } }); - if emit { - self.run_deferred(move |s| s.signals().on_map_changed().emit(map_idx)); - } + self.run_deferred(move |s| s.signals().on_map_changed().emit(map_idx)); } } diff --git a/rust/src/net/protocol.rs b/rust/src/net/protocol.rs index 56185d7..6a4f41f 100644 --- a/rust/src/net/protocol.rs +++ b/rust/src/net/protocol.rs @@ -112,7 +112,7 @@ impl NetworkManager { } Package::SelectMap(map_id) => { if let Some(game) = &mut Game::singleton() { - game.bind_mut().change_map_selection(map_id, true); + game.bind_mut().change_map_selection(map_id); } } Package::GameStarted => { @@ -424,7 +424,7 @@ impl NetworkManager { Package::SelectMap(map_idx) => { if let Some(mut game) = Game::singleton() { if game.bind().opts.is_true(GameOption::AllowAnyMap) { - game.bind_mut().change_map_selection(map_idx, true); + game.bind_mut().change_map_selection(map_idx); } } } diff --git a/rust/src/ui/lobby.rs b/rust/src/ui/lobby.rs index 320d498..524fd80 100644 --- a/rust/src/ui/lobby.rs +++ b/rust/src/ui/lobby.rs @@ -373,6 +373,7 @@ impl LobbyPanel { } pub fn update_map_selection(&mut self, id: u8) { + godot_print!("update map selection"); if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer { match peer { PeerKind::Client(peer, addr) => { @@ -383,8 +384,11 @@ impl LobbyPanel { } } PeerKind::Server(peer, _) => { + if let Some(mut map_selection) = self.map_selection.clone() { + map_selection.select(self.find_idx(id)); + } if let Some(game) = &mut Game::singleton() { - game.bind_mut().change_map_selection(id, false); + game.bind_mut().change_map_selection(id); } self.run_deferred(|s| s.update_players(false)); peer.broadcast_reliable(Package::SelectMap(id));