mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Fixed audio not getting correct volume at settings loading. Added back background music
This commit is contained in:
@@ -11,6 +11,8 @@ import javafx.scene.Scene;
|
|||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.toop.framework.asset.resources.SettingsAsset;
|
import org.toop.framework.asset.resources.SettingsAsset;
|
||||||
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.local.AppSettings;
|
import org.toop.local.AppSettings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -65,6 +67,8 @@ public final class App extends Application {
|
|||||||
|
|
||||||
App.isQuitting = false;
|
App.isQuitting = false;
|
||||||
|
|
||||||
|
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
|
||||||
|
|
||||||
activate(new MainLayer());
|
activate(new MainLayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public final class OptionsLayer extends Layer {
|
|||||||
container.addSlider(100, currentVolume, (volume) -> {
|
container.addSlider(100, currentVolume, (volume) -> {
|
||||||
currentVolume = volume;
|
currentVolume = volume;
|
||||||
settings.setVolume(volume);
|
settings.setVolume(volume);
|
||||||
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue() / 100.0)).asyncPostEvent();
|
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue())).asyncPostEvent();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package org.toop.local;
|
|||||||
|
|
||||||
import org.toop.app.App;
|
import org.toop.app.App;
|
||||||
import org.toop.framework.asset.resources.SettingsAsset;
|
import org.toop.framework.asset.resources.SettingsAsset;
|
||||||
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.framework.settings.Settings;
|
import org.toop.framework.settings.Settings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -20,6 +22,8 @@ public class AppSettings {
|
|||||||
|
|
||||||
AppContext.setLocale(Locale.of(settingsData.locale));
|
AppContext.setLocale(Locale.of(settingsData.locale));
|
||||||
App.setFullscreen(settingsData.fullScreen);
|
App.setFullscreen(settingsData.fullScreen);
|
||||||
|
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume)).asyncPostEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsAsset getPath() {
|
public SettingsAsset getPath() {
|
||||||
|
|||||||
BIN
app/src/main/resources/assets/audio/music/gladius.mp3
Normal file
BIN
app/src/main/resources/assets/audio/music/gladius.mp3
Normal file
Binary file not shown.
@@ -69,15 +69,16 @@ public class SoundManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleVolumeChange(AudioEvents.ChangeVolume event) {
|
private void handleVolumeChange(AudioEvents.ChangeVolume event) {
|
||||||
if (event.newVolume() > 1.0) this.volume = 1.0;
|
double newVolume = event.newVolume() / 100;
|
||||||
else this.volume = Math.max(event.newVolume(), 0.0);
|
if (newVolume > 1.0) this.volume = 1.0;
|
||||||
|
else this.volume = Math.max(newVolume, 0.0);
|
||||||
for (MediaPlayer mediaPlayer : this.activeMusic) {
|
for (MediaPlayer mediaPlayer : this.activeMusic) {
|
||||||
mediaPlayer.setVolume(this.volume);
|
mediaPlayer.setVolume(this.volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGetCurrentVolume(AudioEvents.GetCurrentVolume event) {
|
private void handleGetCurrentVolume(AudioEvents.GetCurrentVolume event) {
|
||||||
new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeReponse(volume, event.snowflakeId()))
|
new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeReponse(volume * 100, event.snowflakeId()))
|
||||||
.asyncPostEvent();
|
.asyncPostEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user