Merge pull request #537 from runelite-extended/implingoverlay

Add impling overlay
This commit is contained in:
Tyler Bochard
2019-06-10 02:33:43 -04:00
committed by GitHub
3 changed files with 103 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
package net.runelite.client.plugins.implings;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.Map;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.components.table.TableAlignment;
import net.runelite.client.ui.overlay.components.table.TableComponent;
import net.runelite.client.ui.overlay.components.PanelComponent;
public class ImplingCounterOverlay extends Overlay
{
private final Client client;
private final ImplingsPlugin plugin;
private final ImplingsConfig config;
private final PanelComponent panelComponent = new PanelComponent();
@Inject
public ImplingCounterOverlay(Client client, ImplingsConfig config, ImplingsPlugin plugin)
{
this.client = client;
this.config = config;
this.plugin = plugin;
setPosition(OverlayPosition.TOP_LEFT);
}
@Override
public Dimension render(Graphics2D graphics)
{
if (!config.showCounter() || plugin.getImplings().isEmpty())
return null;
panelComponent.getChildren().clear();
TableComponent tableComponent = new TableComponent();
tableComponent.setColumnAlignments(TableAlignment.LEFT, TableAlignment.RIGHT);
for (Map.Entry<ImplingType, Integer> entry : plugin.getImplingCounterMap().entrySet())
{
if (plugin.showImplingType(entry.getKey()) && entry.getValue() != 0)
{
tableComponent.addRow(entry.getKey().getName(), entry.getValue().toString());
}
}
panelComponent.getChildren().add(tableComponent);
return panelComponent.render(graphics);
}
}

View File

@@ -320,4 +320,15 @@ public interface ImplingsConfig extends Config
{
return Color.WHITE;
}
@ConfigItem(
position = 26,
keyName = "showCounter",
name = "Show impling counter overlay",
description = "Shows how many of each impling there is nearby"
)
default boolean showCounter()
{
return false;
}
}

View File

@@ -30,11 +30,13 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.GameState;
import net.runelite.api.NPC;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
@@ -58,6 +60,9 @@ public class ImplingsPlugin extends Plugin
private static final int DYNAMIC_SPAWN_ECLECTIC = 1633;
private static final int DYNAMIC_SPAWN_BABY_ESSENCE = 1634;
@Getter
private Map<ImplingType, Integer> implingCounterMap = new HashMap<>();
@Getter(AccessLevel.PACKAGE)
private final List<NPC> implings = new ArrayList<>();
@@ -67,6 +72,10 @@ public class ImplingsPlugin extends Plugin
@Inject
private ImplingsOverlay overlay;
@Inject
private ImplingCounterOverlay implingCounterOverlay;
@Inject
private OverlayManager overlayManager;
@@ -91,6 +100,7 @@ public class ImplingsPlugin extends Plugin
overlayManager.add(overlay);
overlayManager.add(minimapOverlay);
overlayManager.add(implingCounterOverlay);
}
@Override
@@ -98,6 +108,27 @@ public class ImplingsPlugin extends Plugin
{
overlayManager.remove(overlay);
overlayManager.remove(minimapOverlay);
overlayManager.remove(implingCounterOverlay);
}
@Subscribe
public void onGameTick(GameTick event)
{
implingCounterMap.clear();
for (NPC npc : implings)
{
Impling impling = Impling.findImpling(npc.getId());
ImplingType type = impling.getImplingType();
if (implingCounterMap.containsKey(type))
{
implingCounterMap.put(type, implingCounterMap.get(type) + 1);
}
else
{
implingCounterMap.put(type, 1);
}
}
}
@Subscribe
@@ -118,6 +149,7 @@ public class ImplingsPlugin extends Plugin
if (event.getGameState() == GameState.LOGIN_SCREEN || event.getGameState() == GameState.HOPPING)
{
implings.clear();
implingCounterMap.clear();
}
}
@@ -131,6 +163,7 @@ public class ImplingsPlugin extends Plugin
NPC npc = npcDespawned.getNpc();
implings.remove(npc);
}
boolean showNpc(NPC npc)
@@ -183,7 +216,12 @@ public class ImplingsPlugin extends Plugin
return null;
}
switch (impling.getImplingType())
return typeToColor(impling.getImplingType());
}
Color typeToColor(ImplingType type)
{
switch (type)
{
case BABY: