Add host&join menu and work on modelSyncronizer

This commit is contained in:
Felix
2024-11-21 16:14:06 +01:00
parent 02ce0df614
commit c1f4ea480c
13 changed files with 578 additions and 61 deletions

View File

@@ -3,17 +3,18 @@
import com.jme3.app.SimpleApplication;
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.view.*;
import pp.mdga.game.Color;
import pp.mdga.notification.TskSelectNotification;
public class MdgaApp extends SimpleApplication {
private AnimationHandler animationHandler;
private AcousticHandler acousticHandler;
private NotificationSynchronizer notificationSynchronizer;
private InputSyncronizer inputSyncronizer;
private ModelSyncronizer modelSyncronizer;
MdgaView view = null;
private MdgaState state = MdgaState.MAIN;
@@ -45,6 +46,7 @@ public void simpleInitApp() {
acousticHandler = new AcousticHandler(this);
notificationSynchronizer = new NotificationSynchronizer(this);
inputSyncronizer = new InputSyncronizer(this);
modelSyncronizer = new ModelSyncronizer(this);
inputManager.deleteMapping("SIMPLEAPP_Exit");
GuiGlobals.initialize(this);
@@ -57,6 +59,7 @@ public void simpleUpdate(float tpf) {
inputSyncronizer.update();
view.update();
acousticHandler.update();
notificationSynchronizer.update();
}
public void enter(MdgaState state) {
@@ -88,6 +91,10 @@ public void enter(MdgaState state) {
view.enter();
}
public void afteGameCleanup() {
//TODO
}
public AnimationHandler getAnimationHandler() {
return animationHandler;
}
@@ -99,10 +106,14 @@ public AcousticHandler getAcousticHandler() {
public MdgaState getState() {return state; }
public float getResolutionFactor() {
return resolutionFactor;
return resolutionFactor;
}
public MdgaView getView() {
return view;
return view;
}
public ModelSyncronizer getModelSyncronizer() {
return modelSyncronizer;
}
}

View File

@@ -1,4 +1,72 @@
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() {
//TODO call from somewhere
System.out.println("setName");
}
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);
}
}

View File

