Add: fonts, background

This commit is contained in:
2026-05-10 10:21:26 +02:00
parent f3cd29169c
commit be1b746363
13 changed files with 192 additions and 170 deletions
Vendored Executable → Regular
View File
@@ -10,13 +10,14 @@ import javafx.stage.Stage;
public class GUI implements IView { // stessa interfaccia che implementa TUI
private final Stage stage;
private final MainView mainView = new MainView();
private final MainView mainView;
private Game model;
private ClientController controller;
private String username;
public GUI(Stage stage) {
this.stage = stage;
this.mainView = new MainView();
}
@Override
@@ -2,6 +2,7 @@ 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.Cards.TribeCards.Characters.*;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Slot;
@@ -9,11 +10,15 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.geometry.Bounds;
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.*;
import javafx.scene.shape.*;
import javafx.scene.text.Font;
import javafx.stage.Popup;
import java.util.ArrayList;
import java.util.List;
@@ -21,18 +26,25 @@ 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 playersHand;
@FXML private Button reload;
private Popup popup;
private HBox popupCards;
private Game model;
private ClientController controller;
private String username;
@FXML
public void initialize() {
initPopup();
}
public void setModel(Game model) {
this.model = model;
}
@@ -41,7 +53,7 @@ public class MainFXMLController {
public void render() {
//mainHBox.setBackground(new Background(new BackgroundImage(new Image(getClass().getResourceAsStream("/GUIImages/Background.png")), null, null, null, null)));
// Upper list
upperList.setSpacing(6);
upperList.setAlignment(Pos.CENTER);
@@ -51,14 +63,13 @@ public class MainFXMLController {
for (TribeCard card : model.getUpperListTribeCards()) {
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);
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png")));
img.fitHeightProperty().bind(upperList.heightProperty().subtract(10));
img.setPreserveRatio(true);
view.setOnMouseClicked(e -> controller.drawUpperTribeCard(username, index));
img.setOnMouseClicked(e -> controller.drawUpperTribeCard(username, index));
upperList.getChildren().add(view);
upperList.getChildren().add(img);
i++;
}
@@ -73,15 +84,14 @@ public class MainFXMLController {
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);
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-"+slot.getSlotId()+".png")));
view.fitHeightProperty().bind(board.heightProperty().subtract(10));
view.setPreserveRatio(true);
img.fitHeightProperty().bind(board.heightProperty().subtract(10));
img.setPreserveRatio(true);
view.setOnMouseClicked(e -> controller.slotChoice(username, index));
img.setOnMouseClicked(e -> controller.slotChoice(username, index));
board.getChildren().add(view);
board.getChildren().add(img);
i++;
}
@@ -96,14 +106,13 @@ public class MainFXMLController {
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);
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png")));
img.fitHeightProperty().bind(lowerList.heightProperty().subtract(10));
img.setPreserveRatio(true);
view.setOnMouseClicked(e -> controller.drawLowerTribeCard(username, index));
img.setOnMouseClicked(e -> controller.drawLowerTribeCard(username, index));
lowerList.getChildren().add(view);
lowerList.getChildren().add(img);
i++;
}
@@ -111,159 +120,79 @@ public class MainFXMLController {
// My hand
myHand.getChildren().clear();
myHand.setSpacing(6);
//myHand.setAlignment(Pos.CENTER_LEFT);
myHand.setAlignment(Pos.CENTER);
myHand.getChildren().add(createCardPane(model.getPlayerByUsername(username).artists.stream().map(x -> (TribeCard) x).toList(), myHand));
myHand.getChildren().add(createCardPane(model.getPlayerByUsername(username).gatherers.stream().map(x -> (TribeCard) x).toList(), myHand));
myHand.getChildren().add(createCardPane(model.getPlayerByUsername(username).inventors.stream().map(x -> (TribeCard) x).toList(), myHand));
myHand.getChildren().add(createCardPane(model.getPlayerByUsername(username).builders.stream().map(x -> (TribeCard) x).toList(), myHand));
myHand.getChildren().add(createCardPane(model.getPlayerByUsername(username).shamans.stream().map(x -> (TribeCard) x).toList(), myHand));
myHand.getChildren().add(createCardPane(model.getPlayerByUsername(username).hunters.stream().map(x -> (TribeCard) x).toList(), myHand));
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);
}
/**
// Artists
Pane artists = new Pane();
artists.prefHeightProperty().bind(myHand.heightProperty());
artists.prefWidthProperty().bind(
artists.heightProperty().multiply(0.63).add((model.getPlayerByUsername(username).artists.size() - 1) * 50)
);
for (int j=0;j<model.getPlayerByUsername(username).artists.size();j++) {
TribeCard card=model.getPlayerByUsername(username).artists.get(j);
void drawMyHandCard(HBox myHand, ArrayList<? extends TribeCard> cardList) {
if (!cardList.isEmpty()) {
ImageView img = new ImageView(new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + cardList.getLast().getIdIMG() + ".png")));
img.fitHeightProperty().bind(myHand.heightProperty().subtract(10));
img.setPreserveRatio(true);
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
ImageView view = new ImageView(tribeImg);
view.fitHeightProperty().bind(artists.heightProperty().subtract(10));
view.setPreserveRatio(true);
view.setLayoutX((model.getPlayerByUsername(username).artists.size() -j ) * 50); // solo X cambia
view.setLayoutY(5);
artists.getChildren().addLast(view);
i++;
Label label = new Label(String.valueOf(cardList.size()));
label.setTranslateY(-55);
label.setTranslateX(10);
Font.loadFont(getClass().getResourceAsStream("/Fonts/InknutAntiqua-Regular.ttf"), 16);
label.setStyle("-fx-font-family: 'Inknut Antiqua'; -fx-font-size: 50px; -fx-font-weight: bold; -fx-text-fill: black;");
StackPane.setAlignment(label, Pos.TOP_RIGHT);
StackPane stack = new StackPane(img, label);
stack.setClip(null);
stack.setOnMouseClicked(e -> openPopup(cardList));
myHand.getChildren().add(stack);
}
myHand.getChildren().add(artists);
// Gatherers
Pane gatherers=new Pane();
gatherers.prefHeightProperty().bind(myHand.heightProperty());
gatherers.prefWidthProperty().bind(
gatherers.heightProperty().multiply(0.63).add((model.getPlayerByUsername(username).gatherers.size() - 1) * 50)
);
for (int j=0;j<model.getPlayerByUsername(username).gatherers.size();j++) {
TribeCard card=model.getPlayerByUsername(username).gatherers.get(j);
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
ImageView view = new ImageView(tribeImg);
view.fitHeightProperty().bind(artists.heightProperty().subtract(10));
view.setPreserveRatio(true);
view.setLayoutX((model.getPlayerByUsername(username).gatherers.size() -j ) * 50); // solo X cambia
view.setLayoutY(5);
gatherers.getChildren().addLast(view);
i++;
}
myHand.getChildren().add(gatherers);
// Inventors
Pane inventors=new Pane();
inventors.prefHeightProperty().bind(myHand.heightProperty());
for (int j=0;j<model.getPlayerByUsername(username).inventors.size();j++) {
TribeCard card=model.getPlayerByUsername(username).inventors.get(j);
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
ImageView view = new ImageView(tribeImg);
view.fitHeightProperty().bind(inventors.heightProperty().subtract(10));
view.setPreserveRatio(true);
view.setLayoutX((model.getPlayerByUsername(username).inventors.size() -j )* 50); // solo X cambia
view.setLayoutY(5);
inventors.getChildren().addLast(view);
i++;
}
myHand.getChildren().add(inventors);
// Builders
Pane builders=new Pane();
builders.prefHeightProperty().bind(myHand.heightProperty());
for (int j=0;j<model.getPlayerByUsername(username).builders.size();j++) {
TribeCard card=model.getPlayerByUsername(username).builders.get(j);
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
ImageView view = new ImageView(tribeImg);
view.fitHeightProperty().bind(builders.heightProperty().subtract(10));
view.setPreserveRatio(true);
view.setLayoutX((model.getPlayerByUsername(username).builders.size() -j ) * 50); // solo X cambia
view.setLayoutY(5);
builders.getChildren().addLast(view);
i++;
}
myHand.getChildren().add(builders);
// Shamans
Pane shamans=new Pane();
shamans.prefHeightProperty().bind(myHand.heightProperty());
for (int j=0;j<model.getPlayerByUsername(username).shamans.size();j++) {
TribeCard card=model.getPlayerByUsername(username).shamans.get(j);
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
ImageView view = new ImageView(tribeImg);
view.fitHeightProperty().bind(shamans.heightProperty().subtract(10));
view.setPreserveRatio(true);
view.setLayoutX((model.getPlayerByUsername(username).shamans.size() -j ) * 50); // solo X cambia
view.setLayoutY(5);
shamans.getChildren().addLast(view);
i++;
}
myHand.getChildren().add(shamans);
// Hunters
Pane hunters=new Pane();
hunters.prefHeightProperty().bind(myHand.heightProperty());
for (int j=0;j<model.getPlayerByUsername(username).hunters.size();j++) {
TribeCard card=model.getPlayerByUsername(username).hunters.get(j);
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
ImageView view = new ImageView(tribeImg);
view.fitHeightProperty().bind(hunters.heightProperty().subtract(10));
view.setPreserveRatio(true);
view.setLayoutX((model.getPlayerByUsername(username).hunters.size() -j )* 50); // solo X cambia
view.setLayoutY(5);
hunters.getChildren().addLast(view);
i++;
}
myHand.getChildren().add(hunters);
*/
}
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;");
private Pane createCardPane(List<TribeCard> cards, HBox container) {
Pane pane = new Pane();
int n = cards.size();
pane.prefHeightProperty().bind(container.heightProperty());
for (int j = 0; j < n; j++) {
TribeCard card = cards.get(j);
Image tribeImg = new Image(getClass().getResourceAsStream("/GUIImages/Fronts/card-" + card.getIdIMG() + ".png"));
ImageView view = new ImageView(tribeImg);
view.fitHeightProperty().bind(pane.heightProperty().subtract(10));
view.setPreserveRatio(true);
view.setLayoutX(j * 50);
view.setLayoutY(5);
pane.getChildren().add(view);
if (j == 0) {
view.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() {
@Override
public void changed(ObservableValue<? extends Bounds> obs, Bounds old, Bounds bounds) {
if (bounds.getWidth() > 0) {
pane.setPrefWidth(bounds.getWidth() + (n - 1) * 50);
view.layoutBoundsProperty().removeListener(this);
}
}
});
}
}
return pane;
popup = new Popup();
popup.getContent().add(content);
popup.setAutoHide(true); // si chiude anche cliccando fuori
}
private void openPopup(ArrayList<? extends TribeCard> cardList) {
popupCards.getChildren().clear();
for (TribeCard card : cardList) {
ImageView img = new ImageView(new Image(getClass().getResourceAsStream(
"/GUIImages/Fronts/card-" + card.getIdIMG() + ".png")));
img.setFitHeight(200);
img.setPreserveRatio(true);
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);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+93
View File
@@ -0,0 +1,93 @@
Copyright (c) 2014 Claus Eggers Sørensen (es@forthehearts.net)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

+6 -7
View File
@@ -4,18 +4,17 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.Pane?>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/26" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.polimi.ingsw.gc14.View.GUI.MainFXMLController">
<HBox fx:id="mainHBox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/26" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.polimi.ingsw.gc14.View.GUI.MainFXMLController" >
<children>
<VBox prefHeight="1080.0" prefWidth="1486.0">
<children>
<HBox fx:id="upperList" prefHeight="255.0" prefWidth="200.0" style="-fx-background-color: #91352d;" />
<HBox fx:id="board" prefHeight="300.0" prefWidth="200.0" style="-fx-background-color: #2d3c91;" />
<HBox fx:id="lowerList" prefHeight="255.0" prefWidth="200.0" style="-fx-background-color: #2d915b;" />
<HBox fx:id="myHand" prefHeight="270.0" prefWidth="1324.0" style="-fx-background-color: #8e912d;" />
<HBox fx:id="upperList" prefHeight="255.0" prefWidth="200.0" />
<HBox fx:id="board" prefHeight="300.0" prefWidth="200.0" />
<HBox fx:id="lowerList" prefHeight="255.0" prefWidth="200.0" />
<HBox fx:id="myHand" prefHeight="270.0" prefWidth="1324.0" />
</children>
</VBox>
<VBox fx:id="playersHand" prefHeight="1080.0" prefWidth="531.0" style="-fx-background-color: #742d91;">
<VBox fx:id="playersHand" prefHeight="1080.0" prefWidth="531.0" style="-fx-background-color: white;">
<children>
<Button fx:id="reload" mnemonicParsing="false" onAction="#render" prefHeight="335.0" prefWidth="510.0" text="Reload" />
</children></VBox>