added a resize option

* if the window is resized and ther is enough space for a new column, the UI will be adapt to fit the new size
This commit is contained in:
Jannik 2017-09-12 19:45:39 +02:00
parent 0124a5b1a4
commit 78791bb7e1
18 changed files with 77 additions and 49 deletions

Binary file not shown.

View File

@ -16,7 +16,7 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?> <?import javafx.scene.text.TextFlow?>
<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"> <AnchorPane fx:id="mainAnchorPane" 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> <children>
<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"> <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> <content>
@ -105,13 +105,13 @@
</font> </font>
</Label> </Label>
</children></AnchorPane> </children></AnchorPane>
<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"> <JFXButton fx:id="playBtn" buttonType="RAISED" layoutX="396.0" maxHeight="28.0" minWidth="100.0" onAction="#playBtnAction" ripplerFill="#00aacc" text="play" textAlignment="CENTER" visible="false" AnchorPane.bottomAnchor="12.0">
<font> <font>
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />
</font> </font>
</JFXButton> </JFXButton>
<JFXButton fx:id="totalPlaytimeBtn" buttonType="RAISED" maxHeight="32.0" minWidth="100.0" onAction="#totalPlaytimeBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="516.5" AnchorPane.topAnchor="558.0"> <JFXButton fx:id="totalPlaytimeBtn" buttonType="RAISED" layoutX="275.5" maxHeight="32.0" minWidth="100.0" onAction="#totalPlaytimeBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" text="0 h 0 min" visible="false" AnchorPane.bottomAnchor="10.0">
</JFXButton> </JFXButton>
<JFXButton fx:id="lastTimePlayedBtn" buttonType="RAISED" maxHeight="32.0" minWidth="100.0" onAction="#lastTimePlayedBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="516.5" AnchorPane.topAnchor="558.0" /> <JFXButton fx:id="lastTimePlayedBtn" buttonType="RAISED" layoutX="516.5" maxHeight="32.0" minWidth="100.0" onAction="#lastTimePlayedBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" text="Last played, never" visible="false" AnchorPane.bottomAnchor="10.0" />
</children> </children>
</AnchorPane> </AnchorPane>

View File

