clean up some mwc code + UIROMDataType

it should be now much better to understand the generatePosition() method
This commit is contained in:
Jannik 2019-05-15 16:19:31 +02:00
parent df33c21826
commit 0599945036
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
3 changed files with 81 additions and 155 deletions

View File

@ -218,10 +218,10 @@ public class Main extends Application {
@Override @Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, final Number newValue) { 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 // call only if there is enough space for a new row
if (mainWindowController.getOldXPosHelper() != xPosHelperMax) { if (mainWindowController.getOldXNextElement() != xMaxElements) {
mainWindowController.refreshUIData(); mainWindowController.refreshUIData();
} }

View File

@ -78,7 +78,6 @@ import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.ChoiceBox; import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -194,8 +193,8 @@ public class MainWindowController {
private String versionName = "Purple Comet"; private String versionName = "Purple Comet";
private int xPos = -200; private int xPos = -200;
private int yPos = 17; private int yPos = 17;
private int xPosHelper = 0; private int xNextElement = 0;
private int oldXPosHelper; private int oldXNextElement;
private int selectedUIDataIndex; private int selectedUIDataIndex;
private int selected; private int selected;
private DirectoryChooser directoryChooser = new DirectoryChooser(); private DirectoryChooser directoryChooser = new DirectoryChooser();
@ -1024,29 +1023,14 @@ public class MainWindowController {
* @param titleID : game ID * @param titleID : game ID
*/ */
public void addGame(String title, String coverPath, String romPath, String titleID){ 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()); Image coverImage = new Image(new File(coverPath).toURI().toString());
UIROMDataType uiROMElement = new UIROMDataType();
generatePosition(); generatePosition();
UIROMDataType uiROMElement = new UIROMDataType(VBox, gameTitleLabel, gameBtn, imageView, titleID, romPath);
uiROMElement.getLabel().setText(title); 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().setImage(coverImage);
uiROMElement.getImageView().setFitHeight(300);
uiROMElement.getImageView().setFitWidth(200);
uiROMElement.getButton().setGraphic(uiROMElement.getImageView());
uiROMElement.getButton().setContextMenu(gameContextMenu); 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>() { uiROMElement.getButton().addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override @Override
public void handle(MouseEvent event) { 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 // add uiROMElement to games list
games.add(uiROMElement); games.add(uiROMElement);
} }
@ -1154,20 +1134,21 @@ public class MainWindowController {
//remove all games from gamesAnchorPane and add them afterwards //remove all games from gamesAnchorPane and add them afterwards
public void refreshUIData() { public void refreshUIData() {
//remove all games form gamesAnchorPane //remove all games form gamesAnchorPane
gamesAnchorPane.getChildren().removeAll(gamesAnchorPane.getChildren()); gamesAnchorPane.getChildren().clear();
//reset position //reset position
xPos = -200; xPos = -200;
yPos = 17; yPos = 17;
xPosHelper = 0; xNextElement = 0;
//add all games to gamesAnchorPane (UI) //add all games to gamesAnchorPane (UI)
for(int i=0; i< games.size(); i++){ for(UIROMDataType game : games) {
generatePosition(); generatePosition();
games.get(i).getVBox().setLayoutX(getxPos());
games.get(i).getVBox().setLayoutY(getyPos()); game.setLayoutX(xPos);
gamesAnchorPane.getChildren().add(games.get(i).getVBox()); game.setLayoutY(yPos);
} gamesAnchorPane.getChildren().add(game);
}
} }
// set the selected local strings to all needed elements // 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 * calculates how many games can be displayed in one row
*/ */
private void generatePosition() { 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){ if(xNextElement >= xMaxElements){
oldXPosHelper = xPosHelper; oldXNextElement = xNextElement;
xPos = 17; xPos = 17;
yPos = yPos + 345; yPos = yPos + 345;
xPosHelper = 1; xNextElement = 1;
}else{ }else{
xPos = xPos + 217; xPos = xPos + 217;
xPosHelper++; xNextElement++;
} }
} }
@ -1536,30 +1518,6 @@ public class MainWindowController {
return primaryStage; 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() { public String getGameExecutePath() {
return gameExecutePath; return gameExecutePath;
} }
@ -1584,8 +1542,8 @@ public class MainWindowController {
this.playBtn = playBtn; this.playBtn = playBtn;
} }
public int getOldXPosHelper() { public int getOldXNextElement() {
return oldXPosHelper; return oldXNextElement;
} }
public String getLanguage() { public String getLanguage() {

View File

@ -22,105 +22,73 @@ package com.cemu_UI.datatypes;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import javafx.beans.property.SimpleObjectProperty; import javafx.geometry.Insets;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox; 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> vBox = new SimpleObjectProperty<>(); public String getTitleID() {
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();
/**
* 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 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(){
return titleID; return titleID;
} }
public StringProperty romPathProperty(){ public String getRomPath() {
return romPath; return romPath;
} }
public Label getLabel() {
public final VBox getVBox() { return label;
return vBoxProperty().get(); }
public JFXButton getButton() {
return button;
}
public ImageView getImageView() {
return imageView;
}
public void setTitleID(String titleID) {
this.titleID = titleID;
}
public void setRomPath(String romPath) {
this.romPath = romPath;
}
public void setLabel(Label label) {
this.label = label;
}
public void setButton(JFXButton button) {
this.button = button;
}
public void setImageView(ImageView imageView) {
this.imageView = imageView;
} }
public final Label getLabel() {
return labelProperty().get();
}
public final JFXButton getButton() {
return buttonProperty().get();
}
public final ImageView getImageView() {
return imageViewProperty().get();
}
public final String getTitleID(){
return titleIDProperty().get();
}
public final String getRomPath(){
return romPathProperty().get();
}
public final void setVBox(VBox vBox) {
vBoxProperty().set(vBox);
}
public final void setLabel(Label label) {
labelProperty().set(label);
}
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);
}
} }