dialog rework and mor license shipping work

* update/add DLC are now JFXDilaog styled
* added MIT license
This commit is contained in:
Jannik 2017-11-22 23:30:20 +01:00
parent 15196718c5
commit ba9fd1bb32
3 changed files with 98 additions and 106 deletions

View File

@ -474,54 +474,62 @@ public class MainWindowController {
addUpdate.setOnAction(new EventHandler<ActionEvent>() { addUpdate.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
String titleID = selectedGameTitleID;
String updatePath;
LOGGER.info("update: "+selectedGameTitleID); LOGGER.info("update: "+selectedGameTitleID);
if (selectedGameTitleID == null) { if (selectedGameTitleID == null) {
LOGGER.warn("trying to update null! null is not valid!"); LOGGER.warn("trying to update null! null is not valid!");
String headingText = "update game"; String headingText = "update game";
String bodyText = "please select a game, \""+selectedGameTitleID+"\" is not a valid type!"; String bodyText = "please select a game,\n"
JFXInfoDialog aboutDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane); + "\""+selectedGameTitleID+"\" is not a valid type!";
aboutDialog.show(); JFXInfoDialog updateGameErrorDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane);
updateGameErrorDialog.show();
} else { } else {
Alert updateAlert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser String headingText = "update \"" + selectedGameTitle + "\"";
updateAlert.setTitle("cemu_UI"); String bodyText = "pleas select the update root directory";
updateAlert.setHeaderText("update "+selectedGameTitle); EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){
updateAlert.setContentText("pleas select the update root directory"); @Override
updateAlert.initOwner(main.primaryStage); public void handle(ActionEvent event){
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirecroty = directoryChooser.showDialog(main.primaryStage);
String updatePath = selectedDirecroty.getAbsolutePath();
String[] parts = selectedGameTitleID.split("-"); //split string into 2 parts at "-"
File srcDir = new File(updatePath);
File destDir;
if (System.getProperty("os.name").equals("Linux")) {
destDir = new File(cemuPath+"/mlc01/usr/title/"+parts[0]+"/"+parts[1]);
} else {
destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]);
}
// if directory doesn't exist create it
if (destDir.exists() != true) {
destDir.mkdir();
}
Optional<ButtonType> result = updateAlert.showAndWait(); try {
if (result.get() == ButtonType.OK) { LOGGER.info("copying the content of " + updatePath + " to " + destDir.toString());
DirectoryChooser directoryChooser = new DirectoryChooser(); playBtn.setText("updating...");
File selectedDirecroty = directoryChooser.showDialog(main.primaryStage); playBtn.setDisable(true);
updatePath = selectedDirecroty.getAbsolutePath(); FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator
String[] parts = titleID.split("-"); //split string into 2 parts at "-" playBtn.setText("play");
playBtn.setDisable(false);
File srcDir = new File(updatePath); LOGGER.info("copying files done!");
File destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]); } catch (IOException e) {
e.printStackTrace();
LOGGER.info(updatePath); }
LOGGER.info(destDir.toString());
if (destDir.exists() != true) {
destDir.mkdir();
} }
};
try {
LOGGER.info("copying files..."); EventHandler<ActionEvent> cancelAction = new EventHandler<ActionEvent>() {
playBtn.setText("updating..."); @Override
playBtn.setDisable(true); public void handle(ActionEvent event) {
FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator
playBtn.setText("play");
playBtn.setDisable(false);
LOGGER.info("copying files done!");
} catch (IOException e) {
e.printStackTrace();
} }
} else { };
updatePath = null;
} JFXOkayCancelDialog updateGameDialog = new JFXOkayCancelDialog(headingText, bodyText,
dialogBtnStyle, 350, 170, okayAction, cancelAction, main.pane);
updateGameDialog.show();
} }
} }
}); });
@ -529,20 +537,17 @@ public class MainWindowController {
addDLC.setOnAction(new EventHandler<ActionEvent>() { addDLC.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
String titleID = selectedGameTitleID;
String dlcPath;
LOGGER.info("add DLC: "+selectedGameTitleID); LOGGER.info("add DLC: "+selectedGameTitleID);
if (selectedGameTitleID == null) { if (selectedGameTitleID == null) {
LOGGER.warn("trying to add a dlc to null! null is not valid!"); LOGGER.warn("trying to add a dlc to null! null is not valid!");
String headingText = "add DLC"; String headingText = "add DLC";
String bodyText = "please select a game, \""+selectedGameTitleID+"\" is not a valid type!"; String bodyText = "please select a game,\n"
JFXInfoDialog aboutDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane); // TODO check if we can use a lower heigth + "\"" + selectedGameTitleID + "\" is not a valid type!";
aboutDialog.show(); JFXInfoDialog addDLCErrorDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane);
} else { addDLCErrorDialog.show();
//TESTING TODO if this works we can use this for update too } else {
String headingText = "add a DLC to \"+selectedGameTitle"; String headingText = "add a DLC to \"" + selectedGameTitle + "\"";
String bodyText = "pleas select the DLC root directory"; String bodyText = "pleas select the DLC root directory";
EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){ EventHandler<ActionEvent> okayAction = new EventHandler<ActionEvent>(){
@Override @Override
@ -550,20 +555,22 @@ public class MainWindowController {
DirectoryChooser directoryChooser = new DirectoryChooser(); DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirecroty = directoryChooser.showDialog(main.primaryStage); File selectedDirecroty = directoryChooser.showDialog(main.primaryStage);
String dlcPath = selectedDirecroty.getAbsolutePath(); String dlcPath = selectedDirecroty.getAbsolutePath();
String[] parts = titleID.split("-"); //split string into 2 parts at "-" String[] parts = selectedGameTitleID.split("-"); //split string into 2 parts at "-"
File srcDir = new File(dlcPath); File srcDir = new File(dlcPath);
File destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]+"\\aoc"); File destDir;
if (System.getProperty("os.name").equals("Linux")) {
destDir = new File(cemuPath+"/mlc01/usr/title/"+parts[0]+"/"+parts[1]+"/aoc");
} else {
destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]+"\\aoc");
}
LOGGER.info(dlcPath); // if directory doesn't exist create it
LOGGER.info(destDir.toString());
if (destDir.exists() != true) { if (destDir.exists() != true) {
destDir.mkdir(); destDir.mkdir();
} }
try { try {
LOGGER.info("copying files..."); LOGGER.info("copying the content of " + dlcPath + " to " + destDir.toString());
playBtn.setText("copying files..."); playBtn.setText("copying files...");
playBtn.setDisable(true); playBtn.setDisable(true);
FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator
@ -576,48 +583,16 @@ public class MainWindowController {
} }
}; };
JFXOkayCancelDialog updateGameDialog = new JFXOkayCancelDialog(headingText, bodyText, dialogBtnStyle, 350, 170, main.pane); EventHandler<ActionEvent> cancelAction = new EventHandler<ActionEvent>() {
updateGameDialog.setOkayAction(okayAction); @Override
public void handle(ActionEvent event) {
// old dilaog (if testing works we can remove this)
Alert updateAlert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
updateAlert.setTitle("cemu_UI");
updateAlert.setHeaderText("add a DLC to "+selectedGameTitle);
updateAlert.setContentText("pleas select the DLC root directory");
updateAlert.initOwner(main.primaryStage);
Optional<ButtonType> result = updateAlert.showAndWait();
if (result.get() == ButtonType.OK) {
DirectoryChooser directoryChooser = new DirectoryChooser();
File selectedDirecroty = directoryChooser.showDialog(main.primaryStage);
dlcPath = selectedDirecroty.getAbsolutePath();
String[] parts = titleID.split("-"); //split string into 2 parts at "-"
File srcDir = new File(dlcPath);
File destDir = new File(cemuPath+"\\mlc01\\usr\\title\\"+parts[0]+"\\"+parts[1]+"\\aoc");
LOGGER.info(dlcPath);
LOGGER.info(destDir.toString());
if (destDir.exists() != true) {
destDir.mkdir();
}
try {
LOGGER.info("copying files...");
playBtn.setText("copying files...");
playBtn.setDisable(true);
FileUtils.copyDirectory(srcDir, destDir); //TODO progress indicator
playBtn.setText("play");
playBtn.setDisable(false);
LOGGER.info("copying files done!");
} catch (IOException e) {
e.printStackTrace();
} }
} else { };
dlcPath = null;
} JFXOkayCancelDialog addDLCDialog = new JFXOkayCancelDialog(headingText, bodyText,
dialogBtnStyle, 350, 170, okayAction, cancelAction, main.pane);
addDLCDialog.show();
} }
} }
}); });
@ -975,9 +950,7 @@ public class MainWindowController {
}; };
JFXOkayCancelDialog cloudSyncErrorDialog = new JFXOkayCancelDialog(headingText, bodyText, dialogBtnStyle, JFXOkayCancelDialog cloudSyncErrorDialog = new JFXOkayCancelDialog(headingText, bodyText, dialogBtnStyle,
419, 140, main.pane); 419, 140, okayAction, cancelAction, main.pane);
cloudSyncErrorDialog.setOkayAction(okayAction);
cloudSyncErrorDialog.setCancelAction(cancelAction);
cloudSyncErrorDialog.show(); cloudSyncErrorDialog.show();
} }
} }

