Use ItemManager in GrandExchangePlugin

This commit is contained in:
Max Weber
2018-04-11 03:46:18 -06:00
parent 30413c0257
commit 8cd5675d36
4 changed files with 10 additions and 28 deletions

View File

@@ -30,14 +30,13 @@ import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.game.AsyncBufferedImage;
import net.runelite.client.util.LinkBrowser;
import net.runelite.client.util.StackFormatter;
@@ -46,7 +45,7 @@ class GrandExchangeItemPanel extends JPanel
{
private static final Dimension ICON_SIZE = new Dimension(32, 32);
GrandExchangeItemPanel(BufferedImage icon, String name, int itemID, int gePrice, Double
GrandExchangeItemPanel(AsyncBufferedImage icon, String name, int itemID, int gePrice, Double
haPrice)
{
BorderLayout layout = new BorderLayout();
@@ -88,7 +87,7 @@ class GrandExchangeItemPanel extends JPanel
itemIcon.setPreferredSize(ICON_SIZE);
if (icon != null)
{
itemIcon.setIcon(new ImageIcon(icon));
icon.addTo(itemIcon);
}
add(itemIcon, BorderLayout.LINE_START);

View File

@@ -24,19 +24,19 @@
*/
package net.runelite.client.plugins.grandexchange;
import java.awt.image.BufferedImage;
import lombok.Data;
import net.runelite.client.game.AsyncBufferedImage;
@Data
public class GrandExchangeItems
{
private final BufferedImage icon;
private final AsyncBufferedImage icon;
private final String name;
private final int itemId;
private final int gePrice;
private final double haPrice;
GrandExchangeItems(BufferedImage icon, String name, int itemId, int gePrice, double haPrice)
GrandExchangeItems(AsyncBufferedImage icon, String name, int itemId, int gePrice, double haPrice)
{
this.icon = icon;
this.name = name;

View File

@@ -44,10 +44,10 @@ import javax.swing.border.EmptyBorder;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.ItemComposition;
import net.runelite.client.game.AsyncBufferedImage;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.hiscore.IconTextField;
import net.runelite.http.api.item.Item;
import net.runelite.http.api.item.ItemClient;
import net.runelite.http.api.item.ItemPrice;
import net.runelite.http.api.item.SearchResult;
@@ -60,8 +60,6 @@ class GrandExchangeSearchPanel extends JPanel
private final ItemManager itemManager;
private final ScheduledExecutorService executor;
private ItemClient itemClient;
private Icon search;
private IconTextField searchBox = new IconTextField();
@@ -150,8 +148,6 @@ class GrandExchangeSearchPanel extends JPanel
if (result != null && !result.getItems().isEmpty())
{
itemClient = new ItemClient();
for (Item item : result.getItems())
{
int itemId = item.getId();
@@ -172,20 +168,7 @@ class GrandExchangeSearchPanel extends JPanel
log.warn("Unable to fetch item price for {}", itemId, ex);
}
BufferedImage itemImage = null;
try
{
itemImage = itemClient.getIcon(itemId);
}
catch (IOException ex)
{
log.warn("Unable to fetch item icon for {}", itemId, ex);
}
if (itemImage == null)
{
log.warn("Unable to fetch item icon for {}", itemId);
}
AsyncBufferedImage itemImage = itemManager.getImage(itemId);
ITEMS_LIST.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));

View File

@@ -25,10 +25,10 @@
package net.runelite.client.plugins.grandexchange;
import java.awt.image.BufferedImage;
import net.runelite.api.GrandExchangeOffer;
import net.runelite.api.GrandExchangeOfferState;
import net.runelite.api.ItemComposition;
import net.runelite.client.game.AsyncBufferedImage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -48,7 +48,7 @@ public class GrandExchangeOfferSlotTest
when(offer.getState()).thenReturn(GrandExchangeOfferState.CANCELLED_BUY);
GrandExchangeOfferSlot offerSlot = new GrandExchangeOfferSlot();
offerSlot.updateOffer(mock(ItemComposition.class), mock(BufferedImage.class), offer);
offerSlot.updateOffer(mock(ItemComposition.class), mock(AsyncBufferedImage.class), offer);
}
}