Skip to content

Commit

Permalink
menu sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Sep 4, 2024
1 parent d00b827 commit 607f5ab
Show file tree
Hide file tree
Showing 31 changed files with 279 additions and 68 deletions.
Binary file added assets/sounds/generic_button_hover.wav
Binary file not shown.
Binary file added assets/sounds/generic_button_press.wav
Binary file not shown.
Binary file added assets/sounds/mainmenu_widget_open.wav
Binary file not shown.
Binary file added assets/sounds/toggle_disable.wav
Binary file not shown.
Binary file added assets/sounds/toggle_enable.wav
Binary file not shown.
Binary file added assets/sounds/voice_chat_mic_off.wav
Binary file not shown.
Binary file added assets/sounds/voice_chat_mic_on.wav
Binary file not shown.
Binary file added assets/sounds/widget_emotes_close.wav
Binary file not shown.
Binary file added assets/sounds/widget_emotes_highlight.wav
Binary file not shown.
Binary file added assets/sounds/widget_emotes_open.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/ui/button.dui
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
border-size="0.75vmin"
border-color="#9c73af"
styles="active: #b2a1ff; inactive: #7f569e; hover: #e2d1ff; disabled: #555555;"
sounds="hover: 'generic_button_hover.wav'; press: 'generic_button_press.wav'"
/>
<div style="
margin: 1vmin;
Expand Down Expand Up @@ -46,6 +47,7 @@
border-size="0.75vmin"
border-color="#9c73af"
styles="active: #b2a1bf; inactive: #7f569e; hover: #d2c1df; disabled: #555555;"
sounds="hover: 'generic_button_hover.wav'; press: 'generic_button_press.wav'"
/>
</div>
</define-template>
Expand All @@ -69,6 +71,7 @@
border-color="#9c73af"
bound-image="@img"
styles="active: #b2a1bf; inactive: #7f569e; hover: #d2c1df; disabled: #555555;"
sounds="hover: 'generic_button_hover.wav'; press: 'generic_button_press.wav'"
>
</bounds>
</div>
Expand Down
35 changes: 33 additions & 2 deletions crates/av/src/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy_kira_audio::{
};
use common::{
sets::{SceneSets, SetupSets},
structs::{AudioSettings, PrimaryCameraRes, PrimaryUser},
structs::{AudioSettings, PrimaryCameraRes, PrimaryUser, SystemAudio},
};
use dcl::interface::ComponentPosition;
use dcl_component::{proto_components::sdk::components::PbAudioSource, SceneComponentId};
Expand All @@ -31,13 +31,14 @@ pub struct AudioSourcePlugin;

impl Plugin for AudioSourcePlugin {
fn build(&self, app: &mut App) {
app.add_event::<SystemAudio>();
app.add_crdt_lww_component::<PbAudioSource, AudioSource>(
SceneComponentId::AUDIO_SOURCE,
ComponentPosition::EntityOnly,
);
app.add_systems(
Update,
(update_audio, update_source_volume).in_set(SceneSets::PostLoop),
(update_audio, update_source_volume, play_system_audio).in_set(SceneSets::PostLoop),
);
app.add_systems(Startup, setup_audio.in_set(SetupSets::Main));
}
Expand Down Expand Up @@ -198,6 +199,36 @@ fn update_audio(
}
}

fn play_system_audio(
mut events: EventReader<SystemAudio>,
audio: Res<bevy_kira_audio::Audio>,
ipfas: IpfsAssetServer,
audio_instances: Res<Assets<AudioInstance>>,
settings: Res<AudioSettings>,
mut playing: Local<HashSet<Handle<AudioInstance>>>,
) {
for event in events.read() {
let h_clip = ipfas.asset_server().load(&event.0);
let volume = settings.system();
let h_instance = audio
.play(h_clip)
.with_volume(bevy_kira_audio::prelude::Volume::Amplitude(volume as f64))
.handle();
playing.insert(h_instance);
debug!("play system audio {}", event.0);
}

playing.retain(|h_instance| {
let retain = audio_instances
.get(h_instance)
.map_or(false, |instance| instance.state().position().is_some());
if !retain {
debug!("drop system audio");
}
retain
})
}

