eros: allow double click on server card to connect

This commit is contained in:
Bixilon 2021-10-21 12:53:31 +02:00
parent 254dc29c1d
commit 4a05a34ef3
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 86 additions and 58 deletions

View File

@ -17,10 +17,10 @@ object StaticConfiguration {
const val DEBUG_MODE = true // if true, additional checks will be made to validate data, ... Decreases performance
const val BIOME_DEBUG_MODE = false // colors all biomes according to the biome hashCode
const val DEBUG_SLOW_LOADING = false // if true, many Thread.sleep will be executed and the start will be delayed (by a lot)
const val SHOW_LOG_MESSAGES_IN_CHAT = true // prints all console messages in the chat box
const val REPLACE_SYSTEM_OUT_STREAMS = true
const val SHOW_LOG_MESSAGES_IN_CHAT = false // prints all console messages in the chat box
const val REPLACE_SYSTEM_OUT_STREAMS = true // Replace System.out and System.err with the custom Log system ones
@Deprecated(message = "Just for hud development purposes")
@Deprecated(message = "Just for hud development purposes; Will be removed once hud is merged")
const val HUD_ONLY = false
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.config.server
import com.squareup.moshi.Json
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.data.assets.AssetsUtil
import de.bixilon.minosoft.data.assets.FileAssetsManager
import de.bixilon.minosoft.data.registries.versions.Version
@ -21,6 +22,7 @@ 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.play.PlayConnection
import de.bixilon.minosoft.protocol.network.connection.status.StatusConnection
import de.bixilon.minosoft.protocol.network.connection.status.StatusConnectionStates
import de.bixilon.minosoft.util.KUtil.synchronizedSetOf
import java.util.*
@ -59,6 +61,11 @@ data class Server(
@Transient
var card: ServerCard? = null
val canConnect: Boolean
get() = ping?.state === StatusConnectionStates.PING_DONE
&& ((forcedVersion ?: ping?.serverVersion) != null)
&& Minosoft.config.config.account.selected?.connections?.containsKey(this) == false
init {
if (id > nextServerId) {
nextServerId = id + 1

View File

@ -34,6 +34,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,23 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
addServerButtonFX.isVisible = !value
}
override fun init() {
serverListViewFX.setCellFactory { ServerCardController.build() }
serverListViewFX.setCellFactory {
val controller = ServerCardController.build()
controller.root.setOnMouseClicked {
if (it.clickCount != 2) {
return@setOnMouseClicked
}
val server = controller.lastServerCard?.server ?: return@setOnMouseClicked
if (!server.canConnect) {
return@setOnMouseClicked
}
connect(server)
}
return@setCellFactory controller
}
refreshList()
@ -84,6 +99,47 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
}
}
fun connect(server: Server, ping: StatusConnection? = server.ping) {
val pingVersion = ping?.serverVersion ?: return
Eros.mainErosController.verifyAccount { account ->
DefaultThreadPool += {
val connection = PlayConnection(
address = server.ping?.realAddress ?: DNSUtil.getServerAddress(server.address),
account = account,
version = server.forcedVersion ?: pingVersion,
)
account.connections[server] = connection
server.connections += connection
connection.registerEvent(CallbackEventInvoker.of<PlayConnectionStateChangeEvent> { event ->
if (event.state.disconnected) {
account.connections -= server
server.connections -= connection
}
JavaFXUtil.runLater { updateServer(server) }
})
connection.registerEvent(JavaFXEventInvoker.of<KickEvent> { event ->
KickDialog(
title = "minosoft:connection.kick.title".toResourceLocation(),
header = "minosoft:connection.kick.header".toResourceLocation(),
description = TranslatableComponents.CONNECTION_KICK_DESCRIPTION(server, account),
reason = event.reason,
).show()
})
connection.registerEvent(JavaFXEventInvoker.of<LoginKickEvent> { event ->
KickDialog(
title = "minosoft:connection.login_kick.title".toResourceLocation(),
header = "minosoft:connection.login_kick.header".toResourceLocation(),
description = TranslatableComponents.CONNECTION_LOGIN_KICK_DESCRIPTION(server, account),
reason = event.reason,
).show()
})
connection.connect()
}
}
}
override fun postInit() {
root.setOnKeyPressed { serverListViewFX.selectionModel.select(null) } // ToDo: Only on escape; not working
}
@ -229,48 +285,9 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
it.add(Button("Connect").apply {
setOnAction {
isDisable = true
val pingVersion = ping?.serverVersion ?: return@setOnAction
Eros.mainErosController.verifyAccount { account ->
DefaultThreadPool += {
val connection = PlayConnection(
address = serverCard.server.ping?.realAddress ?: DNSUtil.getServerAddress(serverCard.server.address),
account = account,
version = serverCard.server.forcedVersion ?: pingVersion,
)
account.connections[serverCard.server] = connection
serverCard.server.connections += connection
connection.registerEvent(CallbackEventInvoker.of<PlayConnectionStateChangeEvent> { event ->
if (event.state.disconnected) {
account.connections -= serverCard.server
serverCard.server.connections -= connection
connect(serverCard.server, ping)
}
JavaFXUtil.runLater { updateServer(serverCard.server) }
})
connection.registerEvent(JavaFXEventInvoker.of<KickEvent> { event ->
KickDialog(
title = "minosoft:connection.kick.title".toResourceLocation(),
header = "minosoft:connection.kick.header".toResourceLocation(),
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".toResourceLocation(),
header = "minosoft:connection.login_kick.header".toResourceLocation(),
description = TranslatableComponents.CONNECTION_LOGIN_KICK_DESCRIPTION(serverCard.server, account),
reason = event.reason,
).show()
})
connection.connect()
}
}
}
isDisable = ping?.state !== StatusConnectionStates.PING_DONE ||
((serverCard.server.forcedVersion ?: ping.serverVersion) == null) ||
Minosoft.config.config.account.selected?.connections?.containsKey(serverCard.server) == true
isDisable = !serverCard.server.canConnect
// ToDo: Also disable, if currently connecting
}, 4, 0)

View File

@ -50,8 +50,8 @@ class ServerCardController : AbstractCard<ServerCard>() {
@FXML private lateinit var serverVersionFX: Label
private var lastServerCard: ServerCard? = null
var lastServerCard: ServerCard? = null
private set
override fun clear() {
faviconFX.image = JavaFXUtil.MINOSOFT_LOGO

View File

@ -120,14 +120,14 @@ class Frustum(private val camera: Camera) {
for (i in 0 until Planes.VALUES.size) {
if (
(planes[i] dot Vec4d(min.x, min.y, min.z, 1.0f)) < 0.0f &&
(planes[i] dot Vec4d(max.x, min.y, min.z, 1.0f)) < 0.0f &&
(planes[i] dot Vec4d(min.x, max.y, min.z, 1.0f)) < 0.0f &&
(planes[i] dot Vec4d(max.x, max.y, min.z, 1.0f)) < 0.0f &&
(planes[i] dot Vec4d(min.x, min.y, max.z, 1.0f)) < 0.0f &&
(planes[i] dot Vec4d(max.x, min.y, max.z, 1.0f)) < 0.0f &&
(planes[i] dot Vec4d(min.x, max.y, max.z, 1.0f)) < 0.0f &&
(planes[i] dot Vec4d(max.x, max.y, max.z, 1.0f)) < 0.0f
(planes[i] dot Vec4d(min.x, min.y, min.z, 1.0f)) < 0.0f
&& (planes[i] dot Vec4d(max.x, min.y, min.z, 1.0f)) < 0.0f
&& (planes[i] dot Vec4d(min.x, max.y, min.z, 1.0f)) < 0.0f
&& (planes[i] dot Vec4d(max.x, max.y, min.z, 1.0f)) < 0.0f
&& (planes[i] dot Vec4d(min.x, min.y, max.z, 1.0f)) < 0.0f
&& (planes[i] dot Vec4d(max.x, min.y, max.z, 1.0f)) < 0.0f
&& (planes[i] dot Vec4d(min.x, max.y, max.z, 1.0f)) < 0.0f
&& (planes[i] dot Vec4d(max.x, max.y, max.z, 1.0f)) < 0.0f
) {
return false
}

View File

@ -18,6 +18,8 @@ import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.data.text.BaseComponent
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.modding.event.events.InternalMessageReceiveEvent
import de.bixilon.minosoft.terminal.CLI
import de.bixilon.minosoft.terminal.RunConfiguration
import java.io.PrintStream
import java.io.PrintWriter
@ -85,8 +87,10 @@ object Log {
stream.println(message.ansiColoredMessage)
// val cliConnection = CLI.getCurrentConnection()
//cliConnection?.fireEvent(InternalMessageReceiveEvent(cliConnection, messageToSend.message))
if (StaticConfiguration.SHOW_LOG_MESSAGES_IN_CHAT) {
val cliConnection = CLI.getCurrentConnection()
cliConnection?.fireEvent(InternalMessageReceiveEvent(cliConnection, messageToSend.message))
}
} catch (exception: Throwable) {
SYSTEM_ERR_STREAM.println("Can not send log message $messageToSend!")
}