diff --git a/src/main/java/com/cemu_UI/application/Main.java b/src/main/java/com/cemu_UI/application/Main.java index 4c42fb6..cf5db89 100644 --- a/src/main/java/com/cemu_UI/application/Main.java +++ b/src/main/java/com/cemu_UI/application/Main.java @@ -218,10 +218,10 @@ public class Main extends Application { @Override public void changed(ObservableValue observable, Number oldValue, final Number newValue) { - int xPosHelperMax = (int) Math.floor((mainWindowController.getMainAnchorPane().getWidth() - 36) / 217); + int xMaxElements = (int) Math.floor((mainWindowController.getMainAnchorPane().getWidth() - 36) / 217); // call only if there is enough space for a new row - if (mainWindowController.getOldXPosHelper() != xPosHelperMax) { + if (mainWindowController.getOldXNextElement() != xMaxElements) { mainWindowController.refreshUIData(); } diff --git a/src/main/java/com/cemu_UI/application/MainWindowController.java b/src/main/java/com/cemu_UI/application/MainWindowController.java index f7ed5ca..cd52ced 100644 --- a/src/main/java/com/cemu_UI/application/MainWindowController.java +++ b/src/main/java/com/cemu_UI/application/MainWindowController.java @@ -78,7 +78,6 @@ import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; -import javafx.geometry.Insets; import javafx.scene.control.ChoiceBox; import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; @@ -194,8 +193,8 @@ public class MainWindowController { private String versionName = "Purple Comet"; private int xPos = -200; private int yPos = 17; - private int xPosHelper = 0; - private int oldXPosHelper; + private int xNextElement = 0; + private int oldXNextElement; private int selectedUIDataIndex; private int selected; private DirectoryChooser directoryChooser = new DirectoryChooser(); @@ -1024,29 +1023,14 @@ public class MainWindowController { * @param titleID : game ID */ public void addGame(String title, String coverPath, String romPath, String titleID){ - VBox VBox = new VBox(); - Label gameTitleLabel = new Label(); - JFXButton gameBtn = new JFXButton(); - ImageView imageView = new ImageView(); Image coverImage = new Image(new File(coverPath).toURI().toString()); + UIROMDataType uiROMElement = new UIROMDataType(); generatePosition(); - - UIROMDataType uiROMElement = new UIROMDataType(VBox, gameTitleLabel, gameBtn, imageView, titleID, romPath); uiROMElement.getLabel().setText(title); - uiROMElement.getLabel().setMaxWidth(200); - uiROMElement.getLabel().setPadding(new Insets(0,0,0,8)); - uiROMElement.getLabel().setFont(Font.font("System", FontWeight.BOLD, 14)); - - // i think we can do this locally and remove the imageView from the data type since it's used as graphic uiROMElement.getImageView().setImage(coverImage); - uiROMElement.getImageView().setFitHeight(300); - uiROMElement.getImageView().setFitWidth(200); - - uiROMElement.getButton().setGraphic(uiROMElement.getImageView()); uiROMElement.getButton().setContextMenu(gameContextMenu); - uiROMElement.getButton().setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 3); "); uiROMElement.getButton().addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { @Override public void handle(MouseEvent event) { @@ -1112,10 +1096,6 @@ public class MainWindowController { } }); - uiROMElement.getVBox().setLayoutX(getxPos()); - uiROMElement.getVBox().setLayoutY(getyPos()); - uiROMElement.getVBox().getChildren().addAll(gameTitleLabel,gameBtn); - // add uiROMElement to games list games.add(uiROMElement); } @@ -1154,20 +1134,21 @@ public class MainWindowController { //remove all games from gamesAnchorPane and add them afterwards public void refreshUIData() { //remove all games form gamesAnchorPane - gamesAnchorPane.getChildren().removeAll(gamesAnchorPane.getChildren()); + gamesAnchorPane.getChildren().clear(); //reset position xPos = -200; yPos = 17; - xPosHelper = 0; + xNextElement = 0; //add all games to gamesAnchorPane (UI) - for(int i=0; i< games.size(); i++){ - generatePosition(); - games.get(i).getVBox().setLayoutX(getxPos()); - games.get(i).getVBox().setLayoutY(getyPos()); - gamesAnchorPane.getChildren().add(games.get(i).getVBox()); - } + for(UIROMDataType game : games) { + generatePosition(); + + game.setLayoutX(xPos); + game.setLayoutY(yPos); + gamesAnchorPane.getChildren().add(game); + } } // set the selected local strings to all needed elements @@ -1367,20 +1348,21 @@ public class MainWindowController { } /** - * xPosHelper based on window width = -24(Windows)/-36(Linux) + * xMaxElements based on window width -36 * calculates how many games can be displayed in one row */ private void generatePosition() { - int xPosHelperMax = (int) Math.floor((mainAnchorPane.getWidth() - 36) / 217); + int xMaxElements = (int) Math.floor((mainAnchorPane.getWidth() - 36) / 217); + System.out.println(xMaxElements); - if(xPosHelper == xPosHelperMax){ - oldXPosHelper = xPosHelper; + if(xNextElement >= xMaxElements){ + oldXNextElement = xNextElement; xPos = 17; yPos = yPos + 345; - xPosHelper = 1; + xNextElement = 1; }else{ xPos = xPos + 217; - xPosHelper++; + xNextElement++; } } @@ -1536,30 +1518,6 @@ public class MainWindowController { return primaryStage; } - public int getxPos() { - return xPos; - } - - public void setxPos(int xPos) { - this.xPos = xPos; - } - - public int getyPos() { - return yPos; - } - - public void setyPos(int yPos) { - this.yPos = yPos; - } - - public int getxPosHelper() { - return xPosHelper; - } - - public void setxPosHelper(int xPosHelper) { - this.xPosHelper = xPosHelper; - } - public String getGameExecutePath() { return gameExecutePath; } @@ -1584,8 +1542,8 @@ public class MainWindowController { this.playBtn = playBtn; } - public int getOldXPosHelper() { - return oldXPosHelper; + public int getOldXNextElement() { + return oldXNextElement; } public String getLanguage() { diff --git a/src/main/java/com/cemu_UI/datatypes/UIROMDataType.java b/src/main/java/com/cemu_UI/datatypes/UIROMDataType.java index 2a66c6e..85f762f 100644 --- a/src/main/java/com/cemu_UI/datatypes/UIROMDataType.java +++ b/src/main/java/com/cemu_UI/datatypes/UIROMDataType.java @@ -22,105 +22,73 @@ package com.cemu_UI.datatypes; import com.jfoenix.controls.JFXButton; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; -public class UIROMDataType { +public class UIROMDataType extends VBox { + + private String titleID; + private String romPath; + private Label label = new Label(); + private JFXButton button = new JFXButton(); + private ImageView imageView = new ImageView(); + + public UIROMDataType() { + super.getChildren().addAll(label, button); + + label.setMaxWidth(200); + label.setPadding(new Insets(0,0,0,8)); + label.setFont(Font.font("System", FontWeight.BOLD, 14)); + + imageView.setFitHeight(300); + imageView.setFitWidth(200); + + button.setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 3); "); + button.setGraphic(imageView); + } - private final SimpleObjectProperty vBox = new SimpleObjectProperty<>(); - private final SimpleObjectProperty