orignal log window
This commit is contained in:
@@ -25,11 +25,9 @@ import org.jackhuang.hmcl.launch.ProcessListener
|
|||||||
import org.jackhuang.hmcl.mod.CurseForgeModpackCompletionTask
|
import org.jackhuang.hmcl.mod.CurseForgeModpackCompletionTask
|
||||||
import org.jackhuang.hmcl.setting.LauncherVisibility
|
import org.jackhuang.hmcl.setting.LauncherVisibility
|
||||||
import org.jackhuang.hmcl.setting.Settings
|
import org.jackhuang.hmcl.setting.Settings
|
||||||
|
import org.jackhuang.hmcl.setting.VersionSetting
|
||||||
import org.jackhuang.hmcl.task.*
|
import org.jackhuang.hmcl.task.*
|
||||||
import org.jackhuang.hmcl.ui.Controllers
|
import org.jackhuang.hmcl.ui.*
|
||||||
import org.jackhuang.hmcl.ui.DialogController
|
|
||||||
import org.jackhuang.hmcl.ui.LaunchingStepsPane
|
|
||||||
import org.jackhuang.hmcl.ui.runOnUiThread
|
|
||||||
import org.jackhuang.hmcl.util.JavaProcess
|
import org.jackhuang.hmcl.util.JavaProcess
|
||||||
import org.jackhuang.hmcl.util.Log4jLevel
|
import org.jackhuang.hmcl.util.Log4jLevel
|
||||||
import java.util.concurrent.ConcurrentSkipListSet
|
import java.util.concurrent.ConcurrentSkipListSet
|
||||||
@@ -71,7 +69,7 @@ object LauncherHelper {
|
|||||||
repository = repository,
|
repository = repository,
|
||||||
versionId = profile.selectedVersion,
|
versionId = profile.selectedVersion,
|
||||||
options = setting.toLaunchOptions(profile.gameDir),
|
options = setting.toLaunchOptions(profile.gameDir),
|
||||||
listener = HMCLProcessListener(it["account"], setting.launcherVisibility),
|
listener = HMCLProcessListener(it["account"], setting),
|
||||||
account = it["account"]
|
account = it["account"]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -110,17 +108,23 @@ object LauncherHelper {
|
|||||||
* Guarantee that one [JavaProcess], one [HMCLProcessListener].
|
* Guarantee that one [JavaProcess], one [HMCLProcessListener].
|
||||||
* Because every time we launched a game, we generates a new [HMCLProcessListener]
|
* Because every time we launched a game, we generates a new [HMCLProcessListener]
|
||||||
*/
|
*/
|
||||||
class HMCLProcessListener(authInfo: AuthInfo?, private val launcherVisibility: LauncherVisibility) : ProcessListener {
|
class HMCLProcessListener(authInfo: AuthInfo?, private val setting: VersionSetting) : ProcessListener {
|
||||||
val forbiddenTokens: List<Pair<String, String>> = if (authInfo == null) emptyList() else
|
val forbiddenTokens: List<Pair<String, String>> = if (authInfo == null) emptyList() else
|
||||||
listOf(
|
listOf(
|
||||||
authInfo.authToken to "<access token>",
|
authInfo.authToken to "<access token>",
|
||||||
authInfo.userId to "<uuid>",
|
authInfo.userId to "<uuid>",
|
||||||
authInfo.username to "<player>"
|
authInfo.username to "<player>"
|
||||||
)
|
)
|
||||||
|
private val launcherVisibility = setting.launcherVisibility
|
||||||
private lateinit var process: JavaProcess
|
private lateinit var process: JavaProcess
|
||||||
private var lwjgl = false
|
private var lwjgl = false
|
||||||
|
private var logWindow: LogWindow? = null
|
||||||
override fun setProcess(process: JavaProcess) {
|
override fun setProcess(process: JavaProcess) {
|
||||||
this.process = process
|
this.process = process
|
||||||
|
|
||||||
|
if (setting.showLogs) {
|
||||||
|
runOnUiThread { logWindow = LogWindow(); logWindow?.show() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLog(log: String, level: Log4jLevel) {
|
override fun onLog(log: String, level: Log4jLevel) {
|
||||||
@@ -129,6 +133,8 @@ object LauncherHelper {
|
|||||||
else
|
else
|
||||||
System.out.print(log)
|
System.out.print(log)
|
||||||
|
|
||||||
|
runOnUiThread { logWindow?.logLine(log, level) }
|
||||||
|
|
||||||
if (!lwjgl && log.contains("LWJGL Version: ")) {
|
if (!lwjgl && log.contains("LWJGL Version: ")) {
|
||||||
lwjgl = true
|
lwjgl = true
|
||||||
when (launcherVisibility) {
|
when (launcherVisibility) {
|
||||||
|
|||||||
@@ -114,6 +114,12 @@ class VersionSetting() {
|
|||||||
val noCommonProperty = ImmediateBooleanProperty(this, "noCommon", false)
|
val noCommonProperty = ImmediateBooleanProperty(this, "noCommon", false)
|
||||||
var noCommon: Boolean by noCommonProperty
|
var noCommon: Boolean by noCommonProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if show the logs after game launched.
|
||||||
|
*/
|
||||||
|
val showLogsProperty = ImmediateBooleanProperty(this, "showLogs", false)
|
||||||
|
var showLogs: Boolean by showLogsProperty
|
||||||
|
|
||||||
// Minecraft settings.
|
// Minecraft settings.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,6 +209,7 @@ class VersionSetting() {
|
|||||||
noJVMArgsProperty.addListener(listener)
|
noJVMArgsProperty.addListener(listener)
|
||||||
notCheckGameProperty.addListener(listener)
|
notCheckGameProperty.addListener(listener)
|
||||||
noCommonProperty.addListener(listener)
|
noCommonProperty.addListener(listener)
|
||||||
|
showLogsProperty.addListener(listener)
|
||||||
serverIpProperty.addListener(listener)
|
serverIpProperty.addListener(listener)
|
||||||
fullscreenProperty.addListener(listener)
|
fullscreenProperty.addListener(listener)
|
||||||
widthProperty.addListener(listener)
|
widthProperty.addListener(listener)
|
||||||
@@ -257,6 +264,7 @@ class VersionSetting() {
|
|||||||
addProperty("noJVMArgs", src.noJVMArgs)
|
addProperty("noJVMArgs", src.noJVMArgs)
|
||||||
addProperty("notCheckGame", src.notCheckGame)
|
addProperty("notCheckGame", src.notCheckGame)
|
||||||
addProperty("noCommon", src.noCommon)
|
addProperty("noCommon", src.noCommon)
|
||||||
|
addProperty("showLogs", src.showLogs)
|
||||||
addProperty("launcherVisibility", src.launcherVisibility.ordinal)
|
addProperty("launcherVisibility", src.launcherVisibility.ordinal)
|
||||||
addProperty("gameDirType", src.gameDirType.ordinal)
|
addProperty("gameDirType", src.gameDirType.ordinal)
|
||||||
}
|
}
|
||||||
@@ -287,6 +295,7 @@ class VersionSetting() {
|
|||||||
noJVMArgs = json["noJVMArgs"]?.asBoolean ?: false
|
noJVMArgs = json["noJVMArgs"]?.asBoolean ?: false
|
||||||
notCheckGame = json["notCheckGame"]?.asBoolean ?: false
|
notCheckGame = json["notCheckGame"]?.asBoolean ?: false
|
||||||
noCommon = json["noCommon"]?.asBoolean ?: false
|
noCommon = json["noCommon"]?.asBoolean ?: false
|
||||||
|
showLogs = json["showLogs"]?.asBoolean ?: false
|
||||||
launcherVisibility = LauncherVisibility.values()[json["launcherVisibility"]?.asInt ?: 1]
|
launcherVisibility = LauncherVisibility.values()[json["launcherVisibility"]?.asInt ?: 1]
|
||||||
gameDirType = EnumGameDirectory.values()[json["gameDirType"]?.asInt ?: 0]
|
gameDirType = EnumGameDirectory.values()[json["gameDirType"]?.asInt ?: 0]
|
||||||
}
|
}
|
||||||
|
|||||||
57
HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/LogWindow.kt
Normal file
57
HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/LogWindow.kt
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2017 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.ui
|
||||||
|
|
||||||
|
import javafx.concurrent.Worker
|
||||||
|
import javafx.scene.Scene
|
||||||
|
import javafx.scene.layout.StackPane
|
||||||
|
import javafx.scene.web.WebEngine
|
||||||
|
import javafx.scene.web.WebView
|
||||||
|
import javafx.stage.Stage
|
||||||
|
import org.jackhuang.hmcl.util.Log4jLevel
|
||||||
|
import org.w3c.dom.Document
|
||||||
|
import org.w3c.dom.Node
|
||||||
|
|
||||||
|
class LogWindow : Stage() {
|
||||||
|
val contentPane = WebView()
|
||||||
|
val rootPane = StackPane().apply {
|
||||||
|
children.setAll(contentPane)
|
||||||
|
}
|
||||||
|
val engine: WebEngine
|
||||||
|
lateinit var body: Node
|
||||||
|
lateinit var document: Document
|
||||||
|
|
||||||
|
init {
|
||||||
|
scene = Scene(rootPane, 800.0, 480.0)
|
||||||
|
engine = contentPane.engine
|
||||||
|
engine.loadContent("<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" /></head><body></body></html>")
|
||||||
|
engine.loadWorker.stateProperty().addListener { _, _, newValue ->
|
||||||
|
if (newValue == Worker.State.SUCCEEDED) {
|
||||||
|
document = engine.document
|
||||||
|
body = document.getElementsByTagName("body").item(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun logLine(line: String, level: Log4jLevel) {
|
||||||
|
body.appendChild(contentPane.engine.document.createElement("div").apply {
|
||||||
|
setAttribute("style", "color: #${level.color.toString().substring(2)};")
|
||||||
|
textContent = line
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,6 +63,7 @@ class VersionSettingsController {
|
|||||||
@FXML lateinit var javaPaneCustom: BorderPane
|
@FXML lateinit var javaPaneCustom: BorderPane
|
||||||
@FXML lateinit var radioCustom: JFXRadioButton
|
@FXML lateinit var radioCustom: JFXRadioButton
|
||||||
@FXML lateinit var btnJavaSelect: JFXButton
|
@FXML lateinit var btnJavaSelect: JFXButton
|
||||||
|
@FXML lateinit var chkShowLogs: JFXToggleButton
|
||||||
|
|
||||||
val javaGroup = ToggleGroup()
|
val javaGroup = ToggleGroup()
|
||||||
|
|
||||||
@@ -81,6 +82,7 @@ class VersionSettingsController {
|
|||||||
chkNoJVMArgs.limitHeight(limitHeight)
|
chkNoJVMArgs.limitHeight(limitHeight)
|
||||||
chkNoCommon.limitHeight(limitHeight)
|
chkNoCommon.limitHeight(limitHeight)
|
||||||
chkNoGameCheck.limitHeight(limitHeight)
|
chkNoGameCheck.limitHeight(limitHeight)
|
||||||
|
chkShowLogs.limitHeight(limitHeight)
|
||||||
|
|
||||||
fun validation(field: JFXTextField) = InvalidationListener { field.validate() }
|
fun validation(field: JFXTextField) = InvalidationListener { field.validate() }
|
||||||
fun validator(nullable: Boolean = false) = NumberValidator(nullable).apply { message = "Must be a number." }
|
fun validator(nullable: Boolean = false) = NumberValidator(nullable).apply { message = "Must be a number." }
|
||||||
@@ -138,6 +140,7 @@ class VersionSettingsController {
|
|||||||
notCheckGameProperty.unbind()
|
notCheckGameProperty.unbind()
|
||||||
noCommonProperty.unbind()
|
noCommonProperty.unbind()
|
||||||
javaDirProperty.unbind()
|
javaDirProperty.unbind()
|
||||||
|
showLogsProperty.unbind()
|
||||||
unbindEnum(cboLauncherVisibility)
|
unbindEnum(cboLauncherVisibility)
|
||||||
unbindEnum(cboRunDirectory)
|
unbindEnum(cboRunDirectory)
|
||||||
}
|
}
|
||||||
@@ -157,6 +160,7 @@ class VersionSettingsController {
|
|||||||
bindBoolean(chkFullscreen, version.fullscreenProperty)
|
bindBoolean(chkFullscreen, version.fullscreenProperty)
|
||||||
bindBoolean(chkNoGameCheck, version.notCheckGameProperty)
|
bindBoolean(chkNoGameCheck, version.notCheckGameProperty)
|
||||||
bindBoolean(chkNoCommon, version.noCommonProperty)
|
bindBoolean(chkNoCommon, version.noCommonProperty)
|
||||||
|
bindBoolean(chkShowLogs, version.showLogsProperty)
|
||||||
|
|
||||||
val javaGroupKey = "java_group.listener"
|
val javaGroupKey = "java_group.listener"
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
|||||||
@@ -15,9 +15,7 @@
|
|||||||
<StackPane xmlns="http://javafx.com/javafx"
|
<StackPane xmlns="http://javafx.com/javafx"
|
||||||
xmlns:fx="http://javafx.com/fxml"
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
fx:controller="org.jackhuang.hmcl.ui.VersionSettingsController">
|
fx:controller="org.jackhuang.hmcl.ui.VersionSettingsController">
|
||||||
<ScrollPane fx:id="scroll"
|
<ScrollPane fx:id="scroll" fitToHeight="true" fitToWidth="true">
|
||||||
style="-fx-font-size: 14; -fx-pref-width: 100%; "
|
|
||||||
fitToHeight="true" fitToWidth="true">
|
|
||||||
<VBox fx:id="rootPane" style="-fx-padding: 20;">
|
<VBox fx:id="rootPane" style="-fx-padding: 20;">
|
||||||
<ComponentList depth="1">
|
<ComponentList depth="1">
|
||||||
|
|
||||||
@@ -97,6 +95,8 @@
|
|||||||
</BorderPane>
|
</BorderPane>
|
||||||
</right>
|
</right>
|
||||||
</BorderPane>
|
</BorderPane>
|
||||||
|
|
||||||
|
<BorderPane><left><Label text="%mainwindow.show_log" /></left><right><JFXToggleButton fx:id="chkShowLogs" size="7" /></right></BorderPane>
|
||||||
</ComponentList>
|
</ComponentList>
|
||||||
<HBox alignment="CENTER" style="-fx-padding: 10 0 10 0;">
|
<HBox alignment="CENTER" style="-fx-padding: 10 0 10 0;">
|
||||||
<JFXButton text="%advancedsettings" onMouseClicked="#onShowAdvanced" />
|
<JFXButton text="%advancedsettings" onMouseClicked="#onShowAdvanced" />
|
||||||
|
|||||||
Reference in New Issue
Block a user