Fixed: Popup now disappear if the window is not focused
This commit is contained in:
@@ -129,6 +129,7 @@ public class GUI extends Application implements IView {
|
||||
Platform.runLater(() -> primaryStage.setMaximized(true));
|
||||
}
|
||||
controllerMain.render(event);
|
||||
controllerMain.initPopup(mainScene);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Cursor;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
@@ -97,7 +98,6 @@ public class MainFXMLController {
|
||||
});
|
||||
addHoverZoom(skipBtn);
|
||||
addHoverZoom(detailsBtn);
|
||||
initPopup();
|
||||
renderBackground();
|
||||
}
|
||||
|
||||
@@ -226,54 +226,6 @@ public class MainFXMLController {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private void renderIcons(HBox iconsRow1, HBox iconsRow2, Player player) {
|
||||
String[][] iconTypes = {
|
||||
{"Artist", "artists"},
|
||||
{"Gatherer", "gatherers"},
|
||||
{"Inventor", "inventors"},
|
||||
{"Builder", "builders"},
|
||||
{"Shaman", "shamans"},
|
||||
{"Hunter", "hunters"}
|
||||
};
|
||||
|
||||
for (int i = 0; i < iconTypes.length; i++) {
|
||||
String iconName = iconTypes[i][0];
|
||||
String fieldName = iconTypes[i][1];
|
||||
|
||||
ImageView icon = new ImageView();
|
||||
icon.setFitWidth(28);
|
||||
icon.setFitHeight(28);
|
||||
icon.setPreserveRatio(true);
|
||||
icon.setImage(loadImage("/GUIImages/Icons/" + iconName + ".png"));
|
||||
|
||||
ArrayList<PlayableCard> cards = getPlayerCards(player.getUserName(), fieldName);
|
||||
if (cards.isEmpty()) {
|
||||
ColorAdjust grayscale = new ColorAdjust();
|
||||
icon.setEffect(grayscale);
|
||||
icon.setOpacity(0.3);
|
||||
} else {
|
||||
icon.setOnMouseClicked(e -> openPopup(new ArrayList<>(cards)));
|
||||
addHoverZoom(icon);
|
||||
}
|
||||
|
||||
if (i < 3) iconsRow1.getChildren().add(icon);
|
||||
else iconsRow2.getChildren().add(icon);
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
|
||||
Player p = controller.miniModel.players.get(username);
|
||||
return switch (type) {
|
||||
case "artists" -> new ArrayList<>(p.artists);
|
||||
case "gatherers" -> new ArrayList<>(p.gatherers);
|
||||
case "inventors" -> new ArrayList<>(p.inventors);
|
||||
case "builders" -> new ArrayList<>(p.builders);
|
||||
case "shamans" -> new ArrayList<>(p.shamans);
|
||||
case "hunters" -> new ArrayList<>(p.hunters);
|
||||
case "building" -> new ArrayList<>(p.buildingCards);
|
||||
default -> new ArrayList<>();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// ==== GROUPS ====
|
||||
@@ -433,6 +385,55 @@ public class MainFXMLController {
|
||||
target.getChildren().add(card);
|
||||
}
|
||||
|
||||
private void renderIcons(HBox iconsRow1, HBox iconsRow2, Player player) {
|
||||
String[][] iconTypes = {
|
||||
{"Artist", "artists"},
|
||||
{"Gatherer", "gatherers"},
|
||||
{"Inventor", "inventors"},
|
||||
{"Builder", "builders"},
|
||||
{"Shaman", "shamans"},
|
||||
{"Hunter", "hunters"}
|
||||
};
|
||||
|
||||
for (int i = 0; i < iconTypes.length; i++) {
|
||||
String iconName = iconTypes[i][0];
|
||||
String fieldName = iconTypes[i][1];
|
||||
|
||||
ImageView icon = new ImageView();
|
||||
icon.setFitWidth(28);
|
||||
icon.setFitHeight(28);
|
||||
icon.setPreserveRatio(true);
|
||||
icon.setImage(loadImage("/GUIImages/Icons/" + iconName + ".png"));
|
||||
|
||||
ArrayList<PlayableCard> cards = getPlayerCards(player.getUserName(), fieldName);
|
||||
if (cards.isEmpty()) {
|
||||
ColorAdjust grayscale = new ColorAdjust();
|
||||
icon.setEffect(grayscale);
|
||||
icon.setOpacity(0.3);
|
||||
} else {
|
||||
icon.setOnMouseClicked(e -> openPopup(new ArrayList<>(cards)));
|
||||
addHoverZoom(icon);
|
||||
}
|
||||
|
||||
if (i < 3) iconsRow1.getChildren().add(icon);
|
||||
else iconsRow2.getChildren().add(icon);
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<PlayableCard> getPlayerCards(String username, String type) {
|
||||
Player p = controller.miniModel.players.get(username);
|
||||
return switch (type) {
|
||||
case "artists" -> new ArrayList<>(p.artists);
|
||||
case "gatherers" -> new ArrayList<>(p.gatherers);
|
||||
case "inventors" -> new ArrayList<>(p.inventors);
|
||||
case "builders" -> new ArrayList<>(p.builders);
|
||||
case "shamans" -> new ArrayList<>(p.shamans);
|
||||
case "hunters" -> new ArrayList<>(p.hunters);
|
||||
case "building" -> new ArrayList<>(p.buildingCards);
|
||||
default -> new ArrayList<>();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// ==== ABSOLUTES ====
|
||||
private void renderBackground() {
|
||||
@@ -576,7 +577,7 @@ public class MainFXMLController {
|
||||
}
|
||||
|
||||
// ==== POPUP ====
|
||||
private void initPopup() {
|
||||
public void initPopup(Scene mainScene) {
|
||||
popupCards = new HBox(10);
|
||||
popupCards.setAlignment(Pos.CENTER);
|
||||
popupCards.setPadding(new Insets(10));
|
||||
@@ -591,12 +592,15 @@ public class MainFXMLController {
|
||||
popup = new Popup();
|
||||
popup.getContent().add(popupCards);
|
||||
popup.setAutoHide(false); // gestito manualmente per permettere click sulle carte
|
||||
|
||||
popup.addEventHandler(Event.ANY, e -> {
|
||||
if (popup.getScene() != null) {
|
||||
popup.getScene().setFill(Color.TRANSPARENT);
|
||||
}
|
||||
});
|
||||
mainScene.getWindow().focusedProperty().addListener((obs, wasFocused, isNowFocused) -> {
|
||||
if(!isNowFocused)
|
||||
popup.hide();
|
||||
});
|
||||
}
|
||||
|
||||
private void showPopup() {
|
||||
|
||||
Reference in New Issue
Block a user