Add jump keybind, fix binding space

This commit is contained in:
Sofia 2026-07-26 02:33:36 +03:00
parent 2464ad00db
commit 9504eb7a88
3 changed files with 18 additions and 7 deletions

View File

@ -20,6 +20,7 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
[node name="v_box_container" type="VBoxContainer" parent="." unique_id=1384128810] [node name="v_box_container" type="VBoxContainer" parent="." unique_id=1384128810]
custom_minimum_size = Vector2(500, 500)
layout_mode = 2 layout_mode = 2
[node name="label" type="Label" parent="v_box_container" unique_id=2036746921] [node name="label" type="Label" parent="v_box_container" unique_id=2036746921]
@ -33,24 +34,18 @@ size_flags_vertical = 3
current_tab = 0 current_tab = 0
[node name="general" type="GridContainer" parent="v_box_container/tab_container" unique_id=833231169] [node name="general" type="GridContainer" parent="v_box_container/tab_container" unique_id=833231169]
custom_minimum_size = Vector2(400, 0)
custom_maximum_size = Vector2(400, -1)
layout_mode = 2 layout_mode = 2
columns = 2 columns = 2
metadata/_tab_index = 0 metadata/_tab_index = 0
[node name="volume" type="GridContainer" parent="v_box_container/tab_container" unique_id=1992916365] [node name="volume" type="GridContainer" parent="v_box_container/tab_container" unique_id=1992916365]
visible = false visible = false
custom_minimum_size = Vector2(400, 0)
custom_maximum_size = Vector2(400, -1)
layout_mode = 2 layout_mode = 2
columns = 2 columns = 2
metadata/_tab_index = 1 metadata/_tab_index = 1
[node name="keybinds" type="GridContainer" parent="v_box_container/tab_container" unique_id=852698711] [node name="keybinds" type="GridContainer" parent="v_box_container/tab_container" unique_id=852698711]
visible = false visible = false
custom_minimum_size = Vector2(400, 0)
custom_maximum_size = Vector2(400, -1)
layout_mode = 2 layout_mode = 2
columns = 2 columns = 2
metadata/_tab_index = 2 metadata/_tab_index = 2

View File

@ -48,6 +48,7 @@ pub struct KeybindSettings {
pub select_shotgun: Keybind, pub select_shotgun: Keybind,
pub shoot: Keybind, pub shoot: Keybind,
pub melee: Keybind, pub melee: Keybind,
pub jump: Keybind,
} }
#[derive(Clone, Copy, Debug, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, Serialize, Deserialize)]
@ -137,6 +138,7 @@ impl Default for GameSettings {
select_shotgun: Keybind::Key(Key::KEY_2.to_godot()), select_shotgun: Keybind::Key(Key::KEY_2.to_godot()),
shoot: Keybind::MouseButton(MouseButton::LEFT.to_godot()), shoot: Keybind::MouseButton(MouseButton::LEFT.to_godot()),
melee: Keybind::Key(Key::F.to_godot()), melee: Keybind::Key(Key::F.to_godot()),
jump: Keybind::Key(Key::SPACE.to_godot()),
}, },
} }
} }
@ -185,6 +187,7 @@ impl GameSettingsManager {
set_keybind("weapon_2", settings.keybinds.select_shotgun); set_keybind("weapon_2", settings.keybinds.select_shotgun);
set_keybind("shoot", settings.keybinds.shoot); set_keybind("shoot", settings.keybinds.shoot);
set_keybind("punch", settings.keybinds.melee); set_keybind("punch", settings.keybinds.melee);
set_keybind("jump", settings.keybinds.jump);
self.settings = settings; self.settings = settings;
if let Some(mut file) = FileAccess::open("user://config.toml", ModeFlags::WRITE) { if let Some(mut file) = FileAccess::open("user://config.toml", ModeFlags::WRITE) {

View File

@ -3,7 +3,8 @@ use std::collections::HashMap;
use godot::{ use godot::{
classes::{ classes::{
Button, Control, GridContainer, IPanelContainer, InputEvent, InputEventKey, Button, Control, GridContainer, IPanelContainer, InputEvent, InputEventKey,
InputEventMouseButton, InputMap, Label, LineEdit, PanelContainer, control::SizeFlags, InputEventMouseButton, InputMap, Label, LineEdit, PanelContainer,
control::{FocusBehaviorRecursive, FocusMode, SizeFlags},
}, },
prelude::*, prelude::*,
}; };
@ -32,6 +33,7 @@ pub enum Setting {
MoveBackward, MoveBackward,
Shoot, Shoot,
Melee, Melee,
Jump,
SelectRaygun, SelectRaygun,
SelectShotgun, SelectShotgun,
} }
@ -61,6 +63,7 @@ impl ToString for Setting {
Setting::SelectShotgun => "Select Shotgun", Setting::SelectShotgun => "Select Shotgun",
Setting::Shoot => "Shoot", Setting::Shoot => "Shoot",
Setting::Melee => "Melee", Setting::Melee => "Melee",
Setting::Jump => "Jump",
} }
.to_string() .to_string()
} }
@ -197,6 +200,8 @@ impl IPanelContainer for SettingsPanel {
Setting::Melee, Setting::Melee,
SettingValue::Keybind(settings.keybinds.melee), SettingValue::Keybind(settings.keybinds.melee),
); );
self.settings
.insert(Setting::Jump, SettingValue::Keybind(settings.keybinds.jump));
let mut keys = self.settings.keys().collect::<Vec<_>>(); let mut keys = self.settings.keys().collect::<Vec<_>>();
keys.sort(); keys.sort();
@ -274,6 +279,9 @@ impl IPanelContainer for SettingsPanel {
if let Some((_, mut button)) = s.keybind_button.take() { if let Some((_, mut button)) = s.keybind_button.take() {
button.set_pressed(false); button.set_pressed(false);
} }
s.base_mut().set_focus_behavior_recursive(
FocusBehaviorRecursive::DISABLED,
);
s.keybind_button = Some((setting_clone, button_clone.clone())) s.keybind_button = Some((setting_clone, button_clone.clone()))
}); });
@ -295,6 +303,8 @@ impl IPanelContainer for SettingsPanel {
self.on_change(setting.clone(), SettingValue::Keybind(keybind)); self.on_change(setting.clone(), SettingValue::Keybind(keybind));
button.set_text(&keybind.to_string()); button.set_text(&keybind.to_string());
button.set_pressed(false); button.set_pressed(false);
self.base_mut()
.set_focus_behavior_recursive(FocusBehaviorRecursive::INHERITED);
} }
} }
} }
@ -351,6 +361,9 @@ impl SettingsPanel {
(Setting::Melee, SettingValue::Keybind(keybind)) => { (Setting::Melee, SettingValue::Keybind(keybind)) => {
new_settings.keybinds.melee = *keybind; new_settings.keybinds.melee = *keybind;
} }
(Setting::Jump, SettingValue::Keybind(keybind)) => {
new_settings.keybinds.jump = *keybind;
}
_ => {} _ => {}
} }
} }