Propagate team options to clients as well
This commit is contained in:
parent
38a84588e5
commit
4c8c010174
@ -328,6 +328,8 @@ impl Game {
|
||||
#[signal]
|
||||
pub fn options_changed();
|
||||
#[signal]
|
||||
pub fn team_options_changed(team: u8);
|
||||
#[signal]
|
||||
pub fn on_goal();
|
||||
#[signal]
|
||||
pub fn on_game_finished();
|
||||
@ -495,7 +497,7 @@ impl Game {
|
||||
team.values.insert(opt, value);
|
||||
}
|
||||
self.run_deferred(move |s| {
|
||||
s.signals().options_changed().emit();
|
||||
s.signals().team_options_changed().emit(team);
|
||||
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
|
||||
if let PeerKind::Server(peer, _) = peer {
|
||||
peer.broadcast_reliable(Package::TeamGameOptionChanged(team, opt, value));
|
||||
|
||||
@ -202,6 +202,11 @@ impl NetworkManager {
|
||||
game.bind_mut().change_option(opt, value);
|
||||
}
|
||||
}
|
||||
Package::TeamGameOptionChanged(team, opt, value) => {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
game.bind_mut().change_team_option(team, opt, value);
|
||||
}
|
||||
}
|
||||
Package::Goal(scorer, teams) => {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
game.bind_mut().handle_goal(scorer, teams);
|
||||
|
||||
@ -12,7 +12,7 @@ use crate::{
|
||||
bgm::{Music, MusicManager},
|
||||
game::{
|
||||
Game, GameManager,
|
||||
opts::{GameOption, GameOptionValue, GameOptions},
|
||||
opts::{GameOption, GameOptionValue, GameOptions, TeamOptions},
|
||||
},
|
||||
lobby_world::LobbyWorld,
|
||||
net::network_manager::{NetworkManager, Package, PeerKind},
|
||||
@ -116,6 +116,18 @@ impl IPanel for LobbyPanel {
|
||||
}
|
||||
});
|
||||
});
|
||||
game.signals()
|
||||
.team_options_changed()
|
||||
.connect_other(self, |s, team| {
|
||||
s.run_deferred(move |s| {
|
||||
if let Some(game) = Game::singleton() {
|
||||
if let Some(opts) = game.bind().get_team_opts(team) {
|
||||
s.on_team_opts_update(team, &opts);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
game.signals().on_map_changed().connect_other(self, |s, _| {
|
||||
s.run_deferred(|s| {
|
||||
s.generate_team_options();
|
||||
@ -268,23 +280,26 @@ impl LobbyPanel {
|
||||
self.run_deferred_gd(move |_| {
|
||||
for (key, value) in values {
|
||||
if let Some(control) = nodes.get(&key).cloned() {
|
||||
match value {
|
||||
GameOptionValue::Boolean(value) => {
|
||||
if let Ok(mut checkbox) = control.try_cast::<CheckBox>() {
|
||||
checkbox.set_pressed(value);
|
||||
}
|
||||
}
|
||||
GameOptionValue::Number(value) => {
|
||||
if let Ok(mut spinbox) = control.try_cast::<SpinBox>() {
|
||||
spinbox.set_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
update_control(control, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn on_team_opts_update(&mut self, team: u8, opts: &TeamOptions) {
|
||||
let values = opts.values.clone();
|
||||
if let Some(nodes) = self.team_option_nodes.get(&team) {
|
||||
let nodes = nodes.clone();
|
||||
self.run_deferred_gd(move |_| {
|
||||
for (key, value) in values {
|
||||
if let Some(control) = nodes.get(&key).cloned() {
|
||||
update_control(control, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn update_ready_button(&mut self) {
|
||||
if let Some(game) = Game::singleton()
|
||||
&& let Some(peer) = &NetworkManager::singleton().bind().peer
|
||||
@ -520,3 +535,18 @@ impl LobbyPanel {
|
||||
nodes
|
||||
}
|
||||
}
|
||||
|
||||
fn update_control(control: Gd<Control>, value: GameOptionValue) {
|
||||
match value {
|
||||
GameOptionValue::Boolean(value) => {
|
||||
if let Ok(mut checkbox) = control.try_cast::<CheckBox>() {
|
||||
checkbox.set_pressed(value);
|
||||
}
|
||||
}
|
||||
GameOptionValue::Number(value) => {
|
||||
if let Ok(mut spinbox) = control.try_cast::<SpinBox>() {
|
||||
spinbox.set_value(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user