Merge branch 'Development' into 276-refactor-the-game-to-use-bitboards-instead

This commit is contained in:
2025-12-04 21:27:35 +01:00
8 changed files with 150 additions and 92 deletions

View File

@@ -1,5 +1,7 @@
package org.toop.app;
import javafx.application.Platform;
import javafx.scene.paint.Color;
import org.toop.Main;
import org.toop.app.widget.Primitive;
import org.toop.app.widget.Widget;
@@ -50,11 +52,13 @@ public final class App extends Application {
final StackPane root = WidgetContainer.setup();
final Scene scene = new Scene(root);
stage.setOpacity(0.0);
stage.setTitle(AppContext.getString("app-title"));
stage.titleProperty().bind(AppContext.bindToKey("app-title"));
stage.setWidth(1080);
stage.setHeight(720);
stage.setWidth(0);
stage.setHeight(0);
scene.getRoot();
@@ -79,26 +83,40 @@ public final class App extends Application {
AppSettings.applySettings();
LoadingWidget loading = new LoadingWidget(Primitive.text(
"Loading...", false), 0, 0, Integer.MAX_VALUE, false // Just set a high default
"Loading...", false), 0, 0, Integer.MAX_VALUE, false, false // Just set a high default
);
WidgetContainer.add(Pos.CENTER, loading);
WidgetContainer.setCurrentView(loading);
setOnLoadingSuccess(loading);
EventFlow loadingFlow = new EventFlow();
final boolean[] hasRun = {false};
loadingFlow
.listen(AssetLoaderEvents.LoadingProgressUpdate.class, e -> {
loading.setMaxAmount(e.isLoadingAmount());
if (!hasRun[0]) {
hasRun[0] = true;
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
Platform.runLater(() -> stage.setOpacity(1.0));
}
try {
loading.setAmount(e.hasLoadedAmount());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Platform.runLater(() -> loading.setMaxAmount(e.isLoadingAmount()));
Platform.runLater(() -> {
try {
loading.setAmount(e.hasLoadedAmount());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
});
if (e.hasLoadedAmount() >= e.isLoadingAmount()) {
loading.triggerSuccess();
Platform.runLater(loading::triggerSuccess);
loadingFlow.unsubscribe("init_loading");
}
@@ -107,7 +125,9 @@ public final class App extends Application {
// Start loading assets
new Thread(() -> ResourceManager.loadAssets(new ResourceLoader("app/src/main/resources/assets")))
.start();
stage.show();
}
private void setOnLoadingSuccess(LoadingWidget loading) {

View File

@@ -88,7 +88,7 @@ public final class Server {
final int reconnectAttempts = 10;
LoadingWidget loading = new LoadingWidget(
Primitive.text("connecting"), 0, 0, reconnectAttempts, true
Primitive.text("connecting"), 0, 0, reconnectAttempts, true, true
);
WidgetContainer.getCurrentView().transitionNext(loading);
@@ -102,6 +102,7 @@ public final class Server {
loading.setOnFailure(() -> {
WidgetContainer.getCurrentView().transitionPrevious();
a.unsubscribe("connecting");
a.unsubscribe("startclient");
WidgetContainer.add(
Pos.CENTER,
new ErrorPopup(AppContext.getString("connecting-failed") + " " + ip + ":" + port)
@@ -153,8 +154,6 @@ public final class Server {
.listen(NetworkEvents.GameResultResponse.class, this::handleGameResult, false)
.listen(NetworkEvents.GameMoveResponse.class, this::handleReceivedMove, false)
.listen(NetworkEvents.YourTurnResponse.class, this::handleYourTurn, false);
startPopulateScheduler();
populateGameList();
}
private void sendChallenge(String opponent) {

View File

@@ -2,7 +2,9 @@ package org.toop.app.widget.complex;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.control.Control;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import org.toop.app.widget.Primitive;
@@ -12,7 +14,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class LoadingWidget extends ViewWidget implements Update { // TODO make of widget type
private final Text loadingText; // TODO Make changeable
private final ProgressBar progressBar;
private final ProgressIndicator progressBar;
private final AtomicBoolean successTriggered = new AtomicBoolean(false);
private final AtomicBoolean failureTriggered = new AtomicBoolean(false);
@@ -25,7 +27,7 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
private Callable<Boolean> failureTrigger = () -> (amount < minAmount);
private float percentage = 0.0f;
private boolean isInfiniteBar = false;
private boolean isInfinite = false;
/**
*
@@ -36,17 +38,18 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
* @param startAmount The starting amount.
* @param maxAmount The max amount.
*/
public LoadingWidget(Text loadingText, int minAmount, int startAmount, int maxAmount, boolean infiniteBar) {
isInfiniteBar = infiniteBar;
public LoadingWidget(Text loadingText, int minAmount, int startAmount, int maxAmount, boolean infinite, boolean circle) {
isInfinite = infinite;
this.maxAmount = maxAmount;
this.minAmount = minAmount;
amount = startAmount;
this.loadingText = loadingText;
progressBar = new ProgressBar();
progressBar = circle ? new ProgressIndicator() : new ProgressBar();
VBox box = Primitive.vbox(this.loadingText, progressBar);
progressBar.getStyleClass().add("loading-progress-bar");
add(Pos.CENTER, box);
}
@@ -75,6 +78,10 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
return (failureTriggered.get() || successTriggered.get());
}
public ProgressIndicator getProgressBar() {
return progressBar;
}
/**
* What to do when success is triggered.
* @param onSuccess The lambda that gets run on success.
@@ -148,6 +155,8 @@ public class LoadingWidget extends ViewWidget implements Update { // TODO make o
if (maxAmount != 0) {
percentage = (float) amount / maxAmount;
}
if (!isInfiniteBar) progressBar.setProgress(percentage);
if (!isInfinite) {
progressBar.setProgress(percentage);
}
}
}

View File

@@ -33,7 +33,7 @@ public class SongDisplay extends VBox implements Widget {
songTitle.getStyleClass().add("song-title");
progressBar = new ProgressBar(0);
progressBar.getStyleClass().add("progress-bar");
progressBar.getStyleClass().add("loading-progress-bar");
progressText = new Text("0:00/0:00");
progressText.getStyleClass().add("progress-text");

View File

@@ -16,7 +16,6 @@
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
-fx-min-width: 220px;
-fx-max-width: 260px;
}
@@ -39,6 +38,18 @@
-fx-background-radius: 30px;
}
.loading-progress-bar {
-fx-progress-color: #3caf3f;
}
.loading-progress-bar > .bar {
-fx-background-color: #3caf3f;
}
.loading-progress-bar > .track {
-fx-background-color: rgba(0,0,0,0.15);
}
.progress-text {
-fx-font-size: 11px;
-fx-fill: white;

View File

@@ -13,68 +13,77 @@
}
.song-display {
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
-fx-min-width: 220px;
-fx-max-width: 260px;
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-min-width: 220px;
-fx-max-width: 260px;
}
.song-title {
-fx-font-size: 14px;
-fx-fill: white;
-fx-font-size: 14px;
-fx-fill: white;
}
.progress-bar {
-fx-pref-width: 200px;
-fx-accent: red;
-fx-inner-background-color: black;
-fx-pref-width: 200px;
-fx-accent: red;
}
.progress-bar > .track {
-fx-background-radius: 30;
-fx-background-radius: 30;
}
.progress-bar > .bar {
-fx-background-radius: 30px;
-fx-background-radius: 30px;
}
.loading-progress-bar {
-fx-progress-color: #28a428;
}
.loading-progress-bar > .bar {
-fx-background-color: #28a428;
}
.loading-progress-bar > .track {
-fx-background-color: rgba(0,0,0,0.15);
}
.progress-text {
-fx-font-size: 11px;
-fx-fill: white;
-fx-font-size: 11px;
-fx-fill: white;
}
.skip-button {
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-text-fill: white;
}
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
}
.skip-button .text {
-fx-fill: white;
.skip-button > .text {
-fx-fill: white;
}
.pause-button {
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-text-fill: white;
}
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
}
.pause-button .text {
-fx-fill: white;
.pause-button > .text {
-fx-fill: white;
}
.previous-button {
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-text-fill: white;
}
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
}
.previous-button .text {
-fx-fill: white;
.previous-button > .text {
-fx-fill: white;
}
.button {

View File

@@ -13,69 +13,79 @@
}
.song-display {
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
-fx-min-width: 220px;
-fx-max-width: 260px;
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-min-width: 220px;
-fx-max-width: 260px;
}
.song-title {
-fx-font-size: 14px;
-fx-fill: black;
-fx-font-size: 14px;
-fx-effect: null;
}
.progress-bar {
-fx-inner-background-color: black;
-fx-pref-width: 200px;
-fx-accent: red;
-fx-inner-background-color: black;
-fx-pref-width: 200px;
-fx-accent: red;
}
.progress-bar > .track {
-fx-background-radius: 30;
-fx-background-radius: 30;
}
.progress-bar > .bar {
-fx-background-radius: 30px;
-fx-background-radius: 30px;
}
.loading-progress-bar {
-fx-progress-color: #3caf3f;
}
.loading-progress-bar > .bar {
-fx-background-color: linear-gradient(to bottom, #a2d1a1, #b8e3b9);
}
.loading-progress-bar > .track {
-fx-background-color: rgba(0,0,0,0.15);
}
.progress-text {
-fx-font-size: 11px;
-fx-fill: black;
-fx-font-size: 11px;
-fx-effect: null;
}
.skip-button {
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-text-fill: black;
}
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-effect: null;
}
.skip-button .text {
-fx-fill: black;
}
.pause-button {
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-text-fill: black;
}
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-effect: null;
}
.pause-button .text {
-fx-fill: black;
-fx-effect: null;
}
.previous-button {
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-text-fill: black;
}
-fx-background-color: transparent;
-fx-background-radius: 0;
-fx-cursor: hand;
-fx-effect: null;
}
.previous-button .text {
-fx-fill: black;
-fx-effect: null;
}
.button {