Add impling overlay
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ 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;
|
||||
@@ -58,6 +59,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 +71,10 @@ public class ImplingsPlugin extends Plugin
|
||||
@Inject
|
||||
private ImplingsOverlay overlay;
|
||||
|
||||
@Inject
|
||||
private ImplingCounterOverlay implingCounterOverlay;
|
||||
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@@ -91,6 +99,7 @@ public class ImplingsPlugin extends Plugin
|
||||
|
||||
overlayManager.add(overlay);
|
||||
overlayManager.add(minimapOverlay);
|
||||
overlayManager.add(implingCounterOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,6 +107,7 @@ public class ImplingsPlugin extends Plugin
|
||||
{
|
||||
overlayManager.remove(overlay);
|
||||
overlayManager.remove(minimapOverlay);
|
||||
overlayManager.remove(implingCounterOverlay);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -109,6 +119,16 @@ public class ImplingsPlugin extends Plugin
|
||||
if (impling != null)
|
||||
{
|
||||
implings.add(npc);
|
||||
|
||||
ImplingType type = impling.getImplingType();
|
||||
if (implingCounterMap.containsKey(type))
|
||||
{
|
||||
implingCounterMap.put(type, implingCounterMap.get(type) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
implingCounterMap.put(type, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +138,7 @@ public class ImplingsPlugin extends Plugin
|
||||
if (event.getGameState() == GameState.LOGIN_SCREEN || event.getGameState() == GameState.HOPPING)
|
||||
{
|
||||
implings.clear();
|
||||
implingCounterMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +152,9 @@ public class ImplingsPlugin extends Plugin
|
||||
|
||||
NPC npc = npcDespawned.getNpc();
|
||||
implings.remove(npc);
|
||||
|
||||
Impling impling = Impling.findImpling(npc.getId());
|
||||
if (impling != null) implingCounterMap.put(impling.getImplingType(), implingCounterMap.get(impling.getImplingType()) - 1);
|
||||
}
|
||||
|
||||
boolean showNpc(NPC npc)
|
||||
@@ -183,7 +207,12 @@ public class ImplingsPlugin extends Plugin
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (impling.getImplingType())
|
||||
return typeToColor(impling.getImplingType());
|
||||
}
|
||||
|
||||
Color typeToColor(ImplingType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
||||
case BABY:
|
||||
|
||||
Reference in New Issue
Block a user