grandexchange: add osbuddy active price to ge item panel (#2090)

* grandexchange: add osbuddy active price to ge item panel
This commit is contained in:
James
2019-12-13 02:06:16 -08:00
committed by Kyle
parent 079d445945
commit 1a40da7900
3 changed files with 57 additions and 34 deletions

View File

@@ -54,7 +54,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(AsyncBufferedImage icon, String name, int itemID, int gePrice, int GrandExchangeItemPanel(AsyncBufferedImage icon, String name, int itemID, int gePrice, int osbPrice, int
haPrice, int geItemLimit) haPrice, int geItemLimit)
{ {
BorderLayout layout = new BorderLayout(); BorderLayout layout = new BorderLayout();
@@ -69,6 +69,12 @@ class GrandExchangeItemPanel extends JPanel
MouseAdapter itemPanelMouseListener = new MouseAdapter() MouseAdapter itemPanelMouseListener = new MouseAdapter()
{ {
@Override
public void mouseReleased(MouseEvent e)
{
geLink(name, itemID);
}
@Override @Override
public void mouseEntered(MouseEvent e) public void mouseEntered(MouseEvent e)
{ {
@@ -88,12 +94,6 @@ class GrandExchangeItemPanel extends JPanel
} }
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
} }
@Override
public void mouseReleased(MouseEvent e)
{
geLink(name, itemID);
}
}; };
addMouseListener(itemPanelMouseListener); addMouseListener(itemPanelMouseListener);
@@ -110,7 +110,7 @@ class GrandExchangeItemPanel extends JPanel
add(itemIcon, BorderLayout.LINE_START); add(itemIcon, BorderLayout.LINE_START);
// Item details panel // Item details panel
JPanel rightPanel = new JPanel(new GridLayout(3, 1)); JPanel rightPanel = new JPanel(new GridLayout((osbPrice > 0) ? 5 : 4, 1));
panels.add(rightPanel); panels.add(rightPanel);
rightPanel.setBackground(background); rightPanel.setBackground(background);
@@ -126,7 +126,7 @@ class GrandExchangeItemPanel extends JPanel
JLabel gePriceLabel = new JLabel(); JLabel gePriceLabel = new JLabel();
if (gePrice > 0) if (gePrice > 0)
{ {
gePriceLabel.setText(QuantityFormatter.formatNumber(gePrice) + " gp"); gePriceLabel.setText("GE Price: " + QuantityFormatter.formatNumber(gePrice) + " gp");
} }
else else
{ {
@@ -135,38 +135,32 @@ class GrandExchangeItemPanel extends JPanel
gePriceLabel.setForeground(ColorScheme.GRAND_EXCHANGE_PRICE); gePriceLabel.setForeground(ColorScheme.GRAND_EXCHANGE_PRICE);
rightPanel.add(gePriceLabel); rightPanel.add(gePriceLabel);
JPanel alchAndLimitPanel = new JPanel(new BorderLayout()); // OSB Price
panels.add(alchAndLimitPanel); if (osbPrice > 0)
alchAndLimitPanel.setBackground(background); {
JLabel osbPricelabel = new JLabel();
osbPricelabel.setText("OSB Price: " + QuantityFormatter.formatNumber(osbPrice) + " gp");
osbPricelabel.setForeground(ColorScheme.GRAND_EXCHANGE_PRICE);
rightPanel.add(osbPricelabel);
}
// Alch price // Alch price
JLabel haPriceLabel = new JLabel(); JLabel haPriceLabel = new JLabel();
haPriceLabel.setText(QuantityFormatter.formatNumber(haPrice) + " alch"); haPriceLabel.setText("Alch Price: " + QuantityFormatter.formatNumber(haPrice) + " gp");
haPriceLabel.setForeground(ColorScheme.GRAND_EXCHANGE_ALCH); haPriceLabel.setForeground(ColorScheme.GRAND_EXCHANGE_ALCH);
alchAndLimitPanel.add(haPriceLabel, BorderLayout.WEST); rightPanel.add(haPriceLabel);
// GE Limit // GE Limit
JLabel geLimitLabel = new JLabel(); JLabel geLimitLabel = new JLabel();
String limitLabelText = geItemLimit == 0 ? "" : "Limit " + QuantityFormatter.formatNumber(geItemLimit); String limitLabelText = geItemLimit == 0 ? "" : "Buy Limit " + QuantityFormatter.formatNumber(geItemLimit);
geLimitLabel.setText(limitLabelText); geLimitLabel.setText(limitLabelText);
geLimitLabel.setForeground(ColorScheme.GRAND_EXCHANGE_LIMIT); geLimitLabel.setForeground(ColorScheme.GRAND_EXCHANGE_LIMIT);
geLimitLabel.setBorder(new CompoundBorder(geLimitLabel.getBorder(), new EmptyBorder(0, 0, 0, 7))); geLimitLabel.setBorder(new CompoundBorder(geLimitLabel.getBorder(), new EmptyBorder(0, 0, 0, 7)));
alchAndLimitPanel.add(geLimitLabel, BorderLayout.EAST); rightPanel.add(geLimitLabel);
rightPanel.add(alchAndLimitPanel);
add(rightPanel, BorderLayout.CENTER); add(rightPanel, BorderLayout.CENTER);
} }
private void matchComponentBackground(JPanel panel, Color color)
{
panel.setBackground(color);
for (Component c : panel.getComponents())
{
c.setBackground(color);
}
}
static void geLink(String name, int itemID) static void geLink(String name, int itemID)
{ {
final String url = "http://services.runescape.com/m=itemdb_oldschool/" final String url = "http://services.runescape.com/m=itemdb_oldschool/"
@@ -176,4 +170,13 @@ class GrandExchangeItemPanel extends JPanel
LinkBrowser.browse(url); LinkBrowser.browse(url);
} }
}
private void matchComponentBackground(JPanel panel, Color color)
{
panel.setBackground(color);
for (Component c : panel.getComponents())
{
c.setBackground(color);
}
}
}

