diff --git a/app/src/main/java/org/toop/app/widget/Updatable.java b/app/src/main/java/org/toop/app/widget/Updatable.java new file mode 100644 index 0000000..cdee4cb --- /dev/null +++ b/app/src/main/java/org/toop/app/widget/Updatable.java @@ -0,0 +1,5 @@ +package org.toop.app.widget; + +public interface Updatable { + void update(); +} diff --git a/app/src/main/java/org/toop/app/widget/tutorial/BaseTutorialWidget.java b/app/src/main/java/org/toop/app/widget/tutorial/BaseTutorialWidget.java index 8096174..51acf14 100644 --- a/app/src/main/java/org/toop/app/widget/tutorial/BaseTutorialWidget.java +++ b/app/src/main/java/org/toop/app/widget/tutorial/BaseTutorialWidget.java @@ -6,6 +6,7 @@ import javafx.scene.image.ImageView; import javafx.scene.text.Text; import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair; import org.toop.app.widget.Primitive; +import org.toop.app.widget.Updatable; import org.toop.app.widget.WidgetContainer; import org.toop.app.widget.complex.PopupWidget; @@ -14,16 +15,17 @@ import org.toop.local.AppContext; import java.util.List; -public class BaseTutorialWidget extends PopupWidget { +public class BaseTutorialWidget extends PopupWidget implements Updatable { private final Text tutorialText; private final ImageView imagery; private final Button previousButton; private final Button nextButton; - private int pageIndex = 0; private final List> pages; private final Runnable nextScreen; + private int pageIndex = 0; + public BaseTutorialWidget(List> pages, Runnable nextScreen) { this.tutorialText = Primitive.text(pages.getFirst().getKey()); this.imagery = Primitive.image(pages.getFirst().getValue()); @@ -46,6 +48,11 @@ public class BaseTutorialWidget extends PopupWidget { WidgetContainer.add(Pos.CENTER, this); } + @Override + public void update() { + update(true); + } + public void update(boolean next) { pageIndex = next ? pageIndex + 1 : pageIndex - 1; diff --git a/app/src/main/java/org/toop/app/widget/tutorial/ShowEnableTutorialWidget.java b/app/src/main/java/org/toop/app/widget/tutorial/ShowEnableTutorialWidget.java index 8096444..62fa0c7 100644 --- a/app/src/main/java/org/toop/app/widget/tutorial/ShowEnableTutorialWidget.java +++ b/app/src/main/java/org/toop/app/widget/tutorial/ShowEnableTutorialWidget.java @@ -4,17 +4,18 @@ import javafx.geometry.Pos; import org.toop.app.widget.Primitive; import org.toop.app.widget.WidgetContainer; import org.toop.app.widget.complex.PopupWidget; +import org.toop.local.AppSettings; public class ShowEnableTutorialWidget extends PopupWidget { - public ShowEnableTutorialWidget(String text, Runnable onYes, Runnable onNo, Runnable onNever) { + public ShowEnableTutorialWidget(Runnable tutorial, Runnable nextScreen, Runnable appSettingsSetter) { var a = Primitive.hbox( - Primitive.button("ok", () -> { onYes.run(); this.hide(); }), - Primitive.button("no", () -> { onNo.run(); this.hide(); }), - Primitive.button("never", () -> { onNever.run(); this.hide(); }) + Primitive.button("ok", () -> { appSettingsSetter.run(); tutorial.run(); this.hide(); }), + Primitive.button("no", () -> { appSettingsSetter.run(); nextScreen.run(); this.hide(); }), + Primitive.button("never", () -> { AppSettings.getSettings().setTutorialFlag(false); nextScreen.run(); this.hide(); }) ); - var txt = Primitive.text(text); + var txt = Primitive.text("tutorial"); add(Pos.CENTER, Primitive.vbox(txt, a)); WidgetContainer.add(Pos.CENTER, this); } diff --git a/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java b/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java index b2c81ad..aa11a77 100644 --- a/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java +++ b/app/src/main/java/org/toop/app/widget/view/LocalMultiplayerView.java @@ -38,84 +38,39 @@ public class LocalMultiplayerView extends ViewWidget { case TICTACTOE: if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstTTT()) { new ShowEnableTutorialWidget( - "tutorial", - () -> { - AppSettings.getSettings().setFirstTTT(false); - new TicTacToeTutorialWidget(() -> new TicTacToeGameThread(information)); - }, - () -> { - AppSettings.getSettings().setFirstTTT(false); - Platform.runLater(() -> { - new TicTacToeGameThread(information); - }); - }, - () -> { - AppSettings.getSettings().setTutorialFlag(false); - Platform.runLater(() -> { - new TicTacToeGameThread(information); - }); - } - + () -> new TicTacToeTutorialWidget(() -> new TicTacToeGameThread(information)), + () -> Platform.runLater(() -> new TicTacToeGameThread(information)), + () -> AppSettings.getSettings().setFirstTTT(false) ); - break; + } else { + new TicTacToeGameThread(information); } - new TicTacToeGameThread(information); break; case REVERSI: if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) { new ShowEnableTutorialWidget( - "tutorial", - () -> { - AppSettings.getSettings().setFirstTTT(false); - new ReversiTutorialWidget(() -> new ReversiGame(information)); - }, - () -> { - AppSettings.getSettings().setFirstTTT(false); - Platform.runLater(() -> { - new ReversiGame(information); - }); - }, - () -> { - AppSettings.getSettings().setTutorialFlag(false); - Platform.runLater(() -> { - new ReversiGame(information); - }); - } - + () -> new ReversiTutorialWidget(() -> new ReversiGame(information)), + () -> Platform.runLater(() -> new ReversiGame(information)), + () -> AppSettings.getSettings().setFirstReversi(false) ); - break; + } else { + new ReversiGame(information); } - new ReversiGame(information); break; case CONNECT4: if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstConnect4()) { new ShowEnableTutorialWidget( - "tutorial", - () -> { - AppSettings.getSettings().setFirstTTT(false); - new Connect4TutorialWidget(() -> new Connect4Game(information)); - }, - () -> { - AppSettings.getSettings().setFirstTTT(false); - Platform.runLater(() -> { - new Connect4Game(information); - }); - }, - () -> { - AppSettings.getSettings().setTutorialFlag(false); - Platform.runLater(() -> { - new Connect4Game(information); - }); - } - + () -> new Connect4TutorialWidget(() -> new Connect4Game(information)), + () -> Platform.runLater(() -> new Connect4Game(information)), + () -> AppSettings.getSettings().setFirstConnect4(false) ); - break; + } else { + new Connect4Game(information); } - new Connect4Game(information); break; - } + } // case BATTLESHIP -> new BattleshipGame(information); - }); + }); var playerSection = setupPlayerSections();