From adc8c8f3b32a320f0dddb58295a9d7f4dc80e14b Mon Sep 17 00:00:00 2001 From: cubewhy Date: Sun, 14 Jan 2024 16:36:39 +0800 Subject: [PATCH] config of loaders installation --- .../celestial/game/addon/LunarCNMod.java | 4 ++ .../celestial/game/addon/WeaveMod.java | 4 ++ .../celestial/gui/pages/GuiSettings.java | 37 +++++++++++++++++++ .../org/cubewhy/celestial/utils/GuiUtils.java | 9 +++++ .../resources/languages/launcher.properties | 4 +- .../languages/launcher_en.properties | 4 +- .../languages/launcher_zh.properties | 4 +- 7 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cubewhy/celestial/game/addon/LunarCNMod.java b/src/main/java/org/cubewhy/celestial/game/addon/LunarCNMod.java index 27bed1ab..4ec3f64a 100644 --- a/src/main/java/org/cubewhy/celestial/game/addon/LunarCNMod.java +++ b/src/main/java/org/cubewhy/celestial/game/addon/LunarCNMod.java @@ -57,6 +57,10 @@ public static List findAll() { return list; } + public static File getInstallation() { + return new File(config.getValue("addon").getAsJsonObject().get("lunarcn").getAsJsonObject().get("installation").getAsString()); + } + public static boolean checkUpdate() throws MalformedURLException { log.info("Updating LunarCN Loader..."); statusBar.setText(f.getString("gui.addon.mods.cn.warn")); diff --git a/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java b/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java index 3b23202b..eb89320f 100644 --- a/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java +++ b/src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java @@ -64,6 +64,10 @@ public static List findAll() { return (target == null) ? null : new WeaveMod(target); } + public static File getInstallation() { + return new File(config.getValue("addon").getAsJsonObject().get("weave").getAsJsonObject().get("installation").getAsString()); + } + @Override public String toString() { return this.file.getName(); diff --git a/src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java b/src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java index c52b1aae..d63ee990 100644 --- a/src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java +++ b/src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java @@ -4,6 +4,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import lombok.extern.slf4j.Slf4j; +import org.cubewhy.celestial.game.addon.LunarCNMod; +import org.cubewhy.celestial.game.addon.WeaveMod; import org.cubewhy.celestial.gui.dialogs.ArgsConfigDialog; import org.cubewhy.celestial.gui.layouts.VerticalFlowLayout; import org.cubewhy.celestial.utils.GuiUtils; @@ -221,6 +223,36 @@ private void initGui() { p10.add(btnWeave); p10.add(btnLunarCN); panelAddon.add(p10); + // installation (loader) + JPanel p11 = new JPanel(); + // lunarcn + JButton btnSelectLunarCNInstallation = new JButton(LunarCNMod.getInstallation().getPath()); + btnSelectLunarCNInstallation.addActionListener((e) -> { + File file = GuiUtils.saveFile(new FileNameExtensionFilter("LunarCN Loader", "jar")); + if (file == null) { + return; + } + JButton source = (JButton) e.getSource(); + source.setText(file.getPath()); + setModLoaderInstallation("lunarcn", file); + }); + p11.add(new JLabel(f.getString("gui.settings.addon.loader.cn.installation"))); + p11.add(btnSelectLunarCNInstallation); + panelAddon.add(p11); + JPanel p12 = new JPanel(); + JButton btnSelectWeaveInstallation = new JButton(WeaveMod.getInstallation().getPath()); + btnSelectWeaveInstallation.addActionListener((e) -> { + File file = GuiUtils.saveFile(new FileNameExtensionFilter("Weave Loader", "jar")); + if (file == null) { + return; + } + JButton source = (JButton) e.getSource(); + source.setText(file.getPath()); + setModLoaderInstallation("weave", file); + }); + p12.add(new JLabel(f.getString("gui.settings.addon.loader.weave.installation"))); + p12.add(btnSelectWeaveInstallation); + panelAddon.add(p12); claim("addon", panelAddon); @@ -231,6 +263,11 @@ private void initGui() { panel.add(panelUnclaimed); } + private void setModLoaderInstallation(String key, @NotNull File file) { + config.getValue("addon").getAsJsonObject().getAsJsonObject(key).addProperty("installation", file.getPath()); + config.save(); + } + /** * Toggle loader * diff --git a/src/main/java/org/cubewhy/celestial/utils/GuiUtils.java b/src/main/java/org/cubewhy/celestial/utils/GuiUtils.java index a787d4de..f814a3e4 100644 --- a/src/main/java/org/cubewhy/celestial/utils/GuiUtils.java +++ b/src/main/java/org/cubewhy/celestial/utils/GuiUtils.java @@ -11,6 +11,7 @@ import javax.swing.*; import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; import java.io.File; public final class GuiUtils { @@ -30,4 +31,12 @@ private GuiUtils() { fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); return (fileDialog.showOpenDialog(Celestial.launcherFrame) == JFileChooser.CANCEL_OPTION) ? null : fileDialog.getSelectedFile(); } + + public static File saveFile(FileNameExtensionFilter filter) { + JFileChooser fileDialog = new JFileChooser(); + fileDialog.setFileFilter(filter); + fileDialog.addChoosableFileFilter(filter); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + return (fileDialog.showSaveDialog(Celestial.launcherFrame) == JFileChooser.CANCEL_OPTION) ? null : fileDialog.getSelectedFile(); + } } diff --git a/src/main/resources/languages/launcher.properties b/src/main/resources/languages/launcher.properties index 9d4f0548..1d82a951 100644 --- a/src/main/resources/languages/launcher.properties +++ b/src/main/resources/languages/launcher.properties @@ -162,4 +162,6 @@ gui.plugins.download=Download %s gui.plugin.unsupported=You are using an API that does not support the plugin market (e.g. the official API), so there is nothing here gui.plugin.exist=Exist gui.settings.addon=Addon -gui.settings.addon.loader.unset=Unset \ No newline at end of file +gui.settings.addon.loader.unset=Unset +gui.settings.addon.loader.weave.installation=Weave installation: +gui.settings.addon.loader.cn.installation=LuanrCN installation: \ No newline at end of file diff --git a/src/main/resources/languages/launcher_en.properties b/src/main/resources/languages/launcher_en.properties index 76fa5614..a8df7018 100644 --- a/src/main/resources/languages/launcher_en.properties +++ b/src/main/resources/languages/launcher_en.properties @@ -162,4 +162,6 @@ gui.plugins.download=Download %s gui.plugin.unsupported=You are using an API that does not support the plugin market (e.g. the official API), so there is nothing here gui.plugin.exist=Exist gui.settings.addon=Addon -gui.settings.addon.loader.unset=Unset \ No newline at end of file +gui.settings.addon.loader.unset=Unset +gui.settings.addon.loader.weave.installation=Weave installation: +gui.settings.addon.loader.cn.installation=LuanrCN installation: \ No newline at end of file diff --git a/src/main/resources/languages/launcher_zh.properties b/src/main/resources/languages/launcher_zh.properties index 499e77c8..b4f7dd2e 100644 --- a/src/main/resources/languages/launcher_zh.properties +++ b/src/main/resources/languages/launcher_zh.properties @@ -161,4 +161,6 @@ gui.plugins.download=下载 %s gui.plugin.unsupported=你正在使用不支持插件市场的API(例如官方API),所以此处什么都没有 gui.plugin.exist=已存在 gui.settings.addon=加载项 -gui.settings.addon.loader.unset=不使用模组加载器 \ No newline at end of file +gui.settings.addon.loader.unset=不使用模组加载器 +gui.settings.addon.loader.weave.installation=Weave安装: +gui.settings.addon.loader.cn.installation=LunarCN安装: \ No newline at end of file