Initial thinking on overlay renderer
This commit is contained in:
@@ -4,7 +4,9 @@ import java.io.File;
|
|||||||
import joptsimple.OptionParser;
|
import joptsimple.OptionParser;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.client.plugins.PluginManager;
|
||||||
import net.runelite.client.ui.ClientUI;
|
import net.runelite.client.ui.ClientUI;
|
||||||
|
import net.runelite.client.ui.OverlayRenderer;
|
||||||
|
|
||||||
|
|
||||||
public class RuneLite
|
public class RuneLite
|
||||||
@@ -13,8 +15,12 @@ public class RuneLite
|
|||||||
public static final File REPO_DIR = new File(RUNELITE_DIR, "repository");
|
public static final File REPO_DIR = new File(RUNELITE_DIR, "repository");
|
||||||
|
|
||||||
public static OptionSet options;
|
public static OptionSet options;
|
||||||
private ClientUI gui;
|
|
||||||
private static Client client;
|
private static Client client;
|
||||||
|
private static RuneLite runelite;
|
||||||
|
|
||||||
|
private ClientUI gui;
|
||||||
|
private PluginManager pluginManager;
|
||||||
|
private OverlayRenderer renderer;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
{
|
{
|
||||||
@@ -22,13 +28,19 @@ public class RuneLite
|
|||||||
parser.accepts("developer-mode");
|
parser.accepts("developer-mode");
|
||||||
options = parser.parse(args);
|
options = parser.parse(args);
|
||||||
|
|
||||||
new RuneLite().start();
|
runelite = new RuneLite();
|
||||||
|
runelite.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Exception
|
public void start() throws Exception
|
||||||
{
|
{
|
||||||
gui = new ClientUI();
|
gui = new ClientUI();
|
||||||
gui.setVisible(true);
|
gui.setVisible(true);
|
||||||
|
|
||||||
|
pluginManager = new PluginManager();
|
||||||
|
pluginManager.loadAll();
|
||||||
|
|
||||||
|
renderer = new OverlayRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Client getClient()
|
public static Client getClient()
|
||||||
@@ -40,4 +52,19 @@ public class RuneLite
|
|||||||
{
|
{
|
||||||
RuneLite.client = client;
|
RuneLite.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RuneLite getRunelite()
|
||||||
|
{
|
||||||
|
return runelite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginManager getPluginManager()
|
||||||
|
{
|
||||||
|
return pluginManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OverlayRenderer getRenderer()
|
||||||
|
{
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package net.runelite.client.plugins;
|
package net.runelite.client.plugins;
|
||||||
|
|
||||||
public class Plugin
|
import net.runelite.client.ui.Overlay;
|
||||||
{
|
|
||||||
|
|
||||||
|
public abstract class Plugin
|
||||||
|
{
|
||||||
|
public abstract Overlay drawOverlay();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
package net.runelite.client.plugins;
|
package net.runelite.client.plugins;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
|
||||||
|
|
||||||
public class PluginManager
|
public class PluginManager
|
||||||
{
|
{
|
||||||
|
private final List<Plugin> plugins = new ArrayList<>();
|
||||||
|
|
||||||
|
public void loadAll()
|
||||||
|
{
|
||||||
|
plugins.add(new OpponentInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Plugin> getPlugins()
|
||||||
|
{
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.runelite.client.plugins.opponentinfo;
|
package net.runelite.client.plugins.opponentinfo;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -9,6 +10,9 @@ import net.runelite.api.Client;
|
|||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
|
import net.runelite.client.ui.Overlay;
|
||||||
|
import net.runelite.client.ui.OverlayPosition;
|
||||||
|
import net.runelite.client.ui.OverlayPriority;
|
||||||
|
|
||||||
public class OpponentInfo extends Plugin
|
public class OpponentInfo extends Plugin
|
||||||
{
|
{
|
||||||
@@ -26,6 +30,7 @@ public class OpponentInfo extends Plugin
|
|||||||
private static final Color HP_RED = new Color(102, 15, 16, 230);
|
private static final Color HP_RED = new Color(102, 15, 16, 230);
|
||||||
|
|
||||||
private final BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
|
private final BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
private final Overlay overlay = new Overlay(image, OverlayPosition.TOP_LEFT, OverlayPriority.HIGH);
|
||||||
|
|
||||||
private Actor getOpponent()
|
private Actor getOpponent()
|
||||||
{
|
{
|
||||||
@@ -38,12 +43,13 @@ public class OpponentInfo extends Plugin
|
|||||||
return player.getInteracting();
|
return player.getInteracting();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics graphics)
|
@Override
|
||||||
|
public Overlay drawOverlay()
|
||||||
{
|
{
|
||||||
Actor opponent = getOpponent();
|
Actor opponent = getOpponent();
|
||||||
|
|
||||||
if (opponent == null)
|
if (opponent == null)
|
||||||
return;
|
return null;
|
||||||
|
|
||||||
int cur = opponent.getHealth();
|
int cur = opponent.getHealth();
|
||||||
int max = opponent.getMaxHealth();
|
int max = opponent.getMaxHealth();
|
||||||
@@ -92,6 +98,8 @@ public class OpponentInfo extends Plugin
|
|||||||
|
|
||||||
g.dispose();
|
g.dispose();
|
||||||
|
|
||||||
graphics.drawImage(image, 10, 25, null);
|
overlay.setDimension(new Dimension(height, image.getWidth()));
|
||||||
|
|
||||||
|
return overlay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.awt.event.ComponentEvent;
|
|||||||
import java.awt.event.ComponentListener;
|
import java.awt.event.ComponentListener;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
@@ -13,9 +12,7 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
|
|
||||||
public final class ClientUI extends JFrame implements ComponentListener
|
public final class ClientUI extends JFrame implements ComponentListener
|
||||||
{
|
{
|
||||||
private static final Logger log = Logger.getLogger(ClientUI.class.getName());
|
|
||||||
|
|
||||||
private ClientPanel panel;
|
private ClientPanel panel;
|
||||||
|
|
||||||
public ClientUI() throws Exception
|
public ClientUI() throws Exception
|
||||||
|
|||||||
59
src/main/java/net/runelite/client/ui/Overlay.java
Normal file
59
src/main/java/net/runelite/client/ui/Overlay.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package net.runelite.client.ui;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class Overlay
|
||||||
|
{
|
||||||
|
private BufferedImage image; // image to draw
|
||||||
|
private Dimension dimension; // dimension of visable overlay
|
||||||
|
private OverlayPosition position; // where to draw it
|
||||||
|
private OverlayPriority priority; // if multiple overlays exist in the same position, who wins
|
||||||
|
|
||||||
|
public Overlay(BufferedImage image, OverlayPosition position, OverlayPriority priority)
|
||||||
|
{
|
||||||
|
this.image = image;
|
||||||
|
this.position = position;
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage getImage()
|
||||||
|
{
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(BufferedImage image)
|
||||||
|
{
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dimension getDimension()
|
||||||
|
{
|
||||||
|
return dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDimension(Dimension dimension)
|
||||||
|
{
|
||||||
|
this.dimension = dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OverlayPosition getPosition()
|
||||||
|
{
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(OverlayPosition position)
|
||||||
|
{
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OverlayPriority getPriority()
|
||||||
|
{
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriority(OverlayPriority priority)
|
||||||
|
{
|
||||||
|
this.priority = priority;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package net.runelite.client.ui;
|
||||||
|
|
||||||
|
public enum OverlayPosition
|
||||||
|
{
|
||||||
|
TOP_LEFT;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.runelite.client.ui;
|
||||||
|
|
||||||
|
public enum OverlayPriority
|
||||||
|
{
|
||||||
|
LOW,
|
||||||
|
MED,
|
||||||
|
HIGH;
|
||||||
|
}
|
||||||
40
src/main/java/net/runelite/client/ui/OverlayRenderer.java
Normal file
40
src/main/java/net/runelite/client/ui/OverlayRenderer.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package net.runelite.client.ui;
|
||||||
|
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.runelite.client.RuneLite;
|
||||||
|
import net.runelite.client.plugins.Plugin;
|
||||||
|
|
||||||
|
public class OverlayRenderer
|
||||||
|
{
|
||||||
|
private static final int TOP_LEFT_BORDER_TOP = 25;
|
||||||
|
private static final int TOP_LEFT_BORDER_LEFT = 10;
|
||||||
|
private static final int TOP_LEFT_PADDING = 10;
|
||||||
|
|
||||||
|
public void render(Graphics graphics)
|
||||||
|
{
|
||||||
|
List<Overlay> overlays = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Plugin plugin : RuneLite.getRunelite().getPluginManager().getPlugins())
|
||||||
|
{
|
||||||
|
Overlay overlay = plugin.drawOverlay();
|
||||||
|
if (overlay != null)
|
||||||
|
overlays.add(overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
Overlay[] topLeft = overlays.stream().filter(o -> o.getPosition() == OverlayPosition.TOP_LEFT).sorted((o1, o2) -> o1.getPriority().compareTo(o2.getPriority())).toArray(s -> new Overlay[s]);
|
||||||
|
int y = TOP_LEFT_BORDER_TOP;
|
||||||
|
|
||||||
|
for (Overlay overlay : topLeft)
|
||||||
|
{
|
||||||
|
BufferedImage image = overlay.getImage();
|
||||||
|
Dimension dimension = overlay.getDimension();
|
||||||
|
|
||||||
|
graphics.drawImage(image, TOP_LEFT_BORDER_LEFT, y, null);
|
||||||
|
y += dimension.getHeight() + TOP_LEFT_PADDING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,8 @@ package net.runelite.inject.callbacks;
|
|||||||
import java.awt.Canvas;
|
import java.awt.Canvas;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
|
import net.runelite.client.RuneLite;
|
||||||
|
import net.runelite.client.ui.OverlayRenderer;
|
||||||
|
|
||||||
public class RSCanvasCallback
|
public class RSCanvasCallback
|
||||||
{
|
{
|
||||||
@@ -14,11 +15,14 @@ public class RSCanvasCallback
|
|||||||
{
|
{
|
||||||
Graphics clientGraphics = clientBuffer.getGraphics();
|
Graphics clientGraphics = clientBuffer.getGraphics();
|
||||||
clientGraphics.drawImage(gameBuffer, 0, 0, null);
|
clientGraphics.drawImage(gameBuffer, 0, 0, null);
|
||||||
//clientGraphics.dispose();
|
|
||||||
|
|
||||||
//clientGraphics = clientBuffer.getGraphics();
|
RuneLite runelite = RuneLite.getRunelite();
|
||||||
//clientGraphics.drawString("something, something 2", 42, 42);
|
if (runelite != null)
|
||||||
new OpponentInfo().draw(clientGraphics);
|
{
|
||||||
|
OverlayRenderer renderer = runelite.getRenderer();
|
||||||
|
if (renderer != null)
|
||||||
|
renderer.render(clientGraphics);
|
||||||
|
}
|
||||||
|
|
||||||
clientGraphics.dispose();
|
clientGraphics.dispose();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user