Merge pull request #184 from tylerthardy/itemSprites
Add method to draw item sprites on screen
@@ -56,5 +56,7 @@ public interface Actor extends Renderable
|
|||||||
|
|
||||||
Point getCanvasImageLocation(Graphics2D graphics, BufferedImage image, int zOffset);
|
Point getCanvasImageLocation(Graphics2D graphics, BufferedImage image, int zOffset);
|
||||||
|
|
||||||
|
Point getCanvasSpriteLocation(Graphics2D graphics, SpritePixels sprite, int zOffset);
|
||||||
|
|
||||||
Point getMinimapLocation();
|
Point getMinimapLocation();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ public interface Client
|
|||||||
|
|
||||||
ItemComposition getItemDefinition(int id);
|
ItemComposition getItemDefinition(int id);
|
||||||
|
|
||||||
|
SpritePixels createItemSprite(int itemId, int quantity, int border, int shadowColor, int stackable, boolean noted);
|
||||||
|
|
||||||
int getBaseX();
|
int getBaseX();
|
||||||
|
|
||||||
int getBaseY();
|
int getBaseY();
|
||||||
|
|||||||
@@ -307,4 +307,32 @@ public class Perspective
|
|||||||
return new Point(xOffset, yOffset);
|
return new Point(xOffset, yOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates sprite position and centers depending on sprite size.
|
||||||
|
*
|
||||||
|
* @param client
|
||||||
|
* @param graphics
|
||||||
|
* @param localLocation local location of the tile
|
||||||
|
* @param sprite SpritePixel for size measurement
|
||||||
|
* @param zOffset offset from ground plane
|
||||||
|
* @return a {@link Point} on screen corresponding to the given
|
||||||
|
* localLocation.
|
||||||
|
*/
|
||||||
|
public static Point getCanvasSpriteLocation(Client client, Graphics2D graphics, Point localLocation, SpritePixels sprite, int zOffset)
|
||||||
|
{
|
||||||
|
int plane = client.getPlane();
|
||||||
|
|
||||||
|
Point p = Perspective.worldToCanvas(client, localLocation.getX(), localLocation.getY(), plane, zOffset);
|
||||||
|
|
||||||
|
if (p == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int xOffset = p.getX() - sprite.getWidth() / 2;
|
||||||
|
int yOffset = p.getY() - sprite.getHeight() / 2;
|
||||||
|
|
||||||
|
return new Point(xOffset, yOffset);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Tyler <https://github.com/tylerthardy>
|
||||||
|
* 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 SpritePixels
|
||||||
|
{
|
||||||
|
int DEFAULT_SHADOW_COLOR = 3153952;
|
||||||
|
|
||||||
|
void drawAt(int x, int y);
|
||||||
|
|
||||||
|
int getWidth();
|
||||||
|
|
||||||
|
int getHeight();
|
||||||
|
}
|
||||||
@@ -24,6 +24,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.fishing;
|
package net.runelite.client.plugins.fishing;
|
||||||
|
|
||||||
|
import net.runelite.api.ItemID;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import static net.runelite.api.NpcID.FISHING_SPOT_1506;
|
import static net.runelite.api.NpcID.FISHING_SPOT_1506;
|
||||||
@@ -58,32 +60,32 @@ import static net.runelite.api.NpcID.FISHING_SPOT_7734;
|
|||||||
|
|
||||||
public enum FishingSpot
|
public enum FishingSpot
|
||||||
{
|
{
|
||||||
SHRIMP("Shrimp, Anchovies", "shrimp",
|
SHRIMP("Shrimp, Anchovies", ItemID.RAW_SHRIMPS,
|
||||||
FISHING_SPOT_1518, FISHING_SPOT_1525, FISHING_SPOT_1528,
|
FISHING_SPOT_1518, FISHING_SPOT_1525, FISHING_SPOT_1528,
|
||||||
FISHING_SPOT_1530, FISHING_SPOT_1544, FISHING_SPOT_7155,
|
FISHING_SPOT_1530, FISHING_SPOT_1544, FISHING_SPOT_7155,
|
||||||
FISHING_SPOT_7469
|
FISHING_SPOT_7469
|
||||||
),
|
),
|
||||||
LOBSTER("Lobster, Swordfish, Tuna", "lobster",
|
LOBSTER("Lobster, Swordfish, Tuna", ItemID.RAW_LOBSTER,
|
||||||
FISHING_SPOT_1510, FISHING_SPOT_1519, FISHING_SPOT_1521,
|
FISHING_SPOT_1510, FISHING_SPOT_1519, FISHING_SPOT_1521,
|
||||||
FISHING_SPOT_1522, FISHING_SPOT_7199, FISHING_SPOT_7470
|
FISHING_SPOT_1522, FISHING_SPOT_7199, FISHING_SPOT_7470
|
||||||
),
|
),
|
||||||
SHARK("Shark, Bass", "shark",
|
SHARK("Shark, Bass", ItemID.RAW_SHARK,
|
||||||
FISHING_SPOT_1511, FISHING_SPOT_1520, FISHING_SPOT_7200
|
FISHING_SPOT_1511, FISHING_SPOT_1520, FISHING_SPOT_7200
|
||||||
),
|
),
|
||||||
MONKFISH("Monkfish", "monkfish",
|
MONKFISH("Monkfish", ItemID.RAW_MONKFISH,
|
||||||
FISHING_SPOT_4316
|
FISHING_SPOT_4316
|
||||||
),
|
),
|
||||||
SALMON("Salmon, Trout", "salmon",
|
SALMON("Salmon, Trout", ItemID.RAW_SALMON,
|
||||||
FISHING_SPOT_1506, FISHING_SPOT_1508, FISHING_SPOT_1515,
|
FISHING_SPOT_1506, FISHING_SPOT_1508, FISHING_SPOT_1515,
|
||||||
FISHING_SPOT_1526, FISHING_SPOT_1527
|
FISHING_SPOT_1526, FISHING_SPOT_1527
|
||||||
),
|
),
|
||||||
BARB_FISH("Sturgeon, Salmon, Trout", "barb",
|
BARB_FISH("Sturgeon, Salmon, Trout", ItemID.LEAPING_STURGEON,
|
||||||
FISHING_SPOT_1542
|
FISHING_SPOT_1542
|
||||||
),
|
),
|
||||||
ANGLERFISH("Anglerfish", "anglerfish",
|
ANGLERFISH("Anglerfish", ItemID.RAW_ANGLERFISH,
|
||||||
FISHING_SPOT_6825
|
FISHING_SPOT_6825
|
||||||
),
|
),
|
||||||
MINNOW("Minnow", "minnow",
|
MINNOW("Minnow", ItemID.MINNOW,
|
||||||
FISHING_SPOT_7730, FISHING_SPOT_7731, FISHING_SPOT_7732, FISHING_SPOT_7733, FISHING_SPOT_7734
|
FISHING_SPOT_7730, FISHING_SPOT_7731, FISHING_SPOT_7732, FISHING_SPOT_7733, FISHING_SPOT_7734
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ public enum FishingSpot
|
|||||||
private static final Map<Integer, FishingSpot> fishingSpots = new HashMap<>();
|
private static final Map<Integer, FishingSpot> fishingSpots = new HashMap<>();
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String image;
|
private final int itemSpriteId;
|
||||||
private final int[] spots;
|
private final int[] spots;
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -107,10 +109,10 @@ public enum FishingSpot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FishingSpot(String spot, String image, int... spots)
|
FishingSpot(String spot, int itemSpriteId, int... spots)
|
||||||
{
|
{
|
||||||
this.name = spot;
|
this.name = spot;
|
||||||
this.image = image;
|
this.itemSpriteId = itemSpriteId;
|
||||||
this.spots = spots;
|
this.spots = spots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,9 +121,9 @@ public enum FishingSpot
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImage()
|
public int getItemSpriteId()
|
||||||
{
|
{
|
||||||
return image;
|
return itemSpriteId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getIds()
|
public int[] getIds()
|
||||||
|
|||||||
@@ -28,15 +28,12 @@ import com.google.common.primitives.Ints;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.SpritePixels;
|
||||||
import net.runelite.api.queries.NPCQuery;
|
import net.runelite.api.queries.NPCQuery;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
@@ -49,8 +46,6 @@ class FishingSpotOverlay extends Overlay
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(FishingSpotOverlay.class);
|
private static final Logger logger = LoggerFactory.getLogger(FishingSpotOverlay.class);
|
||||||
|
|
||||||
private final BufferedImage[] imgCache = new BufferedImage[FishingSpot.values().length];
|
|
||||||
|
|
||||||
private final List<Integer> ids = new ArrayList<>();
|
private final List<Integer> ids = new ArrayList<>();
|
||||||
|
|
||||||
private final RuneLite runelite = RuneLite.getRunelite();
|
private final RuneLite runelite = RuneLite.getRunelite();
|
||||||
@@ -86,10 +81,10 @@ class FishingSpotOverlay extends Overlay
|
|||||||
Color color = npc.getId() == FishingSpot.FLYING_FISH ? Color.RED : Color.CYAN;
|
Color color = npc.getId() == FishingSpot.FLYING_FISH ? Color.RED : Color.CYAN;
|
||||||
if (config.showIcons())
|
if (config.showIcons())
|
||||||
{
|
{
|
||||||
BufferedImage fishImage = getFishImage(spot);
|
SpritePixels fishSprite = getFishSprite(spot);
|
||||||
if (fishImage != null)
|
if (fishSprite != null)
|
||||||
{
|
{
|
||||||
OverlayUtil.renderActorOverlayImage(graphics, npc, fishImage, color.darker());
|
OverlayUtil.renderActorOverlaySprite(graphics, npc, fishSprite, color.darker());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -102,28 +97,9 @@ class FishingSpotOverlay extends Overlay
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage getFishImage(FishingSpot spot)
|
private SpritePixels getFishSprite(FishingSpot spot)
|
||||||
{
|
{
|
||||||
int fishIdx = spot.ordinal();
|
return client.createItemSprite(spot.getItemSpriteId(), 5, 1, SpritePixels.DEFAULT_SHADOW_COLOR, 0, false);
|
||||||
BufferedImage fishImage = null;
|
|
||||||
|
|
||||||
if (imgCache[fishIdx] != null)
|
|
||||||
{
|
|
||||||
return imgCache[fishIdx];
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
InputStream in = FishingSpotOverlay.class.getResourceAsStream(spot.getImage() + ".png");
|
|
||||||
fishImage = ImageIO.read(in);
|
|
||||||
imgCache[fishIdx] = fishImage;
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
logger.warn("Error Loading fish icon", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fishImage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateConfig()
|
public void updateConfig()
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import java.awt.image.BufferedImage;
|
|||||||
|
|
||||||
import net.runelite.api.Actor;
|
import net.runelite.api.Actor;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
|
import net.runelite.api.SpritePixels;
|
||||||
import net.runelite.api.TileObject;
|
import net.runelite.api.TileObject;
|
||||||
|
|
||||||
|
|
||||||
@@ -78,6 +79,14 @@ public class OverlayUtil
|
|||||||
graphics.drawImage(image, x, y, null);
|
graphics.drawImage(image, x, y, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void renderSpriteLocation(Graphics2D graphics, Point imgLoc, SpritePixels sprite)
|
||||||
|
{
|
||||||
|
int x = imgLoc.getX();
|
||||||
|
int y = imgLoc.getY();
|
||||||
|
|
||||||
|
sprite.drawAt(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
public static void renderActorOverlay(Graphics2D graphics, Actor actor, String text, Color color)
|
public static void renderActorOverlay(Graphics2D graphics, Actor actor, String text, Color color)
|
||||||
{
|
{
|
||||||
Polygon poly = actor.getCanvasTilePoly();
|
Polygon poly = actor.getCanvasTilePoly();
|
||||||
@@ -120,6 +129,27 @@ public class OverlayUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void renderActorOverlaySprite(Graphics2D graphics, Actor actor, SpritePixels sprite, Color color)
|
||||||
|
{
|
||||||
|
Polygon poly = actor.getCanvasTilePoly();
|
||||||
|
if (poly != null)
|
||||||
|
{
|
||||||
|
renderPolygon(graphics, poly, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
Point minimapLocation = actor.getMinimapLocation();
|
||||||
|
if (minimapLocation != null)
|
||||||
|
{
|
||||||
|
renderMinimapLocation(graphics, minimapLocation, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
Point imageLocation = actor.getCanvasSpriteLocation(graphics, sprite, actor.getModelHeight());
|
||||||
|
if (imageLocation != null)
|
||||||
|
{
|
||||||
|
renderSpriteLocation(graphics, imageLocation, sprite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void renderTileOverlay(Graphics2D graphics, TileObject tileObject, String text, Color color)
|
public static void renderTileOverlay(Graphics2D graphics, TileObject tileObject, String text, Color color)
|
||||||
{
|
{
|
||||||
Polygon poly = tileObject.getCanvasTilePoly();
|
Polygon poly = tileObject.getCanvasTilePoly();
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 568 B |
|
Before Width: | Height: | Size: 729 B |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 685 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
@@ -32,6 +32,7 @@ import net.runelite.api.NPC;
|
|||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
|
import net.runelite.api.SpritePixels;
|
||||||
import net.runelite.api.mixins.Inject;
|
import net.runelite.api.mixins.Inject;
|
||||||
import net.runelite.api.mixins.Mixin;
|
import net.runelite.api.mixins.Mixin;
|
||||||
import net.runelite.api.mixins.Shadow;
|
import net.runelite.api.mixins.Shadow;
|
||||||
@@ -143,6 +144,13 @@ public abstract class RSActorMixin implements RSActor
|
|||||||
return Perspective.getCanvasImageLocation(client, graphics, getLocalLocation(), image, zOffset);
|
return Perspective.getCanvasImageLocation(client, graphics, getLocalLocation(), image, zOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public Point getCanvasSpriteLocation(Graphics2D graphics, SpritePixels sprite, int zOffset)
|
||||||
|
{
|
||||||
|
return Perspective.getCanvasSpriteLocation(client, graphics, getLocalLocation(), sprite, zOffset);
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public Point getMinimapLocation()
|
public Point getMinimapLocation()
|
||||||
|
|||||||
@@ -230,6 +230,10 @@ public interface RSClient extends RSGameEngine, Client
|
|||||||
@Override
|
@Override
|
||||||
RSItemComposition getItemDefinition(int itemId);
|
RSItemComposition getItemDefinition(int itemId);
|
||||||
|
|
||||||
|
@Import("createSprite")
|
||||||
|
@Override
|
||||||
|
RSSpritePixels createItemSprite(int itemId, int quantity, int thickness, int borderColor, int stackable, boolean noted);
|
||||||
|
|
||||||
@Import("componentTable")
|
@Import("componentTable")
|
||||||
@Override
|
@Override
|
||||||
RSHashTable getComponentTable();
|
RSHashTable getComponentTable();
|
||||||
|
|||||||
@@ -24,6 +24,20 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
public interface RSSpritePixels
|
import net.runelite.api.SpritePixels;
|
||||||
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
|
public interface RSSpritePixels extends SpritePixels
|
||||||
{
|
{
|
||||||
|
@Import("drawAt")
|
||||||
|
@Override
|
||||||
|
void drawAt(int x, int y);
|
||||||
|
|
||||||
|
@Import("height")
|
||||||
|
@Override
|
||||||
|
int getHeight();
|
||||||
|
|
||||||
|
@Import("width")
|
||||||
|
@Override
|
||||||
|
int getWidth();
|
||||||
}
|
}
|
||||||
|
|||||||