Skip to content

Commit

Permalink
Open folder buttons in GuiSettings & KO translate
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jan 17, 2024
1 parent 74e6828 commit 0d217f4
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .idea/resourceBundles.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Dec 09 14:24:38 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions src/main/java/org/cubewhy/celestial/Celestial.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private static void initConfig() {

config.initValue("jre", "") // leave empty if you want to use the default one
.initValue("language", "zh") // en, zh
.initValue("font", (JsonElement) null)
.initValue("installation-dir", new File(configDir, "game").getPath())
.initValue("game-dir", getMinecraftFolder().getPath()) // the minecraft folder
.initValue("game", (JsonElement) null)
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/org/cubewhy/celestial/gui/GuiLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.IOException;
import java.net.URI;
import java.util.Enumeration;
import java.util.Map;

import static org.cubewhy.celestial.Celestial.*;
Expand All @@ -41,6 +43,11 @@ public GuiLauncher() throws IOException {
// init icon
this.resetIcon();

// init font
if (!config.getValue("font").isJsonNull()) {
this.initFont(new Font(config.getValue("font").getAsString(), Font.PLAIN, 13));
}

this.initGui();
// show alert
Map<String, String> alert = LauncherData.getAlert(metadata);
Expand Down Expand Up @@ -84,7 +91,6 @@ private void initGui() throws IOException {
menu.add(btnNext);
menu.add(btnDonate);
menu.add(btnHelp);
// menu.add(btnLanguage);
menu.setSize(100, 20);

this.add(menu, BorderLayout.NORTH);
Expand All @@ -106,7 +112,7 @@ private void initGui() throws IOException {
this.add(mainPanel); // add MainPanel

// try to find the exist game process
new Thread(() ->{
new Thread(() -> {
try {
this.findExistGame();
} catch (IOException e) {
Expand All @@ -115,6 +121,19 @@ private void initGui() throws IOException {
}).start();
}

public void initFont(Font font) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
FontUIResource fontRes = new FontUIResource(font);
for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements(); ) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
UIManager.put(key, fontRes);
}
}
}

public void findExistGame() throws IOException {
try {
VirtualMachine java = SystemUtils.findJava(LauncherData.getMainClass(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.IOException;

import static org.cubewhy.celestial.Celestial.f;
import static org.cubewhy.celestial.utils.GuiUtils.createButtonOpenFolder;

@Slf4j
public class GuiAddonManager extends JPanel {
Expand Down Expand Up @@ -413,21 +414,6 @@ private void loadLunarCNMods(DefaultListModel<LunarCNMod> modList) {
}
}

private @NotNull JButton createButtonOpenFolder(String text, File folder) {
JButton btn = new JButton(text);
btn.addActionListener(e -> {
try {
if (folder.mkdirs()) {
log.info("Creating " + folder + " because the folder not exist");
}
Desktop.getDesktop().open(folder);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
return btn;
}

private static void loadWeaveMods(DefaultListModel<WeaveMod> weave) {
for (WeaveMod weaveMod : WeaveMod.findAll()) {
weave.addElement(weaveMod);
Expand Down
39 changes: 16 additions & 23 deletions src/main/java/org/cubewhy/celestial/gui/pages/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ public GuiSettings() {

private void initGui() {
// config
// jre
panel.add(new JLabel(f.getString("gui.settings.warn.restart")));
JPanel panelFolders = new JPanel();
panelFolders.add(GuiUtils.createButtonOpenFolder(f.getString("gui.settings.folder.main"), config.file.getParentFile()));
panelFolders.add(GuiUtils.createButtonOpenFolder(f.getString("gui.settings.folder.theme"), themesDir));
panelFolders.add(GuiUtils.createButtonOpenFolder(f.getString("gui.settings.folder.log"), launcherLogFile.getParentFile()));
panel.add(panelFolders);
// jre
JPanel panelVM = new JPanel();
panelVM.setLayout(new VerticalFlowLayout(VerticalFlowLayout.LEFT));
panelVM.setBorder(new TitledBorder(null, f.getString("gui.settings.jvm"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.orange));
Expand Down Expand Up @@ -104,9 +109,7 @@ private void initGui() {
JTextField wrapperInput = getAutoSaveTextField(config.getConfig(), "wrapper");
p3.add(wrapperInput);
JButton btnSetVMArgs = new JButton(f.getString("gui.settings.jvm.args"));
btnSetVMArgs.addActionListener((e) -> {
new ArgsConfigDialog("vm-args", config.getConfig()).setVisible(true);
});
btnSetVMArgs.addActionListener((e) -> new ArgsConfigDialog("vm-args", config.getConfig()).setVisible(true));
panelVM.add(btnSetVMArgs);
panelVM.add(p3);

Expand Down Expand Up @@ -167,7 +170,7 @@ private void initGui() {
// language
JPanel p6 = new JPanel();
p6.add(new JLabel(f.getString("gui.settings.launcher.language")));
p6.add(getAutoSaveComboBox(config.getConfig(), "language", List.of(new String[]{"zh", "en", "jp"})));
p6.add(getAutoSaveComboBox(config.getConfig(), "language", List.of(new String[]{"zh", "en", "ja", "ko"})));
panelLauncher.add(p6);
// max threads
JPanel p7 = new JPanel();
Expand Down Expand Up @@ -229,16 +232,9 @@ private void initGui() {
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");
});
btnLoaderUnset.addActionListener((e) -> toggleLoader(null));
btnWeave.addActionListener((e) -> toggleLoader("weave"));
btnLunarCN.addActionListener((e) -> toggleLoader("cn"));
p10.add(btnLoaderUnset);
p10.add(btnWeave);
p10.add(btnLunarCN);
Expand Down Expand Up @@ -375,20 +371,18 @@ private void addUnclaimed(JPanel basePanel, @NotNull JsonObject json) {
if (s.getValue().isJsonPrimitive()) {
JPanel p = getSimplePanel(json, s.getKey());
basePanel.add(p);
}
if (s.getValue().isJsonObject()) {
} else if (s.getValue().isJsonObject()) {
JPanel subPanel = new JPanel();
subPanel.setBorder(new TitledBorder(null, s.getKey(), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.orange));
subPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.LEFT));
basePanel.add(subPanel);
addUnclaimed(subPanel, s.getValue().getAsJsonObject());
}
if (s.getValue().isJsonArray()) {
} else if (s.getValue().isJsonArray()) {
JButton btnShowList = new JButton(s.getKey());
btnShowList.addActionListener((e) -> {
new ArgsConfigDialog(s.getKey(), json).setVisible(true);
});
btnShowList.addActionListener((e) -> new ArgsConfigDialog(s.getKey(), json).setVisible(true));
basePanel.add(btnShowList);
} else if (s.getValue().isJsonNull()) {
basePanel.add(new JLabel(s.getKey() + ": null"));
}
}
}
Expand Down Expand Up @@ -423,7 +417,6 @@ private void addUnclaimed(JPanel basePanel, @NotNull JsonObject json) {
panel.add(new JLabel(key));
JSpinner spinner = getAutoSaveSpinner(json, key, Double.MIN_VALUE, Double.MAX_VALUE);
panel.add(spinner);

}
return panel;
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/cubewhy/celestial/utils/GuiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

package org.cubewhy.celestial.utils;

import lombok.extern.slf4j.Slf4j;
import org.cubewhy.celestial.Celestial;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.io.File;
import java.io.IOException;

@Slf4j
public final class GuiUtils {
private GuiUtils() {
}
Expand All @@ -39,4 +44,19 @@ public static File saveFile(FileNameExtensionFilter filter) {
fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY);
return (fileDialog.showSaveDialog(Celestial.launcherFrame) == JFileChooser.CANCEL_OPTION) ? null : fileDialog.getSelectedFile();
}

public static @NotNull JButton createButtonOpenFolder(String text, File folder) {
JButton btn = new JButton(text);
btn.addActionListener(e -> {
try {
if (folder.mkdirs()) {
log.info("Creating " + folder + " because the folder not exist");
}
Desktop.getDesktop().open(folder);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
return btn;
}
}
5 changes: 4 additions & 1 deletion src/main/resources/languages/launcher.properties
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,7 @@ gui.addon.mods.cn.remove.success=Successfully removed %s
gui.addon.mods.fabric.remove=Remove Mod
gui.addon.mods.fabric.remove.confirm.message=Confirm to remove Fabric mod %s
gui.addon.mods.fabric.remove.success=Fabric mod %s successfully removed
gui.addon.mods.fabric.remove.confirm.title=Confirm removal
gui.addon.mods.fabric.remove.confirm.title=Confirm removal
gui.settings.folder.main=Config Folder
gui.settings.folder.theme=Themes Folder
gui.settings.folder.log=Logs Folder
9 changes: 6 additions & 3 deletions src/main/resources/languages/launcher_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ gui.plugins.exist=Exist
gui.settings.addon=Addon
gui.settings.addon.loader.unset=Unset
gui.settings.addon.loader.weave.installation=Weave installation:
gui.settings.addon.loader.cn.installation=LuanrCN installation:
gui.settings.addon.loader.cn.installation=LunarCN installation:
gui.settings.game=Game
gui.settings.game.args=Game args
gui.settings.game.resize=Resize
Expand All @@ -185,11 +185,14 @@ gui.settings.launcher.theme.exist=Theme %s already exists
gui.settings.launcher.theme.success=Theme added successfully!
gui.addons.mods.fabric=Fabric Mod
gui.addon.mods.fabric.add.success=Add the Fabric Mod successfully!
gui.addon.mods.fabric.add.failure.exists=The Fabirc Mod always exists
gui.addon.mods.fabric.add.failure.exists=The Fabric Mod always exists
gui.addon.mods.fabric.add.failure.io=IO Error!
gui.addon.mods.cn.remove.confirm.message=Confirm removal of LunarCN module %s
gui.addon.mods.cn.remove.success=Successfully removed %s
gui.addon.mods.fabric.remove=Remove Mod
gui.addon.mods.fabric.remove.confirm.message=Confirm to remove Fabric mod %s
gui.addon.mods.fabric.remove.success=Fabric mod %s successfully removed
gui.addon.mods.fabric.remove.confirm.title=Confirm removal
gui.addon.mods.fabric.remove.confirm.title=Confirm removal
gui.settings.folder.main=Config Folder
gui.settings.folder.theme=Themes Folder
gui.settings.folder.log=Logs Folder
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# Do NOT remove this note if you want to copy this file.
#

#
# Celestial Launcher <me@lunarclient.top>
# License under GPLv3
# Do NOT remove this note if you want to copy this file.
#

api.unreachable=現在のAPIにアクセスできません、APIを変更すると問題が解決するかもしれません
gui.about=Celestialは第3のLunarClientランチャーです。我々はうるさいElectronフレームワークを捨て、代わりにJavaで書き直しました。複数のプラットフォームをサポートし、Javaが1つだけ必要です!\
\n\
Expand Down Expand Up @@ -201,3 +207,6 @@ gui.addon.mods.fabric.remove=Mod を削除
gui.addon.mods.fabric.remove.confirm.message=Fabric Mod %s を削除するか確認しますか
gui.addon.mods.fabric.remove.success=Fabric Mod %s が正常に削除されました
gui.addon.mods.fabric.remove.confirm.title=削除の確認
gui.settings.folder.main=設定フォルダー
gui.settings.folder.theme=テーマフォルダー
gui.settings.folder.log=ログフォルダー
Loading

0 comments on commit 0d217f4

Please sign in to comment.