Skip to content

Commit

Permalink
Merge #236
Browse files Browse the repository at this point in the history
236: button sounds r=odecay a=DRuppFv

Note: I removed a lot of code that was not done

Just need help with playing the audio, the audio files are in the PR

Co-authored-by: DRuppFv <DRuppFv@gmail.com>
Co-authored-by: odecay <electricbuck@gmail.com>
Co-authored-by: otis <electricbuck@gmail.com>
  • Loading branch information
3 people committed Sep 19, 2022
2 parents 8098a8f + 060fe7c commit c8ee96f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 1 deletion.
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.
20 changes: 20 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,25 @@ 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 {
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 @@ -133,6 +132,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

0 comments on commit c8ee96f

Please sign in to comment.