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