Update map selection dropdown disable logic

This commit is contained in:
Sofia 2026-07-22 03:23:48 +03:00
parent 5d14a2675c
commit b163c214fe
2 changed files with 17 additions and 8 deletions

View File

@ -89,15 +89,18 @@ impl GameManager {
}
pub struct GameOptions {
/// Wether anyone is allowed to change anyone's team, or just the host and
/// Whether anyone is allowed to change anyone's team, or just the host and
/// the player itself.
pub allow_any_team: bool,
// Whether anyone is allowed to change the map, or just the host.
pub allow_any_map: bool,
}
impl Default for GameOptions {
fn default() -> Self {
Self {
allow_any_team: false,
allow_any_map: false,
}
}
}

View File

@ -4,7 +4,7 @@ use godot::{
};
use crate::{
game_manager::{Game, GameManager},
game_manager::{Game, GameManager, GameOptions},
net::network_manager::{NetworkManager, Package, PeerKind},
ui::player_listing::PlayerListing,
};
@ -68,14 +68,14 @@ impl IPanel for LobbyPanel {
for map in game.bind().maps.iter_shared() {
map_selection.add_item(&map.bind().name);
}
map_selection.select(0);
}
let is_host = if let Some(peer) = &NetworkManager::singleton().bind().peer {
peer.is_host()
} else {
false
};
map_selection.set_disabled(!is_host);
map_selection.select(0);
}
self.on_game_opts_update(&game.bind().opts, is_host);
}
self.update_map_selection(0);
@ -117,6 +117,12 @@ impl IPanel for LobbyPanel {
}
impl LobbyPanel {
fn on_game_opts_update(&mut self, opts: &GameOptions, is_host: bool) {
if let Some(selection) = &mut self.map_selection {
selection.set_disabled(!is_host && !opts.allow_any_map);
}
}
fn update_ready_button(&mut self) {
if let Some(game) = Game::singleton()
&& let Some(peer) = &NetworkManager::singleton().bind().peer