diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt index 939cd424d..a9b031a88 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt @@ -1,6 +1,7 @@ package net.mamoe.mirai.console.graphical.controller import javafx.application.Platform +import javafx.collections.ObservableList import javafx.stage.Modality import kotlinx.io.core.IoBuffer import net.mamoe.mirai.Bot @@ -8,6 +9,7 @@ import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.MiraiConsoleUI import net.mamoe.mirai.console.graphical.model.BotModel import net.mamoe.mirai.console.graphical.model.ConsoleInfo +import net.mamoe.mirai.console.graphical.model.PluginModel import net.mamoe.mirai.console.graphical.model.VerificationCodeModel import net.mamoe.mirai.console.graphical.view.VerificationCodeFragment import net.mamoe.mirai.utils.LoginSolver @@ -21,13 +23,21 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { private val loginSolver = GraphicalLoginSolver() private val cache = mutableMapOf() val mainLog = observableListOf() + + val botList = observableListOf() + val pluginList: ObservableList by lazy(::getPluginsFromConsole) + + val consoleConfig : Map by lazy(::getConfigFromConsole) + val consoleInfo = ConsoleInfo() suspend fun login(qq: String, psd: String) { MiraiConsole.CommandListener.commandChannel.send("/login $qq $psd") } + suspend fun sendCommand(command: String) = MiraiConsole.CommandListener.commandChannel.send(command) + override fun pushLog(identity: Long, message: String) = Platform.runLater { when (identity) { 0L -> mainLog.add(message) @@ -68,6 +78,13 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI { } override fun createLoginSolver(): LoginSolver = loginSolver + + private fun getPluginsFromConsole(): ObservableList { + // TODO + return observableListOf() + } + + private fun getConfigFromConsole() = MiraiConsole.MiraiProperties.config.asMap() } class GraphicalLoginSolver : LoginSolver() { diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/PluginModel.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/PluginModel.kt new file mode 100644 index 000000000..21a59e66b --- /dev/null +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/PluginModel.kt @@ -0,0 +1,19 @@ +package net.mamoe.mirai.console.graphical.model + +import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject +import javafx.beans.property.SimpleBooleanProperty +import javafx.beans.property.SimpleStringProperty +import tornadofx.getValue +import tornadofx.setValue + +class PluginModel : RecursiveTreeObject() { + + val nameProperty = SimpleStringProperty(this, "nameProperty") + val name by nameProperty + + val descriptionProperty = SimpleStringProperty(this, "descriptionProperty") + val description by descriptionProperty + + val enabledProperty = SimpleBooleanProperty(this, "enabledProperty") + var enabled by enabledProperty +} \ No newline at end of file diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt index 5590d9c44..61dcde2ae 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt @@ -1,6 +1,7 @@ package net.mamoe.mirai.console.graphical.util import com.jfoenix.controls.* +import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject import javafx.beans.value.ObservableValue import javafx.collections.ObservableList import javafx.event.EventTarget @@ -42,3 +43,6 @@ internal fun EventTarget.jfxListView(values: ObservableList? = null, op: else it.items = values } } + +fun ?> EventTarget.jfxTreeTableView(items: ObservableList? = null, op: JFXTreeTableView.() -> Unit = {}) + = JFXTreeTableView(RecursiveTreeItem(items, RecursiveTreeObject::getChildren)).attachTo(this, op) \ No newline at end of file diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt new file mode 100644 index 000000000..5b3e4d163 --- /dev/null +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt @@ -0,0 +1,22 @@ +package net.mamoe.mirai.console.graphical.view + +import com.jfoenix.controls.JFXTreeTableColumn +import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController +import net.mamoe.mirai.console.graphical.model.PluginModel +import net.mamoe.mirai.console.graphical.util.jfxTreeTableView +import tornadofx.View + +class PluginsView : View() { + + private val controller = find() + val plugins = controller.pluginList + + override val root = jfxTreeTableView(plugins) { + columns.addAll( + JFXTreeTableColumn("插件名").apply { }, + JFXTreeTableColumn("版本").apply { }, + JFXTreeTableColumn("作者").apply { }, + JFXTreeTableColumn("介绍").apply { } + ) + } +} \ No newline at end of file diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt index 1a81c3721..a0760cd6b 100644 --- a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt @@ -5,6 +5,8 @@ import javafx.collections.ObservableList import javafx.scene.control.Tab import javafx.scene.control.TabPane import javafx.scene.image.Image +import javafx.scene.input.KeyCode +import kotlinx.coroutines.runBlocking import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController import net.mamoe.mirai.console.graphical.model.BotModel import net.mamoe.mirai.console.graphical.util.jfxListView @@ -52,17 +54,26 @@ class PrimaryView : View() { } } } + + // command input + textfield { + setOnKeyPressed { + if (it.code == KeyCode.ENTER) { + runAsync { + runBlocking { controller.sendCommand(text) } + }.ui { text = "" } + } + } + } } center = jfxTabPane { - tab("Login") { - this += find().root - } + tab("Login").content = find().root - tab("Plugin") + tab("Plugins").content = find().root - tab("Settings") + tab("Settings").content = find().root logTab("Main", controller.mainLog) } diff --git a/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/SettingsView.kt b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/SettingsView.kt new file mode 100644 index 000000000..1c0b2968c --- /dev/null +++ b/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/SettingsView.kt @@ -0,0 +1,23 @@ +package net.mamoe.mirai.console.graphical.view + +import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController +import net.mamoe.mirai.console.graphical.util.jfxTextfield +import tornadofx.View +import tornadofx.field +import tornadofx.fieldset +import tornadofx.form + +class SettingsView : View() { + + private val controller = find() + + override val root = form { + controller.consoleConfig.forEach { + fieldset { + field(it.key) { + jfxTextfield(it.value.toString()) { isEditable = false } + } + } + } + } +} \ No newline at end of file