added time played in total, code clean up

time played in total, current way is not really nice maybe will be
change in a future update
This commit is contained in:
Seil0 2017-03-25 15:18:45 +01:00
parent fab1d2d062
commit 7bbe781645
13 changed files with 167 additions and 100 deletions

View File

@ -43,6 +43,11 @@
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="reloadRomsBtn" onAction="#reloadRomsBtnAction" prefHeight="38.0" prefWidth="150.0" text="reload roms">
<font>
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
</children>
</VBox>
<AnchorPane fx:id="settingsAnchorPane" layoutX="38.0" layoutY="27.0" prefHeight="573.0" prefWidth="862.0" style="-fx-background-color: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
@ -60,9 +65,6 @@
</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>

Binary file not shown.

View File

@ -43,6 +43,11 @@
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
<JFXButton fx:id="reloadRomsBtn" onAction="#reloadRomsBtnAction" prefHeight="38.0" prefWidth="150.0" text="reload roms">
<font>
<Font name="System Bold" size="14.0" />
</font>
</JFXButton>
</children>
</VBox>
<AnchorPane fx:id="settingsAnchorPane" layoutX="38.0" layoutY="27.0" prefHeight="573.0" prefWidth="862.0" style="-fx-background-color: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
@ -60,9 +65,6 @@
</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>

View File

