mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
rewrite handling of server types
Fixes some issues, improves it generally
This commit is contained in:
parent
c76a040930
commit
d9e9de4e86
@ -40,7 +40,6 @@ import de.bixilon.minosoft.gui.eros.main.InfoPane
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.card.FaviconManager.saveFavicon
|
||||
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.main.play.server.type.types.CustomServerType
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.type.types.ServerType
|
||||
import de.bixilon.minosoft.gui.eros.modding.invoker.JavaFXEventListener
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
|
||||
@ -282,20 +281,12 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
|
||||
val actions: Array<Node> = arrayOf(
|
||||
Button("Delete").apply {
|
||||
if (server !is ErosServer) {
|
||||
isDisable = true
|
||||
}
|
||||
val type = serverType
|
||||
isDisable = type.readOnly
|
||||
setOnAction {
|
||||
SimpleErosConfirmationDialog(confirmButtonText = "minosoft:general.delete".toResourceLocation(), description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), onConfirm = {
|
||||
val type = serverType
|
||||
if (type !is CustomServerType) {
|
||||
return@SimpleErosConfirmationDialog
|
||||
}
|
||||
type.servers.remove(server)
|
||||
}).show()
|
||||
SimpleErosConfirmationDialog(confirmButtonText = "minosoft:general.delete".toResourceLocation(), description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), onConfirm = { type.remove(server) }).show()
|
||||
}
|
||||
ctext = TranslatableComponents.GENERAL_DELETE
|
||||
isDisable = serverType.readOnly
|
||||
},
|
||||
Button("Edit").apply {
|
||||
if (server !is ErosServer) {
|
||||
@ -402,13 +393,8 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
|
||||
@FXML
|
||||
fun addServer() {
|
||||
ServerModifyDialog(onUpdate = { name, address, forcedVersion, profiles, queryVersion ->
|
||||
val type = serverType
|
||||
if (type !is CustomServerType) {
|
||||
return@ServerModifyDialog
|
||||
}
|
||||
type.servers += ErosServer(profile = ErosProfileManager.selected, name = ChatComponent.of(name), address = address, forcedVersion = forcedVersion, profiles = profiles.toMutableMap(), queryVersion = queryVersion)
|
||||
}).show()
|
||||
val type = serverType ?: return
|
||||
ServerModifyDialog(onUpdate = type::add).show()
|
||||
}
|
||||
|
||||
override fun refresh() {
|
||||
|
@ -21,10 +21,13 @@ import de.bixilon.kutil.observer.list.ListObserver.Companion.observeList
|
||||
import de.bixilon.kutil.observer.list.ListObserver.Companion.observedList
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfile
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.ErosServer
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard
|
||||
import de.bixilon.minosoft.protocol.network.connection.status.StatusConnectionStates
|
||||
import de.bixilon.minosoft.protocol.versions.Version
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import org.kordamp.ikonli.Ikon
|
||||
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
|
||||
@ -42,6 +45,7 @@ object CustomServerType : ServerType {
|
||||
ErosProfileManager::selected.observe(this, true) { profile ->
|
||||
servers.clear()
|
||||
servers += ErosProfileManager.selected.server.entries
|
||||
this.profile = profile
|
||||
|
||||
profile.server::entries.observeList(this) {
|
||||
if (profile !== this.profile) throw RemoveObserver()
|
||||
@ -63,4 +67,13 @@ object CustomServerType : ServerType {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun remove(server: AbstractServer) {
|
||||
profile?.server?.entries?.remove(server)
|
||||
}
|
||||
|
||||
override fun add(name: String, address: String, forcedVersion: Version?, profiles: Map<ResourceLocation, String>, queryVersion: Boolean) {
|
||||
val profile = this.profile ?: return
|
||||
profile.server.entries += ErosServer(profile = profile, name = ChatComponent.of(name), address = address, forcedVersion = forcedVersion, profiles = profiles.toMutableMap(), queryVersion = queryVersion)
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,13 @@
|
||||
package de.bixilon.minosoft.gui.eros.main.play.server.type.types
|
||||
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedListOf
|
||||
import de.bixilon.kutil.exception.Broken
|
||||
import de.bixilon.kutil.observer.list.ListObserver.Companion.observedList
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard
|
||||
import de.bixilon.minosoft.protocol.protocol.LANServerListener
|
||||
import de.bixilon.minosoft.protocol.versions.Version
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import org.kordamp.ikonli.Ikon
|
||||
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
|
||||
@ -34,4 +36,7 @@ object LANServerType : ServerType {
|
||||
override fun refresh(cards: List<ServerCard>) {
|
||||
LANServerListener.clear()
|
||||
}
|
||||
|
||||
override fun remove(server: AbstractServer) = Broken("read only?")
|
||||
override fun add(name: String, address: String, forcedVersion: Version?, profiles: Map<ResourceLocation, String>, queryVersion: Boolean) = Broken("read only")
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
* 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.
|
||||
*
|
||||
@ -15,7 +15,9 @@ package de.bixilon.minosoft.gui.eros.main.play.server.type.types
|
||||
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.AbstractServer
|
||||
import de.bixilon.minosoft.data.language.translate.Translatable
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard
|
||||
import de.bixilon.minosoft.protocol.versions.Version
|
||||
import org.kordamp.ikonli.Ikon
|
||||
|
||||
interface ServerType : Translatable {
|
||||
@ -27,6 +29,9 @@ interface ServerType : Translatable {
|
||||
|
||||
fun refresh(cards: List<ServerCard>)
|
||||
|
||||
fun remove(server: AbstractServer)
|
||||
fun add(name: String, address: String, forcedVersion: Version?, profiles: Map<ResourceLocation, String>, queryVersion: Boolean)
|
||||
|
||||
|
||||
companion object {
|
||||
val TYPES = setOf(
|
||||
|
Loading…
x
Reference in New Issue
Block a user