Use ItemManager in KourendLibraryPlugin

This commit is contained in:
Max Weber
2018-04-11 03:42:11 -06:00
parent b3fa9a5e49
commit 30413c0257
29 changed files with 16 additions and 20 deletions

View File

@@ -24,14 +24,13 @@
*/ */
package net.runelite.client.plugins.kourendlibrary; package net.runelite.client.plugins.kourendlibrary;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.imageio.ImageIO;
import lombok.Getter; import lombok.Getter;
import net.runelite.api.ItemID; import net.runelite.api.ItemID;
import net.runelite.client.game.AsyncBufferedImage;
import net.runelite.client.game.ItemManager;
public enum Book public enum Book
{ {
@@ -77,7 +76,7 @@ public enum Book
return Collections.unmodifiableMap(byId); return Collections.unmodifiableMap(byId);
} }
private static final Map<String, Book> buildByName() private static Map<String, Book> buildByName()
{ {
HashMap<String, Book> byName = new HashMap<>(); HashMap<String, Book> byName = new HashMap<>();
for (Book b : Book.values()) for (Book b : Book.values())
@@ -110,7 +109,7 @@ public enum Book
private final String shortName; private final String shortName;
@Getter @Getter
private final BufferedImage icon; private AsyncBufferedImage icon;
@Getter @Getter
private final boolean isDarkManuscript; private final boolean isDarkManuscript;
@@ -121,7 +120,6 @@ public enum Book
this.isDarkManuscript = false; this.isDarkManuscript = false;
this.shortName = shortName; this.shortName = shortName;
this.name = name; this.name = name;
this.icon = getImage(Integer.toString(id));
} }
Book(int id) Book(int id)
@@ -130,21 +128,13 @@ public enum Book
this.isDarkManuscript = true; this.isDarkManuscript = true;
this.name = "Dark Manuscript"; this.name = "Dark Manuscript";
this.shortName = "Dark Manuscript"; this.shortName = "Dark Manuscript";
this.icon = getImage(Integer.toString(id));
} }
private static BufferedImage getImage(String name) static void fillImages(ItemManager itemManager)
{ {
try for (Book b : values())
{ {
synchronized (ImageIO.class) b.icon = itemManager.getImage(b.item);
{
return ImageIO.read(Book.class.getResourceAsStream("items/" + name + ".png"));
}
}
catch (IOException | IllegalArgumentException e)
{
throw new RuntimeException("Cannot load book " + name, e);
} }
} }
} }

View File

@@ -26,7 +26,6 @@ package net.runelite.client.plugins.kourendlibrary;
import java.awt.Color; import java.awt.Color;
import javax.swing.GroupLayout; import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import net.runelite.client.ui.FontManager; import net.runelite.client.ui.FontManager;
@@ -40,7 +39,8 @@ class BookPanel extends JPanel
GroupLayout layout = new GroupLayout(this); GroupLayout layout = new GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
JLabel image = new JLabel(new ImageIcon(b.getIcon())); JLabel image = new JLabel();
b.getIcon().addTo(image);
JLabel name = new JLabel(b.getShortName()); JLabel name = new JLabel(b.getShortName());
location.setFont(FontManager.getRunescapeSmallFont()); location.setFont(FontManager.getRunescapeSmallFont());

View File

@@ -42,6 +42,7 @@ import net.runelite.api.events.GameTick;
import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.NavigationButton; import net.runelite.client.ui.NavigationButton;
@@ -68,6 +69,9 @@ public class KourendLibraryPlugin extends Plugin
@Inject @Inject
private KourendLibraryOverlay overlay; private KourendLibraryOverlay overlay;
@Inject
private ItemManager itemManager;
private KourendLibraryPanel panel; private KourendLibraryPanel panel;
private NavigationButton navButton; private NavigationButton navButton;
@@ -77,6 +81,8 @@ public class KourendLibraryPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
Book.fillImages(itemManager);
panel = injector.getInstance(KourendLibraryPanel.class); panel = injector.getInstance(KourendLibraryPanel.class);
panel.init(); panel.init();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 658 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 631 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 872 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 686 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 735 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 947 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 738 B