@ -63,6 +63,9 @@ public class MainWindowController {
@FXML
private JFXButton addBtn;
@FXML
private JFXButton reloadRomsBtn;
@FXML
private JFXButton cemuTFBtn;
@ -148,7 +151,7 @@ public class MainWindowController {
public void setMain(Main main) {
this.main = main;
dbController = new dbController(this);
dbController = new dbController(this);
}
void initUI(){
@ -157,6 +160,7 @@ public class MainWindowController {
colorPicker.setValue(Color.valueOf(getColor()));
fullscreenToggleBtn.setSelected(isFullscreen());
addDLC.setDisable(true);
edit.setDisable(true);
applyColor();
}
@ -167,7 +171,6 @@ public class MainWindowController {
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
if(playTrue){
playBtnSlideOut();
lastTimePlayedBtnSlideOut();
}
if(menuTrue == false){
sideMenuSlideIn();
@ -201,12 +204,7 @@ public class MainWindowController {
alert.initOwner(main.primaryStage);
alert.showAndWait();
}else{
System.out.println("show edit window TODO!");
double i = 13;
double j = 4;
i = i/j;
System.out.println(Math.ceil(i)); //aufrunden
System.out.println(Math.floor(i)); //abrunden
System.out.println("show edit window TODO!"); //TODO
}
}
});
@ -226,14 +224,39 @@ public class MainWindowController {
}
else{
int i = gameCover.indexOf((selectedEvent).getSource());
gameVBox.remove(i);
gameCover.remove(i);
gameLabel.remove(i);
// dbController.removeRom(selectedGameTitleID);
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("remove");
alert.setHeaderText("cemu_UI");
alert.setContentText("Are you sure you want to delete "+selectedGameTitle+" ?");
alert.initOwner(main.primaryStage);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
try {
gameVBox.remove(i);
gameCover.remove(i);
gameLabel.remove(i);
dbController.removeRom(selectedGameTitleID);
gamesAnchorPane.getChildren().remove(i);
//TODO remove if animations are done
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
} catch (SQLException | IOException e) {
e.printStackTrace();
}
}
//TODO nachrück animation
// platz(i)/4 -> aufrunden = Reihe; plath(i)-(platz(i)/4 -> abrunden*4)
// jetzt haben wir den platz des gelöschten elements und lönnen alle nachfolgenden nachrücken
gamesAnchorPane.getChildren().remove(i);
// double a = 13;
// double b = 4;
// a = a/b;
// System.out.println(Math.ceil(a)); //aufrunden
// System.out.println(Math.floor(a)); //abrunden
}
}
});
@ -256,7 +279,7 @@ public class MainWindowController {
Alert updateAlert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
updateAlert.setTitle("cemu_UI");
updateAlert.setHeaderText("update "+selectedGameTitle);
updateAlert.setContentText("pleas select the update directory");
updateAlert.setContentText("pleas select the update root directory");
updateAlert.initOwner(main.primaryStage);
Optional<ButtonType> result = updateAlert.showAndWait();
@ -306,7 +329,6 @@ public class MainWindowController {
public void handle(MouseEvent event) {
if (playTrue) {
playBtnSlideOut();
lastTimePlayedBtnSlideOut();
}
}
});
@ -316,7 +338,6 @@ public class MainWindowController {
public void handle(MouseEvent event) {
if (playTrue) {
playBtnSlideOut();
lastTimePlayedBtnSlideOut();
}
}
});
@ -329,28 +350,13 @@ public class MainWindowController {
}
@FXML
void playBtnAction(ActionEvent event){
dbController.setLastPlayed(selectedGameTitleID);
try{
if(fullscreen){
Runtime.getRuntime().exec(getCemuPath()+"\\Cemu.exe -f -g \""+gameExecutePath+"\"");
}else{
Runtime.getRuntime().exec(getCemuPath()+"\\Cemu.exe -g \""+gameExecutePath+"\"");
}
} catch (IOException e) {
//Auto-generated catch block
e.printStackTrace();
}
}
@FXML
void timePlayedBtnAction(ActionEvent event){
}
@FXML
void lastTimePlayedBtnAction(ActionEvent event){
void aboutBtnAction(){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("about");
alert.setHeaderText("cemu_UI");
alert.setContentText("cemu_UI by @Seil0 \npre release 0.1.1 \nwww.kellerkinder.xyz");
alert.initOwner(main.primaryStage);
alert.showAndWait();
}
@FXML
@ -367,13 +373,57 @@ public class MainWindowController {
}
@FXML
void aboutBtnAction(){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("about");
alert.setHeaderText("cemu_UI");
alert.setContentText("cemu_UI by @Seil0 \npre release 0.1.0 \nwww.kellerkinder.xyz");
alert.initOwner(main.primaryStage);
alert.showAndWait();
void reloadRomsBtnAction() throws IOException{
dbController.loadRomDirectory(getRomPath());
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
}
@FXML
void playBtnAction(ActionEvent event) throws InterruptedException, IOException{
dbController.setLastPlayed(selectedGameTitleID);
long startTime;
long endTime;
int playedTime;
int timePlayed;
Process p;
main.primaryStage.setIconified(true);
startTime = System.currentTimeMillis();
try{
if(fullscreen){
p = Runtime.getRuntime().exec(getCemuPath()+"\\Cemu.exe -f -g \""+gameExecutePath+"\"");
}else{
p = Runtime.getRuntime().exec(getCemuPath()+"\\Cemu.exe -g \""+gameExecutePath+"\"");
}
p.waitFor();
endTime = System.currentTimeMillis();
playedTime = (int) Math.floor(((endTime - startTime)/1000/60));
System.out.println((endTime - startTime)/1000+"; "+(endTime - startTime)/1000/60+"; "+playedTime);
timePlayed = Integer.parseInt(dbController.getTimePlayed(selectedGameTitleID))+playedTime;
System.out.println(timePlayed);
dbController.setTimePlayed(Integer.toString(timePlayed), selectedGameTitleID);
timePlayedBtn.setText(dbController.getTimePlayed(selectedGameTitleID)+ " min");
main.primaryStage.setIconified(false);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
void timePlayedBtnAction(ActionEvent event){
}
@FXML
void lastTimePlayedBtnAction(ActionEvent event){
}
@FXML
@ -483,7 +533,7 @@ public class MainWindowController {
Alert romAlert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
romAlert.setTitle("cemu_UI");
romAlert.setHeaderText("add new Game");
romAlert.setContentText("pleas select the .rpx file from the Game you whish to add");
romAlert.setContentText("Please select the .rpx file from the game you want to add.");
romAlert.initOwner(main.primaryStage);
Optional<ButtonType> result = romAlert.showAndWait();
@ -500,7 +550,7 @@ public class MainWindowController {
Alert coverAlert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
coverAlert.setTitle("cemu_UI");
coverAlert.setHeaderText("add new Game");
coverAlert.setContentText("pleas select the cover for the Game you whish to add");
coverAlert.setContentText("Please select the cover for the game you want to add.");
coverAlert.initOwner(main.primaryStage);
Optional<ButtonType> coverResult = coverAlert.showAndWait();
@ -585,6 +635,7 @@ public class MainWindowController {
if(dbController.getLastPlayed(titleID).equals("") || dbController.getLastPlayed(titleID).equals(null)){
lastTimePlayedBtn.setText("Last played, never");
timePlayedBtn.setText(dbController.getTimePlayed(titleID)+ " min");
}else{
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@ -598,11 +649,12 @@ public class MainWindowController {
}else{
lastTimePlayedBtn.setText("Last played, "+dbController.getLastPlayed(titleID));
}
timePlayedBtn.setText(dbController.getTimePlayed(titleID)+ " min");
}
if(playTrue == false){
playBtnSlideIn(); //TODO anderes design(mehr details spielzeit, etc.)
lastTimePlayedBtnSlideIn();
playBtnSlideIn();
}
}
});
@ -639,12 +691,13 @@ public class MainWindowController {
cemuTextField.setFocusColor(Color.valueOf(getColor()));
romTextField.setFocusColor(Color.valueOf(getColor()));
aboutBtn.setStyle("-fx-text-fill: BLACK;");
settingsBtn.setStyle("-fx-text-fill: BLACK;");
addBtn.setStyle("-fx-text-fill: BLACK;");
reloadRomsBtn.setStyle("-fx-text-fill: BLACK;");
playBtn.setStyle("-fx-text-fill: BLACK;");
cemuTFBtn.setStyle(btnStyleBlack);
romTFBtn.setStyle(btnStyleBlack);
aboutBtn.setStyle(btnStyleBlack);
playBtn.setStyle(btnStyleBlack);
lastTimePlayedBtn.setStyle(timeBtnStyle);
@ -734,51 +787,42 @@ public class MainWindowController {
private void playBtnSlideIn(){
playBtn.setVisible(true);
lastTimePlayedBtn.setVisible(true);
timePlayedBtn.setVisible(true);
playTrue = true;
TranslateTransition translateTransition = new TranslateTransition(Duration.millis(300), playBtn);
translateTransition.setFromY(55);
translateTransition.setToY(0);
translateTransition.play();
TranslateTransition playBtnTransition = new TranslateTransition(Duration.millis(300), playBtn);
playBtnTransition.setFromY(55);
playBtnTransition.setToY(0);
playBtnTransition.play();
TranslateTransition lastTimePlayedBtnTransition = new TranslateTransition(Duration.millis(300), lastTimePlayedBtn);
lastTimePlayedBtnTransition.setFromY(55);
lastTimePlayedBtnTransition.setToY(0);
lastTimePlayedBtnTransition.play();
TranslateTransition timePlayedBtnTransition = new TranslateTransition(Duration.millis(300), timePlayedBtn);
timePlayedBtnTransition.setFromY(55);
timePlayedBtnTransition.setToY(0);
timePlayedBtnTransition.play();
}
private void playBtnSlideOut(){
playTrue = false;
TranslateTransition translateTransition = new TranslateTransition(Duration.millis(300), playBtn);
translateTransition.setFromY(0);
translateTransition.setToY(56);
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();
TranslateTransition playBtnTransition = new TranslateTransition(Duration.millis(300), playBtn);
playBtnTransition.setFromY(0);
playBtnTransition.setToY(56);
playBtnTransition.play();
TranslateTransition lastTimePlayedBtnTransition = new TranslateTransition(Duration.millis(300), lastTimePlayedBtn);
lastTimePlayedBtnTransition.setFromY(0);
lastTimePlayedBtnTransition.setToY(56);
lastTimePlayedBtnTransition.play();
TranslateTransition timePlayedBtnTransition = new TranslateTransition(Duration.millis(300), timePlayedBtn);
timePlayedBtnTransition.setFromY(0);
timePlayedBtnTransition.setToY(56);
timePlayedBtnTransition.play();
}
private void editColor(String input){

View File

@ -10,6 +10,7 @@ import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
@ -28,6 +29,7 @@ public class dbController {
}
private MainWindowController mainWindowController;
private ArrayList<String> entries = new ArrayList<>();
private String DB_PATH;
private String DB_PATH_games;
private Connection connection = null;
@ -38,7 +40,6 @@ public class dbController {
loadRomDatabase();
loadGamesDatabase();
createRomDatabase();
loadRomDirectory(mainWindowController.getRomPath());
loadRoms();
checkRemoveEntry();
System.out.println("<==========finished loading sql==========>");
@ -82,6 +83,7 @@ public class dbController {
System.out.println("games database loaded successfull");
}
//creating database, if db has 0 entries search for all .rpx files in the roms directory and add them
void createRomDatabase() {
try {
Statement stmt = connection.createStatement();
@ -91,6 +93,22 @@ public class dbController {
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM local_roms");
while (rs.next()) {
entries.add(rs.getString(2));
}
stmt.close();
rs.close();
}catch (SQLException ea){
System.err.println("Ups! an error occured!");
ea.printStackTrace();
}
if(entries.size() == 0){
loadRomDirectory(mainWindowController.getRomPath());
}
}
void addRom(String title, String coverPath, String romPath, String titleID, String productCode, String region, String lastPlayed, String timePlayed) throws SQLException{
@ -181,7 +199,7 @@ public class dbController {
ImageIO.write(resizeImagePNG, "png", new File(pictureCache+"\\"+rs.getString(3)+".png")); //change path where you want it saved
coverPath = pictureCache+"\\"+rs.getString(3)+".png";
addRom(rs.getString(2), coverPath, file.getCanonicalPath(), rs.getString(1), rs.getString(3), rs.getString(5),"","");
addRom(rs.getString(2), coverPath, file.getCanonicalPath(), rs.getString(1), rs.getString(3), rs.getString(5),"","0");
}
}
System.out.println("");
@ -244,7 +262,7 @@ public class dbController {
void setTimePlayed(String timePlayed, String titleID){
try{
Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE local_roms SET timePlayed='' WHERE titleID = '"+titleID+"';");
stmt.executeUpdate("UPDATE local_roms SET timePlayed='"+timePlayed+"' WHERE titleID = '"+titleID+"';");
connection.commit();
stmt.close();
}catch(SQLException e){
@ -257,7 +275,7 @@ public class dbController {
try{
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT timePlayed FROM local_roms WHERE titleID = '"+titleID+"';" );
timePlayed = rs.getString(4);
timePlayed = rs.getString(1);
stmt.close();
rs.close();
}catch(SQLException e){
@ -265,5 +283,6 @@ public class dbController {
}
return timePlayed;
}
}