Skip to content

Commit

Permalink
toggle loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jan 14, 2024
1 parent 9a608fe commit 45a3d3f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down
78 changes: 78 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 @@ -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;
Expand Down Expand Up @@ -194,13 +195,90 @@ 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));
addUnclaimed(panelUnclaimed, config.getConfig());
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<String, JsonElement> s : json.entrySet()) {
if (!claimed.contains(s.getKey())) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/languages/launcher.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
gui.plugin.exist=Exist
gui.settings.addon=Addon
gui.settings.addon.loader.unset=Unset
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 @@ -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
gui.plugin.exist=Exist
gui.settings.addon=Addon
gui.settings.addon.loader.unset=Unset
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 @@ -159,4 +159,6 @@ gui.plugin.title=插件市场
gui.plugin.refresh=刷新
gui.plugins.download=下载 %s
gui.plugin.unsupported=你正在使用不支持插件市场的API(例如官方API),所以此处什么都没有
gui.plugin.exist=已存在
gui.plugin.exist=已存在
gui.settings.addon=加载项
gui.settings.addon.loader.unset=不使用模组加载器

0 comments on commit 45a3d3f

Please sign in to comment.