@@ -1,5 +1,6 @@
package pp.mdga.client;
import pp.mdga.client.view.GameView;
import pp.mdga.client.view.LobbyView;
import pp.mdga.notification.*;
@@ -8,12 +9,17 @@
public class NotificationSynchronizer {
private final MdgaApp app;
private ArrayList<Notification> notifications = new ArrayList<>();
NotificationSynchronizer(MdgaApp app) {
this.app = app;
}
void update() {
ArrayList<Notification> notifications = new ArrayList<>();
public void addTestNotification(Notification n) {
notifications.add(n);
}
public void update() {
//TODO fetch model notifications
for (Notification n : notifications) {
@@ -45,14 +51,14 @@ private void handleMain(Notification notification) {
}
private void handleLobby(Notification notification) {
LobbyView view = (LobbyView) app.getView();
LobbyView lobbyView = (LobbyView) app.getView();
if (notification instanceof TskSelectNotification) {
TskSelectNotification n = (TskSelectNotification)notification;
lobbyView.setTaken(n.getColor(), true, n.isSelf(), n.getName());
} else if (notification instanceof TskUnselectNotification) {
TskUnselectNotification n = (TskUnselectNotification)notification;
lobbyView.setTaken(n.getColor(), false, false, null);
} else if (notification instanceof GameNotification) {
app.enter(MdgaState.GAME);
} else {
@@ -61,6 +67,8 @@ private void handleLobby(Notification notification) {
}
private void handleGame(Notification notification) {
GameView gameView = (GameView) app.getView();
if (notification instanceof AcquireCardNotification) {
// Handle AcquireCardNotification
} else if (notification instanceof ActivePlayerNotification) {
@@ -74,15 +82,19 @@ private void handleGame(Notification notification) {
} else if (notification instanceof DrawCardNotification) {
// Handle DrawCardNotification
} else if (notification instanceof HomeMoveNotification) {
// Handle HomeMoveNotification
HomeMoveNotification n = (HomeMoveNotification)notification;
gameView.getBoardHandler().moveHomePiece(n.getPieceId(), n.getHomeIndex());
} else if (notification instanceof InterruptNotification) {
// Handle InterruptNotification
} else if (notification instanceof MovePieceNotification) {
// Handle MovePieceNotification
MovePieceNotification n = (MovePieceNotification)notification;
//gameView.getBoardHandler().movePiece(n.get); //TODO
} else if (notification instanceof MoveThrowPieceNotification) {
// Handle MoveThrowPieceNotification
MoveThrowPieceNotification n = (MoveThrowPieceNotification)notification;
//gameView.getBoardHandler().throwPiece(n.); //TODO
} else if (notification instanceof NoShieldNotification) {
// Handle NoShieldNotification
NoShieldNotification n = (NoShieldNotification)notification;
gameView.getBoardHandler().unshieldPiece(n.getPieceId());
} else if (notification instanceof PieceInGameNotification) {
// Handle PieceInGameNotification
} else if (notification instanceof PlayCardNotification) {
@@ -98,11 +110,13 @@ private void handleGame(Notification notification) {
} else if (notification instanceof SelectablePiecesNotification) {
// Handle SelectablePiecesNotification
} else if (notification instanceof ShieldActiveNotification) {
// Handle ShieldActiveNotification
ShieldActiveNotification n = (ShieldActiveNotification)notification;
gameView.getBoardHandler().shieldPiece(n.getPieceId());
} else if (notification instanceof ShieldSuppressedNotification) {
// Handle ShieldSuppressedNotification
ShieldSuppressedNotification n = (ShieldSuppressedNotification)notification;
gameView.getBoardHandler().suppressShield(n.getPieceId());
} else if (notification instanceof StartDialogNotification) {
// Handle StartDialogNotification
app.enter(MdgaState.MAIN);
} else if (notification instanceof SwapPieceNotification) {
// Handle SwapPieceNotification
} else if (notification instanceof WaitMoveNotification) {

View File

@@ -0,0 +1,143 @@
package pp.mdga.client.dialog;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
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;
public class HostDialog extends Dialog {
private TextField portInput;
public HostDialog(MdgaApp app, Node node, Runnable backAction) {
super(app, node);
QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray);
quad1.setMargin(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor());
container.setBackground(quad1);
Texture texture = app.getAssetManager().loadTexture("mdga_logo.png");
QuadBackgroundComponent b = new QuadBackgroundComponent(texture);
Panel imagePanel = new Panel();
imagePanel.setBackground(b);
container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4, texture.getImage().getHeight() / 4, 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("");
}
@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
);
}
@Override
public void hide() {
super.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);
}
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);
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);
}
}

View File

@@ -0,0 +1,192 @@
package pp.mdga.client.dialog;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
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 java.util.regex.Pattern;
public class JoinDialog extends Dialog {
private TextField portInput;
private TextField ipInput;
public JoinDialog(MdgaApp app, Node node, Runnable backAction) {
super(app, node);
QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray);
quad1.setMargin(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor());
container.setBackground(quad1);
Texture texture = app.getAssetManager().loadTexture("mdga_logo.png");
QuadBackgroundComponent b = new QuadBackgroundComponent(texture);
Panel imagePanel = new Panel();
imagePanel.setBackground(b);
container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4, texture.getImage().getHeight() / 4, 0));
//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);
}
@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
);
}
@Override
public void hide() {
super.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);
}
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);
}
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);
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);
}
}

View File

