A lot of work on the wiki designer

This commit is contained in:
modmuss50 2016-04-08 15:19:10 +01:00
parent bc7b5b2566
commit 77102819a4
No known key found for this signature in database
GPG key ID: C69B0D76D1E5F55C
8 changed files with 154 additions and 26 deletions

View file

@ -10,6 +10,7 @@ import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import techreborn.manual.designer.fileUtils.SaveSystem;
import techreborn.manual.designer.windows.MainWindowController;
import java.net.URL;
@ -19,12 +20,15 @@ import java.net.URL;
*/
public class ManualDesigner extends Application {
public static Stage stage;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
stage = primaryStage;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL fxmlUrl = classLoader.getResource("assets/techreborn/designer/mainWindow.fxml");
@ -57,10 +61,17 @@ public class ManualDesigner extends Application {
public void changed(ObservableValue observable, Object oldValue,
Object newValue) {
TreeItem<String> selectedItem = (TreeItem<String>) newValue;
//TODO things if needed
boolean isValid = !SaveSystem.entries.containsKey(selectedItem);
controller.textInput.setDisable(isValid);
controller.nameTextArea.setDisable(isValid);
controller.buttonMeta.setDisable(isValid);
}
});
controller.textInput.setDisable(false);
controller.nameTextArea.setDisable(false);
controller.buttonMeta.setDisable(false);
controller.image.setImage(new Image("assets/techreborn/textures/manual/gui/manual.png"));
controller.image.setPreserveRatio(true);
controller.image.setSmooth(true);
@ -69,5 +80,7 @@ public class ManualDesigner extends Application {
controller.image.setFitWidth(1000);
controller.image.fitWidthProperty().bind(controller.renderPane.widthProperty());
controller.image.fitHeightProperty().bind(controller.renderPane.heightProperty());
controller.load();
}
}

View file

@ -1,12 +1,26 @@
package techreborn.manual.designer.fileUtils;
import javafx.stage.FileChooser;
import techreborn.manual.designer.ManualDesigner;
import java.io.File;
/**
* Created by Mark on 05/04/2016.
*/
public class LoadSystem {
public static void load(){}
public static void load(){
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open master.json");
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Jason File (*.json)", "*.json"));
fileChooser.setInitialFileName("master.json");
fileChooser.setInitialDirectory(new File("."));
File file = fileChooser.showOpenDialog(ManualDesigner.stage);
if(file != null){
if(file.getName().endsWith(".json")){
//Things
}
}
}
}

View file

