change menu labels to reflect settings
This commit is contained in:
parent
83fe739e91
commit
f476f351c9
|
@ -69,9 +69,9 @@ fn handle_game_event(
|
|||
mut er_game: EventReader<GameEvent>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
|
||||
mut ew_updatemenu: EventWriter<menu::UpdateMenuEvent>,
|
||||
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
|
||||
mut q_window: Query<&mut Window, With<PrimaryWindow>>,
|
||||
mut q_menu_vis: Query<&mut Visibility, With<menu::MenuElement>>,
|
||||
mut q_light: Query<&mut DirectionalLight>,
|
||||
mut mapcam: ResMut<camera::MapCam>,
|
||||
opt: Res<var::CommandLineOptions>,
|
||||
|
@ -112,9 +112,7 @@ fn handle_game_event(
|
|||
}
|
||||
GameEvent::SetMenu(turn) => {
|
||||
settings.menu_active = turn.to_bool(settings.menu_active);
|
||||
for mut vis in &mut q_menu_vis {
|
||||
*vis = bool2vis(settings.menu_active);
|
||||
}
|
||||
ew_updatemenu.send(menu::UpdateMenuEvent);
|
||||
}
|
||||
GameEvent::SetThirdPerson(turn) => {
|
||||
settings.third_person = turn.to_bool(settings.third_person);
|
||||
|
|
58
src/menu.rs
58
src/menu.rs
|
@ -22,12 +22,13 @@ impl Plugin for MenuPlugin {
|
|||
app.add_systems(Startup, setup.after(hud::setup));
|
||||
app.add_systems(PreUpdate, show_deathscreen.run_if(on_event::<DeathScreenEvent>()));
|
||||
app.add_systems(Update, handle_deathscreen_input);
|
||||
app.add_systems(PostUpdate, update_menu);
|
||||
app.add_systems(PostUpdate, update_menu.run_if(on_event::<UpdateMenuEvent>()));
|
||||
app.add_systems(Update, handle_input.run_if(alive));
|
||||
app.insert_resource(DeathScreenInputDelayTimer(
|
||||
Timer::from_seconds(1.0, TimerMode::Once)));
|
||||
app.insert_resource(MenuState::default());
|
||||
app.add_event::<DeathScreenEvent>();
|
||||
app.add_event::<UpdateMenuEvent>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,15 +37,16 @@ impl Plugin for MenuPlugin {
|
|||
#[derive(Component)] pub struct MenuTopLevel;
|
||||
#[derive(Component)] pub struct DeathScreenElement;
|
||||
#[derive(Component)] pub struct DeathText;
|
||||
#[derive(Event)] pub struct UpdateMenuEvent;
|
||||
#[derive(Event, PartialEq)] pub enum DeathScreenEvent { Show, Hide }
|
||||
|
||||
pub const MENUDEF: &[(&str, MenuAction)] = &[
|
||||
("Toggle Map [M]", MenuAction::ToggleMap),
|
||||
("Toggle Augmented Reality [TAB]", MenuAction::ToggleAR),
|
||||
("Toggle Sound", MenuAction::ToggleSound),
|
||||
("Toggle Music", MenuAction::ToggleMusic),
|
||||
("", MenuAction::ToggleMap),
|
||||
("", MenuAction::ToggleAR),
|
||||
("", MenuAction::ToggleSound),
|
||||
("", MenuAction::ToggleMusic),
|
||||
("Toggle Fullscreen [F11]", MenuAction::ToggleFullscreen),
|
||||
("Toggle Shadows", MenuAction::ToggleShadows),
|
||||
("", MenuAction::ToggleShadows),
|
||||
("Restart Game", MenuAction::Restart),
|
||||
("Quit", MenuAction::Quit),
|
||||
];
|
||||
|
@ -244,11 +246,15 @@ pub struct MenuState {
|
|||
|
||||
pub fn update_menu(
|
||||
mut q_text: Query<&mut Text, With<MenuTopLevel>>,
|
||||
mut q_vis: Query<&mut Visibility, With<menu::MenuElement>>,
|
||||
menustate: Res<MenuState>,
|
||||
settings: Res<Settings>,
|
||||
) {
|
||||
if !settings.menu_active {
|
||||
return;
|
||||
for mut vis in &mut q_vis {
|
||||
*vis = bool2vis(settings.menu_active);
|
||||
}
|
||||
fn bool2string(boolean: bool) -> String {
|
||||
if boolean { "On" } else { "Off" }.to_string()
|
||||
}
|
||||
if let Ok(mut text) = q_text.get_single_mut() {
|
||||
for i in 0..text.sections.len() {
|
||||
|
@ -257,6 +263,34 @@ pub fn update_menu(
|
|||
} else {
|
||||
text.sections[i].style.color = settings.hud_color;
|
||||
}
|
||||
|
||||
match MENUDEF[i].1 {
|
||||
MenuAction::ToggleSound => {
|
||||
let onoff = bool2string(!settings.mute_sfx);
|
||||
text.sections[i].value = format!("Sound: {onoff}\n");
|
||||
}
|
||||
MenuAction::ToggleMusic => {
|
||||
let onoff = bool2string(!settings.mute_music);
|
||||
text.sections[i].value = format!("Music: {onoff}\n");
|
||||
}
|
||||
MenuAction::ToggleAR => {
|
||||
let onoff = bool2string(settings.hud_active);
|
||||
text.sections[i].value = format!("Augmented Reality: {onoff} [TAB]\n");
|
||||
}
|
||||
MenuAction::ToggleMap => {
|
||||
let onoff = bool2string(settings.map_active);
|
||||
text.sections[i].value = format!("Map: {onoff} [M]\n");
|
||||
}
|
||||
MenuAction::ToggleShadows => {
|
||||
let onoff = if settings.shadows_sun {
|
||||
"Flashlight + Sun"
|
||||
} else {
|
||||
"Flashlight Only"
|
||||
};
|
||||
text.sections[i].value = format!("Shadows: {onoff}\n");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -269,6 +303,7 @@ pub fn handle_input(
|
|||
mut ew_game: EventWriter<game::GameEvent>,
|
||||
mut ew_playerdies: EventWriter<game::PlayerDiesEvent>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
mut ew_updatemenu: EventWriter<UpdateMenuEvent>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(settings.key_menu)
|
||||
|| keyboard_input.just_pressed(settings.key_vehicle) && settings.menu_active
|
||||
|
@ -284,6 +319,7 @@ pub fn handle_input(
|
|||
{
|
||||
menustate.cursor = menustate.cursor.saturating_sub(1);
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
||||
ew_updatemenu.send(UpdateMenuEvent);
|
||||
}
|
||||
if keyboard_input.just_pressed(settings.key_back)
|
||||
|| keyboard_input.just_pressed(settings.key_mousedown)
|
||||
|
@ -291,6 +327,7 @@ pub fn handle_input(
|
|||
{
|
||||
menustate.cursor = (menustate.cursor + 1).min(MENUDEF.len() - 1);
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
||||
ew_updatemenu.send(UpdateMenuEvent);
|
||||
}
|
||||
if keyboard_input.just_pressed(settings.key_interact)
|
||||
|| keyboard_input.just_pressed(KeyCode::Enter)
|
||||
|
@ -300,21 +337,26 @@ pub fn handle_input(
|
|||
MenuAction::ToggleMap => {
|
||||
ew_game.send(GameEvent::SetMap(Toggle));
|
||||
ew_game.send(GameEvent::SetMenu(Turn::Off));
|
||||
ew_updatemenu.send(UpdateMenuEvent);
|
||||
},
|
||||
MenuAction::ToggleAR => {
|
||||
ew_game.send(GameEvent::SetAR(Toggle));
|
||||
ew_updatemenu.send(UpdateMenuEvent);
|
||||
},
|
||||
MenuAction::ToggleMusic => {
|
||||
ew_game.send(GameEvent::SetMusic(Toggle));
|
||||
ew_updatemenu.send(UpdateMenuEvent);
|
||||
},
|
||||
MenuAction::ToggleSound => {
|
||||
ew_game.send(GameEvent::SetSound(Toggle));
|
||||
ew_updatemenu.send(UpdateMenuEvent);
|
||||
},
|
||||
MenuAction::ToggleFullscreen => {
|
||||
ew_game.send(GameEvent::SetFullscreen(Toggle));
|
||||
},
|
||||
MenuAction::ToggleShadows => {
|
||||
ew_game.send(GameEvent::SetShadows(Toggle));
|
||||
ew_updatemenu.send(UpdateMenuEvent);
|
||||
},
|
||||
MenuAction::Restart => {
|
||||
settings.god_mode = false;
|
||||
|
|
Loading…
Reference in a new issue