code clean up

This commit is contained in:
Seil0 2017-03-23 16:17:38 +01:00
parent ba2f4123db
commit fab1d2d062
15 changed files with 180 additions and 75 deletions

Binary file not shown.

View File

@ -14,7 +14,7 @@
<AnchorPane prefHeight="600.0" prefWidth="892.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainWindowController">
<children>
<ScrollPane fx:id="scrollPaneMain" fitToWidth="true" layoutY="38.0" prefHeight="562.0" prefWidth="893.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<ScrollPane fx:id="scrollPaneMain" fitToWidth="true" layoutY="38.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<content>
<AnchorPane fx:id="gamesAnchorPane">
<padding>
@ -22,7 +22,7 @@
</padding></AnchorPane>
</content>
</ScrollPane>
<HBox fx:id="topHBox" prefHeight="38.0" prefWidth="900.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox fx:id="topHBox" prefHeight="38.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<JFXHamburger fx:id="menuHam" prefHeight="38.0" prefWidth="38.0" />
</children>
@ -54,10 +54,16 @@
<JFXColorPicker fx:id="colorPicker" layoutX="14.0" layoutY="89.0" onAction="#colorPickerAction" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="89.0" />
<JFXToggleButton fx:id="fullscreenToggleBtn" layoutX="14.0" layoutY="125.0" onAction="#fullscreenToggleBtnAction" text="start game in fullscreen" />
</children></AnchorPane>
<JFXButton fx:id="playBtn" buttonType="RAISED" layoutX="392.5" layoutY="555.0" onAction="#playBtnAction" prefHeight="38.0" prefWidth="100.0" ripplerFill="#c92a2a" text="play" visible="false" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="392.5" AnchorPane.rightAnchor="392.5" AnchorPane.topAnchor="555.0">
<JFXButton fx:id="playBtn" buttonType="RAISED" maxHeight="38.0" maxWidth="100.0" onAction="#playBtnAction" ripplerFill="#c92a2a" text="play" visible="false" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="396.0" AnchorPane.rightAnchor="396.0" AnchorPane.topAnchor="555.0">
<font>
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="timePlayedBtn" buttonType="RAISED" layoutX="341.0" layoutY="588.0" onAction="#timePlayedBtnAction" prefHeight="32.0" prefWidth="100.0" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="516.5" AnchorPane.topAnchor="558.0">
<font>
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="lastTimePlayedBtn" buttonType="RAISED" maxHeight="32.0" onAction="#lastTimePlayedBtnAction" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="516.5" AnchorPane.topAnchor="558.0" />
</children>
</AnchorPane>

Binary file not shown.

View File

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

View File

@ -14,7 +14,7 @@
<AnchorPane prefHeight="600.0" prefWidth="892.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainWindowController">
<children>
<ScrollPane fx:id="scrollPaneMain" fitToWidth="true" layoutY="38.0" prefHeight="562.0" prefWidth="893.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<ScrollPane fx:id="scrollPaneMain" fitToWidth="true" layoutY="38.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<content>
<AnchorPane fx:id="gamesAnchorPane">
<padding>
@ -22,7 +22,7 @@
</padding></AnchorPane>
</content>
</ScrollPane>
<HBox fx:id="topHBox" prefHeight="38.0" prefWidth="900.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox fx:id="topHBox" prefHeight="38.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<JFXHamburger fx:id="menuHam" prefHeight="38.0" prefWidth="38.0" />
</children>
@ -54,10 +54,16 @@
<JFXColorPicker fx:id="colorPicker" layoutX="14.0" layoutY="89.0" onAction="#colorPickerAction" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="89.0" />
<JFXToggleButton fx:id="fullscreenToggleBtn" layoutX="14.0" layoutY="125.0" onAction="#fullscreenToggleBtnAction" text="start game in fullscreen" />
</children></AnchorPane>
<JFXButton fx:id="playBtn" buttonType="RAISED" layoutX="392.5" layoutY="555.0" onAction="#playBtnAction" prefHeight="38.0" prefWidth="100.0" ripplerFill="#c92a2a" text="play" visible="false" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="392.5" AnchorPane.rightAnchor="392.5" AnchorPane.topAnchor="555.0">
<JFXButton fx:id="playBtn" buttonType="RAISED" maxHeight="38.0" maxWidth="100.0" onAction="#playBtnAction" ripplerFill="#c92a2a" text="play" visible="false" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="396.0" AnchorPane.rightAnchor="396.0" AnchorPane.topAnchor="555.0">
<font>
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="timePlayedBtn" buttonType="RAISED" layoutX="341.0" layoutY="588.0" onAction="#timePlayedBtnAction" prefHeight="32.0" prefWidth="100.0" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="516.5" AnchorPane.topAnchor="558.0">
<font>
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="lastTimePlayedBtn" buttonType="RAISED" maxHeight="32.0" onAction="#lastTimePlayedBtnAction" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="516.5" AnchorPane.topAnchor="558.0" />
</children>
</AnchorPane>

View File

@ -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<ActionEvent>() {
// @Override
// public void handle(ActionEvent event) {
gameBtn.setContextMenu(gameContextMenu);
gameBtn.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@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);

View File

@ -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");
}
/**