mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-24 20:43:33 +08:00
f**k javafx
This commit is contained in:
parent
f68df35665
commit
83611ac09f
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical
@ -1,9 +1,15 @@
|
||||
package net.mamoe.mirai.console.graphical
|
||||
|
||||
import com.jfoenix.controls.JFXDecorator
|
||||
import javafx.scene.control.Button
|
||||
import javafx.stage.Stage
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||
import net.mamoe.mirai.console.graphical.view.Decorator
|
||||
import net.mamoe.mirai.console.graphical.view.PrimaryView
|
||||
import tornadofx.App
|
||||
import tornadofx.FX.Companion.primaryStage
|
||||
import tornadofx.UIComponent
|
||||
import tornadofx.find
|
||||
import tornadofx.launch
|
||||
|
||||
@ -11,7 +17,7 @@ fun main(args: Array<String>) {
|
||||
launch<MiraiGraphicalUI>(args)
|
||||
}
|
||||
|
||||
class MiraiGraphicalUI: App(PrimaryView::class) {
|
||||
class MiraiGraphicalUI: App(Decorator::class) {
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
|
@ -11,3 +11,9 @@ class BotModel(val uin: Long) {
|
||||
val logHistory = observableListOf<String>()
|
||||
val admins = observableListOf<Long>()
|
||||
}
|
||||
|
||||
class BotViewModel(botModel: BotModel? = null) : ItemViewModel<BotModel>(botModel) {
|
||||
val bot = bind(BotModel::botProperty)
|
||||
val logHistory = bind(BotModel::logHistory)
|
||||
val admins = bind(BotModel::admins)
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package net.mamoe.mirai.console.graphical.view
|
||||
|
||||
import com.jfoenix.controls.JFXDecorator
|
||||
import tornadofx.View
|
||||
|
||||
class Decorator: View() {
|
||||
|
||||
override val root = JFXDecorator(primaryStage, find<PrimaryView>().root)
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package net.mamoe.mirai.console.graphical.view
|
||||
|
||||
import com.jfoenix.controls.JFXAlert
|
||||
import com.jfoenix.controls.JFXPopup
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.scene.control.Label
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||
import net.mamoe.mirai.console.graphical.util.jfxButton
|
||||
@ -8,26 +11,31 @@ import net.mamoe.mirai.console.graphical.util.jfxPasswordfield
|
||||
import net.mamoe.mirai.console.graphical.util.jfxTextfield
|
||||
import tornadofx.*
|
||||
|
||||
class LoginFragment : Fragment() {
|
||||
class LoginView : View() {
|
||||
|
||||
private val controller = find<MiraiGraphicalUIController>(FX.defaultScope)
|
||||
private val qq = SimpleStringProperty("0")
|
||||
private val controller = find<MiraiGraphicalUIController>()
|
||||
private val qq = SimpleStringProperty("")
|
||||
private val psd = SimpleStringProperty("")
|
||||
|
||||
override val root = form {
|
||||
fieldset("登录") {
|
||||
field("QQ") {
|
||||
jfxTextfield(qq)
|
||||
override val root = pane {
|
||||
form {
|
||||
fieldset("登录") {
|
||||
field("QQ") {
|
||||
jfxTextfield(qq)
|
||||
}
|
||||
field("密码") {
|
||||
jfxPasswordfield(psd)
|
||||
}
|
||||
}
|
||||
field("密码") {
|
||||
jfxPasswordfield(psd)
|
||||
jfxButton("登录").action {
|
||||
runAsync {
|
||||
runBlocking {
|
||||
controller.login(qq.value, psd.value)
|
||||
}
|
||||
}.ui {
|
||||
// show dialog
|
||||
}
|
||||
}
|
||||
}
|
||||
jfxButton("登录").action {
|
||||
runBlocking {
|
||||
controller.login(qq.value, psd.value)
|
||||
}
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,15 @@
|
||||
package net.mamoe.mirai.console.graphical.view
|
||||
|
||||
import com.jfoenix.controls.JFXListCell
|
||||
import javafx.geometry.Insets
|
||||
import javafx.geometry.Pos
|
||||
import com.jfoenix.controls.*
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.scene.control.Tab
|
||||
import javafx.scene.control.TabPane
|
||||
import javafx.scene.image.Image
|
||||
import javafx.scene.paint.Color
|
||||
import javafx.scene.text.FontWeight
|
||||
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||
import net.mamoe.mirai.console.graphical.model.BotModel
|
||||
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 tornadofx.*
|
||||
import java.io.FileInputStream
|
||||
|
||||
class PrimaryView : View() {
|
||||
|
||||
@ -35,20 +30,12 @@ class PrimaryView : View() {
|
||||
|
||||
setCellFactory {
|
||||
object : JFXListCell<BotModel>() {
|
||||
var tab: Tab? = null
|
||||
|
||||
init {
|
||||
onDoubleClick {
|
||||
if (tab == null) {
|
||||
(center as TabPane).tab(item.uin.toString()) {
|
||||
listview(item.logHistory)
|
||||
onDoubleClick { close() }
|
||||
tab = this
|
||||
}
|
||||
} else {
|
||||
(center as TabPane).tabs.add(tab)
|
||||
}
|
||||
tab?.select()
|
||||
(center as TabPane).logTab(
|
||||
text = item.uin.toString(),
|
||||
logs = item.logHistory
|
||||
).select()
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,44 +52,37 @@ class PrimaryView : View() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hbox {
|
||||
padding = Insets(10.0)
|
||||
spacing = 10.0
|
||||
alignment = Pos.CENTER
|
||||
|
||||
jfxButton("L").action {
|
||||
find<LoginFragment>().openModal()
|
||||
}
|
||||
jfxButton("P")
|
||||
jfxButton("S")
|
||||
|
||||
|
||||
style { backgroundColor += c("00BCD4") }
|
||||
children.style(true) {
|
||||
backgroundColor += c("00BCD4")
|
||||
fontSize = 15.px
|
||||
fontWeight = FontWeight.BOLD
|
||||
textFill = Color.WHITE
|
||||
borderRadius += box(25.px)
|
||||
backgroundRadius += box(25.px)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
center = jfxTabPane {
|
||||
tab("Main") {
|
||||
listview(controller.mainLog) {
|
||||
|
||||
fitToParentSize()
|
||||
cellFormat {
|
||||
graphic = label(it) {
|
||||
maxWidthProperty().bind(this@listview.widthProperty())
|
||||
isWrapText = true
|
||||
}
|
||||
}
|
||||
}
|
||||
tab("Login") {
|
||||
this += find<LoginView>().root
|
||||
}
|
||||
|
||||
tab("Plugin")
|
||||
|
||||
tab("Settings")
|
||||
|
||||
logTab("Main", controller.mainLog)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun TabPane.logTab(
|
||||
text: String? = null,
|
||||
logs: ObservableList<String>,
|
||||
op: Tab.() -> Unit = {}
|
||||
)= tab(text) {
|
||||
listview(logs) {
|
||||
|
||||
fitToParentSize()
|
||||
cellFormat {
|
||||
graphic = label(it) {
|
||||
maxWidthProperty().bind(this@listview.widthProperty())
|
||||
isWrapText = true
|
||||
}
|
||||
}
|
||||
}
|
||||
also(op)
|
||||
}
|
Loading…
Reference in New Issue
Block a user