eros: show startup dialog

This commit is contained in:
Bixilon 2021-12-17 15:03:04 +01:00
parent 61b696c826
commit b85e610bbb
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 160 additions and 5 deletions

View File

@ -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)
}

View File

@ -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) }

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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()
}
}

View File

@ -25,5 +25,6 @@ enum class StartupTasks {
X_START_ON_FIRST_THREAD_WARNING,
FILE_WATCHER,
LOAD_YGGDRASIL,
STARTUP_PROGRESS,
;
}

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?>
<VBox xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="130.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17">
<GridPane VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS"/>
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="NEVER"/>
<RowConstraints vgrow="NEVER"/>
<RowConstraints minHeight="40.0" vgrow="NEVER"/>
<RowConstraints vgrow="ALWAYS"/>
<RowConstraints vgrow="NEVER"/>
</rowConstraints>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</VBox.margin>
<TextFlow fx:id="headerFX">
<Text text="Minosoft is still starting..."/>
<GridPane.margin>
<Insets bottom="10.0"/>
</GridPane.margin>
</TextFlow>
<GridPane GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints hgrow="NEVER"/>
<ColumnConstraints hgrow="ALWAYS"/>
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="NEVER"/>
</rowConstraints>
<TextFlow fx:id="countTextFX" GridPane.columnIndex="1">
<Text text="50/100"/>
</TextFlow>
</GridPane>
<ProgressBar fx:id="progressFX" maxHeight="Infinity" maxWidth="Infinity" progress="0.5" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</GridPane.margin>
</ProgressBar>
<GridPane GridPane.rowIndex="4">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints hgrow="NEVER"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER"/>
</rowConstraints>
<Button fx:id="exitButtonFX" onAction="#exit" text="Exit" GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</GridPane.margin>
</Button>
</GridPane>
</GridPane>
</VBox>

View File

@ -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...