Add mod button in Mod page

This commit is contained in:
huangyuhui 2017-08-20 00:20:41 +08:00
parent 432fd287c9
commit bc53e944af
5 changed files with 94 additions and 2 deletions

View File

@ -58,6 +58,10 @@ object Controllers {
return decorator.showDialog(content)
}
fun dialog(text: String) {
dialog(MessageDialogPane(text, decorator.dialog))
}
fun closeDialog() {
decorator.dialog.close()
}

View File

@ -0,0 +1,37 @@
/*
* 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 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()
}
}
}

View File

@ -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"))
}
}
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXDialogLayout?>
<fx:root xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
type="StackPane">
<JFXDialogLayout>
<heading>
<Label>JFoenix Dialog</Label>
</heading>
<body>
<Label fx:id="content" textAlignment="JUSTIFY" wrapText="true" />
</body>
<actions>
<JFXButton fx:id="acceptButton" styleClass="dialog-accept">ACCEPT
</JFXButton>
</actions>
</JFXDialogLayout>
</fx:root>

View File

@ -3,12 +3,21 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.JFXButton?>
<StackPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.jackhuang.hmcl.ui.ModController">
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.jackhuang.hmcl.ui.ModController">
<ScrollPane fx:id="scrollPane" fitToWidth="true" fitToHeight="true">
<VBox fx:id="rootPane" spacing="10" style="-fx-padding: 20;">
</VBox>
</ScrollPane>
<VBox style="-fx-padding: 15;" spacing="15" pickOnBounds="false" alignment="BOTTOM_RIGHT">
<JFXButton prefWidth="40" prefHeight="40" buttonType="RAISED" fx:id="btnAdd" onMouseClicked="#onAdd"
style="-fx-background-color:#5264AE;-fx-background-radius: 50px;">
<graphic>
<fx:include source="/assets/svg/plus.fxml" />
</graphic>
</JFXButton>
</VBox>
</StackPane>