aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBryson Steck <brysonsteck@protonmail.com>2023-05-31 00:29:45 -0600
committerBryson Steck <brysonsteck@protonmail.com>2023-05-31 00:29:45 -0600
commitb2ffd5fc3f9c03d2de306bdde37e5c6aee879c2e (patch)
treeac37624ee1588a4dfd293b1d95b881a9909b6c4d /src
parentd1bf5734bf86ef81e11414f30a03670660838998 (diff)
downloadServerCraft-b2ffd5fc3f9c03d2de306bdde37e5c6aee879c2e.tar
ServerCraft-b2ffd5fc3f9c03d2de306bdde37e5c6aee879c2e.tar.gz
ServerCraft-b2ffd5fc3f9c03d2de306bdde37e5c6aee879c2e.tar.bz2
partially separated dialogs
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt56
-rw-r--r--src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt96
-rw-r--r--src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt16
3 files changed, 114 insertions, 54 deletions
diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt
index 6c64a76..6eb0af4 100644
--- a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt
+++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt
@@ -57,6 +57,7 @@ import org.rauschig.jarchivelib.*
import xyz.brysonsteck.ServerCraft.server.Server
import xyz.brysonsteck.ServerCraft.server.Download
import xyz.brysonsteck.ServerCraft.App
+import xyz.brysonsteck.ServerCraft.dialogs.Dialog
class PrimaryController {
@FXML
@@ -681,60 +682,7 @@ class PrimaryController {
}
private fun createDialog(type: String, msg: String, yes: String = "Yes", no: String = "No", hold: Boolean = true): Boolean {
- var result = false
- val resources = App().javaClass.getResource("icons/$type.png")
- val dialog = Stage()
- dialog.icons.add(Image(App().javaClass.getResourceAsStream("app.png")))
- dialog.setResizable(false)
- dialog.initModality(Modality.APPLICATION_MODAL);
- dialog.title = directory
- 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.isWrapText = true
- label.layoutX = 115.0
- label.layoutY = if (type == "warning") {10.0} else {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)
- noButton.onAction = EventHandler<ActionEvent>() {
- if (hold) {
- result = false
- } else {
- asyncResult = false
- }
- dialog.hide()
- }
- val yesButton = Button(yes)
- yesButton.onAction = EventHandler<ActionEvent>() {
- if (hold) {
- result = true
- } else {
- asyncResult = true
- }
- dialog.hide()
- }
- yesButton.isDefaultButton = true
- buttonBar.buttons.add(noButton)
- buttonBar.buttons.add(yesButton)
- scenePane.children.addAll(imagePane, label, buttonBar)
- dialog.setScene(dialogScene);
- if (hold) {
- dialog.showAndWait();
- } else {
- dialog.show();
- }
- return result
+ return Dialog(type, directory, msg, yes, no, null, hold).show()
}
private fun loadServerDir(dir: String): Boolean {
diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt
new file mode 100644
index 0000000..0984188
--- /dev/null
+++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt
@@ -0,0 +1,96 @@
+package xyz.brysonsteck.ServerCraft.dialogs
+
+import javafx.scene.control.Button
+import javafx.scene.control.Label
+import javafx.scene.control.ButtonBar
+import javafx.scene.image.Image
+import javafx.scene.image.ImageView
+import javafx.scene.layout.Pane
+import javafx.scene.Scene
+import javafx.stage.Stage
+import javafx.stage.Modality
+import javafx.geometry.Insets
+import javafx.event.EventHandler
+import javafx.event.ActionEvent
+import xyz.brysonsteck.ServerCraft.App
+
+open class Dialog {
+ private var result = false
+
+ private val type: String
+ private val title: String
+ private val msg: String
+ private val yes: String
+ private val no: String
+ private val neutral: Button?
+ private val hold: Boolean
+
+ constructor(type: String,
+ title: String,
+ msg: String,
+ yes: String = "Yes",
+ no: String = "No",
+ neutral: Button?,
+ hold: Boolean = true) {
+ this.type = type
+ this.title = title
+ this.msg = msg
+ this.yes = yes
+ this.no = no
+ this.neutral = neutral
+ this.hold = hold
+ }
+
+ public fun show(): Boolean {
+ val resources = App().javaClass.getResource("icons/$type.png")
+ val dialog = Stage()
+ dialog.icons.add(Image(App().javaClass.getResourceAsStream("app.png")))
+ dialog.setResizable(false)
+ dialog.initModality(Modality.APPLICATION_MODAL);
+ dialog.title = title
+ 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.isWrapText = true
+ label.layoutX = 115.0
+ label.layoutY = if (type == "warning") {10.0} else {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)
+ noButton.onAction = EventHandler<ActionEvent>() {
+ result = false
+ dialog.hide()
+ }
+ val yesButton = Button(yes)
+ yesButton.onAction = EventHandler<ActionEvent>() {
+ result = true
+ dialog.hide()
+ }
+ yesButton.isDefaultButton = true
+ buttonBar.buttons.add(noButton)
+ buttonBar.buttons.add(yesButton)
+ scenePane.children.addAll(imagePane, label, buttonBar)
+ ButtonBar.setButtonData(noButton, ButtonBar.ButtonData.RIGHT)
+ ButtonBar.setButtonData(yesButton, ButtonBar.ButtonData.RIGHT)
+ buttonBar.buttons.add(noButton)
+ buttonBar.buttons.add(yesButton)
+ dialog.setScene(dialogScene);
+ if (hold) {
+ dialog.showAndWait();
+ } else {
+ dialog.show();
+ }
+ return result
+ }
+
+} \ No newline at end of file
diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt
new file mode 100644
index 0000000..a05b3a9
--- /dev/null
+++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt
@@ -0,0 +1,16 @@
+package xyz.brysonsteck.ServerCraft.dialogs
+
+import xyz.brysonsteck.ServerCraft.dialogs.Dialog
+import javafx.scene.control.Button
+
+class EulaDialog: Dialog {
+
+ constructor(type: String,
+ title: String,
+ msg: String,
+ yes: String = "Yes",
+ no: String = "No",
+ neutral: Button?,
+ hold: Boolean = true) : super(type, title, msg, yes, no, neutral, hold)
+
+} \ No newline at end of file