add F1 key to show key bindings

This commit is contained in:
yuni 2024-04-15 23:17:44 +02:00
parent a26a8c79f7
commit 45fbd4e2b5
5 changed files with 49 additions and 4 deletions

View file

@ -27,6 +27,7 @@ Links:
# Key Bindings
- F1: Show key bindings
- Space: Slow down (or match velocity)
- AWSD/Shift/Ctrl: Accelerate
- R: Rotate (hold & move mouse)

View file

@ -691,6 +691,11 @@ pub fn handle_chat_events(
hud::LogLevel::Warning => {
log.warning(message.into());
}
hud::LogLevel::Always => {
log.add(message.into(),
chat.talker.name.clone().unwrap_or("".to_string()),
hud::LogLevel::Always);
}
}
chat.timer = now + ((message.len() as f32).max(CHAT_SPEED_MIN_LEN) * TALKER_SPEED_FACTOR * chat.talker.talking_speed / settings.chat_speed) as f64;

20
src/data/keybindings.in Normal file
View file

@ -0,0 +1,20 @@
X: Teleport to target [CHEAT]
C: Impossibly instant stopping [CHEAT]
Shift+V/B: Same as V/B, but a thousand times faster [CHEAT]
V/B: Impossible acceleration forward/backward [CHEAT]
G: Toggle god mode / cheats [CHEAT]
M: Toggle sound effects
T: Toggle music
Y: Toggle rotation stabilizer
F: Toggle 3rd person view
F11: Toggle fullscreen
Tab: Toggle HUD + Augmented Reality
Right click: Zoom [AUGMENTED REALITY ONLY]
Left click: Target objects [AUGMENTED REALITY ONLY]
JKULIO: Mouseless camera rotation
F7: Restart game
Q: Exit vehicle
E: Interact: Talk to people, enter vehicles
R: Rotate (hold & move mouse)
AWSD/Shift/Ctrl: Accelerate
Space: Slow down (or match velocity)

View file

@ -9,9 +9,9 @@ use std::time::SystemTime;
pub const HUD_REFRESH_TIME: f32 = 0.1;
pub const FONT: &str = "fonts/Yupiter-Regular.ttf";
pub const LOG_MAX: usize = 16;
pub const LOG_MAX_TIME_S: f64 = 30.0;
pub const LOG_MAX_ROWS: usize = 30;
pub const LOG_MAX: usize = LOG_MAX_ROWS;
pub const MAX_CHOICES: usize = 10;
pub const AMBIENT_LIGHT: f32 = 0.0; // Space is DARK
pub const AMBIENT_LIGHT_AR: f32 = 15.0;
@ -74,6 +74,7 @@ pub struct AugmentedRealityOverlay {
struct FPSUpdateTimer(Timer);
pub enum LogLevel {
Always,
Warning,
//Error,
Info,
@ -234,6 +235,9 @@ fn setup(
));
// Add Console
// This one is intentionally NOT a ToggleableHudElement. Instead, console entries
// are filtered based on whether the hud is active or not. LogLevel::Always is
// even shown when hud is inactive.
let bundle_chatbox = TextBundle::from_sections((0..LOG_MAX_ROWS).map(|_|
TextSection::new("", style_console.clone()))
).with_style(Style {
@ -243,7 +247,6 @@ fn setup(
..default()
}).with_text_justify(JustifyText::Right);
commands.spawn((
ToggleableHudElement,
NodeBundle {
style: Style {
width: Val::Percent(50.0),
@ -253,7 +256,6 @@ fn setup(
right: Val::VMin(3.0),
..default()
},
visibility,
..default()
},
)).with_children(|parent| {
@ -503,7 +505,16 @@ fn update_hud(
let mut row = 0;
// Chat Log and System Log
let logfilter = if settings.hud_active {
|_msg: &&Message| { true }
} else {
|msg: &&Message| { match msg.level {
LogLevel::Always => true,
_ => false
}}
};
let messages: Vec<&Message> = log.logs.iter()
.filter(logfilter)
.rev()
.take(LOG_MAX_ROWS)
.collect();
@ -591,6 +602,7 @@ fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
mouse_input: Res<ButtonInput<MouseButton>>,
mut settings: ResMut<var::Settings>,
mut log: ResMut<Log>,
mut q_hud: Query<(&mut Visibility, Option<&OnlyHideWhenTogglingHud>), With<ToggleableHudElement>>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
@ -599,6 +611,11 @@ fn handle_input(
q_objects: Query<(Entity, &Transform), (With<IsClickable>, Without<IsTargeted>, Without<actor::PlayerDrivesThis>, Without<actor::Player>)>,
q_camera: Query<&Transform, With<Camera>>,
) {
if keyboard_input.just_pressed(settings.key_help) {
for line in include_str!("data/keybindings.in").trim().split("\n") {
log.add(line.to_string(), "".to_string(), LogLevel::Always);
}
}
if keyboard_input.just_pressed(settings.key_togglehud) {
if settings.hud_active {
for (mut hudelement_visibility, _) in q_hud.iter_mut() {

View file

@ -49,6 +49,7 @@ pub struct Settings {
pub key_exit: KeyCode,
pub key_restart: KeyCode,
pub key_fullscreen: KeyCode,
pub key_help: KeyCode,
pub key_forward: KeyCode,
pub key_back: KeyCode,
pub key_left: KeyCode,
@ -130,7 +131,7 @@ impl Default for Settings {
hud_color_console: Color::rgb(0.2, 0.5, 0.2),
hud_color_console_warn: Color::rgb(1.0, 0.3, 0.3),
hud_color_console_system: Color::rgb(0.5, 0.5, 0.5),
hud_color_alert: Color::rgb(0.7, 0.3, 0.3),
hud_color_alert: Color::rgb(0.8, 0.3, 0.5),
hud_color_subtitles: Color::rgb(0.8, 0.8, 0.8),
hud_color_choices: Color::rgb(0.45, 0.45, 0.45),
chat_speed: DEFAULT_CHAT_SPEED * if dev_mode { 2.5 } else { 1.0 },
@ -144,6 +145,7 @@ impl Default for Settings {
key_exit: KeyCode::Escape,
key_restart: KeyCode::F7,
key_fullscreen: KeyCode::F11,
key_help: KeyCode::F1,
key_forward: KeyCode::KeyW,
key_back: KeyCode::KeyS,
key_left: KeyCode::KeyA,