corp: use npc overlay service

This commit is contained in:
Adam
2021-09-04 15:18:34 -04:00
parent c52667a5cc
commit 4a9b650249
3 changed files with 27 additions and 71 deletions

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) 2018, 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.client.plugins.corp;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import javax.inject.Inject;
import net.runelite.api.NPC;
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;
class CoreOverlay extends Overlay
{
private final CorpPlugin corpPlugin;
private final CorpConfig config;
@Inject
private CoreOverlay(CorpPlugin corpPlugin, CorpConfig corpConfig)
{
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
this.corpPlugin = corpPlugin;
this.config = corpConfig;
}
@Override
public Dimension render(Graphics2D graphics)
{
NPC core = corpPlugin.getCore();
if (core != null && config.markDarkCore())
{
Polygon canvasTilePoly = core.getCanvasTilePoly();
if (canvasTilePoly != null)
{
OverlayUtil.renderPolygon(graphics, canvasTilePoly, Color.RED.brighter());
}
}
return null;
}
}

View File

@@ -28,9 +28,11 @@ import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("corp")
@ConfigGroup(CorpConfig.GROUP)
public interface CorpConfig extends Config
{
String GROUP = "corp";
@ConfigItem(
keyName = "showDamage",
name = "Show damage overlay",

View File

@@ -25,8 +25,10 @@
package net.runelite.client.plugins.corp;
import com.google.inject.Provides;
import java.awt.Color;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
@@ -50,6 +52,8 @@ import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.QueuedMessage;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.npcoverlay.HighlightedNpc;
import net.runelite.client.game.npcoverlay.NpcOverlayService;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
@@ -89,7 +93,24 @@ public class CorpPlugin extends Plugin
private CorpDamageOverlay corpOverlay;
@Inject
private CoreOverlay coreOverlay;
private CorpConfig config;
@Inject
private NpcOverlayService npcOverlayService;
private final Function<NPC, HighlightedNpc> isCore = (npc) ->
{
if (npc == core)
{
return HighlightedNpc.builder()
.npc(npc)
.tile(true)
.highlightColor(Color.RED.brighter())
.render(n -> config.markDarkCore())
.build();
}
return null;
};
@Provides
CorpConfig getConfig(ConfigManager configManager)
@@ -100,15 +121,15 @@ public class CorpPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
npcOverlayService.registerHighlighter(isCore);
overlayManager.add(corpOverlay);
overlayManager.add(coreOverlay);
}
@Override
protected void shutDown() throws Exception
{
npcOverlayService.unregisterHighlighter(isCore);
overlayManager.remove(corpOverlay);
overlayManager.remove(coreOverlay);
corp = core = null;
yourDamage = 0;