View File

@@ -58,7 +58,7 @@ class GrandExchangePanel extends PluginPanel
private GrandExchangeOffersPanel offersPanel; private GrandExchangeOffersPanel offersPanel;
@Inject @Inject
private GrandExchangePanel(ClientThread clientThread, ItemManager itemManager, ScheduledExecutorService executor) private GrandExchangePanel(ClientThread clientThread, ItemManager itemManager, ScheduledExecutorService executor, GrandExchangeConfig config)
{ {
super(false); super(false);
@@ -66,7 +66,7 @@ class GrandExchangePanel extends PluginPanel
setBackground(ColorScheme.DARK_GRAY_COLOR); setBackground(ColorScheme.DARK_GRAY_COLOR);
// Search Panel // Search Panel
searchPanel = new GrandExchangeSearchPanel(clientThread, itemManager, executor); searchPanel = new GrandExchangeSearchPanel(clientThread, itemManager, executor, config);
//Offers Panel //Offers Panel
offersPanel = new GrandExchangeOffersPanel(); offersPanel = new GrandExchangeOffersPanel();
@@ -98,4 +98,4 @@ class GrandExchangePanel extends PluginPanel
{ {
searchPanel.setItemGELimits(itemGELimits); searchPanel.setItemGELimits(itemGELimits);
} }
} }

View File

@@ -37,6 +37,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.inject.Inject;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@@ -52,6 +53,7 @@ import net.runelite.client.ui.components.IconTextField;
import net.runelite.client.ui.components.PluginErrorPanel; import net.runelite.client.ui.components.PluginErrorPanel;
import net.runelite.client.util.AsyncBufferedImage; import net.runelite.client.util.AsyncBufferedImage;
import net.runelite.http.api.item.ItemPrice; import net.runelite.http.api.item.ItemPrice;
import net.runelite.http.api.osbuddy.OSBGrandExchangeClient;
/** /**
* This panel holds the search section of the Grand Exchange Plugin. * This panel holds the search section of the Grand Exchange Plugin.
@@ -61,6 +63,8 @@ import net.runelite.http.api.item.ItemPrice;
@Singleton @Singleton
class GrandExchangeSearchPanel extends JPanel class GrandExchangeSearchPanel extends JPanel
{ {
@Inject
private static final OSBGrandExchangeClient OSBCLIENT = new OSBGrandExchangeClient();
private static final String ERROR_PANEL = "ERROR_PANEL"; private static final String ERROR_PANEL = "ERROR_PANEL";
private static final String RESULTS_PANEL = "RESULTS_PANEL"; private static final String RESULTS_PANEL = "RESULTS_PANEL";
private static final int MAX_SEARCH_ITEMS = 100; private static final int MAX_SEARCH_ITEMS = 100;
@@ -74,6 +78,9 @@ class GrandExchangeSearchPanel extends JPanel
private final IconTextField searchBar = new IconTextField(); private final IconTextField searchBar = new IconTextField();
private final GrandExchangeConfig config;
/* The results container, this will hold all the individual ge item panels */ /* The results container, this will hold all the individual ge item panels */
private final JPanel searchItemsPanel = new JPanel(); private final JPanel searchItemsPanel = new JPanel();
@@ -88,11 +95,12 @@ class GrandExchangeSearchPanel extends JPanel
@Setter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE)
private Map<Integer, Integer> itemGELimits = Collections.emptyMap(); private Map<Integer, Integer> itemGELimits = Collections.emptyMap();
GrandExchangeSearchPanel(final ClientThread clientThread, final ItemManager itemManager, final ScheduledExecutorService executor) GrandExchangeSearchPanel(final ClientThread clientThread, final ItemManager itemManager, final ScheduledExecutorService executor, final GrandExchangeConfig config)
{ {
this.clientThread = clientThread; this.clientThread = clientThread;
this.itemManager = itemManager; this.itemManager = itemManager;
this.executor = executor; this.executor = executor;
this.config = config;
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBackground(ColorScheme.DARK_GRAY_COLOR); setBackground(ColorScheme.DARK_GRAY_COLOR);
@@ -237,8 +245,20 @@ class GrandExchangeSearchPanel extends JPanel
int index = 0; int index = 0;
for (GrandExchangeItems item : itemsList) for (GrandExchangeItems item : itemsList)
{ {
final int[] osbPrice = {0};
if (config.enableOsbPrices())
{
OSBCLIENT.lookupItem(item.getItemId())
.subscribe(
(osbresult) -> {
osbPrice[0] = osbresult.getOverall_average();
},
(e) -> log.debug("GE : Error getting price of item {}", item.getItemId(), e)
);
}
GrandExchangeItemPanel panel = new GrandExchangeItemPanel(item.getIcon(), item.getName(), GrandExchangeItemPanel panel = new GrandExchangeItemPanel(item.getIcon(), item.getName(),
item.getItemId(), item.getGePrice(), item.getHaPrice(), item.getGeItemLimit()); item.getItemId(), item.getGePrice(), osbPrice[0], item.getHaPrice(), item.getGeItemLimit());
/* /*
Add the first item directly, wrap the rest with margin. This margin hack is because Add the first item directly, wrap the rest with margin. This margin hack is because
@@ -275,4 +295,4 @@ class GrandExchangeSearchPanel extends JPanel
}); });
} }
} }