mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added button to continue and start game. Refactors
This commit is contained in:
@@ -1,63 +1,95 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.text.Text;
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.game.BaseGameThread;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import org.toop.framework.resource.resources.ImageAsset;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class BaseTutorialWidget extends PopupWidget {
|
||||
|
||||
private Text tutorialText;
|
||||
private Button previousButton;
|
||||
private Button nextButton;
|
||||
private ImageView imagery;
|
||||
private int currentTextIndex = 0;
|
||||
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;
|
||||
|
||||
public BaseTutorialWidget(List<ImmutablePair<String, ImageAsset>> pages, Runnable nextScreen) {
|
||||
this.tutorialText = Primitive.text(pages.getFirst().getKey());
|
||||
this.imagery = Primitive.image(pages.getFirst().getValue());
|
||||
|
||||
this.pages = pages;
|
||||
this.nextScreen = nextScreen;
|
||||
|
||||
previousButton = Primitive.button("goback", () -> { update(false); this.hide(); });
|
||||
nextButton = Primitive.button(">", () -> update(true));
|
||||
|
||||
var w = Primitive.hbox(
|
||||
previousButton,
|
||||
nextButton
|
||||
);
|
||||
|
||||
var x = Primitive.vbox(imagery, tutorialText);
|
||||
|
||||
add(Pos.CENTER, Primitive.vbox(x, w));
|
||||
|
||||
public BaseTutorialWidget(String key) {
|
||||
System.out.println("Trying to initialize...");
|
||||
this.tutorialText = Primitive.text(key);
|
||||
WidgetContainer.add(Pos.CENTER, this);
|
||||
}
|
||||
|
||||
private void setOnPrevious(Runnable onPrevious) {
|
||||
this.previousButton = Primitive.button("<", onPrevious);
|
||||
}
|
||||
public void update(boolean next) {
|
||||
pageIndex = next ? pageIndex + 1 : pageIndex - 1;
|
||||
|
||||
private void setOnNext(Runnable onNext) {
|
||||
this.nextButton = Primitive.button(">", onNext);
|
||||
}
|
||||
|
||||
public void setTutorial(ImageAsset image, Runnable onPrevious, Runnable onNext) {
|
||||
setOnPrevious(onPrevious);
|
||||
setOnNext(onNext);
|
||||
this.imagery = Primitive.image(image);
|
||||
var w = Primitive.hbox(previousButton, nextButton);
|
||||
var x = Primitive.vbox(imagery, tutorialText);
|
||||
add(Pos.CENTER, Primitive.vbox(x, w));
|
||||
}
|
||||
|
||||
public void update(boolean next, String[] locKeys, ImageAsset[] imgs) {
|
||||
currentTextIndex = next ? currentTextIndex + 1 : currentTextIndex - 1;
|
||||
|
||||
if (currentTextIndex >= locKeys.length) {
|
||||
currentTextIndex--;
|
||||
if (pageIndex >= pages.size()) {
|
||||
pageIndex--;
|
||||
return;
|
||||
} else if (currentTextIndex < 0) {
|
||||
currentTextIndex++;
|
||||
} else if (pageIndex < 0) {
|
||||
pageIndex++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pageIndex == pages.size()-1) {
|
||||
nextButton.textProperty().unbind();
|
||||
nextButton.setText(AppContext.getString("startgame"));
|
||||
nextButton.setOnAction((_) -> {
|
||||
this.hide();
|
||||
nextScreen.run();
|
||||
});
|
||||
|
||||
} else {
|
||||
nextButton.textProperty().unbind();
|
||||
nextButton.setText(AppContext.getString(">"));
|
||||
nextButton.setOnAction((_) -> this.update(true));
|
||||
}
|
||||
|
||||
if (pageIndex == 0) {
|
||||
previousButton.textProperty().unbind();
|
||||
previousButton.setText(AppContext.getString("goback"));
|
||||
previousButton.setOnAction((_) -> this.hide());
|
||||
} else {
|
||||
previousButton.textProperty().unbind();
|
||||
previousButton.setText(AppContext.getString("<"));
|
||||
previousButton.setOnAction((_) -> this.update(false));
|
||||
}
|
||||
|
||||
var currentPage = pages.get(pageIndex);
|
||||
|
||||
var text = currentPage.getKey();
|
||||
var image = currentPage.getValue();
|
||||
|
||||
tutorialText.textProperty().unbind();
|
||||
tutorialText.setText(AppContext.getString(locKeys[currentTextIndex]));
|
||||
imagery.setImage(Primitive.image(imgs[currentTextIndex]).getImage());
|
||||
tutorialText.setText(AppContext.getString(text));
|
||||
imagery.setImage(Primitive.image(image).getImage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,25 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import javafx.application.Platform;
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.game.Connect4Game;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.resources.ImageAsset;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class Connect4TutorialWidget extends BaseTutorialWidget {
|
||||
private final String[] keys;
|
||||
private final ImageAsset[] images;
|
||||
public Connect4TutorialWidget(GameInformation information) {
|
||||
super(List.of(
|
||||
new ImmutablePair<>("connect4.1", ResourceManager.get("connect41.png")),
|
||||
new ImmutablePair<>("connect4.2", ResourceManager.get("connect42.png"))
|
||||
), () -> Platform.runLater(() -> new Connect4Game(information)));
|
||||
}
|
||||
|
||||
public Connect4TutorialWidget() {
|
||||
String[] newKeys = {
|
||||
"connect4.1", "connect4.2"
|
||||
};
|
||||
|
||||
ImageAsset[] newImages = {
|
||||
ResourceManager.get("connect41.png"),
|
||||
ResourceManager.get("connect42.png")
|
||||
};
|
||||
|
||||
super(newKeys[0]);
|
||||
|
||||
keys = newKeys;
|
||||
images = newImages;
|
||||
|
||||
setTutorial(
|
||||
images[0],
|
||||
() -> update(false, keys, images),
|
||||
() -> update(true, keys, images)
|
||||
);
|
||||
}
|
||||
|
||||
public String[] getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public ImageAsset[] getImages() {
|
||||
return images;
|
||||
super(List.of(
|
||||
new ImmutablePair<>("connect4.1", ResourceManager.get("connect41.png")),
|
||||
new ImmutablePair<>("connect4.2", ResourceManager.get("connect42.png"))
|
||||
), () -> {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,29 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import javafx.application.Platform;
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.game.ReversiGame;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.resources.ImageAsset;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class ReversiTutorialWidget extends BaseTutorialWidget {
|
||||
private final String[] keys;
|
||||
private final ImageAsset[] images;
|
||||
public ReversiTutorialWidget(GameInformation gameInformation) {
|
||||
super(List.of(
|
||||
new ImmutablePair<>("reversi1", ResourceManager.get("reversi1.png")),
|
||||
new ImmutablePair<>("reversi2", ResourceManager.get("reversi2.png")),
|
||||
new ImmutablePair<>("reversi3", ResourceManager.get("cat.jpg")),
|
||||
new ImmutablePair<>("reversi4", ResourceManager.get("cat.jpg"))
|
||||
), () -> Platform.runLater(() -> new ReversiGame(gameInformation)));
|
||||
}
|
||||
|
||||
public ReversiTutorialWidget() {
|
||||
String[] newKeys = {"reversi1", "reversi2", "reversi3", "reversi4"};
|
||||
ImageAsset[] newImages = {
|
||||
ResourceManager.get("reversi1.png"),
|
||||
ResourceManager.get("reversi2.png"),
|
||||
ResourceManager.get("cat.jpg"),
|
||||
ResourceManager.get("cat.jpg")
|
||||
};
|
||||
|
||||
super(newKeys[0]);
|
||||
|
||||
keys = newKeys;
|
||||
images = newImages;
|
||||
|
||||
setTutorial(
|
||||
images[0],
|
||||
() -> update(false, keys, images),
|
||||
() -> update(true, keys, images)
|
||||
);
|
||||
}
|
||||
|
||||
public String[] getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public ImageAsset[] getImages() {
|
||||
return images;
|
||||
super(List.of(
|
||||
new ImmutablePair<>("reversi1", ResourceManager.get("reversi1.png")),
|
||||
new ImmutablePair<>("reversi2", ResourceManager.get("reversi2.png")),
|
||||
new ImmutablePair<>("reversi3", ResourceManager.get("cat.jpg")),
|
||||
new ImmutablePair<>("reversi4", ResourceManager.get("cat.jpg"))
|
||||
), () -> {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ public class ShowEnableTutorialWidget extends PopupWidget {
|
||||
|
||||
public ShowEnableTutorialWidget(String text, Runnable onYes, Runnable onNo, Runnable onNever) {
|
||||
var a = Primitive.hbox(
|
||||
Primitive.button("ok", onYes),
|
||||
Primitive.button("no", onNo),
|
||||
Primitive.button("never", onNever)
|
||||
Primitive.button("ok", () -> { onYes.run(); this.hide(); }),
|
||||
Primitive.button("no", () -> { onNo.run(); this.hide(); }),
|
||||
Primitive.button("never", () -> { onNever.run(); this.hide(); })
|
||||
);
|
||||
|
||||
var txt = Primitive.text(text);
|
||||
|
||||
@@ -1,41 +1,32 @@
|
||||
package org.toop.app.widget.tutorial;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Pos;
|
||||
import org.apache.maven.surefire.shared.lang3.tuple.ImmutablePair;
|
||||
import org.toop.app.GameInformation;
|
||||
import org.toop.app.game.ReversiGame;
|
||||
import org.toop.app.game.TicTacToeGameThread;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.resources.ImageAsset;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class TicTacToeTutorialWidget extends BaseTutorialWidget {
|
||||
|
||||
private final String[] keys;
|
||||
private final ImageAsset[] images;
|
||||
public TicTacToeTutorialWidget(GameInformation gameInformation) {
|
||||
super(List.of(
|
||||
new ImmutablePair<>("tictactoe1", ResourceManager.get("tictactoe1.png")),
|
||||
new ImmutablePair<>("tictactoe2", ResourceManager.get("tictactoe2.png"))
|
||||
), () -> Platform.runLater(() -> new TicTacToeGameThread(gameInformation)));
|
||||
}
|
||||
|
||||
public TicTacToeTutorialWidget() {
|
||||
String[] newKeys = {"tictactoe1", "tictactoe2"};
|
||||
ImageAsset[] newImages = {
|
||||
ResourceManager.get("tictactoe1.png"),
|
||||
ResourceManager.get("tictactoe2.png")
|
||||
};
|
||||
|
||||
super(newKeys[0]);
|
||||
|
||||
keys = newKeys;
|
||||
images = newImages;
|
||||
|
||||
setTutorial(
|
||||
images[0],
|
||||
() -> update(false, keys, images),
|
||||
() -> update(true, keys, images)
|
||||
);
|
||||
super(List.of(
|
||||
new ImmutablePair<>("tictactoe1", ResourceManager.get("tictactoe1.png")),
|
||||
new ImmutablePair<>("tictactoe2", ResourceManager.get("tictactoe2.png"))
|
||||
), () -> {});
|
||||
}
|
||||
|
||||
public String[] getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public ImageAsset[] getImages() {
|
||||
return images;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class LocalMultiplayerView extends ViewWidget {
|
||||
"tutorial",
|
||||
() -> {
|
||||
AppSettings.getSettings().setFirstTTT(false);
|
||||
new TicTacToeTutorialWidget();
|
||||
new TicTacToeTutorialWidget(information);
|
||||
},
|
||||
() -> {
|
||||
AppSettings.getSettings().setFirstTTT(false);
|
||||
@@ -67,7 +67,7 @@ public class LocalMultiplayerView extends ViewWidget {
|
||||
"tutorial",
|
||||
() -> {
|
||||
AppSettings.getSettings().setFirstTTT(false);
|
||||
new ReversiTutorialWidget();
|
||||
new ReversiTutorialWidget(information);
|
||||
},
|
||||
() -> {
|
||||
AppSettings.getSettings().setFirstTTT(false);
|
||||
@@ -93,7 +93,7 @@ public class LocalMultiplayerView extends ViewWidget {
|
||||
"tutorial",
|
||||
() -> {
|
||||
AppSettings.getSettings().setFirstTTT(false);
|
||||
new Connect4TutorialWidget();
|
||||
new Connect4TutorialWidget(information);
|
||||
},
|
||||
() -> {
|
||||
AppSettings.getSettings().setFirstTTT(false);
|
||||
|
||||
@@ -84,6 +84,8 @@ reversi2=Clicking on a dot will flip all the moves between where you place the d
|
||||
reversi3=Your turn may be skipped if there is no legal move. This will let your opponent play again until you get an opportunity at a legal move.
|
||||
reversi4=The player who wins at the end of the game is the one who has the most pieces on the board.
|
||||
tutorialstring=Tutorial
|
||||
startgame=Start game!
|
||||
goback=Go back
|
||||
|
||||
|
||||
arabic=\u0627\u0644\u0639\u0631\u0628\u064a\u0629 (Arabic)
|
||||
|
||||
Reference in New Issue
Block a user