mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
started a basis for the tutorials, tic tac toe is almost done with some general stuff still to do.
This commit is contained in:
@@ -36,4 +36,5 @@ public final class Main {
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@ import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.game.Game;
|
||||
import org.toop.game.tictactoe.TicTacToe;
|
||||
import org.toop.game.tictactoe.TicTacToeAI;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
@@ -24,8 +22,8 @@ public final class TicTacToeGameThread extends BaseGameThread<TicTacToe, TicTacT
|
||||
}
|
||||
|
||||
public TicTacToeGameThread(GameInformation info) {
|
||||
this(info, 0, null, null, null, null);
|
||||
}
|
||||
this(info, 0, null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addCanvasToPrimary() {
|
||||
|
||||
@@ -7,6 +7,9 @@ import org.toop.app.game.TicTacToeGameThread;
|
||||
import org.toop.app.view.View;
|
||||
import org.toop.app.view.ViewStack;
|
||||
import org.toop.app.view.displays.SongDisplay;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.tutorial.BaseTutorialWidget;
|
||||
import org.toop.app.widget.tutorial.TicTacToeTutorialWidget;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
@@ -16,6 +19,7 @@ import javafx.scene.control.Slider;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.local.AppSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -45,8 +49,8 @@ public final class LocalMultiplayerView extends View {
|
||||
}
|
||||
|
||||
switch (information.type) {
|
||||
case TICTACTOE: new TicTacToeGameThread(information); break;
|
||||
case REVERSI: new ReversiGame(information); break;
|
||||
case TICTACTOE: new TicTacToeGameThread(information); break;
|
||||
case REVERSI: new ReversiGame(information); break;
|
||||
case CONNECT4: new Connect4Game(information); break;
|
||||
// case BATTLESHIP: new BattleshipGame(information); break;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.toop.app.widget;
|
||||
|
||||
import javafx.scene.image.ImageView;
|
||||
import org.toop.framework.resource.resources.ImageAsset;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
@@ -18,7 +22,7 @@ import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
public final class Primitive {
|
||||
public final class Primitive {
|
||||
public static Text header(String key) {
|
||||
var header = new Text();
|
||||
header.getStyleClass().add("header");
|
||||
@@ -43,6 +47,16 @@ public final class Primitive {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static ImageView image(File file) {
|
||||
ImageAsset imageAsset = new ImageAsset(file);
|
||||
ImageView imageView = new ImageView(imageAsset.getImage());
|
||||
imageView.getStyleClass().add("image");
|
||||
imageView.setPreserveRatio(true);
|
||||
imageView.setFitWidth(400);
|
||||
imageView.setFitHeight(400);
|
||||
return imageView;
|
||||
}
|
||||
|
||||
public static Button button(String key, Runnable onAction) {
|
||||
var button = new Button();
|
||||
button.getStyleClass().add("button");
|
||||
|
||||
@@ -62,4 +62,16 @@ public final class WidgetContainer {
|
||||
public static ViewWidget getCurrentView() {
|
||||
return currentView;
|
||||
}
|
||||
|
||||
public static void setCurrentView(ViewWidget view) {
|
||||
if (root == null || view == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Platform.runLater(() -> {
|
||||
root.getChildren().clear();
|
||||
root.getChildren().add(view.getNode());
|
||||
currentView = view;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.text.Text;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class BaseTutorialWidget extends ViewWidget {
|
||||
|
||||
private TState state;
|
||||
private Text tutorialText;
|
||||
private Button previousButton;
|
||||
private Button nextButton;
|
||||
private Button noButton;
|
||||
private Button yesButton;
|
||||
private Button neverButton;
|
||||
private ImageView imagery;
|
||||
|
||||
public BaseTutorialWidget(String key, Runnable onNo, Runnable onYes, Runnable onNever) {
|
||||
System.out.println("Trying to initialize...");
|
||||
this.tutorialText = Primitive.text(key);
|
||||
this.yesButton = Primitive.button("ok", () -> onYes.run());
|
||||
this.noButton = Primitive.button("no", () -> onNo.run());
|
||||
this.neverButton = Primitive.button("never", () -> onNever.run());
|
||||
var a = Primitive.hbox(yesButton, noButton, neverButton);
|
||||
add(Pos.CENTER, Primitive.vbox(tutorialText, a));
|
||||
}
|
||||
|
||||
public BaseTutorialWidget(TState state, String key, Runnable onPrevious, Runnable onNext) {
|
||||
this.state = state;
|
||||
this.tutorialText = Primitive.text(key);
|
||||
this.previousButton = Primitive.button("<", () -> onPrevious.run());
|
||||
this.nextButton = Primitive.button(">", () -> onNext.run());
|
||||
var w = Primitive.hbox(previousButton, nextButton);
|
||||
add(Pos.CENTER, Primitive.vbox(tutorialText, w));
|
||||
}
|
||||
|
||||
public BaseTutorialWidget(TState state, String key, File image, Runnable onPrevious, Runnable onNext) {
|
||||
this.state = state;
|
||||
this.imagery = Primitive.image(image);
|
||||
this.tutorialText = Primitive.text(key);
|
||||
this.previousButton = Primitive.button("<", () -> onPrevious.run());
|
||||
this.nextButton = Primitive.button(">", () -> onNext.run());
|
||||
var w = Primitive.hbox(previousButton, nextButton);
|
||||
var x = Primitive.vbox(imagery, tutorialText);
|
||||
add(Pos.CENTER, Primitive.vbox(x, w));
|
||||
}
|
||||
|
||||
public void update(String key, File image) {
|
||||
tutorialText.textProperty().unbind();
|
||||
tutorialText.setText(AppContext.getString(key));
|
||||
imagery.setImage(Primitive.image(image).getImage());
|
||||
}
|
||||
}
|
||||
44
app/src/main/java/org/toop/app/widget/tutorial/TState.java
Normal file
44
app/src/main/java/org/toop/app/widget/tutorial/TState.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
public class TState {
|
||||
|
||||
private int current;
|
||||
private int total;
|
||||
|
||||
public TState(int total) {
|
||||
this.total = total;
|
||||
this.current = 0;
|
||||
}
|
||||
|
||||
public int getCurrent() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public void setCurrent(int current) {
|
||||
this.current = current;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public void next() {
|
||||
current = current + 1;
|
||||
}
|
||||
|
||||
public void previous() {
|
||||
current = current - 1;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return current < total - 1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return current > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import java.io.File;
|
||||
|
||||
public class TicTacToeTutorialWidget extends ViewWidget {
|
||||
|
||||
private TState state;
|
||||
private String[] keys = {"tictactoe1", "tictactoe2"};
|
||||
private File[] images = {
|
||||
new File("app/src/main/resources/assets/images/tictactoe1.png"),
|
||||
new File("app/src/main/resources/assets/images/tictactoe2.png")
|
||||
};
|
||||
private BaseTutorialWidget tutorialWidget;
|
||||
|
||||
public TicTacToeTutorialWidget() {
|
||||
System.out.println("Hi, I got here!");
|
||||
this.state = new TState(keys.length);
|
||||
tutorialWidget = new BaseTutorialWidget(
|
||||
state,
|
||||
keys[state.getCurrent()],
|
||||
images[state.getCurrent()],
|
||||
() -> {
|
||||
if (state.hasPrevious()) {
|
||||
state.previous();
|
||||
update();
|
||||
}
|
||||
},
|
||||
() -> {
|
||||
if (state.hasNext()) {
|
||||
state.next();
|
||||
update();
|
||||
}
|
||||
}
|
||||
);
|
||||
System.out.println("Hi, I got to the end!");
|
||||
add(Pos.CENTER, tutorialWidget);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
tutorialWidget.update(keys[state.getCurrent()], images[state.getCurrent()]);
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,10 @@ public final class GameView extends ViewWidget {
|
||||
private final Text currentPlayerHeader;
|
||||
private final Text currentMoveHeader;
|
||||
private final Text nextPlayerHeader;
|
||||
|
||||
private final Button forfeitButton;
|
||||
private final Button exitButton;
|
||||
|
||||
private final TextField chatInput;
|
||||
private final TextField chatInput;
|
||||
|
||||
public GameView(Runnable onForfeit, Runnable onExit, Consumer<String> onMessage) {
|
||||
currentPlayerHeader = Primitive.header("");
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.game.Connect4Game;
|
||||
import org.toop.app.game.ReversiGame;
|
||||
import org.toop.app.game.TicTacToeGameThread;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.PlayerInfoWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import org.toop.app.widget.popup.ErrorPopup;
|
||||
import org.toop.app.widget.tutorial.BaseTutorialWidget;
|
||||
import org.toop.app.widget.tutorial.TicTacToeTutorialWidget;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import org.toop.local.AppSettings;
|
||||
public class LocalMultiplayerView extends ViewWidget {
|
||||
private final GameInformation information;
|
||||
|
||||
@@ -32,9 +36,39 @@ public class LocalMultiplayerView extends ViewWidget {
|
||||
}
|
||||
|
||||
switch (information.type) {
|
||||
case TICTACTOE -> new TicTacToeGameThread(information);
|
||||
case REVERSI -> new ReversiGame(information);
|
||||
case CONNECT4 -> new Connect4Game(information);
|
||||
case TICTACTOE:
|
||||
System.out.println(AppSettings.getSettings().getTutorialFlag());
|
||||
System.out.println(AppSettings.getSettings().getFirstTTT());
|
||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstTTT()) {
|
||||
BaseTutorialWidget a = new BaseTutorialWidget(
|
||||
"tutorial",
|
||||
() -> {
|
||||
AppSettings.getSettings().setFirstTTT(false);
|
||||
Platform.runLater(() -> {
|
||||
new TicTacToeGameThread(information);
|
||||
});
|
||||
},
|
||||
() -> {
|
||||
Platform.runLater(() -> {
|
||||
ViewWidget c = new TicTacToeTutorialWidget();
|
||||
transitionNext(c);
|
||||
WidgetContainer.setCurrentView(c);
|
||||
});
|
||||
},
|
||||
() -> {
|
||||
AppSettings.getSettings().setTutorialFlag(false);
|
||||
Platform.runLater(() -> {
|
||||
new TicTacToeGameThread(information);
|
||||
});
|
||||
}
|
||||
);
|
||||
transitionNext(a);
|
||||
break;
|
||||
}
|
||||
new TicTacToeGameThread(information);
|
||||
break;
|
||||
case REVERSI: new ReversiGame(information);
|
||||
case CONNECT4: new Connect4Game(information);
|
||||
// case BATTLESHIP -> new BattleshipGame(information);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.toop.app.widget.view;
|
||||
import org.toop.app.App;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public class MainView extends ViewWidget {
|
||||
|
||||
@@ -21,6 +21,8 @@ public class AppSettings {
|
||||
settingsAsset.load();
|
||||
}
|
||||
|
||||
doDefaultSettings();
|
||||
|
||||
Settings settingsData = settingsAsset.getContent();
|
||||
|
||||
AppContext.setLocale(Locale.of(settingsData.locale));
|
||||
@@ -64,4 +66,43 @@ public class AppSettings {
|
||||
public static SettingsAsset getSettings() {
|
||||
return settingsAsset;
|
||||
}
|
||||
|
||||
public static void checkSettings() {
|
||||
Settings s = settingsAsset.getContent();
|
||||
boolean changed = false;
|
||||
|
||||
if (s.showTutorials == null) {
|
||||
settingsAsset.setTutorialFlag(true);
|
||||
changed = true;
|
||||
}
|
||||
if (s.firstReversi == null) {
|
||||
settingsAsset.setFirstReversi(true);
|
||||
changed = true;
|
||||
}
|
||||
if (s.firstTTT == null) {
|
||||
settingsAsset.setFirstTTT(true);
|
||||
changed = true;
|
||||
}
|
||||
if (s.firstConnect4 == null) {
|
||||
settingsAsset.setFirstConnect4(true);
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
getSettings().save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void doDefaultSettings() {
|
||||
settingsAsset.setFirstConnect4(true);
|
||||
settingsAsset.setFirstTTT(true);
|
||||
settingsAsset.setFirstReversi(true);
|
||||
settingsAsset.setLocale("en");
|
||||
settingsAsset.setTheme("dark");
|
||||
settingsAsset.setFullscreen(false);
|
||||
settingsAsset.setVolume(100);
|
||||
settingsAsset.setFxVolume(20);
|
||||
settingsAsset.setMusicVolume(15);
|
||||
settingsAsset.setTutorialFlag(true);
|
||||
settingsAsset.setLayoutSize("medium");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user