Fix audio settings
This commit is contained in:
@@ -15,7 +15,7 @@ public class MdgaApp extends SimpleApplication {
|
|||||||
private ModelSyncronizer modelSyncronizer;
|
private ModelSyncronizer modelSyncronizer;
|
||||||
|
|
||||||
MdgaView view = null;
|
MdgaView view = null;
|
||||||
private MdgaState state = MdgaState.GAME;
|
private MdgaState state = MdgaState.MAIN;
|
||||||
|
|
||||||
private static float resolutionFactor = 1f;
|
private static float resolutionFactor = 1f;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package pp.mdga.client.dialog;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class GetPercentRunnable {
|
||||||
|
private final Supplier<Float> action;
|
||||||
|
|
||||||
|
public GetPercentRunnable(Supplier<Float> action) {
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float get() {
|
||||||
|
return action.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ public class SettingsDialog extends Dialog {
|
|||||||
private TextField nameInput;
|
private TextField nameInput;
|
||||||
|
|
||||||
private HashMap<Slider, PercentRunnable> map = new HashMap<Slider, PercentRunnable>();
|
private HashMap<Slider, PercentRunnable> map = new HashMap<Slider, PercentRunnable>();
|
||||||
|
private HashMap<Slider, GetPercentRunnable> map2 = new HashMap<Slider, GetPercentRunnable>();
|
||||||
|
|
||||||
public SettingsDialog(MdgaApp app, Node node, String path) {
|
public SettingsDialog(MdgaApp app, Node node, String path) {
|
||||||
super(app, node);
|
super(app, node);
|
||||||
@@ -62,7 +63,7 @@ public void addButton(String label, Runnable action, Vector3f size) {
|
|||||||
createButton(label, action, size);
|
createButton(label, action, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSlider(String label, PercentRunnable action, Vector3f size, int start) {
|
public void addSlider(String label, PercentRunnable action, GetPercentRunnable action2, Vector3f size, int start) {
|
||||||
Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||||
|
|
||||||
Slider slider = new Slider("slider");
|
Slider slider = new Slider("slider");
|
||||||
@@ -71,7 +72,7 @@ public void addSlider(String label, PercentRunnable action, Vector3f size, int s
|
|||||||
slider.setBackground(background);
|
slider.setBackground(background);
|
||||||
|
|
||||||
slider.setPreferredSize(size);
|
slider.setPreferredSize(size);
|
||||||
slider.setModel(new DefaultRangedValueModel(0, 10, start));
|
slider.setModel(new DefaultRangedValueModel(0, 100, start));
|
||||||
slider.setPreferredSize(new Vector3f(150 * app.getResolutionFactor(), 30 * app.getResolutionFactor(), 0));
|
slider.setPreferredSize(new Vector3f(150 * app.getResolutionFactor(), 30 * app.getResolutionFactor(), 0));
|
||||||
slider.getDecrementButton().setText(" - ");
|
slider.getDecrementButton().setText(" - ");
|
||||||
slider.getIncrementButton().setText(" + ");
|
slider.getIncrementButton().setText(" + ");
|
||||||
@@ -89,11 +90,20 @@ public void addSlider(String label, PercentRunnable action, Vector3f size, int s
|
|||||||
container.addChild(subContainer);
|
container.addChild(subContainer);
|
||||||
|
|
||||||
map.put(slider, action);
|
map.put(slider, action);
|
||||||
|
map2.put(slider, action2);
|
||||||
|
|
||||||
//abstandshalter
|
//abstandshalter
|
||||||
container.addChild(new Panel(20 * app.getResolutionFactor(), 10 * app.getResolutionFactor(), ColorRGBA.Gray));
|
container.addChild(new Panel(20 * app.getResolutionFactor(), 10 * app.getResolutionFactor(), ColorRGBA.Gray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initVolume() {
|
||||||
|
map2.forEach((slider, runnable) -> {
|
||||||
|
double val = (double) runnable.get();
|
||||||
|
slider.getModel().setPercent(val);
|
||||||
|
System.out.println("initVolume: " + val + " " + slider.getModel().getPercent());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
map.forEach((slider, runnable) -> {
|
map.forEach((slider, runnable) -> {
|
||||||
float val = (float) slider.getModel().getPercent();
|
float val = (float) slider.getModel().getPercent();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.shape.Quad;
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
|
import pp.mdga.client.dialog.GetPercentRunnable;
|
||||||
import pp.mdga.client.dialog.PercentRunnable;
|
import pp.mdga.client.dialog.PercentRunnable;
|
||||||
import pp.mdga.client.dialog.SettingsButtonDialog;
|
import pp.mdga.client.dialog.SettingsButtonDialog;
|
||||||
import pp.mdga.client.MdgaApp;
|
import pp.mdga.client.MdgaApp;
|
||||||
@@ -61,9 +62,9 @@ public MdgaView(MdgaApp app) {
|
|||||||
this.settings.addButton("Zurück", () -> leaveSettings(false), size);
|
this.settings.addButton("Zurück", () -> leaveSettings(false), size);
|
||||||
|
|
||||||
this.audio = new SettingsDialog(app, audioSettingsNode, "audio_icon.png");
|
this.audio = new SettingsDialog(app, audioSettingsNode, "audio_icon.png");
|
||||||
this.audio.addSlider("Lautstärke", new PercentRunnable(app.getAcousticHandler()::setMainVolume), size, 5);
|
this.audio.addSlider("Lautstärke", new PercentRunnable(app.getAcousticHandler()::setMainVolume), new GetPercentRunnable(app.getAcousticHandler()::getMainVolume), size, (int) app.getAcousticHandler().getMainVolume() * 100);
|
||||||
this.audio.addSlider("Musik", new PercentRunnable(app.getAcousticHandler()::setMusicVolume), size, 10);
|
this.audio.addSlider("Musik", new PercentRunnable(app.getAcousticHandler()::setMusicVolume), new GetPercentRunnable(app.getAcousticHandler()::getMusicVolume), size, (int) app.getAcousticHandler().getMusicVolume() * 100);
|
||||||
this.audio.addSlider("Sound", new PercentRunnable(app.getAcousticHandler()::setSoundVolume), size, 10);
|
this.audio.addSlider("Sound", new PercentRunnable(app.getAcousticHandler()::setSoundVolume), new GetPercentRunnable(app.getAcousticHandler()::getSoundVolume), size, (int) app.getAcousticHandler().getSoundVolume() * 100);
|
||||||
this.audio.addButton("Zurück", () -> leaveAudio(), size);
|
this.audio.addButton("Zurück", () -> leaveAudio(), size);
|
||||||
|
|
||||||
this.video = new SettingsDialog(app, videoSettingsNode, "monitor.png");
|
this.video = new SettingsDialog(app, videoSettingsNode, "monitor.png");
|
||||||
@@ -75,6 +76,8 @@ public MdgaView(MdgaApp app) {
|
|||||||
public void enter() {
|
public void enter() {
|
||||||
app.getGuiNode().attachChild(node);
|
app.getGuiNode().attachChild(node);
|
||||||
|
|
||||||
|
audio.initVolume();
|
||||||
|
|
||||||
settingsButton.show();
|
settingsButton.show();
|
||||||
|
|
||||||
onEnter();
|
onEnter();
|
||||||
|
|||||||
Reference in New Issue
Block a user