Browse Source

clean up some mwc code + UIROMDataType

it should be now much better to understand the generatePosition() method
pull/7/head
Jannik 3 years ago
parent
commit
0599945036
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 4
      src/main/java/com/cemu_UI/application/Main.java
  2. 84
      src/main/java/com/cemu_UI/application/MainWindowController.java
  3. 132
      src/main/java/com/cemu_UI/datatypes/UIROMDataType.java

4
src/main/java/com/cemu_UI/application/Main.java

@ -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();
}

84
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<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() {

132
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> 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();
/**
* 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 String getTitleID() {
return titleID;
}
public SimpleObjectProperty<VBox> vBoxProperty(){
return vBox;
public String getRomPath() {
return romPath;
}
public SimpleObjectProperty<Label> labelProperty(){
public Label getLabel() {
return label;
}
public SimpleObjectProperty<JFXButton> buttonProperty(){
public JFXButton getButton() {
return button;
}
public SimpleObjectProperty<ImageView> imageViewProperty(){
public ImageView getImageView() {
return imageView;
}
public StringProperty titleIDProperty(){
return titleID;
}
public StringProperty romPathProperty(){
return romPath;
}
public final VBox getVBox() {
return vBoxProperty().get();
}
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 void setTitleID(String titleID) {
this.titleID = titleID;
}
public final void setLabel(Label label) {
labelProperty().set(label);
public void setRomPath(String romPath) {
this.romPath = romPath;
}
public final void setButton(JFXButton button) {
buttonProperty().set(button);
public void setLabel(Label label) {
this.label = label;
}
public final void setImageView(ImageView imageView) {
imageViewProperty().set(imageView);
public void setButton(JFXButton button) {
this.button = button;
}
public final void setTitleID(String titleID){
titleIDProperty().set(titleID);
public void setImageView(ImageView imageView) {
this.imageView = imageView;
}
public final void setRomPath(String romPath){
romPathProperty().set(romPath);
}
}

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close