Work on Dialogs
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.queue.RenderQueue;
|
import com.jme3.renderer.queue.RenderQueue;
|
||||||
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.control.AbstractControl;
|
import com.jme3.scene.control.AbstractControl;
|
||||||
import com.jme3.shadow.DirectionalLightShadowRenderer;
|
import com.jme3.shadow.DirectionalLightShadowRenderer;
|
||||||
@@ -29,6 +30,8 @@ public class BoardHandler {
|
|||||||
|
|
||||||
private Map<Color, List<AssetOnMap>> playerMap;
|
private Map<Color, List<AssetOnMap>> playerMap;
|
||||||
|
|
||||||
|
private Node node = new Node();
|
||||||
|
|
||||||
public BoardHandler(MdgaApp app) {
|
public BoardHandler(MdgaApp app) {
|
||||||
assert (app != null) : "app is null";
|
assert (app != null) : "app is null";
|
||||||
|
|
||||||
@@ -41,6 +44,12 @@ public BoardHandler(MdgaApp app) {
|
|||||||
public void init() {
|
public void init() {
|
||||||
initMap();
|
initMap();
|
||||||
initCamera();
|
initCamera();
|
||||||
|
|
||||||
|
app.getRootNode().attachChild(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
app.getRootNode().detachChild(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap) {
|
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");
|
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
|
||||||
mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName));
|
mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(texName));
|
||||||
model.setMaterial(mat);
|
model.setMaterial(mat);
|
||||||
app.getRootNode().attachChild(model);
|
node.attachChild(model);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,101 +1,21 @@
|
|||||||
package pp.mdga.client.Dialog;
|
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.Button;
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.GuiGlobals;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
import pp.mdga.client.MdgaApp;
|
import pp.mdga.client.MdgaApp;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for dialogs in the game.
|
|
||||||
*/
|
|
||||||
public abstract class Dialog {
|
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<String, Button> 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) {
|
public Dialog(MdgaApp app) {
|
||||||
this.app = 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public abstract void show();
|
||||||
* Abstract method for building the dialog contents.
|
public abstract void hide();
|
||||||
* Subclasses must override this to define their specific UI.
|
public abstract void addButton(MdgaButton button);
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package pp.mdga.client.Dialog;
|
|
||||||
|
|
||||||
public class InterruptDialog {
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pp.mdga.client.Dialog;
|
|
||||||
|
|
||||||
public class MenuDialog {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pp.mdga.client.Dialog;
|
|
||||||
|
|
||||||
public class NetworkDialog {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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 {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package pp.mdga.client.Dialog;
|
|
||||||
|
|
||||||
public class VideoDialog {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,11 +4,9 @@
|
|||||||
import com.jme3.system.NanoTimer;
|
import com.jme3.system.NanoTimer;
|
||||||
import com.simsilica.lemur.GuiGlobals;
|
import com.simsilica.lemur.GuiGlobals;
|
||||||
import pp.mdga.client.Acoustic.AcousticHandler;
|
import pp.mdga.client.Acoustic.AcousticHandler;
|
||||||
import pp.mdga.client.Acoustic.MdgaSound;
|
|
||||||
import pp.mdga.client.Animation.AnimationHandler;
|
import pp.mdga.client.Animation.AnimationHandler;
|
||||||
import com.jme3.system.AppSettings;
|
import com.jme3.system.AppSettings;
|
||||||
import pp.mdga.client.Board.BoardHandler;
|
import pp.mdga.client.View.*;
|
||||||
import pp.mdga.client.Dialog.DialogView;
|
|
||||||
|
|
||||||
public class MdgaApp extends SimpleApplication {
|
public class MdgaApp extends SimpleApplication {
|
||||||
private AnimationHandler animationHandler;
|
private AnimationHandler animationHandler;
|
||||||
@@ -53,10 +51,10 @@ public void simpleUpdate(float tpf) {
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case LOBBY:
|
case LOBBY:
|
||||||
enter(MdgaState.GAME);
|
//enter(MdgaState.GAME);
|
||||||
break;
|
break;
|
||||||
case GAME:
|
case GAME:
|
||||||
enter(MdgaState.CEREMONY);
|
//enter(MdgaState.CEREMONY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +68,7 @@ public void enter(MdgaState state) {
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case MAIN:
|
case MAIN:
|
||||||
view = new MainMenuView(this);
|
view = new MainView(this);
|
||||||
break;
|
break;
|
||||||
case LOBBY:
|
case LOBBY:
|
||||||
view = new LobbyView(this);
|
view = new LobbyView(this);
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client.View;
|
||||||
|
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
import com.simsilica.lemur.Button;
|
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.
|
* The CeremonyView manages two sub-states: the Award Ceremony and the Statistics screen.
|
||||||
@@ -27,7 +29,7 @@ public CeremonyView(MdgaApp app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void onEnter() {
|
||||||
// Initialize sub-states
|
// Initialize sub-states
|
||||||
setupAwardCeremony();
|
setupAwardCeremony();
|
||||||
setupStatistics();
|
setupStatistics();
|
||||||
@@ -37,10 +39,7 @@ public void enter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void leave() {
|
public void onLeave() {}
|
||||||
rootNode.detachAllChildren();
|
|
||||||
app.getGuiNode().detachChild(rootNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the Award Ceremony sub-state.
|
* Sets up the Award Ceremony sub-state.
|
||||||
@@ -98,34 +97,18 @@ private void setupStatistics() {
|
|||||||
* @param subState The target sub-state.
|
* @param subState The target sub-state.
|
||||||
*/
|
*/
|
||||||
private void switchToSubState(SubState subState) {
|
private void switchToSubState(SubState subState) {
|
||||||
rootNode.detachAllChildren();
|
//rootNode.detachAllChildren();
|
||||||
currentSubState = subState;
|
currentSubState = subState;
|
||||||
|
|
||||||
switch (subState) {
|
switch (subState) {
|
||||||
case AWARD_CEREMONY:
|
case AWARD_CEREMONY:
|
||||||
rootNode.attachChild(awardCeremonyNode);
|
node.attachChild(awardCeremonyNode);
|
||||||
break;
|
break;
|
||||||
case STATISTICS:
|
case STATISTICS:
|
||||||
rootNode.attachChild(statisticsNode);
|
node.attachChild(statisticsNode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
app.getGuiNode().attachChild(rootNode);
|
//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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
public class DetermineStartPlayer extends Game {
|
public class DetermineStartPlayer {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
public class Spectator extends Game {
|
public class Spectator {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
public class Turn extends Game {
|
public class Turn {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package pp.mdga.client;
|
package pp.mdga.client;
|
||||||
|
|
||||||
public class Waiting extends Game {
|
public class Waiting {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package pp.mdga.server;
|
package pp.mdga.server;
|
||||||
|
|
||||||
public class DetermineStartPlayer extends Game {
|
public class DetermineStartPlayer {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user