View File

@ -41,8 +41,8 @@ public class JFXOkayCancelDialog {
private String dialogBtnStyle; private String dialogBtnStyle;
private int dialogWidth; private int dialogWidth;
private int dialogHeight; private int dialogHeight;
private EventHandler<ActionEvent> okayAction = null; private EventHandler<ActionEvent> okayAction;
private EventHandler<ActionEvent> cancelAction = null; private EventHandler<ActionEvent> cancelAction;
private Pane pane; private Pane pane;
/** /**
@ -57,14 +57,14 @@ public class JFXOkayCancelDialog {
* @param pane pane to which the dialog belongs * @param pane pane to which the dialog belongs
*/ */
public JFXOkayCancelDialog(String headingText, String bodyText, String dialogBtnStyle, int dialogWidth, public JFXOkayCancelDialog(String headingText, String bodyText, String dialogBtnStyle, int dialogWidth,
int dialogHeight, Pane pane) { int dialogHeight, EventHandler<ActionEvent> okayAction, EventHandler<ActionEvent> cancelAction, Pane pane) {
this.headingText = headingText; this.headingText = headingText;
this.bodyText = bodyText; this.bodyText = bodyText;
this.dialogBtnStyle = dialogBtnStyle; this.dialogBtnStyle = dialogBtnStyle;
this.dialogWidth = dialogWidth; this.dialogWidth = dialogWidth;
this.dialogHeight = dialogHeight; this.dialogHeight = dialogHeight;
// this.okayAction = okayAction; this.okayAction = okayAction;
// this.cancelAction = cancelAction; this.cancelAction = cancelAction;
this.pane = pane; this.pane = pane;
} }

View File

@ -0,0 +1,19 @@
Copyright (c) 2013, 2014 EclipseSource
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.