runelite-client: add OverlayLayer and rendering logic for multiple overlay layers

This commit is contained in:
UniquePassive
2018-01-14 21:44:46 -05:00
committed by Adam
parent 95bc310bc1
commit b9eb86edf2
4 changed files with 91 additions and 14 deletions

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

@@ -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);
}
}