mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-08 19:35:36 -04:00
Add mod button in Mod page
This commit is contained in:
parent
432fd287c9
commit
bc53e944af
@ -58,6 +58,10 @@ object Controllers {
|
||||
return decorator.showDialog(content)
|
||||
}
|
||||
|
||||
fun dialog(text: String) {
|
||||
dialog(MessageDialogPane(text, decorator.dialog))
|
||||
}
|
||||
|
||||
fun closeDialog() {
|
||||
decorator.dialog.close()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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"))
|
||||
}
|
||||
}
|
||||
}
|
26
HMCL/src/main/resources/assets/fxml/message-dialog.fxml
Normal file
26
HMCL/src/main/resources/assets/fxml/message-dialog.fxml
Normal 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>
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user