diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java index b819731a03..5c169aab11 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/BookPanel.java @@ -28,6 +28,7 @@ import java.awt.Color; import javax.swing.GroupLayout; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; import net.runelite.client.ui.FontManager; class BookPanel extends JPanel @@ -36,6 +37,9 @@ class BookPanel extends JPanel BookPanel(Book b) { + setBorder(new EmptyBorder(3, 3, 3, 3)); + setOpaque(false); + GroupLayout layout = new GroupLayout(this); this.setLayout(layout); @@ -74,4 +78,4 @@ class BookPanel extends JPanel { location.setForeground(target ? Color.GREEN : Color.WHITE); } -} +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java index fb894ee2a8..1afaf27961 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 Abex + * Copyright (c) 2018 Psikoi * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,35 +26,71 @@ package net.runelite.client.plugins.kourendlibrary; import com.google.inject.Inject; +import java.awt.BorderLayout; +import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.io.IOException; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.imageio.ImageIO; import javax.inject.Singleton; +import javax.swing.BorderFactory; import javax.swing.GroupLayout; -import javax.swing.JButton; +import javax.swing.ImageIcon; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.PluginPanel; +import net.runelite.client.util.SwingUtil; @Singleton public class KourendLibraryPanel extends PluginPanel { + private static final ImageIcon RESET_ICON; + private static final ImageIcon RESET_CLICK_ICON; + @Inject private Library library; private final HashMap bookPanels = new HashMap<>(); + static + { + try + { + synchronized (ImageIO.class) + { + BufferedImage resetIcon = ImageIO.read(KourendLibraryPanel.class.getResourceAsStream("reset.png")); + RESET_ICON = new ImageIcon(resetIcon); + RESET_CLICK_ICON = new ImageIcon(SwingUtil.grayscaleOffset(resetIcon, -100)); + } + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + void init() { GroupLayout layout = new GroupLayout(this); setLayout(layout); + setBorder(new EmptyBorder(10, 10, 10, 10)); + setBackground(ColorScheme.DARK_GRAY_COLOR); JPanel books = new JPanel(new GridBagLayout()); + books.setOpaque(false); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; @@ -70,21 +107,45 @@ public class KourendLibraryPanel extends PluginPanel c.gridy++; }); - JButton reset = new JButton("Reset"); - reset.addActionListener(e -> + JLabel reset = new JLabel(RESET_ICON); + reset.addMouseListener(new MouseAdapter() { - library.reset(); - update(); + @Override + public void mousePressed(MouseEvent mouseEvent) + { + reset.setIcon(RESET_CLICK_ICON); + library.reset(); + update(); + } + + @Override + public void mouseReleased(MouseEvent mouseEvent) + { + reset.setIcon(RESET_ICON); + } }); + JPanel header = new JPanel(); + header.setOpaque(false); + header.setLayout(new BorderLayout()); + header.setBorder(new CompoundBorder( + BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(58, 58, 58)), + BorderFactory.createEmptyBorder(0, 0, 10, 0))); + + JLabel pluginName = new JLabel("Kourend Library Plugin"); + pluginName.setForeground(Color.WHITE); + + header.add(reset, BorderLayout.EAST); + header.add(pluginName, BorderLayout.CENTER); + layout.setHorizontalGroup(layout.createParallelGroup() .addComponent(books) - .addComponent(reset) + .addComponent(header) ); layout.setVerticalGroup(layout.createSequentialGroup() + .addComponent(header) + .addGap(10) .addComponent(books) - .addGap(4) - .addComponent(reset) ); update(); @@ -134,4 +195,4 @@ public class KourendLibraryPanel extends PluginPanel } }); } -} +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java b/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java index 41ddd1b9fb..90790cbf36 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java +++ b/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java @@ -32,6 +32,7 @@ import java.awt.Frame; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Rectangle; +import java.awt.RenderingHints; import java.awt.SystemTray; import java.awt.Toolkit; import java.awt.TrayIcon; @@ -41,6 +42,8 @@ import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; +import java.awt.image.LookupOp; +import java.awt.image.LookupTable; import java.util.Enumeration; import java.util.concurrent.Callable; import java.util.function.BiConsumer; @@ -95,6 +98,40 @@ public class SwingUtil System.setProperty("sun.awt.noerasebackground", "true"); } + /** + * Offsets an image in the grayscale (darkens/brightens) by an offset + */ + public static BufferedImage grayscaleOffset(BufferedImage image, int offset) + { + int numComponents = image.getColorModel().getNumComponents(); + int index = numComponents - 1; + + LookupTable lookup = new LookupTable(0, numComponents) + { + @Override + public int[] lookupPixel(int[] src, int[] dest) + { + if (dest[index] != 0) + { + dest[index] = dest[index] + offset; + if (dest[index] < 0) + { + dest[index] = 0; + } + else if (dest[index] > 255) + { + dest[index] = 255; + } + } + + return dest; + } + }; + + LookupOp op = new LookupOp(lookup, new RenderingHints(null)); + return op.filter(image, null); + } + /** * Converts a given color to it's hexidecimal equivalent. */ diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/kourendlibrary/reset.png b/runelite-client/src/main/resources/net/runelite/client/plugins/kourendlibrary/reset.png new file mode 100644 index 0000000000..e94f6102a5 Binary files /dev/null and b/runelite-client/src/main/resources/net/runelite/client/plugins/kourendlibrary/reset.png differ