Bläddra i källkod

Merge remote-tracking branch 'origin/master'

Him188 6 år sedan
förälder
incheckning
2310922790

+ 2 - 0
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiGraphical.kt

@@ -15,6 +15,7 @@ import net.mamoe.mirai.console.graphical.stylesheet.PrimaryStyleSheet
 import net.mamoe.mirai.console.graphical.view.Decorator
 import tornadofx.App
 import tornadofx.find
+import kotlin.system.exitProcess
 
 //object MiraiGraphicalLoader {
 //    @JvmStatic
@@ -33,5 +34,6 @@ class MiraiGraphicalUI : App(Decorator::class, PrimaryStyleSheet::class) {
     override fun stop() {
         super.stop()
         MiraiConsole.stop()
+        exitProcess(0)
     }
 }

+ 19 - 6
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt

@@ -5,8 +5,10 @@ import javafx.collections.ObservableList
 import javafx.stage.Modality
 import javafx.stage.StageStyle
 import kotlinx.coroutines.delay
+import kotlinx.coroutines.isActive
 import net.mamoe.mirai.Bot
 import net.mamoe.mirai.console.command.CommandManager
+import net.mamoe.mirai.console.command.CommandManager.runCommand
 import net.mamoe.mirai.console.command.ConsoleCommandSender
 import net.mamoe.mirai.console.graphical.model.*
 import net.mamoe.mirai.console.graphical.view.dialog.InputDialog
@@ -25,7 +27,7 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
     private val settingModel = find<GlobalSettingModel>()
     private val loginSolver = GraphicalLoginSolver()
     private val cache = mutableMapOf<Long, BotModel>()
-    val mainLog = observableListOf<String>()
+    val mainLog = observableListOf<Pair<String, String>>()
 
 
     val botList = observableListOf<BotModel>()
@@ -41,7 +43,16 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
         CommandManager.runCommand(ConsoleCommandSender, "/login $qq $psd")
     }
 
-    fun sendCommand(command: String) = CommandManager.runCommand(ConsoleCommandSender, command)
+    fun logout(qq: Long) {
+        cache.remove(qq)?.apply {
+            botList.remove(this)
+            if (botProperty.value != null && bot.isActive) {
+                bot.close()
+            }
+        }
+    }
+
+    fun sendCommand(command: String) = runCommand(ConsoleCommandSender, command)
 
     override fun pushLog(identity: Long, message: String) = Platform.runLater {
         this.pushLog(LogPriority.INFO, "", identity, message)
@@ -58,16 +69,18 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
             } else {
                 cache[identity]?.logHistory
             }?.apply {
-                add("[$time] $identityStr $message")
+                add("[$time] $identityStr $message" to priority.name)
                 trim()
             }
         }
     }
 
     override fun prePushBot(identity: Long) = Platform.runLater {
-        BotModel(identity).also {
-            cache[identity] = it
-            botList.add(it)
+        if (!cache.containsKey(identity)) {
+            BotModel(identity).also {
+                cache[identity] = it
+                botList.add(it)
+            }
         }
     }
 

+ 1 - 1
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/BotModel.kt

@@ -11,7 +11,7 @@ class BotModel(val uin: Long) {
     val botProperty = SimpleObjectProperty<Bot>(null)
     var bot: Bot by botProperty
 
-    val logHistory = observableListOf<String>()
+    val logHistory = observableListOf<Pair<String, String>>()
     val admins = observableListOf<Long>()
 }
 

+ 23 - 2
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/PrimaryStyleSheet.kt

@@ -69,9 +69,21 @@ class PrimaryStyleSheet : BaseStyleSheet() {
                         backgroundColor += c(100, 100, 100, 0.4)
                         backgroundRadius += box(5.px)
 
-                        textFill = c(fontColor)
-                        fontWeight = FontWeight.BOLD
+                        label {
+                            textFill = c(fontColor)
+                            fontWeight = FontWeight.BOLD
+                        }
+
+                        button {
+                            opacity = 0.0
+                            backgroundRadius += box(10.px)
+                            backgroundColor += c(fontColor, 0.1)
+                            cursor = Cursor.HAND
 
+                            and(hover) {
+                                opacity = 1.0
+                            }
+                        }
                     }
                 }
             }
