diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginFXMLController.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginFXMLController.java index aa14fed..7528328 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginFXMLController.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LoginFXMLController.java @@ -95,6 +95,7 @@ public class LoginFXMLController { return; } + updateLoginButton(false); controller.setMyUsername(nome); new Thread(() -> { @@ -103,11 +104,26 @@ public class LoginFXMLController { System.setProperty("java.rmi.server.hostname", localInterface); connect(nome, ip, numPlayers, localInterface); } catch (Exception ex) { - Platform.runLater(() -> showError("Network error: " + ex.getMessage())); + Platform.runLater(() -> { + showError("Network error: " + ex.getMessage()); + updateLoginButton(true); + }); } }).start(); } + private void updateLoginButton(boolean enabled) { + btnAccedi.setDisable(!enabled); + btnAccedi.setStyle( + "-fx-font-family: 'Cinzel'; -fx-font-size: 12; -fx-font-weight: bold;" + + "-fx-letter-spacing: 4; -fx-text-fill: #0c0601;" + + "-fx-background-color: linear-gradient(to right, #f4c05a, #c8791a, #f4c05a);" + + "-fx-padding: 13 48 13 48; -fx-background-radius: 2;" + + "-fx-opacity: " + (enabled ? "1.0" : "0.3") + ";" + + "-fx-cursor: " + (enabled ? "hand" : "default") + ";" + ); + } + private String resolveLocalInterface(String serverIp) throws Exception { if (serverIp.equalsIgnoreCase("localhost") || serverIp.startsWith("127.") || serverIp.isEmpty()) { return "127.0.0.1"; @@ -154,21 +170,27 @@ public class LoginFXMLController { private void connect(String nome, String ip, int numPlayers, String localInterface) { if (isRMI) { RMIClient client = new RMIClient(controller, ip, 1099, localInterface); - ErrorType serverResponse=client.connect(nome, numPlayers); - if (serverResponse==null) { + ErrorType serverResponse = client.connect(nome, numPlayers); + if (serverResponse == null) { controller.setClient(client); Platform.runLater(() -> showSuccess("Connected! Waiting for other players…")); } else { - Platform.runLater(() -> showError(serverResponse)); + Platform.runLater(() -> { + showError(serverResponse); + updateLoginButton(true); + }); } } else { TCPClient client = new TCPClient(controller, ip, 8080, 8081); - ErrorType serverResponse=client.connect(nome, numPlayers); - if (serverResponse==null) { + ErrorType serverResponse = client.connect(nome, numPlayers); + if (serverResponse == null) { controller.setClient(client); Platform.runLater(() -> showSuccess("Connected! Waiting for other players…")); } else { - Platform.runLater(() -> showError(serverResponse)); + Platform.runLater(() -> { + showError(serverResponse); + updateLoginButton(true); + }); } } }