Merge pull request #1404 from Abextm/async-item-sprites
Asynchronous item sprites
@@ -44,4 +44,11 @@ public interface SpritePixels
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
BufferedImage toBufferedImage();
|
BufferedImage toBufferedImage();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the contents of the SpritePixels to the BufferedImage.
|
||||||
|
* Width and Height must match
|
||||||
|
*/
|
||||||
|
void toBufferedImage(BufferedImage img);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.google.common.eventbus.EventBus;
|
|||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Provider;
|
||||||
import java.applet.Applet;
|
import java.applet.Applet;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -104,7 +105,7 @@ public class RuneLite
|
|||||||
private TitleToolbar titleToolbar;
|
private TitleToolbar titleToolbar;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ItemManager itemManager;
|
private Provider<ItemManager> itemManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ClanManager clanManager;
|
private ClanManager clanManager;
|
||||||
@@ -169,8 +170,11 @@ public class RuneLite
|
|||||||
eventBus.register(chatMessageManager);
|
eventBus.register(chatMessageManager);
|
||||||
eventBus.register(commandManager);
|
eventBus.register(commandManager);
|
||||||
eventBus.register(pluginManager);
|
eventBus.register(pluginManager);
|
||||||
eventBus.register(itemManager);
|
|
||||||
eventBus.register(clanManager);
|
eventBus.register(clanManager);
|
||||||
|
if (client != null)
|
||||||
|
{
|
||||||
|
eventBus.register(itemManager.get());
|
||||||
|
}
|
||||||
|
|
||||||
// Load user configuration
|
// Load user configuration
|
||||||
configManager.load();
|
configManager.load();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ package net.runelite.client.callback;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
@@ -35,16 +36,32 @@ import net.runelite.api.Client;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ClientThread
|
public class ClientThread
|
||||||
{
|
{
|
||||||
private ConcurrentLinkedQueue<Runnable> invokes = new ConcurrentLinkedQueue<>();
|
private ConcurrentLinkedQueue<BooleanSupplier> invokes = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
public void invokeLater(Runnable r)
|
public void invokeLater(Runnable r)
|
||||||
{
|
{
|
||||||
if (client.isClientThread())
|
invokeLater(() ->
|
||||||
{
|
{
|
||||||
r.run();
|
r.run();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will run r on the game thread, at a unspecified point in the future.
|
||||||
|
* If r returns false, r will be ran again, at a later point
|
||||||
|
*/
|
||||||
|
public void invokeLater(BooleanSupplier r)
|
||||||
|
{
|
||||||
|
if (client.isClientThread())
|
||||||
|
{
|
||||||
|
if (r.getAsBoolean())
|
||||||
|
{
|
||||||
|
invokes.add(r);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
invokes.add(r);
|
invokes.add(r);
|
||||||
@@ -53,14 +70,14 @@ public class ClientThread
|
|||||||
void invoke()
|
void invoke()
|
||||||
{
|
{
|
||||||
assert client.isClientThread();
|
assert client.isClientThread();
|
||||||
Iterator<Runnable> ir = invokes.iterator();
|
Iterator<BooleanSupplier> ir = invokes.iterator();
|
||||||
for (; ir.hasNext(); )
|
for (; ir.hasNext(); )
|
||||||
{
|
{
|
||||||
Runnable r = ir.next();
|
BooleanSupplier r = ir.next();
|
||||||
ir.remove();
|
boolean remove = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
r.run();
|
remove = r.getAsBoolean();
|
||||||
}
|
}
|
||||||
catch (ThreadDeath d)
|
catch (ThreadDeath d)
|
||||||
{
|
{
|
||||||
@@ -70,6 +87,10 @@ public class ClientThread
|
|||||||
{
|
{
|
||||||
log.warn("Exception in invokeLater", e);
|
log.warn("Exception in invokeLater", e);
|
||||||
}
|
}
|
||||||
|
if (remove)
|
||||||
|
{
|
||||||
|
ir.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Abex
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.runelite.client.game;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
public class AsyncBufferedImage extends BufferedImage
|
||||||
|
{
|
||||||
|
private final List<Runnable> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
public AsyncBufferedImage(int width, int height, int imageType)
|
||||||
|
{
|
||||||
|
super(width, height, imageType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call when the buffer has been changed
|
||||||
|
*/
|
||||||
|
public void changed()
|
||||||
|
{
|
||||||
|
for (Runnable r : listeners)
|
||||||
|
{
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a function to be ran when the buffer has changed
|
||||||
|
*/
|
||||||
|
public void onChanged(Runnable r)
|
||||||
|
{
|
||||||
|
listeners.add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls setIcon on c, ensuring it is repainted when this changes
|
||||||
|
*/
|
||||||
|
public void addTo(JButton c)
|
||||||
|
{
|
||||||
|
c.setIcon(makeIcon(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls setIcon on c, ensuring it is repainted when this changes
|
||||||
|
*/
|
||||||
|
public void addTo(JLabel c)
|
||||||
|
{
|
||||||
|
c.setIcon(makeIcon(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageIcon makeIcon(JComponent c)
|
||||||
|
{
|
||||||
|
listeners.add(c::repaint);
|
||||||
|
return new ImageIcon(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,7 +38,6 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -48,6 +47,7 @@ import net.runelite.api.GameState;
|
|||||||
import net.runelite.api.ItemComposition;
|
import net.runelite.api.ItemComposition;
|
||||||
import net.runelite.api.SpritePixels;
|
import net.runelite.api.SpritePixels;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
|
import net.runelite.client.callback.ClientThread;
|
||||||
import net.runelite.http.api.item.ItemClient;
|
import net.runelite.http.api.item.ItemClient;
|
||||||
import net.runelite.http.api.item.ItemPrice;
|
import net.runelite.http.api.item.ItemPrice;
|
||||||
import net.runelite.http.api.item.SearchResult;
|
import net.runelite.http.api.item.SearchResult;
|
||||||
@@ -74,20 +74,22 @@ public class ItemManager
|
|||||||
*/
|
*/
|
||||||
static final ItemPrice NONE = new ItemPrice();
|
static final ItemPrice NONE = new ItemPrice();
|
||||||
|
|
||||||
private final Provider<Client> client;
|
private final Client client;
|
||||||
private final ScheduledExecutorService scheduledExecutorService;
|
private final ScheduledExecutorService scheduledExecutorService;
|
||||||
|
private final ClientThread clientThread;
|
||||||
|
|
||||||
private final ItemClient itemClient = new ItemClient();
|
private final ItemClient itemClient = new ItemClient();
|
||||||
private final LoadingCache<String, SearchResult> itemSearches;
|
private final LoadingCache<String, SearchResult> itemSearches;
|
||||||
private final LoadingCache<Integer, ItemPrice> itemPriceCache;
|
private final LoadingCache<Integer, ItemPrice> itemPriceCache;
|
||||||
private final LoadingCache<ImageKey, BufferedImage> itemImages;
|
private final LoadingCache<ImageKey, AsyncBufferedImage> itemImages;
|
||||||
private final LoadingCache<Integer, ItemComposition> itemCompositions;
|
private final LoadingCache<Integer, ItemComposition> itemCompositions;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ItemManager(Provider<Client> client, ScheduledExecutorService executor)
|
public ItemManager(Client client, ScheduledExecutorService executor, ClientThread clientThread)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.scheduledExecutorService = executor;
|
this.scheduledExecutorService = executor;
|
||||||
|
this.clientThread = clientThread;
|
||||||
|
|
||||||
itemPriceCache = CacheBuilder.newBuilder()
|
itemPriceCache = CacheBuilder.newBuilder()
|
||||||
.maximumSize(1024L)
|
.maximumSize(1024L)
|
||||||
@@ -109,10 +111,10 @@ public class ItemManager
|
|||||||
itemImages = CacheBuilder.newBuilder()
|
itemImages = CacheBuilder.newBuilder()
|
||||||
.maximumSize(128L)
|
.maximumSize(128L)
|
||||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||||
.build(new CacheLoader<ImageKey, BufferedImage>()
|
.build(new CacheLoader<ImageKey, AsyncBufferedImage>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage load(ImageKey key) throws Exception
|
public AsyncBufferedImage load(ImageKey key) throws Exception
|
||||||
{
|
{
|
||||||
return loadImage(key.itemId, key.itemQuantity, key.stackable);
|
return loadImage(key.itemId, key.itemQuantity, key.stackable);
|
||||||
}
|
}
|
||||||
@@ -126,7 +128,7 @@ public class ItemManager
|
|||||||
@Override
|
@Override
|
||||||
public ItemComposition load(Integer key) throws Exception
|
public ItemComposition load(Integer key) throws Exception
|
||||||
{
|
{
|
||||||
return client.get().getItemDefinition(key);
|
return client.getItemDefinition(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -272,32 +274,55 @@ public class ItemManager
|
|||||||
* @param itemId
|
* @param itemId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private BufferedImage loadImage(int itemId, int quantity, boolean stackable)
|
private AsyncBufferedImage loadImage(int itemId, int quantity, boolean stackable)
|
||||||
{
|
{
|
||||||
SpritePixels sprite = client.get().createItemSprite(itemId, quantity, 1, SpritePixels.DEFAULT_SHADOW_COLOR,
|
AsyncBufferedImage img = new AsyncBufferedImage(36, 32, BufferedImage.TYPE_INT_ARGB);
|
||||||
stackable ? 1 : 0, false, CLIENT_DEFAULT_ZOOM);
|
clientThread.invokeLater(() ->
|
||||||
return sprite.toBufferedImage();
|
{
|
||||||
|
if (client.getGameState().ordinal() < GameState.LOGIN_SCREEN.ordinal())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SpritePixels sprite = client.createItemSprite(itemId, quantity, 1, SpritePixels.DEFAULT_SHADOW_COLOR,
|
||||||
|
stackable ? 1 : 0, false, CLIENT_DEFAULT_ZOOM);
|
||||||
|
if (sprite == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sprite.toBufferedImage(img);
|
||||||
|
img.changed();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get item sprite image
|
* Get item sprite image as BufferedImage.
|
||||||
|
* <p>
|
||||||
|
* This method may return immediately with a blank image if not called on the game thread.
|
||||||
|
* The image will be filled in later. If this is used for a UI label/button, it should be added
|
||||||
|
* using AsyncBufferedImage::addTo to ensure it is painted properly
|
||||||
*
|
*
|
||||||
* @param itemId
|
* @param itemId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public BufferedImage getImage(int itemId)
|
public AsyncBufferedImage getImage(int itemId)
|
||||||
{
|
{
|
||||||
return getImage(itemId, 1, false);
|
return getImage(itemId, 1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get item sprite image as BufferedImage
|
* Get item sprite image as BufferedImage.
|
||||||
|
* <p>
|
||||||
|
* This method may return immediately with a blank image if not called on the game thread.
|
||||||
|
* The image will be filled in later. If this is used for a UI label/button, it should be added
|
||||||
|
* using AsyncBufferedImage::addTo to ensure it is painted properly
|
||||||
*
|
*
|
||||||
* @param itemId
|
* @param itemId
|
||||||
* @param quantity
|
* @param quantity
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public BufferedImage getImage(int itemId, int quantity, boolean stackable)
|
public AsyncBufferedImage getImage(int itemId, int quantity, boolean stackable)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,14 +30,13 @@ import java.awt.Dimension;
|
|||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.CompoundBorder;
|
import javax.swing.border.CompoundBorder;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.client.game.AsyncBufferedImage;
|
||||||
import net.runelite.client.util.LinkBrowser;
|
import net.runelite.client.util.LinkBrowser;
|
||||||
import net.runelite.client.util.StackFormatter;
|
import net.runelite.client.util.StackFormatter;
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ class GrandExchangeItemPanel extends JPanel
|
|||||||
{
|
{
|
||||||
private static final Dimension ICON_SIZE = new Dimension(32, 32);
|
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)
|
haPrice)
|
||||||
{
|
{
|
||||||
BorderLayout layout = new BorderLayout();
|
BorderLayout layout = new BorderLayout();
|
||||||
@@ -88,7 +87,7 @@ class GrandExchangeItemPanel extends JPanel
|
|||||||
itemIcon.setPreferredSize(ICON_SIZE);
|
itemIcon.setPreferredSize(ICON_SIZE);
|
||||||
if (icon != null)
|
if (icon != null)
|
||||||
{
|
{
|
||||||
itemIcon.setIcon(new ImageIcon(icon));
|
icon.addTo(itemIcon);
|
||||||
}
|
}
|
||||||
add(itemIcon, BorderLayout.LINE_START);
|
add(itemIcon, BorderLayout.LINE_START);
|
||||||
|
|
||||||
|
|||||||
@@ -24,19 +24,19 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.grandexchange;
|
package net.runelite.client.plugins.grandexchange;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.runelite.client.game.AsyncBufferedImage;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class GrandExchangeItems
|
public class GrandExchangeItems
|
||||||
{
|
{
|
||||||
private final BufferedImage icon;
|
private final AsyncBufferedImage icon;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int itemId;
|
private final int itemId;
|
||||||
private final int gePrice;
|
private final int gePrice;
|
||||||
private final double haPrice;
|
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.icon = icon;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|||||||
@@ -44,10 +44,10 @@ import javax.swing.border.EmptyBorder;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.ItemComposition;
|
import net.runelite.api.ItemComposition;
|
||||||
|
import net.runelite.client.game.AsyncBufferedImage;
|
||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.plugins.hiscore.IconTextField;
|
import net.runelite.client.plugins.hiscore.IconTextField;
|
||||||
import net.runelite.http.api.item.Item;
|
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.ItemPrice;
|
||||||
import net.runelite.http.api.item.SearchResult;
|
import net.runelite.http.api.item.SearchResult;
|
||||||
|
|
||||||
@@ -60,8 +60,6 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
private final ItemManager itemManager;
|
private final ItemManager itemManager;
|
||||||
private final ScheduledExecutorService executor;
|
private final ScheduledExecutorService executor;
|
||||||
|
|
||||||
private ItemClient itemClient;
|
|
||||||
|
|
||||||
private Icon search;
|
private Icon search;
|
||||||
|
|
||||||
private IconTextField searchBox = new IconTextField();
|
private IconTextField searchBox = new IconTextField();
|
||||||
@@ -150,8 +148,6 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
|
|
||||||
if (result != null && !result.getItems().isEmpty())
|
if (result != null && !result.getItems().isEmpty())
|
||||||
{
|
{
|
||||||
itemClient = new ItemClient();
|
|
||||||
|
|
||||||
for (Item item : result.getItems())
|
for (Item item : result.getItems())
|
||||||
{
|
{
|
||||||
int itemId = item.getId();
|
int itemId = item.getId();
|
||||||
@@ -172,20 +168,7 @@ class GrandExchangeSearchPanel extends JPanel
|
|||||||
log.warn("Unable to fetch item price for {}", itemId, ex);
|
log.warn("Unable to fetch item price for {}", itemId, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedImage itemImage = null;
|
AsyncBufferedImage itemImage = itemManager.getImage(itemId);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
ITEMS_LIST.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));
|
ITEMS_LIST.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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());
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 679 B |
|
Before Width: | Height: | Size: 658 B |
|
Before Width: | Height: | Size: 661 B |
|
Before Width: | Height: | Size: 676 B |
|
Before Width: | Height: | Size: 635 B |
|
Before Width: | Height: | Size: 655 B |
|
Before Width: | Height: | Size: 621 B |
|
Before Width: | Height: | Size: 607 B |
|
Before Width: | Height: | Size: 602 B |
|
Before Width: | Height: | Size: 631 B |
|
Before Width: | Height: | Size: 783 B |
|
Before Width: | Height: | Size: 811 B |
|
Before Width: | Height: | Size: 872 B |
|
Before Width: | Height: | Size: 854 B |
|
Before Width: | Height: | Size: 868 B |
|
Before Width: | Height: | Size: 802 B |
|
Before Width: | Height: | Size: 686 B |
|
Before Width: | Height: | Size: 749 B |
|
Before Width: | Height: | Size: 735 B |
|
Before Width: | Height: | Size: 854 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 816 B |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 947 B |
|
Before Width: | Height: | Size: 738 B |
@@ -25,10 +25,10 @@
|
|||||||
|
|
||||||
package net.runelite.client.plugins.grandexchange;
|
package net.runelite.client.plugins.grandexchange;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import net.runelite.api.GrandExchangeOffer;
|
import net.runelite.api.GrandExchangeOffer;
|
||||||
import net.runelite.api.GrandExchangeOfferState;
|
import net.runelite.api.GrandExchangeOfferState;
|
||||||
import net.runelite.api.ItemComposition;
|
import net.runelite.api.ItemComposition;
|
||||||
|
import net.runelite.client.game.AsyncBufferedImage;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -48,7 +48,7 @@ public class GrandExchangeOfferSlotTest
|
|||||||
when(offer.getState()).thenReturn(GrandExchangeOfferState.CANCELLED_BUY);
|
when(offer.getState()).thenReturn(GrandExchangeOfferState.CANCELLED_BUY);
|
||||||
|
|
||||||
GrandExchangeOfferSlot offerSlot = new GrandExchangeOfferSlot();
|
GrandExchangeOfferSlot offerSlot = new GrandExchangeOfferSlot();
|
||||||
offerSlot.updateOffer(mock(ItemComposition.class), mock(BufferedImage.class), offer);
|
offerSlot.updateOffer(mock(ItemComposition.class), mock(AsyncBufferedImage.class), offer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,28 @@ public abstract class RSSpritePixelsMixin implements RSSpritePixels
|
|||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage toBufferedImage()
|
public BufferedImage toBufferedImage()
|
||||||
|
{
|
||||||
|
BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
|
toBufferedImage(img);
|
||||||
|
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public void toBufferedImage(BufferedImage img)
|
||||||
{
|
{
|
||||||
int width = getWidth();
|
int width = getWidth();
|
||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
|
|
||||||
|
if (img.getWidth() != width || img.getHeight() != height)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Image bounds do not match SpritePixels");
|
||||||
|
}
|
||||||
|
|
||||||
int[] pixels = getPixels();
|
int[] pixels = getPixels();
|
||||||
int[] transPixels = new int[pixels.length];
|
int[] transPixels = new int[pixels.length];
|
||||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
|
||||||
|
|
||||||
for (int i = 0; i < pixels.length; i++)
|
for (int i = 0; i < pixels.length; i++)
|
||||||
{
|
{
|
||||||
@@ -51,6 +67,5 @@ public abstract class RSSpritePixelsMixin implements RSSpritePixels
|
|||||||
}
|
}
|
||||||
|
|
||||||
img.setRGB(0, 0, width, height, transPixels, 0, width);
|
img.setRGB(0, 0, width, height, transPixels, 0, width);
|
||||||
return img;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||