mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Refactored switch statement
This commit is contained in:
5
app/src/main/java/org/toop/app/widget/Updatable.java
Normal file
5
app/src/main/java/org/toop/app/widget/Updatable.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package org.toop.app.widget;
|
||||||
|
|
||||||
|
public interface Updatable {
|
||||||
|
void update();
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import javafx.scene.image.ImageView;
|
|||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||||
import org.toop.app.widget.Primitive;
|
import org.toop.app.widget.Primitive;
|
||||||
|
import org.toop.app.widget.Updatable;
|
||||||
import org.toop.app.widget.WidgetContainer;
|
import org.toop.app.widget.WidgetContainer;
|
||||||
import org.toop.app.widget.complex.PopupWidget;
|
import org.toop.app.widget.complex.PopupWidget;
|
||||||
|
|
||||||
@@ -14,16 +15,17 @@ import org.toop.local.AppContext;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BaseTutorialWidget extends PopupWidget {
|
public class BaseTutorialWidget extends PopupWidget implements Updatable {
|
||||||
|
|
||||||
private final Text tutorialText;
|
private final Text tutorialText;
|
||||||
private final ImageView imagery;
|
private final ImageView imagery;
|
||||||
private final Button previousButton;
|
private final Button previousButton;
|
||||||
private final Button nextButton;
|
private final Button nextButton;
|
||||||
private int pageIndex = 0;
|
|
||||||
private final List<ImmutablePair<String, ImageAsset>> pages;
|
private final List<ImmutablePair<String, ImageAsset>> pages;
|
||||||
private final Runnable nextScreen;
|
private final Runnable nextScreen;
|
||||||
|
|
||||||
|
private int pageIndex = 0;
|
||||||
|
|
||||||
public BaseTutorialWidget(List<ImmutablePair<String, ImageAsset>> pages, Runnable nextScreen) {
|
public BaseTutorialWidget(List<ImmutablePair<String, ImageAsset>> pages, Runnable nextScreen) {
|
||||||
this.tutorialText = Primitive.text(pages.getFirst().getKey());
|
this.tutorialText = Primitive.text(pages.getFirst().getKey());
|
||||||
this.imagery = Primitive.image(pages.getFirst().getValue());
|
this.imagery = Primitive.image(pages.getFirst().getValue());
|
||||||
@@ -46,6 +48,11 @@ public class BaseTutorialWidget extends PopupWidget {
|
|||||||
WidgetContainer.add(Pos.CENTER, this);
|
WidgetContainer.add(Pos.CENTER, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
update(true);
|
||||||
|
}
|
||||||
|
|
||||||
public void update(boolean next) {
|
public void update(boolean next) {
|
||||||
pageIndex = next ? pageIndex + 1 : pageIndex - 1;
|
pageIndex = next ? pageIndex + 1 : pageIndex - 1;
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,18 @@ import javafx.geometry.Pos;
|
|||||||
import org.toop.app.widget.Primitive;
|
import org.toop.app.widget.Primitive;
|
||||||
import org.toop.app.widget.WidgetContainer;
|
import org.toop.app.widget.WidgetContainer;
|
||||||
import org.toop.app.widget.complex.PopupWidget;
|
import org.toop.app.widget.complex.PopupWidget;
|
||||||
|
import org.toop.local.AppSettings;
|
||||||
|
|
||||||
public class ShowEnableTutorialWidget extends PopupWidget {
|
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(
|
var a = Primitive.hbox(
|
||||||
Primitive.button("ok", () -> { onYes.run(); this.hide(); }),
|
Primitive.button("ok", () -> { appSettingsSetter.run(); tutorial.run(); this.hide(); }),
|
||||||
Primitive.button("no", () -> { onNo.run(); this.hide(); }),
|
Primitive.button("no", () -> { appSettingsSetter.run(); nextScreen.run(); this.hide(); }),
|
||||||
Primitive.button("never", () -> { onNever.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));
|
add(Pos.CENTER, Primitive.vbox(txt, a));
|
||||||
WidgetContainer.add(Pos.CENTER, this);
|
WidgetContainer.add(Pos.CENTER, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,84 +38,39 @@ public class LocalMultiplayerView extends ViewWidget {
|
|||||||
case TICTACTOE:
|
case TICTACTOE:
|
||||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstTTT()) {
|
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstTTT()) {
|
||||||
new ShowEnableTutorialWidget(
|
new ShowEnableTutorialWidget(
|
||||||
"tutorial",
|
() -> new TicTacToeTutorialWidget(() -> new TicTacToeGameThread(information)),
|
||||||
() -> {
|
() -> Platform.runLater(() -> new TicTacToeGameThread(information)),
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
() -> 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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
);
|
||||||
break;
|
} else {
|
||||||
|
new TicTacToeGameThread(information);
|
||||||
}
|
}
|
||||||
new TicTacToeGameThread(information);
|
|
||||||
break;
|
break;
|
||||||
case REVERSI:
|
case REVERSI:
|
||||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) {
|
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstReversi()) {
|
||||||
new ShowEnableTutorialWidget(
|
new ShowEnableTutorialWidget(
|
||||||
"tutorial",
|
() -> new ReversiTutorialWidget(() -> new ReversiGame(information)),
|
||||||
() -> {
|
() -> Platform.runLater(() -> new ReversiGame(information)),
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
() -> AppSettings.getSettings().setFirstReversi(false)
|
||||||
new ReversiTutorialWidget(() -> new ReversiGame(information));
|
|
||||||
},
|
|
||||||
() -> {
|
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
new ReversiGame(information);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
() -> {
|
|
||||||
AppSettings.getSettings().setTutorialFlag(false);
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
new ReversiGame(information);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
);
|
||||||
break;
|
} else {
|
||||||
|
new ReversiGame(information);
|
||||||
}
|
}
|
||||||
new ReversiGame(information);
|
|
||||||
break;
|
break;
|
||||||
case CONNECT4:
|
case CONNECT4:
|
||||||
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstConnect4()) {
|
if (AppSettings.getSettings().getTutorialFlag() && AppSettings.getSettings().getFirstConnect4()) {
|
||||||
new ShowEnableTutorialWidget(
|
new ShowEnableTutorialWidget(
|
||||||
"tutorial",
|
() -> new Connect4TutorialWidget(() -> new Connect4Game(information)),
|
||||||
() -> {
|
() -> Platform.runLater(() -> new Connect4Game(information)),
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
() -> AppSettings.getSettings().setFirstConnect4(false)
|
||||||
new Connect4TutorialWidget(() -> new Connect4Game(information));
|
|
||||||
},
|
|
||||||
() -> {
|
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
new Connect4Game(information);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
() -> {
|
|
||||||
AppSettings.getSettings().setTutorialFlag(false);
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
new Connect4Game(information);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
);
|
||||||
break;
|
} else {
|
||||||
|
new Connect4Game(information);
|
||||||
}
|
}
|
||||||
new Connect4Game(information);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// case BATTLESHIP -> new BattleshipGame(information);
|
// case BATTLESHIP -> new BattleshipGame(information);
|
||||||
});
|
});
|
||||||
|
|
||||||
var playerSection = setupPlayerSections();
|
var playerSection = setupPlayerSections();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user