tweak dependency error gui

This commit is contained in:
moehreag 2024-06-03 21:40:20 +02:00
parent b82e6bceae
commit f6f536c182

View file

@ -7,6 +7,7 @@ import java.awt.event.ActionEvent;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@ -20,6 +21,7 @@ import dev.frogmc.frogloader.impl.mod.ModUtil;
import dev.frogmc.frogloader.impl.util.URLUtil;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.Nullable;
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class LoaderGui {
@ -87,7 +89,7 @@ public class LoaderGui {
actions.add(new JButton(new AbstractAction("Join Discord") {
@Override
public void actionPerformed(ActionEvent e) {
URLUtil.open(URI.create("https://discord.frogmc.dev"));
}
}));
@ -122,11 +124,9 @@ public class LoaderGui {
public static final ContentType<ModDependencyResolver.UnfulfilledDependencyException> INFO_UNFULFILLED_DEP = new ContentType<>((frame, ex) -> {
JPanel pane = new JPanel(new BorderLayout());
JTextPane title = new JTextPane();
//title.setContentType("text/html");
title.setBackground(pane.getBackground());
title.setEditable(false);
int size = ex.getDependencies().size();
//title.setText("<html><h3>Found "+size+" Error"+(size > 1 ? "s:":":")+"</h3></html>");
title.setText("Found "+size+" Error"+(size > 1 ? "s:":":"));
title.setFont(title.getFont().deriveFont(Font.BOLD, 16f));
title.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0));
@ -139,7 +139,7 @@ public class LoaderGui {
if (e.presentVersion() != null){
description.append("Mod ").append(e.source().id()).append(" (").append(e.source().name()).append(") depends on ");
if (e.dependencyName() != null){
description.append(e.dependencyName()).append(" (").append(e.dependency()).append(") ");
description.append(e.dependency()).append(" (").append(e.dependencyName()).append(") ");
} else {
description.append("a Mod with id ").append(e.dependency());
}
@ -147,7 +147,7 @@ public class LoaderGui {
} else {
description.append("Mod ").append(e.source().id()).append(" (").append(e.source().name()).append(") depends on ");
if (e.dependencyName() != null){
description.append(e.dependencyName()).append(" (").append(e.dependency()).append(") ");
description.append(e.dependency()).append(" (").append(e.dependencyName()).append(") ");
} else {
description.append("a Mod with id ").append(e.dependency());
}
@ -158,7 +158,7 @@ public class LoaderGui {
.map(s -> "0.0.0".equals(s) ? "any version" : "version " + s).orElse("<unknown>"))
.append(" of ");
if (e.dependencyName() != null){
description.append(e.dependencyName()).append(" (").append(e.dependency()).append(") ");
description.append(e.dependency()).append(" (").append(e.dependencyName()).append(") ");
} else {
description.append("Mod with id ").append(e.dependency());
}
@ -178,7 +178,7 @@ public class LoaderGui {
});
actions.add(urlButton);
}
JPanel entry = getEntry(description.toString(), list.getBackground(), actions);
JPanel entry = getEntry(description.toString(), e.range(), list.getBackground(), e.source().icon(), actions);
list.add(entry);
});
pane.add(new JScrollPane(list));
@ -187,11 +187,11 @@ public class LoaderGui {
public static final ContentType<ModDependencyResolver.BreakingModException> INFO_BREAKING_DEP = new ContentType<>((frame, ex) -> {
JPanel pane = new JPanel(new BorderLayout());
JTextPane title = new JTextPane();
title.setContentType("text/html");
title.setBackground(pane.getBackground());
title.setEditable(false);
int size = ex.getBreaks().size();
title.setText("<html><h3>Found "+size+" Error"+(size > 1 ? "s:":":")+"</h3></html>");
title.setText("Found "+size+" Error"+(size > 1 ? "s:":":"));
title.setFont(title.getFont().deriveFont(Font.BOLD, 16f));
pane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
pane.add(title, BorderLayout.NORTH);
@ -204,7 +204,7 @@ public class LoaderGui {
" of Mod %s (%s) ".formatted(e.broken().id(), e.broken().name());
List<JButton> actions = new ArrayList<>();
JPanel entry = getEntry(description, list.getBackground(), actions);
JPanel entry = getEntry(description, e.range(), list.getBackground(), e.source().icon(), actions);
entry.setSize(list.getWidth(), entry.getHeight());
list.add(entry);
});
@ -215,10 +215,10 @@ public class LoaderGui {
JPanel pane = new JPanel(new BorderLayout());
JTextPane title = new JTextPane();
title.setContentType("text/html");
title.setBackground(pane.getBackground());
title.setEditable(false);
title.setText("<html><h3>Caught Fatal Error during game startup:</h3></html>");
title.setText("Caught Fatal Error during game startup:");
title.setFont(title.getFont().deriveFont(Font.BOLD, 16f));
pane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
pane.add(title, BorderLayout.NORTH);
@ -237,21 +237,45 @@ public class LoaderGui {
}
private static String printVersionRange(ModDependencyResolver.VersionRange range){
return "range: \n"+ range.toString().replace("||", "or")+" \n("+range+")";
return "range: \n"+ range.toString().replace("||", "or");
}
private static JPanel getEntry(String description, Color background, List<JButton> actions){
private static JPanel getEntry(String description, ModDependencyResolver.VersionRange range, Color background, @Nullable String icon, List<JButton> actions){
JPanel entry = new JPanel(new BorderLayout());
entry.setBorder(BasicBorders.getInternalFrameBorder());
JTextPane text = new JTextPane();
text.setContentType("text/html");
text.setEditable(false);
text.setBackground(background);
text.setText("<html>" + description.replace("<", "&lt;").replace("\n", "<br>") + "</html>");
Box text = Box.createVerticalBox();
text.setBorder(BorderFactory.createEmptyBorder());
JTextPane desc = new JTextPane();
desc.setContentType("text/html");
desc.setEditable(false);
desc.setBackground(background);
desc.setText("<html>" + description.replace("<", "&lt;").replace("\n", "<br>") + "</html>");
JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
actions.forEach(actionPanel::add);
if (icon != null) {
URL location = LoaderGui.class.getResource(icon);
if (location != null) {
entry.add(new JLabel(new ImageIcon(location)), BorderLayout.WEST);
}
}
text.add(desc);
JCheckBox showAdvanced = new JCheckBox("Show raw version range");
JTextPane advanced = new JTextPane();
advanced.setEditable(false);
advanced.setBackground(background);
advanced.setText(range.toString());
advanced.setVisible(false);
text.add(advanced);
showAdvanced.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
advanced.setVisible(showAdvanced.isSelected());
}
});
entry.add(text);
entry.add(actionPanel, BorderLayout.SOUTH);
Box bottom = Box.createHorizontalBox();
bottom.add(showAdvanced, actionPanel);
entry.add(bottom, BorderLayout.SOUTH);
return entry;
}
}