mirror of
https://github.com/SKCraft/Launcher.git
synced 2025-01-05 19:09:03 +01:00
Add support for custom plugin menus
This commit is contained in:
parent
7aacb4ec01
commit
60adb4fde5
@ -0,0 +1,5 @@
|
||||
package com.skcraft.plugin.curse;
|
||||
|
||||
public class CurseApi {
|
||||
|
||||
}
|
@ -1,10 +1,24 @@
|
||||
package com.skcraft.plugin.curse.creator;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.skcraft.launcher.builder.plugin.BuilderPlugin;
|
||||
import com.skcraft.launcher.creator.plugin.CreatorToolsPlugin;
|
||||
import com.skcraft.launcher.creator.plugin.PluginMenu;
|
||||
import com.skcraft.plugin.curse.CurseBuildPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CurseCreatorPlugin extends CreatorToolsPlugin {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SKCraft Curseforge Tools";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PluginMenu> getPluginMenus() {
|
||||
return Lists.newArrayList(new CurseModsDialog.Menu());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends BuilderPlugin> getBuilderPlugin() {
|
||||
return CurseBuildPlugin.class;
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.skcraft.plugin.curse.creator;
|
||||
|
||||
import com.skcraft.launcher.creator.model.creator.Pack;
|
||||
import com.skcraft.launcher.creator.plugin.PluginMenu;
|
||||
import com.skcraft.launcher.swing.LinedBoxPanel;
|
||||
import com.skcraft.plugin.curse.model.CurseProject;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class CurseModsDialog extends JDialog {
|
||||
private final LinedBoxPanel panel = new LinedBoxPanel(false).fullyPadded();
|
||||
private final JList<CurseProject> searchResults = new JList<>();
|
||||
private final JList<CurseProject> selected = new JList<>();
|
||||
private final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchResults, selected);
|
||||
private final JButton addMod = new JButton("Add Mod >>");
|
||||
private final JButton removeMod = new JButton("Remove Mod");
|
||||
|
||||
private final Pack pack;
|
||||
|
||||
public CurseModsDialog(Window owner, Pack pack) {
|
||||
super(owner);
|
||||
this.pack = pack;
|
||||
|
||||
initComponents();
|
||||
setMinimumSize(new Dimension(500, 250));
|
||||
pack();
|
||||
setLocationRelativeTo(owner);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
splitPane.setDividerLocation(0.5D);
|
||||
splitPane.setDividerSize(10);
|
||||
|
||||
LinedBoxPanel buttonsPanel = new LinedBoxPanel(true);
|
||||
buttonsPanel.addElement(addMod);
|
||||
buttonsPanel.addGlue();
|
||||
buttonsPanel.addElement(removeMod);
|
||||
|
||||
panel.addElement(splitPane);
|
||||
panel.addElement(buttonsPanel);
|
||||
|
||||
add(panel);
|
||||
|
||||
addMod.addActionListener(e -> {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static class Menu implements PluginMenu {
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Add Mods";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresPack() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(Window owner, ActionEvent e, Pack pack) {
|
||||
CurseModsDialog dialog = new CurseModsDialog(owner, pack);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.skcraft.plugin.curse.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CurseProject {
|
||||
private String id;
|
||||
private String name;
|
||||
private String websiteUrl;
|
||||
private String summary;
|
||||
private String slug;
|
||||
private List<GameVersionFile> gameVersionLatestFiles;
|
||||
|
||||
public GameVersionFile findFileForVersion(String version) {
|
||||
for (GameVersionFile file : gameVersionLatestFiles) {
|
||||
if (file.getGameVersion().equals(version)) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.skcraft.plugin.curse.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class GameVersionFile {
|
||||
private String gameVersion;
|
||||
private String projectFileId;
|
||||
private String projectFileName;
|
||||
}
|
@ -31,6 +31,9 @@ import com.skcraft.launcher.creator.dialog.BuildDialog.BuildOptions;
|
||||
import com.skcraft.launcher.creator.dialog.DeployServerDialog.DeployOptions;
|
||||
import com.skcraft.launcher.creator.model.creator.*;
|
||||
import com.skcraft.launcher.creator.model.swing.PackTableModel;
|
||||
import com.skcraft.launcher.creator.plugin.CreatorPluginWrapper;
|
||||
import com.skcraft.launcher.creator.plugin.CreatorToolsPlugin;
|
||||
import com.skcraft.launcher.creator.plugin.PluginMenu;
|
||||
import com.skcraft.launcher.creator.server.TestServer;
|
||||
import com.skcraft.launcher.creator.server.TestServerBuilder;
|
||||
import com.skcraft.launcher.creator.swing.PackDirectoryFilter;
|
||||
@ -107,6 +110,8 @@ public class PackManagerController {
|
||||
}
|
||||
|
||||
public void show() {
|
||||
initPluginMenu();
|
||||
|
||||
frame.setVisible(true);
|
||||
frame.setTitle("Modpack Creator - [" + workspaceDir.getAbsolutePath() + "]");
|
||||
|
||||
@ -313,6 +318,33 @@ public class PackManagerController {
|
||||
config.setUserFiles(userFiles);
|
||||
}
|
||||
|
||||
private void initPluginMenu() {
|
||||
JMenu pluginsMenu = frame.getPluginsMenu();
|
||||
|
||||
for (CreatorPluginWrapper<?> wrapper : creator.getPlugins()) {
|
||||
CreatorToolsPlugin plugin = wrapper.getInstance();
|
||||
JMenu submenu = new JMenu(plugin.getName());
|
||||
|
||||
for (PluginMenu menu : plugin.getPluginMenus()) {
|
||||
JMenuItem item = new JMenuItem(menu.getTitle());
|
||||
item.addActionListener(e -> {
|
||||
Optional<Pack> pack = getSelectedPack(true);
|
||||
|
||||
if (menu.requiresPack() && !pack.isPresent()) {
|
||||
SwingHelper.showErrorDialog(frame, "You must select a pack first", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
menu.onOpen(frame, e, pack.orNull());
|
||||
});
|
||||
|
||||
submenu.add(item);
|
||||
}
|
||||
|
||||
pluginsMenu.add(submenu);
|
||||
}
|
||||
}
|
||||
|
||||
private void initListeners() {
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
|
@ -59,6 +59,7 @@ public class PackManagerFrame extends JFrame {
|
||||
@Getter private final JMenuItem docsMenuItem = new JMenuItem("Documentation");
|
||||
@Getter private final JMenuItem aboutMenuItem = new JMenuItem("About");
|
||||
|
||||
@Getter private final JMenu pluginsMenu = new JMenu("Plugins");
|
||||
@Getter private final JTable packTable = new DefaultTable();
|
||||
|
||||
public PackManagerFrame() {
|
||||
@ -194,6 +195,11 @@ public class PackManagerFrame extends JFrame {
|
||||
menu.addSeparator();
|
||||
menu.add(openConsoleMenuItem);
|
||||
|
||||
menu = pluginsMenu;
|
||||
menu.setMargin(menuInset);
|
||||
menu.setMnemonic('p');
|
||||
menuBar.add(menu);
|
||||
|
||||
menu = new JMenu("Help");
|
||||
menu.setMargin(menuInset);
|
||||
menu.setMnemonic('h');
|
||||
|
@ -35,7 +35,7 @@ public class PluginSelectionDialog extends JDialog {
|
||||
setTitle("Select plugins to enable");
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
initComponents();
|
||||
setPreferredSize(new Dimension(400, 320));
|
||||
setMinimumSize(new Dimension(400, 140));
|
||||
pack();
|
||||
setLocationRelativeTo(owner);
|
||||
}
|
||||
@ -51,6 +51,7 @@ public class PluginSelectionDialog extends JDialog {
|
||||
|
||||
panel.addElement(title);
|
||||
panel.addElement(pluginsTable);
|
||||
panel.addGlue();
|
||||
panel.addElement(buttonsPanel);
|
||||
|
||||
add(panel);
|
||||
|
@ -1,8 +1,17 @@
|
||||
package com.skcraft.launcher.creator.plugin;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.skcraft.launcher.builder.plugin.BuilderPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CreatorToolsPlugin {
|
||||
public abstract String getName();
|
||||
|
||||
public List<PluginMenu> getPluginMenus() {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
public Class<? extends BuilderPlugin> getBuilderPlugin() {
|
||||
return null;
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.skcraft.launcher.creator.plugin;
|
||||
|
||||
import com.skcraft.launcher.creator.model.creator.Pack;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public interface PluginMenu {
|
||||
String getTitle();
|
||||
|
||||
/**
|
||||
* Return true if {@link PluginMenu#onOpen(Window, ActionEvent, Pack)} should only be called
|
||||
* if the user has selected a pack.
|
||||
* @return True to require a pack, false if you don't need one.
|
||||
*/
|
||||
boolean requiresPack();
|
||||
|
||||
/**
|
||||
* Called when the menu item was clicked.
|
||||
*
|
||||
* @param owner Window reference for parenting dialogs.
|
||||
* @param e Action event that triggered this call.
|
||||
* @param pack Pack to operate on; guaranteed to be non-null if {@link PluginMenu#requiresPack()} returns true.
|
||||
*/
|
||||
void onOpen(Window owner, ActionEvent e, Pack pack);
|
||||
}
|
Loading…
Reference in New Issue
Block a user