Merge pull request #372 from UniquePassive/overlay-layers

Add overlay layers
This commit is contained in:
Adam
2018-01-14 21:55:58 -05:00
committed by GitHub
24 changed files with 179 additions and 23 deletions

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.api;
public interface BufferProvider
{
}

View File

@@ -174,4 +174,6 @@ public interface Client
List<Projectile> getProjectiles();
BufferProvider getBufferProvider();
}

View File

@@ -44,10 +44,12 @@ import net.runelite.api.MessageNode;
import net.runelite.api.PacketBuffer;
import net.runelite.api.Point;
import net.runelite.api.Projectile;
import net.runelite.api.Region;
import net.runelite.client.RuneLite;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.game.DeathChecker;
import net.runelite.client.task.Scheduler;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayRenderer;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
@@ -104,7 +106,39 @@ public class Hooks
try
{
renderer.render(graphics2d);
renderer.render(graphics2d, OverlayLayer.ALWAYS_ON_TOP);
}
catch (Exception ex)
{
log.warn("Error during overlay rendering", ex);
}
}
public static void drawRegion(Region region, int var1, int var2, int var3, int var4, int var5, int var6)
{
MainBufferProvider bufferProvider = (MainBufferProvider) client.getBufferProvider();
BufferedImage image = (BufferedImage) bufferProvider.getImage();
Graphics2D graphics2d = (Graphics2D) image.getGraphics();
try
{
renderer.render(graphics2d, OverlayLayer.UNDER_WIDGETS);
}
catch (Exception ex)
{
log.warn("Error during overlay rendering", ex);
}
}
public static void drawAfterWidgets()
{
MainBufferProvider bufferProvider = (MainBufferProvider) client.getBufferProvider();
BufferedImage image = (BufferedImage) bufferProvider.getImage();
Graphics2D graphics2d = (Graphics2D) image.getGraphics();
try
{
renderer.render(graphics2d, OverlayLayer.ABOVE_WIDGETS);
}
catch (Exception ex)
{

View File

@@ -38,6 +38,7 @@ import net.runelite.api.Client;
import net.runelite.api.Perspective;
import net.runelite.api.Projectile;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
public class AoeWarningOverlay extends Overlay
@@ -53,6 +54,7 @@ public class AoeWarningOverlay extends Overlay
public AoeWarningOverlay(@Nullable Client client, AoeWarningPlugin plugin, AoeWarningConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
this.client = client;
this.plugin = plugin;
this.config = config;

View File

@@ -57,6 +57,7 @@ import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
@@ -85,9 +86,7 @@ public class DevToolsOverlay extends Overlay
public DevToolsOverlay(@Nullable Client client, DevToolsPlugin plugin)
{
setPosition(OverlayPosition.DYNAMIC);
setDrawOverBankScreen(true);
setDrawOverClickToPlayScreen(true);
setDrawOverLoginScreen(true);
setLayer(OverlayLayer.ALWAYS_ON_TOP);
this.client = client;
this.plugin = plugin;
}

View File

@@ -37,6 +37,7 @@ import net.runelite.api.NPC;
import net.runelite.api.queries.NPCQuery;
import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import net.runelite.client.util.QueryRunner;
@@ -55,6 +56,7 @@ class FishingSpotOverlay extends Overlay
public FishingSpotOverlay(QueryRunner queryRunner, FishingConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
this.queryRunner = queryRunner;
this.config = config;
}

View File

@@ -50,6 +50,7 @@ import net.runelite.api.widgets.Widget;
import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.http.api.item.ItemPrice;
@@ -95,6 +96,7 @@ public class GroundItemsOverlay extends Overlay
public GroundItemsOverlay(@Nullable Client client, GroundItemsConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
this.client = client;
this.config = config;
}

View File

@@ -35,6 +35,7 @@ import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.widgets.Widget;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
/**
@@ -71,6 +72,7 @@ public class TrapOverlay extends Overlay
TrapOverlay(@Nullable Client client, HunterPlugin plugin, HunterConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
this.plugin = plugin;
this.config = config;
this.client = client;

View File

@@ -40,6 +40,7 @@ import net.runelite.api.NpcID;
import net.runelite.api.Point;
import net.runelite.api.queries.NPCQuery;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.util.QueryRunner;
@@ -64,6 +65,7 @@ public class ImplingsOverlay extends Overlay
public ImplingsOverlay(QueryRunner queryRunner, ImplingsConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
this.queryRunner = queryRunner;
this.config = config;
}

View File

@@ -66,6 +66,7 @@ import static net.runelite.client.plugins.instancemap.WallOffset.NONE;
import static net.runelite.client.plugins.instancemap.WallOffset.TOP_LEFT;
import static net.runelite.client.plugins.instancemap.WallOffset.TOP_RIGHT;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
class InstanceMapOverlay extends Overlay
@@ -114,6 +115,7 @@ class InstanceMapOverlay extends Overlay
InstanceMapOverlay(@Nullable Client client, InstanceMapConfig config, InstanceMapPlugin plugin)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ALWAYS_ON_TOP);
this.client = client;
this.config = config;
this.plugin = plugin;

View File

@@ -54,7 +54,6 @@ class JewelleryCountOverlay extends Overlay
setPosition(OverlayPosition.DYNAMIC);
this.queryRunner = queryRunner;
this.config = config;
this.setDrawOverBankScreen(true);
}
@Override

View File

@@ -49,7 +49,6 @@ class MouseHighlightOverlay extends Overlay
this.client = client;
this.config = config;
this.tooltipManager = tooltipManager;
this.setDrawOverBankScreen(true);
}
@Override

View File

@@ -33,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.Player;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
@@ -50,6 +51,7 @@ public class PlayerIndicatorsOverlay extends Overlay
this.config = config;
this.client = client;
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
}
@Override

View File

@@ -58,7 +58,6 @@ public class BindNeckOverlay extends Overlay
setPosition(OverlayPosition.DYNAMIC);
this.queryRunner = queryRunner;
this.config = config;
this.setDrawOverBankScreen(true);
}
@Override

View File

@@ -59,7 +59,6 @@ public class RunecraftOverlay extends Overlay
this.queryRunner = queryRunner;
this.client = client;
this.config = config;
this.setDrawOverBankScreen(true);
}
@Override

View File

@@ -70,7 +70,6 @@ public class RunepouchOverlay extends Overlay
this.queryRunner = queryRunner;
this.client = client;
this.config = config;
this.setDrawOverBankScreen(true);
}
@Override

View File

@@ -32,6 +32,7 @@ import net.runelite.api.Client;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
@@ -47,6 +48,7 @@ public class TileIndicatorsOverlay extends Overlay
this.config = config;
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.LOW);
setLayer(OverlayLayer.UNDER_WIDGETS);
}
@Override

View File

@@ -47,6 +47,7 @@ import net.runelite.api.Prayer;
import net.runelite.api.Region;
import net.runelite.api.Tile;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
@@ -71,6 +72,7 @@ public class VolcanicMineOverlay extends Overlay
VolcanicMineOverlay(@Nullable Client client, VolcanicMinePlugin plugin, VolcanicMineConfig config)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.UNDER_WIDGETS);
this.client = client;
this.plugin = plugin;
this.config = config;

View File

@@ -31,7 +31,5 @@ public abstract class Overlay implements RenderableEntity
{
private OverlayPosition position = OverlayPosition.TOP_LEFT;
private OverlayPriority priority = OverlayPriority.NONE;
private boolean drawOverLoginScreen = false;
private boolean drawOverBankScreen = false;
private boolean drawOverClickToPlayScreen = false;
private OverlayLayer layer = OverlayLayer.ABOVE_WIDGETS;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018, UniquePassive <https://github.com/uniquepassive>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.ui.overlay;
public enum OverlayLayer
{
/**
* Render overlay above all game elements
*/
ALWAYS_ON_TOP,
/**
* Render under all interfaces
*/
UNDER_WIDGETS,
/**
* Render under the right-click menu
*/
ABOVE_WIDGETS
}

View File

@@ -173,7 +173,7 @@ public class OverlayRenderer
surfaceGraphics = subGraphics;
}
public void render(Graphics2D graphics)
public void render(Graphics2D graphics, OverlayLayer layer)
{
final Client client = clientProvider.get();
@@ -182,6 +182,16 @@ public class OverlayRenderer
return;
}
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
if (client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN) != null)
{
return;
}
final Widget viewport = client.getViewportWidget();
final Rectangle bounds = viewport != null
? new Rectangle(viewport.getBounds())
@@ -204,7 +214,7 @@ public class OverlayRenderer
rightChatboxPoint.move(bounds.x + chatboxBounds.width - BORDER_RIGHT,bounds.y + bounds.height - BORDER_BOTTOM);
overlays.stream()
.filter(overlay -> shouldDrawOverlay(client, overlay))
.filter(overlay -> overlay.getLayer() == layer)
.forEach(overlay ->
{
OverlayPosition overlayPosition = overlay.getPosition();
@@ -282,12 +292,4 @@ public class OverlayRenderer
subGraphics.dispose();
return dimension;
}
private boolean shouldDrawOverlay(Client client, Overlay overlay)
{
return client != null
&& (overlay.isDrawOverLoginScreen() || client.getGameState() == GameState.LOGGED_IN)
&& (overlay.isDrawOverClickToPlayScreen() || client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN) == null)
&& (overlay.isDrawOverBankScreen() || client.getWidget(WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER) == null);
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.rs.api;
import net.runelite.api.BufferProvider;
public interface RSBufferProvider extends BufferProvider
{
}

View File

@@ -25,6 +25,7 @@
package net.runelite.rs.api;
import java.util.Map;
import net.runelite.api.BufferProvider;
import net.runelite.api.Client;
import net.runelite.mapping.Construct;
import net.runelite.mapping.Import;
@@ -350,4 +351,8 @@ public interface RSClient extends RSGameEngine, Client
@Import("isIgnored")
@Override
boolean isIgnored(String name);
@Import("rasterProvider")
@Override
BufferProvider getBufferProvider();
}

View File

@@ -28,7 +28,7 @@ import java.awt.Image;
import net.runelite.api.MainBufferProvider;
import net.runelite.mapping.Import;
public interface RSMainBufferProvider extends MainBufferProvider
public interface RSMainBufferProvider extends RSBufferProvider, MainBufferProvider
{
@Import("image")
@Override