Add some controller bindings for main menu
This commit is contained in:
parent
399606357c
commit
43991a4fa0
@ -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)
|
||||
|
||||
@ -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"]
|
||||
|
||||
@ -72,6 +72,8 @@ pub struct MainMenu {
|
||||
|
||||
recent_servers: Vec<RecentServer>,
|
||||
|
||||
focus_next: bool,
|
||||
|
||||
base: Base<Node3D>,
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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::<Button>();
|
||||
button.set_disabled(value == default_value);
|
||||
|
||||
@ -182,11 +183,14 @@ impl IPanelContainer for SettingsPanel {
|
||||
});
|
||||
|
||||
grid.add_child(&button);
|
||||
self.reset_buttons.insert(*setting, button);
|
||||
}
|
||||
self.reset_buttons.insert(*setting, button.clone());
|
||||
Some(button)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(scene) = self.slider_scene.clone() {
|
||||
let node = match value {
|
||||
let mut node = match value {
|
||||
SettingValue::SliderNumber(slider_value) => {
|
||||
let mut slider = scene.instantiate_as::<SliderContainer>();
|
||||
|
||||
@ -281,12 +285,25 @@ impl IPanelContainer for SettingsPanel {
|
||||
self.values.insert(*setting, node.clone());
|
||||
|
||||
grid.add_child(&node);
|
||||
|
||||
if let Some(reset_btn) = &mut reset_btn {
|
||||
reset_btn.set_focus_neighbor(Side::RIGHT, &node.get_path());
|
||||
node.set_focus_neighbor(Side::LEFT, &reset_btn.get_path());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn input(&mut self, event: Gd<InputEvent>) {
|
||||
if event.is_action("ui_cancel") && self.base().is_visible() {
|
||||
if let Some((_, mut button)) = self.keybind_button.take() {
|
||||
button.set_pressed(false);
|
||||
} else {
|
||||
self.close();
|
||||
}
|
||||
}
|
||||
|
||||
if let Some((setting, mut button)) = self.keybind_button.clone()
|
||||
&& let Some(keybind) = Keybind::from_event(event)
|
||||
{
|
||||
@ -302,6 +319,9 @@ impl IPanelContainer for SettingsPanel {
|
||||
|
||||
#[godot_api]
|
||||
impl SettingsPanel {
|
||||
#[signal]
|
||||
pub fn on_close();
|
||||
|
||||
pub fn change_value(&mut self, setting: Setting, new_value: SettingValue) {
|
||||
if let Some(control) = self.values.get(&setting).cloned() {
|
||||
match new_value.clone() {
|
||||
@ -418,11 +438,18 @@ impl SettingsPanel {
|
||||
#[func]
|
||||
pub fn open(&mut self) {
|
||||
self.base_mut().set_visible(true);
|
||||
if let Some(focus) = &mut self.base_mut().find_next_valid_focus() {
|
||||
focus.grab_focus();
|
||||
}
|
||||
}
|
||||
|
||||
#[func]
|
||||
pub fn close(&mut self) {
|
||||
if let Some((_, mut button)) = self.keybind_button.take() {
|
||||
button.set_pressed(false);
|
||||
}
|
||||
self.base_mut().set_visible(false);
|
||||
self.signals().on_close().emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user