diff options
Diffstat (limited to 'app')
5 files changed, 80 insertions, 48 deletions
diff --git a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt index cffa525..f4f49ae 100644 --- a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt +++ b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt @@ -12,7 +12,7 @@ import javafx.stage.Stage; class App : Application() { override fun start(stage: Stage) { - var scene = Scene(loadFXML("primary"), 1500.0, 900.0) + var scene = Scene(loadFXML("primary"), 963.0, 713.0) stage.title = "Server For Dummies" stage.scene = scene stage.show() diff --git a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/Download.kt b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/Download.kt index da61f75..07a6eca 100644 --- a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/Download.kt +++ b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/Download.kt @@ -9,11 +9,11 @@ class Download: Runnable { public var size: Int public var downloaded: Int public var contentLength: Int + public var status: Status private final val MAX_BUFFER_SIZE: Number = 1024 private var url: URL - private var status: Status constructor (url: URL) { this.url = url @@ -23,10 +23,6 @@ class Download: Runnable { contentLength = 1 } - public fun status(): Status { - return status - } - public fun start() { val thread = Thread(this) thread.start() diff --git a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt index ac45e2a..0932a3d 100644 --- a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt +++ b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt @@ -35,6 +35,8 @@ import javafx.scene.text.TextAlignment import javafx.scene.text.Text import javafx.scene.Scene import javafx.scene.input.MouseEvent +import javafx.scene.image.Image +import javafx.scene.image.ImageView import javafx.stage.FileChooser import javafx.stage.FileChooser.ExtensionFilter import javafx.stage.DirectoryChooser @@ -63,6 +65,8 @@ class PrimaryController { @FXML lateinit private var parentPane: Pane @FXML + lateinit private var directoryPane: Pane + @FXML lateinit private var buttonBar: ButtonBar @FXML lateinit private var flightCheckbox: CheckBox @@ -96,6 +100,12 @@ class PrimaryController { lateinit private var statusBar: Label @FXML lateinit private var progressBar: ProgressBar + @FXML + lateinit private var startButton: Button + @FXML + lateinit private var buildButton: Button + + private var building = false @FXML private fun onDirectoryButtonClick() { @@ -139,22 +149,49 @@ class PrimaryController { @FXML private fun onBuild() { + if (building) { + building = false + return; + } + building = true + worldSettingsPane.isDisable = true + directoryPane.isDisable = true + parentPane.isDisable = true + startButton.isDisable = true + buildButton.text = "Cancel Build" + + @Suppress("OPT_IN_USAGE") GlobalScope.launch(Dispatchers.Default) { - withContext(Dispatchers.JavaFx){statusBar.text = "Downloading a file..."} progressBar.isVisible = true - val download = Download(URL("https://brysonsteck.xyz/pub/a-really-big-file")) - download.start() - while (download.status() == Download.Status.DOWNLOADING) { - var prog = (download.downloaded.toDouble() / download.contentLength.toDouble()) - // for whatever reason I need to print something to the screen in order for it to work - print("") - if (prog >= 0.01) { - withContext(Dispatchers.JavaFx) {progressBar.progress = prog} + var downloads = mapOf( + "Java 20" to "https://download.java.net/java/GA/jdk20.0.1/b4887098932d415489976708ad6d1a4b/9/GPL/openjdk-20.0.1_linux-x64_bin.tar.gz", + "BuildTools" to "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar", + ) + downloads.forEach { + withContext(Dispatchers.JavaFx){statusBar.text = "Downloading ${it.key}..."} + val download = Download(URL(it.value)) + download.start() + while (download.status == Download.Status.DOWNLOADING) { + var prog = (download.downloaded.toDouble() / download.contentLength.toDouble()) + // for whatever reason I need to print something to the screen in order for it to update the progress bar + print("") + if (prog >= 0.01) { + withContext(Dispatchers.JavaFx) {progressBar.progress = prog} + } + if (!building) download.status = Download.Status.CANCELLED + Thread.sleep(300) } - Thread.sleep(300) } progressBar.isVisible = false - withContext(Dispatchers.JavaFx){statusBar.text = "Ready."} + withContext(Dispatchers.JavaFx){ + worldSettingsPane.isDisable = false + directoryPane.isDisable = false + parentPane.isDisable = false + startButton.isDisable = false + buildButton.text = "Build Server" + statusBar.text = if (building) {"Ready."} else {"Server build cancelled."} + building = false; + } } } @@ -163,16 +200,39 @@ class PrimaryController { } - private fun createDialog() { + private fun createDialog(type: String, msg: String, yes: String, no: String) { + val resources = this.javaClass.getResource("icons/$type.png") val dialog = Stage(); dialog.initModality(Modality.APPLICATION_MODAL); - val dialogScene = Scene(App().loadFXML("dialog"), 300.0, 200.0); + val scenePane = Pane() + val dialogScene = Scene(scenePane, 400.0, 150.0); + val imagePane = Pane() + val icon = Image("$resources") + imagePane.layoutX = 14.0 + imagePane.layoutY = 14.0 + imagePane.scaleX = 0.7 + imagePane.scaleY = 0.7 + imagePane.children.add(ImageView(icon)) + val label = Label(msg) + label.layoutX = 115.0 + label.layoutY = 40.0 + val buttonBar = ButtonBar() + buttonBar.padding = Insets(10.0, 10.0, 10.0, 10.0) + buttonBar.layoutX = 0.0 + buttonBar.layoutY = 107.0 + buttonBar.prefWidth = 400.0 + val noButton = Button(no) + val yesButton = Button(yes) + yesButton.isDefaultButton = true + buttonBar.buttons.add(noButton) + buttonBar.buttons.add(yesButton) + scenePane.children.addAll(imagePane, label, buttonBar) dialog.setScene(dialogScene); dialog.show(); } private fun loadServerDir(dir: String): Boolean { - createDialog() + createDialog("info", "There is no server in this directory.\nCreate one?", "Yes", "No") var directory = dir var hasServer = false if (!File(directory).isDirectory) { diff --git a/app/src/main/resources/xyz/brysonsteck/serverfordummies/dialog.fxml b/app/src/main/resources/xyz/brysonsteck/serverfordummies/dialog.fxml deleted file mode 100644 index 6dab79a..0000000 --- a/app/src/main/resources/xyz/brysonsteck/serverfordummies/dialog.fxml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<?import javafx.geometry.Insets?> -<?import javafx.scene.control.Button?> -<?import javafx.scene.control.ButtonBar?> -<?import javafx.scene.control.Label?> -<?import javafx.scene.layout.Pane?> - - -<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"> - <children> - <Pane fx:id="iconPane" layoutX="14.0" layoutY="14.0" prefHeight="82.0" prefWidth="82.0" /> - <Label fx:id="dialogLabel" layoutX="115.0" layoutY="40.0" text="Dialog Box" /> - <ButtonBar layoutY="157.0" prefHeight="43.0" prefWidth="400.0"> - <buttons> - <Button fx:id="otherButton" mnemonicParsing="false" text="Decline" /> - <Button fx:id="defaultButton" defaultButton="true" mnemonicParsing="false" text="Accept" /> - </buttons> - <padding> - <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> - </padding> - </ButtonBar> - </children> -</Pane> diff --git a/app/src/main/resources/xyz/brysonsteck/serverfordummies/primary.fxml b/app/src/main/resources/xyz/brysonsteck/serverfordummies/primary.fxml index c940d08..811ab8d 100644 --- a/app/src/main/resources/xyz/brysonsteck/serverfordummies/primary.fxml +++ b/app/src/main/resources/xyz/brysonsteck/serverfordummies/primary.fxml @@ -19,9 +19,9 @@ <?import javafx.scene.layout.Pane?> <?import javafx.scene.text.Font?> -<Pane fx:id="primary" maxHeight="900.0" maxWidth="1500.0" minHeight="620.0" minWidth="963.0" prefHeight="708.0" prefWidth="963.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="xyz.brysonsteck.serverfordummies.PrimaryController"> +<Pane fx:id="primary" maxHeight="713.0" maxWidth="963.0" minHeight="713.0" minWidth="963.0" prefHeight="713.0" prefWidth="963.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="xyz.brysonsteck.serverfordummies.PrimaryController"> <children> - <HBox prefHeight="39.0" prefWidth="963.0"> + <HBox fx:id="directoryPane" prefHeight="39.0" prefWidth="963.0"> <children> <Button id="openFile" fx:id="chooseDirectoryButton" lineSpacing="10.0" mnemonicParsing="false" onMouseClicked="#onDirectoryButtonClick" text="Choose Directory..."> <opaqueInsets> @@ -220,8 +220,8 @@ </Pane> <ButtonBar fx:id="buttonBar" disable="true" layoutY="635.0" prefHeight="40.0" prefWidth="963.0"> <buttons> - <Button mnemonicParsing="false" onMouseClicked="#onBuild" text="Build Server" /> - <Button defaultButton="true" mnemonicParsing="false" text="Start Server" /> + <Button fx:id="buildButton" mnemonicParsing="false" onMouseClicked="#onBuild" text="Build Server" /> + <Button fx:id="startButton" defaultButton="true" mnemonicParsing="false" prefWidth="120.0" text="Start Server" /> </buttons> <padding> <Insets bottom="8.0" left="8.0" right="8.0" top="8.0" /> |