mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
started working on the widget system
This commit is contained in:
@@ -3,6 +3,7 @@ package org.toop.app;
|
|||||||
import org.toop.app.view.ViewStack;
|
import org.toop.app.view.ViewStack;
|
||||||
import org.toop.app.view.views.MainView;
|
import org.toop.app.view.views.MainView;
|
||||||
import org.toop.app.view.views.QuitView;
|
import org.toop.app.view.views.QuitView;
|
||||||
|
import org.toop.app.widget.WidgetSystem;
|
||||||
import org.toop.framework.audio.events.AudioEvents;
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
import org.toop.framework.resource.ResourceManager;
|
import org.toop.framework.resource.ResourceManager;
|
||||||
@@ -30,14 +31,18 @@ public final class App extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) throws Exception {
|
||||||
final StackPane root = new StackPane();
|
final StackPane root = WidgetSystem.setup();
|
||||||
|
|
||||||
final Scene scene = new Scene(root);
|
final Scene scene = new Scene(root);
|
||||||
ViewStack.setup(scene);
|
ViewStack.setup(scene);
|
||||||
|
scene.setRoot(root);
|
||||||
|
|
||||||
stage.setTitle(AppContext.getString("app-title"));
|
stage.setTitle(AppContext.getString("app-title"));
|
||||||
stage.setWidth(1080);
|
stage.setWidth(1080);
|
||||||
stage.setHeight(720);
|
stage.setHeight(720);
|
||||||
|
|
||||||
|
scene.getRoot();
|
||||||
|
|
||||||
stage.setOnCloseRequest(event -> {
|
stage.setOnCloseRequest(event -> {
|
||||||
event.consume();
|
event.consume();
|
||||||
startQuit();
|
startQuit();
|
||||||
@@ -59,7 +64,7 @@ public final class App extends Application {
|
|||||||
AppSettings.applySettings();
|
AppSettings.applySettings();
|
||||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||||
|
|
||||||
ViewStack.push(new MainView());
|
// ViewStack.push(new MainView());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startQuit() {
|
public static void startQuit() {
|
||||||
|
|||||||
14
app/src/main/java/org/toop/app/Test.java
Normal file
14
app/src/main/java/org/toop/app/Test.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
//package org.toop.app;
|
||||||
|
//
|
||||||
|
//public class Quit {
|
||||||
|
// PopupWidget popup;
|
||||||
|
// Quit() {
|
||||||
|
// this.popup = new PopupWidget(
|
||||||
|
// new ConfirmationWidget(
|
||||||
|
// "are-you-sure",
|
||||||
|
// "yes", () -> App.quit(),
|
||||||
|
// "no", () -> popup.pop()
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@@ -17,7 +17,8 @@ public final class ReversiCanvas extends GameCanvas {
|
|||||||
drawDot(Color.WHITE, 27);
|
drawDot(Color.WHITE, 27);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawLegalPosition(int cell) {
|
public void drawLegalPosition(Color color, int cell) {
|
||||||
drawDot(new Color(1.0f, 0.0f, 0.0f, 0.5f), cell);
|
fill(new Color(color.getRed() * 0.25, color.getGreen() * 0.25, color.getBlue() * 0.25, 1.0), cell);
|
||||||
|
drawDot(new Color(color.getRed() * 0.5, color.getGreen() * 0.5, color.getBlue() * 0.5, 1.0), cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,16 +266,14 @@ public final class ReversiGame {
|
|||||||
final SequentialTransition animation = new SequentialTransition();
|
final SequentialTransition animation = new SequentialTransition();
|
||||||
isPaused.set(true);
|
isPaused.set(true);
|
||||||
|
|
||||||
|
final Color fromColor = game.getCurrentPlayer() == 0? Color.WHITE : Color.BLACK;
|
||||||
|
final Color toColor = game.getCurrentPlayer() == 0? Color.BLACK : Color.WHITE;
|
||||||
|
|
||||||
if (animate && flipped != null) {
|
if (animate && flipped != null) {
|
||||||
for (final Game.Move flip : flipped) {
|
for (final Game.Move flip : flipped) {
|
||||||
canvas.clear(flip.position());
|
canvas.clear(flip.position());
|
||||||
|
canvas.drawDot(fromColor, flip.position());
|
||||||
final Color from = flip.value() == 'W' ? Color.BLACK : Color.WHITE;
|
animation.getChildren().addFirst(canvas.flipDot(fromColor, toColor, flip.position()));
|
||||||
final Color to = flip.value() == 'W' ? Color.WHITE : Color.BLACK;
|
|
||||||
|
|
||||||
canvas.drawDot(from, flip.position());
|
|
||||||
|
|
||||||
animation.getChildren().addFirst(canvas.flipDot(from, to, flip.position()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +283,7 @@ public final class ReversiGame {
|
|||||||
final Game.Move[] legalMoves = game.getLegalMoves();
|
final Game.Move[] legalMoves = game.getLegalMoves();
|
||||||
|
|
||||||
for (final Game.Move legalMove : legalMoves) {
|
for (final Game.Move legalMove : legalMoves) {
|
||||||
canvas.drawLegalPosition(legalMove.position());
|
canvas.drawLegalPosition(toColor, legalMove.position());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
7
app/src/main/java/org/toop/app/widget/Widget.java
Normal file
7
app/src/main/java/org/toop/app/widget/Widget.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package org.toop.app.widget;
|
||||||
|
|
||||||
|
import javafx.scene.Node;
|
||||||
|
|
||||||
|
public interface Widget<T extends Node> {
|
||||||
|
T getNode();
|
||||||
|
}
|
||||||
28
app/src/main/java/org/toop/app/widget/WidgetSystem.java
Normal file
28
app/src/main/java/org/toop/app/widget/WidgetSystem.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package org.toop.app.widget;
|
||||||
|
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
|
||||||
|
public final class WidgetSystem {
|
||||||
|
private static StackPane root;
|
||||||
|
|
||||||
|
public static StackPane setup() {
|
||||||
|
if (root != null) {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
root = new StackPane();
|
||||||
|
root.getStyleClass().add("bg-primary");
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void add(Pos position, Widget<?> widget) {
|
||||||
|
StackPane.setAlignment(widget.getNode(), position);
|
||||||
|
root.getChildren().add(widget.getNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remove(Widget<?> widget) {
|
||||||
|
root.getChildren().remove(widget.getNode());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.toop.app.widget.complex;
|
||||||
|
|
||||||
|
import org.toop.app.widget.WidgetSystem;
|
||||||
|
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
|
||||||
|
public abstract class PopupWidget extends ViewWidget {
|
||||||
|
public PopupWidget() {
|
||||||
|
super("bg-popup");
|
||||||
|
WidgetSystem.add(Pos.CENTER, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pop() {
|
||||||
|
WidgetSystem.remove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.toop.app.widget.complex;
|
||||||
|
|
||||||
|
import org.toop.app.widget.WidgetSystem;
|
||||||
|
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
|
||||||
|
public abstract class PrimaryWidget extends ViewWidget {
|
||||||
|
public PrimaryWidget() {
|
||||||
|
super("bg-primary");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transition(PrimaryWidget primary) {
|
||||||
|
WidgetSystem.add(Pos.CENTER, primary);
|
||||||
|
WidgetSystem.remove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.toop.app.widget.complex;
|
||||||
|
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import org.toop.app.widget.Widget;
|
||||||
|
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
|
||||||
|
public abstract class ViewWidget extends StackPane implements Widget<StackPane> {
|
||||||
|
public ViewWidget(String cssClass) {
|
||||||
|
getStyleClass().add(cssClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Pos position, Widget<?> widget) {
|
||||||
|
setAlignment(widget.getNode(), position);
|
||||||
|
getChildren().add(widget.getNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StackPane getNode() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void reload();
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.toop.app.widget.simple;
|
||||||
|
|
||||||
|
import org.toop.app.widget.Widget;
|
||||||
|
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
|
|
||||||
|
public class LabeledButtonWidget extends VBox implements Widget<VBox> {
|
||||||
|
public LabeledButtonWidget(
|
||||||
|
String labelText,
|
||||||
|
String buttonText, Runnable buttonOnAction
|
||||||
|
) {
|
||||||
|
var text = new Text(labelText);
|
||||||
|
|
||||||
|
var button = new Button(buttonText);
|
||||||
|
button.setOnAction(_ -> buttonOnAction.run());
|
||||||
|
|
||||||
|
super(text, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VBox getNode() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/src/main/java/org/toop/app/widget/view/QuitView.java
Normal file
12
app/src/main/java/org/toop/app/widget/view/QuitView.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package org.toop.app.widget.view;
|
||||||
|
|
||||||
|
import org.toop.app.widget.complex.PopupWidget;
|
||||||
|
|
||||||
|
public class QuitView extends PopupWidget {
|
||||||
|
protected QuitView() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user