From 3d5e0b82b09497ab67fe09fc595eda6f6de4847f Mon Sep 17 00:00:00 2001 From: Seth Date: Sat, 31 Mar 2018 17:38:50 -0500 Subject: [PATCH] impling plugin: Move minimap overlay into it's own overlay to render above minimap on resizable, the overlay must be rendered above widgets --- .../implings/ImplingMinimapOverlay.java | 69 +++++++++++ .../plugins/implings/ImplingsOverlay.java | 112 +++-------------- .../plugins/implings/ImplingsPlugin.java | 113 +++++++++++++++++- 3 files changed, 194 insertions(+), 100 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingMinimapOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingMinimapOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingMinimapOverlay.java new file mode 100644 index 0000000000..415209ec91 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingMinimapOverlay.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, Seth + * 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.implings; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.NPC; +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.OverlayUtil; + +public class ImplingMinimapOverlay extends Overlay +{ + private final ImplingsPlugin plugin; + + @Inject + private ImplingMinimapOverlay(ImplingsPlugin plugin) + { + setPosition(OverlayPosition.DYNAMIC); + setLayer(OverlayLayer.ABOVE_WIDGETS); + this.plugin = plugin; + } + + @Override + public Dimension render(Graphics2D graphics) + { + NPC[] imps = plugin.getImplings(); + if (imps == null) + { + return null; + } + + for (NPC imp : imps) + { + Point minimapLocation = imp.getMinimapLocation(); + if (minimapLocation != null) + { + OverlayUtil.renderMinimapLocation(graphics, minimapLocation, plugin.getIds().get(imp.getId())); + } + } + + return null; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java index f52fe4f433..b91aa7cee2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java @@ -24,25 +24,18 @@ */ package net.runelite.client.plugins.implings; -import com.google.common.primitives.Ints; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Polygon; -import java.util.HashMap; -import java.util.Map; import javax.inject.Inject; -import lombok.Getter; import net.runelite.api.Actor; import net.runelite.api.NPC; -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.ui.overlay.OverlayUtil; -import net.runelite.client.util.QueryRunner; /** * @@ -50,107 +43,40 @@ import net.runelite.client.util.QueryRunner; */ public class ImplingsOverlay extends Overlay { - - // Impling spawns in PuroPuro. Not in NpcID. - private static final int STATIC_SPAWN = 1618; - private static final int DYNAMIC_SPAWN = 1633; - - private final QueryRunner queryRunner; - private final ImplingsConfig config; - - @Getter - private final Map ids = new HashMap<>(); + private final ImplingsPlugin plugin; @Inject - public ImplingsOverlay(QueryRunner queryRunner, ImplingsConfig config) + private ImplingsOverlay(ImplingsPlugin plugin) { setPosition(OverlayPosition.DYNAMIC); setLayer(OverlayLayer.ABOVE_SCENE); - this.queryRunner = queryRunner; - this.config = config; + this.plugin = plugin; } @Override public Dimension render(Graphics2D graphics) { - NPCQuery implingQuery = new NPCQuery().idEquals(Ints.toArray(ids.keySet())); - NPC[] implings = queryRunner.runQuery(implingQuery); - for (NPC imp : implings) + NPC[] imps = plugin.getImplings(); + if (imps == null) { + return null; + } + + for (NPC imp : imps) + { + if (imp == null || imp.getName() == null) + { + continue; + } + //Spawns have the name "null", so they get changed to "Spawn" String text = imp.getName().equals("null") ? "Spawn" : imp.getName(); - drawImp(graphics, imp, text, ids.get(imp.getId())); + drawImp(graphics, imp, text, plugin.getIds().get(imp.getId())); } return null; } - // I am aware this is ugly. As always, feedback is welcome - public void updateConfig() - { - ids.clear(); - if (config.showBaby()) - { - ids.put(NpcID.BABY_IMPLING, config.getBabyColor()); - ids.put(NpcID.BABY_IMPLING_1645, config.getBabyColor()); - } - if (config.showYoung()) - { - ids.put(NpcID.YOUNG_IMPLING, config.getYoungColor()); - ids.put(NpcID.YOUNG_IMPLING_1646, config.getYoungColor()); - } - if (config.showGourmet()) - { - ids.put(NpcID.GOURMET_IMPLING, config.getGourmetColor()); - ids.put(NpcID.GOURMET_IMPLING_1647, config.getGourmetColor()); - } - if (config.showEarth()) - { - ids.put(NpcID.EARTH_IMPLING, config.getEarthColor()); - ids.put(NpcID.EARTH_IMPLING_1648, config.getEarthColor()); - } - if (config.showEssence()) - { - ids.put(NpcID.ESSENCE_IMPLING, config.getEssenceColor()); - ids.put(NpcID.ESSENCE_IMPLING_1649, config.getEssenceColor()); - } - if (config.showEclectic()) - { - ids.put(NpcID.ECLECTIC_IMPLING, config.getEclecticColor()); - ids.put(NpcID.ECLECTIC_IMPLING_1650, config.getEclecticColor()); - } - if (config.showNature()) - { - ids.put(NpcID.NATURE_IMPLING, config.getNatureColor()); - ids.put(NpcID.NATURE_IMPLING_1651, config.getNatureColor()); - } - if (config.showMagpie()) - { - ids.put(NpcID.MAGPIE_IMPLING, config.getMapgieColor()); - ids.put(NpcID.MAGPIE_IMPLING_1652, config.getMapgieColor()); - } - if (config.showNinja()) - { - ids.put(NpcID.NINJA_IMPLING, config.getNinjaColor()); - ids.put(NpcID.NINJA_IMPLING_1653, config.getNinjaColor()); - } - if (config.showDragon()) - { - ids.put(NpcID.DRAGON_IMPLING, config.getDragonColor()); - ids.put(NpcID.DRAGON_IMPLING_1654, config.getDragonColor()); - } - if (config.showLucky()) - { - ids.put(NpcID.LUCKY_IMPLING, config.getLuckyColor()); - ids.put(NpcID.LUCKY_IMPLING_7302, config.getLuckyColor()); - } - if (config.showSpawn()) - { - ids.put(STATIC_SPAWN, config.getSpawnColor()); - ids.put(DYNAMIC_SPAWN, config.getSpawnColor()); - } - } - private void drawImp(Graphics2D graphics, Actor actor, String text, Color color) { Polygon poly = actor.getCanvasTilePoly(); @@ -159,12 +85,6 @@ public class ImplingsOverlay extends Overlay OverlayUtil.renderPolygon(graphics, poly, color); } - Point minimapLocation = actor.getMinimapLocation(); - if (minimapLocation != null) - { - OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color); - } - Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getLogicalHeight()); if (textLocation != null) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java index 52c29b84ed..b95a4525fe 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java @@ -25,13 +25,26 @@ package net.runelite.client.plugins.implings; import com.google.common.eventbus.Subscribe; +import com.google.common.primitives.Ints; import com.google.inject.Provides; +import java.awt.Color; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import javax.inject.Inject; +import lombok.AccessLevel; +import lombok.Getter; +import net.runelite.api.NPC; +import net.runelite.api.NpcID; import net.runelite.api.events.ConfigChanged; +import net.runelite.api.events.GameTick; +import net.runelite.api.queries.NPCQuery; import net.runelite.client.config.ConfigManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.util.QueryRunner; /** * @@ -42,9 +55,28 @@ import net.runelite.client.ui.overlay.Overlay; ) public class ImplingsPlugin extends Plugin { + // Impling spawns in PuroPuro. Not in NpcID. + private static final int STATIC_SPAWN = 1618; + private static final int DYNAMIC_SPAWN = 1633; + + @Getter(AccessLevel.PACKAGE) + private NPC[] implings; + + @Getter(AccessLevel.PACKAGE) + private final Map ids = new HashMap<>(); + @Inject private ImplingsOverlay overlay; + @Inject + private ImplingMinimapOverlay minimapOverlay; + + @Inject + private ImplingsConfig config; + + @Inject + private QueryRunner queryRunner; + @Provides ImplingsConfig getConfig(ConfigManager configManager) { @@ -55,19 +87,92 @@ public class ImplingsPlugin extends Plugin protected void startUp() throws Exception { // Initialize overlay config - overlay.updateConfig(); + updateConfig(); } @Override - public Overlay getOverlay() + public Collection getOverlays() { - return overlay; + return Arrays.asList(overlay, minimapOverlay); } @Subscribe public void updateConfig(ConfigChanged event) { - overlay.updateConfig(); + updateConfig(); + } + + @Subscribe + public void onGameTick(GameTick event) + { + NPCQuery implingQuery = new NPCQuery() + .idEquals(Ints.toArray(ids.keySet())); + implings = queryRunner.runQuery(implingQuery); + } + + public void updateConfig() + { + ids.clear(); + if (config.showBaby()) + { + ids.put(NpcID.BABY_IMPLING, config.getBabyColor()); + ids.put(NpcID.BABY_IMPLING_1645, config.getBabyColor()); + } + if (config.showYoung()) + { + ids.put(NpcID.YOUNG_IMPLING, config.getYoungColor()); + ids.put(NpcID.YOUNG_IMPLING_1646, config.getYoungColor()); + } + if (config.showGourmet()) + { + ids.put(NpcID.GOURMET_IMPLING, config.getGourmetColor()); + ids.put(NpcID.GOURMET_IMPLING_1647, config.getGourmetColor()); + } + if (config.showEarth()) + { + ids.put(NpcID.EARTH_IMPLING, config.getEarthColor()); + ids.put(NpcID.EARTH_IMPLING_1648, config.getEarthColor()); + } + if (config.showEssence()) + { + ids.put(NpcID.ESSENCE_IMPLING, config.getEssenceColor()); + ids.put(NpcID.ESSENCE_IMPLING_1649, config.getEssenceColor()); + } + if (config.showEclectic()) + { + ids.put(NpcID.ECLECTIC_IMPLING, config.getEclecticColor()); + ids.put(NpcID.ECLECTIC_IMPLING_1650, config.getEclecticColor()); + } + if (config.showNature()) + { + ids.put(NpcID.NATURE_IMPLING, config.getNatureColor()); + ids.put(NpcID.NATURE_IMPLING_1651, config.getNatureColor()); + } + if (config.showMagpie()) + { + ids.put(NpcID.MAGPIE_IMPLING, config.getMapgieColor()); + ids.put(NpcID.MAGPIE_IMPLING_1652, config.getMapgieColor()); + } + if (config.showNinja()) + { + ids.put(NpcID.NINJA_IMPLING, config.getNinjaColor()); + ids.put(NpcID.NINJA_IMPLING_1653, config.getNinjaColor()); + } + if (config.showDragon()) + { + ids.put(NpcID.DRAGON_IMPLING, config.getDragonColor()); + ids.put(NpcID.DRAGON_IMPLING_1654, config.getDragonColor()); + } + if (config.showLucky()) + { + ids.put(NpcID.LUCKY_IMPLING, config.getLuckyColor()); + ids.put(NpcID.LUCKY_IMPLING_7302, config.getLuckyColor()); + } + if (config.showSpawn()) + { + ids.put(STATIC_SPAWN, config.getSpawnColor()); + ids.put(DYNAMIC_SPAWN, config.getSpawnColor()); + } } }