Progress in code refactor

This commit is contained in:
2026-05-10 20:10:00 +02:00
parent 0f7095fc4e
commit 6a1aa466e2
2 changed files with 56 additions and 68 deletions
@@ -63,20 +63,7 @@ public class MainFXMLController {
renderUpper();
renderBoard();
renderLower();
// My hand
myHand.getChildren().clear();
myHand.setSpacing(6);
myHand.setAlignment(Pos.CENTER);
drawMyHandCard(myHand, model.getPlayerByUsername(username).artists);
drawMyHandCard(myHand, model.getPlayerByUsername(username).gatherers);
drawMyHandCard(myHand, model.getPlayerByUsername(username).inventors);
drawMyHandCard(myHand, model.getPlayerByUsername(username).builders);
drawMyHandCard(myHand, model.getPlayerByUsername(username).shamans);
drawMyHandCard(myHand, model.getPlayerByUsername(username).hunters);
drawMyHandCard(myHand, model.getPlayerByUsername(username).buildingCards);
drawMyHand();
// Other players and info
@@ -211,37 +198,10 @@ public class MainFXMLController {
}
void drawMyHandCard(HBox myHand, ArrayList<? extends PlayableCard> cardList) {
private void drawMyHandList(HBox myHand, ArrayList<? extends PlayableCard> cardList) {
if (!cardList.isEmpty()) {
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + cardList.getLast().getIdIMG() + ".png")));
img.setFitHeight(200);
img.setPreserveRatio(true);
Rectangle clip = new Rectangle();
clip.setWidth(img.getBoundsInLocal().getWidth());
clip.setHeight(200);
clip.setArcWidth(20);
clip.setArcHeight(20);
img.setClip(clip);
ImageView img = createCard(cardList.getLast());
Label label = new Label(String.valueOf(cardList.size()));
label.setTranslateY(-55);
label.setTranslateX(10);
@@ -253,47 +213,73 @@ public class MainFXMLController {
stack.setOnMouseClicked(e -> openPopup(cardList));
myHand.getChildren().add(stack);
} else {
Region placeholder = new Region();
placeholder.setPrefHeight(200);
placeholder.setPrefWidth(200 * 0.675);
placeholder.setStyle("-fx-background-color: transparent;");
myHand.getChildren().add(placeholder);
}
}
private void drawMyHand() {
myHand.getChildren().clear();
myHand.setSpacing(6);
myHand.setAlignment(Pos.CENTER);
drawMyHandList(myHand, model.getPlayerByUsername(username).artists);
drawMyHandList(myHand, model.getPlayerByUsername(username).gatherers);
drawMyHandList(myHand, model.getPlayerByUsername(username).inventors);
drawMyHandList(myHand, model.getPlayerByUsername(username).builders);
drawMyHandList(myHand, model.getPlayerByUsername(username).shamans);
drawMyHandList(myHand, model.getPlayerByUsername(username).hunters);
drawMyHandList(myHand, model.getPlayerByUsername(username).buildingCards);
}
private void initPopup() {
popupCards = new HBox(10);
popupCards.setAlignment(Pos.CENTER);
popupCards.setPadding(new Insets(10));
Button closeBtn = new Button("X");
closeBtn.setOnAction(e -> popup.hide());
VBox content = new VBox(10, closeBtn, popupCards);
content.setPadding(new Insets(20));
content.setStyle("-fx-background-color: #222; -fx-border-color: white; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-radius: 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(content);
popup.setAutoHide(true); // si chiude anche cliccando fuori
popup.getContent().add(popupCards);
popup.setAutoHide(true);
}
private void openPopup(ArrayList<? extends PlayableCard> cardList) {
popupCards.getChildren().clear();
for (PlayableCard card : cardList) {
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png")));
img.setFitHeight(200);
img.setPreserveRatio(true);
ImageView img = createCard(card);
popupCards.getChildren().add(img);
}
javafx.stage.Window window = myHand.getScene().getWindow();
// Mostralo prima fuori schermo
popup.show(window, 0, 0);
// Poi centralo con le dimensioni reali
double x = window.getX() + (window.getWidth() - popup.getWidth()) / 2;
double y = window.getY() + (window.getHeight() - popup.getHeight()) / 2;
popup.setX(x);
popup.setY(y);
popup.show(window, (window.getWidth() - popup.getWidth()) / 2, (window.getHeight() - popup.getHeight()) / 2);
}
private void renderPlayers(VBox playersHand) {
@@ -306,7 +292,7 @@ public class MainFXMLController {
"-fx-border-width: 2;" +
"-fx-border-radius: 15;" +
"-fx-background-radius: 15;" +
"-fx-background-color: white;"
"-fx-background-color: #b42224;"
);
@@ -342,4 +328,6 @@ public class MainFXMLController {
}
}
+4 -4
View File
@@ -14,22 +14,22 @@
<Insets top="5" right="5" bottom="5" left="5" />
</HBox.margin>
<children>
<HBox fx:id="upperList" prefHeight="200" styleClass="card-list">
<HBox fx:id="upperList" prefHeight="220" minHeight="220" maxHeight="220" styleClass="card-list">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>
</HBox>
<HBox fx:id="board" prefHeight="240" styleClass="card-list">
<HBox fx:id="board" prefHeight="255" minHeight="255" maxHeight="255" styleClass="card-list">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>
</HBox>
<HBox fx:id="lowerList" prefHeight="200" styleClass="card-list">
<HBox fx:id="lowerList" prefHeight="220" minHeight="220" maxHeight="220" styleClass="card-list">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>
</HBox>
<HBox fx:id="myHand" prefHeight="200" styleClass="card-list">
<HBox fx:id="myHand" prefHeight="220" minHeight="220" maxHeight="220" styleClass="card-list">
<VBox.margin>
<Insets top="5" right="5" bottom="5" left="5" />
</VBox.margin>