@@ -12,6 +12,7 @@ public class GUI implements IView { // stessa interfaccia che implementa TUI
|
||||
private final Stage stage;
|
||||
private final MainView mainView = new MainView();
|
||||
private Game model;
|
||||
private ClientController controller;
|
||||
private String username;
|
||||
|
||||
public GUI(Stage stage) {
|
||||
@@ -21,7 +22,12 @@ public class GUI implements IView { // stessa interfaccia che implementa TUI
|
||||
@Override
|
||||
public void setModel(Game model) {
|
||||
this.model = model;
|
||||
mainView.setModel(model);
|
||||
mainView.setModel(model, controller, username);
|
||||
|
||||
Platform.runLater(() -> {
|
||||
stage.setScene(mainView.getScene());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +38,6 @@ public class GUI implements IView { // stessa interfaccia che implementa TUI
|
||||
public void render() {
|
||||
Platform.runLater(() -> {
|
||||
mainView.render();
|
||||
stage.setScene(mainView.getScene());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,6 +55,8 @@ public class GUI implements IView { // stessa interfaccia che implementa TUI
|
||||
this.username=username;
|
||||
}
|
||||
|
||||
public void setController(ClientController controller) { this.controller = controller;}
|
||||
|
||||
// Getter per il launcher
|
||||
public Stage getStage() { return stage; }
|
||||
}
|
||||
@@ -1,8 +1,16 @@
|
||||
package it.polimi.ingsw.gc14.View.GUI;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
public class LoginFXMLController {
|
||||
|
||||
@FXML private TextField campoNome;
|
||||
@@ -12,14 +20,38 @@ public class LoginFXMLController {
|
||||
@FXML private RadioButton btnTCP;
|
||||
@FXML private Button btnAccedi;
|
||||
@FXML private Label labelErrore;
|
||||
@FXML private ComboBox<String> comboInterfaccia;
|
||||
|
||||
@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);
|
||||
|
||||
// Carica le interfacce in background
|
||||
new Thread(() -> {
|
||||
try {
|
||||
List<String> ips = new ArrayList<>();
|
||||
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (interfaces.hasMoreElements()) {
|
||||
NetworkInterface ni = interfaces.nextElement();
|
||||
if (!ni.isUp() || ni.isLoopback() || ni.isVirtual()) continue;
|
||||
Enumeration<InetAddress> addresses = ni.getInetAddresses();
|
||||
while (addresses.hasMoreElements()) {
|
||||
InetAddress addr = addresses.nextElement();
|
||||
if (addr instanceof Inet4Address) {
|
||||
ips.add(ni.getDisplayName() + " -> " + addr.getHostAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
comboInterfaccia.getItems().addAll(ips);
|
||||
if (!ips.isEmpty()) comboInterfaccia.getSelectionModel().selectFirst();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Platform.runLater(() -> setErrore("Errore nel rilevare le interfacce."));
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
// --- Getter esposti a LoginView ---
|
||||
@@ -40,5 +72,11 @@ public class LoginFXMLController {
|
||||
|
||||
public String getIP() { return campoIP.getText().trim(); }
|
||||
|
||||
public String getInterfaccia() {
|
||||
String selected = comboInterfaccia.getValue();
|
||||
if (selected == null) return "";
|
||||
return selected.contains("->") ? selected.split("->")[1].trim() : selected;
|
||||
}
|
||||
|
||||
public void setErrore(String messaggio) { labelErrore.setText(messaggio); }
|
||||
}
|
||||
@@ -31,5 +31,6 @@ public class LoginView {
|
||||
public int getNumPlayers() { return fxmlController.getNumPlayers(); }
|
||||
public int getNetworkType() { return fxmlController.getNetworkType(); }
|
||||
public String getIP() { return fxmlController.getIP(); }
|
||||
public String getInterfaccia() {return fxmlController.getInterfaccia();}
|
||||
public void setErrore(String messaggio) { fxmlController.setErrore(messaggio); }
|
||||
}
|
||||
@@ -1,13 +1,20 @@
|
||||
package it.polimi.ingsw.gc14.View.GUI;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Slot;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.image.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.shape.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainFXMLController {
|
||||
|
||||
@@ -17,27 +24,84 @@ public class MainFXMLController {
|
||||
@FXML private HBox myHand;
|
||||
@FXML private VBox playersHand;
|
||||
|
||||
@FXML private Button reload;
|
||||
|
||||
private Game model;
|
||||
private ClientController controller;
|
||||
private String username;
|
||||
|
||||
public void setModel(Game model) {
|
||||
this.model = model;
|
||||
}
|
||||
public void setController(ClientController controller) {this.controller = controller;}
|
||||
public void setUsername(String username) {this.username = username;}
|
||||
|
||||
public void render() {
|
||||
Image placeholder = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-001.png"));
|
||||
|
||||
|
||||
// Upper list
|
||||
upperList.setSpacing(6);
|
||||
upperList.setAlignment(Pos.CENTER);
|
||||
upperList.getChildren().clear();
|
||||
|
||||
int i = 0;
|
||||
for (TribeCard card : model.getUpperListTribeCards()) {
|
||||
ImageView view = new ImageView(placeholder);
|
||||
view.setFitHeight(250);
|
||||
final int index = i;
|
||||
|
||||
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
|
||||
ImageView view = new ImageView(tribeImg);
|
||||
view.fitHeightProperty().bind(upperList.heightProperty().subtract(10));
|
||||
view.setPreserveRatio(true);
|
||||
|
||||
view.setOnMouseClicked(e -> controller.drawUpperTribeCard(username, index));
|
||||
|
||||
upperList.getChildren().add(view);
|
||||
i++;
|
||||
}
|
||||
|
||||
for (TribeCard card : model.getLowerListTribeCards()) {
|
||||
ImageView view = new ImageView(placeholder);
|
||||
view.setFitHeight(250);
|
||||
|
||||
// Board
|
||||
board.setSpacing(6);
|
||||
board.setAlignment(Pos.CENTER);
|
||||
board.getChildren().clear();
|
||||
|
||||
i = 0;
|
||||
for (Map.Entry<Slot, Player> entry : model.getSlotMap().entrySet()) {
|
||||
Slot slot = entry.getKey();
|
||||
final int index = i;
|
||||
|
||||
Image slotImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-"+slot.getSlotId()+".png"));
|
||||
ImageView view = new ImageView(slotImg);
|
||||
|
||||
view.fitHeightProperty().bind(board.heightProperty().subtract(10));
|
||||
view.setPreserveRatio(true);
|
||||
|
||||
view.setOnMouseClicked(e -> controller.slotChoice(username, index));
|
||||
|
||||
board.getChildren().add(view);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Lower list
|
||||
lowerList.setSpacing(6);
|
||||
lowerList.setAlignment(Pos.CENTER);
|
||||
lowerList.getChildren().clear();
|
||||
|
||||
i = 0;
|
||||
for (TribeCard card : model.getLowerListTribeCards()) {
|
||||
final int index = i;
|
||||
|
||||
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
|
||||
ImageView view = new ImageView(tribeImg);
|
||||
view.fitHeightProperty().bind(lowerList.heightProperty().subtract(10));
|
||||
view.setPreserveRatio(true);
|
||||
|
||||
view.setOnMouseClicked(e -> controller.drawLowerTribeCard(username, index));
|
||||
|
||||
lowerList.getChildren().add(view);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package it.polimi.ingsw.gc14.View.GUI;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Insets;
|
||||
@@ -15,6 +16,8 @@ public class MainView {
|
||||
private final Scene scene;
|
||||
private final MainFXMLController fxmlController;
|
||||
private Game model;
|
||||
private ClientController controller;
|
||||
private String username;
|
||||
|
||||
public MainView() {
|
||||
try {
|
||||
@@ -29,11 +32,17 @@ public class MainView {
|
||||
}
|
||||
|
||||
public Scene getScene() { return scene; }
|
||||
public void setModel(Game model) {
|
||||
public void setModel(Game model, ClientController controller, String username) {
|
||||
this.model = model;
|
||||
fxmlController.setModel(model);
|
||||
this.controller = controller;
|
||||
fxmlController.setController(controller);
|
||||
this.username = username;
|
||||
fxmlController.setUsername(username);
|
||||
|
||||
}
|
||||
public void render() {
|
||||
fxmlController.render();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user