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;
|
package org.toop.app.widget.tutorial;
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.image.ImageView;
|
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.toop.app.GameInformation;
|
||||||
|
import org.toop.app.game.BaseGameThread;
|
||||||
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.app.widget.complex.ViewWidget;
|
|
||||||
|
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import org.toop.framework.resource.resources.ImageAsset;
|
import org.toop.framework.resource.resources.ImageAsset;
|
||||||
import org.toop.local.AppContext;
|
import org.toop.local.AppContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
|
|
||||||
public class BaseTutorialWidget extends PopupWidget {
|
public class BaseTutorialWidget extends PopupWidget {
|
||||||
|
|
||||||
private Text tutorialText;
|
private final Text tutorialText;
|
||||||
private Button previousButton;
|
private final ImageView imagery;
|
||||||
private Button nextButton;
|
private final Button previousButton;
|
||||||
private ImageView imagery;
|
private final Button nextButton;
|
||||||
private int currentTextIndex = 0;
|
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);
|
WidgetContainer.add(Pos.CENTER, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOnPrevious(Runnable onPrevious) {
|
public void update(boolean next) {
|
||||||
this.previousButton = Primitive.button("<", onPrevious);
|
pageIndex = next ? pageIndex + 1 : pageIndex - 1;
|
||||||
}
|
|
||||||
|
|
||||||
private void setOnNext(Runnable onNext) {
|
if (pageIndex >= pages.size()) {
|
||||||
this.nextButton = Primitive.button(">", onNext);
|
pageIndex--;
|
||||||
}
|
|
||||||
|
|
||||||
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--;
|
|
||||||
return;
|
return;
|
||||||
} else if (currentTextIndex < 0) {
|
} else if (pageIndex < 0) {
|
||||||
currentTextIndex++;
|
pageIndex++;
|
||||||
return;
|
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.textProperty().unbind();
|
||||||
tutorialText.setText(AppContext.getString(locKeys[currentTextIndex]));
|
tutorialText.setText(AppContext.getString(text));
|
||||||
imagery.setImage(Primitive.image(imgs[currentTextIndex]).getImage());
|
imagery.setImage(Primitive.image(image).getImage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,25 @@
|
|||||||
package org.toop.app.widget.tutorial;
|
package org.toop.app.widget.tutorial;
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.application.Platform;
|
||||||
import org.toop.app.widget.complex.ViewWidget;
|
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.ResourceManager;
|
||||||
import org.toop.framework.resource.resources.ImageAsset;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
|
|
||||||
public class Connect4TutorialWidget extends BaseTutorialWidget {
|
public class Connect4TutorialWidget extends BaseTutorialWidget {
|
||||||
private final String[] keys;
|
public Connect4TutorialWidget(GameInformation information) {
|
||||||
private final ImageAsset[] images;
|
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() {
|
public Connect4TutorialWidget() {
|
||||||
String[] newKeys = {
|
super(List.of(
|
||||||
"connect4.1", "connect4.2"
|
new ImmutablePair<>("connect4.1", ResourceManager.get("connect41.png")),
|
||||||
};
|
new ImmutablePair<>("connect4.2", ResourceManager.get("connect42.png"))
|
||||||
|
), () -> {});
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,29 @@
|
|||||||
package org.toop.app.widget.tutorial;
|
package org.toop.app.widget.tutorial;
|
||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.application.Platform;
|
||||||
import org.toop.app.widget.complex.ViewWidget;
|
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.ResourceManager;
|
||||||
import org.toop.framework.resource.resources.ImageAsset;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
|
|
||||||
public class ReversiTutorialWidget extends BaseTutorialWidget {
|
public class ReversiTutorialWidget extends BaseTutorialWidget {
|
||||||
private final String[] keys;
|
public ReversiTutorialWidget(GameInformation gameInformation) {
|
||||||
private final ImageAsset[] 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"))
|
||||||
|
), () -> Platform.runLater(() -> new ReversiGame(gameInformation)));
|
||||||
|
}
|
||||||
|
|
||||||
public ReversiTutorialWidget() {
|
public ReversiTutorialWidget() {
|
||||||
String[] newKeys = {"reversi1", "reversi2", "reversi3", "reversi4"};
|
super(List.of(
|
||||||
ImageAsset[] newImages = {
|
new ImmutablePair<>("reversi1", ResourceManager.get("reversi1.png")),
|
||||||
ResourceManager.get("reversi1.png"),
|
new ImmutablePair<>("reversi2", ResourceManager.get("reversi2.png")),
|
||||||
ResourceManager.get("reversi2.png"),
|
new ImmutablePair<>("reversi3", ResourceManager.get("cat.jpg")),
|
||||||
ResourceManager.get("cat.jpg"),
|
new ImmutablePair<>("reversi4", 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ public class ShowEnableTutorialWidget extends PopupWidget {
|
|||||||
|
|
||||||
public ShowEnableTutorialWidget(String text, Runnable onYes, Runnable onNo, Runnable onNever) {
|
public ShowEnableTutorialWidget(String text, Runnable onYes, Runnable onNo, Runnable onNever) {
|
||||||
var a = Primitive.hbox(
|
var a = Primitive.hbox(
|
||||||
Primitive.button("ok", onYes),
|
Primitive.button("ok", () -> { onYes.run(); this.hide(); }),
|
||||||
Primitive.button("no", onNo),
|
Primitive.button("no", () -> { onNo.run(); this.hide(); }),
|
||||||
Primitive.button("never", onNever)
|
Primitive.button("never", () -> { onNever.run(); this.hide(); })
|
||||||
);
|
);
|
||||||
|
|
||||||
var txt = Primitive.text(text);
|
var txt = Primitive.text(text);
|
||||||
|
|||||||
@@ -1,41 +1,32 @@
|
|||||||
package org.toop.app.widget.tutorial;
|
package org.toop.app.widget.tutorial;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.geometry.Pos;
|
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.app.widget.complex.ViewWidget;
|
||||||
import org.toop.framework.resource.ResourceManager;
|
import org.toop.framework.resource.ResourceManager;
|
||||||
import org.toop.framework.resource.resources.ImageAsset;
|
import org.toop.framework.resource.resources.ImageAsset;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TicTacToeTutorialWidget extends BaseTutorialWidget {
|
public class TicTacToeTutorialWidget extends BaseTutorialWidget {
|
||||||
|
|
||||||
private final String[] keys;
|
public TicTacToeTutorialWidget(GameInformation gameInformation) {
|
||||||
private final ImageAsset[] images;
|
super(List.of(
|
||||||
|
new ImmutablePair<>("tictactoe1", ResourceManager.get("tictactoe1.png")),
|
||||||
|
new ImmutablePair<>("tictactoe2", ResourceManager.get("tictactoe2.png"))
|
||||||
|
), () -> Platform.runLater(() -> new TicTacToeGameThread(gameInformation)));
|
||||||
|
}
|
||||||
|
|
||||||
public TicTacToeTutorialWidget() {
|
public TicTacToeTutorialWidget() {
|
||||||
String[] newKeys = {"tictactoe1", "tictactoe2"};
|
super(List.of(
|
||||||
ImageAsset[] newImages = {
|
new ImmutablePair<>("tictactoe1", ResourceManager.get("tictactoe1.png")),
|
||||||
ResourceManager.get("tictactoe1.png"),
|
new ImmutablePair<>("tictactoe2", ResourceManager.get("tictactoe2.png"))
|
||||||
ResourceManager.get("tictactoe2.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class LocalMultiplayerView extends ViewWidget {
|
|||||||
"tutorial",
|
"tutorial",
|
||||||
() -> {
|
() -> {
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
AppSettings.getSettings().setFirstTTT(false);
|
||||||
new TicTacToeTutorialWidget();
|
new TicTacToeTutorialWidget(information);
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
AppSettings.getSettings().setFirstTTT(false);
|
||||||
@@ -67,7 +67,7 @@ public class LocalMultiplayerView extends ViewWidget {
|
|||||||
"tutorial",
|
"tutorial",
|
||||||
() -> {
|
() -> {
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
AppSettings.getSettings().setFirstTTT(false);
|
||||||
new ReversiTutorialWidget();
|
new ReversiTutorialWidget(information);
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
AppSettings.getSettings().setFirstTTT(false);
|
||||||
@@ -93,7 +93,7 @@ public class LocalMultiplayerView extends ViewWidget {
|
|||||||
"tutorial",
|
"tutorial",
|
||||||
() -> {
|
() -> {
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
AppSettings.getSettings().setFirstTTT(false);
|
||||||
new Connect4TutorialWidget();
|
new Connect4TutorialWidget(information);
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
AppSettings.getSettings().setFirstTTT(false);
|
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.
|
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.
|
reversi4=The player who wins at the end of the game is the one who has the most pieces on the board.
|
||||||
tutorialstring=Tutorial
|
tutorialstring=Tutorial
|
||||||
|
startgame=Start game!
|
||||||
|
goback=Go back
|
||||||
|
|
||||||
|
|
||||||
arabic=\u0627\u0644\u0639\u0631\u0628\u064a\u0629 (Arabic)
|
arabic=\u0627\u0644\u0639\u0631\u0628\u064a\u0629 (Arabic)
|
||||||
|
|||||||
Reference in New Issue
Block a user