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 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<ImmutablePair<String, ImageAsset>> pages;
|
||||
private final Runnable nextScreen;
|
||||
|
||||
private int pageIndex = 0;
|
||||
|
||||
public BaseTutorialWidget(List<ImmutablePair<String, ImageAsset>> 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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -38,80 +38,35 @@ 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
break;
|
||||
}
|
||||
// case BATTLESHIP -> new BattleshipGame(information);
|
||||
|
||||
Reference in New Issue
Block a user