fix some eros bugs

This commit is contained in:
Bixilon 2021-12-06 00:27:01 +01:00
parent 7e81c67bdb
commit c96720a076
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 33 additions and 32 deletions

View File

@ -22,5 +22,5 @@ class LightC {
* In original minecraft this setting is called brightness * In original minecraft this setting is called brightness
* Must be non-negative and may not exceed 1 * Must be non-negative and may not exceed 1
*/ */
var gamma by delegate(0.0f) { check(it in 0.0f..1.0f) { "Gama must be non negative and < 1" } } var gamma by delegate(0.0f) { check(it in 0.0f..1.0f) { "Gamma must be non negative and < 1" } }
} }

View File

@ -23,7 +23,7 @@ import de.bixilon.minosoft.util.enum.ValuesEnum
enum class ErosMainActivities( enum class ErosMainActivities(
val layout: ResourceLocation, val layout: ResourceLocation,
) { ) {
PlAY(PlayController.LAYOUT), PLAY(PlayController.LAYOUT),
SETTINGS("".toResourceLocation()), SETTINGS("".toResourceLocation()),
HELP("".toResourceLocation()), HELP("".toResourceLocation()),
ABOUT("".toResourceLocation()), ABOUT("".toResourceLocation()),

View File

@ -24,8 +24,10 @@ import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.clickable import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.clickable
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext
import de.bixilon.minosoft.terminal.RunConfiguration import de.bixilon.minosoft.terminal.RunConfiguration
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.ShutdownManager import de.bixilon.minosoft.util.ShutdownManager
import de.bixilon.minosoft.util.collections.SynchronizedMap
import de.bixilon.minosoft.util.task.pool.DefaultThreadPool import de.bixilon.minosoft.util.task.pool.DefaultThreadPool
import javafx.application.Platform import javafx.application.Platform
import javafx.fxml.FXML import javafx.fxml.FXML
@ -52,11 +54,12 @@ class MainErosController : JavaFXWindowController() {
private lateinit var iconMap: Map<ErosMainActivities, FontIcon> private lateinit var iconMap: Map<ErosMainActivities, FontIcon>
private val controllers: SynchronizedMap<ErosMainActivities, EmbeddedJavaFXController<*>> = synchronizedMapOf()
private var activity: ErosMainActivities = ErosMainActivities.ABOUT // other value (just not the default) private var activity: ErosMainActivities = ErosMainActivities.ABOUT // other value (just not the default)
set(value) { set(value) {
field = value field = value
contentFX.children.setAll(JavaFXUtil.loadEmbeddedController<EmbeddedJavaFXController<*>>(field.layout).root) contentFX.children.setAll(controllers.getOrPut(value) { JavaFXUtil.loadEmbeddedController(field.layout) }.root)
highlightIcon(iconMap[value]) highlightIcon(iconMap[value])
} }
@ -76,7 +79,7 @@ class MainErosController : JavaFXWindowController() {
logoFX.image = JavaFXUtil.MINOSOFT_LOGO logoFX.image = JavaFXUtil.MINOSOFT_LOGO
versionTextFX.text = RunConfiguration.VERSION_STRING versionTextFX.text = RunConfiguration.VERSION_STRING
iconMap = mapOf( iconMap = mapOf(
ErosMainActivities.PlAY to playIconFX, ErosMainActivities.PLAY to playIconFX,
ErosMainActivities.SETTINGS to settingsIconFX, ErosMainActivities.SETTINGS to settingsIconFX,
ErosMainActivities.HELP to helpIconFX, ErosMainActivities.HELP to helpIconFX,
ErosMainActivities.ABOUT to aboutIconFX, ErosMainActivities.ABOUT to aboutIconFX,
@ -89,7 +92,7 @@ class MainErosController : JavaFXWindowController() {
highlightIcon(playIconFX) highlightIcon(playIconFX)
playIconFX.setOnMouseClicked { playIconFX.setOnMouseClicked {
activity = ErosMainActivities.PlAY activity = ErosMainActivities.PLAY
} }
settingsIconFX.setOnMouseClicked { settingsIconFX.setOnMouseClicked {
// ToDo: activity = ErosMainActivities.SETTINGS // ToDo: activity = ErosMainActivities.SETTINGS
@ -118,7 +121,7 @@ class MainErosController : JavaFXWindowController() {
accountImageFX.clickable() accountImageFX.clickable()
accountNameFX.clickable() accountNameFX.clickable()
activity = ErosMainActivities.PlAY activity = ErosMainActivities.PLAY
} }
override fun postInit() { override fun postInit() {

View File

@ -53,16 +53,22 @@ class PlayController : EmbeddedJavaFXController<Pane>() {
playTypeListViewFX.selectionModel.selectedItemProperty().addListener { _, _, new -> playTypeListViewFX.selectionModel.selectedItemProperty().addListener { _, _, new ->
if (this::currentController.isInitialized) {
currentController.terminate()
}
new ?: return@addListener // Should not happen new ?: return@addListener // Should not happen
if (this::currentController.isInitialized) {
val currentController = this.currentController
if (currentController is ServerListController) {
currentController.serverType = new
currentController.initWatch()
currentController.refreshList()
}
return@addListener
}
currentController = JavaFXUtil.loadEmbeddedController<ServerListController>(ServerListController.LAYOUT).apply { currentController = JavaFXUtil.loadEmbeddedController<ServerListController>(ServerListController.LAYOUT).apply {
serverType = new serverType = new
initWatch() initWatch()
refreshList() refreshList()
playTypeContentFX.children.setAll(this.root)
} }
playTypeContentFX.children.setAll(currentController.root)
} }
playTypeListViewFX.selectionModel.select(0) playTypeListViewFX.selectionModel.select(0)
@ -81,8 +87,6 @@ class PlayController : EmbeddedJavaFXController<Pane>() {
companion object { companion object {
val LAYOUT = "minosoft:eros/main/play/play.fxml".toResourceLocation() val LAYOUT = "minosoft:eros/main/play/play.fxml".toResourceLocation()
private val CUSTOM_SERVER_TYPE = "minosoft:server_type.custom".toResourceLocation()
private val LAN_SERVER_TYPE = "minosoft:server_type.lan".toResourceLocation()
private val REFRESH_HEADER = "minosoft:server_list.refresh.header".toResourceLocation() private val REFRESH_HEADER = "minosoft:server_list.refresh.header".toResourceLocation()
private val REFRESH_TEXT1 = "minosoft:server_list.refresh.text1".toResourceLocation() private val REFRESH_TEXT1 = "minosoft:server_list.refresh.text1".toResourceLocation()
private val REFRESH_TEXT2 = "minosoft:server_list.refresh.text2".toResourceLocation() private val REFRESH_TEXT2 = "minosoft:server_list.refresh.text2".toResourceLocation()

View File

@ -64,12 +64,12 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
@FXML private lateinit var serverListViewFX: ListView<ServerCard> @FXML private lateinit var serverListViewFX: ListView<ServerCard>
@FXML private lateinit var serverInfoFX: AnchorPane @FXML private lateinit var serverInfoFX: AnchorPane
lateinit var serverType: ServerType var serverType: ServerType? = null
var readOnly: Boolean = false
set(value) { set(value) {
check(value != null)
field = value field = value
addServerButtonFX.isVisible = !value
addServerButtonFX.isVisible = !value.readOnly
} }
override fun init() { override fun init() {
@ -157,7 +157,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
} }
fun initWatch() { fun initWatch() {
serverType::servers.watchListFX(this) { serverType!!::servers.watchListFX(this) {
while (it.next()) { while (it.next()) {
for (removed in it.removed) { for (removed in it.removed) {
serverListViewFX.items -= ServerCard.CARDS.remove(removed) serverListViewFX.items -= ServerCard.CARDS.remove(removed)
@ -165,6 +165,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
} }
for (added in it.addedSubList) { for (added in it.addedSubList) {
updateServer(added) updateServer(added)
serverListViewFX.refresh()
} }
} }
} }
@ -172,13 +173,13 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
@FXML @FXML
fun refreshList() { fun refreshList() {
if (!this::serverType.isInitialized) { if (serverType == null) {
return return
} }
val selected = serverListViewFX.selectionModel.selectedItem val selected = serverListViewFX.selectionModel.selectedItem
serverListViewFX.items.clear() serverListViewFX.items.clear()
for (server in serverType.servers) { for (server in serverType!!.servers) {
updateServer(server) updateServer(server)
} }
@ -251,7 +252,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
it.columnConstraints += ColumnConstraints() it.columnConstraints += ColumnConstraints()
it.columnConstraints += ColumnConstraints(0.0, -1.0, Double.POSITIVE_INFINITY, Priority.ALWAYS, HPos.LEFT, true) it.columnConstraints += ColumnConstraints(0.0, -1.0, Double.POSITIVE_INFINITY, Priority.ALWAYS, HPos.LEFT, true)
if (!readOnly) { if (!serverType!!.readOnly) {
it.add(Button("Delete").apply { it.add(Button("Delete").apply {
setOnAction { setOnAction {
SimpleErosConfirmationDialog(confirmButtonText = "minosoft:general.delete".toResourceLocation(), description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), onConfirm = { SimpleErosConfirmationDialog(confirmButtonText = "minosoft:general.delete".toResourceLocation(), description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), onConfirm = {
@ -344,12 +345,12 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
@FXML @FXML
fun addServer() { fun addServer() {
UpdateServerDialog(onUpdate = { name, address, forcedVersion -> UpdateServerDialog(onUpdate = { name, address, forcedVersion ->
serverType.servers += Server(name = ChatComponent.of(name), address = address, forcedVersion = forcedVersion) serverType!!.servers += Server(name = ChatComponent.of(name), address = address, forcedVersion = forcedVersion)
}).show() }).show()
} }
override fun refresh() { override fun refresh() {
serverType.refresh(serverListViewFX.items) serverType!!.refresh(serverListViewFX.items)
} }

View File

@ -7,25 +7,16 @@ 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.network.connection.status.StatusConnectionStates
import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.delegate.DelegateManager.listDelegate import de.bixilon.minosoft.util.delegate.DelegateManager.listDelegate
import de.bixilon.minosoft.util.delegate.watcher.entry.ListDelegateWatcher.Companion.watchListFX
import org.kordamp.ikonli.Ikon import org.kordamp.ikonli.Ikon
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
object CustomServerType : ServerType { object CustomServerType : ServerType {
override val icon: Ikon = FontAwesomeSolid.SERVER override val icon: Ikon = FontAwesomeSolid.SERVER
override val hidden: Boolean = false override val hidden: Boolean = false
override var readOnly: Boolean = false
override val servers: MutableList<Server> by listDelegate(ErosProfileManager.selected.server.entries) override val servers: MutableList<Server> by listDelegate(ErosProfileManager.selected.server.entries)
override val translationKey: ResourceLocation = "minosoft:server_type.custom".toResourceLocation() override val translationKey: ResourceLocation = "minosoft:server_type.custom".toResourceLocation()
init {
ErosProfileManager.selected.server::entries.watchListFX(this) {
while (it.next()) {
this.servers += it.addedSubList
this.servers -= it.removed
}
}
}
override fun refresh(cards: List<ServerCard>) { override fun refresh(cards: List<ServerCard>) {
for (serverCard in cards) { for (serverCard in cards) {
serverCard.ping?.let { serverCard.ping?.let {

View File

@ -13,6 +13,7 @@ object LANServerType : ServerType {
override val icon: Ikon = FontAwesomeSolid.NETWORK_WIRED override val icon: Ikon = FontAwesomeSolid.NETWORK_WIRED
override val hidden: Boolean override val hidden: Boolean
get() = !LANServerListener.listening get() = !LANServerListener.listening
override var readOnly: Boolean = true
override val servers: MutableList<Server> by listDelegate() override val servers: MutableList<Server> by listDelegate()
override val translationKey: ResourceLocation = "minosoft:server_type.lan".toResourceLocation() override val translationKey: ResourceLocation = "minosoft:server_type.lan".toResourceLocation()

View File

@ -21,6 +21,7 @@ import org.kordamp.ikonli.Ikon
interface ServerType : Translatable { interface ServerType : Translatable {
val icon: Ikon val icon: Ikon
val hidden: Boolean val hidden: Boolean
var readOnly: Boolean
val servers: MutableList<Server> val servers: MutableList<Server>