profiles: improvements, eros: save server list filters to profile

This commit is contained in:
Bixilon 2021-12-01 23:28:54 +01:00
parent e8c5e94902
commit cc55f61758
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 55 additions and 26 deletions

View File

@ -100,9 +100,9 @@ object Minosoft {
}) })
taskWorker += Task(identifier = StartupTasks.LOAD_PROFILES, priority = ThreadPool.HIGH, dependencies = arrayOf(StartupTasks.LOAD_VERSIONS), executor = { taskWorker += Task(identifier = StartupTasks.LOAD_PROFILES, priority = ThreadPool.HIGH, dependencies = arrayOf(StartupTasks.LOAD_VERSIONS), executor = {
Log.log(LogMessageType.LOAD_PROFILES, LogLevels.VERBOSE) { "Loading profiles..." } Log.log(LogMessageType.PROFILES, LogLevels.VERBOSE) { "Loading profiles..." }
GlobalProfileManager.initialize() GlobalProfileManager.initialize()
Log.log(LogMessageType.LOAD_PROFILES, LogLevels.INFO) { "Profiles loaded!" } Log.log(LogMessageType.PROFILES, LogLevels.INFO) { "Profiles loaded!" }
}) })
taskWorker += Task(identifier = StartupTasks.LOAD_LANGUAGE_FILES, dependencies = arrayOf(StartupTasks.LOAD_CONFIG), executor = { taskWorker += Task(identifier = StartupTasks.LOAD_LANGUAGE_FILES, dependencies = arrayOf(StartupTasks.LOAD_CONFIG), executor = {

View File

@ -109,7 +109,7 @@ interface ProfileManager<T : Profile> {
for (toMigrate in version until latestVersion) { for (toMigrate in version until latestVersion) {
migrate(toMigrate, json) migrate(toMigrate, json)
} }
Log.log(LogMessageType.LOAD_PROFILES, LogLevels.INFO) { "Migrated profile ($path) from version $version to $latestVersion" } Log.log(LogMessageType.PROFILES, LogLevels.INFO) { "Migrated profile ($path) from version $version to $latestVersion" }
json["version"] = latestVersion json["version"] = latestVersion
saveFile = true saveFile = true
} }
@ -129,7 +129,7 @@ interface ProfileManager<T : Profile> {
profiles[selected]?.let { this.selected = it } ?: selectDefault() profiles[selected]?.let { this.selected = it } ?: selectDefault()
} }
Log.log(LogMessageType.LOAD_PROFILES, LogLevels.VERBOSE) { "Loaded ${profiles.size} $namespace profiles!" } Log.log(LogMessageType.PROFILES, LogLevels.VERBOSE) { "Loaded ${profiles.size} $namespace profiles!" }
} }
companion object { companion object {

View File

@ -28,7 +28,7 @@ object ProfilesChangeManager {
if (reference.get() == null) { if (reference.get() == null) {
toRemove += pair toRemove += pair
} }
listener.invoke(previous.unsafeCast(), value.unsafeCast()) listener.invoke(previous, value)
} }
if (toRemove.isNotEmpty()) { if (toRemove.isNotEmpty()) {
if (queue.size == toRemove.size) { if (queue.size == toRemove.size) {

View File

@ -10,5 +10,5 @@ interface ProfileChangeListener<T> {
val profile: Profile? val profile: Profile?
fun invoke(previous: T, value: T) fun invoke(previous: Any?, value: Any?)
} }

View File

@ -3,29 +3,41 @@ package de.bixilon.minosoft.config.profile.change.listener
import de.bixilon.minosoft.config.profile.change.ProfilesChangeManager import de.bixilon.minosoft.config.profile.change.ProfilesChangeManager
import de.bixilon.minosoft.config.profile.profiles.Profile import de.bixilon.minosoft.config.profile.profiles.Profile
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.util.KUtil.unsafeCast
import java.lang.reflect.Field import java.lang.reflect.Field
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
import kotlin.reflect.KProperty0
import kotlin.reflect.jvm.javaField import kotlin.reflect.jvm.javaField
class SimpleProfileChangeListener<T>( class SimpleProfileChangeListener<T>(
override val property: KProperty<T>, override val property: KProperty<T>,
override val field: Field, override val field: Field,
override val profile: Profile?, override val profile: Profile?,
instant: Boolean,
private val callback: (T) -> Unit, private val callback: (T) -> Unit,
) : ProfileChangeListener<T> { ) : ProfileChangeListener<T> {
override fun invoke(previous: T, value: T) { init {
callback(value) if (instant) {
when (property) {
is KProperty0<*> -> invoke(property.get(), property.get())
else -> TODO("Instant fire is not supported for ${property::class.java}")
}
}
}
override fun invoke(previous: Any?, value: Any?) {
callback(value.unsafeCast())
} }
companion object { companion object {
fun <T> KProperty<T>.listen(reference: Any, profile: Profile? = null, callback: ((T) -> Unit)) { fun <T> KProperty<T>.listen(reference: Any, instant: Boolean = false, profile: Profile? = null, callback: ((T) -> Unit)) {
ProfilesChangeManager.register(reference, SimpleProfileChangeListener(this, javaField!!, profile, callback)) ProfilesChangeManager.register(reference, SimpleProfileChangeListener(this, javaField!!, profile, instant, callback))
} }
fun <T> KProperty<T>.listenFX(reference: Any, profile: Profile? = null, callback: ((T) -> Unit)) { fun <T> KProperty<T>.listenFX(reference: Any, instant: Boolean = false, profile: Profile? = null, callback: ((T) -> Unit)) {
ProfilesChangeManager.register(reference, SimpleProfileChangeListener(this, javaField!!, profile) { JavaFXUtil.runLater { callback(it) } }) ProfilesChangeManager.register(reference, SimpleProfileChangeListener(this, javaField!!, profile, instant) { JavaFXUtil.runLater { callback(it) } })
} }
} }
} }

View File

@ -1,7 +1,9 @@
package de.bixilon.minosoft.config.profile.profiles.eros.server package de.bixilon.minosoft.config.profile.profiles.eros.server
import de.bixilon.minosoft.config.profile.profiles.eros.server.list.ListC
import de.bixilon.minosoft.config.profile.profiles.eros.server.modify.ModifyC import de.bixilon.minosoft.config.profile.profiles.eros.server.modify.ModifyC
class ServerC { class ServerC {
val modify = ModifyC() val modify = ModifyC()
val list = ListC()
} }

View File

@ -0,0 +1,9 @@
package de.bixilon.minosoft.config.profile.profiles.eros.server.list
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager.delegate
class ListC {
var hideOffline by delegate(false)
var hideFull by delegate(false)
var hideEmpty by delegate(false)
}

View File

@ -39,7 +39,7 @@ open class ProfileDelegate<V>(
return return
} }
Log.log(LogMessageType.OTHER, LogLevels.VERBOSE) { "Changed option $property in profile $profileName from ${this.value} to $value" } Log.log(LogMessageType.PROFILES, LogLevels.VERBOSE) { "Changed option $property in profile $profileName from ${this.value} to $value" }
profileManager.profiles[profileName]?.saved = false profileManager.profiles[profileName]?.saved = false
val previous = this.value val previous = this.value
this.value = value this.value = value

View File

@ -14,6 +14,8 @@
package de.bixilon.minosoft.gui.eros.main.play.server package de.bixilon.minosoft.gui.eros.main.play.server
import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.profile.change.listener.SimpleProfileChangeListener.Companion.listenFX
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
import de.bixilon.minosoft.config.server.Server import de.bixilon.minosoft.config.server.Server
import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.data.text.ChatComponent
@ -52,9 +54,7 @@ import javafx.scene.layout.*
class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable { class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
@FXML private lateinit var hideOfflineFX: CheckBox @FXML private lateinit var hideOfflineFX: CheckBox
@FXML private lateinit var hideFullFX: CheckBox @FXML private lateinit var hideFullFX: CheckBox
@FXML private lateinit var hideEmptyFX: CheckBox @FXML private lateinit var hideEmptyFX: CheckBox
@ -75,6 +75,16 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
} }
override fun init() { override fun init() {
val serverConfig = ErosProfileManager.selected.server.list
serverConfig::hideOffline.listenFX(this, true) { hideOfflineFX.isSelected = it }
serverConfig::hideFull.listenFX(this, true) { hideFullFX.isSelected = it }
serverConfig::hideEmpty.listenFX(this, true) { hideEmptyFX.isSelected = it }
hideOfflineFX.setOnAction { ErosProfileManager.selected.server.list.hideOffline = hideOfflineFX.isSelected }
hideFullFX.setOnAction { ErosProfileManager.selected.server.list.hideFull = hideFullFX.isSelected }
hideEmptyFX.setOnAction { ErosProfileManager.selected.server.list.hideEmpty = hideEmptyFX.isSelected }
serverListViewFX.setCellFactory { serverListViewFX.setCellFactory {
val controller = ServerCardController.build() val controller = ServerCardController.build()
@ -94,7 +104,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
refreshList() refreshList()
serverListViewFX.selectionModel.selectedItemProperty().addListener { _, old, new -> serverListViewFX.selectionModel.selectedItemProperty().addListener { _, _, new ->
setServerInfo(new) setServerInfo(new)
} }
} }
@ -239,15 +249,11 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
if (!readOnly) { if (!readOnly) {
it.add(Button("Delete").apply { it.add(Button("Delete").apply {
setOnAction { setOnAction {
SimpleErosConfirmationDialog( SimpleErosConfirmationDialog(confirmButtonText = "minosoft:general.delete".toResourceLocation(), description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), onConfirm = {
confirmButtonText = "minosoft:general.delete".toResourceLocation(), Minosoft.config.config.server.entries.remove(serverCard.server.id)
description = TranslatableComponents.EROS_DELETE_SERVER_CONFIRM_DESCRIPTION(serverCard.server.name, serverCard.server.address), Minosoft.config.saveToFile()
onConfirm = { JavaFXUtil.runLater { refreshList() }
Minosoft.config.config.server.entries.remove(serverCard.server.id) }).show()
Minosoft.config.saveToFile()
JavaFXUtil.runLater { refreshList() }
}
).show()
} }
}, 1, 0) }, 1, 0)
it.add(Button("Edit").apply { it.add(Button("Edit").apply {

View File

@ -57,7 +57,7 @@ enum class LogMessageType(
LogLevels.VERBOSE to ChatColors.YELLOW, LogLevels.VERBOSE to ChatColors.YELLOW,
)), )),
LOAD_PROFILES(ChatColors.AQUA), PROFILES(ChatColors.AQUA),
; ;
companion object : ValuesEnum<LogMessageType> { companion object : ValuesEnum<LogMessageType> {