diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java index 4a4ef96b..9efceb3e 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java @@ -1,18 +1,11 @@ package pp.mdga.client; import com.jme3.app.SimpleApplication; -import com.jme3.renderer.RenderManager; import com.simsilica.lemur.GuiGlobals; import pp.mdga.client.acoustic.AcousticHandler; import pp.mdga.client.animation.AnimationHandler; import com.jme3.system.AppSettings; import pp.mdga.client.view.*; -import pp.mdga.game.Color; -import pp.mdga.notification.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; public class MdgaApp extends SimpleApplication { private AnimationHandler animationHandler; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java index fcec93d3..fbf78b2f 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/AcousticHandler.java @@ -5,6 +5,7 @@ import pp.mdga.client.MdgaState; import java.util.*; +import java.util.prefs.Preferences; public class AcousticHandler { private MdgaApp app; @@ -29,8 +30,14 @@ public class AcousticHandler { private ArrayList sounds = new ArrayList<>(); + private Preferences prefs = Preferences.userNodeForPackage(AcousticHandler.class); + public AcousticHandler(MdgaApp app) { this.app = app; + + mainVolume = prefs.getFloat("mainVolume", 1.0f); + musicVolume = prefs.getFloat("musicVolume", 1.0f); + soundVolume = prefs.getFloat("soundVolume", 1.0f); } /** @@ -67,7 +74,19 @@ public void playSound(MdgaSound sound) { assets.add(new SoundAssetDelayVolume(SoundAsset.LOST, 1.0f, 0.0f)); break; case VICTORY: - assets.add(new SoundAssetDelayVolume(SoundAsset.VICTORY, 1.0f, 2.0f)); + assets.add(new SoundAssetDelayVolume(SoundAsset.VICTORY, 1.0f, 0.0f)); + break; + case BUTTON_PRESSED: + assets.add(new SoundAssetDelayVolume(SoundAsset.BUTTON_PRESS, 0.7f, 0.0f)); + break; + case WRONG_INPUT: + assets.add(new SoundAssetDelayVolume(SoundAsset.ERROR, 1.0f, 0.0f)); + break; + case UI_CLICK: + assets.add(new SoundAssetDelayVolume(SoundAsset.UI_CLICK, 0.8f, 0.0f)); + break; + case START: + assets.add(new SoundAssetDelayVolume(SoundAsset.START, 0.8f, 0.2f)); break; default: @@ -362,6 +381,7 @@ public float getSoundVolume() { */ public void setMainVolume(float mainVolume) { this.mainVolume = mainVolume; + prefs.putFloat("mainVolume", mainVolume); } /** @@ -371,6 +391,7 @@ public void setMainVolume(float mainVolume) { */ public void setMusicVolume(float musicVolume) { this.musicVolume = musicVolume; + prefs.putFloat("musicVolume", musicVolume); } /** @@ -380,6 +401,7 @@ public void setMusicVolume(float musicVolume) { */ public void setSoundVolume(float soundVolume) { this.soundVolume = soundVolume; + prefs.putFloat("soundVolume", soundVolume); } /** diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/MdgaSound.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/MdgaSound.java index 6f39f04c..0a4949f3 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/MdgaSound.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/MdgaSound.java @@ -19,5 +19,9 @@ public enum MdgaSound { DESELECT, HURRY, VICTORY, - LOST + LOST, + BUTTON_PRESSED, + WRONG_INPUT, + UI_CLICK, + START, } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/SoundAsset.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/SoundAsset.java index ce4e6c23..c931215a 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/SoundAsset.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/acoustic/SoundAsset.java @@ -17,7 +17,11 @@ enum SoundAsset { DESELECT(""), HURRY(""), VICTORY("LevelUp2.wav"), - LOST("GameOver.wav"); + LOST("GameOver.wav"), + BUTTON_PRESS("menu_button.ogg"), + ERROR("error_sound.ogg"), + UI_CLICK("uiclick.ogg"), + START("gamestart.ogg"); private final String path; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java index 0b1fe1e6..08fb544d 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java @@ -8,6 +8,7 @@ import com.simsilica.lemur.VAlignment; import com.simsilica.lemur.component.QuadBackgroundComponent; import pp.mdga.client.MdgaApp; +import pp.mdga.client.acoustic.MdgaSound; public abstract class ClickButton extends AbstractButton { protected final Runnable action; @@ -27,7 +28,7 @@ public abstract class ClickButton extends AbstractButton { instance = new Button(label); - instance.addClickCommands((button) -> action.run()); + instance.addClickCommands((button) -> { app.getAcousticHandler().playSound(MdgaSound.BUTTON_PRESSED); action.run(); }); instance.setTextHAlignment(HAlignment.Center); instance.setTextVAlignment(VAlignment.Center); @@ -66,6 +67,8 @@ protected void click() { QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_PRESSED); instance.setBackground(background); + app.getAcousticHandler().playSound(MdgaSound.UI_CLICK); + onHover(); }; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java index c7d4e56d..5a1dd930 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java @@ -24,8 +24,8 @@ public AudioSettingsDialog(MdgaApp app, Node node, MdgaView view) { this.view = view; mainVolume = new SliderButton(app, node, "Gesamt Lautstärke"); - musicVolume = new SliderButton(app, node, "Gesamt Lautstärke"); - soundVolume = new SliderButton(app, node, "Gesamt Lautstärke"); + musicVolume = new SliderButton(app, node, "Musik Lautstärke"); + soundVolume = new SliderButton(app, node, "Effekt Lautstärke"); backButton = new MenuButton(app, node, view::leaveAudioSettings, "Zurück"); diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java index b23fc2c3..240a27a1 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/HostDialog.java @@ -9,6 +9,8 @@ import pp.mdga.client.button.MenuButton; import pp.mdga.client.view.MainView; +import java.util.prefs.Preferences; + public class HostDialog extends Dialog { private InputButton portInput; @@ -17,13 +19,15 @@ public class HostDialog extends Dialog { private final MainView view; + private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class); + public HostDialog(MdgaApp app, Node node, MainView view) { super(app, node); this.view = view; portInput = new InputButton(app, node, "Port: ", 5); - portInput.setString("11111"); + portInput.setString(prefs.get("hostPort", "11111")); hostButton = new ButtonRight(app, node, view::forward, "Spiel hosten", 10); backButton = new ButtonLeft(app, node, view::back, "Zurück", 10); @@ -53,10 +57,12 @@ public void update() { } public String getPort() { + prefs.put("hostPort", portInput.getString()); return portInput.getString(); } public void resetPort() { portInput.reset(); + prefs.put("hostPort", "11111"); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java index f03c4bc7..c2d48816 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/JoinDialog.java @@ -3,12 +3,15 @@ import com.jme3.math.Vector2f; import com.jme3.scene.Node; import pp.mdga.client.MdgaApp; +import pp.mdga.client.acoustic.AcousticHandler; import pp.mdga.client.button.ButtonLeft; import pp.mdga.client.button.ButtonRight; import pp.mdga.client.button.InputButton; import pp.mdga.client.button.MenuButton; import pp.mdga.client.view.MainView; +import java.util.prefs.Preferences; + public class JoinDialog extends Dialog { private InputButton ipInput; private InputButton portInput; @@ -18,6 +21,8 @@ public class JoinDialog extends Dialog { private final MainView view; + private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class); + public JoinDialog(MdgaApp app, Node node, MainView view) { super(app, node); @@ -25,7 +30,8 @@ public JoinDialog(MdgaApp app, Node node, MainView view) { ipInput = new InputButton(app, node, "Ip: ", 15); portInput = new InputButton(app, node, "Port: ", 5); - portInput.setString("11111"); + portInput.setString(prefs.get("joinPort", "11111")); + ipInput.setString(prefs.get("jostIp", "")); joinButton = new ButtonRight(app, node, view::forward, "Spiel beitreten", 10); backButton = new ButtonLeft(app, node, view::back, "Zurück", 10); @@ -61,18 +67,22 @@ public void update() { } public String getIpt() { + prefs.put("joinIp", ipInput.getString()); return ipInput.getString(); } public void resetIp() { ipInput.reset(); + prefs.put("joinIp", ""); } public String getPort() { + prefs.put("joinPort", portInput.getString()); return portInput.getString(); } public void resetPort() { portInput.reset(); + prefs.put("joinPort", "11111"); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/CeremonyView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/CeremonyView.java index 5c800265..70e98148 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/CeremonyView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/CeremonyView.java @@ -5,6 +5,7 @@ import com.jme3.scene.Geometry; import pp.mdga.client.MdgaApp; import pp.mdga.client.MdgaState; +import pp.mdga.client.acoustic.MdgaSound; import pp.mdga.client.button.ButtonLeft; import pp.mdga.client.button.ButtonRight; import pp.mdga.client.button.CeremonyButton; @@ -50,6 +51,8 @@ public void onEnter() { enterSub(SubState.AWARD_CEREMONY); rootNode.addLight(ambient); + + app.getAcousticHandler().playSound(MdgaSound.VICTORY); } @Override diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java index c5a6915a..0634ea8a 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/GameView.java @@ -14,6 +14,7 @@ import com.jme3.texture.Image; import com.jme3.texture.Texture2D; import pp.mdga.client.MdgaState; +import pp.mdga.client.acoustic.MdgaSound; import pp.mdga.client.board.BoardHandler; import pp.mdga.client.board.CameraHandler; import pp.mdga.client.MdgaApp; @@ -54,6 +55,8 @@ public void onEnter() { cheatButton.show(); app.getViewPort().addProcessor(fpp); + + app.getAcousticHandler().playSound(MdgaSound.START); } @Override diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/LobbyView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/LobbyView.java index 65a87d60..b97baf84 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/LobbyView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/LobbyView.java @@ -3,6 +3,7 @@ import com.jme3.asset.TextureKey; import com.jme3.light.AmbientLight; import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; import com.jme3.scene.Geometry; import com.jme3.scene.Spatial; @@ -49,11 +50,10 @@ public LobbyView(MdgaApp app) { @Override public void onEnter() { - //cam = new Camera(app.getCamera().getWidth(), app.getCamera().getHeight()); - //cam.setParallelProjection(true); - //float aspect = (float) app.getCamera().getWidth() / app.getCamera().getHeight(); - //float size = 1.65f; - //cam.setFrustum(-1000, 1000, -aspect * size, aspect * size, size, -size); + app.getCamera().setParallelProjection(true); + float aspect = (float) app.getCamera().getWidth() / app.getCamera().getHeight(); + float size = 1.65f; + app.getCamera().setFrustum(-1000, 1000, -aspect * size, aspect * size, size, -size); leaveButton.show(); readyButton.show(); @@ -77,6 +77,18 @@ public void onLeave() { cyberButton.hide(); rootNode.removeLight(ambient); + + app.getCamera().setParallelProjection(false); + + app.getCamera().setFrustumPerspective( + 45.0f, + (float) app.getCamera().getWidth() / app.getCamera().getHeight(), + 0.1f, + 1000.0f + ); + + app.getCamera().setLocation(new Vector3f(0, 0, 10)); + app.getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); } @Override diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java index 4fb81fdd..b1997409 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/view/MainView.java @@ -3,6 +3,7 @@ import com.jme3.scene.Geometry; import pp.mdga.client.MdgaApp; import pp.mdga.client.MdgaState; +import pp.mdga.client.acoustic.MdgaSound; import pp.mdga.client.button.ButtonRight; import pp.mdga.client.button.MenuButton; import pp.mdga.client.button.SettingsButton; @@ -99,7 +100,7 @@ private void tryHost() { if(port >= 1 && port <= 65535) { app.getModelSyncronizer().setName(startDialog.getName()); app.getModelSyncronizer().setHost(port); - //TODO: playSound + //app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT); return; } } catch (NumberFormatException e) { @@ -107,13 +108,44 @@ private void tryHost() { } hostDialog.resetPort(); - //TODO: playSound + app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT); } private void tryJoin() { - //TODO - app.getModelSyncronizer().setName(startDialog.getName()); - app.getModelSyncronizer().setJoin("127.0.0.1", 1); + int port = 0; + String ip = joinDialog.getIpt(); + String portText = hostDialog.getPort(); + + try { + // Validate the port + port = Integer.parseInt(portText); + if (port < 1 || port > 65535) { + throw new IllegalArgumentException("Invalid port"); + } + + // Validate the IP address + if (isValidIpAddress(ip)) { + app.getModelSyncronizer().setName(startDialog.getName()); + app.getModelSyncronizer().setJoin(ip, port); + return; + } + } catch (IllegalArgumentException e) { + // Invalid input, fall through to reset + } + + hostDialog.resetPort(); + joinDialog.resetIp(); + app.getAcousticHandler().playSound(MdgaSound.WRONG_INPUT); + } + + private boolean isValidIpAddress(String ip) { + String ipRegex = + "^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\." + + "(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\." + + "(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\." + + "(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$"; + + return ip != null && ip.matches(ipRegex); } private void enterSub(SubState state) { @@ -160,7 +192,7 @@ public void forward(boolean host) { case MAIN: if(host) { enterSub(SubState.HOST); - //TODO: playSound + //TODO playSound } else { enterSub(SubState.JOIN); //TODO: playSound diff --git a/Projekte/mdga/client/src/main/resources/Sounds/error_sound.ogg b/Projekte/mdga/client/src/main/resources/Sounds/error_sound.ogg new file mode 100644 index 00000000..8742f9fd Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Sounds/error_sound.ogg differ diff --git a/Projekte/mdga/client/src/main/resources/Sounds/gamestart.ogg b/Projekte/mdga/client/src/main/resources/Sounds/gamestart.ogg new file mode 100644 index 00000000..eb7453d3 Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Sounds/gamestart.ogg differ diff --git a/Projekte/mdga/client/src/main/resources/Sounds/menu_button.ogg b/Projekte/mdga/client/src/main/resources/Sounds/menu_button.ogg new file mode 100644 index 00000000..7cb34ff4 Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Sounds/menu_button.ogg differ diff --git a/Projekte/mdga/client/src/main/resources/Sounds/uiclick.ogg b/Projekte/mdga/client/src/main/resources/Sounds/uiclick.ogg new file mode 100644 index 00000000..50d5b470 Binary files /dev/null and b/Projekte/mdga/client/src/main/resources/Sounds/uiclick.ogg differ