Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

button sounds #236

Merged
merged 4 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/ui/down_button_1.ogg
Binary file not shown.
Binary file added assets/ui/down_button_2.ogg
Binary file not shown.
Binary file added assets/ui/down_button_3.ogg
Binary file not shown.
Binary file added assets/ui/down_play_button.ogg
Binary file not shown.
Binary file added assets/ui/focused_button_1.ogg
Binary file not shown.
Binary file added assets/ui/focused_button_2.ogg
Binary file not shown.
Binary file added assets/ui/focused_button_3.ogg
Binary file not shown.
21 changes: 21 additions & 0 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Also for cleanness (named channels have evident function), we don't use the default channel.

use bevy::{prelude::*, utils::HashMap};
use bevy_egui::{egui::output::OutputEvent, EguiContext};
use bevy_kira_audio::{AudioApp, AudioChannel, AudioSource};
use iyes_loopless::prelude::*;

Expand Down Expand Up @@ -92,6 +93,26 @@ pub fn animation_audio_playback(
}
}

/// Plays main menu sounds
pub fn main_menu_sounds(
mut context: ResMut<EguiContext>,
effects_channel: Res<AudioChannel<EffectsChannel>>,
asset_server: Res<AssetServer>,
) {
for event in &context.ctx_mut().output().events {
println!("{:?}", event);
odecay marked this conversation as resolved.
Show resolved Hide resolved
if let OutputEvent::Clicked(info) = event {
if info.label.as_ref().unwrap() == "Start Game" {
//Play down_play_button
effects_channel.play(asset_server.load("ui/down_play_button.ogg"));
} else {
//Play one of the down button audios, except down_play_button
effects_channel.play(asset_server.load("ui/down_button_1.ogg"));
}
}
}
}

pub fn play_menu_music(game_meta: Res<GameMeta>, music_channel: Res<AudioChannel<MusicChannel>>) {
// This is a workaround for a Bevy Kira bug where stopping a sound immediately after
// playing it doesn't work. We run into this issue when the menu starts and immediately
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ fn main() {
asset_server_settings.asset_folder = asset_dir.clone();
}
app.insert_resource(asset_server_settings);

// Add default plugins
#[cfg(feature = "schedule_graph")]
app.add_plugins_with(DefaultPlugins, |plugins| {
Expand Down Expand Up @@ -132,6 +131,10 @@ fn main() {
.run_in_state(GameState::InGame)
.with_system(game_over_on_players_death)
.into(),
)
.add_system_to_stage(
CoreStage::PostUpdate,
main_menu_sounds.before(bevy_egui::EguiSystem::ProcessOutput),
);

// Register reflect types that don't come from plugins
Expand Down