Skip to content

Commit

Permalink
full fabric modManager
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jan 16, 2024
1 parent cbf6688 commit 9a41137
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package org.cubewhy.celestial.game.addon;

import lombok.Getter;
import org.cubewhy.celestial.Celestial;
import org.cubewhy.celestial.game.BaseAddon;
import org.jetbrains.annotations.NotNull;
Expand All @@ -17,9 +18,10 @@
import java.util.List;
import java.util.Objects;

@Getter
public class FabricMod extends BaseAddon {
public static final File modFolder = new File(Celestial.config.getValue("installation-dir").getAsString(), "mods");
public final File file;
private final File file;

public FabricMod(File file) {
this.file = file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,56 @@ private void initGui() {
if (newName != null && file.renameTo(new File(file.getParentFile(), newName + ".jar"))) {
log.info(String.format("Rename LunarCN mod %s -> %s", name, newName + ".jar"));
GuiLauncher.statusBar.setText(String.format(f.getString("gui.addon.rename.success"), newName));
lunarcnList.clear();
loadLunarCNMods(lunarcnList);
}
});

removeLunarCNMod.addActionListener((e) -> {
LunarCNMod currentMod = jListLunarCN.getSelectedValue();
String name = currentMod.getFile().getName();
if (JOptionPane.showConfirmDialog(this, String.format(f.getString("gui.addon.mods.cn.remove.confirm.message"), name), f.getString("gui.addon.mods.cn.remove.confirm.title"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION && currentMod.getFile().delete()) {
GuiLauncher.statusBar.setText(String.format(f.getString("gui.addon.mods.cn.remove.success"), name));
lunarcnList.clear();
loadLunarCNMods(lunarcnList);
}
});

JPopupMenu fabricMenu = new JPopupMenu();
JMenuItem renameFabricMod = new JMenuItem(f.getString("gui.addon.rename"));
JMenuItem removeFabricMod = new JMenuItem(f.getString("gui.addon.mods.fabric.remove"));

renameFabricMod.addActionListener(e -> {
FabricMod currentMod = jListFabric.getSelectedValue();
File file = currentMod.getFile();
String name = file.getName();
String newName = JOptionPane.showInputDialog(this, f.getString("gui.addon.rename.dialog.message"), name.substring(0, name.length() - 4));
if (newName != null && file.renameTo(new File(file.getParentFile(), newName + ".jar"))) {
log.info(String.format("Rename Fabric mod %s -> %s", name, newName + ".jar"));
GuiLauncher.statusBar.setText(String.format(f.getString("gui.addon.rename.success"), newName));
fabricList.clear();
loadFabricMods(fabricList);
}
});

removeFabricMod.addActionListener((e) -> {
FabricMod currentMod = jListFabric.getSelectedValue();
String name = currentMod.getFile().getName();
if (JOptionPane.showConfirmDialog(this, String.format(f.getString("gui.addon.mods.fabric.remove.confirm.message"), name), f.getString("gui.addon.mods.fabric.remove.confirm.title"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION && currentMod.getFile().delete()) {
GuiLauncher.statusBar.setText(String.format(f.getString("gui.addon.mods.fabric.remove.success"), name));
fabricList.clear();
loadFabricMods(fabricList);
}
});

fabricMenu.add(renameFabricMod);
fabricMenu.addSeparator();
fabricMenu.add(removeFabricMod);

// bind menus
bindMenu(jListLunarCN, lunarCNMenu);
bindMenu(jListWeave, weaveMenu);
bindMenu(jListFabric, fabricMenu);
bindMenu(jListAgents, agentMenu);


Expand Down Expand Up @@ -258,8 +302,8 @@ private void initGui() {
// success
new AddonAddEvent(AddonAddEvent.Type.FABRIC, mod);
GuiLauncher.statusBar.setText(f.getString("gui.addon.mods.fabric.add.success"));
agentList.clear();
loadAgents(agentList);
fabricList.clear();
loadFabricMods(fabricList);
} else {
JOptionPane.showMessageDialog(this, f.getString("gui.addon.mods.fabric.add.failure.exists"), "Error", JOptionPane.ERROR_MESSAGE);
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/languages/launcher.properties
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,11 @@ 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.io=IO Error!
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
8 changes: 7 additions & 1 deletion src/main/resources/languages/launcher_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,10 @@ 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.io=IO Error!
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
8 changes: 7 additions & 1 deletion src/main/resources/languages/launcher_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,10 @@ gui.settings.launcher.theme.success=主题添加成功!
gui.addons.mods.fabric=Fabric模组
gui.addon.mods.fabric.add.success=成功添加Fabric模组!
gui.addon.mods.fabric.add.failure.exists=Fabric模组已存在
gui.addon.mods.fabric.add.failure.io=IO错误!
gui.addon.mods.fabric.add.failure.io=IO错误!
gui.addon.mods.cn.remove.confirm.message=确认移除LunarCN模组 %s
gui.addon.mods.cn.remove.success=成功移除 %s
gui.addon.mods.fabric.remove=移除Mod
gui.addon.mods.fabric.remove.confirm.message=确认移除Fabric模组 %s
gui.addon.mods.fabric.remove.success=成功移除Fabric模组 %s
gui.addon.mods.fabric.remove.confirm.title=移除确认

0 comments on commit 9a41137

Please sign in to comment.