@ -1,10 +1,17 @@
package techreborn.manual.designer.fileUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javafx.scene.control.TreeItem;
import javafx.stage.DirectoryChooser;
import techreborn.lib.ModInfo;
import techreborn.manual.designer.ManualDesigner;
import techreborn.manual.saveFormat.Entry;
import techreborn.manual.saveFormat.ManualFormat;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -18,18 +25,39 @@ public class SaveSystem {
public static ManualFormat master;
public static void export(){
static File lastSave = null;
List<Entry> entrieList = new ArrayList<>();
for(Object object : entries.entrySet().toArray()){
Entry entry = (Entry) object;
entrieList.add(entry);
}
System.out.println(entrieList);
public static void export(){
List<Entry> entryList = new ArrayList<>(entries.values());
if(master == null){
master = new ManualFormat("TechReborn", ModInfo.MOD_ID, entrieList);
master = new ManualFormat("TechReborn", ModInfo.MOD_ID, entryList);
}
//TODO things
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("Select export location");
File openLocation = new File(".");
if(lastSave != null){
openLocation = lastSave;
}
chooser.setInitialDirectory(openLocation);
File selectedDirectory = chooser.showDialog(ManualDesigner.stage);
lastSave = selectedDirectory;
File masterJson = new File(selectedDirectory, "master.json");
if(masterJson.exists()){
masterJson.delete();
}
if(selectedDirectory != null){
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(master);
try {
FileWriter writer = new FileWriter(masterJson);
writer.write(json);
writer.close();
} catch (IOException e) {
System.out.println("something bad happened");
e.printStackTrace();
}
}
}

View file

@ -2,23 +2,22 @@ package techreborn.manual.designer.windows;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.MenuBar;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import techreborn.manual.designer.ManualCatergories;
import techreborn.manual.designer.fileUtils.LoadSystem;
import techreborn.manual.designer.fileUtils.SaveSystem;
import techreborn.manual.saveFormat.Entry;
import techreborn.manual.saveFormat.EntryData;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
/**
@ -33,6 +32,8 @@ public class MainWindowController {
public Button buttonNew;
public TextArea textInput;
public Button buttonDelete;
public TextField nameTextArea;
public Button buttonMeta;
public void newItem(Event event) {
if(treeList.getSelectionModel().getSelectedItem() instanceof TreeItem){
@ -42,7 +43,7 @@ public class MainWindowController {
dialog.setTitle("Name?");
dialog.setContentText("Name of item:");
Optional<String> result = dialog.showAndWait();
if(result.isPresent()){
if(result.isPresent() && !result.get().isEmpty()){
TreeItem<String> newItem = new TreeItem<>(result.get());
Entry entry = new Entry();
entry.name = result.get();
@ -62,6 +63,7 @@ public class MainWindowController {
return;
}
item.getChildren().add(newItem);
item.setExpanded(true);
SaveSystem.entries.put(newItem, entry);
} else {
Toolkit.getDefaultToolkit().beep();
@ -99,4 +101,59 @@ public class MainWindowController {
//TODO checks to make sure its being saved
System.exit(0);
}
public void load(){
textInput.textProperty().addListener((observable, oldValue, newValue) -> {
textAreaChanged();
});
nameTextArea.textProperty().addListener((observable, oldValue, newValue) -> {
nameChange();
});
}
public void textAreaChanged() {
if(!treeList.getSelectionModel().isEmpty()){
if(SaveSystem.entries.containsKey(treeList.getSelectionModel().getSelectedItem())){
Entry entry = SaveSystem.entries.get(treeList.getSelectionModel().getSelectedItem());
if(entry != null){
if(entry.data == null){
entry.data = new EntryData();
}
if(entry.data.data == null){
entry.data.data = new HashMap<>();
}
if(entry.data.data.containsKey("text")){
entry.data.data.replace("text", textInput.getText());
} else {
entry.data.data.put("text", textInput.getText());
}
}
SaveSystem.entries.replace((TreeItem) treeList.getSelectionModel().getSelectedItem(), entry);
}
}
}
public void nameChange() {
if(!treeList.getSelectionModel().isEmpty()){
if(SaveSystem.entries.containsKey(treeList.getSelectionModel().getSelectedItem())){
Entry entry = SaveSystem.entries.get(treeList.getSelectionModel().getSelectedItem());
if(entry != null){
if(entry.data == null){
entry.data = new EntryData();
}
if(entry.data.data == null){
entry.data.data = new HashMap<>();
}
if(entry.data.data.containsKey("regName")){
entry.data.data.replace("regName", nameTextArea.getText());
} else {
entry.data.data.put("regName", nameTextArea.getText());
}
}
SaveSystem.entries.replace((TreeItem) treeList.getSelectionModel().getSelectedItem(), entry);
}
}
}
}

View file

@ -10,6 +10,6 @@ public class EntryData {
/**
* Use this to store data for a page
*/
HashMap<String, String> data;
public HashMap<String, String> data;
}

View file

@ -7,11 +7,11 @@ import java.util.List;
*/
public class ManualFormat {
String name;
public String name;
String modId;
public String modId;
List<Entry> entries;
public List<Entry> entries;
public ManualFormat(String name, String modId, List<Entry> entries) {
this.name = name;

View file

@ -56,9 +56,9 @@
<children>
<Label layoutY="6.0" text="Settings" />
<TextArea fx:id="textInput" layoutX="43.0" layoutY="8.0" maxWidth="250.0" prefHeight="59.0" prefWidth="250.0" AnchorPane.bottomAnchor="8.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="8.0" />
<TextField layoutX="88.0" layoutY="25.0" />
<TextField fx:id="nameTextArea" layoutX="88.0" layoutY="25.0" />
<Label layoutX="6.0" layoutY="29.0" text="Registry Name" />
<Button layoutX="19.0" layoutY="59.0" mnemonicParsing="false" text="Set meta" />
<Button fx:id="buttonMeta" layoutX="19.0" layoutY="59.0" mnemonicParsing="false" text="Set meta" />
</children>
</AnchorPane>
</children>

16
testExport/master.json Normal file
View file

@ -0,0 +1,16 @@
{
"name": "TechReborn",
"modId": "techreborn",
"entries": [
{
"name": "Block",
"type": "Text",
"data": {
"data": {
"text": "This is a block, it does things\n\nhow are new lines handled?",
"regName": "minecraft:diamond"
}
}
}
]
}