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.
+4 -4
View File
@@ -16,7 +16,7 @@
<?import javafx.scene.text.Font?>
<?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>
<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>
@@ -105,13 +105,13 @@
</font>
</Label>
</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 name="System Bold" size="14.0" />
</font>
</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 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>
</AnchorPane>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+18 -3
View File
@@ -20,10 +20,11 @@ import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
@@ -56,6 +57,7 @@ public class Main extends Application {
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
cloudController = new CloudController(this);
initActions();
mainWindow();
}
@@ -63,7 +65,7 @@ public class Main extends Application {
try {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml"));
pane = loader.load();
primaryStage.setResizable(false);
// primaryStage.setResizable(false);
primaryStage.setTitle("cemu_UI");
// 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.saveSettings();
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){
@@ -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) {
//delete old log file and create new
if(System.getProperty("os.name").equals("Linux")){
+4 -4
View File
@@ -16,7 +16,7 @@
<?import javafx.scene.text.Font?>
<?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>
<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>
@@ -105,13 +105,13 @@
</font>
</Label>
</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 name="System Bold" size="14.0" />
</font>
</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 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>
</AnchorPane>
+51 -38
View File
@@ -34,7 +34,6 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Optional;
import java.util.Properties;
import javax.imageio.ImageIO;
import javax.swing.ProgressMonitor;
import javax.swing.ProgressMonitorInputStream;
@@ -162,6 +161,9 @@ public class MainWindowController {
@FXML
private AnchorPane gamesAnchorPane;
@FXML
private AnchorPane mainAnchorPane;
@FXML
private ScrollPane scrollPaneMain;
@@ -219,7 +221,7 @@ public class MainWindowController {
private String selectedGameTitle;
private String id;
private String version = "0.1.7";
private String buildNumber = "039";
private String buildNumber = "041";
private String versionName = "Throwback Galaxy";
private int xPos = -200;
private int yPos = 17;
@@ -300,7 +302,7 @@ public class MainWindowController {
* initialize all actions not initialized by a own method
*/
void initActions() {
LOGGER.info("initializing Actions... ");
LOGGER.info("initializing Actions ...");
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
@@ -373,28 +375,14 @@ public class MainWindowController {
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
try {
//remove all elements from gamesAnchorPane
for(int i=0; i< games.size(); i++){
gamesAnchorPane.getChildren().remove(games.get(i).getVBox());
}
//remove game from database
//remove game from database
games.remove(selectedUIDataIndex);
dbController.removeRom(selectedGameTitleID);
//remove all games form gamesAnchorPane (UI)
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());
}
//refresh all games at gamesAnchorPane (UI)
refreshUIData();
} 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 coverPath : path to cover (cache)
* @param romPath : path to rom file (.rpx)
@@ -990,7 +978,6 @@ public class MainWindowController {
@Override
public void handle(MouseEvent event) {
LOGGER.info("selected: "+title+"; ID: "+titleID);
//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()){
@@ -1007,7 +994,7 @@ public class MainWindowController {
games.get(selectedUIDataIndex).getLabel().setStyle("-fx-underline: true;");
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)){
lastTimePlayedBtn.setText("Last played, never");
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min");
@@ -1016,22 +1003,24 @@ public class MainWindowController {
int today = Integer.parseInt(dtf.format(LocalDate.now()).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");
}else if(yesterday == lastday){
}else if(yesterday == lastPlayedDay){
lastTimePlayedBtn.setText("Last played, yesterday");
}else{
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;
totalPlaytimeBtn.setText(hoursPlayed+"h "+minutesPlayed+"min");
}else{
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min");
}
}
//setting total playtime, if total playtime > 60 minutes, formate is "x hours x minutes" (xh x min), else only minutes are showed
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;
totalPlaytimeBtn.setText(hoursPlayed+" h "+minutesPlayed+" min");
}else{
totalPlaytimeBtn.setText(dbController.getTotalPlaytime(titleID)+ " min");
}
if (!playTrue) {
@@ -1046,13 +1035,38 @@ public class MainWindowController {
games.add(new UIROMDataType(VBox, gameTitleLabel, gameBtn, titleID, romPath));
}
//add all games to the UI (only called on startup)
void addUIData(){
//add all games saved in games(ArrayList) to the gamesAnchorPane
void addUIData() {
for(int i=0; i<games.size(); i++){
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) {
String courseTheme;
String gameStyle;
@@ -1173,7 +1187,6 @@ public class MainWindowController {
}
//TODO Changelistener for resizing
/**
* xPosHelper based on window width = -24(Windows)/-36(Linux)
* calculates how many games can be displayed in one row