Add: initialized GUI using FXML file and controller
@@ -50,7 +50,7 @@ public class ClientLauncherGUI extends Application {
|
|||||||
}).start();
|
}).start();
|
||||||
});
|
});
|
||||||
|
|
||||||
stage.setTitle("La mia app");
|
stage.setTitle("Mesos");
|
||||||
stage.setScene(loginView.getScene());
|
stage.setScene(loginView.getScene());
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class ClientController {
|
|||||||
*/
|
*/
|
||||||
public void setModel(Game model) {
|
public void setModel(Game model) {
|
||||||
localController.setModel(model);
|
localController.setModel(model);
|
||||||
view.update(localController.getModel());
|
view.setModel(localController.getModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ public class GUI implements IView { // stessa interfaccia che implementa TUI
|
|||||||
this.stage = stage;
|
this.stage = stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Game model) {
|
public void setModel(Game model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
mainView.setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +31,7 @@ public class GUI implements IView { // stessa interfaccia che implementa TUI
|
|||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
|
mainView.render();
|
||||||
stage.setScene(mainView.getScene());
|
stage.setScene(mainView.getScene());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package it.polimi.ingsw.gc14.View.GUI;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
|
||||||
|
public class LoginFXMLController {
|
||||||
|
|
||||||
|
@FXML private TextField campoNome;
|
||||||
|
@FXML private TextField campoNumPlayers;
|
||||||
|
@FXML private TextField campoIP;
|
||||||
|
@FXML private RadioButton btnRMI;
|
||||||
|
@FXML private RadioButton btnTCP;
|
||||||
|
@FXML private Button btnAccedi;
|
||||||
|
@FXML private Label labelErrore;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
// I RadioButton vanno collegati a un ToggleGroup a mano
|
||||||
|
// perché FXML non lo fa automaticamente
|
||||||
|
ToggleGroup group = new ToggleGroup();
|
||||||
|
btnRMI.setToggleGroup(group);
|
||||||
|
btnTCP.setToggleGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Getter esposti a LoginView ---
|
||||||
|
|
||||||
|
public Button getBtnAccedi() { return btnAccedi; }
|
||||||
|
|
||||||
|
public String getNome() { return campoNome.getText().trim(); }
|
||||||
|
|
||||||
|
public int getNumPlayers() {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(campoNumPlayers.getText().trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNetworkType() { return btnRMI.isSelected() ? 0 : 1; }
|
||||||
|
|
||||||
|
public String getIP() { return campoIP.getText().trim(); }
|
||||||
|
|
||||||
|
public void setErrore(String messaggio) { labelErrore.setText(messaggio); }
|
||||||
|
}
|
||||||
@@ -1,75 +1,35 @@
|
|||||||
package it.polimi.ingsw.gc14.View.GUI;
|
package it.polimi.ingsw.gc14.View.GUI;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.geometry.Pos;
|
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class LoginView {
|
public class LoginView {
|
||||||
|
|
||||||
private final Scene scene;
|
private final Scene scene;
|
||||||
|
private final LoginFXMLController fxmlController;
|
||||||
private final TextField campoNome = new TextField();
|
|
||||||
private final TextField campoNumPlayers = new TextField();
|
|
||||||
private final TextField campoIP = new TextField();
|
|
||||||
private final ToggleGroup networkGroup = new ToggleGroup();
|
|
||||||
private final RadioButton btnRMI = new RadioButton("RMI");
|
|
||||||
private final RadioButton btnTCP = new RadioButton("TCP");
|
|
||||||
private final Button btnAccedi = new Button("Connetti");
|
|
||||||
private final Label labelErrore = new Label("");
|
|
||||||
|
|
||||||
public LoginView() {
|
public LoginView() {
|
||||||
campoNome.setPromptText("Nome utente");
|
|
||||||
campoNumPlayers.setPromptText("Numero di giocatori");
|
|
||||||
campoIP.setPromptText("IP server");
|
|
||||||
|
|
||||||
btnRMI.setToggleGroup(networkGroup);
|
|
||||||
btnTCP.setToggleGroup(networkGroup);
|
|
||||||
btnRMI.setSelected(true); // RMI selezionato di default
|
|
||||||
|
|
||||||
labelErrore.setStyle("-fx-text-fill: red;");
|
|
||||||
|
|
||||||
VBox layout = new VBox(10,
|
|
||||||
new Label("Nome utente:"), campoNome,
|
|
||||||
new Label("Num. giocatori:"), campoNumPlayers,
|
|
||||||
new Label("Protocollo:"), btnRMI, btnTCP,
|
|
||||||
new Label("IP server:"), campoIP,
|
|
||||||
labelErrore,
|
|
||||||
btnAccedi
|
|
||||||
);
|
|
||||||
layout.setAlignment(Pos.CENTER_LEFT);
|
|
||||||
layout.setPadding(new Insets(40));
|
|
||||||
|
|
||||||
scene = new Scene(layout, 350, 380);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Getter esposti al launcher ---
|
|
||||||
|
|
||||||
public Scene getScene() { return scene; }
|
|
||||||
public Button getBtnAccedi() { return btnAccedi; }
|
|
||||||
|
|
||||||
public String getNome() {
|
|
||||||
return campoNome.getText().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumPlayers() {
|
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(campoNumPlayers.getText().trim());
|
FXMLLoader loader = new FXMLLoader(
|
||||||
} catch (NumberFormatException e) {
|
getClass().getResource("/GUIScene/login.fxml")
|
||||||
return -1; // il launcher controlla questo e mostra errore
|
);
|
||||||
|
scene = new Scene(loader.load(), 350, 380);
|
||||||
|
fxmlController = loader.getController();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Impossibile caricare login.fxml", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNetworkType() {
|
// --- Delega tutto al controller FXML ---
|
||||||
return btnRMI.isSelected() ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIP() {
|
public Scene getScene() { return scene; }
|
||||||
return campoIP.getText().trim();
|
public Button getBtnAccedi() { return fxmlController.getBtnAccedi(); }
|
||||||
}
|
public String getNome() { return fxmlController.getNome(); }
|
||||||
|
public int getNumPlayers() { return fxmlController.getNumPlayers(); }
|
||||||
public void setErrore(String messaggio) {
|
public int getNetworkType() { return fxmlController.getNetworkType(); }
|
||||||
labelErrore.setText(messaggio);
|
public String getIP() { return fxmlController.getIP(); }
|
||||||
}
|
public void setErrore(String messaggio) { fxmlController.setErrore(messaggio); }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package it.polimi.ingsw.gc14.View.GUI;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.image.*;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.scene.shape.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainFXMLController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private HBox board;
|
||||||
|
@FXML private HBox upperList;
|
||||||
|
@FXML private HBox lowerList;
|
||||||
|
@FXML private HBox myHand;
|
||||||
|
@FXML private VBox playersHand;
|
||||||
|
|
||||||
|
private Game model;
|
||||||
|
|
||||||
|
public void setModel(Game model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render() {
|
||||||
|
Image placeholder = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-001.png"));
|
||||||
|
|
||||||
|
for (TribeCard card : model.getUpperListTribeCards()) {
|
||||||
|
ImageView view = new ImageView(placeholder);
|
||||||
|
view.setFitWidth(80);
|
||||||
|
view.setFitHeight(120);
|
||||||
|
view.setPreserveRatio(true);
|
||||||
|
upperList.getChildren().add(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TribeCard card : model.getLowerListTribeCards()) {
|
||||||
|
ImageView view = new ImageView(placeholder);
|
||||||
|
view.setFitWidth(80);
|
||||||
|
view.setFitHeight(120);
|
||||||
|
view.setPreserveRatio(true);
|
||||||
|
lowerList.getChildren().add(view);
|
||||||
|
}
|
||||||
|
System.out.println("AGGIORNO GAGAGAGA");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,39 @@
|
|||||||
package it.polimi.ingsw.gc14.View.GUI;
|
package it.polimi.ingsw.gc14.View.GUI;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MainView {
|
public class MainView {
|
||||||
|
|
||||||
private final Scene scene;
|
private final Scene scene;
|
||||||
private final Label labelStato = new Label("In attesa di aggiornamenti...");
|
private final MainFXMLController fxmlController;
|
||||||
|
private Game model;
|
||||||
|
|
||||||
public MainView() {
|
public MainView() {
|
||||||
VBox layout = new VBox(16, labelStato);
|
try {
|
||||||
layout.setAlignment(Pos.CENTER);
|
FXMLLoader loader = new FXMLLoader(
|
||||||
layout.setPadding(new Insets(40));
|
getClass().getResource("/GUIScene/main.fxml")
|
||||||
scene = new Scene(layout, 800, 600);
|
);
|
||||||
|
scene = new Scene(loader.load(), 350, 380);
|
||||||
|
fxmlController = loader.getController();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Impossibile caricare login.fxml", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scene getScene() { return scene; }
|
public Scene getScene() { return scene; }
|
||||||
public void setStato(String testo) { labelStato.setText(testo); }
|
public void setModel(Game model) {
|
||||||
|
this.model = model;
|
||||||
|
fxmlController.setModel(model);
|
||||||
|
}
|
||||||
|
public void render() {
|
||||||
|
fxmlController.render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import it.polimi.ingsw.gc14.Model.Game;
|
|||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
|
|
||||||
public interface IView {
|
public interface IView {
|
||||||
public void update(Game game);
|
public void setModel(Game game);
|
||||||
public void render();
|
public void render();
|
||||||
public void showMessage(String message);
|
public void showMessage(String message);
|
||||||
public void showError(String message);
|
public void showError(String message);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class TUI implements IView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Game model) {
|
public void setModel(Game model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,4 +18,8 @@ module it.polimi.ingsw.gc14 {
|
|||||||
exports it.polimi.ingsw.gc14.Network.RMI.Client to java.rmi;
|
exports it.polimi.ingsw.gc14.Network.RMI.Client to java.rmi;
|
||||||
exports it.polimi.ingsw.gc14.Network to java.rmi;
|
exports it.polimi.ingsw.gc14.Network to java.rmi;
|
||||||
exports it.polimi.ingsw.gc14.Model to java.rmi, com.google.gson;
|
exports it.polimi.ingsw.gc14.Model to java.rmi, com.google.gson;
|
||||||
|
|
||||||
|
// GUI
|
||||||
|
opens it.polimi.ingsw.gc14.View.GUI to javafx.fxml;
|
||||||
|
exports it.polimi.ingsw.gc14.View.GUI;
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 832 KiB After Width: | Height: | Size: 832 KiB |
|
Before Width: | Height: | Size: 833 KiB After Width: | Height: | Size: 833 KiB |
|
Before Width: | Height: | Size: 834 KiB After Width: | Height: | Size: 834 KiB |
|
Before Width: | Height: | Size: 846 KiB After Width: | Height: | Size: 846 KiB |
|
Before Width: | Height: | Size: 905 KiB After Width: | Height: | Size: 905 KiB |
|
Before Width: | Height: | Size: 905 KiB After Width: | Height: | Size: 905 KiB |
|
Before Width: | Height: | Size: 884 KiB After Width: | Height: | Size: 884 KiB |
|
Before Width: | Height: | Size: 682 KiB After Width: | Height: | Size: 682 KiB |
|
Before Width: | Height: | Size: 979 KiB After Width: | Height: | Size: 979 KiB |
|
Before Width: | Height: | Size: 978 KiB After Width: | Height: | Size: 978 KiB |
|
Before Width: | Height: | Size: 1007 KiB After Width: | Height: | Size: 1007 KiB |
|
Before Width: | Height: | Size: 1007 KiB After Width: | Height: | Size: 1007 KiB |
|
Before Width: | Height: | Size: 1008 KiB After Width: | Height: | Size: 1008 KiB |
|
Before Width: | Height: | Size: 957 KiB After Width: | Height: | Size: 957 KiB |
|
Before Width: | Height: | Size: 953 KiB After Width: | Height: | Size: 953 KiB |
|
Before Width: | Height: | Size: 957 KiB After Width: | Height: | Size: 957 KiB |
|
Before Width: | Height: | Size: 952 KiB After Width: | Height: | Size: 952 KiB |
|
Before Width: | Height: | Size: 894 KiB After Width: | Height: | Size: 894 KiB |
|
Before Width: | Height: | Size: 891 KiB After Width: | Height: | Size: 891 KiB |
|
Before Width: | Height: | Size: 895 KiB After Width: | Height: | Size: 895 KiB |
|
Before Width: | Height: | Size: 891 KiB After Width: | Height: | Size: 891 KiB |
|
Before Width: | Height: | Size: 931 KiB After Width: | Height: | Size: 931 KiB |
|
Before Width: | Height: | Size: 926 KiB After Width: | Height: | Size: 926 KiB |
|
Before Width: | Height: | Size: 931 KiB After Width: | Height: | Size: 931 KiB |
|
Before Width: | Height: | Size: 926 KiB After Width: | Height: | Size: 926 KiB |
|
Before Width: | Height: | Size: 932 KiB After Width: | Height: | Size: 932 KiB |
|
Before Width: | Height: | Size: 840 KiB After Width: | Height: | Size: 840 KiB |
|
Before Width: | Height: | Size: 838 KiB After Width: | Height: | Size: 838 KiB |
|
Before Width: | Height: | Size: 836 KiB After Width: | Height: | Size: 836 KiB |
|
Before Width: | Height: | Size: 840 KiB After Width: | Height: | Size: 840 KiB |
|
Before Width: | Height: | Size: 842 KiB After Width: | Height: | Size: 842 KiB |
|
Before Width: | Height: | Size: 833 KiB After Width: | Height: | Size: 833 KiB |
|
Before Width: | Height: | Size: 837 KiB After Width: | Height: | Size: 837 KiB |
|
Before Width: | Height: | Size: 939 KiB After Width: | Height: | Size: 939 KiB |
|
Before Width: | Height: | Size: 936 KiB After Width: | Height: | Size: 936 KiB |
|
Before Width: | Height: | Size: 933 KiB After Width: | Height: | Size: 933 KiB |
|
Before Width: | Height: | Size: 931 KiB After Width: | Height: | Size: 931 KiB |
|
Before Width: | Height: | Size: 1007 KiB After Width: | Height: | Size: 1007 KiB |
|
Before Width: | Height: | Size: 1007 KiB After Width: | Height: | Size: 1007 KiB |
|
Before Width: | Height: | Size: 979 KiB After Width: | Height: | Size: 979 KiB |
|
Before Width: | Height: | Size: 979 KiB After Width: | Height: | Size: 979 KiB |
|
Before Width: | Height: | Size: 979 KiB After Width: | Height: | Size: 979 KiB |
|
Before Width: | Height: | Size: 1007 KiB After Width: | Height: | Size: 1007 KiB |
|
Before Width: | Height: | Size: 957 KiB After Width: | Height: | Size: 957 KiB |
|
Before Width: | Height: | Size: 952 KiB After Width: | Height: | Size: 952 KiB |
|
Before Width: | Height: | Size: 958 KiB After Width: | Height: | Size: 958 KiB |
|
Before Width: | Height: | Size: 952 KiB After Width: | Height: | Size: 952 KiB |
|
Before Width: | Height: | Size: 894 KiB After Width: | Height: | Size: 894 KiB |
|
Before Width: | Height: | Size: 892 KiB After Width: | Height: | Size: 892 KiB |
|
Before Width: | Height: | Size: 895 KiB After Width: | Height: | Size: 895 KiB |
|
Before Width: | Height: | Size: 891 KiB After Width: | Height: | Size: 891 KiB |
|
Before Width: | Height: | Size: 932 KiB After Width: | Height: | Size: 932 KiB |
|
Before Width: | Height: | Size: 926 KiB After Width: | Height: | Size: 926 KiB |
|
Before Width: | Height: | Size: 931 KiB After Width: | Height: | Size: 931 KiB |
|
Before Width: | Height: | Size: 926 KiB After Width: | Height: | Size: 926 KiB |
|
Before Width: | Height: | Size: 839 KiB After Width: | Height: | Size: 839 KiB |
|
Before Width: | Height: | Size: 834 KiB After Width: | Height: | Size: 834 KiB |
|
Before Width: | Height: | Size: 842 KiB After Width: | Height: | Size: 842 KiB |
|
Before Width: | Height: | Size: 833 KiB After Width: | Height: | Size: 833 KiB |
|
Before Width: | Height: | Size: 838 KiB After Width: | Height: | Size: 838 KiB |
|
Before Width: | Height: | Size: 840 KiB After Width: | Height: | Size: 840 KiB |
|
Before Width: | Height: | Size: 938 KiB After Width: | Height: | Size: 938 KiB |
|
Before Width: | Height: | Size: 936 KiB After Width: | Height: | Size: 936 KiB |
|
Before Width: | Height: | Size: 933 KiB After Width: | Height: | Size: 933 KiB |
|
Before Width: | Height: | Size: 936 KiB After Width: | Height: | Size: 936 KiB |
|
Before Width: | Height: | Size: 978 KiB After Width: | Height: | Size: 978 KiB |
|
Before Width: | Height: | Size: 1007 KiB After Width: | Height: | Size: 1007 KiB |
|
Before Width: | Height: | Size: 1007 KiB After Width: | Height: | Size: 1007 KiB |
|
Before Width: | Height: | Size: 979 KiB After Width: | Height: | Size: 979 KiB |
|
Before Width: | Height: | Size: 957 KiB After Width: | Height: | Size: 957 KiB |
|
Before Width: | Height: | Size: 952 KiB After Width: | Height: | Size: 952 KiB |
|
Before Width: | Height: | Size: 957 KiB After Width: | Height: | Size: 957 KiB |
|
Before Width: | Height: | Size: 952 KiB After Width: | Height: | Size: 952 KiB |
|
Before Width: | Height: | Size: 895 KiB After Width: | Height: | Size: 895 KiB |
|
Before Width: | Height: | Size: 891 KiB After Width: | Height: | Size: 891 KiB |
|
Before Width: | Height: | Size: 894 KiB After Width: | Height: | Size: 894 KiB |
|
Before Width: | Height: | Size: 926 KiB After Width: | Height: | Size: 926 KiB |
|
Before Width: | Height: | Size: 931 KiB After Width: | Height: | Size: 931 KiB |
|
Before Width: | Height: | Size: 926 KiB After Width: | Height: | Size: 926 KiB |
|
Before Width: | Height: | Size: 931 KiB After Width: | Height: | Size: 931 KiB |
|
Before Width: | Height: | Size: 833 KiB After Width: | Height: | Size: 833 KiB |
|
Before Width: | Height: | Size: 838 KiB After Width: | Height: | Size: 838 KiB |
|
Before Width: | Height: | Size: 836 KiB After Width: | Height: | Size: 836 KiB |
|
Before Width: | Height: | Size: 839 KiB After Width: | Height: | Size: 839 KiB |
|
Before Width: | Height: | Size: 834 KiB After Width: | Height: | Size: 834 KiB |
|
Before Width: | Height: | Size: 833 KiB After Width: | Height: | Size: 833 KiB |
|
Before Width: | Height: | Size: 840 KiB After Width: | Height: | Size: 840 KiB |
|
Before Width: | Height: | Size: 939 KiB After Width: | Height: | Size: 939 KiB |
|
Before Width: | Height: | Size: 942 KiB After Width: | Height: | Size: 942 KiB |
|
Before Width: | Height: | Size: 938 KiB After Width: | Height: | Size: 938 KiB |