Login remake with font

This commit is contained in:
2026-05-20 16:53:43 +02:00
parent c48180e1b8
commit 2157925746
3 changed files with 83 additions and 43 deletions
@@ -5,6 +5,7 @@ import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
import javafx.animation.*;
import javafx.application.Platform;
import javafx.css.PseudoClass;
import javafx.fxml.FXML;
import javafx.geometry.Rectangle2D;
import javafx.scene.control.*;
@@ -35,29 +36,31 @@ public class LoginFXMLController {
private boolean isRMI = true;
private ClientController controller;
// Definiamo lo pseudo-stato custom per il CSS corrispondente a ":active-protocol"
private final PseudoClass activeProtocolPseudo = PseudoClass.getPseudoClass("active-protocol");
public void setController(ClientController controller) {
this.controller = controller;
}
@FXML
public void initialize() {
// Background
// Background setup
Image img = new Image(getClass().getResourceAsStream("/GUIImages/Background.png"));
backgroundImage.setImage(img);
Rectangle2D screenBounds = Screen.getPrimary().getBounds();
backgroundImage.setFitWidth(screenBounds.getWidth());
backgroundImage.setFitHeight(screenBounds.getHeight());
// Protocol toggle
// Protocol toggle configuration
protocolToggle.setOnMouseClicked(e -> switchProtocol());
protocolToggle.setStyle(protocolToggle.getStyle() + " -fx-cursor: hand;");
// Button hover
final String BASE_BTN = btnAccedi.getStyle();
btnAccedi.setOnMouseEntered(e -> btnAccedi.setStyle(BASE_BTN +
"-fx-effect: dropshadow(gaussian, rgba(244,192,90,0.45), 18, 0, 0, 0);"));
btnAccedi.setOnMouseExited(e -> btnAccedi.setStyle(BASE_BTN));
// Inizializza lo stato grafico iniziale (RMI attivo)
labelRMI.pseudoClassStateChanged(activeProtocolPseudo, true);
labelTCP.pseudoClassStateChanged(activeProtocolPseudo, false);
// Login Action
btnAccedi.setOnAction(e -> onAccediClick());
}
@@ -68,10 +71,9 @@ public class LoginFXMLController {
tt.setToX(isRMI ? 0 : 110);
tt.play();
labelRMI.setStyle("-fx-font-family: 'Cinzel'; -fx-font-size: 11; -fx-font-weight: bold;" +
"-fx-text-fill: " + (isRMI ? "#0c0601" : "rgba(244,192,90,0.55)") + ";");
labelTCP.setStyle("-fx-font-family: 'Cinzel'; -fx-font-size: 11; -fx-font-weight: bold;" +
"-fx-text-fill: " + (isRMI ? "rgba(244,192,90,0.55)" : "#0c0601") + ";");
// Modifica in modo sicuro lo stato senza distruggere i parametri di layout dei nodi
labelRMI.pseudoClassStateChanged(activeProtocolPseudo, isRMI);
labelTCP.pseudoClassStateChanged(activeProtocolPseudo, !isRMI);
}
@FXML
@@ -94,7 +96,6 @@ public class LoginFXMLController {
controller.setMyUsername(nome);
// Resolve the local interface to use, then connect
new Thread(() -> {
try {
String localInterface = resolveLocalInterface(ip);
@@ -106,21 +107,12 @@ public class LoginFXMLController {
}).start();
}
/**
* Given the server IP, finds the local network interface whose subnet
* contains that IP. Falls back to the default route for non-LAN addresses.
* Handles "localhost" and "127.x.x.x" explicitly.
*/
private String resolveLocalInterface(String serverIp) throws Exception {
// localhost shortcut
if (serverIp.equalsIgnoreCase("localhost") ||
serverIp.startsWith("127.") || serverIp.isEmpty()) {
if (serverIp.equalsIgnoreCase("localhost") || serverIp.startsWith("127.") || serverIp.isEmpty()) {
return "127.0.0.1";
}
InetAddress serverAddr = InetAddress.getByName(serverIp);
// Walk every local interface and check if serverAddr is in its subnet
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
while (ifaces.hasMoreElements()) {
NetworkInterface ni = ifaces.nextElement();
@@ -137,17 +129,12 @@ public class LoginFXMLController {
}
}
// No subnet match — use the address the OS would naturally pick
// by opening a UDP socket toward the server (no data is sent)
try (DatagramSocket socket = new DatagramSocket()) {
socket.connect(serverAddr, 9); // port 9 = discard, never actually used
socket.connect(serverAddr, 9);
return socket.getLocalAddress().getHostAddress();
}
}
/**
* Returns true if {@code a} and {@code b} are in the same /prefix subnet.
*/
private boolean sameSubnet(InetAddress a, InetAddress b, int prefix) {
if (prefix < 0 || prefix > 32) return false;
int maskBits = prefix == 0 ? 0 : (0xFFFFFFFF << (32 - prefix));
+20 -15
View File
@@ -3,12 +3,18 @@
<?import javafx.scene.control.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.image.ImageView?>
<?import java.net.URL?>
<StackPane xmlns="http://javafx.com/javafx/21"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="it.polimi.ingsw.gc14.View.GUI.LoginFXMLController"
prefWidth="1280" prefHeight="720"
style="-fx-background-color: #09060300;">
<stylesheets>
<URL value="@styles.css" />
</stylesheets>
<ImageView fx:id="backgroundImage" fitWidth="1920" fitHeight="1080" preserveRatio="false"/>
<!-- Corner decorations -->
@@ -46,7 +52,7 @@
<!-- Title -->
<Label text="MESOS"
style="-fx-font-family: 'Cinzel Decorative'; -fx-font-size: 28; -fx-font-weight: bold;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 24; -fx-font-weight: bold;
-fx-text-fill: #f4c05a;
-fx-effect: dropshadow(gaussian, rgba(244,192,90,0.4), 28, 0, 0, 0);">
<VBox.margin><Insets bottom="4"/></VBox.margin>
@@ -60,12 +66,12 @@
<!-- Username -->
<Label text="USERNAME"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 9; -fx-letter-spacing: 3;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 9; -fx-letter-spacing: 2;
-fx-text-fill: rgba(244,192,90,0.7);">
<VBox.margin><Insets bottom="6"/></VBox.margin>
</Label>
<TextField fx:id="campoNome" promptText="Enter your name"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 12;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 11;
-fx-text-fill: #f0e0c0; -fx-prompt-text-fill: rgba(200,150,80,0.45);
-fx-background-color: rgba(244,192,90,0.07);
-fx-border-color: rgba(200,120,20,0.45); -fx-border-width: 0 0 1 0;
@@ -76,12 +82,12 @@
<!-- Num players -->
<Label text="NUMBER OF PLAYERS"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 9; -fx-letter-spacing: 3;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 9; -fx-letter-spacing: 2;
-fx-text-fill: rgba(244,192,90,0.7);">
<VBox.margin><Insets bottom="6"/></VBox.margin>
</Label>
<TextField fx:id="campoNumPlayers" promptText="2 5"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 12;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 11;
-fx-text-fill: #f0e0c0; -fx-prompt-text-fill: rgba(200,150,80,0.45);
-fx-background-color: rgba(244,192,90,0.07);
-fx-border-color: rgba(200,120,20,0.45); -fx-border-width: 0 0 1 0;
@@ -92,12 +98,12 @@
<!-- Server IP -->
<Label text="SERVER IP"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 9; -fx-letter-spacing: 3;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 9; -fx-letter-spacing: 2;
-fx-text-fill: rgba(244,192,90,0.7);">
<VBox.margin><Insets bottom="6"/></VBox.margin>
</Label>
<TextField fx:id="campoIP" promptText="localhost"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 12;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 11;
-fx-text-fill: #f0e0c0; -fx-prompt-text-fill: rgba(200,150,80,0.45);
-fx-background-color: rgba(244,192,90,0.07);
-fx-border-color: rgba(200,120,20,0.45); -fx-border-width: 0 0 1 0;
@@ -108,7 +114,7 @@
<!-- Protocol toggle -->
<Label text="PROTOCOL"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 9; -fx-letter-spacing: 3;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 9; -fx-letter-spacing: 2;
-fx-text-fill: rgba(244,192,90,0.7);">
<VBox.margin><Insets bottom="8"/></VBox.margin>
</Label>
@@ -123,26 +129,25 @@
-fx-background-radius: 2;"
StackPane.alignment="CENTER_LEFT"/>
<HBox prefWidth="220" prefHeight="36">
<!-- RMI parte attivo di default, usiamo la classe registrata -->
<Label fx:id="labelRMI" text="RMI" prefWidth="110" prefHeight="36" alignment="CENTER"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 11; -fx-font-weight: bold;
-fx-text-fill: #0c0601;"/>
styleClass="toggle-label"/>
<Label fx:id="labelTCP" text="TCP" prefWidth="110" prefHeight="36" alignment="CENTER"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 11; -fx-font-weight: bold;
-fx-text-fill: rgba(244,192,90,0.55);"/>
styleClass="toggle-label"/>
</HBox>
</StackPane>
<!-- Error label -->
<Label fx:id="labelErrore" maxWidth="Infinity" wrapText="true" textAlignment="CENTER"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 10; -fx-text-fill: #e05050;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 10; -fx-text-fill: #e05050;
-fx-min-height: 18;">
<VBox.margin><Insets bottom="16"/></VBox.margin>
</Label>
<!-- Connect button -->
<Button fx:id="btnAccedi" text="CONNECT" maxWidth="Infinity"
style="-fx-font-family: 'Cinzel'; -fx-font-size: 12; -fx-font-weight: bold;
-fx-letter-spacing: 4; -fx-text-fill: #0c0601;
style="-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 11; -fx-font-weight: bold;
-fx-letter-spacing: 3; -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-cursor: hand;"/>
+48
View File
@@ -1,3 +1,7 @@
/* ==========================================
STILI ORIGINALI PREESISTENTI
========================================== */
.card-list {
-fx-background-color: rgba(255,255,255,0.35);
-fx-background-radius: 15;
@@ -48,6 +52,7 @@
-fx-background-radius: 15, 12, 8, 4;
-fx-padding: 15 15 15 15;
}
.action-button {
-fx-background-color: #9d0208;
-fx-text-fill: white;
@@ -61,4 +66,47 @@
.action-button:hover {
-fx-background-color: #b42224;
}
/* Registrazione Font */
@font-face {
font-family: 'Inknut Antiqua';
src: url('../Fonts/InknutAntiqua-Regular.ttf');
}
@font-face {
font-family: 'Inknut Antiqua';
font-weight: bold;
src: url('../Fonts/InknutAntiqua-Bold.ttf');
}
.font-inknut-title {
-fx-font-family: 'Inknut Antiqua';
-fx-font-weight: bold;
-fx-font-size: 24;
}
.font-inknut-normal {
-fx-font-family: 'Inknut Antiqua';
}
.button:hover {
-fx-effect: dropshadow(gaussian, rgba(244,192,90,0.45), 18, 0, 0, 0);
}
/* ==========================================
NUOVI STILI AGGIUNTI PER IL TOGGLE
========================================== */
/* Struttura base fissa dei label RMI e TCP per evitare modifiche di layout */
.toggle-label {
-fx-font-family: 'Inknut Antiqua';
-fx-font-size: 11px;
-fx-font-weight: bold;
-fx-text-fill: rgba(244,192,90,0.55); /* Colore non attivo (dorato trasparente) */
}
/* Stato attivo del protocollo selezionato */
.toggle-label:active-protocol {
-fx-text-fill: #0c0601; /* Grigio scurissimo/nero sul cursore luminoso */
}