From b85e610bbbf88d1ad87e38b07636ef0be8858566 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 17 Dec 2021 15:03:04 +0100 Subject: [PATCH] eros: show startup dialog --- src/main/java/de/bixilon/minosoft/Minosoft.kt | 5 +- .../data/text/TranslatableComponents.kt | 1 + .../gui/eros/dialog/StartingDialog.kt | 87 +++++++++++++++++++ .../minosoft/util/task/worker/StartupTasks.kt | 1 + .../assets/minosoft/eros/dialog/starting.fxml | 65 ++++++++++++++ .../assets/minosoft/language/en_us.lang | 6 +- 6 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/gui/eros/dialog/StartingDialog.kt create mode 100644 src/main/resources/assets/minosoft/eros/dialog/starting.fxml diff --git a/src/main/java/de/bixilon/minosoft/Minosoft.kt b/src/main/java/de/bixilon/minosoft/Minosoft.kt index 64a886caf..9fe9e7599 100644 --- a/src/main/java/de/bixilon/minosoft/Minosoft.kt +++ b/src/main/java/de/bixilon/minosoft/Minosoft.kt @@ -26,6 +26,7 @@ import de.bixilon.minosoft.data.registries.versions.Versions import de.bixilon.minosoft.gui.eros.Eros import de.bixilon.minosoft.gui.eros.XStartOnFirstThreadWarning import de.bixilon.minosoft.gui.eros.crash.ErosCrashReport.Companion.crash +import de.bixilon.minosoft.gui.eros.dialog.StartingDialog import de.bixilon.minosoft.gui.eros.util.JavaFXInitializer import de.bixilon.minosoft.modding.event.events.FinishInitializingEvent import de.bixilon.minosoft.modding.event.master.GlobalEventMaster @@ -116,9 +117,9 @@ object Minosoft { if (!RunConfiguration.DISABLE_EROS) { taskWorker += Task(identifier = StartupTasks.INITIALIZE_JAVAFX, executor = { JavaFXInitializer.start() }) - taskWorker += Task(identifier = StartupTasks.X_START_ON_FIRST_THREAD_WARNING, executor = { XStartOnFirstThreadWarning.show() }, dependencies = arrayOf(StartupTasks.LOAD_PROFILES, StartupTasks.LOAD_LANGUAGE_FILES, StartupTasks.INITIALIZE_JAVAFX)) + taskWorker += Task(identifier = StartupTasks.X_START_ON_FIRST_THREAD_WARNING, executor = { XStartOnFirstThreadWarning.show() }, dependencies = arrayOf(StartupTasks.LOAD_LANGUAGE_FILES, StartupTasks.INITIALIZE_JAVAFX)) - // ToDo: Show start up progress window + taskWorker += Task(identifier = StartupTasks.STARTUP_PROGRESS, executor = { StartingDialog(START_UP_LATCH).show() }, dependencies = arrayOf(StartupTasks.LOAD_LANGUAGE_FILES, StartupTasks.INITIALIZE_JAVAFX)) Util.forceClassInit(Eros::class.java) } diff --git a/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponents.kt b/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponents.kt index 348f0579e..0055740b0 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponents.kt +++ b/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponents.kt @@ -24,6 +24,7 @@ object TranslatableComponents { val GENERAL_CONFIRM = "minosoft:general.confirm".toResourceLocation() val GENERAL_DELETE = "minosoft:general.delete".toResourceLocation() val GENERAL_IGNORE = "minosoft:general.ignore".toResourceLocation() + val GENERAL_EXIT = "minosoft:general.exit".toResourceLocation() val EROS_DELETE_SERVER_CONFIRM_DESCRIPTION = { name: ChatComponent, address: String -> Minosoft.LANGUAGE_MANAGER.translate("minosoft:server_info.delete.dialog.description".toResourceLocation(), null, name, address) } val ACCOUNT_CARD_CONNECTION_COUNT = { count: Int -> Minosoft.LANGUAGE_MANAGER.translate("minosoft:main.account.card.connection_count".toResourceLocation(), null, count) } diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/dialog/StartingDialog.kt b/src/main/java/de/bixilon/minosoft/gui/eros/dialog/StartingDialog.kt new file mode 100644 index 000000000..bab265a87 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/eros/dialog/StartingDialog.kt @@ -0,0 +1,87 @@ +/* + * Minosoft + * Copyright (C) 2021 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.eros.dialog + +import de.bixilon.minosoft.ShutdownReasons +import de.bixilon.minosoft.data.text.TranslatableComponents +import de.bixilon.minosoft.gui.eros.controller.DialogController +import de.bixilon.minosoft.gui.eros.util.JavaFXUtil +import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext +import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text +import de.bixilon.minosoft.util.CountUpAndDownLatch +import de.bixilon.minosoft.util.KUtil.toResourceLocation +import de.bixilon.minosoft.util.ShutdownManager +import javafx.fxml.FXML +import javafx.scene.control.Button +import javafx.scene.control.ProgressBar +import javafx.scene.text.TextFlow + +class StartingDialog( + val latch: CountUpAndDownLatch, +) : DialogController() { + @FXML private lateinit var headerFX: TextFlow + @FXML private lateinit var countTextFX: TextFlow + @FXML private lateinit var progressFX: ProgressBar + @FXML private lateinit var exitButtonFX: Button + + fun show() { + JavaFXUtil.runLater { + JavaFXUtil.openModal(TITLE, LAYOUT, this) + if (latch.count == 0) { + return@runLater + } + update() + stage.show() + } + } + + + override fun init() { + headerFX.text = HEADER + exitButtonFX.ctext = TranslatableComponents.GENERAL_EXIT + latch += { + JavaFXUtil.runLater { + update() + } + } + } + + private fun update() { + val count = latch.count + val total = latch.total + if (count <= 0 && total > 0) { + stage.close() + return + } + countTextFX.text = "${total - count}/${total}" + val progress = if (total <= 0) { + 0.0 + } else { + (total - count.toDouble()) / total.toDouble() + } + progressFX.progress = progress + } + + @FXML + fun exit() { + ShutdownManager.shutdown(reason = ShutdownReasons.REQUESTED_BY_USER) + } + + companion object { + private val LAYOUT = "minosoft:eros/dialog/starting.fxml".toResourceLocation() + + private val TITLE = "minosoft:dialog.starting.title".toResourceLocation() + private val HEADER = "minosoft:dialog.starting.header".toResourceLocation() + } +} diff --git a/src/main/java/de/bixilon/minosoft/util/task/worker/StartupTasks.kt b/src/main/java/de/bixilon/minosoft/util/task/worker/StartupTasks.kt index 060881820..38513af8c 100644 --- a/src/main/java/de/bixilon/minosoft/util/task/worker/StartupTasks.kt +++ b/src/main/java/de/bixilon/minosoft/util/task/worker/StartupTasks.kt @@ -25,5 +25,6 @@ enum class StartupTasks { X_START_ON_FIRST_THREAD_WARNING, FILE_WATCHER, LOAD_YGGDRASIL, + STARTUP_PROGRESS, ; } diff --git a/src/main/resources/assets/minosoft/eros/dialog/starting.fxml b/src/main/resources/assets/minosoft/eros/dialog/starting.fxml new file mode 100644 index 000000000..94505e5da --- /dev/null +++ b/src/main/resources/assets/minosoft/eros/dialog/starting.fxml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/assets/minosoft/language/en_us.lang b/src/main/resources/assets/minosoft/language/en_us.lang index 871711374..55bd81966 100644 --- a/src/main/resources/assets/minosoft/language/en_us.lang +++ b/src/main/resources/assets/minosoft/language/en_us.lang @@ -3,6 +3,7 @@ minosoft:general.cancel=Cancel minosoft:general.confirm=Confirm minosoft:general.delete=Delete minosoft:general.ignore=Ignore +minosoft:general.exit=Exit minosoft:eros_window_title=Minosoft @@ -18,16 +19,15 @@ minosoft:server_info.remote_brand=Remote brand minosoft:server_info.active_connections=Active connections minosoft:server_info.players_online=Players online minosoft:server_info.ping=Latency - minosoft:server_info.delete.dialog.description=Do you really want to delete the server %1$s (%2$s)? minosoft:connection.dialog.verify_assets.title=Verifying assets... - Minosoft minosoft:connection.dialog.verify_assets.header=Verifying and downloading missing assets. This might take a while... - minosoft:connection.dialog.connecting.title=Connecting... - Minosoft minosoft:connection.dialog.connecting.header=Connecting... - +minosoft:dialog.starting.title=Starting... - Minosoft +minosoft:dialog.starting.header=Minosoft is still starting. Please wait... minosoft:connection.play.state.waiting=Waiting for connection... minosoft:connection.play.state.loading_assets=Loading assets... minosoft:connection.play.state.loading=Loading...