From 7c09107d28631b24106dac4bdcfc858324559041 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 18 Nov 2024 15:58:30 +0100 Subject: [PATCH] Work on Dialogs --- .../pp/mdga/client/Board/BoardHandler.java | 11 ++- .../java/pp/mdga/client/Dialog/Dialog.java | 96 ++----------------- .../pp/mdga/client/Dialog/DialogView.java | 26 ----- .../client/Dialog/HorizontalButtonDialog.java | 39 ++++++++ .../mdga/client/Dialog/InterruptDialog.java | 4 - .../pp/mdga/client/Dialog/MdgaButton.java | 49 ++++++++++ .../pp/mdga/client/Dialog/MenuDialog.java | 5 - .../pp/mdga/client/Dialog/NetworkDialog.java | 5 - .../pp/mdga/client/Dialog/SoundDialog.java | 31 ------ .../pp/mdga/client/Dialog/StartDialog.java | 13 --- .../client/Dialog/VerticalButtonDialog.java | 45 +++++++++ .../pp/mdga/client/Dialog/VideoDialog.java | 5 - .../main/java/pp/mdga/client/GameView.java | 24 ----- .../main/java/pp/mdga/client/LobbyView.java | 76 --------------- .../java/pp/mdga/client/MainMenuView.java | 68 ------------- .../src/main/java/pp/mdga/client/MdgaApp.java | 10 +- .../main/java/pp/mdga/client/MdgaView.java | 30 ------ .../mdga/client/{ => View}/CeremonyView.java | 35 ++----- .../java/pp/mdga/client/View/GameView.java | 35 +++++++ .../java/pp/mdga/client/View/LobbyView.java | 64 +++++++++++++ .../java/pp/mdga/client/View/MainView.java | 52 ++++++++++ .../java/pp/mdga/client/View/MdgaView.java | 46 +++++++++ .../pp.mdga/client/DetermineStartPlayer.java | 2 +- .../main/java/pp.mdga/client/Spectator.java | 2 +- .../src/main/java/pp.mdga/client/Turn.java | 2 +- .../src/main/java/pp.mdga/client/Waiting.java | 2 +- .../pp.mdga/server/DetermineStartPlayer.java | 2 +- 27 files changed, 366 insertions(+), 413 deletions(-) delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/DialogView.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/HorizontalButtonDialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/InterruptDialog.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MdgaButton.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MenuDialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/NetworkDialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/SoundDialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/StartDialog.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VerticalButtonDialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VideoDialog.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/GameView.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/LobbyView.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/MainMenuView.java delete mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaView.java rename Projekte/mdga/client/src/main/java/pp/mdga/client/{ => View}/CeremonyView.java (74%) create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/View/GameView.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/View/LobbyView.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/View/MainView.java create mode 100644 Projekte/mdga/client/src/main/java/pp/mdga/client/View/MdgaView.java 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 0496adc7..68ba7470 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 @@ -6,6 +6,7 @@ import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.renderer.queue.RenderQueue; +import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.scene.control.AbstractControl; import com.jme3.shadow.DirectionalLightShadowRenderer; @@ -29,6 +30,8 @@ public class BoardHandler { private Map> playerMap; + private Node node = new Node(); + public BoardHandler(MdgaApp app) { assert (app != null) : "app is null"; @@ -41,6 +44,12 @@ public BoardHandler(MdgaApp app) { public void init() { initMap(); initCamera(); + + app.getRootNode().attachChild(node); + } + + public void shutdown() { + app.getRootNode().detachChild(node); } private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) { @@ -110,7 +119,7 @@ private Spatial createModel(BoardAsset asset, Vector3f pos, float rot) { Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName)); model.setMaterial(mat); - app.getRootNode().attachChild(model); + node.attachChild(model); return model; } 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 6fd3137e..088434ee 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,101 +1,21 @@ package pp.mdga.client.Dialog; -import com.jme3.app.SimpleApplication; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; -import com.simsilica.lemur.GuiGlobals; +import com.simsilica.lemur.component.QuadBackgroundComponent; import pp.mdga.client.MdgaApp; -import java.util.HashMap; -import java.util.Map; - -/** - * Base class for dialogs in the game. - */ public abstract class Dialog { + protected MdgaApp app; - protected MdgaApp app; // Reference to the MdgaApp - protected Container dialogContainer; // Lemur container for the dialog UI - private boolean isVisible; // Visibility flag for the dialog - protected Map buttons; // Map to store buttons by their IDs - - /** - * Constructor for the dialog. - * @param app The MdgaApp instance to attach this dialog to. - */ public Dialog(MdgaApp app) { this.app = app; - this.buttons = new HashMap<>(); - - // Initialize Lemur GUI system if not already done - GuiGlobals.initialize(app); - - // Create the dialog container - dialogContainer = new Container(); - dialogContainer.setLocalTranslation(100, 500, 0); // Default position, can be adjusted - buildDialogContents(dialogContainer); } - /** - * Abstract method for building the dialog contents. - * Subclasses must override this to define their specific UI. - * - * @param container The container to add UI elements to. - */ - protected abstract void buildDialogContents(Container container); - - /** - * Adds a button to the dialog. - * - * @param id Unique ID for the button. - * @param name Display name of the button. - * @param container The container to which the button is added. - * @return The created Button. - */ - protected Button addButton(String id, String name, Container container) { - Button button = new Button(name); - buttons.put(id, button); - container.addChild(button); - return button; - } - - /** - * Gets a button by its ID. - * - * @param id The ID of the button. - * @return The Button, or null if not found. - */ - public Button getButton(String id) { - return buttons.get(id); - } - - /** - * Shows the dialog by attaching it to the GUI node of the MdgaApp. - */ - public void show() { - if (!isVisible) { - app.getGuiNode().attachChild(dialogContainer); - isVisible = true; - } - } - - /** - * Hides the dialog by detaching it from the GUI node of the MdgaApp. - */ - public void hide() { - if (isVisible) { - dialogContainer.removeFromParent(); - isVisible = false; - } - } - - /** - * Cleans up resources used by the dialog. - * Call this when the dialog is no longer needed. - */ - public void cleanup() { - hide(); - buttons.clear(); - dialogContainer = null; - } + public abstract void show(); + public abstract void hide(); + public abstract void addButton(MdgaButton button); } + diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/DialogView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/DialogView.java deleted file mode 100644 index 88d6b76a..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/DialogView.java +++ /dev/null @@ -1,26 +0,0 @@ -package pp.mdga.client.Dialog; - -import pp.dialog.DialogManager; -import pp.mdga.client.MdgaApp; - -public class DialogView { - private MdgaApp app; - - private DialogManager dialogManager = new DialogManager(app); - - private StartDialog dialog; - - public DialogView(MdgaApp app) { - this.app = app; - } - - DialogManager getDialogManager() { - return dialogManager; - } - - public void mainMenu() { - //dialogManager = new DialogManager(app); - //di - //MainMenuDialog mainMenuDialog = new MainMenuDialog(app); - } -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/HorizontalButtonDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/HorizontalButtonDialog.java new file mode 100644 index 00000000..3f5c7cce --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/HorizontalButtonDialog.java @@ -0,0 +1,39 @@ +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.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class HorizontalButtonDialog extends Dialog { + private Node row = new Node(); + + public HorizontalButtonDialog(MdgaApp app) { + super(app); + + //QuadBackgroundComponent quad = new QuadBackgroundComponent(ColorRGBA.Gray); + //quad.setMargin(10, 10); + //container.setBackground(quad); + } + + @Override + public void show() { + app.getGuiNode().attachChild(row); + + row.setLocalTranslation(app.getCamera().getWidth() / 2, app.getCamera().getHeight() / 2, 0); + } + + @Override + public void hide() { + app.getGuiNode().detachChild(row); + } + + @Override + public void addButton(MdgaButton button) { + row.attachChild(button.getButton()); + } +} + + 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 deleted file mode 100644 index 917a9401..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/InterruptDialog.java +++ /dev/null @@ -1,4 +0,0 @@ -package pp.mdga.client.Dialog; - -public class InterruptDialog { -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MdgaButton.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MdgaButton.java new file mode 100644 index 00000000..3fef409e --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MdgaButton.java @@ -0,0 +1,49 @@ +package pp.mdga.client.Dialog; + +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.component.QuadBackgroundComponent; + + +public class MdgaButton { + protected final ColorRGBA COLOR_DEFAULT = ColorRGBA.Gray; + protected final ColorRGBA COLOR_HOVER = ColorRGBA.DarkGray; + + private Button button; + + public MdgaButton(String label, Runnable action, Vector3f size) { + button = new Button(label); + + button.addClickCommands(source -> action.run()); + button.setSize(size); + + QuadBackgroundComponent background = new QuadBackgroundComponent(COLOR_DEFAULT); + background.setMargin(5, 5); + button.setBackground(background); + + button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOn, (source) -> { + QuadBackgroundComponent hoverBackground = new QuadBackgroundComponent(COLOR_HOVER); + hoverBackground.setMargin(5, 5); + source.setBackground(hoverBackground); + }); + + button.addCommands(com.simsilica.lemur.Button.ButtonAction.HighlightOff, (source) -> { + QuadBackgroundComponent normalBackground = new QuadBackgroundComponent(COLOR_DEFAULT); + normalBackground.setMargin(5, 5); + source.setBackground(normalBackground); + }); + } + + public void setLocalTranslation(Vector3f pos) { + button.setLocalTranslation(pos); + } + + public void setSize(Vector3f size) { + button.setSize(size); + } + + public Button getButton() { + return button; + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MenuDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MenuDialog.java deleted file mode 100644 index 0ec98ab0..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/MenuDialog.java +++ /dev/null @@ -1,5 +0,0 @@ -package pp.mdga.client.Dialog; - -public class MenuDialog { - -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/NetworkDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/NetworkDialog.java deleted file mode 100644 index 020d69dc..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/NetworkDialog.java +++ /dev/null @@ -1,5 +0,0 @@ -package pp.mdga.client.Dialog; - -public class NetworkDialog { - -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/SoundDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/SoundDialog.java deleted file mode 100644 index 1876c976..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/SoundDialog.java +++ /dev/null @@ -1,31 +0,0 @@ -package pp.mdga.client.Dialog; - -import com.jme3.scene.Node; -import com.simsilica.lemur.Container; -import com.simsilica.lemur.Label; -import com.simsilica.lemur.input.Button; -import pp.mdga.client.MdgaApp; - -public class SoundDialog extends Dialog { - - public SoundDialog(MdgaApp app) { - super(app); - } - - @Override - protected void buildDialogContents(Container container) { - // Add a title - container.addChild(new Label("Settings")); - - // Add buttons with ID and name - addButton("volume_up", "Increase Volume", container) - .addClickCommands(source -> System.out.println("Volume increased")); - - addButton("volume_down", "Decrease Volume", container) - .addClickCommands(source -> System.out.println("Volume decreased")); - - // Add a close button - addButton("close", "Close", container) - .addClickCommands(source -> hide()); // Close the dialog - } -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/StartDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/StartDialog.java deleted file mode 100644 index 52ebb26e..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/StartDialog.java +++ /dev/null @@ -1,13 +0,0 @@ -package pp.mdga.client.Dialog; - -import com.simsilica.lemur.Checkbox; -import com.simsilica.lemur.Container; -import com.simsilica.lemur.Label; -import com.simsilica.lemur.component.SpringGridLayout; -import pp.dialog.DialogBuilder; -import pp.dialog.SimpleDialog; -import pp.mdga.client.MdgaApp; - -public class StartDialog { - -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VerticalButtonDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VerticalButtonDialog.java new file mode 100644 index 00000000..b862a14e --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VerticalButtonDialog.java @@ -0,0 +1,45 @@ +package pp.mdga.client.Dialog; + +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.Container; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import pp.mdga.client.MdgaApp; + +public class VerticalButtonDialog extends Dialog { + private Container container; + + public VerticalButtonDialog(MdgaApp app) { + super(app); + + container = new Container(); + + QuadBackgroundComponent quad = new QuadBackgroundComponent(ColorRGBA.Gray); + quad.setMargin(10, 10); + container.setBackground(quad); + } + + @Override + public void show() { + app.getGuiNode().attachChild(container); + + container.setLocalTranslation( + app.getCamera().getWidth() / 2 - container.getPreferredSize().x / 2, + app.getCamera().getHeight() / 2 + container.getPreferredSize().y / 2, + 0 + ); + } + + @Override + public void hide() { + app.getGuiNode().detachChild(container); + } + + @Override + public void addButton(MdgaButton button) { + container.addChild(button.getButton()); + } +} + + diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VideoDialog.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VideoDialog.java deleted file mode 100644 index ea6556f1..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Dialog/VideoDialog.java +++ /dev/null @@ -1,5 +0,0 @@ -package pp.mdga.client.Dialog; - -public class VideoDialog { - -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/GameView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/GameView.java deleted file mode 100644 index 9d692e1d..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/GameView.java +++ /dev/null @@ -1,24 +0,0 @@ -package pp.mdga.client; - -import pp.mdga.client.Board.BoardHandler; - -public class GameView extends MdgaView { - private BoardHandler boardHandler; - - public GameView(MdgaApp app) { - super(app); - - boardHandler = new BoardHandler(app); - } - - @Override - public void enter() { - boardHandler.init(); - } - - @Override - public void leave() { - rootNode.detachAllChildren(); - app.getGuiNode().detachChild(rootNode); - } -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/LobbyView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/LobbyView.java deleted file mode 100644 index b4b5ee1c..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/LobbyView.java +++ /dev/null @@ -1,76 +0,0 @@ -package pp.mdga.client; - -import com.jme3.material.Material; -import com.jme3.math.ColorRGBA; -import com.jme3.scene.Geometry; -import com.jme3.scene.shape.Quad; - -/** - * Lobby view, allowing players to choose a color. - */ -public class LobbyView extends MdgaView { - - public LobbyView(MdgaApp app) { - super(app); - } - - @Override - public void enter() { - // Add a background - Geometry background = createBackground("lobby.png"); - rootNode.attachChild(background); - - // Add color selection boxes - float boxSize = 200; - float spacing = 60; - float totalWidth = 4 * boxSize + 3 * spacing; - float startX = (app.getCamera().getWidth() - totalWidth) / 2; - - for (int i = 0; i < 4; i++) { - //Geometry colorBox = createColorBox(startX + i * (boxSize + spacing), app.getCamera().getHeight() / 2 - boxSize / 2, boxSize); - //rootNode.attachChild(colorBox); - } - - app.getGuiNode().attachChild(rootNode); - } - - @Override - public void leave() { - rootNode.detachAllChildren(); - app.getGuiNode().detachChild(rootNode); - } - - /** - * Creates a background geometry with the given texture. - * - * @param texturePath The path to the background texture. - * @return The Geometry for the background. - */ - private Geometry createBackground(String texturePath) { - Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); - Geometry geom = new Geometry("Background", quad); - Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - mat.setTexture("ColorMap", app.getAssetManager().loadTexture(texturePath)); - geom.setMaterial(mat); - geom.setLocalTranslation(0, 0, -1); // Slightly behind other UI elements - return geom; - } - - /** - * Creates a color selection box. - * - * @param x The x-coordinate of the box. - * @param y The y-coordinate of the box. - * @param size The size of the box. - * @return The Geometry for the box. - */ - private Geometry createColorBox(float x, float y, float size) { - Quad quad = new Quad(size, size); - Geometry geom = new Geometry("ColorBox", quad); - Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - mat.setColor("Color", ColorRGBA.Gray); // Example texture/color - geom.setMaterial(mat); - geom.setLocalTranslation(x, y, 0); - return geom; - } -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MainMenuView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MainMenuView.java deleted file mode 100644 index 267a90be..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MainMenuView.java +++ /dev/null @@ -1,68 +0,0 @@ -package pp.mdga.client; - -import com.jme3.material.Material; -import com.jme3.scene.Geometry; -import com.jme3.scene.shape.Quad; -import com.simsilica.lemur.Button; -import com.simsilica.lemur.Container; -import com.simsilica.lemur.Label; - -/** - * Main menu view, providing options to host a game, join a game, or exit. - */ -public class MainMenuView extends MdgaView { - - private Container menuContainer; // Lemur container for menu options - - public MainMenuView(MdgaApp app) { - super(app); - } - - @Override - public void enter() { - // Add a background - Geometry background = createBackground("powercards.png"); - rootNode.attachChild(background); - - // Create a menu container - menuContainer = new Container(); - menuContainer.setLocalTranslation(300, app.getCamera().getHeight() - 200, 0); - - // Add menu options - menuContainer.addChild(new Label("Main Menu")); - - Button hostGameButton = menuContainer.addChild(new Button("Host Game")); - hostGameButton.addClickCommands(source -> System.out.println("Hosting game...")); - - Button joinGameButton = menuContainer.addChild(new Button("Join Game")); - joinGameButton.addClickCommands(source -> app.enter(MdgaState.LOBBY)); - - Button exitButton = menuContainer.addChild(new Button("Exit")); - exitButton.addClickCommands(source -> app.stop()); - - rootNode.attachChild(menuContainer); - app.getGuiNode().attachChild(rootNode); - } - - @Override - public void leave() { - rootNode.detachAllChildren(); - app.getGuiNode().detachChild(rootNode); - } - - /** - * Creates a background geometry with the given texture. - * - * @param texturePath The path to the background texture. - * @return The Geometry for the background. - */ - private Geometry createBackground(String texturePath) { - Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); - Geometry geom = new Geometry("Background", quad); - Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - mat.setTexture("ColorMap", app.getAssetManager().loadTexture(texturePath)); - geom.setMaterial(mat); - geom.setLocalTranslation(0, 0, -1); // Slightly behind other UI elements - return geom; - } -} 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 73939f37..f79690d9 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 @@ -4,11 +4,9 @@ import com.jme3.system.NanoTimer; import com.simsilica.lemur.GuiGlobals; import pp.mdga.client.Acoustic.AcousticHandler; -import pp.mdga.client.Acoustic.MdgaSound; import pp.mdga.client.Animation.AnimationHandler; import com.jme3.system.AppSettings; -import pp.mdga.client.Board.BoardHandler; -import pp.mdga.client.Dialog.DialogView; +import pp.mdga.client.View.*; public class MdgaApp extends SimpleApplication { private AnimationHandler animationHandler; @@ -53,10 +51,10 @@ public void simpleUpdate(float tpf) { switch (state) { case LOBBY: - enter(MdgaState.GAME); + //enter(MdgaState.GAME); break; case GAME: - enter(MdgaState.CEREMONY); + //enter(MdgaState.CEREMONY); break; } } @@ -70,7 +68,7 @@ public void enter(MdgaState state) { switch (state) { case MAIN: - view = new MainMenuView(this); + view = new MainView(this); break; case LOBBY: view = new LobbyView(this); diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaView.java deleted file mode 100644 index adbe6a8a..00000000 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaView.java +++ /dev/null @@ -1,30 +0,0 @@ -package pp.mdga.client; - -import com.jme3.scene.Node; - -public abstract class MdgaView { - protected MdgaApp app; // Reference to the game application - protected Node rootNode; // Node for the state-specific UI elements - - /** - * Constructor for MdgaView. - * - * @param app The MdgaApp instance. - */ - public MdgaView(MdgaApp app) { - this.app = app; - this.rootNode = new Node("StateViewRoot"); - } - - /** - * Called when entering this state. - * Subclasses should override this method to define specific behavior. - */ - public abstract void enter(); - - /** - * Called when leaving this state. - * Subclasses should override this method to define specific behavior. - */ - public abstract void leave(); -} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/CeremonyView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/CeremonyView.java similarity index 74% rename from Projekte/mdga/client/src/main/java/pp/mdga/client/CeremonyView.java rename to Projekte/mdga/client/src/main/java/pp/mdga/client/View/CeremonyView.java index 7fa4caf9..847f867d 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/CeremonyView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/CeremonyView.java @@ -1,4 +1,4 @@ -package pp.mdga.client; +package pp.mdga.client.View; import com.jme3.material.Material; import com.jme3.scene.Geometry; @@ -7,6 +7,8 @@ import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; import com.simsilica.lemur.Button; +import pp.mdga.client.MdgaApp; +import pp.mdga.client.MdgaState; /** * The CeremonyView manages two sub-states: the Award Ceremony and the Statistics screen. @@ -27,7 +29,7 @@ public CeremonyView(MdgaApp app) { } @Override - public void enter() { + public void onEnter() { // Initialize sub-states setupAwardCeremony(); setupStatistics(); @@ -37,10 +39,7 @@ public void enter() { } @Override - public void leave() { - rootNode.detachAllChildren(); - app.getGuiNode().detachChild(rootNode); - } + public void onLeave() {} /** * Sets up the Award Ceremony sub-state. @@ -98,34 +97,18 @@ private void setupStatistics() { * @param subState The target sub-state. */ private void switchToSubState(SubState subState) { - rootNode.detachAllChildren(); + //rootNode.detachAllChildren(); currentSubState = subState; switch (subState) { case AWARD_CEREMONY: - rootNode.attachChild(awardCeremonyNode); + node.attachChild(awardCeremonyNode); break; case STATISTICS: - rootNode.attachChild(statisticsNode); + node.attachChild(statisticsNode); break; } - app.getGuiNode().attachChild(rootNode); - } - - /** - * Creates a background geometry with the given texture. - * - * @param texturePath The path to the background texture. - * @return The Geometry for the background. - */ - private Geometry createBackground(String texturePath) { - Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); - Geometry geom = new Geometry("Background", quad); - Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - mat.setTexture("ColorMap", app.getAssetManager().loadTexture(texturePath)); - geom.setMaterial(mat); - geom.setLocalTranslation(0, 0, -1); // Slightly behind other UI elements - return geom; + //app.getGuiNode().attachChild(rootNode); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/View/GameView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/GameView.java new file mode 100644 index 00000000..299ebe3a --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/GameView.java @@ -0,0 +1,35 @@ +package pp.mdga.client.View; + +import com.jme3.math.Vector3f; +import com.simsilica.lemur.Button; +import pp.mdga.client.Board.BoardHandler; +import pp.mdga.client.Dialog.MdgaButton; +import pp.mdga.client.MdgaApp; +import pp.mdga.client.MdgaState; + +public class GameView extends MdgaView { + private BoardHandler boardHandler; + private MdgaButton button; + + public GameView(MdgaApp app) { + super(app); + + this.boardHandler = new BoardHandler(app); + this.button = new MdgaButton("Weiter", () -> app.enter(MdgaState.CEREMONY), new Vector3f(150, 200, 0)); + } + + @Override + public void enter() { + boardHandler.init(); + + button.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 200, 100, 0)); + app.getGuiNode().attachChild(button.getButton()); + } + + @Override + public void leave() { + app.getGuiNode().detachChild(button.getButton()); + + boardHandler.shutdown(); + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/View/LobbyView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/LobbyView.java new file mode 100644 index 00000000..20441ae5 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/LobbyView.java @@ -0,0 +1,64 @@ +package pp.mdga.client.View; + +import com.jme3.input.InputManager; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.Node; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.Container; +import com.simsilica.lemur.GuiGlobals; +import com.simsilica.lemur.style.ElementId; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.style.Styles; +import pp.mdga.client.Dialog.HorizontalButtonDialog; +import pp.mdga.client.Dialog.MdgaButton; +import pp.mdga.client.Dialog.VerticalButtonDialog; +import pp.mdga.client.MdgaApp; +import pp.mdga.client.MdgaState; +import pp.mdga.game.Color; + +public class LobbyView extends MdgaView { + private Geometry background; + HorizontalButtonDialog dialog; + + public LobbyView(MdgaApp app) { + super(app); + + background = createBackground("lobby.png"); + node.attachChild(background); + + dialog = new HorizontalButtonDialog(app); + + float buttonWidth = 150; + float spacing = 60; + float startX = -((3 * buttonWidth + 2 * spacing) / 2); + float currentX = startX; + + for (int i = 1; i <= 4; i++) { + Color color = Color.values()[i-1]; + MdgaButton button = new MdgaButton(color.name(), () -> app.enter(MdgaState.GAME), new Vector3f(150, 200, 0)); + + button.setLocalTranslation(new Vector3f(currentX, 0, 0)); + currentX += buttonWidth + spacing; + dialog.addButton(button); + } + + //Button weiterButton = createButton("Weiter", new Vector3f(150, 50, 0), ColorRGBA.Blue, ColorRGBA.Cyan); + + //weiterButton.setLocalTranslation(app.getCamera().getWidth() - 200, 100, 0); + } + + @Override + public void onEnter() { + dialog.show(); + } + + @Override + public void onLeave() { + dialog.hide(); + } +} + + + diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/View/MainView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/MainView.java new file mode 100644 index 00000000..f6cd2af1 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/MainView.java @@ -0,0 +1,52 @@ +package pp.mdga.client.View; + +import com.jme3.material.Material; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Quad; +import com.simsilica.lemur.*; +import pp.mdga.client.Dialog.MdgaButton; +import pp.mdga.client.Dialog.VerticalButtonDialog; +import pp.mdga.client.MdgaApp; +import pp.mdga.client.MdgaState; + +import com.jme3.material.Material; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Quad; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.Container; +import com.simsilica.lemur.Label; + +import com.jme3.material.Material; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Quad; + +public class MainView extends MdgaView { + private Geometry background; + VerticalButtonDialog dialog; + + public MainView(MdgaApp app) { + super(app); + + background = createBackground("powercards.png"); + node.attachChild(background); + + Vector3f size = new Vector3f(1, 1, 1); + dialog = new VerticalButtonDialog(app); + dialog.addButton(new MdgaButton("Spiel beitreten", () -> app.enter(MdgaState.LOBBY), size)); + dialog.addButton(new MdgaButton("Spiel hosten", () -> app.enter(MdgaState.LOBBY), size)); + dialog.addButton(new MdgaButton("Einstellungen", () -> System.out.println("Einstellungen"), size)); + dialog.addButton(new MdgaButton("Spiel beenden", () -> app.stop(), size)); + } + + @Override + public void onEnter() { + dialog.show(); + } + + @Override + public void onLeave() { + dialog.hide(); + } +} + diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/View/MdgaView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/MdgaView.java new file mode 100644 index 00000000..a85ba6bf --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/View/MdgaView.java @@ -0,0 +1,46 @@ +package pp.mdga.client.View; + +import com.jme3.asset.TextureKey; +import com.jme3.material.Material; +import com.jme3.scene.Geometry; +import com.jme3.scene.Node; +import com.jme3.scene.shape.Quad; +import com.jme3.texture.Texture; +import pp.mdga.client.MdgaApp; + +public abstract class MdgaView { + protected MdgaApp app; + protected Node node; + + public MdgaView(MdgaApp app) { + this.app = app; + this.node = new Node(); + } + + public void enter() { + app.getGuiNode().attachChild(node); + + onEnter(); + } + + public void leave() { + onLeave(); + + app.getGuiNode().detachChild(node); + } + + protected void onEnter() {} + protected void onLeave() {} + + protected Geometry createBackground(String texturePath) { + TextureKey key = new TextureKey(texturePath, true); + Texture backgroundTexture = app.getAssetManager().loadTexture(key); + Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); + Geometry background = new Geometry("Background", quad); + Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); + mat.setTexture("ColorMap", backgroundTexture); + background.setMaterial(mat); + background.setLocalTranslation(0, 0, -1); + return background; + } +} diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java index f0a863b7..46754cbb 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/DetermineStartPlayer.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class DetermineStartPlayer extends Game { +public class DetermineStartPlayer { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java index 713aee9a..6cfbf762 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Spectator.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class Spectator extends Game { +public class Spectator { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java index 5dc54c3e..29628668 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Turn.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class Turn extends Game { +public class Turn { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java b/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java index 82791f28..684902ee 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/client/Waiting.java @@ -1,4 +1,4 @@ package pp.mdga.client; -public class Waiting extends Game { +public class Waiting { } diff --git a/Projekte/mdga/model/src/main/java/pp.mdga/server/DetermineStartPlayer.java b/Projekte/mdga/model/src/main/java/pp.mdga/server/DetermineStartPlayer.java index 51cb17fc..b577c5cd 100644 --- a/Projekte/mdga/model/src/main/java/pp.mdga/server/DetermineStartPlayer.java +++ b/Projekte/mdga/model/src/main/java/pp.mdga/server/DetermineStartPlayer.java @@ -1,4 +1,4 @@ package pp.mdga.server; -public class DetermineStartPlayer extends Game { +public class DetermineStartPlayer { }