diff options
author | Bryson Steck <brysonsteck@protonmail.com> | 2023-05-09 21:59:26 -0600 |
---|---|---|
committer | Bryson Steck <brysonsteck@protonmail.com> | 2023-05-09 21:59:26 -0600 |
commit | 5b321f0d403996f31b1d101bc24e582d8c0cb631 (patch) | |
tree | 0b71f33d33403083042bdcecbfa5c5177798557e /app/src/main/kotlin/xyz | |
parent | 7db4d246d920586edcc485d514d9651dcc370d67 (diff) | |
download | ServerCraft-5b321f0d403996f31b1d101bc24e582d8c0cb631.tar ServerCraft-5b321f0d403996f31b1d101bc24e582d8c0cb631.tar.gz ServerCraft-5b321f0d403996f31b1d101bc24e582d8c0cb631.tar.bz2 |
dialog working, download files working
Diffstat (limited to 'app/src/main/kotlin/xyz')
3 files changed, 76 insertions, 20 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) { |