From b40b0ec47c82dbd15e1e9229d1d7f6ed404250ae Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Mon, 21 Aug 2017 22:57:45 +0800 Subject: [PATCH] Version setting pane context menu --- .../kotlin/org/jackhuang/hmcl/ui/FXUtils.kt | 49 +++++++++++- .../org/jackhuang/hmcl/ui/VersionPage.kt | 77 +++++++++++++++++-- .../resources/assets/fxml/message-dialog.fxml | 8 +- .../assets/fxml/version-settings.fxml | 4 +- .../main/resources/assets/fxml/version.fxml | 37 +++++++-- .../resources/assets/lang/I18N.properties | 2 +- .../resources/assets/lang/I18N_ru.properties | 2 +- .../resources/assets/lang/I18N_vi.properties | 2 +- .../resources/assets/lang/I18N_zh.properties | 2 +- .../assets/lang/I18N_zh_CN.properties | 2 +- .../resources/assets/svg/folder-black.fxml | 2 + .../resources/assets/svg/wrench-black.fxml | 2 + .../kotlin/org/jackhuang/hmcl/game/Version.kt | 6 +- 13 files changed, 160 insertions(+), 35 deletions(-) create mode 100644 HMCL/src/main/resources/assets/svg/folder-black.fxml create mode 100644 HMCL/src/main/resources/assets/svg/wrench-black.fxml diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/FXUtils.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/FXUtils.kt index 6a996e227..d7e4761c4 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/FXUtils.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/FXUtils.kt @@ -32,9 +32,7 @@ import javafx.fxml.FXMLLoader import javafx.scene.Node import javafx.scene.Parent import javafx.scene.Scene -import javafx.scene.control.ListView -import javafx.scene.control.ScrollBar -import javafx.scene.control.ScrollPane +import javafx.scene.control.* import javafx.scene.image.WritableImage import javafx.scene.input.MouseEvent import javafx.scene.input.ScrollEvent @@ -42,6 +40,11 @@ import javafx.scene.layout.Region import javafx.scene.shape.Rectangle import javafx.util.Duration import org.jackhuang.hmcl.Main +import org.jackhuang.hmcl.util.LOG +import org.jackhuang.hmcl.util.OS +import java.io.File +import java.io.IOException +import java.util.logging.Level fun Node.loadFXML(absolutePath: String) { val fxmlLoader = FXMLLoader(this.javaClass.getResource(absolutePath), Main.RESOURCE_BUNDLE) @@ -187,4 +190,42 @@ fun JFXMasonryPane.resetChildren(children: List) { // Fixes mis-repositioning. ReflectionHelper.setFieldContent(JFXMasonryPane::class.java, this, "oldBoxes", null) this.children.setAll(children) -} \ No newline at end of file +} + +fun openFolder(f: File) { + f.mkdirs() + val path = f.absolutePath + when (OS.CURRENT_OS) { + OS.OSX -> + try { + Runtime.getRuntime().exec(arrayOf("/usr/bin/open", path)); + } catch (ex: IOException) { + LOG.log(Level.SEVERE, "Failed to open $path through /usr/bin/open", ex); + } + else -> + try { + java.awt.Desktop.getDesktop().open(f); + } catch (ex: Throwable) { + LOG.log(Level.SEVERE, "Failed to open $path through java.awt.Desktop.getDesktop().open()", ex); + } + } +} + +@JvmOverloads +fun alert(type: Alert.AlertType, title: String, contentText: String, headerText: String? = null): Boolean { + Alert(type).apply { + this.title = title + this.headerText = headerText + this.contentText = contentText + }.showAndWait().run { + return isPresent && get() == ButtonType.OK + } +} + +@JvmOverloads +fun inputDialog(title: String, contentText: String, headerText: String? = null, defaultValue: String = "") = + TextInputDialog(defaultValue).apply { + this.title = title + this.headerText = headerText + this.contentText = contentText + }.showAndWait() \ No newline at end of file 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 fd5e65e72..deb7fb258 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt @@ -18,36 +18,97 @@ package org.jackhuang.hmcl.ui import com.jfoenix.controls.* -import javafx.beans.InvalidationListener -import javafx.beans.property.Property import javafx.beans.property.SimpleStringProperty import javafx.beans.property.StringProperty -import javafx.beans.value.ChangeListener import javafx.fxml.FXML -import javafx.scene.control.Label -import javafx.scene.control.ScrollPane +import javafx.scene.control.Alert import javafx.scene.layout.* -import javafx.stage.DirectoryChooser +import org.jackhuang.hmcl.download.GameAssetIndexDownloadTask import org.jackhuang.hmcl.i18n import org.jackhuang.hmcl.setting.Profile -import org.jackhuang.hmcl.setting.VersionSetting import org.jackhuang.hmcl.ui.wizard.DecoratorPage -import org.jackhuang.hmcl.util.OS class VersionPage : StackPane(), DecoratorPage { override val titleProperty: StringProperty = SimpleStringProperty(this, "title", null) @FXML lateinit var versionSettingsController: VersionSettingsController @FXML lateinit var modController: ModController + @FXML lateinit var browseList: JFXListView<*> + @FXML lateinit var managementList: JFXListView<*> + @FXML lateinit var btnBrowseMenu: JFXButton + @FXML lateinit var btnManagementMenu: JFXButton + val browsePopup: JFXPopup + val managementPopup: JFXPopup + lateinit var profile: Profile + lateinit var version: String init { loadFXML("/assets/fxml/version.fxml") + + children -= browseList + children -= managementList + + browsePopup = JFXPopup(browseList) + managementPopup = JFXPopup(managementList) } fun load(id: String, profile: Profile) { + this.version = id + this.profile = profile titleProperty.set(i18n("launcher.title.game") + " - " + id) versionSettingsController.loadVersionSetting(profile.getVersionSetting(id)) modController.loadMods(profile.modManager, id) } + + fun onBrowseMenu() { + browseList.selectionModel.select(-1) + browsePopup.show(btnBrowseMenu, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, -12.0, 15.0) + } + + fun onManagementMenu() { + managementList.selectionModel.select(-1) + managementPopup.show(btnManagementMenu, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, -12.0, 15.0) + } + + fun onBrowse() { + openFolder(profile.repository.getRunDirectory(version).resolve(when (browseList.selectionModel.selectedIndex) { + 0 -> "" + 1 -> "mods" + 2 -> "coremods" + 3 -> "config" + 4 -> "resourcepacks" + 5 -> "screenshots" + 6 -> "saves" + else -> throw Error() + })) + } + + fun onManagement() { + when(managementList.selectionModel.selectedIndex) { + 0 -> { // rename a version + val res = inputDialog(title = "Input", contentText = i18n("versions.manage.rename.message"), defaultValue = version) + if (res.isPresent) + if (profile.repository.renameVersion(version, res.get())) { + profile.repository.refreshVersions() + Controllers.navigate(null) + } + } + 1 -> { // remove a version + if (alert(Alert.AlertType.CONFIRMATION, "Confirm", i18n("versions.manage.remove.confirm") + version)) + if (profile.repository.removeVersionFromDisk(version)) { + profile.repository.refreshVersions() + Controllers.navigate(null) + } + } + 2 -> { // redownload asset index + GameAssetIndexDownloadTask(profile.dependency, profile.repository.getVersion(version).resolve(profile.repository)).start() + } + 3 -> { // delete libraries + profile.repository.baseDirectory.resolve("libraries").deleteRecursively() + } + else -> throw Error() + } + } + } \ No newline at end of file diff --git a/HMCL/src/main/resources/assets/fxml/message-dialog.fxml b/HMCL/src/main/resources/assets/fxml/message-dialog.fxml index e8fe81dc7..b40a77532 100644 --- a/HMCL/src/main/resources/assets/fxml/message-dialog.fxml +++ b/HMCL/src/main/resources/assets/fxml/message-dialog.fxml @@ -1,8 +1,5 @@ - - - @@ -13,14 +10,13 @@ type="StackPane"> - + diff --git a/HMCL/src/main/resources/assets/fxml/version-settings.fxml b/HMCL/src/main/resources/assets/fxml/version-settings.fxml index c6bb7a4bf..ef0b32591 100644 --- a/HMCL/src/main/resources/assets/fxml/version-settings.fxml +++ b/HMCL/src/main/resources/assets/fxml/version-settings.fxml @@ -13,8 +13,8 @@ + xmlns:fx="http://javafx.com/fxml" + fx:controller="org.jackhuang.hmcl.ui.VersionSettingsController"> diff --git a/HMCL/src/main/resources/assets/fxml/version.fxml b/HMCL/src/main/resources/assets/fxml/version.fxml index e7094adc8..1d9ec61a7 100644 --- a/HMCL/src/main/resources/assets/fxml/version.fxml +++ b/HMCL/src/main/resources/assets/fxml/version.fxml @@ -15,12 +15,33 @@ - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 94514d7be..d5bc88ad0 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -353,7 +353,7 @@ versions.manage.remove=Delete this version versions.manage.remove.confirm=Sure to remove the version versions.manage.redownload_json=Redownload Minecraft Configuration(minecraft.json) versions.manage.redownload_assets_index=Redownload Assets Index -versions.mamage.remove_libraries=Delete library files +versions.manage.remove_libraries=Delete library files advice.os64butjdk32=Your OS is 64-Bit but your Java is 32-Bit. The 64-Bit Java is recommended. advice.java8=Java 8 is suggested, which can make game run more fluently. And many mods and Minecraft 1.12 and newer versions requires Java 8. diff --git a/HMCL/src/main/resources/assets/lang/I18N_ru.properties b/HMCL/src/main/resources/assets/lang/I18N_ru.properties index 30dd5935f..660d983d2 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ru.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ru.properties @@ -353,7 +353,7 @@ versions.manage.remove=Удалить версию versions.manage.remove.confirm=Не забудьте удалить версию versions.manage.redownload_json=Повторная загрузка конфигурации в Minecraft(minecraft.json) versions.manage.redownload_assets_index=Перекачать библиотеки -versions.mamage.remove_libraries=Библиотека удалить файлы +versions.manage.remove_libraries=Библиотека удалить файлы advice.os64butjdk32=Ваша ОС 64-битная, но ваш java является 32-разрядной. Вам рекомендуется 64-разрядная версия java. advice.java8=Java 8 представляет предположил, что может сделать игру работать более производительной. Многие моды и Minecraft 1.12 и новые версии требуют java 8. diff --git a/HMCL/src/main/resources/assets/lang/I18N_vi.properties b/HMCL/src/main/resources/assets/lang/I18N_vi.properties index a5a32c980..5dccf6d98 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_vi.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_vi.properties @@ -351,7 +351,7 @@ versions.manage.remove=Xóa phiên bản này versions.manage.remove.confirm=Bạn có chắc để xóa phiên bản này không? versions.manage.redownload_json=Download lại cấu hình của minecraft(minecraft.json) versions.manage.redownload_assets_index=Download lại Assets Index -versions.mamage.remove_libraries=Xóa libraries file +versions.manage.remove_libraries=Xóa libraries file advice.os64butjdk32=Hệ điều hành của bạn là 64-Bit nhưng phiên bản Java của bạn là 32-Bit. Khuyên bạn nên dùng Java 64-Bit. advice.java8=Java 8 is suggested, which can make game run more fluently. And many mods and Minecraft 1.12 and newer versions requires Java 8. diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 1bcbb995d..04ebfa863 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -353,7 +353,7 @@ versions.manage.remove=刪除該版本 versions.manage.remove.confirm=真的要刪除版本 versions.manage.redownload_json=重新下載版本配置(minecraft.json) versions.manage.redownload_assets_index=重新下載資源配置(assets_index.json) -versions.mamage.remove_libraries=刪除所有庫檔 +versions.manage.remove_libraries=刪除所有庫檔 advice.os64butjdk32=您的系統是64-bit,但是Java是32位的,推薦您安裝64位Java. advice.java8=檢測到您未使用Java 8及更新版本,Java 8能使遊戲更流暢而且Minecraft 1.12及更新版本和很多Mod強制需要需要Java 8。 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index cbf6e30ee..71ca14f88 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -353,7 +353,7 @@ versions.manage.remove=删除该版本 versions.manage.remove.confirm=真的要删除版本 versions.manage.redownload_json=重新下载版本配置(minecraft.json) versions.manage.redownload_assets_index=重新下载资源配置(assets_index.json) -versions.mamage.remove_libraries=删除所有库文件 +versions.manage.remove_libraries=删除所有库文件 advice.os64butjdk32=您的系统是64位的但是Java是32位的,推荐您安装64位Java. advice.java8=检测到您未使用Java 8及更新版本,Java 8能使游戏更流畅而且Minecraft 1.12及更新版本和很多Mod强制需要需要Java 8。 diff --git a/HMCL/src/main/resources/assets/svg/folder-black.fxml b/HMCL/src/main/resources/assets/svg/folder-black.fxml new file mode 100644 index 000000000..7a5dcacb5 --- /dev/null +++ b/HMCL/src/main/resources/assets/svg/folder-black.fxml @@ -0,0 +1,2 @@ + + diff --git a/HMCL/src/main/resources/assets/svg/wrench-black.fxml b/HMCL/src/main/resources/assets/svg/wrench-black.fxml new file mode 100644 index 000000000..1a784e580 --- /dev/null +++ b/HMCL/src/main/resources/assets/svg/wrench-black.fxml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt index eb60539f3..427d10d5b 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt @@ -111,8 +111,10 @@ open class Version( protected open fun resolve(provider: VersionProvider, resolvedSoFar: MutableSet): Version { if (this.inheritsFrom == null) return this - if (!resolvedSoFar.add(this.id)) - throw CircleDependencyException(resolvedSoFar.toString()) + if (!resolvedSoFar.add(this.id)) { + LOG.warning("Found circular dependency versions: $resolvedSoFar") + return this + } // It is supposed to auto install an version in getVersion. val parent = provider.getVersion(this.inheritsFrom).resolve(provider, resolvedSoFar)