Compare commits
No commits in common. "97ee080970ede7054a9ab4013b046e423c944876" and "3a0eaa58be234cf9044c56bebcd0d68f5acad56e" have entirely different histories.
97ee080970
...
3a0eaa58be
@ -341,8 +341,6 @@ impl Game {
|
||||
pub fn on_pickup_ball(player_id: u16);
|
||||
#[signal]
|
||||
pub fn on_drop_ball();
|
||||
#[signal]
|
||||
pub fn on_host_privileges_changed();
|
||||
|
||||
pub fn singleton() -> Option<Gd<Game>> {
|
||||
if GameManager::singleton().get_children().len() > 0 {
|
||||
@ -354,16 +352,12 @@ impl Game {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_host_privileges(&mut self, player_id: u16, privileges: bool) {
|
||||
if self.self_id.map(|s| s == player_id).unwrap_or(false) {
|
||||
self.set_ready(privileges);
|
||||
pub fn set_host_privileges(&mut self, privileges: bool) {
|
||||
if privileges {
|
||||
self.set_ready(true);
|
||||
}
|
||||
self.host_privileges = privileges;
|
||||
}
|
||||
if let Some(player) = self.find_player_mut(player_id) {
|
||||
player.data.has_host_privileges = privileges;
|
||||
}
|
||||
self.signals().on_host_privileges_changed().emit();
|
||||
}
|
||||
|
||||
pub fn has_host_privileges(&self) -> bool {
|
||||
self.is_host || self.host_privileges
|
||||
@ -503,10 +497,6 @@ impl Game {
|
||||
}
|
||||
|
||||
pub fn finish_game(&mut self) {
|
||||
if !self.game_started {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(recorder) = &mut self.replay_recorder {
|
||||
recorder.bind_mut().stop_recording();
|
||||
}
|
||||
@ -711,7 +701,6 @@ impl Game {
|
||||
ping: 0,
|
||||
team: 0,
|
||||
ready: false,
|
||||
has_host_privileges: host_privileges,
|
||||
},
|
||||
stats: Default::default(),
|
||||
killing_spree: 0,
|
||||
@ -719,6 +708,7 @@ impl Game {
|
||||
character: None,
|
||||
last_held_weapon: WeaponType::Raygun,
|
||||
last_position: Vector3::ZERO,
|
||||
has_host_privileges: host_privileges,
|
||||
});
|
||||
self.run_deferred(move |s| s.signals().on_new_player().emit(id));
|
||||
|
||||
@ -796,25 +786,6 @@ impl Game {
|
||||
}
|
||||
self.players.retain(|p| p.id() != id);
|
||||
self.run_deferred(move |s| s.signals().on_player_disconnected().emit(id));
|
||||
|
||||
self.run_deferred(|s| {
|
||||
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer
|
||||
&& let PeerKind::Server(peer, _) = peer
|
||||
{
|
||||
let players_with_host = s
|
||||
.players
|
||||
.iter()
|
||||
.filter(|p| p.data.has_host_privileges)
|
||||
.count();
|
||||
if players_with_host == 0
|
||||
&& let Some(player) = s.players.iter_mut().next()
|
||||
{
|
||||
player.data.has_host_privileges = true;
|
||||
peer.broadcast_reliable(Package::SetHostPrivileges(player.id(), true));
|
||||
s.signals().on_host_privileges_changed().emit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn update_player_nick(&mut self, player_id: u16, nick: String) {
|
||||
@ -1725,6 +1696,7 @@ pub struct Player {
|
||||
pub killing_spree_cd: f64,
|
||||
pub last_held_weapon: WeaponType,
|
||||
pub last_position: Vector3,
|
||||
pub has_host_privileges: bool,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
@ -1898,7 +1870,6 @@ pub struct NetPlayer {
|
||||
pub name: String,
|
||||
pub ping: u128,
|
||||
pub team: u8,
|
||||
pub has_host_privileges: bool,
|
||||
}
|
||||
|
||||
impl From<NetPlayer> for Player {
|
||||
@ -1912,6 +1883,7 @@ impl From<NetPlayer> for Player {
|
||||
killing_spree_cd: 0.,
|
||||
last_held_weapon: WeaponType::Raygun,
|
||||
last_position: Vector3::ZERO,
|
||||
has_host_privileges: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -368,7 +368,6 @@ pub enum Package {
|
||||
SelectMap(u8),
|
||||
GameStarted,
|
||||
MapLoaded,
|
||||
SetHostPrivileges(u16, bool),
|
||||
|
||||
// Game packages
|
||||
SpawnPlayer(u16, NetTransform),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use godot::{global::godot_print, obj::Singleton};
|
||||
use godot::obj::Singleton;
|
||||
use teanet::PeerMessage;
|
||||
|
||||
use crate::{
|
||||
@ -104,16 +104,10 @@ impl NetworkManager {
|
||||
);
|
||||
game.bind_mut().set_self(self_id);
|
||||
if host_privileges {
|
||||
game.bind_mut().set_host_privileges(self_id, true);
|
||||
game.bind_mut().set_host_privileges(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Package::SetHostPrivileges(player_id, host_privileges) => {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
game.bind_mut()
|
||||
.set_host_privileges(player_id, host_privileges);
|
||||
}
|
||||
}
|
||||
Package::SetNick(id, nick) => {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
game.bind_mut().update_player_nick(id, nick);
|
||||
@ -507,7 +501,7 @@ impl NetworkManager {
|
||||
if let Some(player) = player {
|
||||
if game.bind().opts.is_true(GameOption::AllowAnyTeam)
|
||||
|| player.id() == player_id
|
||||
|| player.data.has_host_privileges
|
||||
|| player.has_host_privileges
|
||||
{
|
||||
game.bind_mut().try_set_player_team(player_id, team);
|
||||
}
|
||||
@ -521,7 +515,7 @@ impl NetworkManager {
|
||||
if game.bind().opts.is_true(GameOption::AllowAnyMap) {
|
||||
game.bind_mut().change_map_selection(map_idx, false);
|
||||
} else if let Some(player) = player
|
||||
&& player.data.has_host_privileges
|
||||
&& player.has_host_privileges
|
||||
{
|
||||
game.bind_mut().change_map_selection(map_idx, false);
|
||||
}
|
||||
@ -573,7 +567,7 @@ impl NetworkManager {
|
||||
let player =
|
||||
game.bind().find_player_by_addr(&conn.address).cloned();
|
||||
if let Some(player) = player
|
||||
&& player.data.has_host_privileges
|
||||
&& player.has_host_privileges
|
||||
{
|
||||
game.bind_mut().start_game();
|
||||
}
|
||||
@ -584,7 +578,7 @@ impl NetworkManager {
|
||||
let player =
|
||||
game.bind().find_player_by_addr(&conn.address).cloned();
|
||||
if let Some(player) = player
|
||||
&& player.data.has_host_privileges
|
||||
&& player.has_host_privileges
|
||||
{
|
||||
game.bind_mut().change_option(key, value, false);
|
||||
}
|
||||
@ -595,24 +589,12 @@ impl NetworkManager {
|
||||
let player =
|
||||
game.bind().find_player_by_addr(&conn.address).cloned();
|
||||
if let Some(player) = player
|
||||
&& player.data.has_host_privileges
|
||||
&& player.has_host_privileges
|
||||
{
|
||||
game.bind_mut().change_team_option(team, key, value, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Package::FinishGame => {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
let player =
|
||||
game.bind().find_player_by_addr(&conn.address).cloned();
|
||||
if let Some(player) = player
|
||||
&& player.data.has_host_privileges
|
||||
{
|
||||
godot_print!("Finishing game");
|
||||
game.bind_mut().finish_game();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
},
|
||||
|
||||
@ -871,14 +871,7 @@ impl LocalPlayer {
|
||||
#[func]
|
||||
pub fn exit_to_lobby(&mut self) {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
|
||||
match peer {
|
||||
PeerKind::Client(peer, socket_addr) => {
|
||||
peer.send_reliable(socket_addr, Package::FinishGame);
|
||||
}
|
||||
PeerKind::Server(..) => game.bind_mut().finish_game(),
|
||||
}
|
||||
}
|
||||
game.bind_mut().finish_game();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -43,10 +43,8 @@ pub struct Hud {
|
||||
impl IControl for Hud {
|
||||
fn ready(&mut self) {
|
||||
self.run_deferred(|s| {
|
||||
if let Some(exit_to_lobby) = &mut s.exit_to_lobby
|
||||
&& let Some(game) = &Game::singleton()
|
||||
{
|
||||
exit_to_lobby.set_visible(game.bind().has_host_privileges());
|
||||
if let Some(exit_to_lobby) = &mut s.exit_to_lobby {
|
||||
exit_to_lobby.set_visible(NetworkManager::singleton().bind().is_host());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -130,16 +130,6 @@ impl IPanel for LobbyPanel {
|
||||
});
|
||||
});
|
||||
|
||||
game.signals()
|
||||
.on_host_privileges_changed()
|
||||
.connect_other(self, |s| {
|
||||
s.run_deferred(|s| {
|
||||
if let Some(game) = Game::singleton() {
|
||||
s.set_options_disabled(!game.bind().has_host_privileges());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let is_host = if let Some(game) = &Game::singleton() {
|
||||
game.bind().has_host_privileges()
|
||||
} else {
|
||||
@ -272,26 +262,6 @@ impl LobbyPanel {
|
||||
NetworkManager::singleton().bind_mut().disconnect();
|
||||
}
|
||||
|
||||
fn set_options_disabled(&mut self, disabled: bool) {
|
||||
if let Some(game) = &Game::singleton() {
|
||||
for (option, value) in &game.bind().opts.values {
|
||||
if let Some(control) = self.option_nodes.get(option) {
|
||||
set_control_disabled(control.clone(), value.clone(), disabled);
|
||||
}
|
||||
}
|
||||
for (team_id, opts) in game.bind().opts.teams.iter().enumerate() {
|
||||
if let Some(team_controls) = self.team_option_nodes.get(&(team_id as u8)) {
|
||||
for (option, value) in &opts.values {
|
||||
if let Some(control) = team_controls.get(option) {
|
||||
set_control_disabled(control.clone(), value.clone(), disabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.on_game_opts_update(&game.bind().opts, game.bind().has_host_privileges());
|
||||
}
|
||||
}
|
||||
|
||||
fn use_alt_colors_changed(&mut self, value: bool) {
|
||||
if let Some(game) = &mut Game::singleton() {
|
||||
game.bind_mut().private_opts.use_alternate_team_colors = value;
|
||||
@ -608,18 +578,3 @@ fn update_control(control: Gd<Control>, value: GameOptionValue) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_control_disabled(control: Gd<Control>, value: GameOptionValue, disabled: bool) {
|
||||
match value {
|
||||
GameOptionValue::Boolean(_) => {
|
||||
if let Ok(mut checkbox) = control.try_cast::<CheckBox>() {
|
||||
checkbox.set_disabled(disabled);
|
||||
}
|
||||
}
|
||||
GameOptionValue::Number(_) => {
|
||||
if let Ok(mut spinbox) = control.try_cast::<SpinBox>() {
|
||||
spinbox.set_editable(!disabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user