Make plugins work with new ClientUI
- Change LinkBrowser to not use ClientUI as parent for message box (not required at all) and change it from Guice service to static utility class - Set screenshot plugin offsets statically without recalculating them based on swing component Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -60,16 +60,14 @@ public class SessionManager
|
||||
private final EventBus eventBus;
|
||||
private ConfigManager configManager;
|
||||
private ScheduledExecutorService executor;
|
||||
private final LinkBrowser browser;
|
||||
private final AccountClient loginClient = new AccountClient();
|
||||
|
||||
@Inject
|
||||
public SessionManager(ConfigManager configManager, EventBus eventBus, ScheduledExecutorService executor, LinkBrowser browser)
|
||||
public SessionManager(ConfigManager configManager, EventBus eventBus, ScheduledExecutorService executor)
|
||||
{
|
||||
this.configManager = configManager;
|
||||
this.eventBus = eventBus;
|
||||
this.executor = executor;
|
||||
this.browser = browser;
|
||||
eventBus.register(this);
|
||||
}
|
||||
|
||||
@@ -213,7 +211,7 @@ public class SessionManager
|
||||
openSession(new AccountSession(login.getUid(), Instant.now()));
|
||||
|
||||
// Navigate to login link
|
||||
browser.browse(login.getOauthUrl());
|
||||
LinkBrowser.browse(login.getOauthUrl());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -120,13 +120,11 @@ class FeedPanel extends PluginPanel
|
||||
|
||||
private final FeedConfig config;
|
||||
private final Supplier<FeedResult> feedSupplier;
|
||||
private final LinkBrowser linkBrowser;
|
||||
|
||||
FeedPanel(FeedConfig config, Supplier<FeedResult> feedSupplier, LinkBrowser linkBrowser)
|
||||
FeedPanel(FeedConfig config, Supplier<FeedResult> feedSupplier)
|
||||
{
|
||||
this.config = config;
|
||||
this.feedSupplier = feedSupplier;
|
||||
this.linkBrowser = linkBrowser;
|
||||
}
|
||||
|
||||
void rebuildFeed()
|
||||
@@ -294,7 +292,7 @@ class FeedPanel extends PluginPanel
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
avatarAndRight.setBackground(hoverColor);
|
||||
linkBrowser.browse(item.getUrl());
|
||||
LinkBrowser.browse(item.getUrl());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.task.Schedule;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.util.LinkBrowser;
|
||||
import net.runelite.http.api.feed.FeedClient;
|
||||
import net.runelite.http.api.feed.FeedResult;
|
||||
|
||||
@@ -63,9 +62,6 @@ public class FeedPlugin extends Plugin
|
||||
@Inject
|
||||
private ScheduledExecutorService executorService;
|
||||
|
||||
@Inject
|
||||
private LinkBrowser linkBrowser;
|
||||
|
||||
private FeedPanel feedPanel;
|
||||
private NavigationButton navButton;
|
||||
|
||||
@@ -86,7 +82,7 @@ public class FeedPlugin extends Plugin
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
feedPanel = new FeedPanel(config, feedSupplier, linkBrowser);
|
||||
feedPanel = new FeedPanel(config, feedSupplier);
|
||||
|
||||
BufferedImage icon;
|
||||
synchronized (ImageIO.class)
|
||||
|
||||
@@ -45,10 +45,9 @@ import net.runelite.client.util.LinkBrowser;
|
||||
class GrandExchangeItemPanel extends JPanel
|
||||
{
|
||||
private static final NumberFormat NUMBER_FORMATTER = NumberFormat.getInstance();
|
||||
|
||||
private static final Dimension ICON_SIZE = new Dimension(32, 32);
|
||||
|
||||
GrandExchangeItemPanel(LinkBrowser linkBrowser, BufferedImage icon, String name, int itemID, int gePrice, Double
|
||||
GrandExchangeItemPanel(BufferedImage icon, String name, int itemID, int gePrice, Double
|
||||
haPrice)
|
||||
{
|
||||
BorderLayout layout = new BorderLayout();
|
||||
@@ -75,7 +74,7 @@ class GrandExchangeItemPanel extends JPanel
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
geLink(linkBrowser, name, itemID);
|
||||
geLink(name, itemID);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -125,13 +124,13 @@ class GrandExchangeItemPanel extends JPanel
|
||||
add(rightPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private void geLink(LinkBrowser linkBrowser, String name, int itemID)
|
||||
private void geLink(String name, int itemID)
|
||||
{
|
||||
final String url = "http://services.runescape.com/m=itemdb_oldschool/"
|
||||
+ name.replaceAll(" ", "_")
|
||||
+ "/viewitem?obj="
|
||||
+ itemID;
|
||||
|
||||
linkBrowser.browse(url);
|
||||
LinkBrowser.browse(url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import net.runelite.api.Client;
|
||||
import net.runelite.api.GrandExchangeOffer;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
import net.runelite.client.util.LinkBrowser;
|
||||
|
||||
@Slf4j
|
||||
class GrandExchangePanel extends PluginPanel
|
||||
@@ -54,7 +53,7 @@ class GrandExchangePanel extends PluginPanel
|
||||
private JTabbedPane tabbedPane = new JTabbedPane();
|
||||
|
||||
@Inject
|
||||
GrandExchangePanel(Client client, ItemManager itemManager, ScheduledExecutorService executor, LinkBrowser linkBrowser)
|
||||
GrandExchangePanel(Client client, ItemManager itemManager, ScheduledExecutorService executor)
|
||||
{
|
||||
setLayout(new BorderLayout());
|
||||
add(tabbedPane, BorderLayout.NORTH);
|
||||
@@ -68,7 +67,7 @@ class GrandExchangePanel extends PluginPanel
|
||||
}
|
||||
|
||||
// Search Panel
|
||||
searchPanel = new GrandExchangeSearchPanel(client, itemManager, executor, linkBrowser);
|
||||
searchPanel = new GrandExchangeSearchPanel(client, itemManager, executor);
|
||||
|
||||
tabbedPane.addTab("Offers", offerPanel);
|
||||
tabbedPane.addTab("Search", searchPanel);
|
||||
|
||||
@@ -46,7 +46,6 @@ import net.runelite.api.Client;
|
||||
import net.runelite.api.ItemComposition;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.plugins.hiscore.IconTextField;
|
||||
import net.runelite.client.util.LinkBrowser;
|
||||
import net.runelite.http.api.item.Item;
|
||||
import net.runelite.http.api.item.ItemClient;
|
||||
import net.runelite.http.api.item.ItemPrice;
|
||||
@@ -60,7 +59,6 @@ class GrandExchangeSearchPanel extends JPanel
|
||||
private final Client client;
|
||||
private final ItemManager itemManager;
|
||||
private final ScheduledExecutorService executor;
|
||||
private final LinkBrowser linkBrowser;
|
||||
|
||||
private ItemClient itemClient;
|
||||
|
||||
@@ -71,12 +69,11 @@ class GrandExchangeSearchPanel extends JPanel
|
||||
private JPanel searchItemsPanel = new JPanel();
|
||||
private JLabel searchingLabel = new JLabel();
|
||||
|
||||
GrandExchangeSearchPanel(Client client, ItemManager itemManager, ScheduledExecutorService executor, LinkBrowser linkBrowser)
|
||||
GrandExchangeSearchPanel(Client client, ItemManager itemManager, ScheduledExecutorService executor)
|
||||
{
|
||||
this.client = client;
|
||||
this.itemManager = itemManager;
|
||||
this.executor = executor;
|
||||
this.linkBrowser = linkBrowser;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -203,7 +200,7 @@ class GrandExchangeSearchPanel extends JPanel
|
||||
{
|
||||
for (GrandExchangeItems item : ITEMS_LIST)
|
||||
{
|
||||
GrandExchangeItemPanel panel = new GrandExchangeItemPanel(linkBrowser, item.getIcon(), item.getName(),
|
||||
GrandExchangeItemPanel panel = new GrandExchangeItemPanel(item.getIcon(), item.getName(),
|
||||
item.getItemId(), item.getGePrice(), item.getHaPrice());
|
||||
|
||||
searchItemsPanel.add(panel);
|
||||
|
||||
@@ -31,7 +31,6 @@ import java.awt.Color;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
@@ -410,9 +409,8 @@ public class ScreenshotPlugin extends Plugin
|
||||
clientUi.paint(graphics);
|
||||
|
||||
// Evaluate the position of the game inside the frame
|
||||
Point gamePoint = SwingUtilities.convertPoint(client.getCanvas(), 0, 0, clientUi);
|
||||
gameOffsetX = gamePoint.x;
|
||||
gameOffsetY = gamePoint.y;
|
||||
gameOffsetX = 6;
|
||||
gameOffsetY = 0;
|
||||
}
|
||||
|
||||
// Draw the game onto the screenshot
|
||||
|
||||
@@ -30,13 +30,10 @@ import java.awt.datatransfer.StringSelection;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
|
||||
/**
|
||||
* Utility class used for browser navigation
|
||||
@@ -45,21 +42,13 @@ import net.runelite.client.ui.ClientUI;
|
||||
@Slf4j
|
||||
public class LinkBrowser
|
||||
{
|
||||
private final Provider<ClientUI> clientUIProvider;
|
||||
|
||||
@Inject
|
||||
private LinkBrowser(final Provider<ClientUI> clientUIProvider)
|
||||
{
|
||||
this.clientUIProvider = clientUIProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to navigate to specified URL in browser. In case operation fails, displays message box with message
|
||||
* and copies link to clipboard to navigate to.
|
||||
* @param url url to open
|
||||
* @return true if operation was successful
|
||||
*/
|
||||
public boolean browse(final String url)
|
||||
public static boolean browse(final String url)
|
||||
{
|
||||
if (!Desktop.isDesktopSupported())
|
||||
{
|
||||
@@ -93,18 +82,11 @@ public class LinkBrowser
|
||||
* Open swing message box with specified message and copy data to clipboard
|
||||
* @param message message to show
|
||||
*/
|
||||
private void showMessageBox(final String message, final String data)
|
||||
private static void showMessageBox(final String message, final String data)
|
||||
{
|
||||
final ClientUI clientUI = clientUIProvider.get();
|
||||
|
||||
if (clientUI == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
final int result = JOptionPane.showConfirmDialog(clientUI, message, "Message",
|
||||
final int result = JOptionPane.showConfirmDialog(null, message, "Message",
|
||||
JOptionPane.OK_CANCEL_OPTION);
|
||||
|
||||
if (result == JOptionPane.OK_OPTION)
|
||||
|
||||
Reference in New Issue
Block a user