mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
01623afc32
@ -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<Long, BotModel>()
|
||||
val mainLog = observableListOf<String>()
|
||||
|
||||
|
||||
val botList = observableListOf<BotModel>()
|
||||
val pluginList: ObservableList<PluginModel> by lazy(::getPluginsFromConsole)
|
||||
|
||||
val consoleConfig : Map<String, Any> 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<PluginModel> {
|
||||
// TODO
|
||||
return observableListOf<PluginModel>()
|
||||
}
|
||||
|
||||
private fun getConfigFromConsole() = MiraiConsole.MiraiProperties.config.asMap()
|
||||
}
|
||||
|
||||
class GraphicalLoginSolver : LoginSolver() {
|
||||
|
@ -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<PluginModel>() {
|
||||
|
||||
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
|
||||
}
|
@ -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 <T> EventTarget.jfxListView(values: ObservableList<T>? = null, op:
|
||||
else it.items = values
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : RecursiveTreeObject<T>?> EventTarget.jfxTreeTableView(items: ObservableList<T>? = null, op: JFXTreeTableView<T>.() -> Unit = {})
|
||||
= JFXTreeTableView<T>(RecursiveTreeItem(items, RecursiveTreeObject<T>::getChildren)).attachTo(this, op)
|
@ -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<MiraiGraphicalUIController>()
|
||||
val plugins = controller.pluginList
|
||||
|
||||
override val root = jfxTreeTableView(plugins) {
|
||||
columns.addAll(
|
||||
JFXTreeTableColumn<PluginModel, String>("插件名").apply { },
|
||||
JFXTreeTableColumn<PluginModel, String>("版本").apply { },
|
||||
JFXTreeTableColumn<PluginModel, String>("作者").apply { },
|
||||
JFXTreeTableColumn<PluginModel, String>("介绍").apply { }
|
||||
)
|
||||
}
|
||||
}
|
@ -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<LoginView>().root
|
||||
}
|
||||
tab("Login").content = find<LoginView>().root
|
||||
|
||||
tab("Plugin")
|
||||
tab("Plugins").content = find<PluginsView>().root
|
||||
|
||||
tab("Settings")
|
||||
tab("Settings").content = find<SettingsView>().root
|
||||
|
||||
logTab("Main", controller.mainLog)
|
||||
}
|
||||
|
@ -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<MiraiGraphicalUIController>()
|
||||
|
||||
override val root = form {
|
||||
controller.consoleConfig.forEach {
|
||||
fieldset {
|
||||
field(it.key) {
|
||||
jfxTextfield(it.value.toString()) { isEditable = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user