clean up some mwc code + UIROMDataType
it should be now much better to understand the generatePosition() method
This commit is contained in:
parent
df33c21826
commit
0599945036
|
@ -218,10 +218,10 @@ public class Main extends Application {
|
|||
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<MouseEvent>() {
|
||||
@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() {
|
||||
|
|
|
@ -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 final SimpleObjectProperty<VBox> vBox = new SimpleObjectProperty<>();
|
||||
private final SimpleObjectProperty<Label> label = new SimpleObjectProperty<>();
|
||||
private final SimpleObjectProperty<JFXButton> button = new SimpleObjectProperty<>();
|
||||
private final SimpleObjectProperty<ImageView> imageView = new SimpleObjectProperty<>();
|
||||
private final StringProperty titleID = new SimpleStringProperty();
|
||||
private final StringProperty romPath = new SimpleStringProperty();
|
||||
private String titleID;
|
||||
private String romPath;
|
||||
private Label label = new Label();
|
||||
private JFXButton button = new JFXButton();
|
||||
private ImageView imageView = new ImageView();
|
||||
|
||||
/**
|
||||
* Data type used for UI ROM elements all uiROMElemts are of this data type
|
||||
*/
|
||||
public UIROMDataType (final VBox vBox, final Label label, final JFXButton button, final ImageView imageView, final String titleID, final String romPath){
|
||||
this.vBox.set(vBox);
|
||||
this.label.set(label);
|
||||
this.button.set(button);
|
||||
this.imageView.set(imageView);
|
||||
this.titleID.set(titleID);
|
||||
this.romPath.set(romPath);
|
||||
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);
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<VBox> vBoxProperty(){
|
||||
return vBox;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<Label> labelProperty(){
|
||||
return label;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<JFXButton> buttonProperty(){
|
||||
return button;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<ImageView> imageViewProperty(){
|
||||
return imageView;
|
||||
}
|
||||
|
||||
public StringProperty titleIDProperty(){
|
||||
public String getTitleID() {
|
||||
return titleID;
|
||||
}
|
||||
|
||||
public StringProperty romPathProperty(){
|
||||
public String getRomPath() {
|
||||
return romPath;
|
||||
}
|
||||
|
||||
|
||||
public final VBox getVBox() {
|
||||
return vBoxProperty().get();
|
||||
public Label getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public final Label getLabel() {
|
||||
return labelProperty().get();
|
||||
public JFXButton getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
public final JFXButton getButton() {
|
||||
return buttonProperty().get();
|
||||
public ImageView getImageView() {
|
||||
return imageView;
|
||||
}
|
||||
|
||||
public final ImageView getImageView() {
|
||||
return imageViewProperty().get();
|
||||
public void setTitleID(String titleID) {
|
||||
this.titleID = titleID;
|
||||
}
|
||||
|
||||
public final String getTitleID(){
|
||||
return titleIDProperty().get();
|
||||
public void setRomPath(String romPath) {
|
||||
this.romPath = romPath;
|
||||
}
|
||||
|
||||
public final String getRomPath(){
|
||||
return romPathProperty().get();
|
||||
public void setLabel(Label label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
|
||||
public final void setVBox(VBox vBox) {
|
||||
vBoxProperty().set(vBox);
|
||||
public void setButton(JFXButton button) {
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
public final void setLabel(Label label) {
|
||||
labelProperty().set(label);
|
||||
public void setImageView(ImageView imageView) {
|
||||
this.imageView = imageView;
|
||||
}
|
||||
|
||||
public final void setButton(JFXButton button) {
|
||||
buttonProperty().set(button);
|
||||
}
|
||||
|
||||
public final void setImageView(ImageView imageView) {
|
||||
imageViewProperty().set(imageView);
|
||||
}
|
||||
|
||||
public final void setTitleID(String titleID){
|
||||
titleIDProperty().set(titleID);
|
||||
}
|
||||
|
||||
public final void setRomPath(String romPath){
|
||||
romPathProperty().set(romPath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue