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);
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)
{
BorderLayout layout = new BorderLayout();
@@ -69,6 +69,12 @@ class GrandExchangeItemPanel extends JPanel
MouseAdapter itemPanelMouseListener = new MouseAdapter()
{
@Override
public void mouseReleased(MouseEvent e)
{
geLink(name, itemID);
}
@Override
public void mouseEntered(MouseEvent e)
{
@@ -88,12 +94,6 @@ class GrandExchangeItemPanel extends JPanel
}
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
@Override
public void mouseReleased(MouseEvent e)
{
geLink(name, itemID);
}
};
addMouseListener(itemPanelMouseListener);
@@ -110,7 +110,7 @@ class GrandExchangeItemPanel extends JPanel
add(itemIcon, BorderLayout.LINE_START);
// 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);
rightPanel.setBackground(background);
@@ -126,7 +126,7 @@ class GrandExchangeItemPanel extends JPanel
JLabel gePriceLabel = new JLabel();
if (gePrice > 0)
{
gePriceLabel.setText(QuantityFormatter.formatNumber(gePrice) + " gp");
gePriceLabel.setText("GE Price: " + QuantityFormatter.formatNumber(gePrice) + " gp");
}
else
{
@@ -135,38 +135,32 @@ class GrandExchangeItemPanel extends JPanel
gePriceLabel.setForeground(ColorScheme.GRAND_EXCHANGE_PRICE);
rightPanel.add(gePriceLabel);
JPanel alchAndLimitPanel = new JPanel(new BorderLayout());
panels.add(alchAndLimitPanel);
alchAndLimitPanel.setBackground(background);
// OSB Price
if (osbPrice > 0)
{
JLabel osbPricelabel = new JLabel();
osbPricelabel.setText("OSB Price: " + QuantityFormatter.formatNumber(osbPrice) + " gp");
osbPricelabel.setForeground(ColorScheme.GRAND_EXCHANGE_PRICE);
rightPanel.add(osbPricelabel);
}
// Alch price
JLabel haPriceLabel = new JLabel();
haPriceLabel.setText(QuantityFormatter.formatNumber(haPrice) + " alch");
haPriceLabel.setText("Alch Price: " + QuantityFormatter.formatNumber(haPrice) + " gp");
haPriceLabel.setForeground(ColorScheme.GRAND_EXCHANGE_ALCH);
alchAndLimitPanel.add(haPriceLabel, BorderLayout.WEST);
rightPanel.add(haPriceLabel);
// GE Limit
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.setForeground(ColorScheme.GRAND_EXCHANGE_LIMIT);
geLimitLabel.setBorder(new CompoundBorder(geLimitLabel.getBorder(), new EmptyBorder(0, 0, 0, 7)));
alchAndLimitPanel.add(geLimitLabel, BorderLayout.EAST);
rightPanel.add(alchAndLimitPanel);
rightPanel.add(geLimitLabel);
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)
{
final String url = "http://services.runescape.com/m=itemdb_oldschool/"
@@ -176,4 +170,13 @@ class GrandExchangeItemPanel extends JPanel
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;
@Inject
private GrandExchangePanel(ClientThread clientThread, ItemManager itemManager, ScheduledExecutorService executor)
private GrandExchangePanel(ClientThread clientThread, ItemManager itemManager, ScheduledExecutorService executor, GrandExchangeConfig config)
{
super(false);
@@ -66,7 +66,7 @@ class GrandExchangePanel extends PluginPanel
setBackground(ColorScheme.DARK_GRAY_COLOR);
// Search Panel
searchPanel = new GrandExchangeSearchPanel(clientThread, itemManager, executor);
searchPanel = new GrandExchangeSearchPanel(clientThread, itemManager, executor, config);
//Offers Panel
offersPanel = new GrandExchangeOffersPanel();
@@ -98,4 +98,4 @@ class GrandExchangePanel extends PluginPanel
{
searchPanel.setItemGELimits(itemGELimits);
}
}
}

View File

@@ -37,6 +37,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Singleton;
import javax.inject.Inject;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
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.util.AsyncBufferedImage;
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.
@@ -61,6 +63,8 @@ import net.runelite.http.api.item.ItemPrice;
@Singleton
class GrandExchangeSearchPanel extends JPanel
{
@Inject
private static final OSBGrandExchangeClient OSBCLIENT = new OSBGrandExchangeClient();
private static final String ERROR_PANEL = "ERROR_PANEL";
private static final String RESULTS_PANEL = "RESULTS_PANEL";
private static final int MAX_SEARCH_ITEMS = 100;
@@ -74,6 +78,9 @@ class GrandExchangeSearchPanel extends JPanel
private final IconTextField searchBar = new IconTextField();
private final GrandExchangeConfig config;
/* The results container, this will hold all the individual ge item panels */
private final JPanel searchItemsPanel = new JPanel();
@@ -88,11 +95,12 @@ class GrandExchangeSearchPanel extends JPanel
@Setter(AccessLevel.PACKAGE)
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.itemManager = itemManager;
this.executor = executor;
this.config = config;
setLayout(new BorderLayout());
setBackground(ColorScheme.DARK_GRAY_COLOR);
@@ -237,8 +245,20 @@ class GrandExchangeSearchPanel extends JPanel
int index = 0;
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(),
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
@@ -275,4 +295,4 @@ class GrandExchangeSearchPanel extends JPanel
});
}
}
}