Skip to content

Commit 2f284b7

Browse files
committed
Some further changes
1 parent ace3a03 commit 2f284b7

2 files changed

Lines changed: 46 additions & 29 deletions

File tree

  • bootstrap/src/main/java/org/geysermc/pack/converter/bootstrap
  • converter/src/main/java/org/geysermc/pack/converter/util

bootstrap/src/main/java/org/geysermc/pack/converter/bootstrap/ThunderGUI.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,21 @@
3535
import javax.imageio.ImageIO;
3636
import javax.swing.*;
3737
import java.awt.*;
38+
import java.awt.image.BufferedImage;
3839
import java.io.IOException;
3940
import java.io.InputStream;
4041
import java.math.RoundingMode;
4142
import java.nio.file.Files;
4243
import java.nio.file.Path;
4344
import java.text.DecimalFormat;
45+
import java.time.LocalDate;
46+
import java.time.Month;
4447
import java.util.List;
4548
import java.util.Random;
4649
import java.util.concurrent.atomic.AtomicBoolean;
4750
import java.util.concurrent.atomic.AtomicLong;
4851

4952
public class ThunderGUI extends JFrame {
50-
private static List<String> MESSAGES = List.of(
51-
"Your order is ready!", "Also try Rainbow!", "The floodgates are open!",
52-
"Your pack has been converted!", "(╯°□°)╯︵ ┻━┻"
53-
);
54-
5553
private final DecimalFormat decimalFormat;
5654
private final AtomicBoolean converting = new AtomicBoolean(false);
5755
private final AtomicLong startTime = new AtomicLong(0);
@@ -62,7 +60,7 @@ public class ThunderGUI extends JFrame {
6260

6361
private Path inputPath = null;
6462
private Path outputPath = null;
65-
private Icon currentIcon = null;
63+
private BufferedImage currentIcon = null;
6664

6765
public ThunderGUI(boolean debug) throws IOException {
6866
vanillaPackPath = Path.of(System.getenv("LOCALAPPDATA") != null ? System.getenv("LOCALAPPDATA") : System.getProperty("user.home"), "Thunder", "Vanilla-Assets.zip");
@@ -74,6 +72,7 @@ public ThunderGUI(boolean debug) throws IOException {
7472
InputStream iconStream = Main.class.getResourceAsStream("/icon.png");
7573
if (iconStream != null) this.setIconImage(ImageIO.read(iconStream));
7674
this.setSize(800, 300);
75+
this.setLocationRelativeTo(null);
7776
this.setLayout(null);
7877
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
7978
this.setResizable(false);
@@ -141,21 +140,6 @@ public ThunderGUI(boolean debug) throws IOException {
141140
.pack();
142141

143142
dataLabel.setText("%s Converted! Time elapsed: %ss".formatted(inputPath.getFileName().toString(), decimalFormat.format((System.currentTimeMillis() - startTime.get()) / 1000d)));
144-
145-
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
146-
int option = JOptionPane.showConfirmDialog(
147-
this,
148-
"%s Would you like to view the pack?".formatted(MESSAGES.get(new Random().nextInt(MESSAGES.size()))),
149-
"Pack Converted!",
150-
JOptionPane.YES_NO_OPTION,
151-
JOptionPane.QUESTION_MESSAGE,
152-
currentIcon
153-
);
154-
155-
if (option == JOptionPane.YES_OPTION) {
156-
Desktop.getDesktop().open(outputPath.getParent().toFile());
157-
}
158-
}
159143
} catch (Exception e) {
160144
logListener.error("An issue occured while converting:", e);
161145
} finally {
@@ -215,10 +199,24 @@ public ThunderGUI(boolean debug) throws IOException {
215199
javaPackButton.setIcon(null);
216200
} else {
217201
javaPackButton.setText(null);
218-
currentIcon = new BufferedImageIcon(
219-
ImageUtil.resize(ImageIO.read(Files.newInputStream(iconPath)), 175, 175)
202+
203+
LocalDate date = LocalDate.now();
204+
205+
currentIcon = ImageUtil.borderRadias(
206+
ImageUtil.resize(
207+
ImageIO.read(Files.newInputStream(iconPath)),
208+
198,
209+
198
210+
),
211+
5
220212
);
221-
javaPackButton.setIcon(currentIcon);
213+
214+
if (date.getMonth().equals(Month.APRIL) && date.getDayOfMonth() == 1) {
215+
List<Integer> rotations = List.of(90, 180, 270);
216+
currentIcon = ImageUtil.rotate(currentIcon, rotations.get(new Random().nextInt(rotations.size())));
217+
}
218+
219+
javaPackButton.setIcon(new BufferedImageIcon(currentIcon));
222220
}
223221
});
224222
} catch (IOException e) {

converter/src/main/java/org/geysermc/pack/converter/util/ImageUtil.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,15 @@
3535
import java.awt.Graphics2D;
3636
import java.awt.Image;
3737
import java.awt.geom.AffineTransform;
38+
import java.awt.geom.RoundRectangle2D;
3839
import java.awt.image.AffineTransformOp;
3940
import java.awt.image.BufferedImage;
4041
import java.io.ByteArrayInputStream;
4142
import java.io.ByteArrayOutputStream;
4243
import java.io.File;
4344
import java.io.IOException;
4445
import java.io.InputStream;
45-
import java.nio.ByteBuffer;
46-
import java.nio.ByteOrder;
47-
import java.nio.channels.WritableByteChannel;
48-
import java.nio.file.Files;
4946
import java.nio.file.Path;
50-
import java.nio.file.StandardOpenOption;
5147

5248
public class ImageUtil {
5349

@@ -495,6 +491,29 @@ public static BufferedImage expandCanvas(BufferedImage image, int width, int hei
495491
return newImage;
496492
}
497493

494+
/**
495+
* Adds a border radias onto the image
496+
*
497+
* @param image Image to use
498+
* @param radias the border radias
499+
* @return The image with a border radias
500+
*/
501+
public static BufferedImage borderRadias(BufferedImage image, int radias) {
502+
BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
503+
Graphics2D g2 = newImage.createGraphics();
504+
505+
g2.setComposite(AlphaComposite.Src);
506+
g2.setColor(Color.WHITE);
507+
g2.fill(new RoundRectangle2D.Float(0, 0, image.getWidth(), image.getHeight(), radias, radias));
508+
509+
g2.setComposite(AlphaComposite.SrcAtop);
510+
g2.drawImage(image, 0, 0, null);
511+
512+
g2.dispose();
513+
514+
return newImage;
515+
}
516+
498517
/**
499518
* Limit a number between two values
500519
*

0 commit comments

Comments
 (0)