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

View File

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

View File

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