Skip to content

Commit

Permalink
Update FishingSpot to use sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerthardy authored and Adam- committed Oct 19, 2017
1 parent 97f7bd0 commit 3afa41b
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package net.runelite.client.plugins.fishing;

import net.runelite.api.ItemID;

import java.util.HashMap;
import java.util.Map;
import static net.runelite.api.NpcID.FISHING_SPOT_1506;
Expand Down Expand Up @@ -58,40 +60,40 @@

public enum FishingSpot
{
SHRIMP("Shrimp, Anchovies", "shrimp",
SHRIMP("Shrimp, Anchovies", ItemID.RAW_SHRIMPS,
FISHING_SPOT_1518, FISHING_SPOT_1525, FISHING_SPOT_1528,
FISHING_SPOT_1530, FISHING_SPOT_1544, FISHING_SPOT_7155,
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_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
),
MONKFISH("Monkfish", "monkfish",
MONKFISH("Monkfish", ItemID.RAW_MONKFISH,
FISHING_SPOT_4316
),
SALMON("Salmon, Trout", "salmon",
SALMON("Salmon, Trout", ItemID.RAW_SALMON,
FISHING_SPOT_1506, FISHING_SPOT_1508, FISHING_SPOT_1515,
FISHING_SPOT_1526, FISHING_SPOT_1527
),
BARB_FISH("Sturgeon, Salmon, Trout", "barb",
BARB_FISH("Sturgeon, Salmon, Trout", ItemID.LEAPING_STURGEON,
FISHING_SPOT_1542
),
ANGLERFISH("Anglerfish", "anglerfish",
ANGLERFISH("Anglerfish", ItemID.RAW_ANGLERFISH,
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
);

public static final int FLYING_FISH = FISHING_SPOT_7734;
private static final Map<Integer, FishingSpot> fishingSpots = new HashMap<>();

private final String name;
private final String image;
private final int itemSpriteId;
private final int[] spots;

static
Expand All @@ -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.image = image;
this.itemSpriteId = itemSpriteId;
this.spots = spots;
}

Expand All @@ -119,9 +121,9 @@ public String getName()
return name;
}

public String getImage()
public int getItemSpriteId()
{
return image;
return itemSpriteId;
}

public int[] getIds()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.NPC;
import net.runelite.api.SpritePixels;
import net.runelite.api.queries.NPCQuery;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.overlay.Overlay;
Expand All @@ -49,8 +46,6 @@ class FishingSpotOverlay extends Overlay
{
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 RuneLite runelite = RuneLite.getRunelite();
Expand Down Expand Up @@ -86,10 +81,10 @@ public Dimension render(Graphics2D graphics)
Color color = npc.getId() == FishingSpot.FLYING_FISH ? Color.RED : Color.CYAN;
if (config.showIcons())
{
BufferedImage fishImage = getFishImage(spot);
if (fishImage != null)
SpritePixels fishSprite = getFishSprite(spot);
if (fishSprite != null)
{
OverlayUtil.renderActorOverlayImage(graphics, npc, fishImage, color.darker());
OverlayUtil.renderActorOverlaySprite(graphics, npc, fishSprite, color.darker());
}
}
else
Expand All @@ -102,28 +97,9 @@ public Dimension render(Graphics2D graphics)
return null;
}

private BufferedImage getFishImage(FishingSpot spot)
private SpritePixels getFishSprite(FishingSpot spot)
{
int fishIdx = spot.ordinal();
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;
return client.createItemSprite(spot.getItemSpriteId(), 5, 1, SpritePixels.DEFAULT_SHADOW_COLOR, 0, false);
}

public void updateConfig()
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 3afa41b

Please sign in to comment.