Refactor completed
This commit is contained in:
@@ -11,7 +11,6 @@ import it.polimi.ingsw.gc14.Model.Slot;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.*;
|
||||
import javafx.scene.layout.*;
|
||||
@@ -19,19 +18,20 @@ import javafx.scene.shape.*;
|
||||
import javafx.stage.Popup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainFXMLController {
|
||||
|
||||
@FXML private HBox mainHBox;
|
||||
|
||||
@FXML private HBox board;
|
||||
@FXML private HBox upperList;
|
||||
@FXML private HBox lowerList;
|
||||
@FXML private HBox myHand;
|
||||
|
||||
@FXML private VBox sidePanel;
|
||||
@FXML private Button reload;
|
||||
@FXML private HBox info;
|
||||
|
||||
@FXML private Label era;
|
||||
@FXML private Label round;
|
||||
@FXML private Label player;
|
||||
@@ -43,51 +43,41 @@ public class MainFXMLController {
|
||||
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;}
|
||||
|
||||
|
||||
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
// Reapply CSS
|
||||
mainHBox.sceneProperty().addListener((obs, oldScene, newScene) -> {
|
||||
if (newScene != null) {
|
||||
newScene.getRoot().applyCss();
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize popup
|
||||
initPopup();
|
||||
}
|
||||
|
||||
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() {
|
||||
renderBackground();
|
||||
renderUpper();
|
||||
renderBoard();
|
||||
renderLower();
|
||||
drawMyHand();
|
||||
|
||||
|
||||
// Other players and info
|
||||
sidePanel.getChildren().clear();
|
||||
era.setText(Integer.toString(model.getCurrentState().getEra()));
|
||||
round.setText(Integer.toString(model.getCurrentState().getRound()));
|
||||
player.setText(model.getCurrentState().getCurrentPlayer().getUserName());
|
||||
|
||||
sidePanel.setSpacing(6);
|
||||
sidePanel.getChildren().add(info);
|
||||
renderPlayers(sidePanel);
|
||||
|
||||
renderMyHand();
|
||||
renderSidePanel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ==== RENDER METHODS ====
|
||||
// BACKGROUND
|
||||
private void renderBackground() {
|
||||
BackgroundSize size = new BackgroundSize(
|
||||
BackgroundSize.AUTO, BackgroundSize.AUTO,
|
||||
@@ -102,7 +92,7 @@ public class MainFXMLController {
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
// UPPER, LOWER AND BOARD
|
||||
private ImageView createCard(PlayableCard card) {
|
||||
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png")));
|
||||
img.setFitHeight(200);
|
||||
@@ -116,8 +106,6 @@ public class MainFXMLController {
|
||||
img.setClip(clip);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
private ImageView createSlot(Slot slot) {
|
||||
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-"+slot.getSlotId()+".png")));
|
||||
img.setFitHeight(240);
|
||||
@@ -131,8 +119,6 @@ public class MainFXMLController {
|
||||
img.setClip(clip);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
private void renderUpper() {
|
||||
upperList.setSpacing(6);
|
||||
upperList.setAlignment(Pos.CENTER);
|
||||
@@ -155,8 +141,6 @@ public class MainFXMLController {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void renderBoard() {
|
||||
board.setSpacing(6);
|
||||
board.setAlignment(Pos.CENTER);
|
||||
@@ -172,8 +156,6 @@ public class MainFXMLController {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void renderLower() {
|
||||
lowerList.setSpacing(6);
|
||||
lowerList.setAlignment(Pos.CENTER);
|
||||
@@ -197,7 +179,7 @@ public class MainFXMLController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MY HAND
|
||||
private void drawMyHandList(HBox myHand, ArrayList<? extends PlayableCard> cardList) {
|
||||
if (!cardList.isEmpty()) {
|
||||
|
||||
@@ -221,9 +203,7 @@ public class MainFXMLController {
|
||||
myHand.getChildren().add(placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawMyHand() {
|
||||
private void renderMyHand() {
|
||||
myHand.getChildren().clear();
|
||||
myHand.setSpacing(6);
|
||||
myHand.setAlignment(Pos.CENTER);
|
||||
@@ -237,64 +217,25 @@ public class MainFXMLController {
|
||||
drawMyHandList(myHand, model.getPlayerByUsername(username).buildingCards);
|
||||
}
|
||||
|
||||
// SIDE PANEL
|
||||
private void renderSidePanel() {
|
||||
sidePanel.getChildren().clear();
|
||||
sidePanel.setSpacing(6);
|
||||
sidePanel.setAlignment(Pos.CENTER);
|
||||
|
||||
era.setText(Integer.toString(model.getCurrentState().getEra()));
|
||||
round.setText(Integer.toString(model.getCurrentState().getRound()));
|
||||
player.setText(model.getCurrentState().getCurrentPlayer().getUserName());
|
||||
sidePanel.getChildren().add(info);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void initPopup() {
|
||||
popupCards = new HBox(10);
|
||||
popupCards.setAlignment(Pos.CENTER);
|
||||
popupCards.setPadding(new Insets(10));
|
||||
popupCards.setStyle("-fx-background-color: #b42224; -fx-border-color: black; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-radius: 10;");
|
||||
|
||||
popup = new Popup();
|
||||
popup.getContent().add(popupCards);
|
||||
popup.setAutoHide(true);
|
||||
renderPlayers(sidePanel);
|
||||
}
|
||||
|
||||
private void openPopup(ArrayList<? extends PlayableCard> cardList) {
|
||||
popupCards.getChildren().clear();
|
||||
|
||||
for (PlayableCard card : cardList) {
|
||||
ImageView img = createCard(card);
|
||||
popupCards.getChildren().add(img);
|
||||
}
|
||||
|
||||
javafx.stage.Window window = myHand.getScene().getWindow();
|
||||
|
||||
popup.show(window, (window.getWidth() - popup.getWidth()) / 2, (window.getHeight() - popup.getHeight()) / 2);
|
||||
}
|
||||
|
||||
private void renderPlayers(VBox playersHand) {
|
||||
for (Player player : model.getPlayers()) {
|
||||
VBox card = new VBox();
|
||||
VBox.setMargin(card, new Insets(5, 5, 5, 5));
|
||||
card.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
card.setStyle(
|
||||
"-fx-border-color: black;" +
|
||||
"-fx-border-width: 2;" +
|
||||
"-fx-border-radius: 15;" +
|
||||
"-fx-background-radius: 15;" +
|
||||
"-fx-background-color: #b42224;"
|
||||
);
|
||||
|
||||
card.setAlignment(Pos.CENTER);
|
||||
card.getStyleClass().add("player-card");
|
||||
|
||||
Label usernameLabel;
|
||||
if(player.getUserName().equals(username)) {
|
||||
@@ -304,13 +245,10 @@ public class MainFXMLController {
|
||||
usernameLabel = new Label(player.getUserName());
|
||||
}
|
||||
usernameLabel.getStyleClass().add("label-medium");
|
||||
|
||||
Label foodLabel = new Label("Food: " + player.getFoodValue());
|
||||
foodLabel.getStyleClass().add("label-small");
|
||||
|
||||
Label prestigeLabel = new Label("Prestige: " + player.getPrestigeValue());
|
||||
prestigeLabel.getStyleClass().add("label-small");
|
||||
|
||||
card.getChildren().addAll(usernameLabel, foodLabel, prestigeLabel);
|
||||
|
||||
ArrayList<PlayableCard> playerCard = new ArrayList<>();
|
||||
@@ -327,7 +265,26 @@ public class MainFXMLController {
|
||||
}
|
||||
}
|
||||
|
||||
// POPUP
|
||||
private void initPopup() {
|
||||
popupCards = new HBox(10);
|
||||
popupCards.setAlignment(Pos.CENTER);
|
||||
popupCards.setPadding(new Insets(10));
|
||||
popupCards.getStyleClass().add("popup");
|
||||
|
||||
popup = new Popup();
|
||||
popup.getContent().add(popupCards);
|
||||
popup.setAutoHide(true);
|
||||
}
|
||||
private void openPopup(ArrayList<? extends PlayableCard> cardList) {
|
||||
popupCards.getChildren().clear();
|
||||
|
||||
for (PlayableCard card : cardList) {
|
||||
ImageView img = createCard(card);
|
||||
popupCards.getChildren().add(img);
|
||||
}
|
||||
|
||||
javafx.stage.Window window = myHand.getScene().getWindow();
|
||||
popup.show(window, (window.getWidth() - popup.getWidth()) / 2, (window.getHeight() - popup.getHeight()) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,5 +35,13 @@
|
||||
-fx-border-width: 2;
|
||||
-fx-border-radius: 15;
|
||||
-fx-background-radius: 15;
|
||||
-fx-background-color: white;
|
||||
-fx-background-color: #b42224;
|
||||
}
|
||||
|
||||
.popup {
|
||||
-fx-background-color: #b42224;
|
||||
-fx-border-color: black;
|
||||
-fx-border-width: 2;
|
||||
-fx-border-radius: 10;
|
||||
-fx-background-radius: 10;
|
||||
}
|
||||
Reference in New Issue
Block a user