Browse Source

Major code clean up

* DBController doesn't need mwc anymore
* no dialogs anymore, only alerts
pull/7/head
Jannik 3 years ago
parent
commit
07ded89069
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 1
      src/main/java/com/cemu_UI/application/Main.java
  2. 359
      src/main/java/com/cemu_UI/application/MainWindowController.java
  3. 2
      src/main/java/com/cemu_UI/controller/CloudController.java
  4. 207
      src/main/java/com/cemu_UI/controller/DBController.java
  5. 35
      src/main/java/com/cemu_UI/datatypes/UIROMDataType.java
  6. 250
      src/main/java/com/cemu_UI/uiElements/JFXEditGameAlert.java
  7. 230
      src/main/java/com/cemu_UI/uiElements/JFXEditGameDialog.java
  8. 2
      src/main/java/com/cemu_UI/uiElements/JFXInfoAlert.java
  9. 15
      src/main/java/com/cemu_UI/uiElements/JFXOkayCancelAlert.java
  10. 6
      src/main/java/com/cemu_UI/uiElements/JFXTextAreaAlert.java

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

@ -148,7 +148,6 @@ public class Main extends Application {
// init here as it loads the games to the mwc and the gui, therefore the window must exist
mainWindowController.init();
mainWindowController.getDbController().init();
// if cloud sync is activated start sync
if (XMLController.isCloudSync()) {

359
src/main/java/com/cemu_UI/application/MainWindowController.java

@ -56,7 +56,7 @@ import com.cemu_UI.datatypes.CourseTableDataType;
import com.cemu_UI.datatypes.GlobalDataTypes.CloudService;
import com.cemu_UI.datatypes.SmmdbApiDataType;
import com.cemu_UI.datatypes.UIROMDataType;
import com.cemu_UI.uiElements.JFXEditGameDialog;
import com.cemu_UI.uiElements.JFXEditGameAlert;
import com.cemu_UI.uiElements.JFXInfoAlert;
import com.cemu_UI.uiElements.JFXOkayCancelAlert;
import com.cemu_UI.uiElements.JFXTextAreaAlert;
@ -187,7 +187,7 @@ public class MainWindowController {
private boolean menuTrue = false;
private boolean playTrue = false;
private String gameExecutePath;
private String dialogBtnStyle;
private String btnStyle;
private String selectedGameTitleID;
private String selectedGameTitle;
private String id;
@ -215,22 +215,8 @@ public class MainWindowController {
private MenuItem addDLC = new MenuItem("add DLC");
private ContextMenu gameContextMenu = new ContextMenu(edit, remove, addUpdate, addDLC);
private Label lastGameLabel = new Label();
private ImageView add_circle_black = new ImageView(new Image("icons/ic_add_circle_black_24dp_1x.png"));
private ImageView info_black = new ImageView(new Image("icons/ic_info_black_24dp_1x.png"));
private ImageView settings_black = new ImageView(new Image("icons/ic_settings_black_24dp_1x.png"));
private ImageView cached_black = new ImageView(new Image("icons/ic_cached_black_24dp_1x.png"));
private ImageView smmdb_black = new ImageView(new Image("icons/ic_get_app_black_24dp_1x.png"));
private ImageView add_circle_white = new ImageView(new Image("icons/ic_add_circle_white_24dp_1x.png"));
private ImageView info_white = new ImageView(new Image("icons/ic_info_white_24dp_1x.png"));
private ImageView settings_white = new ImageView(new Image("icons/ic_settings_white_24dp_1x.png"));
private ImageView cached_white = new ImageView(new Image("icons/ic_cached_white_24dp_1x.png"));
private ImageView smmdb_white = new ImageView(new Image("icons/ic_get_app_white_24dp_1x.png"));
private Image close_black = new Image("icons/close_black_2048x2048.png");
// language support
private ResourceBundle bundle;
private String language;
private String lastPlayed;
private String today;
private String yesterday;
@ -239,7 +225,7 @@ public class MainWindowController {
public MainWindowController(Main main) {
xmlController = new XMLController();
this.main = main;
dbController = new DBController(this);
dbController = DBController.getInstance();
smmdbAPIController = new SmmdbAPIController();
}
@ -252,6 +238,11 @@ public class MainWindowController {
checkAutoUpdate();
initUI();
initActions();
dbController.init();
dbController.refreshDataBase();
games = dbController.loadAllGames();
addAllGames();
}
/**
@ -351,14 +342,14 @@ public class MainWindowController {
String[] gameInfo = dbController.getGameInfo(selectedGameTitleID);
// new edit dialog
String headingText = bundle.getString("editHeadingText") + " \"" + selectedGameTitle + "\"";
JFXEditGameDialog editGameDialog = new JFXEditGameDialog(headingText, bundle.getString("editBodyText"),
dialogBtnStyle, 450, 300, 1, MWC, primaryStage, main.getPane());
editGameDialog.setTitle(gameInfo[0]);
editGameDialog.setCoverPath(gameInfo[1]);
editGameDialog.setRomPath(gameInfo[2]);
editGameDialog.setTitleID(gameInfo[3]);
editGameDialog.show();
String headingText = XMLController.getLocalBundle().getString("editHeadingText") + " \"" + selectedGameTitle + "\"";
JFXEditGameAlert editGameAlert = new JFXEditGameAlert(headingText,
XMLController.getLocalBundle().getString("editBodyText"), btnStyle, 1, primaryStage, MWC);
editGameAlert.setTitle(gameInfo[0]);
editGameAlert.setCoverPath(gameInfo[1]);
editGameAlert.setRomPath(gameInfo[2]);
editGameAlert.setTitleID(gameInfo[3]);
editGameAlert.showAndWait();
} catch (Exception e) {
LOGGER.warn("trying to edit " + selectedGameTitleID + ",which is not a valid type!", e);
}
@ -367,10 +358,9 @@ public class MainWindowController {
remove.setOnAction(event -> {
try {
LOGGER.info("remove " + selectedGameTitle + "(" + selectedGameTitleID + ")");
String headingText = bundle.getString("removeHeadingText") + " \"" + selectedGameTitle + "\"";
String bodyText = bundle.getString("removeBodyText") + " " + selectedGameTitle + " ?";
JFXOkayCancelAlert removeGameAlert = new JFXOkayCancelAlert(headingText, bodyText, dialogBtnStyle,
String headingText = XMLController.getLocalBundle().getString("removeHeadingText") + " \"" + selectedGameTitle + "\"";
String bodyText = XMLController.getLocalBundle().getString("removeBodyText") + " " + selectedGameTitle + " ?";
JFXOkayCancelAlert removeGameAlert = new JFXOkayCancelAlert(headingText, bodyText, btnStyle,
primaryStage);
removeGameAlert.setOkayAction(e -> {
try {
@ -411,10 +401,10 @@ public class MainWindowController {
try {
LOGGER.info("copying the content of " + updatePath + " to " + destDir.toString());
playBtn.setText(bundle.getString("playBtnUpdating"));
playBtn.setText(XMLController.getLocalBundle().getString("playBtnUpdating"));
playBtn.setDisable(true);
FileUtils.copyDirectory(srcDir, destDir);
playBtn.setText(bundle.getString("playBtnPlay"));
playBtn.setText(XMLController.getLocalBundle().getString("playBtnPlay"));
playBtn.setDisable(false);
LOGGER.info("copying files done!");
} catch (IOException e) {
@ -430,9 +420,9 @@ public class MainWindowController {
}
};
String headingText = bundle.getString("addUpdateHeadingText") + " \"" + selectedGameTitle + "\"";
String headingText = XMLController.getLocalBundle().getString("addUpdateHeadingText") + " \"" + selectedGameTitle + "\"";
JFXOkayCancelAlert updateGameAlert = new JFXOkayCancelAlert(headingText,
bundle.getString("addUpdateBodyText"), dialogBtnStyle, primaryStage);
XMLController.getLocalBundle().getString("addUpdateBodyText"), btnStyle, primaryStage);
updateGameAlert.setOkayAction(okayAction);
updateGameAlert.setCancelAction(cancelAction);
updateGameAlert.showAndWait();
@ -447,7 +437,7 @@ public class MainWindowController {
public void handle(ActionEvent event) {
try {
LOGGER.info("add DLC: " + selectedGameTitleID);
String headingText = bundle.getString("addDLCHeadingText") + " \"" + selectedGameTitle + "\"";
String headingText = XMLController.getLocalBundle().getString("addDLCHeadingText") + " \"" + selectedGameTitle + "\"";
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
@ -465,10 +455,10 @@ public class MainWindowController {
try {
LOGGER.info("copying the content of " + dlcPath + " to " + destDir.toString());
playBtn.setText(bundle.getString("playBtnCopyingFiles"));
playBtn.setText(XMLController.getLocalBundle().getString("playBtnCopyingFiles"));
playBtn.setDisable(true);
FileUtils.copyDirectory(srcDir, destDir);
playBtn.setText(bundle.getString("playBtnPlay"));
playBtn.setText(XMLController.getLocalBundle().getString("playBtnPlay"));
playBtn.setDisable(false);
LOGGER.info("copying files done!");
} catch (IOException e) {
@ -485,7 +475,7 @@ public class MainWindowController {
};
JFXOkayCancelAlert addDLCAlert = new JFXOkayCancelAlert(headingText,
bundle.getString("addDLCBodyText"), dialogBtnStyle, primaryStage);
XMLController.getLocalBundle().getString("addDLCBodyText"), btnStyle, primaryStage);
addDLCAlert.setOkayAction(okayAction);
addDLCAlert.setCancelAction(cancelAction);
addDLCAlert.showAndWait();
@ -561,7 +551,7 @@ public class MainWindowController {
smmdbImageView.setImage(scaledImage); // set imageview to image
} catch (MalformedURLException | URISyntaxException e) {
LOGGER.warn("There was either a problem or no image!", e);
smmdbImageView.setImage(close_black);
smmdbImageView.setImage(new Image("icons/close_black_2048x2048.png"));
}
addCourseDescription(courses.get(i));
}
@ -613,16 +603,16 @@ public class MainWindowController {
LOGGER.error("Cloud not read the license file!", ex);
}
JFXTextAreaAlert licenseAlert = new JFXTextAreaAlert("cemu_UI", textAreaText, dialogBtnStyle, primaryStage);
JFXTextAreaAlert licenseAlert = new JFXTextAreaAlert("cemu_UI", textAreaText, btnStyle, primaryStage);
licenseAlert.showAndWait();
};
JFXOkayCancelAlert licenseOverviewAlert = new JFXOkayCancelAlert(
bundle.getString("licensesLblHeadingText"), bundle.getString("licensesLblBodyText"),
dialogBtnStyle, primaryStage);
XMLController.getLocalBundle().getString("licensesLblHeadingText"),
XMLController.getLocalBundle().getString("licensesLblBodyText"), btnStyle, primaryStage);
licenseOverviewAlert.setOkayAction(oE -> {});
licenseOverviewAlert.setCancelAction(cancelAction);
licenseOverviewAlert.setCancelText(bundle.getString("showLicenses"));
licenseOverviewAlert.setCancelText(XMLController.getLocalBundle().getString("showLicenses"));
licenseOverviewAlert.showAndWait();
}
});
@ -633,7 +623,7 @@ public class MainWindowController {
xmlController.saveSettings();
} else {
String bodyText = newValue + ": No such file or directory";
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, primaryStage);
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, btnStyle, primaryStage);
fileErrorDialog.showAndWait();
LOGGER.warn(newValue + ": No such file or directory");
}
@ -646,7 +636,7 @@ public class MainWindowController {
reloadRoms();
} else {
String bodyText = newValue + ": No such file or directory";
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, primaryStage);
JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, btnStyle, primaryStage);
fileErrorDialog.showAndWait();
LOGGER.warn(newValue + ": No such file or directory");
}
@ -662,10 +652,11 @@ public class MainWindowController {
@FXML
private void aboutBtnAction() {
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName + "\" \n"
+ bundle.getString("aboutBtnBodyText");
JFXInfoAlert infoAlert = new JFXInfoAlert(bundle.getString("aboutBtnHeadingText"), bodyText, dialogBtnStyle, primaryStage);
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName
+ "\" \n" + XMLController.getLocalBundle().getString("aboutBtnBodyText");
JFXInfoAlert infoAlert = new JFXInfoAlert(XMLController.getLocalBundle().getString("aboutBtnHeadingText"),
bodyText, btnStyle, primaryStage);
infoAlert.showAndWait();
}
@ -694,7 +685,7 @@ public class MainWindowController {
@Override
public void run() {
Platform.runLater(() -> {
smmdbDownloadBtn.setText(bundle.getString("smmdbDownloadBtnLoading"));
smmdbDownloadBtn.setText(XMLController.getLocalBundle().getString("smmdbDownloadBtnLoading"));
smmdbDownloadBtn.setDisable(true);
root.getChildren().remove(0,root.getChildren().size());
});
@ -708,7 +699,7 @@ public class MainWindowController {
Platform.runLater(() -> {
root.getChildren().add(new TreeItem<CourseTableDataType>(helpCourse)); // add data to root-node
smmdbDownloadBtn.setText(bundle.getString("smmdbDownloadBtnDownload"));
smmdbDownloadBtn.setText(XMLController.getLocalBundle().getString("smmdbDownloadBtnDownload"));
smmdbDownloadBtn.setDisable(false);
});
}
@ -870,8 +861,8 @@ public class MainWindowController {
// cloud sync init error dialog
JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(
bundle.getString("cloudSyncErrorHeadingText"),
bundle.getString("cloudSyncErrorBodyText"), dialogBtnStyle, primaryStage);
XMLController.getLocalBundle().getString("cloudSyncErrorHeadingText"),
XMLController.getLocalBundle().getString("cloudSyncErrorBodyText"), btnStyle, primaryStage);
cloudSyncErrorDialog.showAndWait();
}
@ -881,8 +872,8 @@ public class MainWindowController {
};
JFXOkayCancelAlert cloudSyncWarningAlert = new JFXOkayCancelAlert(
bundle.getString("cloudSyncWaringHeadingText"), bundle.getString("cloudSyncWaringHeadingText"),
dialogBtnStyle, primaryStage);
XMLController.getLocalBundle().getString("cloudSyncWaringHeadingText"),
XMLController.getLocalBundle().getString("cloudSyncWaringHeadingText"), btnStyle, primaryStage);
cloudSyncWarningAlert.setOkayAction(okayAction);
cloudSyncWarningAlert.setCancelAction(e -> cloudSyncToggleBtn.setSelected(false));
cloudSyncWarningAlert.showAndWait();
@ -897,10 +888,10 @@ public class MainWindowController {
@FXML
private void addBtnAction() {
JFXEditGameDialog addGameDialog = new JFXEditGameDialog(bundle.getString("addGameBtnHeadingText"),
bundle.getString("addGameBtnBodyText"), dialogBtnStyle, 450, 300, 0, this, primaryStage,
main.getPane());
addGameDialog.show();
JFXEditGameAlert addGameAlert = new JFXEditGameAlert(
XMLController.getLocalBundle().getString("addGameBtnHeadingText"),
XMLController.getLocalBundle().getString("addGameBtnBodyText"), btnStyle, 0, primaryStage, MWC);
addGameAlert.showAndWait();
}
/**
@ -916,9 +907,10 @@ public class MainWindowController {
if (romPath.length() == 0 || coverPath.length() == 0 || title.length() == 0 || titleID.length() == 0) {
LOGGER.info("No parameter set!");
//addGame error dialog
JFXInfoAlert errorAlert = new JFXInfoAlert(bundle.getString("addBtnReturnErrorHeadingText"),
bundle.getString("addBtnReturnErrorBodyText"), dialogBtnStyle, primaryStage);
// addGame error dialog
JFXInfoAlert errorAlert = new JFXInfoAlert(
XMLController.getLocalBundle().getString("addBtnReturnErrorHeadingText"),
XMLController.getLocalBundle().getString("addBtnReturnErrorBodyText"), btnStyle, primaryStage);
errorAlert.showAndWait();
} else {
@ -936,7 +928,8 @@ public class MainWindowController {
try {
dbController.addGame(title, coverPath, romPath, titleID, "", "", "", "0");
dbController.loadSingleGame(titleID);
games.add(dbController.loadSingleGame(titleID));
addGame(games.stream().filter(x -> x.getRomPath().equals(romPath)).findFirst().orElse(null));
if (menuTrue) {
sideMenuSlideOut();
burgerTask.setRate(-1.0);
@ -953,7 +946,8 @@ public class MainWindowController {
public void editBtnReturn(String title, String coverPath, String romPath, String titleID) {
dbController.setGameInfo(title, coverPath, romPath, titleID);
games.remove(selectedUIDataIndex);
dbController.loadSingleGame(titleID);
games.add(dbController.loadSingleGame(titleID));
addGame(games.stream().filter(x -> x.getRomPath().equals(romPath)).findFirst().orElse(null));
refreshUIData();
LOGGER.info("successfully edited " + titleID + ", new name is \"" + title + "\"");
@ -967,7 +961,7 @@ public class MainWindowController {
* @param titleID : game ID
*/
public void addGame(String title, String coverPath, String romPath, String titleID){
UIROMDataType uiROMElement = new UIROMDataType(titleID, romPath, title, coverPath, gameContextMenu);
UIROMDataType uiROMElement = new UIROMDataType(romPath, titleID, title, coverPath, gameContextMenu);
uiROMElement.getButton().addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
@ -1038,6 +1032,85 @@ public class MainWindowController {
games.add(uiROMElement);
}
/**
* add the context menu and button action for all games
*/
private void addAllGames() {
for (UIROMDataType game : games) {
addGame(game);
}
refreshUIData(); // refresh the list of games displayed on screen
}
/**
* add the context menu and button action for one game
* @param game a game
*/
private void addGame(UIROMDataType game) {
game.getButton().setContextMenu(gameContextMenu);
game.getButton().addEventHandler(MouseEvent.MOUSE_CLICKED, (event) -> {
LOGGER.info("selected: " + game.getLabel().getText() + "; ID: " + game.getTitleID());
// getting the selected game index by comparing event.getSource() with games.get(i).getButton()
for (int i = 0; i < games.size(); i++) {
if (games.get(i).getButton() == event.getSource()) {
selectedUIDataIndex = i;
}
}
gameExecutePath = game.getRomPath();
selectedGameTitleID = game.getTitleID();
selectedGameTitle = game.getName();
// underlining selected Label
lastGameLabel.setStyle("-fx-underline: false;");
games.get(selectedUIDataIndex).getLabel().setStyle("-fx-underline: true;");
lastGameLabel = games.get(selectedUIDataIndex).getLabel();
// setting last played, if lastPlayed is empty game was never played before, else set correct date
if (dbController.getLastPlayed(game.getTitleID()).equals("") || dbController.getLastPlayed(game.getTitleID()).equals(null)) {
lastTimePlayedBtn.setText(lastPlayed + never);
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(game.getTitleID()) + " min");
} else {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
int tToday = Integer.parseInt(dtf.format(LocalDate.now()).replaceAll("-", ""));
int tYesterday = Integer.parseInt(dtf.format(LocalDate.now().minusDays(1)).replaceAll("-", ""));
int tLastPlayedDay = Integer.parseInt(dbController.getLastPlayed(game.getTitleID()).replaceAll("-", ""));
if (tLastPlayedDay == tToday) {
lastTimePlayedBtn.setText(lastPlayed + today);
} else if (tLastPlayedDay == tYesterday) {
lastTimePlayedBtn.setText(lastPlayed + yesterday);
} else {
lastTimePlayedBtn.setText(lastPlayed + dbController.getLastPlayed(game.getTitleID()));
}
}
/**
* setting total playtime, if total playtime > 60 minutes, format is "x hours x
* minutes" (x h x min), else only minutes are showed
*/
if (Integer.parseInt(dbController.getTotalPlaytime(game.getTitleID())) > 60) {
int hoursPlayed = (int) Math.floor(Integer.parseInt(dbController.getTotalPlaytime(game.getTitleID())) / 60);
int minutesPlayed = Integer.parseInt(dbController.getTotalPlaytime(game.getTitleID())) - 60 * hoursPlayed;
totalPlaytimeBtn.setText(hoursPlayed + " h " + minutesPlayed + " min");
} else {
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(game.getTitleID()) + " min");
}
if (!playTrue) {
playBtnSlideIn();
}
if (menuTrue) {
sideMenuSlideOut();
burgerTask.setRate(-1.0);
burgerTask.play();
menuTrue = false;
}
});
}
/**
* reload all ROMs from the ROM directory
*/
@ -1055,10 +1128,10 @@ public class MainWindowController {
dbController.loadRomDirectory(XMLController.getRomDirectoryPath()); // reload the ROM directory
games.clear(); // remove all games from the mwc game list
dbController.loadAllGames(); // load all games from the database to the mwc
games = dbController.loadAllGames();
addAllGames();
Platform.runLater(() -> {
refreshUIData(); // refresh the list of games displayed on screen
mainAnchorPane.getChildren().remove(spinner);
});
};
@ -1077,58 +1150,55 @@ public class MainWindowController {
switch (XMLController.getUsrLocal()) {
case "en_US":
XMLController.setLocalBundle(ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.US)); // us_English
bundle = ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.US); // us_English
languageChoisBox.getSelectionModel().select(0);
break;
case "de_DE":
XMLController.setLocalBundle(ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.GERMAN)); // German
bundle = ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.GERMAN); // German
languageChoisBox.getSelectionModel().select(1);
break;
default:
XMLController.setLocalBundle(ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.US)); // default local
bundle = ResourceBundle.getBundle("locals.cemu_UI-Local", Locale.US); // default local
languageChoisBox.getSelectionModel().select(0);
break;
}
// Buttons
aboutBtn.setText(bundle.getString("aboutBtn"));
settingsBtn.setText(bundle.getString("settingsBtn"));
addBtn.setText(bundle.getString("addBtn"));
reloadRomsBtn.setText(bundle.getString("reloadRomsBtn"));
smmdbBtn.setText(bundle.getString("smmdbBtn"));
cemuTFBtn.setText(bundle.getString("cemuTFBtn"));
romTFBtn.setText(bundle.getString("romTFBtn"));
updateBtn.setText(bundle.getString("updateBtnCheckNow"));
smmdbDownloadBtn.setText(bundle.getString("smmdbDownloadBtn"));
playBtn.setText(bundle.getString("playBtn"));
cloudSyncToggleBtn.setText(bundle.getString("cloudSyncToggleBtn"));
autoUpdateToggleBtn.setText(bundle.getString("autoUpdateToggleBtn"));
fullscreenToggleBtn.setText(bundle.getString("fullscreenToggleBtn"));
aboutBtn.setText(XMLController.getLocalBundle().getString("aboutBtn"));
settingsBtn.setText(XMLController.getLocalBundle().getString("settingsBtn"));
addBtn.setText(XMLController.getLocalBundle().getString("addBtn"));
reloadRomsBtn.setText(XMLController.getLocalBundle().getString("reloadRomsBtn"));
smmdbBtn.setText(XMLController.getLocalBundle().getString("smmdbBtn"));
cemuTFBtn.setText(XMLController.getLocalBundle().getString("cemuTFBtn"));
romTFBtn.setText(XMLController.getLocalBundle().getString("romTFBtn"));
updateBtn.setText(XMLController.getLocalBundle().getString("updateBtnCheckNow"));
smmdbDownloadBtn.setText(XMLController.getLocalBundle().getString("smmdbDownloadBtn"));
playBtn.setText(XMLController.getLocalBundle().getString("playBtn"));
cloudSyncToggleBtn.setText(XMLController.getLocalBundle().getString("cloudSyncToggleBtn"));
autoUpdateToggleBtn.setText(XMLController.getLocalBundle().getString("autoUpdateToggleBtn"));
fullscreenToggleBtn.setText(XMLController.getLocalBundle().getString("fullscreenToggleBtn"));
// Labels
cemu_UISettingsLbl.setText(bundle.getString("cemu_UISettingsLbl"));
cemuDirectoryLbl.setText(bundle.getString("cemuDirectoryLbl"));
romDirectoryLbl.setText(bundle.getString("romDirectoryLbl"));
mainColorLbl.setText(bundle.getString("mainColorLbl"));
languageLbl.setText(bundle.getString("languageLbl"));
updateLbl.setText(bundle.getString("updateLbl"));
branchLbl.setText(bundle.getString("branchLbl"));
cemuSettingsLbl.setText(bundle.getString("cemuSettingsLbl"));
licensesLbl.setText(bundle.getString("licensesLbl"));
cemu_UISettingsLbl.setText(XMLController.getLocalBundle().getString("cemu_UISettingsLbl"));
cemuDirectoryLbl.setText(XMLController.getLocalBundle().getString("cemuDirectoryLbl"));
romDirectoryLbl.setText(XMLController.getLocalBundle().getString("romDirectoryLbl"));
mainColorLbl.setText(XMLController.getLocalBundle().getString("mainColorLbl"));
languageLbl.setText(XMLController.getLocalBundle().getString("languageLbl"));
updateLbl.setText(XMLController.getLocalBundle().getString("updateLbl"));
branchLbl.setText(XMLController.getLocalBundle().getString("branchLbl"));
cemuSettingsLbl.setText(XMLController.getLocalBundle().getString("cemuSettingsLbl"));
licensesLbl.setText(XMLController.getLocalBundle().getString("licensesLbl"));
// Columns
titleColumn.setText(bundle.getString("titleColumn"));
idColumn.setText(bundle.getString("idColumn"));
starsColumn.setText(bundle.getString("starsColumn"));
timeColumn.setText(bundle.getString("timeColumn"));
titleColumn.setText(XMLController.getLocalBundle().getString("titleColumn"));
idColumn.setText(XMLController.getLocalBundle().getString("idColumn"));
starsColumn.setText(XMLController.getLocalBundle().getString("starsColumn"));
timeColumn.setText(XMLController.getLocalBundle().getString("timeColumn"));
// Strings
lastPlayed = bundle.getString("lastPlayed");
today = bundle.getString("today");
yesterday = bundle.getString("yesterday");
never = bundle.getString("never");
lastPlayed = XMLController.getLocalBundle().getString("lastPlayed");
today = XMLController.getLocalBundle().getString("today");
yesterday = XMLController.getLocalBundle().getString("yesterday");
never = XMLController.getLocalBundle().getString("never");
}
// if AutoUpdate, then check for updates
@ -1271,8 +1341,7 @@ public class MainWindowController {
// change the color of all needed GUI elements
private void applyColor() {
String boxStyle = "-fx-background-color: #" + XMLController.getColor() + ";";
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: BLACK;";
String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; -fx-text-fill: WHITE;";
String textFill = "";
BigInteger icolor = new BigInteger(XMLController.getColor(),16);
BigInteger ccolor = new BigInteger("78909cff",16);
@ -1282,55 +1351,45 @@ public class MainWindowController {
romTextField.setFocusColor(Color.valueOf(XMLController.getColor()));
if (icolor.compareTo(ccolor) == -1) {
dialogBtnStyle = btnStyleWhite;
aboutBtn.setStyle("-fx-text-fill: WHITE;");
settingsBtn.setStyle("-fx-text-fill: WHITE;");
addBtn.setStyle("-fx-text-fill: WHITE;");
reloadRomsBtn.setStyle("-fx-text-fill: WHITE;");
smmdbBtn.setStyle("-fx-text-fill: WHITE;");
playBtn.setStyle("-fx-text-fill: WHITE; -fx-font-family: Roboto Medium;");
cemuTFBtn.setStyle(btnStyleWhite);
romTFBtn.setStyle(btnStyleWhite);
updateBtn.setStyle(btnStyleWhite);
smmdbDownloadBtn.setStyle(btnStyleWhite);
playBtn.setStyle(btnStyleWhite);
aboutBtn.setGraphic(info_white);
settingsBtn.setGraphic(settings_white);
addBtn.setGraphic(add_circle_white);
reloadRomsBtn.setGraphic(cached_white);
smmdbBtn.setGraphic(smmdb_white);
textFill = "-fx-text-fill: WHITE;";
aboutBtn.setGraphic(new ImageView(new Image("icons/ic_info_white_24dp_1x.png")));
settingsBtn.setGraphic(new ImageView(new Image("icons/ic_settings_white_24dp_1x.png")));
addBtn.setGraphic(new ImageView(new Image("icons/ic_add_circle_white_24dp_1x.png")));
reloadRomsBtn.setGraphic(new ImageView(new Image("icons/ic_cached_white_24dp_1x.png")));
smmdbBtn.setGraphic(new ImageView(new Image("icons/ic_get_app_white_24dp_1x.png")));
menuHam.getStyleClass().clear();
menuHam.getStyleClass().add("jfx-hamburgerW");
} else {
dialogBtnStyle = btnStyleBlack;
aboutBtn.setStyle("-fx-text-fill: BLACK;");
settingsBtn.setStyle("-fx-text-fill: BLACK;");
addBtn.setStyle("-fx-text-fill: BLACK;");
reloadRomsBtn.setStyle("-fx-text-fill: BLACK;");
smmdbBtn.setStyle("-fx-text-fill: BLACK;");
playBtn.setStyle("-fx-text-fill: BLACK; -fx-font-family: Roboto Medium;");
cemuTFBtn.setStyle(btnStyleBlack);
romTFBtn.setStyle(btnStyleBlack);
updateBtn.setStyle(btnStyleBlack);
smmdbDownloadBtn.setStyle(btnStyleBlack);
playBtn.setStyle(btnStyleBlack);
aboutBtn.setGraphic(info_black);
settingsBtn.setGraphic(settings_black);
addBtn.setGraphic(add_circle_black);
reloadRomsBtn.setGraphic(cached_black);
smmdbBtn.setGraphic(smmdb_black);
textFill = "-fx-text-fill: BLACK;";
aboutBtn.setGraphic(new ImageView(new Image("icons/ic_info_black_24dp_1x.png")));
settingsBtn.setGraphic(new ImageView(new Image("icons/ic_settings_black_24dp_1x.png")));
addBtn.setGraphic(new ImageView(new Image("icons/ic_add_circle_black_24dp_1x.png")));
reloadRomsBtn.setGraphic(new ImageView(new Image("icons/ic_cached_black_24dp_1x.png")));
smmdbBtn.setGraphic(new ImageView(new Image("icons/ic_get_app_black_24dp_1x.png")));
menuHam.getStyleClass().clear();
menuHam.getStyleClass().add("jfx-hamburgerB");
}
for (int i = 0; i < games.size(); i++) {
games.get(i).getButton().setRipplerFill(Paint.valueOf(XMLController.getColor()));
btnStyle = "-fx-button-type: RAISED; -fx-background-color: #" + XMLController.getColor() + "; " + textFill;
aboutBtn.setStyle(textFill);
settingsBtn.setStyle(textFill);
addBtn.setStyle(textFill);
reloadRomsBtn.setStyle(textFill);
smmdbBtn.setStyle(textFill);
playBtn.setStyle(textFill);
cemuTFBtn.setStyle(btnStyle);
romTFBtn.setStyle(btnStyle);
updateBtn.setStyle(btnStyle);
smmdbDownloadBtn.setStyle(btnStyle);
playBtn.setStyle(btnStyle);
for(UIROMDataType game : games) {
game.getButton().setRipplerFill(Paint.valueOf(XMLController.getColor()));
}
}
@ -1411,10 +1470,6 @@ public class MainWindowController {
public Main getMain() {
return main;
}
public DBController getDbController() {
return dbController;
}
public Stage getPrimaryStage() {
return primaryStage;
@ -1444,18 +1499,6 @@ public class MainWindowController {
this.playBtn = playBtn;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public ResourceBundle getBundle() {
return bundle;
}
public AnchorPane getMainAnchorPane() {
return mainAnchorPane;
}

2
src/main/java/com/cemu_UI/controller/CloudController.java

@ -41,6 +41,8 @@ import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
public class CloudController {
// TODO make singleton
public CloudController(MainWindowController mwc) {
this.mwc = mwc;

207
src/main/java/com/cemu_UI/controller/DBController.java

@ -28,6 +28,7 @@ import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@ -45,92 +46,94 @@ import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.cemu_UI.application.MainWindowController;
import com.cemu_UI.datatypes.UIROMDataType;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class DBController {
public DBController(MainWindowController mainWindowController) {
this.mainWindowController = mainWindowController;
}
private MainWindowController mainWindowController;
private static DBController instance = null;
private ArrayList<String> entries = new ArrayList<>();
private String DB_PATH_localRoms;
private String DB_PATH_games;
private Connection connection = null;
private Connection connectionGames = null;
private String DB_PATH_LocalGames;
private String DB_PATH_ReverenceGames;
private Connection connectionLocal = null;
private Connection connectionReverence = null;
private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName());
public DBController() {
}
public static DBController getInstance() {
if (instance == null) {
instance = new DBController();
}
return instance;
}
/**
* initialize the sqlite database controller
* load ROM and games database
* load all games
* initialize the {@link DBController} with the database connection check if
* there is a need to create a new database refresh the database
*/
public void init() {
LOGGER.info("<========== starting loading sql ==========>");
loadRomDatabase();
loadGamesDatabase();
initDatabaseConnection();
createRomDatabase();
LOGGER.info("<========== finished loading sql ==========>");
}
/**
* set the path to the localRoms.db file and initialize the connection
* create a new connection to the HomeFlix.db database
* AutoCommit is set to false to prevent some issues, so manual commit is active!
*
* TODO this should be called LocalGames
*/
private void loadRomDatabase() {
if (System.getProperty("os.name").equals("Linux")) {
DB_PATH_localRoms = System.getProperty("user.home") + "/cemu_UI/localRoms.db";
} else {
DB_PATH_localRoms = System.getProperty("user.home") + "\\Documents\\cemu_UI" + "\\" + "localRoms.db";
}
private void initDatabaseConnection() {
DB_PATH_LocalGames = XMLController.getDirCemuUI() + "/localRoms.db";
DB_PATH_ReverenceGames = XMLController.getRference_gamesFile().getAbsolutePath();
try {
// create a database connection
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_localRoms);
connection.setAutoCommit(false); // AutoCommit to false -> manual commit is active
connectionLocal = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_LocalGames);
connectionLocal.setAutoCommit(false);
connectionReverence = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_ReverenceGames);
connectionReverence.setAutoCommit(false);
} catch (SQLException e) {
// if the error message is "out of memory", probably no database file is found
LOGGER.error("error while loading the ROM database", e);
// if the error message is "out of memory", it probably means no database file is found
LOGGER.error("error while loading the Local- or ReverenceGames database", e);
}
LOGGER.info("ROM database loaded successfull");
LOGGER.info("Local- and ReverenceGames database loaded successfull");
}
/**
* set the path to the localRoms.db file and initialize the connection
* games.db contains a reverence list to for the automatic detection mode
*/
private void loadGamesDatabase() {
DB_PATH_games = XMLController.getRference_gamesFile().getAbsolutePath();
try {
// create a database connection
connectionGames = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_games);
connectionGames.setAutoCommit(false); // AutoCommit to false -> manual commit is active
} catch (SQLException e) {
LOGGER.error("error while loading the games database", e);
}
LOGGER.info("games database loaded successfull");
}
/**
* creating the local_roms table in localRoms.db
* if the table has no entries, call loadRomDirectory
*
* TODO the local_roms table should be called local_games
* TODO the local_roms table should be called LocalGames
*/
void createRomDatabase() {
try {
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
stmt.executeUpdate("create table if not exists local_roms (title, coverPath, romPath, titleID, productCode, region, lastPlayed, timePlayed)");
connectionLocal.commit();
stmt.close();
connection.commit();
} catch (SQLException e) {
LOGGER.error("error while creating ROM database", e);
LOGGER.error("error while creating local-games database", e);
}
}
/**
* refresh database to contain all (new added) games
*/
public void refreshDataBase() {
LOGGER.info("<========== starting refreshing database ==========>");
entries.clear();
try {
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms");
while (rs.next()) {
entries.add(rs.getString(2));
@ -140,63 +143,80 @@ public class DBController {
} catch (SQLException e) {
LOGGER.error("error while loading ROMs from ROM database, local_roms table", e);
}
if (entries.size() == 0) {
mainWindowController.reloadRoms();
} else {
loadAllGames();
mainWindowController.refreshUIData();
}
LOGGER.info("<========== finished refreshing database ==========>");
}
// add a game to the database
public void addGame(String title, String coverPath, String romPath, String titleID, String productCode, String region, String lastPlayed, String timePlayed) throws SQLException{
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
stmt.executeUpdate("insert into local_roms values ('"+title+"','"+coverPath+"','"+romPath+"','"+titleID+"',"
+ "'"+productCode+"','"+region+"','"+lastPlayed+"','"+timePlayed+"')");
connection.commit();
connectionLocal.commit();
stmt.close();
LOGGER.info("added \""+title+"\" to ROM database");
}
// remove a game from the database
public void removeGame(String titleID) throws SQLException{
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
stmt.executeUpdate("delete from local_roms where titleID = '"+titleID+"'");
connection.commit();
connectionLocal.commit();
stmt.close();
LOGGER.info("removed \""+titleID+"\" from ROM database");
}
//load all ROMs to the mainWindowController
public void loadAllGames(){
LOGGER.info("loading all games on startup into the mainWindowController ...");
try {
Statement stmt = connection.createStatement();
/**
* load all games from the database to a ObservableList, order entries by title
* @return a ObservableList that contains all local games from the database
*/
public ObservableList<UIROMDataType> loadAllGames() {
ObservableList<UIROMDataType> games = FXCollections.observableArrayList();
LOGGER.info("loading all local games from the database ...");
try {
Statement stmt = connectionLocal.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms");
while (rs.next()) {
mainWindowController.addGame(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4));
games.add(new UIROMDataType(rs.getString("romPath"), rs.getString("titleID"), rs.getString("title"),
rs.getString("coverPath")));
}
stmt.close();
rs.close();
}catch (Exception e){
LOGGER.error("error while loading all games into the mainWindowController", e);
} catch (Exception e) {
LOGGER.error("error while loading all local games from the database", e);
}
return games;
}
//load a single ROM to the mainWindowController
public void loadSingleGame(String titleID){
LOGGER.info("loading a single game (ID: "+titleID+") into the mainWindowController ...");
/**
* load one game from the database
* @param titleID the titleID of the game you wish to get
* @return the game you asked for
*/
public UIROMDataType loadSingleGame(String titleID) {
UIROMDataType game = null;
LOGGER.info("loading a single game (ID: {}) from the database ...", titleID);
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms where titleID = '"+titleID+"'");
PreparedStatement ps = connectionLocal.prepareStatement("SELECT * FROM local_roms where titleID = ?");
ps.setString(1, titleID);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
mainWindowController.addGame(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4));
game = new UIROMDataType(rs.getString("romPath"), rs.getString("titleID"), rs.getString("title"),
rs.getString("coverPath"));
}
stmt.close();
rs.close();
ps.close();
}catch (Exception e){
LOGGER.error("error while loading a single game into the mainWindowController", e);
}
return game;
}
/**
@ -210,7 +230,7 @@ public class DBController {
File pictureCache = XMLController.getPictureCache();
String coverPath;
try {
Statement stmt = connectionGames.createStatement();
Statement stmt = connectionReverence.createStatement();
List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
LOGGER.info("<============================== start loading ROM Directory ==============================>");
LOGGER.info("Getting all .rpx files in " + dir.getCanonicalPath()+" including those in subdirectories");
@ -256,7 +276,7 @@ public class DBController {
* @throws SQLException
*/
private boolean checkAddEntry(String title) throws SQLException{
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
boolean check = false;
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms WHERE title = '"+title+"';");
while (rs.next()) {
@ -274,15 +294,6 @@ public class DBController {
//LOGGER.info("check if entry removed not done yet!");
}
private static BufferedImage resizeImage(BufferedImage originalImage, int type, int IMG_WIDTH, int IMG_HEIGHT) {
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
return resizedImage;
}
/**
* getting info for a game with titleID
* @param titleID Title-ID of the Game
@ -292,7 +303,7 @@ public class DBController {
String[] gameInfo = new String[4];
LOGGER.info("getting game info for titleID: "+titleID+" ...");
try {
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms where titleID = '"+titleID+"'");
while (rs.next()) {
gameInfo[0] = rs.getString(1);// title
@ -311,10 +322,10 @@ public class DBController {
public void setGameInfo(String title, String coverPath, String romPath, String titleID){
LOGGER.info("setting game info for titleID: "+titleID+" ...");
try {
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
stmt.executeUpdate("UPDATE local_roms SET title = '" + title + "', coverPath = '" + coverPath + "',"
+ " romPath = '" + romPath + "' WHERE titleID = '"+titleID+"';");
connection.commit();
connectionLocal.commit();
stmt.close();
}catch (Exception e){
LOGGER.error("error while setting game info", e);
@ -323,9 +334,9 @@ public class DBController {
public void setLastPlayed(String titleID){
try{
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
stmt.executeUpdate("UPDATE local_roms SET lastPlayed=date('now') WHERE titleID = '"+titleID+"';");
connection.commit();
connectionLocal.commit();
stmt.close();
}catch(SQLException e){
LOGGER.error("failed to set the last played", e);
@ -335,7 +346,7 @@ public class DBController {
public String getLastPlayed(String titleID){
String lastPlayed = null;
try{
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
ResultSet rs = stmt.executeQuery("SELECT lastPlayed FROM local_roms WHERE titleID = '"+titleID+"';" );
lastPlayed = rs.getString(1);
stmt.close();
@ -348,9 +359,9 @@ public class DBController {
public void setTotalPlaytime(String timePlayed, String titleID){
try{
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
stmt.executeUpdate("UPDATE local_roms SET timePlayed='"+timePlayed+"' WHERE titleID = '"+titleID+"';");
connection.commit();
connectionLocal.commit();
stmt.close();
}catch(SQLException e){
LOGGER.error("failed to set total play time", e);
@ -361,7 +372,7 @@ public class DBController {
public String getTotalPlaytime(String titleID){
String timePlayed = null;
try{
Statement stmt = connection.createStatement();
Statement stmt = connectionLocal.createStatement();
ResultSet rs = stmt.executeQuery("SELECT timePlayed FROM local_roms WHERE titleID = '"+titleID+"';" );
timePlayed = rs.getString(1);
stmt.close();
@ -372,5 +383,13 @@ public class DBController {
return timePlayed;
}
private static BufferedImage resizeImage(BufferedImage originalImage, int type, int IMG_WIDTH, int IMG_HEIGHT) {
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
return resizedImage;
}
}

35
src/main/java/com/cemu_UI/datatypes/UIROMDataType.java

@ -36,19 +36,32 @@ import javafx.scene.text.FontWeight;
public class UIROMDataType extends VBox {
private String titleID;
private String romPath;
private String titleID;
private String name;
private Label label = new Label();
private JFXButton button = new JFXButton();
private ImageView imageView = new ImageView();
public UIROMDataType(String titleID, String romPath, String text, String coverPath, ContextMenu contextMenu) {
public UIROMDataType(String romPath, String titleID, String name, String coverPath) {
this();
this.romPath = romPath;
this.titleID = titleID;
this.name = name;
label.setText(name);
imageView.setImage(new Image(new File(coverPath).toURI().toString()));
}
public UIROMDataType(String romPath, String titleID, String name, String coverPath, ContextMenu contextMenu) {
this();
this.romPath = romPath;
this.titleID = titleID;
this.name = name;
label.setText(text);
label.setText(name);
imageView.setImage(new Image(new File(coverPath).toURI().toString()));
button.setContextMenu(contextMenu);
}
@ -67,12 +80,16 @@ public class UIROMDataType extends VBox {
button.setGraphic(imageView);
}
public String getRomPath() {
return romPath;
}
public String getTitleID() {
return titleID;
}
public String getRomPath() {
return romPath;
public String getName() {
return name;
}
public Label getLabel() {
@ -86,13 +103,17 @@ public class UIROMDataType extends VBox {
public ImageView getImageView() {
return imageView;
}
public void setRomPath(String romPath) {
this.romPath = romPath;
}
public void setTitleID(String titleID) {
this.titleID = titleID;
}
public void setRomPath(String romPath) {
this.romPath = romPath;
public void setName(String name) {
this.name = name;
}
public void setLabel(Label label) {

250
src/main/java/com/cemu_UI/uiElements/JFXEditGameAlert.java

@ -0,0 +1,250 @@
/**
* cemu_UI
*
* Copyright 2017-2019 <@Seil0>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package com.cemu_UI.uiElements;
import java.io.File;
import com.cemu_UI.application.MainWindowController;
import com.cemu_UI.controller.XMLController;
import com.jfoenix.controls.JFXAlert;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialogLayout;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class JFXEditGameAlert {
private String headingText;
private String bodyText;
private String title = "";
private String coverPath = "";
private String romPath = "";
private String titleID = "";
private String btnStyle;
private int mode;
private Stage stage;
private MainWindowController mwc; // TODO remove this!
/**
* Creates a new JFoenix Alert to show some information with okay and cancel option
* @param headingText Heading text of the alert
* @param bodyText Content text of the alert
* @param btnStyle Style of the buttons
* @param mode Set to 0 for add and 1 for edit mode
* @param stage Stage to which the Alert belongs
* @param mwc a mwc dep, it's horrible i know
*/
public JFXEditGameAlert(String headingText, String bodyText, String btnStyle, int mode, Stage stage, MainWindowController mwc) {
this.headingText = headingText;
this.bodyText = bodyText;
this.btnStyle = btnStyle;
this.mode = mode;
this.stage = stage;
this.mwc = mwc;
}
public void showAndWait( ) {
JFXAlert<Void> alert = new JFXAlert<>(stage);
TextField gameTitleTF = new TextField();
gameTitleTF.setPromptText(XMLController.getLocalBundle().getString("gameTitle"));
TextField gameTitleIDTF = new TextField();
gameTitleIDTF.setPromptText(XMLController.getLocalBundle().getString("titleID"));
TextField romPathTF = new TextField();
romPathTF.setPromptText(XMLController.getLocalBundle().getString("romPath"));
TextField gameCoverTF = new TextField();
gameCoverTF.setPromptText(XMLController.getLocalBundle().getString("coverPath"));
if (mode == 1) {
gameTitleTF.setText(title);
gameTitleIDTF.setText(titleID);
romPathTF.setText(romPath);
gameCoverTF.setText(coverPath);
gameTitleIDTF.setEditable(false);
}
JFXButton okayBtn = new JFXButton(XMLController.getLocalBundle().getString("okayBtnText"));
okayBtn.setOnAction(event -> {
if (romPathTF.getText().toString().length() == 0 || gameCoverTF.getText().toString().length() == 0
|| gameTitleTF.getText().toString().