@@ -20,19 +20,25 @@ public class LobbyButtonDialog extends Dialog {
private boolean taken = false;
public LobbyButtonDialog(MdgaApp app, Node node, String label, Runnable action, int pos) {
private final String label;
private int val;
public LobbyButtonDialog(MdgaApp app, Node node, String label, int pos) {
super(app, node);
clickCommand = (Button source) -> {
//action.run();
toggleButton();
};
this.pos = pos;
this.label = label;
this.button = new Button(label);
this.button.setFontSize(fontSize);
val = pos;
createNotTakenButton(new Vector3f(170 * app.getResolutionFactor(), 250 * app.getResolutionFactor(), 0));
}
@@ -51,13 +57,17 @@ public void hide() {
super.hide();
}
public void setTaken(boolean isTaken, boolean self) {
public void setTaken(boolean isTaken, boolean self, String name) {
taken = isTaken;
if(isTaken) {
createTakenButton(new Vector3f(170 * app.getResolutionFactor(), 250 * app.getResolutionFactor(), 0), self);
button.setText(label + "\n\n" + name);
} else {
createNotTakenButton(new Vector3f(170 * app.getResolutionFactor(), 250 * app.getResolutionFactor(), 0));
button.setText(label);
}
}
@@ -98,7 +108,12 @@ protected void createNotTakenButton(Vector3f size) {
}
private void toggleButton() {
setTaken(!taken, true);
if(taken) {
app.getModelSyncronizer().unselectTsk();
}
else {
app.getModelSyncronizer().selectTsk(Color.values()[val]);
}
}
protected void createTakenButton(Vector3f size, boolean self) {

View File

@@ -9,10 +9,10 @@
import com.simsilica.lemur.component.SpringGridLayout;
import pp.mdga.client.MdgaApp;
public class InputButtonDialog extends Dialog {
public class StartDialog extends Dialog {
private TextField nameInput;
public InputButtonDialog(MdgaApp app, Node node) {
public StartDialog(MdgaApp app, Node node) {
super(app, node);
QuadBackgroundComponent quad1 = new QuadBackgroundComponent(ColorRGBA.Gray);
@@ -84,5 +84,3 @@ public String getName() {
return nameInput.getText();
}
}

View File

@@ -80,7 +80,7 @@ private void forward() {
enterSub(SubState.STATISTICS);
break;
case STATISTICS:
app.enter(MdgaState.MAIN);
app.getModelSyncronizer().enter(MdgaState.MAIN);
break;
}
}

View File

@@ -2,6 +2,7 @@
import pp.mdga.client.board.BoardHandler;
import pp.mdga.client.board.CameraHandler;
import pp.mdga.client.dialog.SingleButtonLeftDialog;
import pp.mdga.client.dialog.SingleButtonRightDialog;
import pp.mdga.client.MdgaApp;
import pp.mdga.client.MdgaState;
@@ -10,6 +11,7 @@ public class GameView extends MdgaView {
private BoardHandler boardHandler;
private CameraHandler camera;
private SingleButtonLeftDialog leaveButton;
private SingleButtonRightDialog continueButton;
public GameView(MdgaApp app) {
@@ -18,7 +20,9 @@ public GameView(MdgaApp app) {
this.boardHandler = new BoardHandler(app);
this.camera = new CameraHandler(app);
continueButton = new SingleButtonRightDialog(app, node, "Weiter", () -> app.enter(MdgaState.CEREMONY));
leaveButton = new SingleButtonLeftDialog(app, settingsNode, "Verlassen", () -> leaveGame());
continueButton = new SingleButtonRightDialog(app, node, "Weiter", () -> app.getModelSyncronizer().enter(MdgaState.CEREMONY));
}
@Override
@@ -36,4 +40,26 @@ public void onLeave() {
camera.shutdown();
boardHandler.shutdown();
}
@Override
protected void enterExtendedSettings() {
leaveButton.show();
}
@Override
protected void leaveExtendedSettings() {
leaveButton.hide();
}
private void leaveGame() {
leaveSettings(false);
app.getModelSyncronizer().leave();
app.afteGameCleanup();
}
public BoardHandler getBoardHandler() {
return boardHandler;
}
}

View File

@@ -24,13 +24,13 @@ public LobbyView(MdgaApp app) {
background = createBackground("lobby.png");
node.attachChild(background);
readyButton = new SingleButtonRightDialog(app, node, "Fertig", () -> app.enter(MdgaState.GAME));
leaveButton = new SingleButtonLeftDialog(app, node, "Verlassen", () -> app.enter(MdgaState.MAIN));
readyButton = new SingleButtonRightDialog(app, node, "Fertig", () -> app.getModelSyncronizer().setReady());
leaveButton = new SingleButtonLeftDialog(app, node, "Verlassen", () -> app.getModelSyncronizer().leave());
lobbyButtons.add(new LobbyButtonDialog(app, node, "CIR", () -> System.out.println("cir"), 0));
lobbyButtons.add(new LobbyButtonDialog(app, node, "LUFTWAFFE", () -> System.out.println("lw"), 1));
lobbyButtons.add(new LobbyButtonDialog(app, node, "HEER", () -> System.out.println("heer"), 2));
lobbyButtons.add(new LobbyButtonDialog(app, node, "MARINE", () -> System.out.println("marine"), 3));
lobbyButtons.add(new LobbyButtonDialog(app, node, "HEER", 0));
lobbyButtons.add(new LobbyButtonDialog(app, node, "MARINE", 1));
lobbyButtons.add(new LobbyButtonDialog(app, node, "CIR", 2));
lobbyButtons.add(new LobbyButtonDialog(app, node, "LUFTWAFFE", 3));
}
@Override
@@ -53,10 +53,7 @@ public void onLeave() {
leaveButton.hide();
}
public void setTaken(Color color, boolean isTaken, boolean isSelf) {
lobbyButtons.get(color.ordinal()).setTaken(isTaken, isSelf);
public void setTaken(Color color, boolean isTaken, boolean isSelf, String name) {
lobbyButtons.get(color.ordinal()).setTaken(isTaken, isSelf, name);
}
}

View File

@@ -1,16 +1,19 @@
package pp.mdga.client.view;
import com.jme3.scene.Geometry;
import pp.mdga.client.dialog.InputButtonDialog;
import pp.mdga.client.dialog.Dialog;
import pp.mdga.client.dialog.HostDialog;
import pp.mdga.client.dialog.JoinDialog;
import pp.mdga.client.dialog.StartDialog;
import pp.mdga.client.MdgaApp;
import pp.mdga.client.MdgaState;
import com.jme3.math.Vector3f;
public class MainView extends MdgaView {
private Geometry background;
private InputButtonDialog dialog;
private StartDialog dialog;
private Dialog subDialog;
public MainView(MdgaApp app) {
super(app);
@@ -19,9 +22,9 @@ public MainView(MdgaApp app) {
node.attachChild(background);
Vector3f size = new Vector3f(280, 60, 0);
dialog = new InputButtonDialog(app, node);
dialog.addButton("Spiel beitreten", () -> app.enter(MdgaState.LOBBY), size);
dialog.addButton("Spiel hosten", () -> app.enter(MdgaState.LOBBY), size);
dialog = new StartDialog(app, node);
dialog.addButton("Spiel beitreten", () -> enterJoin(), size);
dialog.addButton("Spiel hosten", () -> enterHost(), size);
dialog.addButton("Einstellungen", () -> enterSettings(false), size);
dialog.addButton("Spiel beenden", () -> app.stop(), size);
}
@@ -34,6 +37,39 @@ public void onEnter() {
@Override
public void onLeave() {
dialog.hide();
if(subDialog != null) {
subDialog.hide();
subDialog = null;
}
}
private void enterJoin() {
subDialog = new JoinDialog(app, node, () -> leaveJoin());
dialog.hide();
subDialog.show();
}
private void leaveJoin() {
subDialog.hide();
dialog.show();
subDialog = null;
}
private void enterHost() {
subDialog = new HostDialog(app, node, () -> leaveHost());
dialog.hide();
subDialog.show();
}
private void leaveHost() {
subDialog.hide();
dialog.show();
subDialog = null;
}
}

View File

@@ -16,13 +16,13 @@ public abstract class MdgaView {
protected MdgaApp app;
protected Node node;
int depth = 0;
boolean isVideo = false;
boolean isAudio = false;
protected int depth = 0;
private boolean isVideo = false;
private boolean isAudio = false;
private Node settingsNode;
private Node audioNode;
private Node videoNode;
protected Node settingsNode;
protected Node audioSettingsNode;
protected Node videoSettingsNode;
private SettingsButtonDialog settingsButton;
@@ -39,8 +39,8 @@ public MdgaView(MdgaApp app) {
this.node = new Node();
this.settingsNode = new Node();
this.audioNode = new Node();
this.videoNode = new Node();
this.audioSettingsNode = new Node();
this.videoSettingsNode = new Node();
this.settingsButton = new SettingsButtonDialog(app, node, "", () -> enterSettings(false));
@@ -48,10 +48,10 @@ public MdgaView(MdgaApp app) {
settingsNode.attachChild(settingsBackground);
this.audioBackground = createBackground("background/lautsprecher.png");
audioNode.attachChild(audioBackground);
audioSettingsNode.attachChild(audioBackground);
this.videoBackground = createBackground("background/monitors.png");
videoNode.attachChild(videoBackground);
videoSettingsNode.attachChild(videoBackground);
Vector3f size = new Vector3f(280, 60, 0);
@@ -60,13 +60,13 @@ public MdgaView(MdgaApp app) {
this.settings.addButton("Audio", () -> enterAudio(), size);
this.settings.addButton("Zurück", () -> leaveSettings(false), size);
this.audio = new SettingsDialog(app, audioNode, "audio_icon.png");
this.audio = new SettingsDialog(app, audioSettingsNode, "audio_icon.png");
this.audio.addSlider("Lautstärke", new PercentRunnable(app.getAcousticHandler()::setMainVolume), size, 5);
this.audio.addSlider("Musik", new PercentRunnable(app.getAcousticHandler()::setMusicVolume), size, 10);
this.audio.addSlider("Sound", new PercentRunnable(app.getAcousticHandler()::setSoundVolume), size, 10);
this.audio.addButton("Zurück", () -> leaveAudio(), size);
this.video = new SettingsDialog(app, videoNode, "monitor.png");
this.video = new SettingsDialog(app, videoSettingsNode, "monitor.png");
this.video.addButton("A", () -> System.out.println("A"), size);
this.video.addButton("B", () -> System.out.println("B"), size);
this.video.addButton("Zurück", () -> leaveVideo(), size);
@@ -107,6 +107,9 @@ protected Geometry createBackground(String texturePath) {
return background;
}
protected void enterExtendedSettings() {}
protected void leaveExtendedSettings() {}
protected void enterSettings(boolean soft) {
leave();
@@ -114,6 +117,8 @@ protected void enterSettings(boolean soft) {
if(!soft) {
depth++;
enterExtendedSettings();
}
settings.show();
@@ -125,6 +130,7 @@ protected void leaveSettings(boolean soft) {
app.getGuiNode().detachChild(settingsNode);
if(!soft) {
leaveExtendedSettings();
enter();
depth--;
}
@@ -136,7 +142,7 @@ protected void enterAudio() {
depth++;
isAudio = true;
app.getGuiNode().attachChild(audioNode);
app.getGuiNode().attachChild(audioSettingsNode);
audio.show();
}
@@ -144,7 +150,7 @@ protected void enterAudio() {
protected void leaveAudio() {
audio.hide();
app.getGuiNode().detachChild(audioNode);
app.getGuiNode().detachChild(audioSettingsNode);
isAudio = false;
depth--;
@@ -155,7 +161,7 @@ protected void leaveAudio() {
protected void enterVideo() {
leaveSettings(true);
app.getGuiNode().attachChild(videoNode);
app.getGuiNode().attachChild(videoSettingsNode);
depth++;
@@ -167,7 +173,7 @@ protected void enterVideo() {
protected void leaveVideo() {
video.hide();
app.getGuiNode().detachChild(videoNode);
app.getGuiNode().detachChild(videoSettingsNode);
depth--;
isVideo = false;

View File

@@ -9,15 +9,18 @@ public class TskSelectNotification extends Notification{
private Color color;
private String name;
private boolean self;
/**
* Constructor.
* @param color the color of the player that is in the game.
* @param name the name of the player that is in the game.
* @param self true if it was the local player selecting the tsk, false otherwise
*/
TskSelectNotification(Color color, String name) {
TskSelectNotification(Color color, String name, boolean self) {
this.color = color;
this.name = name;
this.self = self;
}
/**
@@ -35,4 +38,12 @@ public Color getColor() {
public String getName() {
return name;
}
/**
* Tells if it was the local player selecting this tsk.
* @return ture if it was the local player selecting the tsk.
*/
public boolean isSelf() {
return self;
}
}