@ -20,10 +20,11 @@ import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.util.Optional; import java.util.Optional;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import javafx.application.Application; import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.stage.DirectoryChooser; import javafx.stage.DirectoryChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -56,6 +57,7 @@ public class Main extends Application {
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
cloudController = new CloudController(this); cloudController = new CloudController(this);
initActions();
mainWindow(); mainWindow();
} }
@ -63,7 +65,7 @@ public class Main extends Application {
try { try {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml")); FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml"));
pane = loader.load(); pane = loader.load();
primaryStage.setResizable(false); // primaryStage.setResizable(false);
primaryStage.setTitle("cemu_UI"); primaryStage.setTitle("cemu_UI");
// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon // primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon
@ -114,7 +116,7 @@ public class Main extends Application {
mainWindowController.setxPosHelper(0); mainWindowController.setxPosHelper(0);
mainWindowController.saveSettings(); mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs) Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itselfdownloading games.db... System.exit(0); //finishes itself
} }
if(pictureCache.exists() != true){ if(pictureCache.exists() != true){
@ -187,6 +189,19 @@ public class Main extends Application {
} }
} }
private void initActions() {
final ChangeListener<Number> listener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, final Number newValue) {
mainWindowController.refreshUIData();
mainWindowController.refreshplayBtnPosition();
}
};
//add listener to primaryStage
primaryStage.widthProperty().addListener(listener);
}
public static void main(String[] args) { public static void main(String[] args) {
//delete old log file and create new //delete old log file and create new
if(System.getProperty("os.name").equals("Linux")){ if(System.getProperty("os.name").equals("Linux")){

View File

@ -16,7 +16,7 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?> <?import javafx.scene.text.TextFlow?>
<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"> <AnchorPane fx:id="mainAnchorPane" 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> <children>
<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"> <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> <content>
@ -105,13 +105,13 @@
</font> </font>
</Label> </Label>
</children></AnchorPane> </children></AnchorPane>
<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"> <JFXButton fx:id="playBtn" buttonType="RAISED" layoutX="396.0" maxHeight="28.0" minWidth="100.0" onAction="#playBtnAction" ripplerFill="#00aacc" text="play" textAlignment="CENTER" visible="false" AnchorPane.bottomAnchor="12.0">
<font> <font>
<Font name="System Bold" size="14.0" /> <Font name="System Bold" size="14.0" />
</font> </font>
</JFXButton> </JFXButton>
<JFXButton fx:id="totalPlaytimeBtn" buttonType="RAISED" maxHeight="32.0" minWidth="100.0" onAction="#totalPlaytimeBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="516.5" AnchorPane.topAnchor="558.0"> <JFXButton fx:id="totalPlaytimeBtn" buttonType="RAISED" layoutX="275.5" maxHeight="32.0" minWidth="100.0" onAction="#totalPlaytimeBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" text="0 h 0 min" visible="false" AnchorPane.bottomAnchor="10.0">
</JFXButton> </JFXButton>
<JFXButton fx:id="lastTimePlayedBtn" buttonType="RAISED" maxHeight="32.0" minWidth="100.0" onAction="#lastTimePlayedBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" visible="false" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="516.5" AnchorPane.topAnchor="558.0" /> <JFXButton fx:id="lastTimePlayedBtn" buttonType="RAISED" layoutX="516.5" maxHeight="32.0" minWidth="100.0" onAction="#lastTimePlayedBtnAction" prefHeight="32.0" style="-fx-background-color: #ffffff; -fx-button-type: RAISED; -fx-text-fill: BLACK;" text="Last played, never" visible="false" AnchorPane.bottomAnchor="10.0" />
</children> </children>
</AnchorPane> </AnchorPane>

View File

@ -34,7 +34,6 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
import java.util.Properties; import java.util.Properties;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.ProgressMonitor; import javax.swing.ProgressMonitor;
import javax.swing.ProgressMonitorInputStream; import javax.swing.ProgressMonitorInputStream;
@ -162,6 +161,9 @@ public class MainWindowController {
@FXML @FXML
private AnchorPane gamesAnchorPane; private AnchorPane gamesAnchorPane;
@FXML
private AnchorPane mainAnchorPane;
@FXML @FXML
private ScrollPane scrollPaneMain; private ScrollPane scrollPaneMain;
@ -219,7 +221,7 @@ public class MainWindowController {
private String selectedGameTitle; private String selectedGameTitle;
private String id; private String id;
private String version = "0.1.7"; private String version = "0.1.7";
private String buildNumber = "039"; private String buildNumber = "041";
private String versionName = "Throwback Galaxy"; private String versionName = "Throwback Galaxy";
private int xPos = -200; private int xPos = -200;
private int yPos = 17; private int yPos = 17;
@ -300,7 +302,7 @@ public class MainWindowController {
* initialize all actions not initialized by a own method * initialize all actions not initialized by a own method
*/ */
void initActions() { void initActions() {
LOGGER.info("initializing Actions... "); LOGGER.info("initializing Actions ...");
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam); HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{ menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
@ -373,28 +375,14 @@ public class MainWindowController {
Optional<ButtonType> result = alert.showAndWait(); Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){ if (result.get() == ButtonType.OK){
try { try {
//remove all elements from gamesAnchorPane //remove game from database
for(int i=0; i< games.size(); i++){
gamesAnchorPane.getChildren().remove(games.get(i).getVBox());
}
//remove game from database
games.remove(selectedUIDataIndex); games.remove(selectedUIDataIndex);
dbController.removeRom(selectedGameTitleID); dbController.removeRom(selectedGameTitleID);
//remove all games form gamesAnchorPane (UI)
gamesAnchorPane.getChildren().removeAll(gamesAnchorPane.getChildren()); //refresh all games at gamesAnchorPane (UI)
//reset position refreshUIData();
xPos = -200;
yPos = 17;
xPosHelper = 0;
//add all games to gamesAnchorPane (UI)
for(int i=0; i< games.size(); i++){
generatePosition();
games.get(i).getVBox().setLayoutX(getxPos());
games.get(i).getVBox().setLayoutY(getyPos());
gamesAnchorPane.getChildren().add(games.get(i).getVBox());
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); LOGGER.error("error!",e);
} }
} }
} }
@ -958,7 +946,7 @@ public class MainWindowController {
} }
/** /**
* add game to the program and initialize all needed actions (start, time stamps, titleID) * add game to games(ArrayList) and initialize all needed actions (start, time stamps, titleID)
* @param title : game title * @param title : game title
* @param coverPath : path to cover (cache) * @param coverPath : path to cover (cache)
* @param romPath : path to rom file (.rpx) * @param romPath : path to rom file (.rpx)
@ -990,7 +978,6 @@ public class MainWindowController {
@Override @Override
public void handle(MouseEvent event) { public void handle(MouseEvent event) {
LOGGER.info("selected: "+title+"; ID: "+titleID); LOGGER.info("selected: "+title+"; ID: "+titleID);
//getting the selected game index by comparing event.getSource() with games.get(i).getButton() //getting the selected game index by comparing event.getSource() with games.get(i).getButton()
for(int i=0; i<games.size(); i++){ for(int i=0; i<games.size(); i++){
if(games.get(i).getButton() == event.getSource()){ if(games.get(i).getButton() == event.getSource()){
@ -1007,7 +994,7 @@ public class MainWindowController {
games.get(selectedUIDataIndex).getLabel().setStyle("-fx-underline: true;"); games.get(selectedUIDataIndex).getLabel().setStyle("-fx-underline: true;");
lastGameLabel = games.get(selectedUIDataIndex).getLabel(); lastGameLabel = games.get(selectedUIDataIndex).getLabel();
//setting last played //setting last played, if lastPlayed is empty game was never played before, else set correct date
if(dbController.getLastPlayed(titleID).equals("") || dbController.getLastPlayed(titleID).equals(null)){ if(dbController.getLastPlayed(titleID).equals("") || dbController.getLastPlayed(titleID).equals(null)){
lastTimePlayedBtn.setText("Last played, never"); lastTimePlayedBtn.setText("Last played, never");
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min"); totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min");
@ -1016,22 +1003,24 @@ public class MainWindowController {
int today = Integer.parseInt(dtf.format(LocalDate.now()).replaceAll("-", "")); int today = Integer.parseInt(dtf.format(LocalDate.now()).replaceAll("-", ""));
int yesterday = Integer.parseInt(dtf.format(LocalDate.now().minusDays(1)).replaceAll("-", "")); int yesterday = Integer.parseInt(dtf.format(LocalDate.now().minusDays(1)).replaceAll("-", ""));
int lastday = Integer.parseInt(dbController.getLastPlayed(titleID).replaceAll("-", "")); int lastPlayedDay = Integer.parseInt(dbController.getLastPlayed(titleID).replaceAll("-", ""));
if(today == lastday){ if(today == lastPlayedDay){
lastTimePlayedBtn.setText("Last played, today"); lastTimePlayedBtn.setText("Last played, today");
}else if(yesterday == lastday){ }else if(yesterday == lastPlayedDay){
lastTimePlayedBtn.setText("Last played, yesterday"); lastTimePlayedBtn.setText("Last played, yesterday");
}else{ }else{
lastTimePlayedBtn.setText("Last played, "+dbController.getLastPlayed(titleID)); lastTimePlayedBtn.setText("Last played, "+dbController.getLastPlayed(titleID));
} }
if(Integer.parseInt(dbController.getTotalPlaytime(titleID)) > 60){ }
int hoursPlayed = (int) Math.floor(Integer.parseInt(dbController.getTotalPlaytime(titleID))/60);
int minutesPlayed = Integer.parseInt(dbController.getTotalPlaytime(titleID))-60*hoursPlayed; //setting total playtime, if total playtime > 60 minutes, formate is "x hours x minutes" (xh x min), else only minutes are showed
totalPlaytimeBtn.setText(hoursPlayed+"h "+minutesPlayed+"min"); if(Integer.parseInt(dbController.getTotalPlaytime(titleID)) > 60){
}else{ int hoursPlayed = (int) Math.floor(Integer.parseInt(dbController.getTotalPlaytime(titleID))/60);
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min"); int minutesPlayed = Integer.parseInt(dbController.getTotalPlaytime(titleID))-60*hoursPlayed;
} totalPlaytimeBtn.setText(hoursPlayed+" h "+minutesPlayed+" min");
}else{
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min");
} }
if (!playTrue) { if (!playTrue) {
@ -1046,13 +1035,38 @@ public class MainWindowController {
games.add(new UIROMDataType(VBox, gameTitleLabel, gameBtn, titleID, romPath)); games.add(new UIROMDataType(VBox, gameTitleLabel, gameBtn, titleID, romPath));
} }
//add all games to the UI (only called on startup) //add all games saved in games(ArrayList) to the gamesAnchorPane
void addUIData(){ void addUIData() {
for(int i=0; i<games.size(); i++){ for(int i=0; i<games.size(); i++){
gamesAnchorPane.getChildren().add(games.get(i).getVBox()); gamesAnchorPane.getChildren().add(games.get(i).getVBox());
} }
} }
//remove all games from gamesAnchorPane and add them afterwards
void refreshUIData() {
//remove all games form gamesAnchorPane
gamesAnchorPane.getChildren().removeAll(gamesAnchorPane.getChildren());
//reset position
xPos = -200;
yPos = 17;
xPosHelper = 0;
//add all games to gamesAnchorPane (UI)
for(int i=0; i< games.size(); i++){
generatePosition();
games.get(i).getVBox().setLayoutX(getxPos());
games.get(i).getVBox().setLayoutY(getyPos());
gamesAnchorPane.getChildren().add(games.get(i).getVBox());
}
}
void refreshplayBtnPosition() {
playBtn.setLayoutX((mainAnchorPane.getWidth()/2)-50);
totalPlaytimeBtn.setLayoutX((mainAnchorPane.getWidth()/2)-50-20.5-100);
lastTimePlayedBtn.setLayoutX((mainAnchorPane.getWidth()/2)+50+20.5);
}
private void addCourseDescription(SmmdbApiDataType course) { private void addCourseDescription(SmmdbApiDataType course) {
String courseTheme; String courseTheme;
String gameStyle; String gameStyle;
@ -1173,7 +1187,6 @@ public class MainWindowController {
} }
//TODO Changelistener for resizing
/** /**
* xPosHelper based on window width = -24(Windows)/-36(Linux) * xPosHelper based on window width = -24(Windows)/-36(Linux)
* calculates how many games can be displayed in one row * calculates how many games can be displayed in one row