mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Tutorial images now use ImageAsset.java
This commit is contained in:
@@ -47,8 +47,7 @@ public final class Primitive {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImageView image(File file) {
|
public static ImageView image(ImageAsset imageAsset) {
|
||||||
ImageAsset imageAsset = new ImageAsset(file);
|
|
||||||
ImageView imageView = new ImageView(imageAsset.getImage());
|
ImageView imageView = new ImageView(imageAsset.getImage());
|
||||||
imageView.getStyleClass().add("image");
|
imageView.getStyleClass().add("image");
|
||||||
imageView.setPreserveRatio(true);
|
imageView.setPreserveRatio(true);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.toop.app.widget.complex.PopupWidget;
|
|||||||
import org.toop.app.widget.complex.ViewWidget;
|
import org.toop.app.widget.complex.ViewWidget;
|
||||||
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import org.toop.framework.resource.resources.ImageAsset;
|
||||||
import org.toop.local.AppContext;
|
import org.toop.local.AppContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -35,7 +36,7 @@ public class BaseTutorialWidget extends PopupWidget {
|
|||||||
this.nextButton = Primitive.button(">", onNext);
|
this.nextButton = Primitive.button(">", onNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTutorial(File image, Runnable onPrevious, Runnable onNext) {
|
public void setTutorial(ImageAsset image, Runnable onPrevious, Runnable onNext) {
|
||||||
setOnPrevious(onPrevious);
|
setOnPrevious(onPrevious);
|
||||||
setOnNext(onNext);
|
setOnNext(onNext);
|
||||||
this.imagery = Primitive.image(image);
|
this.imagery = Primitive.image(image);
|
||||||
@@ -44,7 +45,7 @@ public class BaseTutorialWidget extends PopupWidget {
|
|||||||
add(Pos.CENTER, Primitive.vbox(x, w));
|
add(Pos.CENTER, Primitive.vbox(x, w));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(boolean next, String[] locKeys, File[] imgs) {
|
public void update(boolean next, String[] locKeys, ImageAsset[] imgs) {
|
||||||
currentTextIndex = next ? currentTextIndex + 1 : currentTextIndex - 1;
|
currentTextIndex = next ? currentTextIndex + 1 : currentTextIndex - 1;
|
||||||
|
|
||||||
if (currentTextIndex >= locKeys.length) {
|
if (currentTextIndex >= locKeys.length) {
|
||||||
|
|||||||
@@ -2,25 +2,29 @@ package org.toop.app.widget.tutorial;
|
|||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
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.resources.ImageAsset;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class Connect4TutorialWidget extends BaseTutorialWidget {
|
public class Connect4TutorialWidget extends BaseTutorialWidget {
|
||||||
private final String[] keys;
|
private final String[] keys;
|
||||||
|
private final ImageAsset[] images;
|
||||||
private final File[] images = {
|
|
||||||
new File("app/src/main/resources/assets/images/connect41.png"),
|
|
||||||
new File("app/src/main/resources/assets/images/connect42.png")
|
|
||||||
};
|
|
||||||
|
|
||||||
public Connect4TutorialWidget() {
|
public Connect4TutorialWidget() {
|
||||||
String[] newKeys = {
|
String[] newKeys = {
|
||||||
"connect4.1", "connect4.2"
|
"connect4.1", "connect4.2"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ImageAsset[] newImages = {
|
||||||
|
ResourceManager.get("connect41.png"),
|
||||||
|
ResourceManager.get("connect42.png")
|
||||||
|
};
|
||||||
|
|
||||||
super(newKeys[0]);
|
super(newKeys[0]);
|
||||||
|
|
||||||
keys = newKeys;
|
keys = newKeys;
|
||||||
|
images = newImages;
|
||||||
|
|
||||||
setTutorial(
|
setTutorial(
|
||||||
images[0],
|
images[0],
|
||||||
@@ -33,7 +37,7 @@ public class Connect4TutorialWidget extends BaseTutorialWidget {
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File[] getImages() {
|
public ImageAsset[] getImages() {
|
||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,28 @@ package org.toop.app.widget.tutorial;
|
|||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
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.resources.ImageAsset;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class ReversiTutorialWidget extends BaseTutorialWidget {
|
public class ReversiTutorialWidget extends BaseTutorialWidget {
|
||||||
private final String[] keys;
|
private final String[] keys;
|
||||||
private final File[] images = {new File("app/src/main/resources/assets/images/reversi1.png"), new File("app/src/main/resources/assets/images/reversi2.png"), new File("app/src/main/resources/assets/images/cat.jpg"), new File("app/src/main/resources/assets/images/cat.jpg")};
|
private final ImageAsset[] images;
|
||||||
|
|
||||||
public ReversiTutorialWidget() {
|
public ReversiTutorialWidget() {
|
||||||
String[] newKeys = {"reversi1", "reversi2", "reversi3", "reversi4"};
|
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]);
|
super(newKeys[0]);
|
||||||
|
|
||||||
keys = newKeys;
|
keys = newKeys;
|
||||||
|
images = newImages;
|
||||||
|
|
||||||
setTutorial(
|
setTutorial(
|
||||||
images[0],
|
images[0],
|
||||||
@@ -27,7 +36,7 @@ public class ReversiTutorialWidget extends BaseTutorialWidget {
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File[] getImages() {
|
public ImageAsset[] getImages() {
|
||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,15 @@ import org.toop.app.widget.WidgetContainer;
|
|||||||
import org.toop.app.widget.complex.PopupWidget;
|
import org.toop.app.widget.complex.PopupWidget;
|
||||||
|
|
||||||
public class ShowEnableTutorialWidget extends PopupWidget {
|
public class ShowEnableTutorialWidget extends PopupWidget {
|
||||||
// private final Button yesButton;
|
|
||||||
// private final Button noButton;
|
|
||||||
// private final Button neverButton;
|
|
||||||
|
|
||||||
public ShowEnableTutorialWidget(String words, Runnable onYes, Runnable onNo, Runnable onNever) {
|
|
||||||
// this.yesButton = Primitive.button("ok", onYes);
|
|
||||||
// this.noButton = Primitive.button("no", onNo);
|
|
||||||
// this.neverButton = Primitive.button("never", 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),
|
||||||
Primitive.button("no", onNo),
|
Primitive.button("no", onNo),
|
||||||
Primitive.button("never", onNever)
|
Primitive.button("never", onNever)
|
||||||
);
|
);
|
||||||
|
|
||||||
var txt = Primitive.text(words);
|
var txt = Primitive.text(text);
|
||||||
add(Pos.CENTER, Primitive.vbox(txt, a));
|
add(Pos.CENTER, Primitive.vbox(txt, a));
|
||||||
WidgetContainer.add(Pos.CENTER, this);
|
WidgetContainer.add(Pos.CENTER, this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,27 @@ package org.toop.app.widget.tutorial;
|
|||||||
|
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
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.resources.ImageAsset;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class TicTacToeTutorialWidget extends BaseTutorialWidget {
|
public class TicTacToeTutorialWidget extends BaseTutorialWidget {
|
||||||
|
|
||||||
private final String[] keys;
|
private final String[] keys;
|
||||||
private final File[] images = {
|
private final ImageAsset[] images;
|
||||||
new File("app/src/main/resources/assets/images/tictactoe1.png"),
|
|
||||||
new File("app/src/main/resources/assets/images/tictactoe2.png")
|
|
||||||
};
|
|
||||||
|
|
||||||
public TicTacToeTutorialWidget() {
|
public TicTacToeTutorialWidget() {
|
||||||
String[] newKeys = {"tictactoe1", "tictactoe2"};
|
String[] newKeys = {"tictactoe1", "tictactoe2"};
|
||||||
|
ImageAsset[] newImages = {
|
||||||
|
ResourceManager.get("tictactoe1.png"),
|
||||||
|
ResourceManager.get("tictactoe2.png")
|
||||||
|
};
|
||||||
|
|
||||||
super(newKeys[0]);
|
super(newKeys[0]);
|
||||||
|
|
||||||
keys = newKeys;
|
keys = newKeys;
|
||||||
|
images = newImages;
|
||||||
|
|
||||||
setTutorial(
|
setTutorial(
|
||||||
images[0],
|
images[0],
|
||||||
@@ -30,7 +35,7 @@ public class TicTacToeTutorialWidget extends BaseTutorialWidget {
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File[] getImages() {
|
public ImageAsset[] getImages() {
|
||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.toop.framework.resource.types.LoadableResource;
|
|||||||
|
|
||||||
@FileExtension({"png", "jpg", "jpeg"})
|
@FileExtension({"png", "jpg", "jpeg"})
|
||||||
public class ImageAsset extends BaseResource implements LoadableResource {
|
public class ImageAsset extends BaseResource implements LoadableResource {
|
||||||
private Image image;
|
private Image image = null;
|
||||||
|
|
||||||
public ImageAsset(final File file) {
|
public ImageAsset(final File file) {
|
||||||
super(file);
|
super(file);
|
||||||
@@ -40,8 +40,7 @@ public class ImageAsset extends BaseResource implements LoadableResource {
|
|||||||
public Image getImage() {
|
public Image getImage() {
|
||||||
if (!this.isLoaded) {
|
if (!this.isLoaded) {
|
||||||
this.load();
|
this.load();
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user