Merge pull request #82 from RobinWeymans/imps-plugin

Implings plugin
This commit is contained in:
Adam
2017-06-16 09:30:23 -04:00
committed by GitHub
4 changed files with 430 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ import net.runelite.client.plugins.fpsinfo.FPS;
import net.runelite.client.plugins.grounditems.GroundItems;
import net.runelite.client.plugins.hiscore.Hiscore;
import net.runelite.client.plugins.idlenotifier.IdleNotifier;
import net.runelite.client.plugins.implings.Implings;
import net.runelite.client.plugins.mousehighlight.MouseHighlight;
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
import net.runelite.client.plugins.pestcontrol.PestControl;
@@ -81,6 +82,7 @@ public class PluginManager
plugins.add(new AccountPlugin());
plugins.add(new ConfigPlugin());
plugins.add(new GroundItems());
plugins.add(new Implings());
if (RuneLite.getOptions().has("developer-mode"))
{

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2017, Robin <robin.weymans@gmail.com>
* 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.Font;
import java.awt.GraphicsEnvironment;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.overlay.Overlay;
/**
*
* @author robin
*/
public class Implings extends Plugin
{
private final ImplingsConfig config = RuneLite.getRunelite().getConfigManager().getConfig(ImplingsConfig.class);
private final ImplingsOverlay overlay = new ImplingsOverlay(this);
private Font font;
@Override
protected void startUp() throws Exception
{
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
font = font.deriveFont(Font.BOLD, 16);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
}
@Override
protected void shutDown() throws Exception
{
}
public ImplingsConfig getConfig()
{
return config;
}
@Override
public Overlay getOverlay()
{
return overlay;
}
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2017, Robin <robin.weymans@gmail.com>
* 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 net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
/**
*
* @author robin
*/
@ConfigGroup(
keyName = "implings",
name = "Implings",
description = "Configuration for the implings plugin"
)
public interface ImplingsConfig
{
@ConfigItem(
keyName = "showbaby",
name = "Show Baby implings",
description = "Configures whether or not Baby impling tags are displayed"
)
default boolean showBaby()
{
return false;
}
@ConfigItem(
keyName = "showyoung",
name = "Show Young implings",
description = "Configures whether or not Young impling tags are displayed"
)
default boolean showYoung()
{
return false;
}
@ConfigItem(
keyName = "showgourmet",
name = "Show Gourmet implings",
description = "Configures whether or not Gourmet impling tags are displayed"
)
default boolean showGourmet()
{
return false;
}
@ConfigItem(
keyName = "showearth",
name = "Show Earth implings",
description = "Configures whether or not Earth impling tags are displayed"
)
default boolean showEarth()
{
return false;
}
@ConfigItem(
keyName = "showessence",
name = "Show Essence implings",
description = "Configures whether or not Essence impling tags are displayed"
)
default boolean showEssence()
{
return false;
}
@ConfigItem(
keyName = "showeclectic",
name = "Show Eclectic implings",
description = "Configures whether or not Eclectic impling tags are displayed"
)
default boolean showEclectic()
{
return false;
}
@ConfigItem(
keyName = "shownature",
name = "Show Nature implings",
description = "Configures whether or not Nature impling tags are displayed"
)
default boolean showNature()
{
return false;
}
@ConfigItem(
keyName = "showmagpie",
name = "Show Magpie implings",
description = "Configures whether or not Magpie impling tags are displayed"
)
default boolean showMagpie()
{
return false;
}
@ConfigItem(
keyName = "showninja",
name = "Show Ninja implings",
description = "Configures whether or not Ninja impling tags are displayed"
)
default boolean showNinja()
{
return false;
}
@ConfigItem(
keyName = "showdragon",
name = "Show Dragon implings",
description = "Configures whether or not Dragon impling tags are displayed"
)
default boolean showDragon()
{
return true;
}
@ConfigItem(
keyName = "showlucky",
name = "Show Lucky implings",
description = "Configures whether or not Lucky impling tags are displayed"
)
default boolean showLucky()
{
return true;
}
@ConfigItem(
keyName = "showspawn",
name = "Show Spawn locations",
description = "Configures whether or not spawn locations are displayed"
)
default boolean showSpawn()
{
return false;
}
}

View File

@@ -0,0 +1,195 @@
/*
* Copyright (c) 2017, Robin <robin.weymans@gmail.com>
* 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 com.google.common.base.Suppliers;
import com.google.common.primitives.Ints;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.GameState;
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.RuneLite;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
/**
*
* @author robin
*/
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 ImplingsConfig config;
private final Supplier<List<Integer>> ids = Suppliers.memoizeWithExpiration(this::checkConfig, 1, TimeUnit.SECONDS);
private final Client client = RuneLite.getClient();
public ImplingsOverlay(Implings plugin)
{
super(OverlayPosition.DYNAMIC);
this.config = plugin.getConfig();
}
@Override
public Dimension render(Graphics2D graphics)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return null;
}
NPCQuery implingQuery = new NPCQuery().idEquals(Ints.toArray(ids.get()));
NPC[] implings = client.runQuery(implingQuery);
for (NPC imp : implings)
{
//Spawns have the name "null", so they get changed to "Spawn"
String text = imp.getName().equals("null") ? "Spawn" : imp.getName();
drawImp(graphics, imp, text, Color.WHITE);
}
return null;
}
// I am aware this is ugly. As always, feedback is welcome
private List<Integer> checkConfig()
{
List<Integer> ids = new LinkedList<>();
if (config.showBaby())
{
ids.add(NpcID.BABY_IMPLING);
ids.add(NpcID.BABY_IMPLING_2);
}
if (config.showYoung())
{
ids.add(NpcID.YOUNG_IMPLING);
ids.add(NpcID.YOUNG_IMPLING_2);
}
if (config.showGourmet())
{
ids.add(NpcID.GOURMET_IMPLING);
ids.add(NpcID.GOURMET_IMPLING_2);
}
if (config.showEarth())
{
ids.add(NpcID.EARTH_IMPLING);
ids.add(NpcID.EARTH_IMPLING_2);
}
if (config.showEssence())
{
ids.add(NpcID.ESSENCE_IMPLING);
ids.add(NpcID.ESSENCE_IMPLING_2);
}
if (config.showEclectic())
{
ids.add(NpcID.ECLECTIC_IMPLING);
ids.add(NpcID.ECLECTIC_IMPLING_2);
}
if (config.showNature())
{
ids.add(NpcID.NATURE_IMPLING);
ids.add(NpcID.NATURE_IMPLING_2);
}
if (config.showMagpie())
{
ids.add(NpcID.MAGPIE_IMPLING);
ids.add(NpcID.MAGPIE_IMPLING_2);
}
if (config.showNinja())
{
ids.add(NpcID.NINJA_IMPLING);
ids.add(NpcID.NINJA_IMPLING_2);
}
if (config.showDragon())
{
ids.add(NpcID.DRAGON_IMPLING);
ids.add(NpcID.DRAGON_IMPLING_2);
}
if (config.showLucky())
{
ids.add(NpcID.LUCKY_IMPLING);
ids.add(NpcID.LUCKY_IMPLING_2);
}
if (config.showSpawn())
{
ids.add(STATIC_SPAWN);
ids.add(DYNAMIC_SPAWN);
}
return ids;
}
private void drawImp(Graphics2D graphics, Actor actor, String text, Color color)
{
Polygon poly = actor.getCanvasTilePoly();
if (poly != null)
{
graphics.setColor(color);
graphics.setStroke(new BasicStroke(2));
graphics.drawPolygon(poly);
graphics.setColor(new Color(0, 0, 0, 50));
graphics.fillPolygon(poly);
}
Point minimapLocation = actor.getMinimapLocation();
if (minimapLocation != null)
{
graphics.setColor(color);
graphics.fillOval(minimapLocation.getX(), minimapLocation.getY(), 5, 5);
graphics.setColor(Color.WHITE);
graphics.setStroke(new BasicStroke(1));
graphics.drawOval(minimapLocation.getX(), minimapLocation.getY(), 5, 5);
}
Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getModelHeight());
if (textLocation != null)
{
int x = textLocation.getX();
int y = textLocation.getY();
graphics.setColor(Color.BLACK);
graphics.drawString(text, x + 1, y + 1);
graphics.setColor(color);
graphics.drawString(text, x, y);
}
}
}