Disable team switch button without rights
This commit is contained in:
parent
3608194e5a
commit
05bf6401e0
@ -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)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Node, init)]
|
#[class(base=Node, init)]
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
@ -98,6 +112,8 @@ pub struct Game {
|
|||||||
pub selected_map: Option<Gd<MapResource>>,
|
pub selected_map: Option<Gd<MapResource>>,
|
||||||
pub maps: Array<Gd<MapResource>>,
|
pub maps: Array<Gd<MapResource>>,
|
||||||
|
|
||||||
|
pub opts: GameOptions,
|
||||||
|
|
||||||
is_host: bool,
|
is_host: bool,
|
||||||
player_counter: u16,
|
player_counter: u16,
|
||||||
pub self_id: Option<u16>,
|
pub self_id: Option<u16>,
|
||||||
|
|||||||
@ -319,7 +319,7 @@ impl NetworkManager {
|
|||||||
.find_player_by_addr(&conn.address)
|
.find_player_by_addr(&conn.address)
|
||||||
.map(|p| p.id());
|
.map(|p| p.id());
|
||||||
if let Some(self_id) = self_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);
|
game.bind_mut().try_set_player_team(player_id, team, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,11 @@ use godot::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{game_manager::Game, team_resource::TeamResource};
|
use crate::{
|
||||||
|
game_manager::{Game, GameOptions},
|
||||||
|
net::network_manager::NetworkManager,
|
||||||
|
team_resource::TeamResource,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=GridContainer, init)]
|
#[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 {
|
impl PlayerListing {
|
||||||
|
pub fn update_game_options(&mut self, opts: &GameOptions, self_id: Option<u16>) {
|
||||||
|
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) {
|
pub fn update(&mut self) {
|
||||||
if let Some(player_id) = &self.player_id
|
if let Some(player_id) = &self.player_id
|
||||||
&& let Some(game) = Game::singleton()
|
&& let Some(game) = Game::singleton()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user