Skip to content

Commit

Permalink
Custom icon support
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
Gaming32 committed Sep 22, 2023
1 parent b78bfe0 commit 1751da6
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,30 @@ public static void startLoadingScreen(boolean fabricReady) {
dialog.setResizable(false);

try {
final Path iconPath = configDir.resolve("icon.png");
dialog.setIconImage(ImageIO.read(
ClassLoader.getSystemResource("assets/mod-loading-screen/icon.png"))
);
Files.exists(iconPath)
? iconPath.toUri().toURL()
: ClassLoader.getSystemResource("assets/mod-loading-screen/icon.png")
));
} catch (Exception e) {
println("Failed to load icon.png", e);
}

ImageIcon icon;
ImageIcon background;
try {
final Path backgroundPath = configDir.resolve("background.png");
icon = new ImageIcon(
background = new ImageIcon(
Files.exists(backgroundPath)
? backgroundPath.toUri().toURL()
: ClassLoader.getSystemResource("assets/mod-loading-screen/" + (runningOnQuilt ? "quilt-banner.png" : "aof4.png"))
);
icon.setImage(icon.getImage().getScaledInstance(960, 540, Image.SCALE_SMOOTH));
background.setImage(background.getImage().getScaledInstance(960, 540, Image.SCALE_SMOOTH));
} catch (Exception e) {
println("Failed to load background.png", e);
icon = null;
background = null;
}
label = new JLabel(icon);
label = new JLabel(background);
final BoxLayout layout = new BoxLayout(label, BoxLayout.Y_AXIS);
label.setLayout(layout);
label.add(Box.createVerticalGlue());
Expand Down Expand Up @@ -206,7 +209,8 @@ private static void loadConfig() {

try (OutputStream os = Files.newOutputStream(configFile)) {
configProperties.store(os,
"To use a custom background image, create a file named background.png in this folder. The recommended size is 960x540."
"To use a custom background image, create a file named background.png in this folder. The recommended size is 960x540.\n" +
"To use a custom icon image, create a file named icon.png in this folder. It should be square."
);
} catch (Exception e) {
println("Failed to write config", e);
Expand Down

0 comments on commit 1751da6

Please sign in to comment.