diff --git a/build.gradle b/build.gradle index 64bab1e3..72df0589 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'org.cubewhy.celestial' -version = '1.4-pre1-SNAPSHOT' +version = '1.4-pre2-SNAPSHOT' println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) println('Celestial Launcher -> https://www.lunarclient.top/') 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 44bc1947..c52b1aae 100644 --- a/src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java +++ b/src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java @@ -9,6 +9,7 @@ import org.cubewhy.celestial.utils.GuiUtils; import org.cubewhy.celestial.utils.SystemUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.TitledBorder; @@ -194,6 +195,35 @@ private void initGui() { claim("installation-dir"); claim("game-dir"); + // addon + JPanel panelAddon = new JPanel(); + panelAddon.setLayout(new VerticalFlowLayout(VerticalFlowLayout.LEFT)); + panelAddon.setBorder(new TitledBorder(null, f.getString("gui.settings.addon"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.orange)); + JPanel p10 = new JPanel(); + ButtonGroup btnGroup = new ButtonGroup(); + JRadioButton btnLoaderUnset = new JRadioButton(f.getString("gui.settings.addon.loader.unset"), isLoaderSelected(null)); + btnGroup.add(btnLoaderUnset); + JRadioButton btnWeave = new JRadioButton("Weave", isLoaderSelected("weave")); + btnGroup.add(btnWeave); + JRadioButton btnLunarCN = new JRadioButton("LunarCN", isLoaderSelected("cn")); + btnGroup.add(btnLunarCN); + btnLoaderUnset.addActionListener((e) -> { + // make weave & cn = false + toggleLoader(null); + }); + btnWeave.addActionListener((e) -> { + toggleLoader("weave"); + }); + btnLunarCN.addActionListener((e) -> { + toggleLoader("cn"); + }); + p10.add(btnLoaderUnset); + p10.add(btnWeave); + p10.add(btnLunarCN); + panelAddon.add(p10); + + claim("addon", panelAddon); + JPanel panelUnclaimed = new JPanel(); panelUnclaimed.setBorder(new TitledBorder(null, f.getString("gui.settings.unclaimed"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.orange)); panelUnclaimed.setLayout(new VerticalFlowLayout(VerticalFlowLayout.LEFT)); @@ -201,6 +231,54 @@ private void initGui() { panel.add(panelUnclaimed); } + /** + * Toggle loader + * + * @param type null, cn, weave + */ + private void toggleLoader(@Nullable String type) { + boolean b1 = false; // weave + boolean b2 = false; // lccn + if (type != null) { + if (type.equals("cn")) { + b2 = true; + } else if (type.equals("weave")) { + b1 = true; + } + } + JsonObject addon = config.getValue("addon").getAsJsonObject(); + JsonObject weave = addon.get("weave").getAsJsonObject(); + JsonObject cn = addon.get("lunarcn").getAsJsonObject(); + weave.addProperty("enable", b1); + cn.addProperty("enable", b2); + config.save(); + } + + private boolean isLoaderSelected(String type) { + JsonObject addon = config.getValue("addon").getAsJsonObject(); + JsonObject weave = addon.get("weave").getAsJsonObject(); + JsonObject cn = addon.get("lunarcn").getAsJsonObject(); + boolean stateWeave = weave.get("enable").getAsBoolean(); + boolean stateCN = cn.get("enable").getAsBoolean(); + if (stateWeave && stateCN && type != null) { + // correct it + + log.warn("Weave cannot load with LunarCN, auto corrected"); + weave.addProperty("enable", false); + cn.addProperty("enable", false); + config.save(); + return isLoaderSelected(null); + } + if (type == null) { + return !(stateWeave || stateCN); + } else if (type.equals("weave")) { + return stateWeave; + } else if (type.equals("cn")) { + return stateCN; + } + return false; + } + private void addUnclaimed(JPanel basePanel, @NotNull JsonObject json) { for (Map.Entry s : json.entrySet()) { if (!claimed.contains(s.getKey())) { diff --git a/src/main/resources/languages/launcher.properties b/src/main/resources/languages/launcher.properties index 10b9b125..9d4f0548 100644 --- a/src/main/resources/languages/launcher.properties +++ b/src/main/resources/languages/launcher.properties @@ -160,4 +160,6 @@ gui.plugin.title=Plugins gui.plugin.refresh=Refresh 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 \ No newline at end of file +gui.plugin.exist=Exist +gui.settings.addon=Addon +gui.settings.addon.loader.unset=Unset \ 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 61e30355..76fa5614 100644 --- a/src/main/resources/languages/launcher_en.properties +++ b/src/main/resources/languages/launcher_en.properties @@ -160,4 +160,6 @@ gui.plugin.title=Plugins gui.plugin.refresh=Refresh 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 \ No newline at end of file +gui.plugin.exist=Exist +gui.settings.addon=Addon +gui.settings.addon.loader.unset=Unset \ 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 07ddfcd0..499e77c8 100644 --- a/src/main/resources/languages/launcher_zh.properties +++ b/src/main/resources/languages/launcher_zh.properties @@ -159,4 +159,6 @@ gui.plugin.title=插件市场 gui.plugin.refresh=刷新 gui.plugins.download=下载 %s gui.plugin.unsupported=你正在使用不支持插件市场的API(例如官方API),所以此处什么都没有 -gui.plugin.exist=已存在 \ No newline at end of file +gui.plugin.exist=已存在 +gui.settings.addon=加载项 +gui.settings.addon.loader.unset=不使用模组加载器 \ No newline at end of file