mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Working audio rocker in settings menu.
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
package org.toop.app.menu;
|
package org.toop.app.menu;
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.CheckBox;
|
|
||||||
import javafx.scene.control.ChoiceBox;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.Region;
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
@@ -11,6 +10,8 @@ import javafx.scene.layout.VBox;
|
|||||||
import org.toop.app.App;
|
import org.toop.app.App;
|
||||||
import org.toop.framework.asset.ResourceManager;
|
import org.toop.framework.asset.ResourceManager;
|
||||||
import org.toop.framework.asset.resources.LocalizationAsset;
|
import org.toop.framework.asset.resources.LocalizationAsset;
|
||||||
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.local.AppContext;
|
import org.toop.local.AppContext;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -34,6 +35,7 @@ public final class OptionsMenu extends Menu {
|
|||||||
screenDeviceSelectorCreation(),
|
screenDeviceSelectorCreation(),
|
||||||
displayModeSelectorCreation(),
|
displayModeSelectorCreation(),
|
||||||
selectFullscreenCreation(),
|
selectFullscreenCreation(),
|
||||||
|
volumeSelectorCreation(),
|
||||||
exitOptionsButton);
|
exitOptionsButton);
|
||||||
|
|
||||||
optionsBox.setAlignment(Pos.CENTER);
|
optionsBox.setAlignment(Pos.CENTER);
|
||||||
@@ -113,4 +115,28 @@ public final class OptionsMenu extends Menu {
|
|||||||
return setFullscreen;
|
return setFullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Slider volumeSelectorCreation() {
|
||||||
|
Slider volumeSlider = new Slider(0, 100, 50);
|
||||||
|
new EventFlow()
|
||||||
|
.addPostEvent(AudioEvents.GetCurrentVolume.class)
|
||||||
|
.onResponse(AudioEvents.GetCurrentVolumeReponse.class, event -> {
|
||||||
|
volumeSlider.setValue(event.currentVolume() * 100);
|
||||||
|
}).asyncPostEvent();
|
||||||
|
volumeSlider.setShowTickLabels(true);
|
||||||
|
volumeSlider.setShowTickMarks(true);
|
||||||
|
volumeSlider.setMajorTickUnit(25);
|
||||||
|
volumeSlider.setMinorTickCount(4);
|
||||||
|
volumeSlider.setBlockIncrement(5);
|
||||||
|
volumeSlider.setMaxWidth(225);
|
||||||
|
|
||||||
|
Label valueLabel = new Label(String.valueOf((int) volumeSlider.getValue()));
|
||||||
|
|
||||||
|
volumeSlider.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||||
|
valueLabel.setText(String.valueOf(newVal.intValue()));
|
||||||
|
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(newVal.doubleValue()/100.0))
|
||||||
|
.asyncPostEvent();
|
||||||
|
});
|
||||||
|
return volumeSlider;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,7 @@ public class SoundManager {
|
|||||||
.listen(this::handleStopSound)
|
.listen(this::handleStopSound)
|
||||||
.listen(this::handleMusicStart)
|
.listen(this::handleMusicStart)
|
||||||
.listen(this::handleVolumeChange)
|
.listen(this::handleVolumeChange)
|
||||||
|
.listen(this::handleGetCurrentVolume)
|
||||||
.listen(AudioEvents.playOnClickButton.class, _ -> {
|
.listen(AudioEvents.playOnClickButton.class, _ -> {
|
||||||
try {
|
try {
|
||||||
playSound("hitsound0.wav", false);
|
playSound("hitsound0.wav", false);
|
||||||
@@ -70,6 +71,12 @@ public class SoundManager {
|
|||||||
for (MediaPlayer mediaPlayer : this.activeMusic) {
|
for (MediaPlayer mediaPlayer : this.activeMusic) {
|
||||||
mediaPlayer.setVolume(this.volume);
|
mediaPlayer.setVolume(this.volume);
|
||||||
}
|
}
|
||||||
|
IO.println("Volume: " + this.volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleGetCurrentVolume(AudioEvents.GetCurrentVolume event) {
|
||||||
|
new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeReponse(volume, event.snowflakeId()))
|
||||||
|
.asyncPostEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMusicStart(AudioEvents.StartBackgroundMusic e) {
|
private void handleMusicStart(AudioEvents.StartBackgroundMusic e) {
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package org.toop.framework.audio.events;
|
package org.toop.framework.audio.events;
|
||||||
|
|
||||||
import org.toop.framework.asset.resources.MusicAsset;
|
import org.toop.framework.asset.resources.MusicAsset;
|
||||||
|
import org.toop.framework.eventbus.events.EventWithSnowflake;
|
||||||
import org.toop.framework.eventbus.events.EventWithoutSnowflake;
|
import org.toop.framework.eventbus.events.EventWithoutSnowflake;
|
||||||
import org.toop.framework.eventbus.events.EventsBase;
|
import org.toop.framework.eventbus.events.EventsBase;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class AudioEvents extends EventsBase {
|
public class AudioEvents extends EventsBase {
|
||||||
/** Starts playing a sound. */
|
/** Starts playing a sound. */
|
||||||
public record PlayAudio(String fileName, boolean loop)
|
public record PlayAudio(String fileName, boolean loop)
|
||||||
@@ -13,5 +16,27 @@ public class AudioEvents extends EventsBase {
|
|||||||
|
|
||||||
public record StartBackgroundMusic() implements EventWithoutSnowflake {}
|
public record StartBackgroundMusic() implements EventWithoutSnowflake {}
|
||||||
public record ChangeVolume(double newVolume) implements EventWithoutSnowflake {}
|
public record ChangeVolume(double newVolume) implements EventWithoutSnowflake {}
|
||||||
|
public record GetCurrentVolume(long snowflakeId) implements EventWithSnowflake {
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> result() {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long eventSnowflake() {
|
||||||
|
return snowflakeId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public record GetCurrentVolumeReponse(double currentVolume, long snowflakeId) implements EventWithSnowflake {
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> result() {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long eventSnowflake() {
|
||||||
|
return snowflakeId;
|
||||||
|
}
|
||||||
|
}
|
||||||
public record playOnClickButton() implements EventWithoutSnowflake {}
|
public record playOnClickButton() implements EventWithoutSnowflake {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user