Skip to content

Commit

Permalink
config of loaders installation
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jan 14, 2024
1 parent 45a3d3f commit adc8c8f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public static List<LunarCNMod> 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"));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/cubewhy/celestial/game/addon/WeaveMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public static List<WeaveMod> 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();
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/cubewhy/celestial/utils/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
}
4 changes: 3 additions & 1 deletion src/main/resources/languages/launcher.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
gui.settings.addon.loader.unset=Unset
gui.settings.addon.loader.weave.installation=Weave installation:
gui.settings.addon.loader.cn.installation=LuanrCN installation:
4 changes: 3 additions & 1 deletion src/main/resources/languages/launcher_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
gui.settings.addon.loader.unset=Unset
gui.settings.addon.loader.weave.installation=Weave installation:
gui.settings.addon.loader.cn.installation=LuanrCN installation:
4 changes: 3 additions & 1 deletion src/main/resources/languages/launcher_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,6 @@ gui.plugins.download=下载 %s
gui.plugin.unsupported=你正在使用不支持插件市场的API(例如官方API),所以此处什么都没有
gui.plugin.exist=已存在
gui.settings.addon=加载项
gui.settings.addon.loader.unset=不使用模组加载器
gui.settings.addon.loader.unset=不使用模组加载器
gui.settings.addon.loader.weave.installation=Weave安装:
gui.settings.addon.loader.cn.installation=LunarCN安装:

0 comments on commit adc8c8f

Please sign in to comment.