From a267f2240619ed62970bc8e159f33e5ee181d591 Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 8 Aug 2026 21:06:56 +0300 Subject: [PATCH] Make goal icon only show up when holding ball --- rust/src/game/mod.rs | 21 +++++++++++++++++++++ rust/src/map/goal.rs | 40 ++++++++++++++++++++++++++++++++++++---- rust/src/player/mod.rs | 3 +++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/rust/src/game/mod.rs b/rust/src/game/mod.rs index a0b3016..b588572 100644 --- a/rust/src/game/mod.rs +++ b/rust/src/game/mod.rs @@ -336,6 +336,10 @@ impl Game { pub fn on_player_killed(player: u16); #[signal] pub fn on_map_loaded(map: Gd); + #[signal] + pub fn on_pickup_ball(player_id: u16); + #[signal] + pub fn on_drop_ball(); pub fn singleton() -> Option> { if GameManager::singleton().get_children().len() > 0 { @@ -734,6 +738,7 @@ impl Game { velocity: Option, player_id: Option, ) { + godot_print!("Spawned ball"); if let Some(map) = &mut self.current_map { let mut ball = map.bind_mut().spawn_ball(transform, velocity, player_id); if let Some(ball) = &mut ball { @@ -759,6 +764,7 @@ impl Game { } }); } + self.signals().on_drop_ball().emit(); } pub fn despawn_ball(&mut self) { @@ -860,6 +866,21 @@ impl Game { return; } + if weapon_type == WeaponType::Ball { + self.run_deferred(move |s| s.signals().on_pickup_ball().emit(player_id)); + } + + if let Some(player) = self.find_player(player_id).clone() + && let Some(character) = player.character.clone() + { + if let Some(weapon) = character.dyn_bind().get_weapon() + && weapon.dyn_bind().get_type() == WeaponType::Ball + && weapon_type != WeaponType::Ball + { + self.run_deferred(move |s| s.signals().on_drop_ball().emit()); + } + } + if let Some(player) = self.find_player_mut(player_id) && let Some(character) = &mut player.character { diff --git a/rust/src/map/goal.rs b/rust/src/map/goal.rs index a20e6ea..2ddb63a 100644 --- a/rust/src/map/goal.rs +++ b/rust/src/map/goal.rs @@ -26,6 +26,19 @@ pub struct Goal { #[godot_api] impl IArea3D for Goal { fn ready(&mut self) { + self.update_icon_visibility(); + + if let Some(game) = &mut Game::singleton() { + game.bind_mut() + .signals() + .on_pickup_ball() + .connect_other(self, |s, _| s.run_deferred(|s| s.update_icon_visibility())); + game.bind_mut() + .signals() + .on_drop_ball() + .connect_other(self, |s| s.run_deferred(|s| s.update_icon_visibility())); + } + self.update_color(); self.base() .signals() @@ -67,7 +80,22 @@ impl Goal { } } - fn on_enter(&self, node: Gd) { + fn update_icon_visibility(&mut self) { + if let Some(icon) = &mut self.icon { + if let Some(game) = Game::singleton() + && let Some(ball_holder) = game.bind().ball_holder + && let Some(player) = game.bind().find_player(ball_holder) + && ball_holder == game.bind().self_id.unwrap_or(0) + && player.data.team != self.team + { + icon.set_visible(true); + } else { + icon.set_visible(false); + } + } + } + + fn on_enter(&mut self, node: Gd) { if !NetworkManager::singleton().bind().is_host() { return; } @@ -85,7 +113,7 @@ impl Goal { } if let Some(player_id) = is_goal { - if let Some(mut game) = Game::singleton() { + if let Some(game) = Game::singleton() { let teams = game .bind() .get_teams() @@ -94,8 +122,12 @@ impl Goal { .map(|(id, _)| id as u8) .filter(|id| *id != self.team) .collect(); - game.bind_mut().respawn_ball(); - game.bind_mut().handle_goal(player_id, teams); + self.run_deferred_gd(move |_| { + if let Some(game) = &mut Game::singleton() { + game.bind_mut().respawn_ball(); + game.bind_mut().handle_goal(player_id, teams); + } + }); } } } diff --git a/rust/src/player/mod.rs b/rust/src/player/mod.rs index ee78976..2f38545 100644 --- a/rust/src/player/mod.rs +++ b/rust/src/player/mod.rs @@ -154,6 +154,9 @@ impl PlayerCommon for T { { s.swap_weapon(player.last_held_weapon, false); } + if let Some(game) = &mut Game::singleton() { + game.bind_mut().ball_holder.take(); + } if NetworkManager::singleton().bind().is_host() { if let Some(mut game) = Game::singleton() { if let Some(ball_origin) = &s.get_camera_origin() {