mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
change: toggles
This commit is contained in:
@@ -87,11 +87,11 @@ public final class Container {
|
|||||||
return addButton("button", x, runnable);
|
return addButton("button", x, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Label addToggle(String cssClass, String unChecked, String checked, Consumer<Boolean> consumer) {
|
public Label addToggle(String cssClass, String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||||
final Label element = new Label(unChecked);
|
final Label element = new Label(toggled? x2 : x1);
|
||||||
element.getStyleClass().add(cssClass);
|
element.getStyleClass().add(cssClass);
|
||||||
|
|
||||||
final BooleanProperty selected = new SimpleBooleanProperty(false);
|
final BooleanProperty checked = new SimpleBooleanProperty(toggled);
|
||||||
|
|
||||||
element.setOnMouseEntered(_ -> {
|
element.setOnMouseEntered(_ -> {
|
||||||
GlobalEventBus.post(new AppEvents.OnNodeHover());
|
GlobalEventBus.post(new AppEvents.OnNodeHover());
|
||||||
@@ -99,23 +99,23 @@ public final class Container {
|
|||||||
|
|
||||||
element.setOnMouseClicked(_ -> {
|
element.setOnMouseClicked(_ -> {
|
||||||
GlobalEventBus.post(new AppEvents.OnNodeClick());
|
GlobalEventBus.post(new AppEvents.OnNodeClick());
|
||||||
selected.set(!selected.get());
|
checked.set(!checked.get());
|
||||||
|
|
||||||
if (selected.get()) {
|
if (checked.get()) {
|
||||||
element.setText(checked);
|
element.setText(x1);
|
||||||
} else {
|
} else {
|
||||||
element.setText(unChecked);
|
element.setText(x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
consumer.accept(selected.get());
|
consumer.accept(checked.get());
|
||||||
});
|
});
|
||||||
|
|
||||||
container.getChildren().addLast(element);
|
container.getChildren().addLast(element);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Label addToggle(String unChecked, String checked, Consumer<Boolean> consumer) {
|
public Label addToggle(String x1, String x2, boolean toggled, Consumer<Boolean> consumer) {
|
||||||
return addToggle("toggle", unChecked, checked, consumer);
|
return addToggle("toggle", x1, x2, toggled, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pane getContainer() { return container; }
|
public Pane getContainer() { return container; }
|
||||||
|
|||||||
@@ -56,6 +56,24 @@ public abstract class Layer {
|
|||||||
layer.getChildren().addLast(canvas.getCanvas());
|
layer.getChildren().addLast(canvas.getCanvas());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void pop() {
|
||||||
|
if (layer.getChildren().size() <= 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
layer.getChildren().removeLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void popAll() {
|
||||||
|
final int containers = layer.getChildren().size();
|
||||||
|
|
||||||
|
for (int i = 1; i < containers; i++) {
|
||||||
|
layer.getChildren().removeLast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public StackPane getLayer() { return layer; }
|
public StackPane getLayer() { return layer; }
|
||||||
public Region getBackground() { return background; }
|
public Region getBackground() { return background; }
|
||||||
|
|
||||||
|
public abstract void reload();
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,8 @@ public final class MainLayer extends Layer {
|
|||||||
super("main.css");
|
super("main.css");
|
||||||
|
|
||||||
final Container gamesContainer = Container.create(Container.Type.VERTICAL, 5);
|
final Container gamesContainer = Container.create(Container.Type.VERTICAL, 5);
|
||||||
gamesContainer.addButton("Tic Tac Toe", () -> { App.activate(new SelectionLayer(GameType.TICTACTOE)); });
|
gamesContainer.addButton("Tic Tac Toe", () -> { App.activate(new MultiplayerLayer(GameType.TICTACTOE)); });
|
||||||
gamesContainer.addButton("Othello", () -> { App.activate(new SelectionLayer(GameType.OTHELLO)); });
|
gamesContainer.addButton("Othello", () -> { App.activate(new MultiplayerLayer(GameType.OTHELLO)); });
|
||||||
|
|
||||||
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
||||||
controlContainer.addButton("Credits", () -> {});
|
controlContainer.addButton("Credits", () -> {});
|
||||||
@@ -23,4 +23,8 @@ public final class MainLayer extends Layer {
|
|||||||
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2);
|
addContainer(gamesContainer, Pos.TOP_LEFT, 2, 2);
|
||||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package org.toop.app.layer.layers;
|
||||||
|
|
||||||
|
import org.toop.app.App;
|
||||||
|
import org.toop.app.GameType;
|
||||||
|
import org.toop.app.layer.Container;
|
||||||
|
import org.toop.app.layer.Layer;
|
||||||
|
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
|
||||||
|
public class MultiplayerLayer extends Layer {
|
||||||
|
boolean isConnectionLocal = true;
|
||||||
|
|
||||||
|
boolean isPlayer1Human = true;
|
||||||
|
boolean isPlayer2Human = true;
|
||||||
|
|
||||||
|
protected MultiplayerLayer(GameType type) {
|
||||||
|
super("multiplayer.css");
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
popAll();
|
||||||
|
|
||||||
|
final Container connectionContainer = Container.create(Container.Type.VERTICAL, 0);
|
||||||
|
connectionContainer.addToggle("Local", "Server", !isConnectionLocal, (server) -> {
|
||||||
|
if (server) {
|
||||||
|
System.out.println("Server is checked now");
|
||||||
|
}
|
||||||
|
|
||||||
|
isConnectionLocal = !server;
|
||||||
|
reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
final Container player1Container = Container.create(Container.Type.VERTICAL, 5);
|
||||||
|
|
||||||
|
player1Container.addToggle("Human", "Computer", !isPlayer1Human, (computer) -> {
|
||||||
|
isPlayer1Human = !computer;
|
||||||
|
reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isPlayer1Human) {
|
||||||
|
player1Container.addText("player is human");
|
||||||
|
player1Container.addText("input player name here: ...");
|
||||||
|
} else {
|
||||||
|
player1Container.addText("playing against ai");
|
||||||
|
player1Container.addToggle("Easy", "Hard", false, (hard) -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
final Container player2Container = Container.create(Container.Type.VERTICAL, 5);
|
||||||
|
|
||||||
|
if (isConnectionLocal) {
|
||||||
|
player2Container.addToggle("Human", "Computer", !isPlayer2Human, (computer) -> {
|
||||||
|
isPlayer2Human = !computer;
|
||||||
|
reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isPlayer2Human) {
|
||||||
|
player2Container.addText("player is human");
|
||||||
|
player2Container.addText("input player name here: ...");
|
||||||
|
} else {
|
||||||
|
player2Container.addText("playing against ai");
|
||||||
|
player2Container.addToggle("Easy", "Hard", false, (hard) -> {});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player2Container.addText("enter server ip here: ...");
|
||||||
|
player2Container.addText("enter server port here: ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
||||||
|
controlContainer.addButton("Back", () -> { App.activate(new MainLayer()); });
|
||||||
|
|
||||||
|
addContainer(connectionContainer, Pos.TOP_CENTER, 0, 20);
|
||||||
|
|
||||||
|
addContainer(player1Container, Pos.CENTER_LEFT, 10, 0);
|
||||||
|
addContainer(player2Container, Pos.CENTER_RIGHT, -10, 0);
|
||||||
|
|
||||||
|
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,4 +19,8 @@ public final class QuitLayer extends Layer {
|
|||||||
|
|
||||||
addContainer(mainContainer, Pos.CENTER, 0, 0);
|
addContainer(mainContainer, Pos.CENTER, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package org.toop.app.layer.layers;
|
|
||||||
|
|
||||||
import org.toop.app.App;
|
|
||||||
import org.toop.app.GameType;
|
|
||||||
import org.toop.app.layer.Container;
|
|
||||||
import org.toop.app.layer.Layer;
|
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
|
||||||
|
|
||||||
public class SelectionLayer extends Layer {
|
|
||||||
protected SelectionLayer(GameType type) {
|
|
||||||
super("selection.css");
|
|
||||||
|
|
||||||
final Container player1Container = Container.create(Container.Type.HORIZONTAL, 5);
|
|
||||||
player1Container.addToggle("test","other test", (checked) -> {
|
|
||||||
if (checked) {
|
|
||||||
System.out.println("Checked");
|
|
||||||
} else {
|
|
||||||
System.out.println("Un checked");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final Container controlContainer = Container.create(Container.Type.VERTICAL, 5);
|
|
||||||
controlContainer.addButton("Back", () -> { App.activate(new MainLayer()); });
|
|
||||||
|
|
||||||
addContainer(player1Container, Pos.TOP_LEFT, 2, 2);
|
|
||||||
addContainer(controlContainer, Pos.BOTTOM_LEFT, 2, -2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user