WorldMapPlugin: Cache icons, don't get icons on edt

This commit is contained in:
Lucwousin
2019-10-15 12:41:35 +02:00
parent 3b9a5df8b1
commit 535fccde53
3 changed files with 51 additions and 26 deletions

View File

@@ -25,8 +25,10 @@
*/ */
package net.runelite.client.plugins.worldmap; package net.runelite.client.plugins.worldmap;
import java.awt.image.BufferedImage;
import lombok.Getter; import lombok.Getter;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.client.util.ImageUtil;
@Getter @Getter
enum TeleportLocationData enum TeleportLocationData
@@ -188,6 +190,24 @@ enum TeleportLocationData
private final String tooltip; private final String tooltip;
private final WorldPoint location; private final WorldPoint location;
private final String iconPath; private final String iconPath;
private BufferedImage image;
BufferedImage getImage()
{
if (image == null)
{
try
{
image = ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, this.getIconPath());
}
catch (RuntimeException e)
{
return WorldMapPlugin.BLANK_ICON;
}
}
return image;
}
TeleportLocationData(TeleportType type, String destination, int magicLevel, WorldPoint location, String iconPath) TeleportLocationData(TeleportType type, String destination, int magicLevel, WorldPoint location, String iconPath)
{ {

View File

@@ -26,14 +26,12 @@
package net.runelite.client.plugins.worldmap; package net.runelite.client.plugins.worldmap;
import net.runelite.client.ui.overlay.worldmap.WorldMapPoint; import net.runelite.client.ui.overlay.worldmap.WorldMapPoint;
import net.runelite.client.util.ImageUtil;
class TeleportPoint extends WorldMapPoint class TeleportPoint extends WorldMapPoint
{ {
TeleportPoint(TeleportLocationData data) TeleportPoint(TeleportLocationData data)
{ {
super(data.getLocation(), WorldMapPlugin.BLANK_ICON); super(data.getLocation(), data.getImage());
setTooltip(data.getTooltip()); setTooltip(data.getTooltip());
setImage(ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, data.getIconPath()));
} }
} }

View File

@@ -29,6 +29,7 @@ import com.google.inject.Inject;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.ScheduledExecutorService;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Experience; import net.runelite.api.Experience;
import net.runelite.api.GameState; import net.runelite.api.GameState;
@@ -127,6 +128,9 @@ public class WorldMapPlugin extends Plugin
@Inject @Inject
private EventBus eventBus; private EventBus eventBus;
@Inject
private ScheduledExecutorService executor;
private int agilityLevel = 0; private int agilityLevel = 0;
private int woodcuttingLevel = 0; private int woodcuttingLevel = 0;
@@ -308,30 +312,33 @@ public class WorldMapPlugin extends Plugin
} }
worldMapPointManager.removeIf(TeleportPoint.class::isInstance); worldMapPointManager.removeIf(TeleportPoint.class::isInstance);
Arrays.stream(TeleportLocationData.values()) // This next part gets 142 icons from disk, and does so on the EDT (at first run)
.filter(data -> executor.submit(() ->
{ Arrays.stream(TeleportLocationData.values())
switch (data.getType()) .filter(data ->
{ {
case NORMAL_MAGIC: switch (data.getType())
return this.normalTeleportIcon; {
case ANCIENT_MAGICKS: case NORMAL_MAGIC:
return this.ancientTeleportIcon; return this.normalTeleportIcon;
case LUNAR_MAGIC: case ANCIENT_MAGICKS:
return this.lunarTeleportIcon; return this.ancientTeleportIcon;
case ARCEUUS_MAGIC: case LUNAR_MAGIC:
return this.arceuusTeleportIcon; return this.lunarTeleportIcon;
case JEWELLERY: case ARCEUUS_MAGIC:
return this.jewelleryTeleportIcon; return this.arceuusTeleportIcon;
case SCROLL: case JEWELLERY:
return this.scrollTeleportIcon; return this.jewelleryTeleportIcon;
case OTHER: case SCROLL:
return this.miscellaneousTeleportIcon; return this.scrollTeleportIcon;
default: case OTHER:
return false; return this.miscellaneousTeleportIcon;
} default:
}).map(TeleportPoint::new) return false;
.forEach(worldMapPointManager::add); }
}).map(TeleportPoint::new)
.forEach(worldMapPointManager::add)
);
} }
private void updateQuestStartPointIcons() private void updateQuestStartPointIcons()