#[allow(clippy::too_many_arguments)]
fn update_source_volume(
query: Query<(
Expand Down
2 changes: 1 addition & 1 deletion crates/avatar/src/colliders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn update_avatar_collider_actions(
.with_prop("title", format!("{} profile", profile.content.name))
.with_prop("booth-instance", instance)
.with_prop("eth-address", profile.content.eth_address.clone())
.with_prop("buttons", vec![DuiButton::close("Ok")]),
.with_prop("buttons", vec![DuiButton::close_happy("Ok")]),
)
.unwrap();

Expand Down
21 changes: 21 additions & 0 deletions crates/common/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,27 @@ pub enum SettingsTab {
#[derive(Event, Clone)]
pub struct ShowSettingsEvent(pub SettingsTab);

#[derive(Event, Clone)]
pub struct SystemAudio(pub String);

impl From<&str> for SystemAudio {
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}

impl From<String> for SystemAudio {
fn from(value: String) -> Self {
Self(value)
}
}

impl From<&String> for SystemAudio {
fn from(value: &String) -> Self {
Self(value.to_owned())
}
}

#[derive(Resource, Default)]
pub struct PermissionTarget {
pub scene: Option<Entity>,
Expand Down
4 changes: 2 additions & 2 deletions crates/restricted_actions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ fn show_nft_dialog(
DuiButton::new("View on OpenSea.io", link.is_some(), move || {
let _ = opener::open(link.as_ref().unwrap());
}),
DuiButton::close("Close"),
DuiButton::close_happy("Close"),
],
),
)
Expand All @@ -985,7 +985,7 @@ fn show_nft_dialog(
DuiProps::new()
.with_prop("title", "Failed to load NFT")
.with_prop("body", "Failed to load NFT")
.with_prop("buttons", vec![DuiButton::close("Shame")]),
.with_prop("buttons", vec![DuiButton::close_sad("Shame")]),
)
.unwrap();
}
Expand Down
8 changes: 6 additions & 2 deletions crates/system_ui/src/change_realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use bevy::{
tasks::{IoTaskPool, Task},
};
use bevy_dui::{DuiCommandsExt, DuiProps, DuiRegistry};
use common::util::TaskExt;
use common::{
structs::SystemAudio,
util::{FireEventEx, TaskExt},
};
use ipfs::{ChangeRealmEvent, CurrentRealm};
use isahc::AsyncReadResponseExt;
use serde::Deserialize;
Expand Down Expand Up @@ -100,7 +103,7 @@ fn change_realm_dialog(
.clone()
.unwrap_or(String::from("<none>")),
)
.with_prop("buttons", vec![DuiButton::close("cancel")]),
.with_prop("buttons", vec![DuiButton::close_sad("cancel")]),
)
.unwrap();
commands
Expand Down Expand Up @@ -134,6 +137,7 @@ fn update_server_list(
.with_prop(
"onclick",
On::<Click>::new(move |mut commands: Commands, mut e: EventWriter<ChangeRealmEvent>| {
commands.fire_event(SystemAudio("sounds/toggle_enable.wav".to_owned()));
e.send(ChangeRealmEvent {
new_realm: server.url.clone(),
});
Expand Down
29 changes: 17 additions & 12 deletions crates/system_ui/src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use bevy_console::{ConsoleCommandEntered, ConsoleConfiguration, PrintConsoleLine
use bevy_dui::{DuiCommandsExt, DuiProps, DuiRegistry};
use common::{
dcl_assert,
structs::{PrimaryUser, ToolTips},
util::{RingBuffer, RingBufferReceiver, TryPushChildrenEx},
structs::{PrimaryUser, SystemAudio, ToolTips},
util::{FireEventEx, RingBuffer, RingBufferReceiver, TryPushChildrenEx},
};
use comms::{
chat_marker_things, global_crdt::ChatEvent, profile::UserProfile, NetworkMessage, Transport,
Expand Down Expand Up @@ -82,15 +82,19 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..Default::default()
},
Interaction::default(),
On::<Click>::new(|mut q: Query<&mut Style, With<ChatboxContainer>>| {
if let Ok(mut style) = q.get_single_mut() {
style.display = if style.display == Display::Flex {
Display::None
} else {
Display::Flex
};
}
}),
On::<Click>::new(
|mut commands: Commands, mut q: Query<&mut Style, With<ChatboxContainer>>| {
if let Ok(mut style) = q.get_single_mut() {
style.display = if style.display == Display::Flex {
commands.fire_event(SystemAudio("sounds/toggle_disable.wav".to_owned()));
Display::None
} else {
commands.fire_event(SystemAudio("sounds/toggle_enable.wav".to_owned()));
Display::Flex
};
}
},
),
On::<HoverEnter>::new(|mut tooltip: ResMut<ToolTips>| {
tooltip.0.insert(
"chat-button",
Expand Down Expand Up @@ -152,11 +156,12 @@ fn chat_popup(mut commands: Commands, root: Res<SystemUiRoot>, dui: Res<DuiRegis
})
.pipe(select_chat_tab);

let close_ui = |mut q: Query<&mut Style, With<ChatboxContainer>>| {
let close_ui = |mut commands: Commands, mut q: Query<&mut Style, With<ChatboxContainer>>| {
let Ok(mut style) = q.get_single_mut() else {
return;
};
style.display = Display::None;
commands.fire_event(SystemAudio("sounds/toggle_disable.wav".to_owned()));
};

let props = DuiProps::new()
Expand Down
4 changes: 2 additions & 2 deletions crates/system_ui/src/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ui_core::{
combo_box::ComboBox,
interact_style::Active,
toggle::Toggled,
ui_actions::{close_ui, Click, DataChanged, On, UiCaller},
ui_actions::{close_ui_happy, Click, DataChanged, On, UiCaller},
};

use crate::profile::{close_settings, OnCloseEvent, SettingsDialog};
Expand Down Expand Up @@ -521,7 +521,7 @@ pub fn spawn_discover_popup(
}
};

let jump_in = On::<Click>::new(system.pipe(close_settings).pipe(close_ui));
let jump_in = On::<Click>::new(system.pipe(close_settings).pipe(close_ui_happy));

let image_path = IpfsPath::new_from_url(&item.image, "image");
let h_image = asset_server.load::<Image>(PathBuf::from(&image_path));
Expand Down
14 changes: 11 additions & 3 deletions crates/system_ui/src/emote_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use bevy::{
use bevy_dui::{DuiComponentFromClone, DuiEntityCommandsExt, DuiProps, DuiRegistry};
use collectibles::{CollectibleError, CollectibleManager, Emote, EmoteUrn};
use common::{
structs::{ActiveDialog, PrimaryUser},
util::ModifyComponentExt,
structs::{ActiveDialog, PrimaryUser, SystemAudio},
util::{FireEventEx, ModifyComponentExt},
};
use comms::profile::CurrentUserProfile;
use ui_core::{
Expand Down Expand Up @@ -248,6 +248,7 @@ fn show_emote_ui(

if let Some(ev) = ev {
for ent in existing.iter() {
commands.fire_event(SystemAudio("sounds/widget_emotes_close.wav".to_owned()));
commands.entity(ent).despawn_recursive();

for (button, interact) in &buttons {
Expand All @@ -267,6 +268,8 @@ fn show_emote_ui(
return;
};

commands.fire_event(SystemAudio("sounds/widget_emotes_open.wav".to_owned()));

let mut props = window.single().get_layout_props(1.5, 0.6, coords);

let Some(player_emotes) = profile
Expand Down Expand Up @@ -343,7 +346,12 @@ fn show_emote_ui(
Interaction::default(),
FocusPolicy::Block,
On::<HoverEnter>::new(
move |mut color: Query<&mut UiImage>, mut text: Query<&mut Text>| {
move |mut commands: Commands,
mut color: Query<&mut UiImage>,
mut text: Query<&mut Text>| {
commands.fire_event(SystemAudio(
"sounds/widget_emotes_highlight.wav".to_owned(),
));
if let Ok(mut img) = color.get_mut(button) {
img.color = Color::srgb(1.0, 1.0, 1.50);
}
Expand Down
20 changes: 13 additions & 7 deletions crates/system_ui/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use bevy::{
use bevy_dui::{DuiCommandsExt, DuiEntityCommandsExt, DuiProps, DuiRegistry};
use common::{
profile::SerializedProfile,
structs::{ActiveDialog, AppConfig, ChainLink, DialogPermit, PreviousLogin},
util::{project_directories, TaskExt},
structs::{ActiveDialog, AppConfig, ChainLink, DialogPermit, PreviousLogin, SystemAudio},
util::{project_directories, FireEventEx, TaskExt},
};
use comms::{
preview::PreviewMode,
Expand All @@ -23,7 +23,7 @@ use ipfs::{CurrentRealm, IpfsAssetServer};
use scene_runner::Toaster;
use ui_core::{
button::DuiButton,
ui_actions::{close_ui, Click, EventCloneExt, On},
ui_actions::{close_ui_happy, Click, EventCloneExt, On},
};
use wallet::{
browser_auth::{
Expand Down Expand Up @@ -102,11 +102,11 @@ fn login(
&dui,
"motd",
DuiProps::default()
.with_prop("buttons", vec![DuiButton::new_enabled("Ok", close_ui)]),
.with_prop("buttons", vec![DuiButton::new_enabled("Ok", close_ui_happy)]),
)
.unwrap();
commands.entity(components.root).insert(permit);
}).pipe(close_ui))]),
}).pipe(close_ui_happy))]),
)
.unwrap();
commands.entity(components.root).insert(permit);
Expand All @@ -115,8 +115,10 @@ fn login(
.spawn_template(
&dui,
"motd",
DuiProps::default()
.with_prop("buttons", vec![DuiButton::new_enabled("Ok", close_ui)]),
DuiProps::default().with_prop(
"buttons",
vec![DuiButton::new_enabled("Ok", close_ui_happy)],
),
)
.unwrap();
commands.entity(components.root).insert(permit);
Expand Down Expand Up @@ -373,6 +375,7 @@ fn login(

Ok((previous_login.root_address, local_wallet, auth, profile))
}));
commands.fire_event(SystemAudio("sounds/toggle_enable.wav".to_owned()));
}
LoginType::NewRemote => {
info!("new remote");
Expand All @@ -398,6 +401,7 @@ fn login(
.unwrap();

*dialog = Some(components.root);
commands.fire_event(SystemAudio("sounds/toggle_enable.wav".to_owned()));
}
LoginType::Guest => {
info!("guest");
Expand All @@ -417,10 +421,12 @@ fn login(
base_url: ipfas.ipfs().contents_endpoint().unwrap_or_default(),
});
current_profile.is_deployed = true;
commands.fire_event(SystemAudio("sounds/toggle_enable.wav".to_owned()));
}
LoginType::Cancel => {
*final_task = None;
*dialog = None;
commands.fire_event(SystemAudio("sounds/toggle_disable.wav".to_owned()));
}
}
}
Expand Down
Loading

0 comments on commit 607f5ab

Please sign in to comment.