Skip to content

Commit

Permalink
Overhauled UI!
Browse files Browse the repository at this point in the history
Added tab system to seperate functionality!
Added a dedicated FX folder for JavaFX stuff!

Fixed the default no output air mode so it actually works now!

Going to make a github release for this!
  • Loading branch information
gamma-02 committed Mar 31, 2024
1 parent 37cfb09 commit 2b165b4
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 39 deletions.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

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

2 changes: 1 addition & 1 deletion .idea/vcs.xml

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

18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>net.gneisscode.nbttocsv.JFXHack</mainClass>
<mainClass>net.gneisscode.nbttocsv.JavaFXThings.JFXHack</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
Expand All @@ -195,7 +195,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>net.gneisscode.nbttocsv.JFXHack</mainClass>
<mainClass>net.gneisscode.nbttocsv.JavaFXThings.JFXHack</mainClass>
</manifest>
</archive>
</configuration>
Expand All @@ -205,13 +205,13 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>net.gneisscode.nbttocsv.JFXHack</mainClass>
</manifest>
</archive>
<!-- <archive>-->
<!-- <manifest>-->
<!-- <addClasspath>true</addClasspath>-->
<!-- <classpathPrefix>lib/</classpathPrefix>-->
<!-- <mainClass>net.gneisscode.nbttocsv.JavaFXThings.JFXHack</mainClass>-->
<!-- </manifest>-->
<!-- </archive>-->
</configuration>
<executions>
<execution>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
requires org.apache.commons.lang3;
requires NBT;
requires com.opencsv;
requires java.desktop;

opens net.gneisscode.nbttocsv to javafx.fxml;
exports net.gneisscode.nbttocsv;
exports net.gneisscode.nbttocsv.utils;
exports net.gneisscode.nbttocsv.JavaFXThings;
opens net.gneisscode.nbttocsv.JavaFXThings to javafx.fxml;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static String getExecuteCommand(BlockContainer fromBlock, boolean relativ
* @return The formatted function file
*/
public static String getStructureBuildStartFunction(String functionName){
URL defaultFunction = FunctionConverter.class.getResource("/net/gneisscode/nbttocsv/buid_start.txt");
URL defaultFunction = FunctionConverter.class.getResource("buid_start.txt");
if (defaultFunction == null) {
return "ERROR";
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/net/gneisscode/nbttocsv/HelloApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import net.gneisscode.nbttocsv.utils.Util;
import net.querz.nbt.tag.*;
import org.kordamp.bootstrapfx.BootstrapFX;

public class HelloApplication extends Application {

Expand All @@ -22,10 +23,16 @@ public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 320, 350);
stage.setTitle("NBT to CSV");
Scene scene = new Scene(fxmlLoader.load(), 450, 350);


scene.getStylesheets().add(BootstrapFX.bootstrapFXStylesheet());



stage.setScene(scene);

stage.setTitle("NBT to CSV");
stage.show();
}

Expand Down
52 changes: 41 additions & 11 deletions src/main/java/net/gneisscode/nbttocsv/HelloController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

import com.opencsv.CSVWriter;
import com.opencsv.CSVWriterBuilder;
import javafx.animation.Timeline;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import net.querz.nbt.tag.CompoundTag;
import org.controlsfx.control.ToggleSwitch;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -25,12 +26,18 @@

public class HelloController implements Initializable {
@FXML
public Label outputCsvButton;
public Label outputCsvInfo;
@FXML
public ToggleSwitch writeAir;
@FXML
public TextField csvPathInput;
@FXML
public Button inputButton;
@FXML
public Label outputCsvTitle;
@FXML
public TabPane fullPanel;
@FXML
private Label welcomeText;

@FXML
Expand Down Expand Up @@ -62,18 +69,20 @@ protected void onOutputClick(){
if(HelloApplication.BLOCKS.isEmpty())
return;

ArrayList<BlockContainer> blocks = new ArrayList<>();

for(BlockContainer block : HelloApplication.BLOCKS){
block.resolve();
if(!writeAir.isSelected())
HelloApplication.BLOCKS.remove(block);
if(!writeAir.isSelected() && !block.location.equals("minecraft:air"))
blocks.add(block);
}

FileWriter outputFile = null;
try {

outputFile = new FileWriter(FileSystems.getDefault().getPath(csvPathInput.getText()).toFile());
} catch (IOException e) {
outputCsvButton.setText("Path invalid!");
outputCsvInfo.setText("Path invalid!");
throw new RuntimeException(e);
}

Expand All @@ -83,7 +92,7 @@ protected void onOutputClick(){
int longestRow = 0;

ArrayList<String[]> lines = new ArrayList<>();
for(BlockContainer b : HelloApplication.BLOCKS){
for(BlockContainer b : blocks){

ArrayList<String> row = b.getCsvRow();

Expand All @@ -100,7 +109,7 @@ protected void onOutputClick(){
outputWriter.writeNext(header.toArray(new String[0]));
outputWriter.writeAll(lines);

outputCsvButton.setText("Successfully written!");
outputCsvInfo.setText("Successfully written!");
try {
outputWriter.close();
} catch (IOException e) {
Expand All @@ -109,11 +118,32 @@ protected void onOutputClick(){

}

private ChangeListener<Boolean> listener;

@FXML
private TextField inputArea;

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
outputCsvButton.setText("Output controls");
fullPanel.setStyle("-fx-focus-color: transparent; -fx-faint-focus-color: transparent;");

// inputButton.getStyleClass().setAll("btn","btn-danger");
inputArea.setPrefHeight(30);
csvPathInput.setPrefHeight(30);

listener = new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
writeAir.setText("Write air states to CSV: " + (newValue ? "Yes" : "No"));

}

};
writeAir.selectedProperty().addListener(listener);
}

public void onFunctionTabSelected(Event event) {


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.gneisscode.nbttocsv.JavaFXThings;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TextField;

public class DissapearingLableTextField extends TextField {
DissapearingLableTextField(){
this("");
}

DissapearingLableTextField(String text){
super(text);


}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package net.gneisscode.nbttocsv;
package net.gneisscode.nbttocsv.JavaFXThings;

import net.gneisscode.nbttocsv.HelloApplication;

public class JFXHack {
public static void main(String[] args){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Loading

0 comments on commit 2b165b4

Please sign in to comment.