Fix: login button doesn't allow multiple connection
This commit is contained in:
@@ -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";
|
||||
@@ -159,7 +175,10 @@ public class LoginFXMLController {
|
||||
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);
|
||||
@@ -168,7 +187,10 @@ public class LoginFXMLController {
|
||||
controller.setClient(client);
|
||||
Platform.runLater(() -> showSuccess("Connected! Waiting for other players…"));
|
||||
} else {
|
||||
Platform.runLater(() -> showError(serverResponse));
|
||||
Platform.runLater(() -> {
|
||||
showError(serverResponse);
|
||||
updateLoginButton(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user