Refactor TickCounter

This commit is contained in:
Scott Burns
2019-05-16 01:17:49 +02:00
parent 82e76a5ccb
commit f29a72ad34
4 changed files with 148 additions and 110 deletions

View File

@@ -1,14 +1,14 @@
package net.runelite.client.plugins.tickcounter; package net.runelite.client.plugins.tickcounter;
import java.awt.Color;
import net.runelite.client.config.Alpha; import net.runelite.client.config.Alpha;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
import java.awt.*;
@ConfigGroup("tickcounter") @ConfigGroup("tickcounter")
public interface TickCounterConfig extends Config { public interface TickCounterConfig extends Config
{
@ConfigItem( @ConfigItem(
keyName = "resetInstance", keyName = "resetInstance",
name = "Reset on new instances", name = "Reset on new instances",
@@ -19,6 +19,7 @@ public interface TickCounterConfig extends Config {
{ {
return true; return true;
} }
@Alpha @Alpha
@ConfigItem( @ConfigItem(
keyName = "selfColor", keyName = "selfColor",
@@ -30,6 +31,7 @@ public interface TickCounterConfig extends Config {
{ {
return Color.green; return Color.green;
} }
@Alpha @Alpha
@ConfigItem( @ConfigItem(
keyName = "totalColor", keyName = "totalColor",
@@ -41,6 +43,7 @@ public interface TickCounterConfig extends Config {
{ {
return Color.RED; return Color.RED;
} }
@Alpha @Alpha
@ConfigItem( @ConfigItem(
keyName = "otherColor", keyName = "otherColor",
@@ -52,6 +55,7 @@ public interface TickCounterConfig extends Config {
{ {
return Color.white; return Color.white;
} }
@Alpha @Alpha
@ConfigItem( @ConfigItem(
keyName = "bgColor", keyName = "bgColor",
@@ -63,6 +67,7 @@ public interface TickCounterConfig extends Config {
{ {
return new Color(70, 61, 50, 156); return new Color(70, 61, 50, 156);
} }
@Alpha @Alpha
@ConfigItem( @ConfigItem(
keyName = "titleColor", keyName = "titleColor",

View File

@@ -1,15 +1,12 @@
package net.runelite.client.plugins.tickcounter; package net.runelite.client.plugins.tickcounter;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
@@ -18,7 +15,8 @@ import net.runelite.client.ui.overlay.components.LineComponent;
import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent; import net.runelite.client.ui.overlay.components.TitleComponent;
public class TickCounterOverlay extends Overlay { public class TickCounterOverlay extends Overlay
{
private TickCounterPlugin plugin; private TickCounterPlugin plugin;
private TickCounterConfig config; private TickCounterConfig config;
@@ -26,7 +24,8 @@ public class TickCounterOverlay extends Overlay {
private PanelComponent panelComponent = new PanelComponent(); private PanelComponent panelComponent = new PanelComponent();
@Inject @Inject
public TickCounterOverlay(TickCounterPlugin plugin,Client client,TickCounterConfig config) { public TickCounterOverlay(TickCounterPlugin plugin, Client client, TickCounterConfig config)
{
super(plugin); super(plugin);
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
setPosition(OverlayPosition.DETACHED); setPosition(OverlayPosition.DETACHED);
@@ -37,27 +36,31 @@ public class TickCounterOverlay extends Overlay {
} }
@Override @Override
public Dimension render(Graphics2D g) { public Dimension render(Graphics2D g)
{
List<LayoutableRenderableEntity> elems = panelComponent.getChildren(); List<LayoutableRenderableEntity> elems = panelComponent.getChildren();
elems.clear(); elems.clear();
panelComponent.setBackgroundColor(config.bgColor()); panelComponent.setBackgroundColor(config.bgColor());
elems.add(TitleComponent.builder().text("Combat counter").color(config.titleColor()).build()); elems.add(TitleComponent.builder().text("Combat counter").color(config.titleColor()).build());
List<Entry<String, Integer>> list = new ArrayList<>(plugin.activity.entrySet()); List<Entry<String, Integer>> list = new ArrayList<>(plugin.activity.entrySet());
list.sort(new Comparator<Entry<String, Integer>>() { list.sort((o1, o2) -> {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
int value = -Integer.compare(o1.getValue(), o2.getValue()); int value = -Integer.compare(o1.getValue(), o2.getValue());
if (value == 0) if (value == 0)
{
value = o1.getKey().compareTo(o2.getKey()); value = o1.getKey().compareTo(o2.getKey());
return value;
} }
return value;
}); });
int total = 0; int total = 0;
for (Entry<String, Integer> e : list) { for (Entry<String, Integer> e : list)
{
total += e.getValue(); total += e.getValue();
if(e.getKey().equals(client.getLocalPlayer().getName())){ if (e.getKey().equals(client.getLocalPlayer().getName()))
{
elems.add(LineComponent.builder().leftColor(config.selfColor()).rightColor(config.selfColor()).left(e.getKey()).right(e.getValue().toString()).build()); elems.add(LineComponent.builder().leftColor(config.selfColor()).rightColor(config.selfColor()).left(e.getKey()).right(e.getValue().toString()).build());
}else{ }
else
{
elems.add(LineComponent.builder().left(e.getKey()).right(e.getValue().toString()).leftColor(config.otherColor()).rightColor(config.otherColor()).build()); elems.add(LineComponent.builder().left(e.getKey()).right(e.getValue().toString()).leftColor(config.otherColor()).rightColor(config.otherColor()).build());
} }

View File

@@ -1,13 +1,11 @@
package net.runelite.client.plugins.tickcounter; package net.runelite.client.plugins.tickcounter;
import com.google.inject.Provides;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import com.google.inject.Provides;
import net.runelite.api.Actor; import net.runelite.api.Actor;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Player; import net.runelite.api.Player;
@@ -27,49 +25,62 @@ import net.runelite.client.ui.overlay.OverlayManager;
enabledByDefault = false, enabledByDefault = false,
type = PluginType.PVP type = PluginType.PVP
) )
public class TickCounterPlugin extends Plugin { public class TickCounterPlugin extends Plugin
{
@Inject @Inject
private OverlayManager overlayManager; private OverlayManager overlayManager;
@Inject @Inject
private TickCounterConfig config; private TickCounterConfig config;
@Inject @Inject
private Client client; private Client client;
@Provides @Provides
TickCounterConfig provideConfig(ConfigManager configManager) TickCounterConfig provideConfig(ConfigManager configManager)
{ {
return configManager.getConfig(TickCounterConfig.class); return configManager.getConfig(TickCounterConfig.class);
} }
@Inject @Inject
private TickCounterOverlay overlay; private TickCounterOverlay overlay;
Map<String, Integer> activity = new HashMap<>(); Map<String, Integer> activity = new HashMap<>();
private List<Player> blowpiping = new ArrayList<>(); private List<Player> blowpiping = new ArrayList<>();
boolean instanced = false; private boolean instanced = false;
boolean prevInstance = false; private boolean prevInstance = false;
@Override @Override
protected void startUp() throws Exception { protected void startUp() throws Exception
{
overlayManager.add(overlay); overlayManager.add(overlay);
} }
@Override @Override
protected void shutDown() throws Exception { protected void shutDown() throws Exception
{
overlayManager.remove(overlay); overlayManager.remove(overlay);
activity.clear(); activity.clear();
} }
@Subscribe @Subscribe
public void onAnimationChanged(AnimationChanged e) { public void onAnimationChanged(AnimationChanged e)
{
if (!(e.getActor() instanceof Player)) if (!(e.getActor() instanceof Player))
{
return; return;
}
Player p = (Player) e.getActor(); Player p = (Player) e.getActor();
int weapon = -1; int weapon = -1;
if (p.getPlayerComposition() != null) if (p.getPlayerComposition() != null)
{
weapon = p.getPlayerComposition().getEquipmentId(KitType.WEAPON); weapon = p.getPlayerComposition().getEquipmentId(KitType.WEAPON);
}
int delta = 0; int delta = 0;
switch (p.getAnimation()) { switch (p.getAnimation())
{
case 7617: // rune knife case 7617: // rune knife
case 8194: // dragon knife case 8194: // dragon knife
case 8291: // dragon knife spec case 8291: // dragon knife spec
@@ -89,9 +100,13 @@ public class TickCounterPlugin extends Plugin {
break; break;
case 426: // bow shoot case 426: // bow shoot
if (weapon == 20997) // twisted bow if (weapon == 20997) // twisted bow
{
delta = 5; delta = 5;
}
else // shortbow else // shortbow
{
delta = 3; delta = 3;
}
break; break;
case 376: // dds poke case 376: // dds poke
case 377: // dds slash case 377: // dds slash
@@ -119,7 +134,8 @@ public class TickCounterPlugin extends Plugin {
delta = 4; delta = 4;
break; break;
case 393: // staff bash case 393: // staff bash
if (weapon == 13652) { // claw scratch if (weapon == 13652)
{ // claw scratch
delta = 4; delta = 4;
break; break;
} }
@@ -135,9 +151,13 @@ public class TickCounterPlugin extends Plugin {
break; break;
case 401: case 401:
if (weapon == 13576) // dwh bop if (weapon == 13576) // dwh bop
{
delta = 6; delta = 6;
}
else // used by pickaxe and axe else // used by pickaxe and axe
{
delta = 5; delta = 5;
}
break; break;
case 1378: case 1378:
case 7045: case 7045:
@@ -162,33 +182,43 @@ public class TickCounterPlugin extends Plugin {
blowpiping.remove(p); blowpiping.remove(p);
break; break;
} }
if (delta > 0) { if (delta > 0)
{
String name = p.getName(); String name = p.getName();
this.activity.put(name, this.activity.getOrDefault(name, 0) + delta); this.activity.put(name, this.activity.getOrDefault(name, 0) + delta);
} }
} }
@Subscribe @Subscribe
public void onClientTick(ClientTick e) { public void onClientTick(ClientTick e)
{
/* /*
* Hack for blowpipe since the AnimationChanged event doesn't fire when using a * Hack for blowpipe since the AnimationChanged event doesn't fire when using a
* blowpipe because of its speed. If blowpipe animation restarts, then add 2 * blowpipe because of its speed. If blowpipe animation restarts, then add 2
*/ */
for (Player p : blowpiping) { for (Player p : blowpiping)
{
Actor rsp = p; Actor rsp = p;
if (rsp.getActionFrame() == 0 && rsp.getActionFrameCycle() == 1) { if (rsp.getActionFrame() == 0 && rsp.getActionFrameCycle() == 1)
{
String name = p.getName(); String name = p.getName();
int activity = this.activity.getOrDefault(name, 0).intValue(); int activity = this.activity.getOrDefault(name, 0);
this.activity.put(name, activity + 2); this.activity.put(name, activity + 2);
} }
} }
} }
@Subscribe @Subscribe
public void onGameTick(GameTick tick){ public void onGameTick(GameTick tick)
if(!config.instance())return; {
if (!config.instance())
{
return;
}
prevInstance = instanced; prevInstance = instanced;
instanced = client.isInInstancedRegion(); instanced = client.isInInstancedRegion();
if(!prevInstance && instanced){ if (!prevInstance && instanced)
{
activity.clear(); activity.clear();
} }
} }