eros: kick/disconnect dialog

This commit is contained in:
Bixilon 2021-07-30 13:34:11 +02:00
parent ba57efa4be
commit a5df0fc8f7
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 162 additions and 9 deletions

View File

@ -12,4 +12,4 @@ followed by `in`. So `vinPosition` is a valid name.
## Uniforms
Prefixed with u
Prefixed with `u`

View File

@ -14,6 +14,8 @@
package de.bixilon.minosoft.data.text
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.server.Server
import de.bixilon.minosoft.data.accounts.Account
import de.bixilon.minosoft.util.KUtil.asResourceLocation
object TranslatableComponents {
@ -24,4 +26,6 @@ object TranslatableComponents {
val EROS_DELETE_SERVER_CONFIRM_DESCRIPTION = { name: ChatComponent, address: String -> Minosoft.LANGUAGE_MANAGER.translate("minosoft:server_info.delete.dialog.description".asResourceLocation(), null, name, address) }
val ACCOUNT_CARD_CONNECTION_COUNT = { count: Int -> Minosoft.LANGUAGE_MANAGER.translate("minosoft:main.account.card.connection_count".asResourceLocation(), null, count) }
val CONNECTION_KICK_DESCRIPTION = { server: Server, account: Account -> Minosoft.LANGUAGE_MANAGER.translate("minosoft:connection.kick.description".asResourceLocation(), null, server.name, account.username) }
val CONNECTION_LOGIN_KICK_DESCRIPTION = { server: Server, account: Account -> Minosoft.LANGUAGE_MANAGER.translate("minosoft:connection.login_kick.description".asResourceLocation(), null, server.name, account.username) }
}

View File

@ -0,0 +1,61 @@
/*
* 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.dialogs.connection
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.gui.eros.controller.JavaFXWindowController
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text
import de.bixilon.minosoft.util.KUtil.asResourceLocation
import javafx.application.Platform
import javafx.fxml.FXML
import javafx.scene.control.Button
import javafx.scene.text.TextFlow
class KickDialog(
val title: Any,
val header: Any,
val description: Any? = null,
val reason: ChatComponent,
) : JavaFXWindowController() {
@FXML private lateinit var headerFX: TextFlow
@FXML private lateinit var descriptionFX: TextFlow
@FXML private lateinit var reasonFX: TextFlow
@FXML private lateinit var reconnectButtonFX: Button
@FXML private lateinit var closeButtonFX: Button
fun show() {
Platform.runLater {
JavaFXUtil.openModal(title, LAYOUT, this)
stage.show()
}
}
override fun init() {
headerFX.text = Minosoft.LANGUAGE_MANAGER.translate(header)
descriptionFX.text = description?.let { Minosoft.LANGUAGE_MANAGER.translate(it) } ?: ChatComponent.EMPTY
reasonFX.text = reason
reconnectButtonFX.isDisable = true // ToDo
closeButtonFX.setOnAction {
stage.hide()
}
}
companion object {
private val LAYOUT = "minosoft:eros/dialog/connection/kick.fxml".asResourceLocation()
}
}

View File

@ -22,9 +22,12 @@ import de.bixilon.minosoft.gui.eros.Eros
import de.bixilon.minosoft.gui.eros.controller.EmbeddedJavaFXController
import de.bixilon.minosoft.gui.eros.dialogs.SimpleErosConfirmationDialog
import de.bixilon.minosoft.gui.eros.dialogs.UpdateServerDialog
import de.bixilon.minosoft.gui.eros.dialogs.connection.KickDialog
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCardController
import de.bixilon.minosoft.gui.eros.modding.invoker.JavaFXEventInvoker
import de.bixilon.minosoft.modding.event.events.KickEvent
import de.bixilon.minosoft.modding.event.events.LoginKickEvent
import de.bixilon.minosoft.modding.event.events.connection.play.PlayConnectionStateChangeEvent
import de.bixilon.minosoft.modding.event.events.connection.status.StatusConnectionStateChangeEvent
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
@ -239,6 +242,23 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
}
Platform.runLater { updateServer(serverCard.server) }
})
connection.registerEvent(JavaFXEventInvoker.of<KickEvent> { event ->
KickDialog(
title = "minosoft:connection.kick.title".asResourceLocation(),
header = "minosoft:connection.kick.header".asResourceLocation(),
description = TranslatableComponents.CONNECTION_KICK_DESCRIPTION(serverCard.server, account),
reason = event.reason,
).show()
})
connection.registerEvent(JavaFXEventInvoker.of<LoginKickEvent> { event ->
KickDialog(
title = "minosoft:connection.login_kick.title".asResourceLocation(),
header = "minosoft:connection.login_kick.header".asResourceLocation(),
description = TranslatableComponents.CONNECTION_LOGIN_KICK_DESCRIPTION(serverCard.server, account),
reason = event.reason,
).show()
})
connection.connect()
}
}

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<HBox xmlns:fx="http://javafx.com/fxml/1" fx:id="root" prefWidth="600.0" xmlns="http://javafx.com/javafx/16">
<GridPane HBox.hgrow="ALWAYS">
<rowConstraints>
<RowConstraints vgrow="NEVER"/>
<RowConstraints vgrow="NEVER"/>
<RowConstraints vgrow="ALWAYS"/>
<RowConstraints vgrow="NEVER"/>
</rowConstraints>
<TextFlow fx:id="headerFX" style="-fx-font-size: 30;">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="10.0"/>
</GridPane.margin>
<Text text="Kicked"/>
</TextFlow>
<TextFlow fx:id="descriptionFX" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</GridPane.margin>
<Text text="You got kicked from example.de. Used account: Testuser"/>
</TextFlow>
<TextFlow fx:id="reasonFX" textAlignment="CENTER" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="10.0"/>
</GridPane.margin>
<Text text="Kick reason&#10;&#10;Can be multiple lines long&#10;"/>
</TextFlow>
<GridPane GridPane.rowIndex="3">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints hgrow="NEVER"/>
<ColumnConstraints hgrow="NEVER"/>
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="NEVER"/>
</rowConstraints>
<Button fx:id="reconnectButtonFX" text="Reconnect" GridPane.columnIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="10.0"/>
</GridPane.margin>
</Button>
<Button fx:id="closeButtonFX" text="Close" GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="10.0"/>
</GridPane.margin>
</Button>
</GridPane>
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS"/>
</columnConstraints>
</GridPane>
</HBox>

View File

@ -19,7 +19,7 @@
<RowConstraints vgrow="ALWAYS"/>
<RowConstraints vgrow="NEVER"/>
</rowConstraints>
<TextFlow fx:id="headerFX">
<TextFlow style="-fx-font-size: 30;" fx:id="headerFX">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0"/>
</GridPane.margin>

View File

@ -18,7 +18,7 @@
<RowConstraints vgrow="ALWAYS"/>
<RowConstraints vgrow="NEVER"/>
</rowConstraints>
<TextFlow fx:id="headerFX">
<TextFlow style="-fx-font-size: 30;" fx:id="headerFX">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0"/>
</GridPane.margin>

View File

@ -87,3 +87,14 @@ minosoft:main.account.add.mojang.password.label=Password
minosoft:main.account.add.mojang.password.placeholder=********
minosoft:main.account.add.mojang.add_button=Add
minosoft:main.account.add.mojang.cancel_button=Cancel
minosoft:connection.kick.title=Kicked from server
minosoft:connection.kick.header=You got kicked
minosoft:connection.kick.description=You got kicked from %1$s (connected with: %2$s)
minosoft:connection.kick.reconnect_button=Reconnect
minosoft:connection.kick.close_button=Close
minosoft:connection.login_kick.title=Kicked from server
minosoft:connection.login_kick.header=You got kicked
minosoft:connection.login_kick.description=You got kicked while logging in from %1$s (connected with: %2$s)