Added: Specific Error Display

This commit is contained in:
rubenpirreram
2026-05-26 19:08:11 +02:00
parent 9083fd8df4
commit 55ce0c1d0a
27 changed files with 223 additions and 149 deletions
@@ -1,25 +1,16 @@
package it.polimi.ingsw.gc14.View.GUI;
import it.polimi.ingsw.gc14.Controller.ClientController;
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
import it.polimi.ingsw.gc14.ErrorType;
import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.View.GUI.LoginFXMLController;
import it.polimi.ingsw.gc14.View.GUI.MainFXMLController;
import it.polimi.ingsw.gc14.View.IView;
import javafx.animation.PauseTransition;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.io.IOException;
import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.ENDED;
import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.TOTEM_CHOICE;
@@ -144,12 +135,11 @@ public class GUI extends Application implements IView {
}
@Override
public void showError(String message) {
public void showError(ErrorType error) {
Platform.runLater(() -> {
synchronized (miniModel) {
controllerMain.isError = true;
controllerMain.render();
System.out.println("ERRORE PORCODIDODODODOD");
}
});
}
@@ -1,6 +1,7 @@
package it.polimi.ingsw.gc14.View.GUI;
import it.polimi.ingsw.gc14.Controller.ClientController;
import it.polimi.ingsw.gc14.ErrorType;
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
import javafx.animation.*;
@@ -153,23 +154,28 @@ public class LoginFXMLController {
private void connect(String nome, String ip, int numPlayers, String localInterface) {
if (isRMI) {
RMIClient client = new RMIClient(controller, ip, 1099, localInterface);
if (client.connect(nome, numPlayers)) {
ErrorType serverResponse=client.connect(nome, numPlayers);
if (serverResponse==null) {
controller.setClient(client);
Platform.runLater(() -> showSuccess("Connected! Waiting for other players…"));
} else {
Platform.runLater(() -> showError("RMI connection failed."));
Platform.runLater(() -> showError(serverResponse));
}
} else {
TCPClient client = new TCPClient(controller, ip, 8080, 8081);
if (client.connect(nome, numPlayers)) {
ErrorType serverResponse=client.connect(nome, numPlayers);
if (serverResponse==null) {
controller.setClient(client);
Platform.runLater(() -> showSuccess("Connected! Waiting for other players…"));
} else {
Platform.runLater(() -> showError("TCP connection failed."));
Platform.runLater(() -> showError(serverResponse));
}
}
}
private void showError(ErrorType errorType) {
labelErrore.setTextFill(Color.web("#e05050"));
labelErrore.setText(errorType.toString());
}
private void showError(String msg) {
labelErrore.setTextFill(Color.web("#e05050"));
labelErrore.setText(msg);
@@ -1,5 +1,6 @@
package it.polimi.ingsw.gc14.View;
import it.polimi.ingsw.gc14.ErrorType;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
@@ -7,7 +8,9 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
public interface IView {
public void setModel(MiniModel miniModel);
public void render();
public void showMessage(String message);
public void showError(String message);
void showMessage(String message);
public void showError(ErrorType error);
}
@@ -1,4 +1,5 @@
package it.polimi.ingsw.gc14.View.TUI;
import it.polimi.ingsw.gc14.ErrorType;
import it.polimi.ingsw.gc14.Model.*;
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
@@ -231,12 +232,12 @@ public class TUI implements IView {
/**
* Prints an error message to standard output.
*
* @param message the error message to display
* @param error the error message to display
*/
public void showError(String message) {
public void showError(ErrorType error) {
clearTerminal();
render();
System.out.println(message);
System.out.println(error);
}
/**