diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/Controllers.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/Controllers.kt index a27328e23..8cd828f80 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/Controllers.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/Controllers.kt @@ -58,6 +58,10 @@ object Controllers { return decorator.showDialog(content) } + fun dialog(text: String) { + dialog(MessageDialogPane(text, decorator.dialog)) + } + fun closeDialog() { decorator.dialog.close() } diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/MessageDialogPane.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/MessageDialogPane.kt new file mode 100644 index 000000000..96a170269 --- /dev/null +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/MessageDialogPane.kt @@ -0,0 +1,37 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2017 huangyuhui + * + * 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 com.jfoenix.controls.JFXButton +import com.jfoenix.controls.JFXDialog +import javafx.fxml.FXML +import javafx.scene.control.Label +import javafx.scene.layout.StackPane + +class MessageDialogPane(val text: String, val dialog: JFXDialog): StackPane() { + @FXML lateinit var acceptButton: JFXButton + @FXML lateinit var content: Label + init { + loadFXML("/assets/fxml/message-dialog.fxml") + content.text = text + acceptButton.setOnMouseClicked { + dialog.close() + } + } + +} \ 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 c596ef6ce..71dc772f1 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt @@ -21,6 +21,8 @@ import com.jfoenix.effects.JFXDepthManager import javafx.fxml.FXML import javafx.scene.control.ScrollPane import javafx.scene.layout.VBox +import javafx.stage.FileChooser +import org.jackhuang.hmcl.i18n import org.jackhuang.hmcl.mod.ModManager import org.jackhuang.hmcl.task.Scheduler import org.jackhuang.hmcl.task.task @@ -45,6 +47,7 @@ class ModController { for (modInfo in modManager.getMods(versionId)) { rootPane.children += ModItem(modInfo) { modManager.removeMods(versionId, modInfo) + loadMods(modManager, versionId) }.apply { JFXDepthManager.setDepth(this, 1) style += "-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;" @@ -62,4 +65,17 @@ class ModController { } } } + + fun onAdd() { + val chooser = FileChooser() + chooser.title = i18n("mods.choose_mod") + chooser.extensionFilters.setAll(FileChooser.ExtensionFilter("Mod", "*.jar", "*.zip", "*.litemod")) + val res = chooser.showOpenDialog(Controllers.stage) ?: return + try { + modManager.addMod(versionId, res) + loadMods(modManager, versionId) + } catch (e: Exception) { + Controllers.dialog(i18n("mods.failed")) + } + } } \ 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 new file mode 100644 index 000000000..e8fe81dc7 --- /dev/null +++ b/HMCL/src/main/resources/assets/fxml/message-dialog.fxml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/HMCL/src/main/resources/assets/fxml/mod.fxml b/HMCL/src/main/resources/assets/fxml/mod.fxml index 68a651082..b3d8aa912 100644 --- a/HMCL/src/main/resources/assets/fxml/mod.fxml +++ b/HMCL/src/main/resources/assets/fxml/mod.fxml @@ -3,12 +3,21 @@ + + xmlns:fx="http://javafx.com/fxml" + fx:controller="org.jackhuang.hmcl.ui.ModController"> + + + + + + +