diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index c7636ed..f31644b 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -88,6 +88,20 @@ impl GameManager { } } +pub struct GameOptions { + /// Wether anyone is allowed to change anyone's team, or just the host and + /// the player itself. + pub allow_any_team: bool, +} + +impl Default for GameOptions { + fn default() -> Self { + Self { + allow_any_team: false, + } + } +} + #[derive(GodotClass)] #[class(base=Node, init)] pub struct Game { @@ -98,6 +112,8 @@ pub struct Game { pub selected_map: Option>, pub maps: Array>, + pub opts: GameOptions, + is_host: bool, player_counter: u16, pub self_id: Option, diff --git a/rust/src/net/protocol.rs b/rust/src/net/protocol.rs index 43786cf..0b82644 100644 --- a/rust/src/net/protocol.rs +++ b/rust/src/net/protocol.rs @@ -319,7 +319,7 @@ impl NetworkManager { .find_player_by_addr(&conn.address) .map(|p| p.id()); if let Some(self_id) = self_id { - if self_id == player_id { + if game.bind().opts.allow_any_team || self_id == player_id { game.bind_mut().try_set_player_team(player_id, team, true); } } diff --git a/rust/src/ui/player_listing.rs b/rust/src/ui/player_listing.rs index 1a1967b..86321b2 100644 --- a/rust/src/ui/player_listing.rs +++ b/rust/src/ui/player_listing.rs @@ -3,7 +3,11 @@ use godot::{ prelude::*, }; -use crate::{game_manager::Game, team_resource::TeamResource}; +use crate::{ + game_manager::{Game, GameOptions}, + net::network_manager::NetworkManager, + team_resource::TeamResource, +}; #[derive(GodotClass)] #[class(base=GridContainer, init)] @@ -52,10 +56,22 @@ impl IGridContainer for PlayerListing { } }); } + + if let Some(game) = &Game::singleton() { + self.update_game_options(&game.bind().opts, game.bind().self_id); + } } } impl PlayerListing { + pub fn update_game_options(&mut self, opts: &GameOptions, self_id: Option) { + let is_host = NetworkManager::singleton().bind().is_host(); + + if let Some(dropdown) = &mut self.team_dropdown { + dropdown.set_disabled(!is_host && !opts.allow_any_team && self.player_id != self_id); + } + } + pub fn update(&mut self) { if let Some(player_id) = &self.player_id && let Some(game) = Game::singleton()