From fb0778a309d609ed56a38272634fc93e465ae18c Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Wed, 3 Jul 2024 17:36:08 +0200 Subject: [PATCH] add hover warning to connect button when minosoft can not connect to it --- .../main/play/server/ServerListController.kt | 18 +++++++++---- .../main/play/server/card/ConnectError.kt | 26 +++++++++++++++++++ .../eros/main/play/server/card/ServerCard.kt | 13 +++++----- .../minosoft/gui/eros/util/JavaFXUtil.kt | 9 ++++++- .../resources/assets/minosoft/eros/style.css | 14 +++++++++- .../assets/minosoft/language/en_us.lang | 3 +++ 6 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ConnectError.kt diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt index 7e65fe36c..5311805fe 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 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. * @@ -59,6 +59,7 @@ import javafx.scene.Node import javafx.scene.control.Button import javafx.scene.control.CheckBox import javafx.scene.control.ListView +import javafx.scene.control.Tooltip import javafx.scene.input.KeyCode import javafx.scene.layout.Pane @@ -109,7 +110,7 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable { return@setOnMouseClicked } val card = controller.item ?: return@setOnMouseClicked - if (!card.canConnect(accountProfile.selected ?: return@setOnMouseClicked)) { + if (card.canConnect(accountProfile.selected) != null) { return@setOnMouseClicked } @@ -334,14 +335,21 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable { isDisable = true connect(serverCard) } + + isDisable = true // temp state val selected = account.selected - isDisable = selected != null && !serverCard.canConnect(selected) // ToDo: Also disable, if currently connecting ctext = CONNECT - serverCard.ping::state.observeFX(serverCard) { isDisable = selected == null || !serverCard.canConnect(selected) } + serverCard.ping::state.observeFX(serverCard, instant = true) { + val error = serverCard.canConnect(selected) + isDisable = error != null + val tooltip = if (error == null) null else Tooltip().apply { ctext = error; styleClass += "tooltip-error" } + Tooltip.install(serverInfoFX, tooltip) // can not add to the button, because java fx sucks. disabled nodes don't get click/hover events + } }, ) + serverInfoFX.update(serverCard, SERVER_INFO_PROPERTIES, actions) } @@ -422,7 +430,7 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable { TranslatableComponents.GENERAL_EMPTY to { " " }, - "minosoft:server_info.remote_version".toResourceLocation() to { it.ping.serverVersion ?: "unknown" }, + "minosoft:server_info.remote_version".toResourceLocation() to { it.ping.serverVersion ?: "§cunknown\nPlease force a specific version!" }, "minosoft:server_info.remote_brand".toResourceLocation() to { it.ping.status?.serverBrand }, "minosoft:server_info.players_online".toResourceLocation() to { it.ping.status?.let { status -> "${status.usedSlots?.thousands()} / ${status.slots?.thousands()}" } }, "minosoft:server_info.ping".toResourceLocation() to { it.ping.pong?.latency?.formatNanos() }, diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ConnectError.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ConnectError.kt new file mode 100644 index 000000000..70a1def68 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ConnectError.kt @@ -0,0 +1,26 @@ +/* + * Minosoft + * Copyright (C) 2020-2024 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.main.play.server.card + +import de.bixilon.minosoft.data.language.translate.Translatable +import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft + +enum class ConnectError : Translatable { + NO_ACCOUNT, + ALREADY_CONNECTED, + UNKNOWN_VERSION, + ; + + override val translationKey = minosoft("server_list.error.${name.lowercase()}") +} diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCard.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCard.kt index ce2f98333..dd02ed4c6 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCard.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCard.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 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. * @@ -44,14 +44,13 @@ class ServerCard( } - fun canConnect(account: Account): Boolean { - if (server in account.connections) { - return false - } + fun canConnect(account: Account?): ConnectError? { + if (account == null) return ConnectError.NO_ACCOUNT + if (server in account.connections) return ConnectError.ALREADY_CONNECTED if (server.forcedVersion == null && ping.serverVersion == null) { - return false + return ConnectError.UNKNOWN_VERSION } - return true + return null } diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt b/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt index 4caf383d0..26df819d8 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/util/JavaFXUtil.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 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. * @@ -45,6 +45,7 @@ import javafx.scene.control.Alert import javafx.scene.control.Labeled import javafx.scene.control.TableColumnBase import javafx.scene.control.TextField +import javafx.scene.control.Tooltip import javafx.scene.image.Image import javafx.scene.input.KeyCode import javafx.scene.input.KeyEvent @@ -166,6 +167,12 @@ object JavaFXUtil { this.text = IntegratedLanguage.LANGUAGE.translate(value).message } + var Tooltip.ctext: Any? + get() = this.text + set(value) { + this.text = IntegratedLanguage.LANGUAGE.translate(value).message + } + var TableColumnBase<*, *>.ctext: Any? get() = this.text set(value) { diff --git a/src/main/resources/assets/minosoft/eros/style.css b/src/main/resources/assets/minosoft/eros/style.css index 739a71fdb..0ab5ebda4 100644 --- a/src/main/resources/assets/minosoft/eros/style.css +++ b/src/main/resources/assets/minosoft/eros/style.css @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 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. * @@ -350,3 +350,15 @@ .progress-bar > .track { -fx-background-color: -secondary-color; } + + +.tooltip { + -fx-background-color: -secondary-color; + -fx-border-radius: 2px; + -fx-border-width: 1px; + -fx-border-color: -secondary-text-color; +} + +.tooltip-error { + -fx-text-fill: #ff0000; +} diff --git a/src/main/resources/assets/minosoft/language/en_us.lang b/src/main/resources/assets/minosoft/language/en_us.lang index 8ff626049..22a70ee69 100644 --- a/src/main/resources/assets/minosoft/language/en_us.lang +++ b/src/main/resources/assets/minosoft/language/en_us.lang @@ -86,6 +86,9 @@ minosoft:server_list.button.edit=Edit minosoft:server_list.refresh.header=Refresh minosoft:server_list.refresh.text1=Get the latest minosoft:server_list.refresh.text2=information +minosoft:server_list.error.no_account=You don't have an account selected!\nPlease click on the minosoft icon in the right top corner. +minosoft:server_list.error.already_connected=You are already connected with the selected account. Please choose a different one! +minosoft:server_list.error.unknown_version=The server is using an version that minosoft does not support (yet)!\nPlease edit the server and try forcing a different version.\nFeel free to add that version to minosoft (PR)