fix(engine): settings toast shows correct volume type (SFX vs Music)
Previously every SettingsChangedEvent fired an "SFX: X%" toast, even when the music volume was adjusted in the Settings panel. Now the toast handler tracks the previous SFX and music levels independently and only shows a toast for whichever value actually changed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -287,14 +287,24 @@ fn handle_challenge_toast(
|
|||||||
fn handle_settings_toast(
|
fn handle_settings_toast(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut events: EventReader<SettingsChangedEvent>,
|
mut events: EventReader<SettingsChangedEvent>,
|
||||||
|
mut last_sfx: Local<Option<f32>>,
|
||||||
|
mut last_music: Local<Option<f32>>,
|
||||||
) {
|
) {
|
||||||
for ev in events.read() {
|
for ev in events.read() {
|
||||||
let pct = (ev.0.sfx_volume * 100.0).round() as i32;
|
let sfx = ev.0.sfx_volume;
|
||||||
spawn_toast(
|
let music = ev.0.music_volume;
|
||||||
&mut commands,
|
let sfx_changed = last_sfx.is_none_or(|prev| (prev - sfx).abs() > f32::EPSILON);
|
||||||
format!("SFX: {pct}%"),
|
let music_changed = last_music.is_none_or(|prev| (prev - music).abs() > f32::EPSILON);
|
||||||
VOLUME_TOAST_SECS,
|
*last_sfx = Some(sfx);
|
||||||
);
|
*last_music = Some(music);
|
||||||
|
if sfx_changed {
|
||||||
|
let pct = (sfx * 100.0).round() as i32;
|
||||||
|
spawn_toast(&mut commands, format!("SFX: {pct}%"), VOLUME_TOAST_SECS);
|
||||||
|
}
|
||||||
|
if music_changed {
|
||||||
|
let pct = (music * 100.0).round() as i32;
|
||||||
|
spawn_toast(&mut commands, format!("Music: {pct}%"), VOLUME_TOAST_SECS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user