diff --git a/HMCL/build.gradle b/HMCL/build.gradle index 2d94b82fe..8e4f7e7df 100644 --- a/HMCL/build.gradle +++ b/HMCL/build.gradle @@ -121,4 +121,5 @@ task makePackGZ(dependsOn: jar) doLast { } build.dependsOn makeExecutable -build.dependsOn makePackGZ \ No newline at end of file +//build.dependsOn makePackGZ +//Kotlin classes will be ignored by Pack200 due to class unrecognized attribute \ No newline at end of file diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountItem.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountItem.kt index 9b7d5db81..9a4bd285e 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountItem.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountItem.kt @@ -30,7 +30,7 @@ import javafx.scene.layout.StackPane import javafx.scene.layout.VBox import java.util.concurrent.Callable -class AccountItem(i: Int, width: Double, height: Double, group: ToggleGroup) : StackPane() { +class AccountItem(i: Int, group: ToggleGroup) : StackPane() { @FXML lateinit var icon: Pane @FXML lateinit var content: VBox @FXML lateinit var header: StackPane diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountsPage.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountsPage.kt index 9bacc35f7..5cde9d476 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountsPage.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/AccountsPage.kt @@ -112,7 +112,7 @@ class AccountsPage() : StackPane(), DecoratorPage { } private fun buildNode(i: Int, account: Account, group: ToggleGroup): Node { - return AccountItem(i, Math.random() * 100 + 100, Math.random() * 100 + 100, group).apply { + return AccountItem(i, group).apply { chkSelected.properties["account"] = account chkSelected.isSelected = Settings.selectedAccount == account lblUser.text = account.username diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/LeftPaneController.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/LeftPaneController.kt index ef5f3a59b..df12b53fb 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/LeftPaneController.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/LeftPaneController.kt @@ -99,7 +99,7 @@ class LeftPaneController(val leftPane: VBox) { fun onProfileChanged(event: ProfileChangedEvent) { val profile = event.value - profile.selectedVersionProperty.addListener { observable -> + profile.selectedVersionProperty.addListener { _ -> versionChanged(profile.selectedVersion) } profile.selectedVersionProperty.fireValueChangedEvent() @@ -122,14 +122,15 @@ class LeftPaneController(val leftPane: VBox) { ripplerContainer.selected = true profile.selectedVersion = version.id } - ripplerContainer.userData = version.id to item + ripplerContainer.properties["version"] = version.id to item versionsPane.children += ripplerContainer } } + @Suppress("UNCHECKED_CAST") fun versionChanged(selectedVersion: String) { versionsPane.children - .filter { it is RipplerContainer && it.userData is Pair<*, *> } - .forEach { (it as RipplerContainer).selected = (it.userData as Pair).first == selectedVersion } + .filter { it is RipplerContainer && it.properties["version"] is Pair<*, *> } + .forEach { (it as RipplerContainer).selected = (it.properties["version"] as Pair).first == selectedVersion } } } \ No newline at end of file diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt index 012c037f8..10429187d 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt @@ -29,14 +29,16 @@ import java.util.concurrent.Callable class ModController { @FXML lateinit var scrollPane: ScrollPane @FXML lateinit var rootPane: VBox - lateinit var modManager: ModManager - lateinit var versionId: String + private lateinit var modManager: ModManager + private lateinit var versionId: String fun initialize() { scrollPane.smoothScrolling() } - fun loadMods() { + fun loadMods(modManager: ModManager, versionId: String) { + this.modManager = modManager + this.versionId = versionId Task.of(Callable { modManager.refreshMods(versionId) }).subscribe(Scheduler.JAVAFX) { diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/RipplerContainer.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/RipplerContainer.kt index 97f22620c..605dd3114 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/RipplerContainer.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/RipplerContainer.kt @@ -129,7 +129,7 @@ open class RipplerContainer(@NamedArg("container") container: Node): StackPane() return@Callable background } }, backgroundProperty())) - ripplerFillProperty.addListener { o, oldVal, newVal -> this.buttonRippler.ripplerFill = newVal } + ripplerFillProperty.addListener { _, _, newVal -> this.buttonRippler.ripplerFill = newVal } if (background == null || this.isJavaDefaultBackground(background)) { background = Background(BackgroundFill(Color.TRANSPARENT, this.defaultRadii, null)) } @@ -149,11 +149,7 @@ open class RipplerContainer(@NamedArg("container") container: Node): StackPane() } protected fun updateChildren() { - children.add(container) - - if (this.buttonContainer != null) { - this.children.add(0, this.buttonContainer) - } + children.addAll(buttonContainer, container) for (i in 1..this.children.size - 1) { this.children[i].isPickOnBounds = false @@ -161,34 +157,6 @@ open class RipplerContainer(@NamedArg("container") container: Node): StackPane() } - fun layoutChildren(x: Double, y: Double, w: Double, h: Double) { - if (this.invalid) { - if (ripplerFill == null) { - for (i in this.children.size - 1 downTo 1) { - if (this.children[i] is Shape) { - this.buttonRippler.ripplerFill = (this.children[i] as Shape).fill - (this.children[i] as Shape).fillProperty().addListener { o, oldVal, newVal -> this.buttonRippler.ripplerFill = newVal } - break - } - - if (this.children[i] is Label) { - this.buttonRippler.ripplerFill = (this.children[i] as Label).textFill - (this.children[i] as Label).textFillProperty().addListener { o, oldVal, newVal -> this.buttonRippler.ripplerFill = newVal } - break - } - } - } else { - this.buttonRippler.ripplerFill = ripplerFill - } - - this.invalid = false - } - - val shift = 1.0 - this.buttonContainer.resizeRelocate(layoutBounds.minX - shift, layoutBounds.minY - shift, width + 2.0 * shift, height + 2.0 * shift) - //this.layoutLabelInArea(x, y, w, h) - } - private fun isJavaDefaultBackground(background: Background): Boolean { try { val firstFill = (background.fills[0] as BackgroundFill).fill.toString() diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt index 55b6745ad..808766ab2 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt @@ -46,9 +46,7 @@ class VersionPage : StackPane(), DecoratorPage { fun load(id: String, profile: Profile) { titleProperty.set("Version settings - " + id) - versionSettingsController.loadVersionSetting(id, profile.getVersionSetting(id)) - modController.modManager = profile.modManager - modController.versionId = id - modController.loadMods() + versionSettingsController.loadVersionSetting(profile.getVersionSetting(id)) + modController.loadMods(profile.modManager, id) } } \ No newline at end of file diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionSettingsController.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionSettingsController.kt index 8f00daf5d..1d095560f 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionSettingsController.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionSettingsController.kt @@ -71,7 +71,7 @@ class VersionSettingsController { txtMetaspace.textProperty().addListener(validation(txtMetaspace)) } - fun loadVersionSetting(id: String, version: VersionSetting) { + fun loadVersionSetting(version: VersionSetting) { rootPane.children -= advancedSettingsPane lastVersionSetting?.apply { diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/AbstractWizardDisplayer.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/AbstractWizardDisplayer.kt index 640e605cf..1a65f5e69 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/AbstractWizardDisplayer.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/AbstractWizardDisplayer.kt @@ -96,6 +96,7 @@ interface AbstractWizardDisplayer : WizardDisplayer { navigateTo(StackPane().apply { children += vbox }, Navigation.NavigationDirection.FINISH) task.executor().let { executor -> + @Suppress("NAME_SHADOWING") executor.taskListener = object : TaskListener { override fun onReady(task: Task) { Platform.runLater { tasksBar.progressProperty().set(finishedTasks * 1.0 / executor.totTask.get()) } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt index 2a331d1a4..1ed29157e 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt @@ -24,13 +24,10 @@ import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.io.File -private fun lessThan32(b: ByteArray, x: Int): Int { - var x = x - while (x < b.size) { - if (b[x] < 32) - return x - x++ - } +private fun lessThan32(b: ByteArray, startIndex: Int): Int { + for (i in startIndex until b.size) + if (b[i] < 32) + return i return -1 } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt index 3267db7c0..1096f3e63 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt @@ -68,7 +68,7 @@ class ModInfo ( val file = if (modFile.extension == DISABLED_EXTENSION) modFile.absoluteFile.parentFile.resolve(modFile.nameWithoutExtension) else modFile - var description = "Unrecognized mod file" + val description: String if (file.extension == "zip" || file.extension == "jar") try { return ForgeModMetadata.fromFile(modFile) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt index 4b7ee2d7d..72740fcab 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt @@ -113,6 +113,7 @@ abstract class Task { } fun executor() = TaskExecutor().submit(this) + fun executor(taskListener: TaskListener) = TaskExecutor().submit(this).apply { this.taskListener = taskListener } fun subscribe(subscriber: Task) = executor().apply { submit(subscriber).start()