diff --git a/bin/application/Main.class b/bin/application/Main.class index 59c3a07..bb67c86 100644 Binary files a/bin/application/Main.class and b/bin/application/Main.class differ diff --git a/bin/application/MainWindow.fxml b/bin/application/MainWindow.fxml index e762ec0..75c7178 100644 --- a/bin/application/MainWindow.fxml +++ b/bin/application/MainWindow.fxml @@ -14,7 +14,7 @@ - + @@ -22,7 +22,7 @@ - + @@ -54,10 +54,16 @@ - + + + + + + + diff --git a/bin/application/MainWindowController$1.class b/bin/application/MainWindowController$1.class index d7bfc02..866f9d0 100644 Binary files a/bin/application/MainWindowController$1.class and b/bin/application/MainWindowController$1.class differ diff --git a/bin/application/MainWindowController$2.class b/bin/application/MainWindowController$2.class index 103ae18..925c44a 100644 Binary files a/bin/application/MainWindowController$2.class and b/bin/application/MainWindowController$2.class differ diff --git a/bin/application/MainWindowController$3.class b/bin/application/MainWindowController$3.class index 278d9b9..5c96335 100644 Binary files a/bin/application/MainWindowController$3.class and b/bin/application/MainWindowController$3.class differ diff --git a/bin/application/MainWindowController$4.class b/bin/application/MainWindowController$4.class index 648318f..4f71d50 100644 Binary files a/bin/application/MainWindowController$4.class and b/bin/application/MainWindowController$4.class differ diff --git a/bin/application/MainWindowController$5.class b/bin/application/MainWindowController$5.class index 391012d..e813135 100644 Binary files a/bin/application/MainWindowController$5.class and b/bin/application/MainWindowController$5.class differ diff --git a/bin/application/MainWindowController$6.class b/bin/application/MainWindowController$6.class index 0da5c71..f35e8ee 100644 Binary files a/bin/application/MainWindowController$6.class and b/bin/application/MainWindowController$6.class differ diff --git a/bin/application/MainWindowController$7.class b/bin/application/MainWindowController$7.class index b03be32..bc89952 100644 Binary files a/bin/application/MainWindowController$7.class and b/bin/application/MainWindowController$7.class differ diff --git a/bin/application/MainWindowController.class b/bin/application/MainWindowController.class index ca0c2bf..8b79d8c 100644 Binary files a/bin/application/MainWindowController.class and b/bin/application/MainWindowController.class differ diff --git a/bin/application/dbController.class b/bin/application/dbController.class index 3b8c3b9..1e4f6ea 100644 Binary files a/bin/application/dbController.class and b/bin/application/dbController.class differ diff --git a/src/application/Main.java b/src/application/Main.java index b873857..6082751 100644 --- a/src/application/Main.java +++ b/src/application/Main.java @@ -1,13 +1,16 @@ package application; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; import java.util.Optional; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.stage.DirectoryChooser; -import javafx.stage.FileChooser; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Alert; @@ -20,12 +23,16 @@ public class Main extends Application { Stage primaryStage; private MainWindowController mainWindowController; - private File dirWin = new File(System.getProperty("user.home") + "/Documents/cemu_UI"); //Windows: C:/Users/"User"/Documents/HomeFlix - private File dirLinux = new File(System.getProperty("user.home") + "/cemu_UI"); //Linux: /home/"User"/HomeFlix - private File fileWin = new File(dirWin + "/config.xml"); //Windows: C:/Users/"User"/Documents/HomeFlix/config.xml - private File fileLinux = new File(dirLinux + "/config.xml"); //Linux: /home/"User"/HomeFlix/config.xml - private File pictureCacheWin = new File(dirWin+"/picture_cache"); - private File pictureCacheLinux = new File(dirLinux+"/picture_cache"); + private String dirWin = System.getProperty("user.home") + "/Documents/cemu_UI"; //Windows: C:/Users/"User"/Documents/HomeFlix + private String dirLinux = System.getProperty("user.home") + "/cemu_UI"; //Linux: /home/"User"/HomeFlix + private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db"; + private File directory; + private File configFile; + private File gamesDBFile; + @SuppressWarnings("unused") + private File localDB; + private File pictureCache; + @Override public void start(Stage primaryStage) { @@ -37,8 +44,6 @@ public class Main extends Application { try { FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml")); AnchorPane pane = loader.load(); - primaryStage.setMinHeight(600.00); - primaryStage.setMinWidth(900.00); primaryStage.setResizable(false); primaryStage.setTitle("cemu_UI"); // primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/recources/Homeflix_Icon_64x64.png"))); //adds application icon @@ -46,46 +51,61 @@ public class Main extends Application { mainWindowController = loader.getController(); //Link of FXMLController and controller class mainWindowController.setMain(this); //call setMain - //Linux if directory exists -> check config.xml + //get os and the right paths if(System.getProperty("os.name").equals("Linux")){ - if(dirLinux.exists() != true){ - dirLinux.mkdir(); - pictureCacheLinux.mkdir(); - }else if(fileLinux.exists() != true){ - firstStart(); - mainWindowController.setColor("00a8cc"); - mainWindowController.setxPosHelper(0); - mainWindowController.saveSettings(); - Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs) - System.exit(0); //finishes itself - } - if(pictureCacheLinux.exists() != true){ - pictureCacheLinux.mkdir(); - } - //windows + directory = new File(dirLinux); + configFile = new File(dirLinux + "/config.xml"); + gamesDBFile = new File(dirLinux + "/games.db"); + localDB = new File(dirLinux+"/localRoms.db"); + pictureCache= new File(dirLinux+"/picture_cache"); }else{ - if(dirWin.exists() != true){ - dirWin.mkdir(); - pictureCacheWin.mkdir(); - }else if(fileWin.exists() != true){ - firstStart(); - mainWindowController.setColor("00a8cc"); - mainWindowController.setxPosHelper(0); - mainWindowController.saveSettings(); - Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs) - System.exit(0); //finishes itself - } - if(pictureCacheWin.exists() != true){ - pictureCacheWin.mkdir(); + directory = new File(dirWin); + configFile = new File(dirWin + "/config.xml"); + gamesDBFile = new File(dirWin + "/games.db"); + localDB = new File(dirWin+"/localRoms.db"); + pictureCache= new File(dirWin+"/picture_cache"); + } + + //startup checks + System.out.println(directory.exists()); + System.out.println(configFile.exists()); + if(directory.exists() != true){ + System.out.println("mkdir all"); + directory.mkdir(); + pictureCache.mkdir(); + } + + if(configFile.exists() != true){ + System.out.println("firststart"); + firstStart(); + mainWindowController.setColor("00a8cc"); + mainWindowController.setxPosHelper(0); + mainWindowController.saveSettings(); + Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs) + System.exit(0); //finishes itself + } + + if(pictureCache.exists() != true){ + pictureCache.mkdir(); + } + + if(gamesDBFile.exists() != true){ + try { + System.out.print("downloading games.db... "); + URL website = new URL(gamesDBdownloadURL); + ReadableByteChannel rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(gamesDBFile); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + System.out.println("done!"); + } catch (Exception e) { + e.printStackTrace(); } } - //TODO download games.db + //loading settings and initialize UI mainWindowController.loadSettings(); - mainWindowController.dbController.main(); - mainWindowController.dbController.loadRoms(); - mainWindowController.initActions(); mainWindowController.initUI(); diff --git a/src/application/MainWindow.fxml b/src/application/MainWindow.fxml index e762ec0..75c7178 100644 --- a/src/application/MainWindow.fxml +++ b/src/application/MainWindow.fxml @@ -14,7 +14,7 @@ - + @@ -22,7 +22,7 @@ - + @@ -54,10 +54,16 @@ - + + + + + + + diff --git a/src/application/MainWindowController.java b/src/application/MainWindowController.java index d65fa7c..4780489 100644 --- a/src/application/MainWindowController.java +++ b/src/application/MainWindowController.java @@ -9,6 +9,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.sql.SQLException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Optional; import java.util.Properties; @@ -70,6 +72,12 @@ public class MainWindowController { @FXML private JFXButton playBtn; + @FXML + private JFXButton timePlayedBtn; + + @FXML + private JFXButton lastTimePlayedBtn; + @FXML private JFXHamburger menuHam; @@ -109,6 +117,7 @@ public class MainWindowController { private String romPath; private String gameExecutePath; private String selectedGameTitleID; + private String selectedGameTitle; private String color; private int xPos = -200; private int yPos = 17; @@ -152,12 +161,13 @@ public class MainWindowController { } void initActions() { - System.out.println("initializing Actions ..."); + System.out.print("initializing Actions... "); HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam); menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{ if(playTrue){ playBtnSlideOut(); + lastTimePlayedBtnSlideOut(); } if(menuTrue == false){ sideMenuSlideIn(); @@ -215,7 +225,6 @@ public class MainWindowController { alert.showAndWait(); } else{ - System.out.println("remove TODO!"); int i = gameCover.indexOf((selectedEvent).getSource()); gameVBox.remove(i); gameCover.remove(i); @@ -246,7 +255,7 @@ public class MainWindowController { }else{ Alert updateAlert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser updateAlert.setTitle("cemu_UI"); - updateAlert.setHeaderText("add new Game"); + updateAlert.setHeaderText("update "+selectedGameTitle); updateAlert.setContentText("pleas select the update directory"); updateAlert.initOwner(main.primaryStage); @@ -269,7 +278,11 @@ public class MainWindowController { try { System.out.println("copying files..."); - FileUtils.copyDirectory(srcDir, destDir); + playBtn.setText("updating..."); + playBtn.setDisable(true); + FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator + playBtn.setText("play"); + playBtn.setDisable(false); System.out.println("done!"); } catch (IOException e) { e.printStackTrace(); @@ -293,6 +306,7 @@ public class MainWindowController { public void handle(MouseEvent event) { if (playTrue) { playBtnSlideOut(); + lastTimePlayedBtnSlideOut(); } } }); @@ -302,6 +316,7 @@ public class MainWindowController { public void handle(MouseEvent event) { if (playTrue) { playBtnSlideOut(); + lastTimePlayedBtnSlideOut(); } } }); @@ -327,6 +342,16 @@ public class MainWindowController { e.printStackTrace(); } } + + @FXML + void timePlayedBtnAction(ActionEvent event){ + + } + + @FXML + void lastTimePlayedBtnAction(ActionEvent event){ + + } @FXML void settingsBtnAction(ActionEvent event) { @@ -346,7 +371,7 @@ public class MainWindowController { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("about"); alert.setHeaderText("cemu_UI"); - alert.setContentText("cemu_UI by @Seil0 \npre release 0.0.1 \nwww.kellerkinder.xyz"); + alert.setContentText("cemu_UI by @Seil0 \npre release 0.1.0 \nwww.kellerkinder.xyz"); alert.initOwner(main.primaryStage); alert.showAndWait(); } @@ -526,57 +551,68 @@ public class MainWindowController { void addGame(String title, String coverPath, String romPath, String titleID){ ImageView imageView = new ImageView(); //TODO abgerundete Kanten, - Label gameTitle = new Label(title); - File file = new File(coverPath); + Label gameTitleLabel = new Label(title); + File coverFile = new File(coverPath); VBox VBox = new VBox(); JFXButton gameBtn = new JFXButton(); - Image image = new Image(file.toURI().toString()); + Image coverImage = new Image(coverFile.toURI().toString()); generatePosition(); // System.out.println("Title: "+title+"; cover: "+coverPath+"; rom: "+romPath); // System.out.println("X: "+getxPos()+"; Y: "+getyPos()); gameVBox.add(VBox); gameCover.add(gameBtn); - gameLabel.add(gameTitle); - gameTitle.setMaxWidth(200); - imageView.setImage(image); + gameLabel.add(gameTitleLabel); + gameTitleLabel.setMaxWidth(200); + imageView.setImage(coverImage); imageView.setFitHeight(300); imageView.setFitWidth(200); gameBtn.setGraphic(imageView); - gameBtn.setContextMenu(gameContextMenu); -// gameBtn.setOnAction(new EventHandler() { -// @Override -// public void handle(ActionEvent event) { - + gameBtn.setContextMenu(gameContextMenu); gameBtn.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { @Override public void handle(MouseEvent event) { - System.out.println("selected: "+title+"; ID: "+titleID); + gameExecutePath = romPath; selectedGameTitleID = titleID; + selectedGameTitle = title; selectedEvent = event; lastGameLabel.setStyle("-fx-underline: false;"); gameLabel.get(gameCover.indexOf(event.getSource())).setStyle("-fx-underline: true;"); lastGameLabel = gameLabel.get(gameCover.indexOf(event.getSource())); - System.out.println(dbController.getLastPlayed(titleID)); + + if(dbController.getLastPlayed(titleID).equals("") || dbController.getLastPlayed(titleID).equals(null)){ + lastTimePlayedBtn.setText("Last played, never"); + }else{ + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + int localInt = Integer.parseInt(dtf.format(LocalDate.now()).replaceAll("-", "")); + int lastInt = Integer.parseInt(dbController.getLastPlayed(titleID).replaceAll("-", "")); + + if(localInt == lastInt){ + lastTimePlayedBtn.setText("Last played, today"); + }else if(localInt-1 == lastInt){ + lastTimePlayedBtn.setText("Last played, yesterday"); + }else{ + lastTimePlayedBtn.setText("Last played, "+dbController.getLastPlayed(titleID)); + } + } if(playTrue == false){ - playBtnSlideIn(); //TODO anderes design(mehr details spielzeit, zuletzt gespielt, etc.) + playBtnSlideIn(); //TODO anderes design(mehr details spielzeit, etc.) + lastTimePlayedBtnSlideIn(); } } }); - gameTitle.setFont(Font.font("System", FontWeight.BOLD, 14)); - VBox.getChildren().addAll(gameTitle,gameBtn); + gameTitleLabel.setFont(Font.font("System", FontWeight.BOLD, 14)); + VBox.getChildren().addAll(gameTitleLabel,gameBtn); VBox.setLayoutX(getxPos()); VBox.setLayoutY(getyPos()); -// gameVBox.setMouseTransparent(false); gamesAnchorPane.getChildren().add(VBox); - -// gamesAnchorPane.getChildren().add(gameBtn); } @@ -595,6 +631,7 @@ public class MainWindowController { private void applyColor(){ String style = "-fx-background-color: #"+getColor()+";"; String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #"+getColor()+"; -fx-text-fill: BLACK;"; + String timeBtnStyle = "-fx-button-type: RAISED; -fx-background-color: #ffffff; -fx-text-fill: BLACK;"; getColor(); sideMenuVBox.setStyle(style); @@ -609,10 +646,13 @@ public class MainWindowController { romTFBtn.setStyle(btnStyleBlack); aboutBtn.setStyle(btnStyleBlack); playBtn.setStyle(btnStyleBlack); + + lastTimePlayedBtn.setStyle(timeBtnStyle); + timePlayedBtn.setStyle(timeBtnStyle); } void saveSettings(){ - System.out.println("saving Settings ..."); + System.out.print("saving Settings... "); OutputStream outputStream; //new output-stream try { props.setProperty("cemuPath", getCemuPath()); @@ -636,7 +676,7 @@ public class MainWindowController { } void loadSettings(){ - System.out.print("loading settings ..."); + System.out.print("loading settings... "); InputStream inputStream; try { if(System.getProperty("os.name").equals("Linux")){ @@ -709,6 +749,38 @@ public class MainWindowController { translateTransition.play(); } + @SuppressWarnings("unused") + private void timePlayedBtnSlideIn(){ + timePlayedBtn.setVisible(true); + TranslateTransition translateTransition = new TranslateTransition(Duration.millis(300), timePlayedBtn); + translateTransition.setFromY(55); + translateTransition.setToY(0); + translateTransition.play(); + } + + @SuppressWarnings("unused") + private void timePlayedBtnSlideOut(){ + TranslateTransition translateTransition = new TranslateTransition(Duration.millis(300), timePlayedBtn); + translateTransition.setFromY(0); + translateTransition.setToY(56); + translateTransition.play(); + } + + private void lastTimePlayedBtnSlideIn(){ + lastTimePlayedBtn.setVisible(true); + TranslateTransition translateTransition = new TranslateTransition(Duration.millis(300), lastTimePlayedBtn); + translateTransition.setFromY(55); + translateTransition.setToY(0); + translateTransition.play(); + } + + private void lastTimePlayedBtnSlideOut(){ + TranslateTransition translateTransition = new TranslateTransition(Duration.millis(300), lastTimePlayedBtn); + translateTransition.setFromY(0); + translateTransition.setToY(56); + translateTransition.play(); + } + private void editColor(String input){ StringBuilder sb = new StringBuilder(input); sb.delete(0, 2); diff --git a/src/application/dbController.java b/src/application/dbController.java index 414705a..6241dcd 100644 --- a/src/application/dbController.java +++ b/src/application/dbController.java @@ -39,6 +39,7 @@ public class dbController { loadGamesDatabase(); createRomDatabase(); loadRomDirectory(mainWindowController.getRomPath()); + loadRoms(); checkRemoveEntry(); System.out.println("<==========finished loading sql==========>"); } @@ -57,7 +58,7 @@ public class dbController { // if the error message is "out of memory", it probably means no database file is found System.err.println(e.getMessage()); } - System.out.println("rom database loaded to driver manager"); + System.out.println("rom database loaded successfull"); } /**