diff --git a/src/main/java/de/bixilon/minosoft/data/registries/identified/Namespaces.kt b/src/main/java/de/bixilon/minosoft/data/registries/identified/Namespaces.kt index 778782b6e..6d6264c88 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/identified/Namespaces.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/identified/Namespaces.kt @@ -31,4 +31,8 @@ object Namespaces { fun minosoft(path: String): ResourceLocation { return ResourceLocation(MINOSOFT, path) } + + fun i18n(path: String): ResourceLocation { + return minosoft(path) + } } diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/dialog/ServerModifyDialog.kt b/src/main/java/de/bixilon/minosoft/gui/eros/dialog/ServerModifyDialog.kt index 8ab268884..939313eaa 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/dialog/ServerModifyDialog.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/dialog/ServerModifyDialog.kt @@ -16,7 +16,6 @@ package de.bixilon.minosoft.gui.eros.dialog import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.kutil.primitive.BooleanUtil.decide -import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.ErosServer import de.bixilon.minosoft.data.registries.identified.ResourceLocation @@ -27,13 +26,17 @@ 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.placeholder import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text +import de.bixilon.minosoft.gui.eros.util.cell.VersionListCell import de.bixilon.minosoft.protocol.versions.Version import de.bixilon.minosoft.protocol.versions.VersionTypes import de.bixilon.minosoft.protocol.versions.Versions import de.bixilon.minosoft.util.DNSUtil import de.bixilon.minosoft.util.KUtil.toResourceLocation import javafx.fxml.FXML -import javafx.scene.control.* +import javafx.scene.control.Button +import javafx.scene.control.CheckBox +import javafx.scene.control.ComboBox +import javafx.scene.control.TextField import javafx.scene.text.TextFlow /** @@ -132,20 +135,7 @@ class ServerModifyDialog( } } - forcedVersionFX.setCellFactory { - object : ListCell() { - override fun updateItem(version: Version?, empty: Boolean) { - super.updateItem(version, empty) - version ?: return - - text = if (version == Versions.AUTOMATIC) { - Minosoft.LANGUAGE_MANAGER.forceTranslate(VERSION_AUTOMATIC).message - } else { - "${version.name} (${version.type.name.lowercase()})" - } - } - } - } + forcedVersionFX.setCellFactory { VersionListCell() } forcedVersionFX.selectionModel.selectedItemProperty().addListener { _, _, next -> if (next == Versions.AUTOMATIC) { optionQueryVersionFX.isSelected = true @@ -226,7 +216,7 @@ class ServerModifyDialog( private val SERVER_ADDRESS_LABEL = "minosoft:modify_server.address.label".toResourceLocation() private val SERVER_ADDRESS_PLACEHOLDER = "minosoft:modify_server.address.placeholder".toResourceLocation() private val FORCED_VERSION_LABEL = "minosoft:modify_server.forced_version.label".toResourceLocation() - private val VERSION_AUTOMATIC = "minosoft:modify_server.forced_version.automatic".toResourceLocation() + val VERSION_AUTOMATIC = "minosoft:modify_server.forced_version.automatic".toResourceLocation() private val SHOW_RELEASES = "minosoft:modify_server.forced_version.releases".toResourceLocation() private val SHOW_SNAPSHOTS = "minosoft:modify_server.forced_version.snapshots".toResourceLocation() private val PROFILES_LABEL = "minosoft:modify_server.profiles.label".toResourceLocation() diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/dialog/profiles/ProfileSelectDialog.kt b/src/main/java/de/bixilon/minosoft/gui/eros/dialog/profiles/ProfileSelectDialog.kt index 48cfee495..82c70baa6 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/dialog/profiles/ProfileSelectDialog.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/dialog/profiles/ProfileSelectDialog.kt @@ -13,17 +13,20 @@ package de.bixilon.minosoft.gui.eros.dialog.profiles +import de.bixilon.kutil.cast.CastUtil.nullCast import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.config.profile.ProfileType import de.bixilon.minosoft.config.profile.manager.ProfileManagers import de.bixilon.minosoft.data.language.translate.Translatable import de.bixilon.minosoft.data.registries.identified.Identified +import de.bixilon.minosoft.data.registries.identified.Namespaces.i18n import de.bixilon.minosoft.data.registries.identified.ResourceLocation 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.gui.eros.util.cell.LabeledListCell import de.bixilon.minosoft.util.KUtil.toResourceLocation import javafx.fxml.FXML import javafx.scene.control.* @@ -122,7 +125,7 @@ class ProfileSelectDialog( init { graphic = label - comboBox.maxWidth = Double.MAX_VALUE + comboBox.maxWidth = -1.0 selectedProperty().addListener { _, _, _ -> cancelEdit() } comboBox.selectionModel.selectedItemProperty().addListener { _, _, selected -> commitEdit(selected) @@ -163,9 +166,10 @@ class ProfileSelectDialog( private inner class IdentifiedCell : EditTableCell() { init { + comboBox.setCellFactory { LabeledListCell { it.nullCast()?.identifier } } comboBox.selectionModel.selectedItemProperty().addListener { _, previous, selected -> if (previous == null && selected != null && this.index == tableView.items.size - 1) { - tableView.items += ProfileEntry(null, "") + tableView.items += ProfileEntry(null, null) tableView.refresh() } } @@ -181,7 +185,7 @@ class ProfileSelectDialog( } for (manager in ProfileManagers) { if (type != manager.type && manager.type in out) continue - comboBox.items += type + comboBox.items += manager.type } } comboBox.selectionModel.select(type) @@ -192,7 +196,7 @@ class ProfileSelectDialog( override fun update(entry: ProfileEntry) = updateItem(entry.type) override fun updateItem(item: Identified?) { - label.ctext = item?.toString() ?: CLICK_ME_TO_ADD + label.ctext = item?.identifier?.toString() ?: CLICK_ME_TO_ADD tableRow.item.type = item.unsafeCast() } } @@ -212,21 +216,12 @@ class ProfileSelectDialog( comboBox.selectionModel.select(SelectSpecialOptions.NONE) } styleClass.add("table-row-cell") + comboBox.setCellFactory { LabeledListCell { it } } + comboBox.width } override fun startEdit() { comboBox.items.clear() - comboBox.setCellFactory { - object : ListCell() { - override fun updateItem(item: Any?, empty: Boolean) { - super.updateItem(item, empty) - if (empty) { - return - } - ctext = item - } - } - } comboBox.items += SelectSpecialOptions.NONE comboBox.items += SelectSpecialOptions.CREATE @@ -253,8 +248,8 @@ class ProfileSelectDialog( private enum class SelectSpecialOptions(override val translationKey: ResourceLocation?) : Translatable { - NONE("minosoft:general.dialog.profile.select.none".toResourceLocation()), - CREATE("minosoft:general.dialog.profile.select.create".toResourceLocation()), + NONE(i18n("general.dialog.profile.select.none")), + CREATE(i18n("general.dialog.profile.select.create")), ; } } diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/util/cell/LabeledListCell.kt b/src/main/java/de/bixilon/minosoft/gui/eros/util/cell/LabeledListCell.kt new file mode 100644 index 000000000..64d60cda4 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/eros/util/cell/LabeledListCell.kt @@ -0,0 +1,32 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 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.util.cell + +import de.bixilon.minosoft.data.text.EmptyComponent +import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext +import javafx.scene.control.ListCell + +open class LabeledListCell( + val texter: (T) -> Any?, +) : ListCell() { + + override fun updateItem(item: T, empty: Boolean) { + super.updateItem(item, empty) + ctext = if (empty || item == null) { + EmptyComponent + } else { + texter.invoke(item) ?: EmptyComponent + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/util/cell/VersionListCell.kt b/src/main/java/de/bixilon/minosoft/gui/eros/util/cell/VersionListCell.kt new file mode 100644 index 000000000..b5e2170bd --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/eros/util/cell/VersionListCell.kt @@ -0,0 +1,27 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 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.util.cell + +import de.bixilon.minosoft.Minosoft +import de.bixilon.minosoft.gui.eros.dialog.ServerModifyDialog +import de.bixilon.minosoft.protocol.versions.Version +import de.bixilon.minosoft.protocol.versions.Versions + +class VersionListCell : LabeledListCell({ + if (it == Versions.AUTOMATIC) { + Minosoft.LANGUAGE_MANAGER.forceTranslate(ServerModifyDialog.VERSION_AUTOMATIC).message + } else { + "${it.name} (${it.type.name.lowercase()})" + } +})