From 1727ee8bec9f837cfc5abb9307ad13eb3162e899 Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:37:10 +0100 Subject: [PATCH] First work on consent dialog #18 --- build.gradle | 2 +- .../configuration/type/CurseRemoteMod.java | 2 +- .../core/manage/select/InstallSelector.java | 29 +++++++++---------- .../select/SelectableInstallOption.java | 8 ++++- .../jan/moddirector/core/ui/SetupDialog.java | 16 +++++----- .../core/ui/page/ModSelectionPage.java | 16 +++++----- 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/build.gradle b/build.gradle index 37ab49f..6370f41 100644 --- a/build.gradle +++ b/build.gradle @@ -1,2 +1,2 @@ group 'net.jan' -version '1.8.0-SNAPSHOT' +version '1.8.1-SNAPSHOT' diff --git a/mod-director-core/src/main/java/net/jan/moddirector/core/configuration/type/CurseRemoteMod.java b/mod-director-core/src/main/java/net/jan/moddirector/core/configuration/type/CurseRemoteMod.java index aecfce0..20d8cb9 100644 --- a/mod-director-core/src/main/java/net/jan/moddirector/core/configuration/type/CurseRemoteMod.java +++ b/mod-director-core/src/main/java/net/jan/moddirector/core/configuration/type/CurseRemoteMod.java @@ -57,7 +57,7 @@ public String remoteType() { @Override public String offlineName() { - return addonId + ":" + fileId; + return "Project ID: " + addonId + ", File ID: " + fileId; } @Override diff --git a/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/InstallSelector.java b/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/InstallSelector.java index a61e4c2..484dcae 100644 --- a/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/InstallSelector.java +++ b/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/InstallSelector.java @@ -58,23 +58,20 @@ public void accept( ModDirectorRemoteMod remoteMod = mod.getRemoteMod(); if(remoteMod != null) { InstallationPolicy policy = remoteMod.getInstallationPolicy(); - if(policy != null) { - String optionalKey = policy.getOptionalKey(); - if(optionalKey == null) { - alwaysInstall.add(mod); - } else if(!ignoredGroups.contains(optionalKey)) { - SelectableInstallOption installOption = new SelectableInstallOption( - policy.isSelectedByDefault(), - policy.getName() == null ? remoteMod.offlineName() : policy.getName(), - policy.getDescription() - ); - if(optionalKey.equals("$")) { - singleOptions.add(installOption); - } else { - groupOptions.computeIfAbsent(optionalKey, k -> new ArrayList<>()).add(installOption); - } - optionsToMod.put(installOption, mod); + String optionalKey = policy == null ? "$" : policy.getOptionalKey(); + if(!ignoredGroups.contains(optionalKey)) { + SelectableInstallOption installOption = new SelectableInstallOption( + policy == null || optionalKey == null || policy.isSelectedByDefault(), + policy == null || policy.getName() == null ? remoteMod.offlineName() : policy.getName() + " - " + remoteMod.offlineName(), + policy == null ? "" : policy.getDescription(), + policy == null || remoteMod.remoteType() == null ? "Unknown" : remoteMod.remoteType() + ); + if(optionalKey == null || optionalKey.equals("$")) { + singleOptions.add(installOption); + } else { + groupOptions.computeIfAbsent(optionalKey, k -> new ArrayList<>()).add(installOption); } + optionsToMod.put(installOption, mod); } } } diff --git a/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/SelectableInstallOption.java b/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/SelectableInstallOption.java index de8ac5e..82d07d1 100644 --- a/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/SelectableInstallOption.java +++ b/mod-director-core/src/main/java/net/jan/moddirector/core/manage/select/SelectableInstallOption.java @@ -3,13 +3,15 @@ public class SelectableInstallOption { private final String description; private final String name; + private final String source; private boolean selected; - public SelectableInstallOption(boolean selectedByDefault, String name, String description) { + public SelectableInstallOption(boolean selectedByDefault, String name, String description, String source) { this.selected = selectedByDefault; this.name = name; this.description = description; + this.source = source; } public boolean isSelected() { @@ -27,4 +29,8 @@ public String getName() { public String getDescription() { return description; } + + public String getSource() { + return source; + } } diff --git a/mod-director-core/src/main/java/net/jan/moddirector/core/ui/SetupDialog.java b/mod-director-core/src/main/java/net/jan/moddirector/core/ui/SetupDialog.java index 58efcd1..39aa00e 100644 --- a/mod-director-core/src/main/java/net/jan/moddirector/core/ui/SetupDialog.java +++ b/mod-director-core/src/main/java/net/jan/moddirector/core/ui/SetupDialog.java @@ -10,7 +10,7 @@ import java.util.concurrent.CountDownLatch; public class SetupDialog extends JDialog { - private static final int HEIGHT = 400; + private static final int HEIGHT = 500; private static final int WIDTH = (int) (HEIGHT * /* golden ratio */ 1.618); private final ModpackConfiguration configuration; @@ -22,7 +22,7 @@ public SetupDialog(ModpackConfiguration configuration) { this.configuration = configuration; this.nextButton = new JButton("Next"); - this.nextButton.addActionListener((e) -> nextLatch.countDown()); + this.nextButton.addActionListener(e -> nextLatch.countDown()); setTitle(configuration.packName()); setSize(WIDTH, HEIGHT); @@ -51,17 +51,17 @@ private T updateContent(T newContent, boolean hasNextButton) scrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, HEIGHT - 55)); wrapperPanel.add(scrollPane); - JPanel creditsPanel = new JPanel(); - creditsPanel.setMaximumSize(new Dimension(WIDTH, 30)); - creditsPanel.setLayout(new BorderLayout()); + JPanel consentPanel = new JPanel(); + consentPanel.setMaximumSize(new Dimension(WIDTH, 30)); + consentPanel.setLayout(new BorderLayout()); wrapperPanel.add(Box.createVerticalStrut(5)); - creditsPanel.add(new JLabel("Powered by ModDirector"), BorderLayout.WEST); - wrapperPanel.add(creditsPanel); + consentPanel.add(new JLabel("By checking the boxes above, you give consent to download the respective files!"), BorderLayout.WEST); + wrapperPanel.add(consentPanel); if(hasNextButton) { - creditsPanel.add(nextButton, BorderLayout.EAST); + consentPanel.add(nextButton, BorderLayout.EAST); nextButton.setAlignmentX(Component.RIGHT_ALIGNMENT); nextLatch = new CountDownLatch(1); } else { diff --git a/mod-director-core/src/main/java/net/jan/moddirector/core/ui/page/ModSelectionPage.java b/mod-director-core/src/main/java/net/jan/moddirector/core/ui/page/ModSelectionPage.java index d5a11cb..0e31388 100644 --- a/mod-director-core/src/main/java/net/jan/moddirector/core/ui/page/ModSelectionPage.java +++ b/mod-director-core/src/main/java/net/jan/moddirector/core/ui/page/ModSelectionPage.java @@ -11,7 +11,7 @@ public class ModSelectionPage extends JPanel { public ModSelectionPage(InstallSelector selector) { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - JLabel titleLabel = new JLabel("Select mods to install", SwingConstants.CENTER); + JLabel titleLabel = new JLabel("Select files to download", SwingConstants.CENTER); titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, 20)); titleLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, titleLabel.getMinimumSize().height)); add(titleLabel); @@ -21,20 +21,20 @@ public ModSelectionPage(InstallSelector selector) { } private void setupSingleOption(SelectableInstallOption option) { - JPanel optionPanel = new JPanel(); + String borderText = option.getSource().startsWith("http") ? "URL" : option.getSource(); + JPanel optionPanel = new JPanel(new BorderLayout()); optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS)); + optionPanel.setBorder(BorderFactory.createTitledBorder(borderText)); - JCheckBox installCheckBox = new JCheckBox("Install"); - installCheckBox.setSelected(option.isSelected()); - installCheckBox.addItemListener((e) -> option.setSelected(installCheckBox.isSelected())); + String checkboxText = option.getSource().startsWith("http") ? option.getSource() : option.getName(); + JCheckBox installCheckBox = new JCheckBox(checkboxText, option.isSelected()); + installCheckBox.addItemListener(e -> option.setSelected(installCheckBox.isSelected())); optionPanel.add(installCheckBox); if(option.getDescription() != null) { optionPanel.add(new JLabel(asHtml(option.getDescription()))); } - optionPanel.setBorder(BorderFactory.createTitledBorder(option.getName())); - add(optionPanel); } @@ -50,7 +50,7 @@ private void setupGroupOption(String groupName, List op JRadioButton installRadioButton = new JRadioButton(option.getName()); installRadioButton.setSelected(option.isSelected()); - installRadioButton.addItemListener((e) -> option.setSelected(installRadioButton.isSelected())); + installRadioButton.addItemListener(e -> option.setSelected(installRadioButton.isSelected())); group.add(installRadioButton); optionPanel.add(installRadioButton);