Added quit button to GUI

This commit is contained in:
2026-06-14 23:19:54 +02:00
parent d9fa4225da
commit 6e8eda0198
9 changed files with 38 additions and 50 deletions
@@ -311,7 +311,7 @@ public class Player implements Serializable {
}
if(!this.gatherers.isEmpty()){
table.addRow(this.gatherers.size() + " Gatherers: \uD83C\uDF56:-" + 3*this.gatherers.size());
table.addRow(this.gatherers.size() + " Gatherers: \uD83C\uDF56:" + 3*this.gatherers.size());
if(last == 3){
table.addSeparator();
}
@@ -6,6 +6,8 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
import it.polimi.ingsw.gc14.Network.EventType;
import javafx.application.Platform;
import javafx.animation.PauseTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.TranslateTransition;
import javafx.event.Event;
@@ -54,6 +56,8 @@ public class MainFXMLController {
@FXML private Button skipBtn;
/** Button that opens the game details popup. */
@FXML private Button detailsBtn;
/** Button that disconnects and closes the client. */
@FXML private Button quitBtn;
/** Label showing the current round number and game stage. */
@FXML private Label infoText;
/** Maps each player's username to their current food-value label in the side panel. */
@@ -98,6 +102,30 @@ public class MainFXMLController {
public void setController(ClientController controller) {
this.controller = controller;
skipBtn.setOnAction(e -> controller.skipTurn());
PauseTransition quitTimer = new PauseTransition(javafx.util.Duration.seconds(3));
quitTimer.setOnFinished(e -> {
quitBtn.setText("Quit");
quitBtn.setStyle("");
});
final boolean[] quitPending = {false};
quitBtn.setOnAction(e -> {
if (quitPending[0]) {
controller.disconnect();
Platform.exit();
System.exit(0);
} else {
quitPending[0] = true;
quitBtn.setText("Sure?");
quitBtn.setStyle("-fx-background-color: #c0392b; -fx-text-fill: white;");
quitTimer.playFromStart();
quitTimer.setOnFinished(ev -> {
quitPending[0] = false;
quitBtn.setText("Quit");
quitBtn.setStyle("");
});
}
});
}
/** Initializes the scene: loads fonts, sets up the popup, and registers input listeners. */
@@ -107,6 +135,7 @@ public class MainFXMLController {
addHoverZoom(skipBtn);
addHoverZoom(detailsBtn);
addHoverZoom(quitBtn);
popup = new Popup();
mainHBox.sceneProperty().addListener((obs, oldScene, newScene) -> {
if (newScene != null) {
@@ -295,8 +295,8 @@ public class TUI implements IView {
var upperCards = new AsciiTable(BorderStyle.ROUNDED, 2);
var lowerCards = new AsciiTable(BorderStyle.ROUNDED, 2);
upperCards.addHeader("Char/Events", "Building");
lowerCards.addHeader("Char/Events", "Building");
upperCards.addHeader("Char/\033[38;5;180mEvents\033[0m", "Building");
lowerCards.addHeader("Char/\033[38;5;180mEvents\033[0m", "Building");
int maxU = Math.max(model.upperListTribeCards.size(), model.upperListBuildingCards.size());
for (int i = 0; i < maxU; i++) {