Skip to content

Commit

Permalink
ITS ALIVE .... and its working :)
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel <[email protected]>
  • Loading branch information
Manuel authored and Arcadianer committed Apr 9, 2018
1 parent 41aa805 commit bcecf2a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
5 changes: 2 additions & 3 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 57 additions & 8 deletions src/core/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
import javafx.fxml.FXML;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;

import javax.swing.*;
import java.io.*;
import java.text.SimpleDateFormat;

public class Controller {
@FXML
@FXML
private ChoiceBox save_select;
@FXML

@FXML
private ChoiceBox load_select;

@FXML
private Label savelabel;


private File save_file;
private File load_file;
private File[] sandbox_saves_hinterland;
private File[] sandbox_saves_local;

Expand All @@ -46,14 +51,16 @@ public boolean accept(File dir, String name) {
Platform.runLater(new Runnable() {
@Override
public void run() {
for (File file: sandbox_saves_hinterland) {
save_select.getItems().add(file.getName()+" (game)");
if (sandbox_saves_hinterland != null) {
for (File file : sandbox_saves_hinterland) {
save_select.getItems().add(file.getName() + " (game)");
}
}

save_select.getItems().add(new Separator());

if (sandbox_saves_local != null) {
for (File file: sandbox_saves_local) {
save_select.getItems().add(file.getName()+" (backup)");
load_select.getItems().add(file.getName() + " (backup)");
}
}
save_select.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
Expand All @@ -64,6 +71,15 @@ public void changed(ObservableValue<? extends Number> observable, Number oldValu
savelabel.setText(simpleDateFormat.format(save_file.lastModified()));
}
});
load_select.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println(newValue);
load_file = sandbox_saves_local[(int) newValue];
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
savelabel.setText(simpleDateFormat.format(load_file.lastModified()));
}
});
}

});
Expand All @@ -73,6 +89,7 @@ public void changed(ObservableValue<? extends Number> observable, Number oldValu
private static void copyFileUsingStream(File source, File dest) throws IOException {
InputStream is = null;
OutputStream os = null;

try {
is = new FileInputStream(source);
os = new FileOutputStream(dest);
Expand All @@ -87,4 +104,36 @@ private static void copyFileUsingStream(File source, File dest) throws IOExcepti
}
}

@FXML
private void load() {
if (load_file != null) {
try {
File dest = new File(System.getProperty("user.home") + "\\AppData\\Local\\Hinterland\\TheLongDark\\" + load_file.getName());
copyFileUsingStream(load_file, dest);
JOptionPane.showMessageDialog(null, "Save Loaded");

} catch (IOException e) {
e.printStackTrace();
}

}

}

@FXML
private void save() {
if (save_file != null) {
try {
File dest = new File("saves\\" + save_file.getName());
copyFileUsingStream(save_file, dest);
JOptionPane.showMessageDialog(null, "Games Saved");

} catch (IOException e) {
e.printStackTrace();
}

}

}

}
2 changes: 1 addition & 1 deletion src/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("main_screen.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setTitle("Saver");
Scene mainscreen=new Scene(root);
primaryStage.setScene(mainscreen);
primaryStage.show();
Expand Down
17 changes: 8 additions & 9 deletions src/core/main_screen.fxml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane fx:id="save_label" alignment="center" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="core.Controller">
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" />
Expand All @@ -19,12 +14,16 @@
<ColumnConstraints minWidth="10.0" prefWidth="69.0" />
</columnConstraints>
<children>
<Button alignment="CENTER" mnemonicParsing="false" text="Save Load" GridPane.halignment="CENTER" />
<Button alignment="CENTER" mnemonicParsing="false" text="Restore Load" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<Button fx:id="load_button" alignment="CENTER" mnemonicParsing="false" onAction="#save" text="Save Load"
GridPane.halignment="CENTER"/>
<Button alignment="CENTER" mnemonicParsing="false" onAction="#load" text="Restore Load"
GridPane.halignment="CENTER" GridPane.rowIndex="1">
<GridPane.margin>
<Insets />
</GridPane.margin></Button>
<Label fx:id="savelabel" alignment="CENTER" prefHeight="17.0" prefWidth="111.0" text="&lt;No File&gt;" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
<ChoiceBox fx:id="save_select" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="82.0" GridPane.columnIndex="1" />
<ChoiceBox fx:id="load_select" layoutX="151.0" layoutY="13.0" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="25.0" prefWidth="82.0" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
</children>
</GridPane>

0 comments on commit bcecf2a

Please sign in to comment.