diff --git a/Projekte/mdga/client/hs_err_pid112363.log b/Projekte/mdga/client/hs_err_pid112363.log new file mode 100644 index 00000000..7e7c369f --- /dev/null +++ b/Projekte/mdga/client/hs_err_pid112363.log @@ -0,0 +1,32 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# SIGSEGV (0xb) at pc=0x000076fb04e70b48, pid=112363, tid=112397 +# +# JRE version: OpenJDK Runtime Environment Temurin-20.0.2+9 (20.0.2+9) (build 20.0.2+9) +# Java VM: OpenJDK 64-Bit Server VM Temurin-20.0.2+9 (20.0.2+9, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64) +# Problematic frame: +# C [libLLVM.so.18.1+0x1070b48] llvm::EVT::isExtendedVector() const+0x8 +# +# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/cedric/ProgProjekt/Gruppe-01/Projekte/mdga/client/core.112363) +# +# If you would like to submit a bug report, please visit: +# https://github.com/adoptium/adoptium-support/issues +# The crash happened outside the Java Virtual Machine in native code. +# See problematic frame for where to report the bug. +# + +--------------- S U M M A R Y ------------ + +Command Line: -Ddebugger.agent.enable.coroutines=true -Djava.util.logging.config.file=logging.properties -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:37129 -javaagent:/usr/share/idea/plugins/java/lib/rt/debugger-agent.jar -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea pp.mdga.client.MdgaApp + +Host: AMD Ryzen 5 8640HS w/ Radeon 760M Graphics, 12 cores, 14G, Manjaro Linux +Time: Fri Nov 29 22:02:46 2024 CET elapsed time: 26.893420 seconds (0d 0h 0m 26s) + +--------------- T H R E A D --------------- + +Current thread (0x000076fbec5e6dd0): JavaThread "jME3 Main" [_thread_in_native, id=112397, stack(0x000076fbd00fe000,0x000076fbd01fe000)] + +Stack: [0x000076fbd00fe000,0x000076fbd01fe000], sp=0x000076fbd01f4ef8, free space=987k +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +C [libLLVM.so.18.1+0x1070b48] llvm::EVT::isExtendedVector() const+0x8 \ No newline at end of file diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Asset.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Asset.java index f96e5e40..4e73fda1 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Asset.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Asset.java @@ -3,11 +3,11 @@ public enum Asset { bigTent, cardStack, - cir, - heer, + cir("Models/cir/cir_newOrigin.obj"), + heer("Models/heer/heer_newOrigin.obj"), jet, - lw, - marine, + lw("Models/lw/lw_newOrigin.obj"), + marine("Models/marine/marine_newOrigin.obj"), node_home_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"), node_wait_blue("Models/node_home/node_home.j3o", "Models/node_home/node_home_blue_diff.png"), node_home_black("Models/node_home/node_home.j3o", "Models/node_home/node_home_black_diff.png"), @@ -27,9 +27,12 @@ public enum Asset { shield_ring("Models/shield_ring/shield_ring.obj", null), tree_small("Models/tree_small/tree_small.obj", "Models/tree_small/tree_small_diff.png"), tree_big("Models/tree_big/tree_big.obj", "Models/tree_big/tree_big_diff.png"), - turboCard, - swapCard, - shieldCard, + turboCard("Models/turboCard/turboCard.obj", "Models/turboCard/turboCard_diff.png"), + turboSymbol("Models/turboCard/turboSymbol.obj", "Models/turboCard/turboCard_diff.png"), + swapCard("Models/swapCard/swapCard.obj", "Models/swapCard/swapCard_diff.png"), + swapSymbol("Models/swapCard/swapSymbol.obj", "Models/swapCard/swapCard_diff.png"), + shieldCard("Models/shieldCard/shieldCard.obj", "Models/shieldCard/shieldCard_diff.png"), + shieldSymbol("Models/shieldCard/shieldSymbol.obj", "Models/shieldCard/shieldCard_diff.png"), dice("Models/dice/dice.obj", "Models/dice/dice_diff.jpeg") ; @@ -51,6 +54,13 @@ public enum Asset { this.size = 1f; } + Asset(String modelPath) { + String folderFileName = "./" + root + name() + "/" + name(); + this.modelPath = modelPath; + this.diffPath = folderFileName + "_diff.png";; + this.size = 1f; + } + Asset(float size) { String folderFileName = "./" + root + name() + "/" + name(); this.modelPath = folderFileName + ".j3o"; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java index dafebe30..895042a3 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/InputSynchronizer.java @@ -1,5 +1,6 @@ package pp.mdga.client; +import com.jme3.collision.CollisionResult; import com.jme3.collision.CollisionResults; import com.jme3.input.InputManager; import com.jme3.input.KeyInput; @@ -17,6 +18,7 @@ import pp.mdga.client.board.PieceControl; import pp.mdga.client.gui.CardControl; import pp.mdga.client.view.GameView; +import pp.mdga.game.Color; import pp.mdga.game.Piece; public class InputSynchronizer { @@ -41,6 +43,7 @@ public class InputSynchronizer { private void setupInput() { inputManager.addMapping("Settings", new KeyTrigger(KeyInput.KEY_ESCAPE)); + inputManager.addMapping("Forward", new KeyTrigger(KeyInput.KEY_RETURN)); inputManager.addMapping("RotateRightMouse", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT)); inputManager.addMapping("MouseLeft", new MouseAxisTrigger(MouseInput.AXIS_X, false)); // Left movement @@ -52,7 +55,7 @@ private void setupInput() { inputManager.addMapping("Click", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); - inputManager.addListener(actionListener, "Settings", "RotateRightMouse", "Click", "Test"); + inputManager.addListener(actionListener, "Settings", "Forward", "RotateRightMouse", "Click", "Test"); inputManager.addListener(analogListener, "MouseLeft", "MouseRight", "MouseScrollUp", "MouseScrollDown"); } @@ -64,25 +67,28 @@ public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("Settings") && isPressed) { app.getView().pressEscape(); } + if (name.equals("Forward") && isPressed) { + app.getView().pressForward(); + } if (name.equals("RotateRightMouse")) { rightMousePressed = isPressed; } if(name.equals("Click") && isPressed) { if (app.getView() instanceof GameView gameView) { - CardControl cardLayerSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class); + CardControl cardLayerSelect = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayerRootNode(), CardControl.class); OutlineControl boardSelect = checkHover(app.getCamera(), app.getRootNode(), OutlineControl.class); if(cardLayerSelect != null) { //cardSelect - cardLayerSelect.outline(); + if(cardLayerSelect.isSelectable()) gameView.getGuiHandler().selectCard(cardLayerSelect); } - if(cardLayerSelect == null && boardSelect != null) { + else if(boardSelect != null) { //boardSelect if(boardSelect instanceof PieceControl pieceControl){ if(pieceControl.isSelectable()) gameView.getBoardHandler().pieceSelect(pieceControl); } if(boardSelect instanceof NodeControl nodeControl){ -// nodeControl.outline(); +// } } else { @@ -93,7 +99,8 @@ public void onAction(String name, boolean isPressed, float tpf) { } if(name.equals("Test") &&isPressed){ - test = true; + if(app.getView() instanceof GameView gameView){ + } } } }; @@ -115,6 +122,7 @@ else if (name.equals("MouseScrollDown")) { } else if (name.equals("MouseLeft") || name.equals("MouseRight") || name.equals("MouseVertical")){ hoverPiece(); + hoverCard(); } } }; @@ -123,8 +131,23 @@ private T checkHover(Camera cam, Node root, Class CollisionResults results = new CollisionResults(); Ray ray = new Ray(cam.getLocation(), getMousePos(cam).subtract(cam.getLocation()).normalize()); root.collideWith(ray, results); + for(CollisionResult collisionResult : results){ + if(collisionResult.getGeometry().getControl(controlType) != null) return collisionResult.getGeometry().getControl(controlType); + } + return null; + } + + private T checkHoverOrtho(Camera cam, Node root, Class controlType) { + CollisionResults results = new CollisionResults(); + Vector3f mousePos = getMousePos(cam); + mousePos.setZ(cam.getLocation().getZ()); + Ray ray = new Ray(mousePos, getMousePos(cam).subtract(mousePos).normalize()); + root.collideWith(ray, results); if (results.size() > 0) { - return results.getClosestCollision().getGeometry().getControl(controlType); + for(CollisionResult res : results ){ + T control = res.getGeometry().getControl(controlType); + if(control != null) return control; + } } return null; } @@ -143,33 +166,26 @@ private void hoverPiece() { } } - private void hoverCardOutline() { + private void hoverCard() { if (app.getView() instanceof GameView gameView) { - CardControl control = checkHover(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayer().getRootNode(), CardControl.class); + CardControl control = checkCard(gameView); if (control != null) { if(control != hoverCard){ - pieceOff(); + cardOff(); hoverCard = control; - hoverCard.outline(); + hoverCard.hover(); } } - else pieceOff(); + else cardOff(); } } - private void hoverAction(){ - - } - private PieceControl checkPiece(){ return checkHover(app.getCamera(), app.getRootNode(), PieceControl.class); } - - - private void outlineOff(OutlineControl outline) { - if (outline != null) outline.deOutline(); - outline = null; + private CardControl checkCard(GameView gameView){ + return checkHoverOrtho(gameView.getGuiHandler().getCardLayerCamera(), gameView.getGuiHandler().getCardLayerRootNode(), CardControl.class); } private void pieceOff(){ @@ -177,9 +193,16 @@ private void pieceOff(){ hoverPiece = null; } + private void cardOff(){ + if(hoverCard != null) hoverCard.hoverOff(); + hoverCard = null; + } + private Vector3f getMousePos(Camera cam){ Vector2f mousePositionScreen = inputManager.getCursorPosition(); - return cam.getWorldCoordinates(mousePositionScreen, 0); + Vector3f world = cam.getWorldCoordinates(mousePositionScreen, 0); + if (cam.isParallelProjection()) world.setZ(0); + return world; } public float getRotation() { 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 f354f693..8c3cd992 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; @@ -22,21 +15,21 @@ public class MdgaApp extends SimpleApplication { private ModelSyncronizer modelSyncronizer; MdgaView view = null; - private MdgaState state = MdgaState.GAME; + private MdgaState state = null; - private static float resolutionFactor = 1.8f; + private static float imageScale = 1.5f; + + private MdgaView mainView; + private MdgaView lobbyView; + private MdgaView gameView; + private MdgaView ceremonyView; public static void main(String[] args) { AppSettings settings = new AppSettings(true); settings.setSamples(128); settings.setCenterWindow(true); - - int width = (int)(1280 * resolutionFactor); - int height = (int)(720 * resolutionFactor); - - settings.setWidth(width); - settings.setHeight(height); - + settings.setWidth(1920); + settings.setHeight(1080); settings.setVSync(false); MdgaApp app = new MdgaApp(); @@ -47,52 +40,29 @@ public static void main(String[] args) { @Override public void simpleInitApp() { + GuiGlobals.initialize(this); + + inputManager.deleteMapping("SIMPLEAPP_Exit"); + + flyCam.setEnabled(false); + animationHandler = new AnimationHandler(this); acousticHandler = new AcousticHandler(this); notificationSynchronizer = new NotificationSynchronizer(this); inputSynchronizer = new InputSynchronizer(this); modelSyncronizer = new ModelSyncronizer(this); - inputManager.deleteMapping("SIMPLEAPP_Exit"); - inputManager.deleteMapping("FLYCAM_ZoomIn"); - inputManager.deleteMapping("FLYCAM_ZoomOut"); - inputManager.deleteMapping("FLYCAM_RotateDrag"); - flyCam.setEnabled(false); - GuiGlobals.initialize(this); + mainView = new MainView(this); + lobbyView = new LobbyView(this); + gameView = new GameView(this); + ceremonyView = new CeremonyView(this); - enter(state); - - List test = new ArrayList<>(); - UUID player0 = UUID.randomUUID(); - test.add(player0); - UUID player1 = UUID.randomUUID(); - test.add(player1); - test.add(UUID.randomUUID()); - test.add(UUID.randomUUID()); - - List test_1 = new ArrayList<>(); - UUID player0_1 = UUID.randomUUID(); - test_1.add(player0_1); - UUID player1_1 = UUID.randomUUID(); - test_1.add(player1_1); - test_1.add(UUID.randomUUID()); - test_1.add(UUID.randomUUID()); - - notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.AIRFORCE, test, "Player 1")); - notificationSynchronizer.addTestNotification(new PlayerInGameNotification(Color.NAVY, test_1, "Player 2")); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, true)); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, true)); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player0_1, 20, 21)); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player1, 0, true)); - notificationSynchronizer.addTestNotification(new MovePieceNotification(player0, 0, 7)); -// notificationSynchronizer.addTestNotification(new SelectableMoveNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(7,3)), new ArrayList<>(List.of(false, false)))); - notificationSynchronizer.addTestNotification(new SwapPieceNotification(player0, player0_1)); -// notificationSynchronizer.addTestNotification(new SelectableSwapNotification(new ArrayList<>(List.of(player0, player1)), new ArrayList<>(List.of(player0_1)))); + enter(MdgaState.MAIN); } @Override public void simpleUpdate(float tpf) { - view.update(); + view.update(tpf); acousticHandler.update(); notificationSynchronizer.update(); } @@ -106,16 +76,16 @@ public void enter(MdgaState state) { switch (state) { case MAIN: - view = new MainView(this); + view = mainView; break; case LOBBY: - view = new LobbyView(this); + view = lobbyView; break; case GAME: - view = new GameView(this); + view = gameView; break; case CEREMONY: - view = new CeremonyView(this); + view = ceremonyView; break; case NONE: throw new RuntimeException("cant enter state NONE"); @@ -126,10 +96,6 @@ public void enter(MdgaState state) { view.enter(); } - public void afteGameCleanup() { - //TODO - } - public AnimationHandler getAnimationHandler() { return animationHandler; } @@ -140,8 +106,8 @@ public AcousticHandler getAcousticHandler() { public MdgaState getState() {return state; } - public float getResolutionFactor() { - return resolutionFactor; + public float getImageScale() { + return imageScale; } public MdgaView getView() { @@ -153,4 +119,6 @@ public ModelSyncronizer getModelSyncronizer() { } public InputSynchronizer getInputSyncronizer() { return inputSynchronizer; } + + public NotificationSynchronizer getNotificationSynchronizer() { return notificationSynchronizer; } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSynchronizer.java new file mode 100644 index 00000000..8d2c08ab --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSynchronizer.java @@ -0,0 +1,123 @@ +package pp.mdga.client; + +import pp.mdga.client.view.CeremonyView; +import pp.mdga.client.view.GameView; +import pp.mdga.client.view.LobbyView; +import pp.mdga.game.BonusCard; +import pp.mdga.game.Color; +import pp.mdga.notification.AcquireCardNotification; +import pp.mdga.notification.DrawCardNotification; +import pp.mdga.notification.TskSelectNotification; + +import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class ModelSynchronizer { + private static final Logger LOGGER = Logger.getLogger(ModelSynchronizer.class.getName()); + private MdgaApp app; + + ModelSynchronizer(MdgaApp app) { + this.app = app; + } + + public void animationEnd() { + + } + + public void selectSwap(UUID a, UUID b) { + // TODO call from somewhere + LOGGER.log(Level.INFO, "selectPiece"); + } + + public void selectPiece(UUID piece) { + // TODO call from somewhere + LOGGER.log(Level.INFO, "selectPiece"); + } + + public void selectCard(BonusCard card) { + // TODO call from somewhere + LOGGER.log(Level.INFO, "selectCard"); + } + + public void confirm() { + LOGGER.log(Level.INFO, "confirm"); + } + + public void selectTsk(Color color) { + // TODO call from somewhere + LOGGER.log(Level.INFO, "selectTsk: {0}", color); + LobbyView view = (LobbyView) app.getView(); + view.setTaken(color, true, true, "OwnPlayerName"); + } + + public void unselectTsk() { + // TODO call from somewhere + LOGGER.log(Level.INFO, "unselectTsk"); + } + + public void rolledDice() { + // TODO call from somewhere + LOGGER.log(Level.INFO, "rolledDice"); + } + + public void setName(String name) { + // TODO call from somewhere + LOGGER.log(Level.INFO, "setName: {0}", name); + } + + public void setReady() { + LOGGER.log(Level.INFO, "setReady"); + enter(MdgaState.GAME); + } + + public void setHost(int port) { + // TODO call from somewhere + LOGGER.log(Level.INFO, "setHost: {0}", port); + enter(MdgaState.LOBBY); + } + + public void setJoin(String ip, int port) { + // TODO call from somewhere + LOGGER.log(Level.INFO, "setJoin with IP: {0}, Port: {1}", new Object[]{ip, port}); + enter(MdgaState.LOBBY); + } + + public void leave() { + LOGGER.log(Level.INFO, "leave"); + enter(MdgaState.MAIN); + } + + public void enter(MdgaState state) { + LOGGER.log(Level.INFO, "enter: {0}", state); + app.enter(state); + + if (state == MdgaState.CEREMONY) { + CeremonyView ceremonyView = (CeremonyView) app.getView(); + ceremonyView.addCeremonyParticipant(Color.AIRFORCE, 1, "ugidffdg"); + ceremonyView.addCeremonyParticipant(Color.ARMY, 2, "ugidffdg"); + ceremonyView.addCeremonyParticipant(Color.NAVY, 3, "ugidffdg"); + ceremonyView.addCeremonyParticipant(Color.CYBER, 4, "ugidffdg"); + + ceremonyView.addStatisticsRow("player sdgsd", 1, 2, 3, 4, 5, 6); + ceremonyView.addStatisticsRow("player sdgsd", 1, 2, 3, 4, 5, 6); + ceremonyView.addStatisticsRow("player sdgsd", 1, 2, 3, 4, 5, 6); + ceremonyView.addStatisticsRow("player sdgsd", 1, 2, 3, 4, 5, 6); + ceremonyView.addStatisticsRow("Gesamt", 1, 2, 3, 4, 5, 6); + } + + if (state == MdgaState.GAME) { + GameView gameView = (GameView) app.getView(); + + app.getNotificationSynchronizer().addTestNotification(new DrawCardNotification(Color.AIRFORCE, BonusCard.SHIELD)); + } + + if (state == MdgaState.LOBBY) { + LobbyView lobbyView = (LobbyView) app.getView(); + + app.getNotificationSynchronizer().addTestNotification(new TskSelectNotification(Color.CYBER, "blablabupp", false)); + app.getNotificationSynchronizer().addTestNotification(new TskSelectNotification(Color.ARMY, "Spieler 2", false)); + lobbyView.setReady(Color.ARMY, true); + } + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSyncronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSyncronizer.java deleted file mode 100644 index fae79021..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/ModelSyncronizer.java +++ /dev/null @@ -1,72 +0,0 @@ -package pp.mdga.client; - -import pp.mdga.client.view.LobbyView; -import pp.mdga.game.Color; - -public class ModelSyncronizer { - private MdgaApp app; - - ModelSyncronizer(MdgaApp app) { - this.app = app; - } - - public void selectPiece() { - //TODO call from somewhere - System.out.println("selectPiece"); - } - - public void selectCard() { - //TODO call from somewhere - System.out.println("selectCard"); - } - - public void selectTsk(Color color) { - //TODO call from somewhere - System.out.println("selectTsk: " + color); - LobbyView view = (LobbyView) app.getView(); - view.setTaken(color, true, true, "OwnPlayerName"); - } - - public void unselectTsk() { - //TODO call from somewhere - System.out.println("unselectTsk"); - } - - public void rolledDice() { - //TODO call from somewhere - System.out.println("rolledDice"); - } - - public void setName(String name) { - //TODO call from somewhere - System.out.println("setName:" + name); - } - - public void setReady() { - //TODO call from somewhere - System.out.println("setReady"); - app.enter(MdgaState.GAME); - } - - public void setHost(int port) { - //TODO call from somewhere - System.out.println("setHost: " + port); - app.enter(MdgaState.LOBBY); - } - - public void setJoin(String ip, int port) { - //TODO call from somewhere - System.out.println("setJoin"); - app.enter(MdgaState.LOBBY); - } - - public void leave() { - System.out.println("leave"); - app.enter(MdgaState.MAIN); - } - - public void enter(MdgaState state) { - System.out.println("enter:" + state); - app.enter(state); - } -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java index b35d1471..7c8a8bb9 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java @@ -1,7 +1,11 @@ package pp.mdga.client; +import pp.mdga.client.board.BoardHandler; +import pp.mdga.client.gui.GuiHandler; +import pp.mdga.client.view.CeremonyView; import pp.mdga.client.view.GameView; import pp.mdga.client.view.LobbyView; +import pp.mdga.game.Color; import pp.mdga.notification.*; import java.util.ArrayList; @@ -53,12 +57,12 @@ private void handleMain(Notification notification) { private void handleLobby(Notification notification) { LobbyView lobbyView = (LobbyView) app.getView(); - if (notification instanceof TskSelectNotification) { - TskSelectNotification n = (TskSelectNotification)notification; + if (notification instanceof TskSelectNotification n) { lobbyView.setTaken(n.getColor(), true, n.isSelf(), n.getName()); - } else if (notification instanceof TskUnselectNotification) { - TskUnselectNotification n = (TskUnselectNotification)notification; + } else if (notification instanceof TskUnselectNotification n) { lobbyView.setTaken(n.getColor(), false, false, null); + //} else if(notification instanceof LobbyReadyNotification lobbyReadyNotification) { + // lobbyView.setReady(lobbyReadyNotification.getColor(), lobbyReadyNotification.isReady()): } else if (notification instanceof GameNotification) { app.enter(MdgaState.GAME); } else { @@ -68,6 +72,8 @@ private void handleLobby(Notification notification) { private void handleGame(Notification notification) { GameView gameView = (GameView) app.getView(); + GuiHandler guiHandler = gameView.getGuiHandler(); + BoardHandler boardHandler = gameView.getBoardHandler(); if (notification instanceof AcquireCardNotification) { // Handle AcquireCardNotification @@ -75,56 +81,96 @@ private void handleGame(Notification notification) { gameView.getGuiHandler().setActivePlayer(n.getColor()); } else if (notification instanceof CeremonyNotification) { app.enter(MdgaState.CEREMONY); + CeremonyView ceremonyView = (CeremonyView) app.getView(); + int size = n.getNames().size(); + + if (n.getPiecesThrown().size() != size || + n.getPiecesLost().size() != size || + n.getBonusCardsPlayed().size() != size || + n.getSixes().size() != size || + n.getNodesMoved().size() != size || + n.getBonusNodes().size() != size) { + throw new IllegalArgumentException("All data lists in CeremonyNotification must have the same size."); + } + + for (int i = 0; i < size; i++) { + Color color = n.getColors().get(i); + String name = n.getNames().get(i); + int v1 = n.getPiecesThrown().get(i); + int v2 = n.getPiecesLost().get(i); + int v3 = n.getBonusCardsPlayed().get(i); + int v4 = n.getSixes().get(i); + int v5 = n.getNodesMoved().get(i); + int v6 = n.getBonusNodes().get(i); + + ceremonyView.addCeremonyParticipant(color, i, name); + ceremonyView.addStatisticsRow(name, v1, v2, v3, v4, v5, v6); + } } else if (notification instanceof DiceNowNotification) { - // Handle DiceNowNotification - } else if (notification instanceof DicingNotification) { - // Handle DicingNotification - } else if (notification instanceof DrawCardNotification) { - // Handle DrawCardNotification + guiHandler.showDice(); + } else if (notification instanceof DicingNotification n) { + //TODO ??? + } else if (notification instanceof DrawCardNotification n) { + guiHandler.drawCard(n.getColor()); } else if (notification instanceof HomeMoveNotification home) { - gameView.getBoardHandler().moveHomePiece(home.getPieceId(), home.getHomeIndex()); + boardHandler.moveHomePiece(home.getPieceId(), home.getHomeIndex()); + guiHandler.hideText(); } else if (notification instanceof InterruptNotification) { - // Handle InterruptNotification + //TODO ??? } else if (notification instanceof MovePieceNotification n) { if(n.isMoveStart()) { //StartMove - gameView.getBoardHandler().movePieceStart(n.getPiece(), n.getMoveIndex()); + boardHandler.movePieceStart(n.getPiece(), n.getMoveIndex()); } else { //InfieldMove - gameView.getBoardHandler().movePiece(n.getPiece(), n.getStartIndex(), n.getMoveIndex()); + boardHandler.movePiece(n.getPiece(), n.getStartIndex(), n.getMoveIndex()); + } + } else if (notification instanceof ThrowPieceNotification n) { + boardHandler.throwPiece(n.getPieceId()); + } else if (notification instanceof NoShieldNotification n) { + boardHandler.unshieldPiece(n.getPieceId()); + } else if (notification instanceof PlayCardNotification n) { + switch(n.getCard()){ + case SWAP -> guiHandler.swap(); + case TURBO -> guiHandler.turbo(); + case SHIELD -> guiHandler.shield(); + default -> throw new RuntimeException("invalid card"); } - } else if (notification instanceof NoShieldNotification) { - NoShieldNotification n = (NoShieldNotification)notification; - gameView.getBoardHandler().unshieldPiece(n.getPieceId()); - } else if (notification instanceof PlayCardNotification) { - // Handle PlayCardNotification } else if (notification instanceof PlayerInGameNotification n) { - // Handle PlayerInGameNotification - gameView.getBoardHandler().addPlayer(n.getColor(),n.getPiecesList()); - gameView.getGuiHandler().addPlayer(n.getColor(),n.getName()); + boardHandler.addPlayer(n.getColor(),n.getPiecesList()); + guiHandler.addPlayer(n.getColor(),n.getName()); } else if (notification instanceof ResumeNotification) { - // Handle ResumeNotification - } else if (notification instanceof RollDiceNotification) { - // Handle RollDiceNotification - } else if (notification instanceof SelectableCardsNotification) { - // Handle SelectableCardsNotification - } else if (notification instanceof ShieldActiveNotification) { - ShieldActiveNotification n = (ShieldActiveNotification)notification; - gameView.getBoardHandler().shieldPiece(n.getPieceId()); - } else if (notification instanceof ShieldSuppressedNotification) { - ShieldSuppressedNotification n = (ShieldSuppressedNotification)notification; - gameView.getBoardHandler().suppressShield(n.getPieceId()); + //TODO + } else if (notification instanceof RollDiceNotification n) { + if(n.getColor() == gameView.getOwnColor()){ + guiHandler.rollDice(n.getEyes(), n.isTurbo() ? n.getMultiplier() : -1); + } + else { + if (n.isTurbo()) guiHandler.showRolledDiceMult(n.getEyes(), n.getMultiplier(), n.getColor()); + else guiHandler.showRolledDice(n.getEyes(), n.getColor()); + } + } else if (notification instanceof SelectableCardsNotification n) { + guiHandler.setSelectableCards(n.getCards()); + } else if (notification instanceof ShieldActiveNotification n) { + boardHandler.shieldPiece(n.getPieceId()); + } else if (notification instanceof ShieldSuppressedNotification n) { + boardHandler.suppressShield(n.getPieceId()); } else if (notification instanceof StartDialogNotification) { app.enter(MdgaState.MAIN); } else if (notification instanceof SwapPieceNotification n) { - gameView.getBoardHandler().swapPieces(n.getFirstPiece(), n.getSecondPiece()); + boardHandler.swapPieces(n.getFirstPiece(), n.getSecondPiece()); + guiHandler.swap(); } else if (notification instanceof WaitMoveNotification) { - // Handle WaitMoveNotification + //TODO ??? } else if (notification instanceof SelectableMoveNotification n) { - gameView.getBoardHandler().outlineMove(n.getPieces(), n.getMoveIndexe(), n.getHomeMoves()); + boardHandler.outlineMove(n.getPieces(), n.getMoveIndexe(), n.getHomeMoves()); } else if (notification instanceof SelectableSwapNotification n) { - gameView.getBoardHandler().outlineSwap(n.getOwnPieces(), n.getEnemyPieces()); + boardHandler.outlineSwap(n.getOwnPieces(), n.getEnemyPieces()); + } else if (notification instanceof SelectableShieldNotification n) { + boardHandler.outlineShield(n.getOwnPieces()); + } else if (notification instanceof TurboActiveNotification){ + guiHandler.turbo(); } else { throw new RuntimeException("notification not expected: " + notification.toString()); } 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 08979182..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; @@ -23,14 +24,20 @@ public class AcousticHandler { private GameMusic scheduled = null; // Scheduled track to play next private GameMusic old = null; // Old track being faded out - private float mainVolume = 1.0f; + private float mainVolume = 0.0f; private float musicVolume = 1.0f; private float soundVolume = 1.0f; 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/board/BoardHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/BoardHandler.java index bd6f3e6e..cd26a2d2 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/BoardHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/BoardHandler.java @@ -9,6 +9,7 @@ import com.jme3.scene.control.AbstractControl; import pp.mdga.client.Asset; import pp.mdga.client.MdgaApp; +import pp.mdga.client.gui.DiceControl; import pp.mdga.game.Color; import java.util.*; @@ -20,9 +21,6 @@ public class BoardHandler { private final MdgaApp app; - private final PileControl drawPile = null; - private final PileControl discardPile = null; - private ArrayList infield; private Map pieces; @@ -31,7 +29,6 @@ public class BoardHandler { private Map> waitingNodesMap; private Map> waitingPiecesMap; private Map pieceColor; - private Set outlineControls; private Node node; @@ -39,23 +36,39 @@ public class BoardHandler { private boolean isInitialised; - private boolean scheduleInit = false; - private boolean scheduleShutdown = false; - - private List selectableOwnPieces = new ArrayList<>(); - private List selectableEnemyPieces = new ArrayList<>(); + private List selectableOwnPieces; + private List selectableEnemyPieces; + private List outlineNodes; private PieceControl selectedOwnPiece; private PieceControl selectedEnemyPiece; + private DiceControl diceControl; public BoardHandler(MdgaApp app, FilterPostProcessor fpp) { if(app == null) throw new RuntimeException("app is null"); - this.isInitialised = false; this.app = app; this.fpp = fpp; - selectedEnemyPiece = null; + isInitialised = false; + + node = new Node("BoardHandler root node"); + } + + public void init() { + isInitialised = true; + selectableOwnPieces = new ArrayList<>(); + selectableEnemyPieces = new ArrayList<>(); + outlineNodes = new ArrayList<>(); selectedOwnPiece = null; + selectedEnemyPiece = null; initMap(); + app.getRootNode().attachChild(node); + } + + public void shutdown(){ + clearSelectable(); + isInitialised = false; + initMap(); + app.getRootNode().detachChild(node); } private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) { @@ -64,22 +77,15 @@ private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) { } private void initMap() { - if (isInitialised) return; - - this.isInitialised = true; - this.node = new Node("Asset Node"); - - this.pieces = new HashMap<>(); - this.colorAssetsMap = new HashMap<>(); - this.infield = new ArrayList<>(40); - this.homeNodesMap = new HashMap<>(); - this.waitingNodesMap = new HashMap<>(); - this.waitingPiecesMap = new HashMap<>(); - this.pieceColor = new HashMap<>(); - this.outlineControls = new HashSet<>(); - - - + pieces = new HashMap<>(); + colorAssetsMap = new HashMap<>(); + infield = new ArrayList<>(40); + homeNodesMap = new HashMap<>(); + waitingNodesMap = new HashMap<>(); + waitingPiecesMap = new HashMap<>(); + pieceColor = new HashMap<>(); + diceControl = new DiceControl(app.getAssetManager()); + diceControl.create(new Vector3f(0,0,0), 0.7f, true); List assetOnMaps = MapLoader.loadMap(MAP_NAME); @@ -164,7 +170,7 @@ private float getRotationMove(Vector3f prev, Vector3f next) { return newRot; } - private void movePiece_rek(UUID uuid, int curIndex, int moveIndex){ + private void movePieceRek(UUID uuid, int curIndex, int moveIndex){ if (curIndex == moveIndex) return; curIndex = (curIndex + 1) % infield.size(); @@ -176,7 +182,7 @@ private void movePiece_rek(UUID uuid, int curIndex, int moveIndex){ movePieceToNode(pieceControl, nodeControl); - movePiece_rek(uuid, curIndex, moveIndex); + movePieceRek(uuid, curIndex, moveIndex); } private List addItemToMapList(Map> map, E key, T item){ @@ -186,11 +192,24 @@ private List addItemToMapList(Map> map, E key, T item){ return list; } - private List removeItemFromMapList(Map> map, E key, T item){ + private void removeItemFromMapList(Map> map, E key, T item){ List list = map.getOrDefault(key, new ArrayList<>()); list.remove(item); map.put(key, list); - return list; + } + + private Vector3f getWaitingPos(Color color){ + return getMeanPosition(waitingNodesMap.get(color).stream().map(NodeControl::getLocation).toList()); + } + + public static Vector3f getMeanPosition(List vectors) { + if (vectors.isEmpty()) return new Vector3f(0, 0, 0); + + Vector3f sum = new Vector3f(0, 0, 0); + for (Vector3f v : vectors) { + sum.addLocal(v); + } + return sum.divide(vectors.size()); } //public methods**************************************************************************************************** @@ -255,7 +274,7 @@ public void movePieceStart(UUID uuid, int nodeIndex){ public void movePiece(UUID uuid, int curIndex, int moveIndex){ if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); - movePiece_rek(uuid, curIndex, moveIndex); + movePieceRek(uuid, curIndex, moveIndex); } public void throwPiece(UUID uuid){ @@ -294,47 +313,25 @@ public void suppressShield(UUID uuid){ public void swapPieces(UUID piece1, UUID piece2){ if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); - PieceControl piece1_control = pieces.get(piece1); - PieceControl piece2_control = pieces.get(piece2); + PieceControl piece1Control = pieces.get(piece1); + PieceControl piece2Control = pieces.get(piece2); - if(piece1_control == null) throw new RuntimeException("piece1 UUID is not valid"); - if(piece2_control == null) throw new RuntimeException("piece2 UUID is not valid"); + if(piece1Control == null) throw new RuntimeException("piece1 UUID is not valid"); + if(piece2Control == null) throw new RuntimeException("piece2 UUID is not valid"); - float rot1 = piece1_control.getRotation(); - float rot2 = piece2_control.getRotation(); + float rot1 = piece1Control.getRotation(); + float rot2 = piece2Control.getRotation(); - piece1_control.setRotation(rot2); - piece2_control.setRotation(rot1); + piece1Control.setRotation(rot2); + piece2Control.setRotation(rot1); - Vector3f pos1 = piece1_control.getLocation().clone(); - Vector3f pos2 = piece2_control.getLocation().clone(); + Vector3f pos1 = piece1Control.getLocation().clone(); + Vector3f pos2 = piece2Control.getLocation().clone(); - piece1_control.setLocation(pos2); - piece2_control.setLocation(pos1); + piece1Control.setLocation(pos2); + piece2Control.setLocation(pos1); } - public void init() { -// outlineControls.forEach((outlineControl) -> { -// outlineControl.outline(outlineControl.getColor()); -// }); - - isInitialised = true; - scheduleInit = false; - app.getRootNode().attachChild(node); - } - - public void shutdown(){ - outlineControls.forEach((outlineControl) -> { - outlineControl.deOutline(); - }); - - isInitialised = false; - scheduleShutdown = false; - app.getRootNode().detachChild(node); - } - - //List - //List public void highlight(UUID uuid, boolean bool){ if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); @@ -343,23 +340,6 @@ public void highlight(UUID uuid, boolean bool){ } - public void deOutline(UUID uuid){ - if (!isInitialised) throw new RuntimeException("BoardHandler is not initialized"); - - pieces.get(uuid).deOutline(); - - outlineControls.remove(pieces.get(uuid)); - } - - public void outline(int index){ -// infield.get(index).outline(); - - outlineControls.add(infield.get(index)); - } - - - - //called when (dice) moveNum is received from server to display the movable pieces and corresponding moveNodes public void outlineMove(List pieces, List moveIndexe, List homeMoves) { if(pieces.size() != moveIndexe.size() || pieces.size() != homeMoves.size()) throw new RuntimeException("arrays are not the same size"); @@ -385,6 +365,7 @@ public void outlineMove(List pieces, List moveIndexe, List ownPieces, List enemyPieces){ } } + public void outlineShield(List pieces){ + selectableOwnPieces.clear(); + selectableEnemyPieces.clear(); + selectedOwnPiece = null; + selectedEnemyPiece = null; + + for (UUID uuid : pieces){ + PieceControl p = this.pieces.get(uuid); + p.highlight(false); + p.setHoverable(true); + p.setSelectable(true); + selectableOwnPieces.add(p); + } + } + //called from inputSynchronizer when a piece is selectable public void pieceSelect(PieceControl pieceSelected) { boolean isSelected = pieceSelected.isSelected(); @@ -449,29 +445,37 @@ else if(selectableEnemyPieces.contains(pieceSelected)) { public void clearSelectable(){ for(PieceControl p : selectableEnemyPieces) { p.unSelect(); + p.unHighlight(); p.setSelectable(false); } for(PieceControl p : selectableOwnPieces) { p.unSelect(); + p.unHighlight(); p.setSelectable(false); } + for(NodeControl n : outlineNodes){ + n.deOutline(); + } + outlineNodes.clear(); selectableEnemyPieces.clear(); selectableOwnPieces.clear(); selectedEnemyPiece = null; selectedOwnPiece = null; } - - - public void deOutline(int index){ - infield.get(index).deOutline(); - - outlineControls.remove(infield.get(index)); - } - public void enableHover(UUID uuid){ pieces.get(uuid).setHoverable(true); } + public void showDice(Color color){ + node.attachChild(diceControl.getSpatial()); + diceControl.setPos(getWaitingPos(color).add(new Vector3f(0,0,4))); + diceControl.spin(); + } + + public void hideDice(){ + diceControl.hide(); + } + } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/CameraHandler.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/CameraHandler.java index 76898d6d..a1c6b8d6 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/CameraHandler.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/CameraHandler.java @@ -4,9 +4,14 @@ import com.jme3.light.DirectionalLight; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; +import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.post.FilterPostProcessor; +import com.jme3.scene.Spatial; import com.jme3.shadow.DirectionalLightShadowFilter; +import com.jme3.shadow.EdgeFilteringMode; +import com.jme3.util.SkyFactory; +import com.jme3.util.SkyFactory.EnvMapType; import pp.mdga.client.MdgaApp; public class CameraHandler { @@ -17,8 +22,21 @@ public class CameraHandler { private static final int SHADOWMAP_SIZE = 1024 * 8; - public CameraHandler(MdgaApp app, FilterPostProcessor fpp){ + private Vector3f defaultCameraPosition; + private Quaternion defaultCameraRotation; + + FilterPostProcessor fpp; + DirectionalLightShadowFilter dlsf; + + Spatial sky; + + public CameraHandler(MdgaApp app, FilterPostProcessor fpp) { this.app = app; + this.fpp = fpp; + + // Save the default camera state + this.defaultCameraPosition = app.getCamera().getLocation().clone(); + this.defaultCameraRotation = app.getCamera().getRotation().clone(); sun = new DirectionalLight(); sun.setColor(ColorRGBA.White); @@ -27,19 +45,35 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp){ ambient = new AmbientLight(); ambient.setColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1)); - DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(app.getAssetManager(), SHADOWMAP_SIZE, 4); + dlsf = new DirectionalLightShadowFilter(app.getAssetManager(), SHADOWMAP_SIZE, 4); dlsf.setLight(sun); + dlsf.setEnabled(true); + dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON); + dlsf.setShadowIntensity(0.7f); fpp.addFilter(dlsf); + + sky = SkyFactory.createSky(app.getAssetManager(), "Images/sky/sky.dds", EnvMapType.EquirectMap).rotate(FastMath.HALF_PI*1,0,FastMath.HALF_PI*0.2f); + + } public void init() { app.getRootNode().addLight(sun); app.getRootNode().addLight(ambient); + app.getRootNode().attachChild(sky); + fpp.addFilter(dlsf); } public void shutdown() { app.getRootNode().removeLight(sun); app.getRootNode().removeLight(ambient); + app.getRootNode().detachChild(sky); + + // Reset the camera to its default state + app.getCamera().setLocation(defaultCameraPosition); + app.getCamera().setRotation(defaultCameraRotation); + + fpp.removeFilter(dlsf); } public void update(float scroll, float rotation) { diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java index c01df106..385d1007 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/OutlineControl.java @@ -5,6 +5,7 @@ import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; import com.jme3.renderer.ViewPort; +import com.jme3.scene.Spatial; import com.jme3.scene.control.AbstractControl; import pp.mdga.client.MdgaApp; import pp.mdga.client.board.Outline.SelectObjectOutliner; @@ -12,17 +13,21 @@ public class OutlineControl extends AbstractControl { private static final int THICKNESS_DEFAULT = 6; private final SelectObjectOutliner outlineOwn; + private MdgaApp app; public OutlineControl(MdgaApp app, FilterPostProcessor fpp){ + this.app = app; outlineOwn = new SelectObjectOutliner(THICKNESS_DEFAULT, fpp, app.getRenderManager(), app.getAssetManager(), app.getCamera()); } public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam){ + this.app = app; outlineOwn = new SelectObjectOutliner(THICKNESS_DEFAULT, fpp, app.getRenderManager(), app.getAssetManager(), cam); } public OutlineControl(MdgaApp app, FilterPostProcessor fpp, Camera cam, int thickness){ + this.app = app; outlineOwn = new SelectObjectOutliner(thickness, fpp, app.getRenderManager(), app.getAssetManager(), cam); } @@ -48,4 +53,23 @@ protected void controlUpdate(float tpf) { protected void controlRender(RenderManager rm, ViewPort vp) { } + + public void initSpatial(){ + + } + + @Override + public void setSpatial(Spatial spatial){ + if(this.spatial == null && spatial != null){ + super.setSpatial(spatial); + initSpatial(); + } + else{ + super.setSpatial(spatial); + } + } + + public MdgaApp getApp() { + return app; + } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/PieceControl.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/PieceControl.java index a82c359d..7cb5a6ec 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/board/PieceControl.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/board/PieceControl.java @@ -32,9 +32,9 @@ public class PieceControl extends OutlineControl { private static final ColorRGBA OUTLINE_ENEMY_HOVER_COLOR = ColorRGBA.Green; private static final ColorRGBA OUTLINE_OWN_SELECT_COLOR = ColorRGBA.Cyan; private static final ColorRGBA OUTLINE_ENEMY_SELECT_COLOR = ColorRGBA.Orange; - private static final int OUTLINE_HIGHLIGHT_WIDTH = 6; - private static final int OUTLINE_HOVER_WIDTH = 6; - private static final int OUTLINE_SELECT_WIDTH = 8; + private static final int OUTLINE_HIGHLIGHT_WIDTH = 8; + private static final int OUTLINE_HOVER_WIDTH = 8; + private static final int OUTLINE_SELECT_WIDTH = 10; private final Node parentNode; private boolean enemy; @@ -87,16 +87,6 @@ public void setLocation(Vector3f loc){ } @Override - public void setSpatial(Spatial spatial){ - if(this.spatial == null && spatial != null){ - super.setSpatial(spatial); - initSpatial(); - } - else{ - super.setSpatial(spatial); - } - } - public void initSpatial(){ setRotation(this.initRotation); @@ -143,8 +133,6 @@ public Material getMaterial(){ return ((Geometry) getSpatial()).getMaterial(); } - - //highlight own/enemy figure to select public void highlight(boolean enemy) { this.enemy = enemy; highlight = true; @@ -153,9 +141,9 @@ public void highlight(boolean enemy) { public void unHighlight(){ highlight = false; + deOutline(); } - public void hover(){ if(!hoverable) return; super.outline(enemy ? OUTLINE_ENEMY_HOVER_COLOR : OUTLINE_OWN_HOVER_COLOR, OUTLINE_HOVER_WIDTH); @@ -194,8 +182,4 @@ public boolean isSelectable() { public void setHoverable(boolean hoverable) { this.hoverable = hoverable; } - - public void deOutline() { - super.deOutline(); - } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/AbstractButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/AbstractButton.java new file mode 100644 index 00000000..de37adc1 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/AbstractButton.java @@ -0,0 +1,56 @@ +package pp.mdga.client.button; + +import com.jme3.font.BitmapFont; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public abstract class AbstractButton { + public static final ColorRGBA BUTTON_NORMAL = ColorRGBA.fromRGBA255(169, 165, 104, 255); + public static final ColorRGBA BUTTON_PRESSED = ColorRGBA.fromRGBA255(105, 117, 89, 255); + public static final ColorRGBA TEXT_NORMAL = ColorRGBA.Black; + public static final ColorRGBA TEXT_PRESSED = ColorRGBA.fromRGBA255( 180, 195, 191, 255); + + public static final float HORIZONTAL = 16; + public static final float VERTICAL = 9; + + protected BitmapFont font; + + protected final MdgaApp app; + protected final Node node; + + protected Vector2f pos; + protected float fontSizeFactor = 1.0f; + + protected float fontSize; + protected float horizontalStep; + protected float verticalStep; + protected float heightStep; + protected float widthStep; + + protected boolean adjust = false; + + public AbstractButton(MdgaApp app, Node node) { + this.app = app; + this.node = node; + + font = app.getAssetManager().loadFont("Fonts/Gunplay.fnt"); + } + + public abstract void show(); + public abstract void hide(); + + public void setPos(Vector2f pos) { + this.pos = pos; + } + + protected void calculateRelative() { + fontSize = fontSizeFactor * 15 * (float)app.getCamera().getWidth() / 720; + + horizontalStep = (float)app.getCamera().getWidth() / HORIZONTAL; + verticalStep = (float)app.getCamera().getHeight() / VERTICAL; + heightStep = verticalStep / 2; + widthStep = horizontalStep / 2; + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonLeft.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonLeft.java new file mode 100644 index 00000000..16933f5f --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonLeft.java @@ -0,0 +1,21 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public class ButtonLeft extends ClickButton { + public ButtonLeft(MdgaApp app, Node node, Runnable action, String label, int narrowFactor) { + super(app, node, action, label, new Vector2f( 5, 2), new Vector2f(0.5f * narrowFactor, 1.8f)); + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonRight.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonRight.java new file mode 100644 index 00000000..aacacd4c --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ButtonRight.java @@ -0,0 +1,23 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public class ButtonRight extends ClickButton { + public ButtonRight(MdgaApp app, Node node, Runnable action, String label, int narrowFactor) { + super(app, node, action, label, new Vector2f( 5, 2), new Vector2f(HORIZONTAL - 0.5f * narrowFactor, 1.8f)); + + adjust = true; + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/CeremonyButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/CeremonyButton.java new file mode 100644 index 00000000..4b207f0b --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/CeremonyButton.java @@ -0,0 +1,178 @@ +package pp.mdga.client.button; + +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.renderer.queue.RenderQueue; +import com.jme3.scene.Node; +import com.jme3.scene.Spatial; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.Asset; +import pp.mdga.client.MdgaApp; +import pp.mdga.game.Color; + +public class CeremonyButton extends ClickButton { + public enum Pos { + FIRST, + SECOND, + THIRD, + LOST, + } + + static final float WIDTH = 4.0f; + + private final Node node3d; + + private boolean rotate = false; + private Spatial model; + private float rot = 180; + + private LobbyButton.Taken taken = LobbyButton.Taken.NOT; + + private LabelButton label; + + public CeremonyButton(MdgaApp app, Node node, Node node3d, Color tsk, Pos pos, String name) { + super(app, node, () -> {} , "", new Vector2f(WIDTH, 7), new Vector2f(0, 0)); + + this.node3d = node3d; + + label = new LabelButton(app, node, name, new Vector2f( WIDTH, 1), new Vector2f(0, 0)); + + final float mid = HORIZONTAL / 2; + final float uiSpacing = 1.4f; + final float figSpacingX = 0.9f; + final float figSpacingY = 0.25f; + + float uiX = mid; + float uiY = 6; + float figX = 0; + float figY = -0.32f; + + Asset asset = switch (tsk) { + case CYBER -> { + instance.setText("CIR"); + yield Asset.cir; + } + case AIRFORCE -> { + instance.setText("Luftwaffe"); + yield Asset.lw; + } + case ARMY -> { + instance.setText("Heer"); + yield Asset.heer; + } + case NAVY -> { + instance.setText("Marine"); + yield Asset.marine; + } + }; + + switch (pos) { + case FIRST: + rotate = true; + uiX = 0; + uiY -= 0; + figX = 0; + figY -= 1 * figSpacingY; + break; + case SECOND: + adjust = true; + label.adjust = true; + uiX -= uiSpacing; + uiY -= 1; + figX -= figSpacingX; + figY -= 2 * figSpacingY; + figY -= 0.1f; + break; + case THIRD: + uiX += uiSpacing; + uiY -= 1.5f; + figX += figSpacingX; + figY -= 3 * figSpacingY; + figY -= 0.07f; + break; + case LOST: + adjust = true; + label.adjust = true; + uiX -= 1 * uiSpacing + 0.4f; + uiX -= WIDTH / 2; + uiY -= 2; + figX -= 2 * figSpacingX; + figY -= 4 * figSpacingY; + break; + } + + setPos(new Vector2f(uiX, uiY)); + label.setPos(new Vector2f(uiX, uiY + 1)); + + createModel(asset, new Vector3f(figX, figY, 6)); + } + + @Override + public void onHover() { + ColorRGBA buttonNormal = ColorRGBA.Gray.clone();// BUTTON_NORMAL.clone(); + buttonNormal.a = 0.01f; + + QuadBackgroundComponent background = new QuadBackgroundComponent(buttonNormal); + instance.setBackground(background); + } + + @Override + public void onUnHover() { + ColorRGBA buttonNormal = ColorRGBA.Gray.clone();// BUTTON_NORMAL.clone(); + buttonNormal.a = 0.01f; + + QuadBackgroundComponent background = new QuadBackgroundComponent(buttonNormal); + instance.setBackground(background); + } + + @Override + public void show() { + release(); + + calculateRelative(); + setRelative(); + + node.attachChild(instance); + node3d.attachChild(model); + + label.show(); + } + + @Override + public void hide() { + node.detachChild(instance); + node3d.detachChild(model); + + label.hide(); + } + + public void update(float tpf) { + if(rotate) { + rot += 140.0f * tpf; + rot %= 360; + } else { + rot = 180; + } + + model.setLocalRotation(new Quaternion().fromAngles((float) Math.toRadians(90), (float) Math.toRadians(rot), (float) Math.toRadians(180))); + } + + private void createModel(Asset asset, Vector3f pos) { + String modelName = asset.getModelPath(); + String texName = asset.getDiffPath(); + + model = app.getAssetManager().loadModel(modelName); + model.scale(asset.getSize() / 2); + model.rotate((float) Math.toRadians(90), (float) Math.toRadians(rot), (float) Math.toRadians(180)); + model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); + + model.setLocalTranslation(pos); + + Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); + mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName)); + model.setMaterial(mat); + } +} 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 new file mode 100644 index 00000000..08fb544d --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/ClickButton.java @@ -0,0 +1,108 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.scene.Node; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.HAlignment; +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; + + protected String label; + protected Vector2f size; + + protected Button instance; + + ClickButton(MdgaApp app, Node node, Runnable action, String label, Vector2f size, Vector2f pos) { + super(app, node); + + this.action = action; + this.label = label; + this.pos = pos; + this.size = size; + + instance = new Button(label); + + instance.addClickCommands((button) -> { app.getAcousticHandler().playSound(MdgaSound.BUTTON_PRESSED); action.run(); }); + instance.setTextHAlignment(HAlignment.Center); + instance.setTextVAlignment(VAlignment.Center); + + instance.addCommands(Button.ButtonAction.HighlightOn, (button) -> click()); + instance.addCommands(Button.ButtonAction.HighlightOff, (button) -> release()); + + instance.setFont(font); + instance.setFocusColor(TEXT_NORMAL); + + calculateRelative(); + setRelative(); + } + + @Override + public void show() { + release(); + + calculateRelative(); + setRelative(); + + node.attachChild(instance); + } + + @Override + public void hide() { + node.detachChild(instance); + } + + protected abstract void onHover(); + protected abstract void onUnHover(); + + protected void click() { + instance.setColor(TEXT_PRESSED); + instance.setHighlightColor(TEXT_PRESSED); + + QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_PRESSED); + instance.setBackground(background); + + app.getAcousticHandler().playSound(MdgaSound.UI_CLICK); + + onHover(); + }; + + protected void release() { + instance.setColor(TEXT_NORMAL); + instance.setHighlightColor(TEXT_NORMAL); + + QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_NORMAL); + instance.setBackground(background); + + onUnHover(); + }; + + protected void setRelative() { + instance.setFontSize(fontSize); + + instance.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); + + float xAdjust = 0.0f; + if(adjust) { + xAdjust = instance.getPreferredSize().x; + } + + instance.setLocalTranslation(pos.x * horizontalStep - xAdjust, pos.y * verticalStep, -1); + + final float horizontalMid = ((float)app.getCamera().getWidth() / 2) - (instance.getPreferredSize().x / 2); + final float verticalMid = ((float)app.getCamera().getHeight() / 2) - instance.getPreferredSize().y / 2; + + if(0 == pos.x) { + instance.setLocalTranslation(horizontalMid, instance.getLocalTranslation().y, instance.getLocalTranslation().z); + } + + if(0 == pos.y) { + instance.setLocalTranslation(instance.getLocalTranslation().x, verticalMid, instance.getLocalTranslation().z); + } + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/InputButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/InputButton.java new file mode 100644 index 00000000..99034ebd --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/InputButton.java @@ -0,0 +1,102 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.scene.Node; +import com.simsilica.lemur.*; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class InputButton extends AbstractButton { + private Label label; + private TextField field; + + private Container container = new Container(); + + private final int maxLenght; + + protected Vector2f size; + + public InputButton(MdgaApp app, Node node, String label, int maxLenght) { + super(app, node); + + this.label = new Label(label); + this.maxLenght = maxLenght; + + this.label.setColor(TEXT_NORMAL); + + field = new TextField(""); + field.setColor(TEXT_NORMAL); + field.setTextHAlignment(HAlignment.Left); + field.setTextVAlignment(VAlignment.Center); + + QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(BUTTON_NORMAL); + field.setBackground(grayBackground); + + this.label.setFont(font); + field.setFont(font); + + pos = new Vector2f( 0, 0); + size = new Vector2f(5.5f, 1); + + container.addChild(this.label); + container.addChild(field); + } + + @Override + public void show() { + calculateRelative(); + setRelative(); + + node.attachChild(container); + } + + @Override + public void hide() { + node.detachChild(container); + } + + public void update() { + String text = field.getText(); + int length = text.length(); + + if (length > maxLenght) { + field.setText(text.substring(0, maxLenght)); + } + } + + protected void setRelative() { + this.label.setFontSize(fontSize); + field.setFontSize(fontSize); + + field.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); + + float xAdjust = 0.0f; + if(adjust) { + xAdjust = container.getPreferredSize().x; + } + + container.setLocalTranslation(pos.x * horizontalStep - xAdjust, pos.y * verticalStep, -1); + + final float horizontalMid = ((float)app.getCamera().getWidth() / 2) - (container.getPreferredSize().x / 2); + final float verticalMid = ((float)app.getCamera().getHeight() / 2) - container.getPreferredSize().y / 2; + + if(0 == pos.x) { + container.setLocalTranslation(horizontalMid, container.getLocalTranslation().y, -1); + } + + if(0 == pos.y) { + container.setLocalTranslation(container.getLocalTranslation().x, verticalMid, -1); + } + } + + public String getString() { + return field.getText(); + } + + public void setString(String string) { field.setText(string); } + + public void reset() { + field.setText(""); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LabelButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LabelButton.java new file mode 100644 index 00000000..1740a954 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LabelButton.java @@ -0,0 +1,63 @@ +package pp.mdga.client.button; + +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class LabelButton extends ClickButton{ + private ColorRGBA text = TEXT_NORMAL; + private ColorRGBA button = BUTTON_NORMAL; + + public LabelButton(MdgaApp app, Node node, String label, Vector2f size, Vector2f pos) { + super(app, node, () -> {}, label, size, pos); + } + + @Override + public void show() { + release(); + + calculateRelative(); + setRelative(); + + instance.setFontSize(fontSize / 2); + + node.attachChild(instance); + } + + @Override + public void hide() { + node.detachChild(instance); + } + + @Override + public void onHover() { + instance.setColor(text); + instance.setHighlightColor(text); + + QuadBackgroundComponent background = new QuadBackgroundComponent(button); + instance.setBackground(background); + } + + @Override + public void onUnHover() { + instance.setColor(text); + instance.setHighlightColor(text); + + QuadBackgroundComponent background = new QuadBackgroundComponent(button); + instance.setBackground(background); + } + + public void setText(String text) { + instance.setText(text); + } + + public void setColor(ColorRGBA text, ColorRGBA button) { + this.text = text; + this.button = button; + + hide(); + show(); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java new file mode 100644 index 00000000..5264327c --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/LobbyButton.java @@ -0,0 +1,218 @@ +package pp.mdga.client.button; + +import com.jme3.light.AmbientLight; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.renderer.queue.RenderQueue; +import com.jme3.scene.Node; +import com.jme3.scene.Spatial; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.Asset; +import pp.mdga.client.MdgaApp; +import pp.mdga.game.Color; + +public class LobbyButton extends ClickButton { + public enum Taken { + NOT, + SELF, + OTHER, + } + + static final ColorRGBA LOBBY_TAKEN = ColorRGBA.fromRGBA255(193,58,59, 25); + static final ColorRGBA LOBBY_READY = ColorRGBA.fromRGBA255(55,172,190, 25); + static final ColorRGBA LOBBY_READY_HOVER = ColorRGBA.fromRGBA255(17,211,218, 25); + static final ColorRGBA LOBBY_SELF_NORMAL = ColorRGBA.fromRGBA255(34,103,24, 25); + static final ColorRGBA LOBBY_SELF_HOVER = ColorRGBA.fromRGBA255(42,151,19, 25); + + static final float WIDTH = 4.0f; + + private final Node node3d; + + private boolean rotate = false; + private Spatial model; + private float rot = 180; + + private Taken taken = Taken.NOT; + + private LabelButton label; + + private boolean isReady = false; + + public LobbyButton(MdgaApp app, Node node, Node node3d, Runnable action, Color tsk) { + super(app, node, action, "", new Vector2f(WIDTH, 7), new Vector2f(0, 0)); + + this.node3d = node3d; + + label = new LabelButton(app, node, "- leer -", new Vector2f( WIDTH, 1), new Vector2f(0, 0)); + + final float mid = HORIZONTAL / 2; + final float uiSpacing = 0.4f; + final float figSpacing = 0.51f; + + float uiX = mid; + float figX = 0; + Asset asset = null; + + switch (tsk) { + case CYBER: + adjust = true; + label.adjust = true; + uiX -= 3 * uiSpacing; + uiX -= WIDTH / 2; + asset = Asset.cir; + figX -= 3 * figSpacing; + instance.setText("CIR"); + break; + case AIRFORCE: + adjust = true; + label.adjust = true; + uiX -= uiSpacing; + asset = Asset.lw; + figX -= figSpacing; + instance.setText("Luftwaffe"); + break; + case ARMY: + uiX += uiSpacing; + asset = Asset.heer; + figX += figSpacing; + instance.setText("Heer"); + break; + case NAVY: + uiX += 3 * uiSpacing; + uiX += WIDTH / 2; + asset = Asset.marine; + figX += 3 * figSpacing; + instance.setText("Marine"); + break; + } + + setPos(new Vector2f(uiX, 6)); + label.setPos(new Vector2f(uiX, 7)); + + createModel(asset, new Vector3f(figX, -0.55f, 6)); + } + + @Override + public void onHover() { + ColorRGBA buttonPressed = BUTTON_PRESSED.clone(); + + switch (taken) { + case NOT: + buttonPressed.a = 0.3f; + break; + case SELF: + buttonPressed = LOBBY_SELF_HOVER; + break; + case OTHER: + buttonPressed = LOBBY_TAKEN; + break; + } + + if(isReady) { + buttonPressed = LOBBY_READY_HOVER; + } + + QuadBackgroundComponent background = new QuadBackgroundComponent(buttonPressed); + instance.setBackground(background); + + rotate = true; + } + + @Override + public void onUnHover() { + ColorRGBA buttonNormal = ColorRGBA.Gray.clone();// BUTTON_NORMAL.clone(); + + switch (taken) { + case NOT: + buttonNormal.a = 0.1f; + break; + case SELF: + buttonNormal = LOBBY_SELF_NORMAL; + break; + case OTHER: + buttonNormal = LOBBY_TAKEN; + break; + } + + if(isReady) { + buttonNormal = LOBBY_READY; + } + + QuadBackgroundComponent background = new QuadBackgroundComponent(buttonNormal); + instance.setBackground(background); + + rotate = false; + } + + @Override + public void show() { + release(); + + calculateRelative(); + setRelative(); + + node.attachChild(instance); + node3d.attachChild(model); + + label.show(); + } + + @Override + public void hide() { + node.detachChild(instance); + node3d.detachChild(model); + + label.hide(); + } + + public void update(float tpf) { + if(rotate) { + rot += 140.0f * tpf; + rot %= 360; + } else { + rot = 180; + } + + model.setLocalRotation(new Quaternion().fromAngles((float) Math.toRadians(90), (float) Math.toRadians(rot), (float) Math.toRadians(180))); + } + + private void createModel(Asset asset, Vector3f pos) { + String modelName = asset.getModelPath(); + String texName = asset.getDiffPath(); + + model = app.getAssetManager().loadModel(modelName); + model.scale(asset.getSize() / 2); + model.rotate((float) Math.toRadians(90), (float) Math.toRadians(rot), (float) Math.toRadians(180)); + model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); + + model.setLocalTranslation(pos); + + Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); + mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName)); + model.setMaterial(mat); + } + + public Taken getTaken() { + return taken; + } + + public void setTaken(Taken taken, String name) { + this.taken = taken; + + if(taken == Taken.NOT) { + label.setText("- leer -"); + isReady = false; + } else { + label.setText(name); + } + + onUnHover(); + } + + public void setReady(boolean isReady) { + this.isReady = isReady; + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/MenuButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/MenuButton.java new file mode 100644 index 00000000..7217ee36 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/MenuButton.java @@ -0,0 +1,21 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; + +public class MenuButton extends ClickButton { + public MenuButton(MdgaApp app, Node node, Runnable action, String label) { + super(app, node, action, label, new Vector2f( 5.5f, 2), new Vector2f(0, 0)); + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SettingsButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SettingsButton.java new file mode 100644 index 00000000..eef5c263 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SettingsButton.java @@ -0,0 +1,34 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import com.simsilica.lemur.HAlignment; +import com.simsilica.lemur.VAlignment; +import com.simsilica.lemur.component.IconComponent; +import pp.mdga.client.MdgaApp; + +public class SettingsButton extends ClickButton { + private IconComponent icon; + + public SettingsButton(MdgaApp app, Node node, Runnable action) { + super(app, node, action, "", new Vector2f(2, 2), new Vector2f(HORIZONTAL - 0.5f, VERTICAL - 0.5f)); + + adjust = true; + + icon = new IconComponent("Images/zahnrad.png"); + icon.setIconScale(0.1f * app.getImageScale()); + icon.setHAlignment(HAlignment.Center); + icon.setVAlignment(VAlignment.Center); + instance.setIcon(icon); + } + + @Override + public void onHover() { + + } + + @Override + public void onUnHover() { + + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SliderButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SliderButton.java new file mode 100644 index 00000000..4dbccf91 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/button/SliderButton.java @@ -0,0 +1,109 @@ +package pp.mdga.client.button; + +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.scene.Node; +import com.simsilica.lemur.*; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class SliderButton extends AbstractButton { + private Label label; + + private Slider slider; + + private Container container = new Container(); + + protected Vector2f size; + + public SliderButton(MdgaApp app, Node node, String label) { + super(app, node); + + this.label = new Label(label); + + this.label.setColor(TEXT_NORMAL); + + slider = new Slider("slider"); + + slider.getDecrementButton().setText(" - "); + slider.getDecrementButton().setFont(font); + slider.getDecrementButton().setFocusColor(TEXT_NORMAL); + slider.getDecrementButton().setTextVAlignment(VAlignment.Bottom); + slider.getDecrementButton().setColor(TEXT_NORMAL); + slider.getDecrementButton().setHighlightColor(TEXT_NORMAL); + + slider.getIncrementButton().setText(" + "); + slider.getIncrementButton().setFont(font); + slider.getIncrementButton().setFocusColor(TEXT_NORMAL); + slider.getIncrementButton().setTextVAlignment(VAlignment.Bottom); + slider.getIncrementButton().setColor(TEXT_NORMAL); + slider.getIncrementButton().setHighlightColor(TEXT_NORMAL); + + slider.getThumbButton().setText("X"); + slider.getThumbButton().setFont(font); + slider.getThumbButton().setFocusColor(TEXT_NORMAL); + slider.getThumbButton().setColor(TEXT_NORMAL); + slider.getThumbButton().setHighlightColor(TEXT_NORMAL); + + QuadBackgroundComponent background = new QuadBackgroundComponent(BUTTON_NORMAL); + slider.setBackground(background); + + this.label.setFont(font); + + pos = new Vector2f( 0, 0); + size = new Vector2f(5.5f, 1); + + container.addChild(this.label); + + container.addChild(slider); + } + + @Override + public void show() { + calculateRelative(); + setRelative(); + + node.attachChild(container); + } + + @Override + public void hide() { + node.detachChild(container); + } + + protected void setRelative() { + this.label.setFontSize(fontSize); + + slider.getDecrementButton().setFontSize(fontSize); + slider.getIncrementButton().setFontSize(fontSize); + slider.getThumbButton().setFontSize(fontSize); + + slider.setPreferredSize(new Vector3f(size.x * widthStep, size.y * heightStep, 0)); + + float xAdjust = 0.0f; + if(adjust) { + xAdjust = container.getPreferredSize().x; + } + + container.setLocalTranslation(pos.x * horizontalStep - xAdjust, pos.y * verticalStep, -1); + + final float horizontalMid = ((float)app.getCamera().getWidth() / 2) - (container.getPreferredSize().x / 2); + final float verticalMid = ((float)app.getCamera().getHeight() / 2) - container.getPreferredSize().y / 2; + + if(0 == pos.x) { + container.setLocalTranslation(horizontalMid, container.getLocalTranslation().y, -1); + } + + if(0 == pos.y) { + container.setLocalTranslation(container.getLocalTranslation().x, verticalMid, -1); + } + } + + public float getPercent() { + return (float) slider.getModel().getPercent(); + } + + public void setPercent(float percent) { + slider.getModel().setPercent(percent); + } +} 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 new file mode 100644 index 00000000..5a1dd930 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/AudioSettingsDialog.java @@ -0,0 +1,82 @@ +package pp.mdga.client.dialog; + +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; +import pp.mdga.client.button.MenuButton; +import pp.mdga.client.button.SliderButton; +import pp.mdga.client.view.MdgaView; + +public class AudioSettingsDialog extends Dialog { + private final MdgaView view; + + private SliderButton mainVolume; + private SliderButton musicVolume; + private SliderButton soundVolume; + + private MenuButton backButton; + + private boolean active = false; + + public AudioSettingsDialog(MdgaApp app, Node node, MdgaView view) { + super(app, node); + + this.view = view; + + mainVolume = 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"); + + float offset = 1.0f; + + mainVolume.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.75f; + + musicVolume.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.75f; + + soundVolume.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.75f * 1.3f; + + backButton.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.75f; + } + + @Override + protected void onShow() { + active = true; + + mainVolume.setPercent(app.getAcousticHandler().getMainVolume()); + musicVolume.setPercent(app.getAcousticHandler().getMusicVolume()); + soundVolume.setPercent(app.getAcousticHandler().getSoundVolume()); + + backButton.show(); + + mainVolume.show(); + musicVolume.show(); + soundVolume.show(); + } + + @Override + protected void onHide() { + active = false; + + backButton.hide(); + + mainVolume.hide(); + musicVolume.hide(); + soundVolume.hide(); + } + + public void update() { + if(!active) { + return; + } + + app.getAcousticHandler().setMainVolume(mainVolume.getPercent()); + app.getAcousticHandler().setMusicVolume(musicVolume.getPercent()); + app.getAcousticHandler().setSoundVolume(soundVolume.getPercent()); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/CeremonyDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/CeremonyDialog.java new file mode 100644 index 00000000..d21296d0 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/CeremonyDialog.java @@ -0,0 +1,105 @@ +package pp.mdga.client.dialog; + +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector2f; +import com.jme3.scene.Node; +import pp.mdga.client.MdgaApp; +import pp.mdga.client.button.AbstractButton; +import pp.mdga.client.button.LabelButton; +import pp.mdga.client.button.MenuButton; + +import java.util.ArrayList; + +public class CeremonyDialog extends Dialog { + private ArrayList> labels; + + float offsetX; + + public CeremonyDialog(MdgaApp app, Node node) { + super(app, node); + + prepare(); + } + + @Override + protected void onShow() { + for (ArrayList row : labels) { + for (LabelButton b : row) { + b.show(); + } + } + } + + @Override + protected void onHide() { + for (ArrayList row : labels) { + for (LabelButton b : row) { + b.hide(); + } + } + } + + public void addStatisticsRow(String name, int v1, int v2, int v3, int v4, int v5, int v6) { + float offsetYSmall = 0.5f; + + ArrayList row = new ArrayList<>(); + + Vector2f sizeSmall = new Vector2f(4, 1.2f); + row.add(new LabelButton(app, node, name, sizeSmall, new Vector2f())); + row.add(new LabelButton(app, node, "" + v1, sizeSmall, new Vector2f())); + row.add(new LabelButton(app, node, "" + v2, sizeSmall, new Vector2f())); + row.add(new LabelButton(app, node, "" + v3, sizeSmall, new Vector2f())); + row.add(new LabelButton(app, node, "" + v4, sizeSmall, new Vector2f())); + row.add(new LabelButton(app, node, "" + v5, sizeSmall, new Vector2f())); + row.add(new LabelButton(app, node, "" + v6, sizeSmall, new Vector2f())); + + ColorRGBA colorText = AbstractButton.TEXT_NORMAL.clone(); + colorText.a = 0.1f; + + ColorRGBA colorButton = AbstractButton.BUTTON_NORMAL.clone(); + colorButton.a = 0.1f; + + int j = 0; + for (LabelButton b : row) { + if(j > 0) { + b.setColor(colorText, colorButton); + } + + b.setPos(new Vector2f(offsetX, MenuButton.VERTICAL - offsetYSmall)); + offsetYSmall += 0.8f; + + j++; + } + + offsetX += 2.3f; + + labels.add(row); + } + + public void prepare() { + offsetX = 0.5f; + + labels = new ArrayList<>(); + + ArrayList first = new ArrayList<>(); + Vector2f size = new Vector2f(4, 1.2f); + first.add(new LabelButton(app, node, "", size, new Vector2f())); + first.add(new LabelButton(app, node, "Figuren geworfen", size, new Vector2f())); + first.add(new LabelButton(app, node, "Figuren verloren", size, new Vector2f())); + first.add(new LabelButton(app, node, "Verwendete Bonuskarten", size, new Vector2f())); + first.add(new LabelButton(app, node, "Gewürfelte 6en", size, new Vector2f())); + first.add(new LabelButton(app, node, "Gelaufene Felder", size, new Vector2f())); + first.add(new LabelButton(app, node, "Bonusfeldern erreicht", size, new Vector2f())); + + float offsetY = 0.5f; + + for (LabelButton b : first) { + b.setPos(new Vector2f(offsetX, MenuButton.VERTICAL - offsetY)); + offsetY += 0.8f; + } + + offsetX += 2.3f; + + labels.add(first); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java index 421f4cff..89c39555 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/Dialog.java @@ -1,82 +1,32 @@ package pp.mdga.client.dialog; -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; import com.jme3.scene.Node; -import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; -import com.simsilica.lemur.HAlignment; -import com.simsilica.lemur.VAlignment; -import com.simsilica.lemur.component.QuadBackgroundComponent; import pp.mdga.client.MdgaApp; -import static com.jme3.math.FastMath.floor; - public abstract class Dialog { - protected final ColorRGBA COLOR_DEFAULT = ColorRGBA.Gray; - protected final ColorRGBA COLOR_HOVER = ColorRGBA.DarkGray; - - protected Container container; - protected final MdgaApp app; - private final Node node; + protected final Node node = new Node(); - protected final float vertical_step; - protected final float horitontal_step; + private final Node root; - protected float fontSize = 35; - - public Dialog(MdgaApp app, Node node) { + Dialog(MdgaApp app, Node node) { this.app = app; - this.node = node; - this.container = new Container(); - - this.horitontal_step = app.getCamera().getWidth() / 16; - this.vertical_step = app.getCamera().getHeight() / 9; - - int val = (int) (32 * Math.min(app.getResolutionFactor() * 0.9f, 1)); - fontSize = val; + this.root = node; } public void show() { - node.attachChild(container); + root.attachChild(node); + + onShow(); } - public void hide () { - node.detachChild(container); + public void hide() { + root.detachChild(node); + + onHide(); } - protected void createButton(String label, Runnable action, Vector3f size) { - Button button = new Button(label); - button.addClickCommands(source -> action.run()); - button.setFontSize(fontSize); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - button.setPreferredSize(size); - button.setTextHAlignment(HAlignment.Center); - button.setTextVAlignment(VAlignment.Center); - - QuadBackgroundComponent background = new QuadBackgroundComponent(COLOR_DEFAULT); - background.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - button.setBackground(background); - - button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOn, (source) -> { - QuadBackgroundComponent hoverBackground = new QuadBackgroundComponent(COLOR_HOVER); - hoverBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - source.setBackground(hoverBackground); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - }); - - button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOff, (source) -> { - QuadBackgroundComponent normalBackground = new QuadBackgroundComponent(COLOR_DEFAULT); - normalBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - source.setBackground(normalBackground); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - }); - - container.addChild(button); - } + protected abstract void onShow(); + protected abstract void onHide (); } - diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/GetPercentRunnable.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/GetPercentRunnable.java deleted file mode 100644 index d50a5450..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/GetPercentRunnable.java +++ /dev/null @@ -1,15 +0,0 @@ -package pp.mdga.client.dialog; - -import java.util.function.Supplier; - -public class GetPercentRunnable { - private final Supplier action; - - public GetPercentRunnable(Supplier action) { - this.action = action; - } - - public float get() { - return action.get(); - } -} 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 02522c5b..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 @@ -1,143 +1,68 @@ package pp.mdga.client.dialog; -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; +import com.jme3.math.Vector2f; import com.jme3.scene.Node; -import com.jme3.texture.Texture; -import com.simsilica.lemur.*; -import com.simsilica.lemur.component.QuadBackgroundComponent; -import com.simsilica.lemur.component.SpringGridLayout; import pp.mdga.client.MdgaApp; +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; -public class HostDialog extends Dialog { - private TextField portInput; +import java.util.prefs.Preferences; - public HostDialog(MdgaApp app, Node node, Runnable backAction) { +public class HostDialog extends Dialog { + private InputButton portInput; + + private ButtonRight hostButton; + private ButtonLeft backButton; + + private final MainView view; + + private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class); + + public HostDialog(MdgaApp app, Node node, MainView view) { super(app, node); - QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray); - quad1.setMargin(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor()); - container.setBackground(quad1); + this.view = view; - Texture texture = app.getAssetManager().loadTexture("Images/mdga_logo.png"); + portInput = new InputButton(app, node, "Port: ", 5); + portInput.setString(prefs.get("hostPort", "11111")); - QuadBackgroundComponent b = new QuadBackgroundComponent(texture); + hostButton = new ButtonRight(app, node, view::forward, "Spiel hosten", 10); + backButton = new ButtonLeft(app, node, view::back, "Zurück", 10); - Panel imagePanel = new Panel(); - imagePanel.setBackground(b); + float offset = 3.0f; - container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0)); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createTextField(); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - Container sub = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - createButton(sub, "Abbrechen", backAction, new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - sub.addChild(new Panel(40 * app.getResolutionFactor(), 0 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createButton(sub, "Starten", () -> tryStart(), new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - container.addChild(sub); - } - - void tryStart() { - if (null == portInput.getText()) { - portInput.setText(""); - return; - } - - int port = 0; - - try { - port = Integer.parseInt(portInput.getText()); - } catch (NumberFormatException e) { - portInput.setText(""); - return; - } - - if(port >= 1 && port <= 65535) { - app.getModelSyncronizer().setHost(port); - } - - portInput.setText(""); + portInput.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.5f; } @Override - public void show() { - super.show(); - - container.setLocalTranslation( - app.getCamera().getWidth() / 2 - container.getPreferredSize().x / 2, - app.getCamera().getHeight() / 2 + container.getPreferredSize().y / 2, - 0 - ); + protected void onShow() { + portInput.show(); + hostButton.show(); + backButton.show(); } @Override - public void hide() { - super.hide(); + protected void onHide() { + portInput.hide(); + hostButton.hide(); + backButton.hide(); } - private void createTextField() { - Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - Label nameLabel = new Label("Port:\t"); - nameLabel.setFontSize(fontSize); - nameLabel.setColor(ColorRGBA.Black); - - portInput = new TextField(""); - - portInput.setColor(ColorRGBA.Black); - portInput.setTextHAlignment(HAlignment.Left); - portInput.setFontSize(fontSize); - portInput.setSingleLine(true); - - QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(ColorRGBA.DarkGray); - portInput.setBackground(grayBackground); - - subContainer.addChild(nameLabel); - subContainer.addChild(portInput); - - container.addChild(subContainer); + public void update() { + portInput.update(); } - protected void createButton(Container c, String label, Runnable action, Vector3f size) { - Button button = new Button(label); - button.addClickCommands(source -> action.run()); - button.setFontSize(fontSize); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - button.setPreferredSize(size); - button.setTextHAlignment(HAlignment.Center); - button.setTextVAlignment(VAlignment.Center); + public String getPort() { + prefs.put("hostPort", portInput.getString()); + return portInput.getString(); + } - QuadBackgroundComponent background = new QuadBackgroundComponent(COLOR_DEFAULT); - background.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - button.setBackground(background); - - button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOn, (source) -> { - QuadBackgroundComponent hoverBackground = new QuadBackgroundComponent(COLOR_HOVER); - hoverBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - source.setBackground(hoverBackground); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - }); - - button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOff, (source) -> { - QuadBackgroundComponent normalBackground = new QuadBackgroundComponent(COLOR_DEFAULT); - normalBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - source.setBackground(normalBackground); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - }); - - c.addChild(button); + public void resetPort() { + portInput.reset(); + prefs.put("hostPort", "11111"); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/InterruptDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/InterruptDialog.java new file mode 100644 index 00000000..4fd87803 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/InterruptDialog.java @@ -0,0 +1,4 @@ +package pp.mdga.client.dialog; + +public class InterruptDialog { +} 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 f89f3d74..0cc6b74f 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 @@ -1,192 +1,88 @@ package pp.mdga.client.dialog; -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; +import com.jme3.math.Vector2f; import com.jme3.scene.Node; -import com.jme3.texture.Texture; -import com.simsilica.lemur.*; -import com.simsilica.lemur.component.QuadBackgroundComponent; -import com.simsilica.lemur.component.SpringGridLayout; 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.regex.Pattern; +import java.util.prefs.Preferences; public class JoinDialog extends Dialog { - private TextField portInput; - private TextField ipInput; + private InputButton ipInput; + private InputButton portInput; - public JoinDialog(MdgaApp app, Node node, Runnable backAction) { + private ButtonRight joinButton; + private ButtonLeft backButton; + + private final MainView view; + + private Preferences prefs = Preferences.userNodeForPackage(JoinDialog.class); + + public JoinDialog(MdgaApp app, Node node, MainView view) { super(app, node); - QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray); - quad1.setMargin(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor()); - container.setBackground(quad1); + this.view = view; - Texture texture = app.getAssetManager().loadTexture("Images/mdga_logo.png"); + ipInput = new InputButton(app, node, "Ip: ", 15); + portInput = new InputButton(app, node, "Port: ", 5); + portInput.setString(prefs.get("joinPort", "11111")); + ipInput.setString(prefs.get("joinIp", "")); - QuadBackgroundComponent b = new QuadBackgroundComponent(texture); + joinButton = new ButtonRight(app, node, view::forward, "Spiel beitreten", 10); + backButton = new ButtonLeft(app, node, view::back, "Zurück", 10); - Panel imagePanel = new Panel(); - imagePanel.setBackground(b); + float offset = 3.0f; - container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0)); + ipInput.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.5f; - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createIpField(); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createPortField(); - - //abstandshalter - container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray)); - - Container sub = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - createButton(sub, "Abbrechen", backAction, new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - sub.addChild(new Panel(40 * app.getResolutionFactor(), 0 * app.getResolutionFactor(), ColorRGBA.Gray)); - - createButton(sub, "Beitreten", () -> tryJoin(), new Vector3f(170 * app.getResolutionFactor(), 60 * app.getResolutionFactor(), 0)); - - container.addChild(sub); - } - - void tryJoin() { - if (null == portInput.getText()) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - int port = 0; - - try { - port = Integer.parseInt(portInput.getText()); - } catch (NumberFormatException e) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - if(!(port >= 1 && port <= 65535)) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - if (null == ipInput.getText()) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - String ipv4Pattern = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; - - if(!Pattern.matches(ipv4Pattern, ipInput.getText())) { - portInput.setText(""); - ipInput.setText(""); - return; - } - - app.getModelSyncronizer().setJoin(ipInput.getText(), port); + portInput.setPos(new Vector2f(0, MenuButton.VERTICAL - offset)); + offset += 1.5f; } @Override - public void show() { - super.show(); - - container.setLocalTranslation( - app.getCamera().getWidth() / 2 - container.getPreferredSize().x / 2, - app.getCamera().getHeight() / 2 + container.getPreferredSize().y / 2, - 0 - ); + protected void onShow() { + ipInput.show(); + portInput.show(); + joinButton.show(); + backButton.show(); } @Override - public void hide() { - super.hide(); + protected void onHide() { + ipInput.hide(); + portInput.hide(); + joinButton.hide(); + backButton.hide(); } - private void createPortField() { - Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - Label nameLabel = new Label("Port:\t"); - nameLabel.setFontSize(fontSize); - nameLabel.setColor(ColorRGBA.Black); - - portInput = new TextField(""); - - portInput.setColor(ColorRGBA.Black); - portInput.setTextHAlignment(HAlignment.Left); - portInput.setFontSize(fontSize); - portInput.setSingleLine(true); - - QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(ColorRGBA.DarkGray); - portInput.setBackground(grayBackground); - - subContainer.addChild(nameLabel); - subContainer.addChild(portInput); - - container.addChild(subContainer); + public void update() { + ipInput.update(); + portInput.update(); } - private void createIpField() { - Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - - Label nameLabel = new Label("Ip:\t"); - nameLabel.setFontSize(fontSize); - nameLabel.setColor(ColorRGBA.Black); - - ipInput = new TextField(""); - - ipInput.setColor(ColorRGBA.Black); - ipInput.setTextHAlignment(HAlignment.Left); - ipInput.setFontSize(fontSize); - ipInput.setSingleLine(true); - - QuadBackgroundComponent grayBackground = new QuadBackgroundComponent(ColorRGBA.DarkGray); - ipInput.setBackground(grayBackground); - - subContainer.addChild(nameLabel); - subContainer.addChild(ipInput); - - container.addChild(subContainer); + public String getIpt() { + prefs.put("joinIp", ipInput.getString()); + return ipInput.getString(); } - protected void createButton(Container c, String label, Runnable action, Vector3f size) { - Button button = new Button(label); - button.addClickCommands(source -> action.run()); - button.setFontSize(fontSize); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - button.setPreferredSize(size); - button.setTextHAlignment(HAlignment.Center); - button.setTextVAlignment(VAlignment.Center); + public void resetIp() { + ipInput.reset(); + prefs.put("joinIp", ""); + } - QuadBackgroundComponent background = new QuadBackgroundComponent(COLOR_DEFAULT); - background.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - button.setBackground(background); + public String getPort() { + prefs.put("joinPort", portInput.getString()); + return portInput.getString(); + } - button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOn, (source) -> { - QuadBackgroundComponent hoverBackground = new QuadBackgroundComponent(COLOR_HOVER); - hoverBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - source.setBackground(hoverBackground); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - }); - - button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOff, (source) -> { - QuadBackgroundComponent normalBackground = new QuadBackgroundComponent(COLOR_DEFAULT); - normalBackground.setMargin(5 * app.getResolutionFactor(), 5 * app.getResolutionFactor()); - source.setBackground(normalBackground); - button.setHighlightColor(ColorRGBA.White); - button.setColor(ColorRGBA.Black); - }); - - c.addChild(button); + public void resetPort() { + portInput.reset(); + prefs.put("joinPort", "11111"); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/LobbyButtonDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/LobbyButtonDialog.java deleted file mode 100644 index 5c1195d9..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/dialog/LobbyButtonDialog.java +++ /dev/null @@ -1,165 +0,0 @@ -package pp.mdga.client.dialog; - -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; -import com.jme3.scene.Node; -import com.simsilica.lemur.Button; -import com.simsilica.lemur.Command; -import com.simsilica.lemur.HAlignment; -import com.simsilica.lemur.VAlignment; -import com.simsilica.lemur.component.QuadBackgroundComponent; -import pp.mdga.client.MdgaApp; -import pp.mdga.game.Color; - -public class LobbyButtonDialog extends Dialog { - private final int pos; - - private Button button; - - private Command