WorldMapPlugin: Cache icons, don't get icons on edt
This commit is contained in:
@@ -25,8 +25,10 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.worldmap;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
|
||||
@Getter
|
||||
enum TeleportLocationData
|
||||
@@ -188,6 +190,24 @@ enum TeleportLocationData
|
||||
private final String tooltip;
|
||||
private final WorldPoint location;
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -26,14 +26,12 @@
|
||||
package net.runelite.client.plugins.worldmap;
|
||||
|
||||
import net.runelite.client.ui.overlay.worldmap.WorldMapPoint;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
|
||||
class TeleportPoint extends WorldMapPoint
|
||||
{
|
||||
TeleportPoint(TeleportLocationData data)
|
||||
{
|
||||
super(data.getLocation(), WorldMapPlugin.BLANK_ICON);
|
||||
super(data.getLocation(), data.getImage());
|
||||
setTooltip(data.getTooltip());
|
||||
setImage(ImageUtil.getResourceStreamFromClass(WorldMapPlugin.class, data.getIconPath()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Experience;
|
||||
import net.runelite.api.GameState;
|
||||
@@ -127,6 +128,9 @@ public class WorldMapPlugin extends Plugin
|
||||
@Inject
|
||||
private EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
private int agilityLevel = 0;
|
||||
private int woodcuttingLevel = 0;
|
||||
|
||||
@@ -308,30 +312,33 @@ public class WorldMapPlugin extends Plugin
|
||||
}
|
||||
|
||||
worldMapPointManager.removeIf(TeleportPoint.class::isInstance);
|
||||
Arrays.stream(TeleportLocationData.values())
|
||||
.filter(data ->
|
||||
{
|
||||
switch (data.getType())
|
||||
// This next part gets 142 icons from disk, and does so on the EDT (at first run)
|
||||
executor.submit(() ->
|
||||
Arrays.stream(TeleportLocationData.values())
|
||||
.filter(data ->
|
||||
{
|
||||
case NORMAL_MAGIC:
|
||||
return this.normalTeleportIcon;
|
||||
case ANCIENT_MAGICKS:
|
||||
return this.ancientTeleportIcon;
|
||||
case LUNAR_MAGIC:
|
||||
return this.lunarTeleportIcon;
|
||||
case ARCEUUS_MAGIC:
|
||||
return this.arceuusTeleportIcon;
|
||||
case JEWELLERY:
|
||||
return this.jewelleryTeleportIcon;
|
||||
case SCROLL:
|
||||
return this.scrollTeleportIcon;
|
||||
case OTHER:
|
||||
return this.miscellaneousTeleportIcon;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}).map(TeleportPoint::new)
|
||||
.forEach(worldMapPointManager::add);
|
||||
switch (data.getType())
|
||||
{
|
||||
case NORMAL_MAGIC:
|
||||
return this.normalTeleportIcon;
|
||||
case ANCIENT_MAGICKS:
|
||||
return this.ancientTeleportIcon;
|
||||
case LUNAR_MAGIC:
|
||||
return this.lunarTeleportIcon;
|
||||
case ARCEUUS_MAGIC:
|
||||
return this.arceuusTeleportIcon;
|
||||
case JEWELLERY:
|
||||
return this.jewelleryTeleportIcon;
|
||||
case SCROLL:
|
||||
return this.scrollTeleportIcon;
|
||||
case OTHER:
|
||||
return this.miscellaneousTeleportIcon;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}).map(TeleportPoint::new)
|
||||
.forEach(worldMapPointManager::add)
|
||||
);
|
||||
}
|
||||
|
||||
private void updateQuestStartPointIcons()
|
||||
|
||||
Reference in New Issue
Block a user