fixes #696 and adds the intended functionality

some slight cleanup as well
This commit is contained in:
gazivodag
2019-06-23 07:57:00 -04:00
parent f8ba2de7a1
commit 7b6e47897b
3 changed files with 101 additions and 163 deletions

View File

@@ -35,10 +35,10 @@ import net.runelite.client.config.Stub;
public interface PileIndicatorsConfig extends Config public interface PileIndicatorsConfig extends Config
{ {
@ConfigItem( @ConfigItem(
keyName = "playerPilesStub", keyName = "playerPilesStub",
name = "Player Piles", name = "Player Piles",
description = "", description = "",
position = 0 position = 0
) )
default Stub playerPilesStub() default Stub playerPilesStub()
{ {
@@ -46,11 +46,11 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 1, position = 1,
keyName = "enablePlayers", keyName = "enablePlayers",
name = "Enable Player Piling", name = "Enable Player Piling",
description = "Enable the option to highlight players when they pile.", description = "Enable the option to highlight players when they pile.",
parent = "playerPilesStub" parent = "playerPilesStub"
) )
default boolean enablePlayers() default boolean enablePlayers()
{ {
@@ -58,11 +58,11 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 2, position = 2,
keyName = "wildyOnlyPlayer", keyName = "wildyOnlyPlayer",
name = "Wilderness Only", name = "Wilderness Only",
description = "Show player piling only when in the Wilderness.", description = "Show player piling only when in the Wilderness.",
parent = "playerPilesStub" parent = "playerPilesStub"
) )
default boolean wildyOnlyPlayer() default boolean wildyOnlyPlayer()
{ {
@@ -70,11 +70,11 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 3, position = 3,
keyName = "playerPileColor", keyName = "playerPileColor",
name = "Player Pile Color", name = "Player Pile Color",
description = "Color used for player piles.", description = "Color used for player piles.",
parent = "playerPilesStub" parent = "playerPilesStub"
) )
default Color playerPileColor() default Color playerPileColor()
{ {
@@ -82,10 +82,10 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "npcPilesStub", keyName = "npcPilesStub",
name = "NPC Piles", name = "NPC Piles",
description = "", description = "",
position = 4 position = 4
) )
default Stub npcPilesStub() default Stub npcPilesStub()
{ {
@@ -93,11 +93,11 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 5, position = 5,
keyName = "enableNPCS", keyName = "enableNPCS",
name = "Enable NPC Piling", name = "Enable NPC Piling",
description = "Enable the option to highlight NPCs when they pile.", description = "Enable the option to highlight NPCs when they pile.",
parent = "npcPilesStub" parent = "npcPilesStub"
) )
default boolean enableNPCS() default boolean enableNPCS()
{ {
@@ -105,11 +105,11 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 6, position = 6,
keyName = "npcPileColor", keyName = "npcPileColor",
name = "NPC Pile Color", name = "NPC Pile Color",
description = "Color used for NPC piles.", description = "Color used for NPC piles.",
parent = "npcPilesStub" parent = "npcPilesStub"
) )
default Color npcPileColor() default Color npcPileColor()
{ {
@@ -117,10 +117,10 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "mixedPilesStub", keyName = "mixedPilesStub",
name = "Mixed Piles", name = "Mixed Piles",
description = "", description = "",
position = 7 position = 7
) )
default Stub mixedPilesStub() default Stub mixedPilesStub()
{ {
@@ -128,11 +128,11 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 8, position = 8,
keyName = "mixedPileColor", keyName = "mixedPileColor",
name = "Mixed Pile Color", name = "Mixed Pile Color",
description = "Color used for mixed piles.", description = "Color used for mixed piles.",
parent = "mixedPilesStub" parent = "mixedPilesStub"
) )
default Color mixedPileColor() default Color mixedPileColor()
{ {
@@ -140,10 +140,10 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "pilesSizeStub", keyName = "pilesSizeStub",
name = "Pile size", name = "Pile size",
description = "", description = "",
position = 9 position = 9
) )
default Stub pilesSizeStub() default Stub pilesSizeStub()
{ {
@@ -151,14 +151,14 @@ public interface PileIndicatorsConfig extends Config
} }
@Range( @Range(
min = 2 min = 2
) )
@ConfigItem( @ConfigItem(
position = 10, position = 10,
keyName = "minimumPileSize", keyName = "minimumPileSize",
name = "Minimum Pile Size", name = "Minimum Pile Size",
description = "Any pile under this size will not show up. (Minimum: 2)", description = "Any pile under this size will not show up. (Minimum: 2)",
parent = "pilesSizeStub" parent = "pilesSizeStub"
) )
default int minimumPileSize() default int minimumPileSize()
{ {
@@ -166,10 +166,10 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "miscellaneousStub", keyName = "miscellaneousStub",
name = "Miscellaneous", name = "Miscellaneous",
description = "", description = "",
position = 11 position = 11
) )
default Stub miscellaneousStub() default Stub miscellaneousStub()
{ {
@@ -177,11 +177,11 @@ public interface PileIndicatorsConfig extends Config
} }
@ConfigItem( @ConfigItem(
position = 12, position = 12,
keyName = "numberOnly", keyName = "numberOnly",
name = "Display Number Only", name = "Display Number Only",
description = "Shorten \"PILE SIZE: 1\" to \"1\"", description = "Shorten \"PILE SIZE: 1\" to \"1\"",
parent = "miscellaneousStub" parent = "miscellaneousStub"
) )
default boolean numberOnly() default boolean numberOnly()
{ {
@@ -190,24 +190,26 @@ public interface PileIndicatorsConfig extends Config
@ConfigItem( @ConfigItem(
position = 13, position = 13,
keyName = "drawPileTile",
name = "Draw Pile Tile",
description = "Draws the tile of the pile for best visibility.",
parent = "miscellaneousStub"
)
default boolean drawPileTile()
{
return true;
}
@ConfigItem(
position = 14,
keyName = "drawPileHull", keyName = "drawPileHull",
name = "Draws the hull of the pile.", name = "Draw Pile Convex Hull",
description = "Draws the hull of the pile for best visibility." description = "Draws the hull of the pile for best visibility.",
parent = "miscellaneousStub"
) )
default boolean drawPileHull() default boolean drawPileHull()
{ {
return false; return false;
} }
@ConfigItem(
position = 14,
keyName = "highlightPile",
name = "Highlight Pile",
description = "Highlights Pile Onscreen"
)
default boolean highlightPile()
{
return false;
}
} }

View File

@@ -26,12 +26,15 @@ package net.runelite.client.plugins.pileindicators;
import net.runelite.api.Actor; import net.runelite.api.Actor;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.client.plugins.playerindicators.PlayerIndicatorsService;
import net.runelite.client.ui.overlay.*;
import javax.inject.Inject; import javax.inject.Inject;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
public class PileIndicatorsOverlay extends Overlay public class PileIndicatorsOverlay extends Overlay
{ {
@@ -39,16 +42,14 @@ public class PileIndicatorsOverlay extends Overlay
private final Client client; private final Client client;
private final PileIndicatorsPlugin plugin; private final PileIndicatorsPlugin plugin;
private final PileIndicatorsConfig config; private final PileIndicatorsConfig config;
private final PlayerIndicatorsService playerIndicatorsService;
@Inject @Inject
PileIndicatorsOverlay(final Client client, final PileIndicatorsPlugin plugin, final PileIndicatorsConfig config, PlayerIndicatorsService playerIndicatorsService) PileIndicatorsOverlay(final Client client, final PileIndicatorsPlugin plugin, final PileIndicatorsConfig config)
{ {
super(plugin); super(plugin);
this.client = client; this.client = client;
this.plugin = plugin; this.plugin = plugin;
this.config = config; this.config = config;
this.playerIndicatorsService = playerIndicatorsService;
setLayer(OverlayLayer.ABOVE_SCENE); setLayer(OverlayLayer.ABOVE_SCENE);
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
@@ -60,18 +61,7 @@ public class PileIndicatorsOverlay extends Overlay
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
ArrayList<ArrayList<Actor>> stackList = plugin.getStacks(); ArrayList<ArrayList<Actor>> stackList = plugin.getStacks();
if (config.drawPileHull())
{
playerIndicatorsService.forEachPlayer((player, color) ->
{
if (plugin.isPile(player))
{
Polygon objectClickbox = player.getConvexHull();
renderPoly(graphics, config.playerPileColor(), objectClickbox);
}
});
}
if (stackList != null) if (stackList != null)
{ {
for (ArrayList<Actor> actorArrayList : stackList) for (ArrayList<Actor> actorArrayList : stackList)
@@ -82,17 +72,16 @@ public class PileIndicatorsOverlay extends Overlay
try try
{ {
Actor actorToRender = actorArrayList.get(0); //guaranteed to have at least two players Actor actorToRender = actorArrayList.get(0); //guaranteed to have at least two players
final String text; final String pileTypeStr = pileType == PileType.PLAYER_PILE ? "PLAYER" : pileType == PileType.NPC_PILE ? "NPC" : pileType == PileType.MIXED_PILE ? "MIXED" : "";
if (config.numberOnly()) final String text = config.numberOnly() ? "" + actorArrayList.size() : (pileTypeStr + " PILE SIZE: " + actorArrayList.size());
if (config.drawPileTile())
{ {
text = "" + actorArrayList.size(); OverlayUtil.renderPolygon(graphics, actorToRender.getCanvasTilePoly(), pileColor);
} }
else if (config.drawPileHull())
{ {
text = "PILE SIZE: " + actorArrayList.size(); OverlayUtil.renderPolygon(graphics, actorToRender.getConvexHull(), pileColor);
} }
OverlayUtil.renderPolygon(graphics, actorToRender.getCanvasTilePoly(), pileColor);
OverlayUtil.renderTextLocation(graphics, actorToRender.getCanvasTextLocation(graphics, text, 40), text, pileColor); OverlayUtil.renderTextLocation(graphics, actorToRender.getCanvasTextLocation(graphics, text, 40), text, pileColor);
} }
catch (Exception ignored) catch (Exception ignored)
@@ -104,16 +93,4 @@ public class PileIndicatorsOverlay extends Overlay
return null; return null;
} }
private void renderPoly(Graphics2D graphics, Color color, Polygon polygon)
{
if (polygon != null)
{
graphics.setColor(color);
graphics.setStroke(new BasicStroke(2));
graphics.draw(polygon);
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20));
graphics.fill(polygon);
}
}
} }

View File

@@ -27,10 +27,12 @@ package net.runelite.client.plugins.pileindicators;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.Provides; import com.google.inject.Provides;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.*; import net.runelite.api.Actor;
import net.runelite.api.events.GameTick; import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.Player;
import net.runelite.api.Varbits;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType; import net.runelite.client.plugins.PluginType;
@@ -40,15 +42,13 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@PluginDescriptor( @PluginDescriptor(
name = "Pile Indicators", name = "Pile Indicators",
description = "Highlight and count how many npcs/players are stacked on each other.", description = "Highlight and count how many npcs/players are stacked on each other.",
tags = {"overlay", "pile", "stack", "pvp", "pvm", "pve"}, tags = {"overlay", "pile", "stack", "pvp", "pvm", "pve"},
type = PluginType.UTILITY, type = PluginType.UTILITY,
enabledByDefault = false enabledByDefault = false
) )
@Singleton @Singleton
@@ -68,9 +68,6 @@ public class PileIndicatorsPlugin extends Plugin
@Inject @Inject
private PileIndicatorsOverlay overlay; private PileIndicatorsOverlay overlay;
private List<String> pileList;
private ArrayList<String> callers = new ArrayList<>();
@Provides @Provides
PileIndicatorsConfig provideConfig(ConfigManager configManager) PileIndicatorsConfig provideConfig(ConfigManager configManager)
{ {
@@ -94,35 +91,6 @@ public class PileIndicatorsPlugin extends Plugin
overlayManager.remove(overlay); overlayManager.remove(overlay);
} }
@Subscribe
public void onGameTick(GameTick gameTick)
{
if (config.highlightPile() && callers != null)
{
for (Player p : client.getPlayers())
{
for (String name : callers)
{
Actor pile;
String finalName = name.toLowerCase().replace("_", " ");
if (p.getName().toLowerCase().replace("_", " ").equals(finalName))
{
pile = p.getInteracting();
if (pile != null)
{
pileList.set(callers.indexOf(name), pile.getName());
//pileList.add(pile.getName());
}
else
{
pileList.set(callers.indexOf(name), "");
}
}
}
}
}
}
protected ArrayList<ArrayList<Actor>> getStacks() protected ArrayList<ArrayList<Actor>> getStacks()
{ {
ArrayList<ArrayList<Actor>> outerArrayList = new ArrayList<>(); ArrayList<ArrayList<Actor>> outerArrayList = new ArrayList<>();
@@ -195,15 +163,6 @@ public class PileIndicatorsPlugin extends Plugin
return null; return null;
} }
boolean isPile(Player player)
{
if (Objects.nonNull(pileList) && pileList.size() > 0)
{
return pileList.contains(player.getName());
}
return false;
}
protected PileType getPileType(ArrayList<Actor> pile) protected PileType getPileType(ArrayList<Actor> pile)
{ {
PileType pileType = null; PileType pileType = null;