diff --git a/godot/project.godot b/godot/project.godot index cda2310..720a816 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -65,6 +65,12 @@ ui_accept={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) ] } +ui_cancel={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":16,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null) +] +} toggle_cli={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":167,"key_label":0,"unicode":167,"location":0,"echo":false,"script":null) diff --git a/godot/scenes/main.tscn b/godot/scenes/main.tscn index ab69167..63482db 100644 --- a/godot/scenes/main.tscn +++ b/godot/scenes/main.tscn @@ -7,11 +7,10 @@ [ext_resource type="Texture2D" uid="uid://3gpd2qpyw5eq" path="res://assets/title.png" id="4_pm3ni"] [ext_resource type="PackedScene" uid="uid://c62c5iq0w72ka" path="res://maps/precipice/precipice_static.scn" id="6_tefeu"] -[node name="menu" type="MainMenu" unique_id=2036763876 node_paths=PackedStringArray("camera", "main_position", "host_position", "host_main_button", "main_panel", "host_panel", "join_panel", "host_port", "join_addr", "join_port", "recent_servers_button", "popup_panel", "popup_title", "popup_text", "popup_button", "open_replay_dialog")] +[node name="menu" type="MainMenu" unique_id=2036763876 node_paths=PackedStringArray("camera", "main_position", "host_position", "main_panel", "host_panel", "join_panel", "host_port", "join_addr", "join_port", "recent_servers_button", "popup_panel", "popup_title", "popup_text", "popup_button", "open_replay_dialog")] camera = NodePath("camera_3d") main_position = NodePath("main_pos") host_position = NodePath("host_pos") -host_main_button = NodePath("menus/main_panel/v_box_container/margin_container/v_box_container/host") main_panel = NodePath("menus/main_panel") host_panel = NodePath("menus/host_panel") join_panel = NodePath("menus/join_panel") @@ -350,4 +349,5 @@ text = "Ok" [connection signal="pressed" from="menus/host_panel/v_box_container/back" to="." method="go_to_main_menu"] [connection signal="pressed" from="menus/join_panel/v_box_container/join" to="." method="join_game"] [connection signal="pressed" from="menus/join_panel/v_box_container/back" to="." method="go_to_main_menu"] +[connection signal="on_close" from="menus/settings" to="." method="focus_next"] [connection signal="pressed" from="menus/popup_panel/v_box_container/ok" to="." method="hide_popup"] diff --git a/rust/src/ui/main_menu.rs b/rust/src/ui/main_menu.rs index e75e88d..72af24b 100644 --- a/rust/src/ui/main_menu.rs +++ b/rust/src/ui/main_menu.rs @@ -72,6 +72,8 @@ pub struct MainMenu { recent_servers: Vec, + focus_next: bool, + base: Base, } @@ -106,11 +108,7 @@ impl INode3D for MainMenu { .bind_mut() .play(Some(Music::MainMenu), false); - if let Some(panel) = &mut self.main_panel { - if let Some(focus) = &mut panel.find_next_valid_focus() { - focus.grab_focus_ex().hide_focus(true).done(); - } - } + self.focus_next = true; } fn process(&mut self, _delta: f64) { @@ -169,10 +167,11 @@ impl INode3D for MainMenu { } self.prev_panel = Some(panel.clone()); panel.set_visible(true); - if changed { + if changed || self.focus_next { if let Some(focus) = &mut panel.find_next_valid_focus() { - focus.grab_focus_ex().hide_focus(true).done(); + focus.grab_focus(); } + self.focus_next = false; } } } @@ -283,6 +282,10 @@ impl MainMenu { if let Some(button) = &mut self.popup_button { button.set_visible(ok); } + + if let Some(focus) = &mut panel.find_next_valid_focus() { + focus.grab_focus(); + } } } @@ -290,6 +293,7 @@ impl MainMenu { pub fn hide_popup(&mut self) { if let Some(panel) = &mut self.popup_panel { panel.set_visible(false); + self.focus_next = true; } } @@ -307,4 +311,9 @@ impl MainMenu { } } } + + #[func] + pub fn focus_next(&mut self) { + self.focus_next = true; + } } diff --git a/rust/src/ui/settings.rs b/rust/src/ui/settings.rs index 55ee2bc..ef3459c 100644 --- a/rust/src/ui/settings.rs +++ b/rust/src/ui/settings.rs @@ -4,6 +4,7 @@ use godot::{ classes::{ Button, Control, GridContainer, IPanelContainer, InputEvent, Label, LineEdit, OptionButton, PanelContainer, + class_macros::private::virtuals::Xrvrs::Side, control::{FocusBehaviorRecursive, SizeFlags}, }, prelude::*, @@ -171,7 +172,7 @@ impl IPanelContainer for SettingsPanel { label.set_h_size_flags(SizeFlags::EXPAND | SizeFlags::SHRINK_BEGIN); grid.add_child(&label); - if let Some(reset_btn) = &self.reset_button { + let mut reset_btn = if let Some(reset_btn) = &self.reset_button { let mut button = reset_btn.instantiate_as::