Fixed: now main window and leaderboard contents are adapted to window size, Added: scrollable popup leaderboard
This commit is contained in:
@@ -6,6 +6,7 @@ import javafx.animation.ScaleTransition;
|
||||
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.stage.Popup;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
@@ -291,11 +292,8 @@ public class LeaderboardFXMLController {
|
||||
// Carte piccole in riga
|
||||
for (PlayableCard card : cards) {
|
||||
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
|
||||
img.setFitHeight(160);
|
||||
img.setFitHeight(230);
|
||||
img.setPreserveRatio(true);
|
||||
// Tooltip al hover: mostra la carta grande in un secondo popup
|
||||
img.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> img.setFitHeight(180));
|
||||
img.addEventHandler(MouseEvent.MOUSE_EXITED, e -> img.setFitHeight(160));
|
||||
img.setCursor(Cursor.HAND);
|
||||
row.getChildren().add(img);
|
||||
}
|
||||
@@ -309,11 +307,16 @@ public class LeaderboardFXMLController {
|
||||
grid.getChildren().add(empty);
|
||||
}
|
||||
|
||||
grid.setMaxHeight(460);
|
||||
grid.setMaxWidth(680);
|
||||
popupContent.getChildren().add(grid);
|
||||
ScrollPane scrollPane = new ScrollPane(grid);
|
||||
scrollPane.setFitToWidth(true);
|
||||
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
|
||||
scrollPane.setStyle("-fx-background: transparent; -fx-background-color: transparent;");
|
||||
|
||||
// altezza massima = 80% della finestra
|
||||
Window window = rootPane.getScene().getWindow();
|
||||
scrollPane.setMaxHeight(window.getHeight() * 0.8);
|
||||
popupContent.getChildren().add(scrollPane);
|
||||
popup.show(window, 0, 0);
|
||||
popup.getScene().setFill(Color.TRANSPARENT);
|
||||
popup.setX(window.getX() + (window.getWidth() - popup.getWidth()) / 2);
|
||||
|
||||
@@ -7,7 +7,10 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.animation.ScaleTransition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Insets;
|
||||
@@ -24,6 +27,7 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.*;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Popup;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
|
||||
@@ -67,11 +71,8 @@ public class MainFXMLController {
|
||||
mainHBox.sceneProperty().addListener((obs, oldScene, newScene) -> {
|
||||
if (newScene != null) {
|
||||
newScene.getRoot().applyCss();
|
||||
// chiudi popup cliccando fuori da esso
|
||||
newScene.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
|
||||
if (popup.isShowing()) {
|
||||
popup.hide();
|
||||
}
|
||||
if (popup.isShowing()) popup.hide();
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -107,13 +108,15 @@ public class MainFXMLController {
|
||||
|
||||
|
||||
// ==== EFFECTS ====
|
||||
private void addClip(Node node) {
|
||||
private void addClip(ImageView img) {
|
||||
Rectangle clip = new Rectangle();
|
||||
clip.setWidth(node.getBoundsInLocal().getWidth());
|
||||
clip.setHeight(node.getBoundsInLocal().getHeight());
|
||||
clip.setArcWidth(20);
|
||||
clip.setArcHeight(20);
|
||||
node.setClip(clip);
|
||||
clip.heightProperty().bind(img.fitHeightProperty());
|
||||
clip.widthProperty().bind(img.fitHeightProperty().multiply(
|
||||
img.getImage().getWidth() / img.getImage().getHeight()
|
||||
));
|
||||
img.setClip(clip);
|
||||
}
|
||||
|
||||
private void addHoverZoom(Node node) {
|
||||
@@ -160,8 +163,8 @@ public class MainFXMLController {
|
||||
|
||||
private StackPane createSlot(Slot slot, boolean withZoom, boolean withShadow) {
|
||||
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + slot.getSlotId() + ".png"));
|
||||
img.setFitHeight(240);
|
||||
img.setPreserveRatio(true);
|
||||
img.fitHeightProperty().bind(board.heightProperty().add(-15));
|
||||
addClip(img);
|
||||
StackPane wrapper = new StackPane(img);
|
||||
|
||||
@@ -180,13 +183,12 @@ public class MainFXMLController {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private StackPane createCard(PlayableCard card, boolean withZoom, boolean withShadow) {
|
||||
private StackPane createCard(PlayableCard card, boolean withZoom, boolean withShadow, Region parent) {
|
||||
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
|
||||
img.setFitHeight(200);
|
||||
img.setPreserveRatio(true);
|
||||
img.fitHeightProperty().bind(parent.heightProperty().multiply(0.85));
|
||||
addClip(img);
|
||||
StackPane wrapper = new StackPane(img);
|
||||
|
||||
if (withShadow) addShadow(wrapper);
|
||||
if (withZoom) addHoverZoom(wrapper);
|
||||
return wrapper;
|
||||
@@ -251,7 +253,7 @@ public class MainFXMLController {
|
||||
int i = 0;
|
||||
for (TribeCard card : controller.miniModel.board.upperListTribe) {
|
||||
final int index = i;
|
||||
StackPane img = createCard(card, true, true);
|
||||
StackPane img = createCard(card, true, true, upperList);
|
||||
img.setOnMouseClicked(e -> controller.drawUpperTribeCard(controller.myUsername, index));
|
||||
upperList.getChildren().add(img);
|
||||
i++;
|
||||
@@ -267,7 +269,7 @@ public class MainFXMLController {
|
||||
int i = 0;
|
||||
for (TribeCard card : controller.miniModel.board.lowerListTribe) {
|
||||
final int index = i;
|
||||
StackPane img = createCard(card, true, true);
|
||||
StackPane img = createCard(card, true, true, lowerList);
|
||||
img.setOnMouseClicked(e -> controller.drawLowerTribeCard(controller.myUsername, index));
|
||||
lowerList.getChildren().add(img);
|
||||
i++;
|
||||
@@ -278,7 +280,7 @@ public class MainFXMLController {
|
||||
private void drawUpperBuilding() {
|
||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.board.upperListBuilding);
|
||||
if (!cardList.isEmpty()) {
|
||||
StackPane img = createCard(cardList.getLast(), true, true);
|
||||
StackPane img = createCard(cardList.getLast(), true, true, upperList);
|
||||
Label label = new Label(String.valueOf(cardList.size()));
|
||||
label.setTranslateY(-55);
|
||||
label.setTranslateX(10);
|
||||
@@ -293,7 +295,7 @@ public class MainFXMLController {
|
||||
private void drawLowerBuilding() {
|
||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.board.lowerListBuilding);
|
||||
if (!cardList.isEmpty()) {
|
||||
StackPane img = createCard(cardList.getLast(), true, true);
|
||||
StackPane img = createCard(cardList.getLast(), true, true, lowerList);
|
||||
Label label = new Label(String.valueOf(cardList.size()));
|
||||
label.setTranslateY(-55);
|
||||
label.setTranslateX(10);
|
||||
@@ -305,23 +307,22 @@ public class MainFXMLController {
|
||||
}
|
||||
}
|
||||
|
||||
private void drawMyHandList(ArrayList<? extends PlayableCard> cardList) {
|
||||
private void drawMyHandList(ArrayList<? extends PlayableCard> cardList, HBox parent) {
|
||||
if (!cardList.isEmpty()) {
|
||||
StackPane img = createCard(cardList.getLast(), true, true);
|
||||
StackPane img = createCard(cardList.getLast(), true, true, parent);
|
||||
Label label = new Label(String.valueOf(cardList.size()));
|
||||
label.setTranslateY(-55);
|
||||
label.setTranslateX(10);
|
||||
label.getStyleClass().add("label-large");
|
||||
StackPane.setAlignment(label, Pos.TOP_RIGHT);
|
||||
img.getChildren().add(label);
|
||||
img.setOnMouseClicked(e -> openPopup(new ArrayList<>(cardList)));
|
||||
myHand.getChildren().add(img);
|
||||
parent.getChildren().add(img);
|
||||
} else {
|
||||
Region placeholder = new Region();
|
||||
placeholder.setPrefHeight(200);
|
||||
placeholder.setPrefWidth(200 * 0.675);
|
||||
placeholder.prefHeightProperty().bind(parent.heightProperty().multiply(0.85));
|
||||
placeholder.prefWidthProperty().bind(placeholder.prefHeightProperty().multiply(0.675));
|
||||
placeholder.setStyle("-fx-background-color: transparent;");
|
||||
myHand.getChildren().add(placeholder);
|
||||
parent.getChildren().add(placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,13 +480,13 @@ public class MainFXMLController {
|
||||
myHand.setAlignment(Pos.CENTER);
|
||||
|
||||
Player me = controller.miniModel.players.get(controller.myUsername);
|
||||
drawMyHandList(me.artists);
|
||||
drawMyHandList(me.gatherers);
|
||||
drawMyHandList(me.inventors);
|
||||
drawMyHandList(me.builders);
|
||||
drawMyHandList(me.shamans);
|
||||
drawMyHandList(me.hunters);
|
||||
drawMyHandList(me.buildingCards);
|
||||
drawMyHandList(me.artists,myHand);
|
||||
drawMyHandList(me.gatherers,myHand);
|
||||
drawMyHandList(me.inventors,myHand);
|
||||
drawMyHandList(me.builders,myHand);
|
||||
drawMyHandList(me.shamans,myHand);
|
||||
drawMyHandList(me.hunters,myHand);
|
||||
drawMyHandList(me.buildingCards,myHand);
|
||||
}
|
||||
|
||||
private void renderSidePanel() {
|
||||
@@ -559,7 +560,7 @@ public class MainFXMLController {
|
||||
private void openPopup(ArrayList<? extends PlayableCard> cardList) {
|
||||
popupCards.getChildren().clear();
|
||||
for (PlayableCard card : cardList) {
|
||||
popupCards.getChildren().add(createCard(card, false, false));
|
||||
popupCards.getChildren().add(createCardPopup(card, false, false));
|
||||
}
|
||||
showPopup();
|
||||
}
|
||||
@@ -569,7 +570,7 @@ public class MainFXMLController {
|
||||
popupCards.getChildren().clear();
|
||||
for (int i = 0; i < cardList.size(); i++) {
|
||||
final int index = i;
|
||||
StackPane img = createCard(cardList.get(i), true, false);
|
||||
StackPane img = createCardPopup(cardList.get(i), true, false);
|
||||
img.setOnMouseClicked(e -> {
|
||||
popup.hide();
|
||||
controller.drawUpperBuildingCard(controller.myUsername, index);
|
||||
@@ -584,7 +585,7 @@ public class MainFXMLController {
|
||||
popupCards.getChildren().clear();
|
||||
for (int i = 0; i < cardList.size(); i++) {
|
||||
final int index = i;
|
||||
StackPane img = createCard(cardList.get(i), true, false);
|
||||
StackPane img = createCardPopup(cardList.get(i), true, false);
|
||||
img.setOnMouseClicked(e -> {
|
||||
popup.hide();
|
||||
controller.drawLowerBuildingCard(controller.myUsername, index);
|
||||
@@ -604,4 +605,14 @@ public class MainFXMLController {
|
||||
popupCards.getChildren().add(wrapper);
|
||||
showPopup();
|
||||
}
|
||||
private StackPane createCardPopup(PlayableCard card, boolean withZoom, boolean withShadow) {
|
||||
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
|
||||
img.setFitHeight(200);
|
||||
img.setPreserveRatio(true);
|
||||
addClip(img);
|
||||
StackPane wrapper = new StackPane(img);
|
||||
if (withShadow) addShadow(wrapper);
|
||||
if (withZoom) addHoverZoom(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<HBox fx:id="mainHBox"
|
||||
maxHeight="Infinity" maxWidth="Infinity"
|
||||
prefHeight="1080.0" prefWidth="1920.0"
|
||||
@@ -22,64 +23,76 @@
|
||||
<Insets top="5" right="5" bottom="5" left="5" />
|
||||
</HBox.margin>
|
||||
<children>
|
||||
<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="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="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="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="upperList" styleClass="card-list" VBox.vgrow="ALWAYS">
|
||||
<VBox.margin>
|
||||
<Insets top="5" right="5" bottom="5" left="5" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
|
||||
<HBox fx:id="board" prefHeight="255" minHeight="255" maxHeight="255" styleClass="card-list" VBox.vgrow="NEVER">
|
||||
<VBox.margin>
|
||||
<Insets top="5" right="5" bottom="5" left="5" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
|
||||
<HBox fx:id="lowerList" styleClass="card-list" VBox.vgrow="ALWAYS">
|
||||
<VBox.margin>
|
||||
<Insets top="5" right="5" bottom="5" left="5" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
|
||||
<HBox fx:id="myHand" styleClass="card-list" VBox.vgrow="ALWAYS">
|
||||
<VBox.margin>
|
||||
<Insets top="5" right="5" bottom="5" left="5" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
</children>
|
||||
</VBox>
|
||||
|
||||
<!-- VBox destra: dimensione fissa, non si espande -->
|
||||
<VBox fx:id="sidePanel"
|
||||
prefWidth="250.0"
|
||||
maxWidth="250.0"
|
||||
minWidth="250.0"
|
||||
HBox.hgrow="NEVER"
|
||||
styleClass="side-panel">
|
||||
<HBox.margin>
|
||||
<Insets bottom="10" left="10" right="10" top="10" />
|
||||
</HBox.margin>
|
||||
<children>
|
||||
<HBox fx:id="info" prefHeight="107.0" prefWidth="483.0" styleClass="frame">
|
||||
<children>
|
||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
||||
<children>
|
||||
<Label styleClass="label-medium" text="Era" />
|
||||
<Label fx:id="era" styleClass="label-medium" text="VALORE" />
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
||||
<children>
|
||||
<Label styleClass="label-medium" text="Round" />
|
||||
<Label fx:id="round" styleClass="label-medium" text="VALORE" />
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
||||
<children>
|
||||
<Label styleClass="label-medium" text="Player" />
|
||||
<Label fx:id="player" styleClass="label-medium" text="VALORE" />
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
</HBox>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox fx:id="sidePanel"
|
||||
prefWidth="250.0"
|
||||
maxWidth="250.0"
|
||||
minWidth="250.0"
|
||||
HBox.hgrow="NEVER"
|
||||
styleClass="side-panel">
|
||||
<HBox.margin>
|
||||
<Insets bottom="10" left="10" right="10" top="10" />
|
||||
</HBox.margin>
|
||||
<children>
|
||||
<ScrollPane fitToWidth="true" hbarPolicy="NEVER" vbarPolicy="AS_NEEDED" VBox.vgrow="ALWAYS">
|
||||
<content>
|
||||
<VBox spacing="10">
|
||||
<children>
|
||||
<HBox fx:id="info" prefHeight="107.0" prefWidth="483.0" styleClass="frame">
|
||||
<children>
|
||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
||||
<children>
|
||||
<Label styleClass="label-medium" text="Era" />
|
||||
<Label fx:id="era" styleClass="label-medium" text="VALORE" />
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
||||
<children>
|
||||
<Label styleClass="label-medium" text="Round" />
|
||||
<Label fx:id="round" styleClass="label-medium" text="VALORE" />
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
||||
<children>
|
||||
<Label styleClass="label-medium" text="Player" />
|
||||
<Label fx:id="player" styleClass="label-medium" text="VALORE" />
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
</HBox>
|
||||
<!-- altri elementi qui sotto -->
|
||||
</children>
|
||||
</VBox>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
</children>
|
||||
</VBox>
|
||||
|
||||
</children>
|
||||
</HBox>
|
||||
@@ -7,21 +7,21 @@
|
||||
<StackPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="it.polimi.ingsw.gc14.View.GUI.LeaderboardFXMLController"
|
||||
fx:id="rootPane"
|
||||
prefWidth="1280"
|
||||
prefHeight="720">
|
||||
fx:id="rootPane">
|
||||
|
||||
<!-- Overlay scuro semitrasparente sopra il background -->
|
||||
<Region style="-fx-background-color: rgba(0,0,0,0.45);"/>
|
||||
|
||||
<!-- Contenuto centrato -->
|
||||
<VBox fx:id="mainVBox" alignment="CENTER" spacing="32">
|
||||
<padding><Insets top="50" right="120" bottom="50" left="120"/></padding>
|
||||
|
||||
<!-- Lista giocatori (Winner/GameOver label aggiunta da render()) -->
|
||||
<VBox fx:id="rankingList" alignment="CENTER" spacing="16"/>
|
||||
<ScrollPane fitToWidth="true"
|
||||
hbarPolicy="NEVER"
|
||||
vbarPolicy="AS_NEEDED"
|
||||
style="-fx-background: transparent; -fx-background-color: transparent;"
|
||||
VBox.vgrow="ALWAYS">
|
||||
<VBox fx:id="rankingList" alignment="CENTER" spacing="16"/>
|
||||
</ScrollPane>
|
||||
|
||||
<!-- Bottone nuova partita -->
|
||||
<Button fx:id="newGameButton" text="NUOVA PARTITA"
|
||||
styleClass="action-button"
|
||||
onAction="#onNewGame"/>
|
||||
|
||||
Reference in New Issue
Block a user