@@ -112,6 +124,15 @@ class PrimaryStyleSheet : BaseStyleSheet() {
                 }
 
                 listCell {
+
+                    and(":WARNING") {
+                        backgroundColor += c("FFFF00", 0.3) // Yellow
+                    }
+
+                    and(":ERROR") {
+                        backgroundColor += c("FF0000", 0.3) // Red
+                    }
+
                     and(":selected") {
                         backgroundColor += c(stressColor, 1.0)
                     }

+ 15 - 0
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/SVG.kt

@@ -0,0 +1,15 @@
+package net.mamoe.mirai.console.graphical.util
+
+import com.jfoenix.svg.SVGGlyph
+import javafx.scene.paint.Color
+
+class SVG {
+    companion object {
+        var close = SVGGlyph(
+            0,
+            "CLOSE",
+            "M810 274l-238 238 238 238-60 60-238-238-238 238-60-60 238-238-238-238 60-60 238 238 238-238z",
+            Color.WHITE
+        ).apply { setSize(8.0, 8.0) }
+    }
+}

+ 31 - 6
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt

@@ -5,18 +5,21 @@ import com.jfoenix.controls.JFXListCell
 import javafx.collections.ObservableList
 import javafx.geometry.Insets
 import javafx.geometry.Pos
+import javafx.scene.control.Alert
+import javafx.scene.control.ButtonType
 import javafx.scene.control.Tab
 import javafx.scene.control.TabPane
 import javafx.scene.image.Image
 import javafx.scene.input.KeyCode
+import javafx.scene.layout.Priority
 import javafx.stage.FileChooser
 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.*
 import net.mamoe.mirai.console.graphical.util.jfxButton
 import net.mamoe.mirai.console.graphical.util.jfxListView
 import net.mamoe.mirai.console.graphical.util.jfxTabPane
-import net.mamoe.mirai.console.graphical.util.myButtonBar
 import tornadofx.*
 
 class PrimaryView : View() {
@@ -72,8 +75,27 @@ class PrimaryView : View() {
                         override fun updateItem(item: BotModel?, empty: Boolean) {
                             super.updateItem(item, empty)
                             if (item != null && !empty) {
-                                graphic = null
-                                text = item.uin.toString()
+                                graphic = hbox {
+
+                                    alignment = Pos.CENTER_LEFT
+
+                                    label(item.uin.toString())
+                                    pane {
+                                        hgrow = Priority.ALWAYS
+                                    }
+                                    jfxButton(graphic = SVG.close) {
+                                        buttonType = JFXButton.ButtonType.FLAT
+                                        tooltip("退出登录")
+                                    }.action {
+                                        alert(Alert.AlertType.CONFIRMATION, "${item.uin}将会退出登录,是否确认") {
+                                            if (it == ButtonType.OK) {
+                                                tab?.close()
+                                                controller.logout(item.uin)
+                                            }
+                                        }
+                                    }
+                                }
+                                text = ""
                             } else {
                                 graphic = null
                                 text = ""
@@ -129,7 +151,7 @@ private fun TabPane.fixedTab(title: String) = tab(title) { isClosable = false }
 
 private fun TabPane.logTab(
     text: String? = null,
-    logs: ObservableList<String>,
+    logs: ObservableList<Pair<String, String>>,
     closeable: Boolean = true,
     op: Tab.() -> Unit = {}
 ) = tab(text) {
@@ -152,7 +174,7 @@ private fun TabPane.logTab(
                     path.firstOrNull()?.run {
                         if (!exists()) createNewFile()
                         writer().use {
-                            logs.forEach { log -> it.appendln(log) }
+                            logs.forEach { log -> it.appendln(log.first) }
                         }
                         true
                     } ?: false
@@ -166,7 +188,10 @@ private fun TabPane.logTab(
 
             fitToParentSize()
             cellFormat {
-                graphic = label(it) {
+
+                addPseudoClass(it.second)
+
+                graphic = label(it.first) {
                     maxWidthProperty().bind([email protected]())
                     isWrapText = true
                 }

+ 12 - 0
mirai-console/src/main/kotlin/net/mamoe/mirai/console/center/CuiPluginCenter.kt

@@ -0,0 +1,12 @@
+package net.mamoe.mirai.console.center
+
+object CuiPluginCenter: PluginCenter{
+    override suspend fun fetchPlugin(page: Int): Map<String, PluginCenter.PluginInsight> {
+        TODO("Not yet implemented")
+    }
+
+    override suspend fun findPlugin(name: String): PluginCenter.PluginInfo? {
+        TODO("Not yet implemented")
+    }
+
+}

+ 49 - 0
mirai-console/src/main/kotlin/net/mamoe/mirai/console/center/PluginCenter.kt

@@ -0,0 +1,49 @@
+package net.mamoe.mirai.console.center
+
+interface PluginCenter {
+
+    companion object{
+        val Default:PluginCenter = CuiPluginCenter
+    }
+
+    data class PluginInsight(
+        val name:String,
+        val version:String,
+        val coreVersion:String,
+        val consoleVersion:String,
+        val author:String,
+        val description: String,
+        val tags:List<String>,
+        val commands:List<String>,
+    )
+
+    data class PluginInfo(
+        val name:String,
+        val version:String,
+        val coreVersion:String,
+        val consoleVersion:String,
+        val tags:List<String>,
+        val author:String,
+        val contact:String,
+        val description: String,
+        val usage:String,
+        val vcs:String,
+        val commands:String,
+        val changeLog:List<String>
+    )
+
+    /**
+     * 获取一些中心的插件基本信息,
+     * 能获取到多少由实际的PluginCenter决定
+     * 返回 插件名->Insight
+     */
+    suspend fun fetchPlugin(page: Int) :Map<String,PluginInsight>
+
+    /**
+     * 尝试获取到某个插件by全名, case sensitive
+     * null则没有
+     */
+    suspend fun findPlugin(name:String):PluginInfo?
+
+}
+