Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion phira/src/page/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl OffsetPage {
let cali = audio.create_music(
AudioClip::new(load_file("cali.ogg").await?)?,
MusicParams {
amplifier: get_data().config.volume_music,
loop_mix_time: 0.,
..Default::default()
},
Expand Down Expand Up @@ -179,7 +180,9 @@ impl Page for OffsetPage {
if self.cali_last {
let g = ui.to_global(ct);
self.emitter.emit_at(vec2(g.0, g.1), 0., self.color);
let _ = self.cali_hit.play(PlaySfxParams::default());
let _ = self.cali_hit.play(PlaySfxParams {
amplifier: config.volume_sfx,
});
}
self.cali_last = false;
}
Expand Down
4 changes: 3 additions & 1 deletion phira/src/page/respack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ impl Page for ResPackPage {
emitter.emit_at(vec2(cx, line), 0., pack.info.fx_perfect());
}
if let Some(sfxs) = &mut self.sfxs {
let _ = sfxs[(irnd % 3) as usize].play(PlaySfxParams::default());
let _ = sfxs[(irnd % 3) as usize].play(PlaySfxParams {
amplifier: get_data().config.volume_sfx,
});
}
self.last_round = irnd;
}
Expand Down
3 changes: 2 additions & 1 deletion phira/src/page/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use prpr::{
ext::{open_url, poll_future, semi_white, LocalTask, RectExt, SafeTexture},
scene::{request_input, return_input, show_error, show_message, take_input},
task::Task,
ui::{DRectButton, Scroll, Slider, Ui, PREFER_REDUCED_MOTION},
ui::{DRectButton, Scroll, Slider, Ui, PREFER_REDUCED_MOTION, UI_SFX_VOLUME},
};
use prpr_l10n::{LanguageIdentifier, LANG_IDENTS, LANG_NAMES};
use reqwest::Url;
Expand Down Expand Up @@ -701,6 +701,7 @@ impl AudioList {
return Ok(wt);
}
if let wt @ Some(_) = self.sfx_slider.touch(touch, t, &mut config.volume_sfx) {
UI_SFX_VOLUME.store(config.volume_sfx.to_bits(), Ordering::Relaxed);
return Ok(wt);
}
let old = config.volume_bgm;
Expand Down
1 change: 1 addition & 0 deletions phira/src/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl MainScene {
}

async fn init() -> Result<()> {
prpr::ui::UI_SFX_VOLUME.store(get_data().config.volume_sfx.to_bits(), Ordering::Relaxed);
// init button hitsound
macro_rules! load_sfx {
($name:ident, $path:literal) => {{
Expand Down
2 changes: 1 addition & 1 deletion phira/src/scene/song.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn create_music(clip: AudioClip) -> Result<Music> {
it.borrow_mut().create_music(
clip,
MusicParams {
amplifier: 0.7,
amplifier: get_data().config.volume_music * 0.7,
loop_mix_time: 0.,
..Default::default()
},
Expand Down
15 changes: 11 additions & 4 deletions prpr/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ use std::{
cell::RefCell,
collections::HashMap,
ops::{Deref, DerefMut, Range},
sync::atomic::{AtomicBool, Ordering},
sync::atomic::{AtomicBool, AtomicU32, Ordering},
};

pub static PREFER_REDUCED_MOTION: AtomicBool = AtomicBool::new(false);
pub static UI_SFX_VOLUME: AtomicU32 = AtomicU32::new(1.0f32.to_bits());

#[derive(Default, Clone, Copy)]
pub struct Gravity(u8);
Expand Down Expand Up @@ -1390,23 +1391,29 @@ thread_local! {
pub fn button_hit() {
UI_BTN_HITSOUND.with(|it| {
if let Some(sfx) = it.borrow_mut().as_mut() {
let _ = sfx.play(PlaySfxParams::default());
let _ = sfx.play(PlaySfxParams {
amplifier: f32::from_bits(UI_SFX_VOLUME.load(Ordering::Relaxed)),
});
}
});
}

pub fn button_hit_large() {
UI_BTN_HITSOUND_LARGE.with(|it| {
if let Some(sfx) = it.borrow_mut().as_mut() {
let _ = sfx.play(PlaySfxParams::default());
let _ = sfx.play(PlaySfxParams {
amplifier: f32::from_bits(UI_SFX_VOLUME.load(Ordering::Relaxed)),
});
}
});
}

pub fn list_switch() {
UI_SWITCH_SOUND.with(|it| {
if let Some(sfx) = it.borrow_mut().as_mut() {
let _ = sfx.play(PlaySfxParams::default());
let _ = sfx.play(PlaySfxParams {
amplifier: f32::from_bits(UI_SFX_VOLUME.load(Ordering::Relaxed)),
});
}
});
}
Loading