mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
fix some eros bugs
This commit is contained in:
parent
4214b37176
commit
3fa1d16ebc
@ -20,7 +20,7 @@ import javafx.scene.layout.HBox
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
|
||||
abstract class AbstractCard<T> : ListCell<T>(), Initializable {
|
||||
abstract class AbstractCardController<T> : ListCell<T>(), Initializable {
|
||||
@FXML lateinit var root: HBox
|
||||
|
||||
override fun initialize(url: URL?, resourceBundle: ResourceBundle?) {
|
@ -16,14 +16,14 @@ package de.bixilon.minosoft.gui.eros.main.account
|
||||
import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.TranslatableComponents
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCard
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCardController
|
||||
import de.bixilon.minosoft.gui.eros.card.CardFactory
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import javafx.fxml.FXML
|
||||
import javafx.scene.text.TextFlow
|
||||
|
||||
class AccountCardController : AbstractCard<Account>() {
|
||||
class AccountCardController : AbstractCardController<Account>() {
|
||||
@FXML private lateinit var connectionCountFX: TextFlow
|
||||
@FXML private lateinit var stateFX: TextFlow
|
||||
@FXML private lateinit var accountNameFX: TextFlow
|
||||
|
@ -144,10 +144,10 @@ class AccountController : EmbeddedJavaFXController<Pane>() {
|
||||
setOnAction {
|
||||
SimpleErosConfirmationDialog(
|
||||
onConfirm = {
|
||||
profile.entries -= account.id
|
||||
if (profile.selected == account) {
|
||||
profile.selected = null
|
||||
}
|
||||
profile.entries -= account.id
|
||||
JavaFXUtil.runLater { refreshList() }
|
||||
}
|
||||
).show()
|
||||
|
@ -16,7 +16,7 @@ package de.bixilon.minosoft.gui.eros.main.account
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.profile.delegate.watcher.entry.MapProfileDelegateWatcher.Companion.profileWatchMapFX
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCard
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCardController
|
||||
import de.bixilon.minosoft.gui.eros.card.CardFactory
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
@ -24,7 +24,7 @@ import javafx.fxml.FXML
|
||||
import javafx.scene.text.TextFlow
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
|
||||
class AccountTypeCardController : AbstractCard<ErosAccountType<*>>() {
|
||||
class AccountTypeCardController : AbstractCardController<ErosAccountType<*>>() {
|
||||
@FXML private lateinit var iconFX: FontIcon
|
||||
@FXML private lateinit var headerFX: TextFlow
|
||||
@FXML private lateinit var textFX: TextFlow
|
||||
|
@ -37,6 +37,7 @@ import de.bixilon.minosoft.modding.event.events.connection.status.StatusConnecti
|
||||
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates.Companion.disconnected
|
||||
import de.bixilon.minosoft.protocol.network.connection.status.StatusConnection
|
||||
import de.bixilon.minosoft.protocol.network.connection.status.StatusConnectionStates
|
||||
import de.bixilon.minosoft.util.DNSUtil
|
||||
import de.bixilon.minosoft.util.KUtil.decide
|
||||
@ -73,9 +74,9 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
override fun init() {
|
||||
val erosProfile = ErosProfileManager.selected
|
||||
val serverConfig = erosProfile.server.list
|
||||
serverConfig::hideOffline.profileWatchFX(this, true) { hideOfflineFX.isSelected = it }
|
||||
serverConfig::hideFull.profileWatchFX(this, true) { hideFullFX.isSelected = it }
|
||||
serverConfig::hideEmpty.profileWatchFX(this, true) { hideEmptyFX.isSelected = it }
|
||||
serverConfig::hideOffline.profileWatchFX(this, true) { hideOfflineFX.isSelected = it;refreshList() }
|
||||
serverConfig::hideFull.profileWatchFX(this, true) { hideFullFX.isSelected = it;refreshList() }
|
||||
serverConfig::hideEmpty.profileWatchFX(this, true) { hideEmptyFX.isSelected = it;refreshList() }
|
||||
|
||||
hideOfflineFX.setOnAction { ErosProfileManager.selected.server.list.hideOffline = hideOfflineFX.isSelected }
|
||||
hideFullFX.setOnAction { ErosProfileManager.selected.server.list.hideFull = hideFullFX.isSelected }
|
||||
@ -85,12 +86,13 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
val accountProfile = erosProfile.general.accountProfile
|
||||
serverListViewFX.setCellFactory {
|
||||
val controller = ServerCardController.build()
|
||||
controller.serverList = this
|
||||
|
||||
controller.root.setOnMouseClicked {
|
||||
if (it.clickCount != 2) {
|
||||
return@setOnMouseClicked
|
||||
}
|
||||
val card = controller.lastServerCard ?: return@setOnMouseClicked
|
||||
val card = controller.serverCard ?: return@setOnMouseClicked
|
||||
if (!card.canConnect(accountProfile.selected ?: return@setOnMouseClicked)) {
|
||||
return@setOnMouseClicked
|
||||
}
|
||||
@ -168,6 +170,9 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
|
||||
@FXML
|
||||
fun refreshList() {
|
||||
if (!this::serverType.isInitialized) {
|
||||
return
|
||||
}
|
||||
val selected = serverListViewFX.selectionModel.selectedItem
|
||||
serverListViewFX.items.clear()
|
||||
|
||||
@ -183,30 +188,16 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
}
|
||||
|
||||
private fun updateServer(server: Server) {
|
||||
val card = ServerCard.CARDS[server] ?: let {
|
||||
val card = ServerCard(server)
|
||||
card.serverListStatusInvoker = JavaFXEventInvoker.of<StatusConnectionStateChangeEvent>(instantFire = false) { updateServer(server) }
|
||||
card
|
||||
val card = ServerCard.CARDS[server] ?: ServerCard(server).apply {
|
||||
serverListStatusInvoker = JavaFXEventInvoker.of<StatusConnectionStateChangeEvent>(instantFire = false) { updateServer(server) }
|
||||
}
|
||||
val wasSelected = serverListViewFX.selectionModel.selectedItem === card
|
||||
// Platform.runLater {serverListViewFX.items.remove(card)}
|
||||
|
||||
card.ping?.let {
|
||||
if (hideOfflineFX.isSelected && it.error != null) {
|
||||
if (it.hide) {
|
||||
return
|
||||
}
|
||||
|
||||
it.lastServerStatus?.let { status ->
|
||||
val usedSlots = status.usedSlots ?: 0
|
||||
val slots = status.slots ?: 0
|
||||
if (hideFullFX.isSelected && usedSlots >= slots && slots > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (hideEmptyFX.isSelected && usedSlots == 0 && slots > 0) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!serverListViewFX.items.contains(card)) {
|
||||
@ -229,8 +220,6 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
val serverType = serverType
|
||||
val account = ErosProfileManager.selected.general.accountProfile
|
||||
|
||||
val ping = serverCard.ping
|
||||
|
||||
val pane = GridPane()
|
||||
|
||||
AnchorPane.setLeftAnchor(pane, 10.0)
|
||||
@ -320,6 +309,36 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
||||
serverInfoFX.children.setAll(pane)
|
||||
}
|
||||
|
||||
val StatusConnection.hide: Boolean
|
||||
get() {
|
||||
if (hideOfflineFX.isSelected && error != null) {
|
||||
return true
|
||||
}
|
||||
|
||||
lastServerStatus?.let { status ->
|
||||
val usedSlots = status.usedSlots ?: 0
|
||||
val slots = status.slots ?: 0
|
||||
if (hideFullFX.isSelected && usedSlots >= slots && slots > 0) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (hideEmptyFX.isSelected && usedSlots == 0 && slots > 0) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun onPingUpdate(card: ServerCard) {
|
||||
val ping = card.ping ?: return
|
||||
if (ping.hide) {
|
||||
if (serverListViewFX.selectionModel.selectedItem == card) {
|
||||
serverListViewFX.selectionModel.select(null)
|
||||
}
|
||||
serverListViewFX.items.remove(card)
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
fun addServer() {
|
||||
UpdateServerDialog(onUpdate = { name, address, forcedVersion ->
|
||||
|
@ -76,14 +76,12 @@ class ServerCard(
|
||||
|
||||
@Synchronized
|
||||
fun ping(): StatusConnection {
|
||||
var ping = ping
|
||||
if (ping == null) {
|
||||
ping = StatusConnection(server.address)
|
||||
this.ping = ping
|
||||
this.ping?.let { return it }
|
||||
|
||||
val ping = StatusConnection(server.address)
|
||||
serverListStatusInvoker?.let { ping.registerEvent(it) }
|
||||
ping.ping()
|
||||
}
|
||||
|
||||
this.ping = ping
|
||||
return ping
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,9 @@ package de.bixilon.minosoft.gui.eros.main.play.server.card
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCard
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCardController
|
||||
import de.bixilon.minosoft.gui.eros.card.CardFactory
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.ServerListController
|
||||
import de.bixilon.minosoft.gui.eros.modding.invoker.JavaFXEventInvoker
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext
|
||||
@ -36,7 +37,7 @@ import javafx.scene.image.ImageView
|
||||
import javafx.scene.text.TextFlow
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
class ServerCardController : AbstractCard<ServerCard>() {
|
||||
class ServerCardController : AbstractCardController<ServerCard>() {
|
||||
@FXML private lateinit var faviconFX: ImageView
|
||||
@FXML private lateinit var serverNameFX: TextFlow
|
||||
@FXML private lateinit var motdFX: TextFlow
|
||||
@ -44,8 +45,9 @@ class ServerCardController : AbstractCard<ServerCard>() {
|
||||
@FXML private lateinit var playerCountFX: Label
|
||||
@FXML private lateinit var serverVersionFX: Label
|
||||
|
||||
var serverList: ServerListController? = null
|
||||
|
||||
var lastServerCard: ServerCard? = null
|
||||
var serverCard: ServerCard? = null
|
||||
private set
|
||||
|
||||
override fun clear() {
|
||||
@ -58,23 +60,22 @@ class ServerCardController : AbstractCard<ServerCard>() {
|
||||
serverVersionFX.ctext = ""
|
||||
}
|
||||
|
||||
override fun updateItem(card: ServerCard?, empty: Boolean) {
|
||||
super.updateItem(card, empty)
|
||||
override fun updateItem(item: ServerCard?, empty: Boolean) {
|
||||
super.updateItem(item, empty)
|
||||
|
||||
root.isVisible = card != null
|
||||
this.lastServerCard = card
|
||||
card ?: return
|
||||
root.isVisible = item != null
|
||||
this.serverCard = item
|
||||
item ?: return
|
||||
|
||||
serverNameFX.text = card.server.name
|
||||
serverNameFX.text = item.server.name
|
||||
|
||||
card.ping()
|
||||
item.unregister()
|
||||
item.ping()
|
||||
|
||||
card.unregister()
|
||||
item.favicon?.let { faviconFX.image = it }
|
||||
|
||||
card.favicon?.let { faviconFX.image = it }
|
||||
|
||||
card.statusReceiveInvoker = JavaFXEventInvoker.of<ServerStatusReceiveEvent> {
|
||||
if (lastServerCard != card || it.connection.error != null) {
|
||||
item.statusReceiveInvoker = JavaFXEventInvoker.of<ServerStatusReceiveEvent> {
|
||||
if (serverCard != item || it.connection.error != null) {
|
||||
// error already occurred, not setting any data
|
||||
return@of
|
||||
}
|
||||
@ -84,30 +85,34 @@ class ServerCardController : AbstractCard<ServerCard>() {
|
||||
|
||||
faviconFX.image = it.status.favicon?.let { favicon -> Image(ByteArrayInputStream(favicon)) } ?: JavaFXUtil.MINOSOFT_LOGO
|
||||
|
||||
it.status.favicon?.let { favicon -> card.rawFavicon = favicon }
|
||||
it.status.favicon?.let { favicon -> item.rawFavicon = favicon }
|
||||
serverList?.onPingUpdate(item)
|
||||
}
|
||||
|
||||
card.statusUpdateInvoker = JavaFXEventInvoker.of<StatusConnectionStateChangeEvent> {
|
||||
if (lastServerCard != card || it.connection.error != null || it.connection.lastServerStatus != null) {
|
||||
item.statusUpdateInvoker = JavaFXEventInvoker.of<StatusConnectionStateChangeEvent> {
|
||||
if (serverCard != item || it.connection.error != null || it.connection.lastServerStatus != null) {
|
||||
// error or motd is already displayed
|
||||
return@of
|
||||
}
|
||||
motdFX.text = ChatComponent.of(Minosoft.LANGUAGE_MANAGER.translate(it.state))
|
||||
serverList?.onPingUpdate(item)
|
||||
}
|
||||
|
||||
card.statusErrorInvoker = JavaFXEventInvoker.of<ConnectionErrorEvent> {
|
||||
if (lastServerCard != card) {
|
||||
item.statusErrorInvoker = JavaFXEventInvoker.of<ConnectionErrorEvent> {
|
||||
if (serverCard != item) {
|
||||
return@of
|
||||
}
|
||||
motdFX.text = it.exception.text
|
||||
serverList?.onPingUpdate(item)
|
||||
}
|
||||
|
||||
card.pongInvoker = JavaFXEventInvoker.of<StatusPongReceiveEvent> {
|
||||
if (lastServerCard != card || it.connection.error != null) {
|
||||
item.pongInvoker = JavaFXEventInvoker.of<StatusPongReceiveEvent> {
|
||||
if (serverCard != item || it.connection.error != null) {
|
||||
// error already occurred, not setting any data
|
||||
return@of
|
||||
}
|
||||
pingFX.text = "${it.latency} ms"
|
||||
serverList?.onPingUpdate(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
package de.bixilon.minosoft.gui.eros.main.play.server.type
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCard
|
||||
import de.bixilon.minosoft.gui.eros.card.AbstractCardController
|
||||
import de.bixilon.minosoft.gui.eros.card.CardFactory
|
||||
import de.bixilon.minosoft.gui.eros.main.play.server.type.types.ServerType
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text
|
||||
@ -24,7 +24,7 @@ import javafx.fxml.FXML
|
||||
import javafx.scene.text.TextFlow
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
|
||||
class ServerTypeCardController : AbstractCard<ServerType>() {
|
||||
class ServerTypeCardController : AbstractCardController<ServerType>() {
|
||||
@FXML private lateinit var iconFX: FontIcon
|
||||
@FXML private lateinit var headerFX: TextFlow
|
||||
@FXML private lateinit var textFX: TextFlow
|
||||
|
Loading…
x
Reference in New Issue
Block a user