diff --git a/godot/scenes/lobby.tscn b/godot/scenes/lobby.tscn index f895877..d7a8c6c 100644 --- a/godot/scenes/lobby.tscn +++ b/godot/scenes/lobby.tscn @@ -39,6 +39,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +focus_next = Callable() theme = ExtResource("3_dfnwm") theme_override_styles/panel = SubResource("StyleBoxFlat_7j863") @@ -229,3 +230,4 @@ current = true [connection signal="pressed" from="lobby/v_box_container3/h_box_container/exit_button" to="lobby" method="exit"] [connection signal="pressed" from="lobby/v_box_container3/h_box_container/options_button" to="lobby" method="open_options"] [connection signal="pressed" from="lobby/v_box_container3/h_box_container/settings_button" to="lobby/settings" method="open"] +[connection signal="on_close" from="lobby/settings" to="lobby" method="focus_next"] diff --git a/rust/src/ui/game_finished_screen.rs b/rust/src/ui/game_finished_screen.rs index dab6f3a..e2eb17f 100644 --- a/rust/src/ui/game_finished_screen.rs +++ b/rust/src/ui/game_finished_screen.rs @@ -59,6 +59,10 @@ impl IPanel for GameFinishedScreen { .on_saved() .connect_other(self, Self::on_replay_saved); } + + if let Some(focus) = &mut self.base_mut().find_next_valid_focus() { + focus.grab_focus(); + } } } diff --git a/rust/src/ui/hud.rs b/rust/src/ui/hud.rs index 1ae802c..3535e87 100644 --- a/rust/src/ui/hud.rs +++ b/rust/src/ui/hud.rs @@ -114,11 +114,15 @@ impl IControl for Hud { fn input(&mut self, event: Gd) { if event.is_action_pressed("pause") { if let Some(pause_panel) = &mut self.pause_panel { - let is_visible = pause_panel.is_visible(); - pause_panel.set_visible(!is_visible); + let was_visible = pause_panel.is_visible(); + pause_panel.set_visible(!was_visible); if !pause_panel.is_visible() { if let Some(settings_panel) = &mut self.settings_panel { - settings_panel.set_visible(false); + settings_panel.bind_mut().close(); + } + } else { + if let Some(focus) = &mut pause_panel.find_next_valid_focus() { + focus.grab_focus(); } } self.update_lock(); diff --git a/rust/src/ui/lobby.rs b/rust/src/ui/lobby.rs index 635bf7d..a97af6d 100644 --- a/rust/src/ui/lobby.rs +++ b/rust/src/ui/lobby.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use godot::{ classes::{ - Button, CheckBox, CompressedTexture2D, Control, GridContainer, IPanel, Label, LineEdit, - OptionButton, Os, Panel, SpinBox, TabContainer, VBoxContainer, + Button, CheckBox, CompressedTexture2D, Control, GridContainer, IPanel, InputEvent, Label, + LineEdit, OptionButton, Os, Panel, SpinBox, TabContainer, VBoxContainer, }, prelude::*, }; @@ -223,6 +223,14 @@ impl IPanel for LobbyPanel { MusicManager::singleton() .bind_mut() .play(Some(Music::MainMenu), false); + + self.focus_next(); + } + + fn input(&mut self, event: Gd) { + if event.is_action_pressed("ui_cancel") { + self.close_options(); + } } } @@ -235,13 +243,19 @@ impl LobbyPanel { fn open_options(&mut self) { if let Some(panel) = &mut self.options_panel { panel.set_visible(true); + if let Some(focus) = &mut panel.find_next_valid_focus() { + focus.grab_focus(); + } } } #[func] fn close_options(&mut self) { - if let Some(panel) = &mut self.options_panel { + if let Some(panel) = &mut self.options_panel + && panel.is_visible() + { panel.set_visible(false); + self.focus_next(); } } @@ -537,6 +551,13 @@ impl LobbyPanel { } nodes } + + #[func] + pub fn focus_next(&mut self) { + if let Some(focus) = &mut self.base_mut().find_next_valid_focus() { + focus.grab_focus(); + } + } } fn update_control(control: Gd, value: GameOptionValue) { diff --git a/rust/src/ui/replay_finished_screen.rs b/rust/src/ui/replay_finished_screen.rs index 774effa..4383d1d 100644 --- a/rust/src/ui/replay_finished_screen.rs +++ b/rust/src/ui/replay_finished_screen.rs @@ -33,6 +33,10 @@ impl IPanel for ReplayFinishedScreen { GameManager::singleton().bind().go_to_main_menu(); }); } + + if let Some(focus) = &mut self.base_mut().find_next_valid_focus() { + focus.grab_focus(); + } } }