Agility plugin: generate less garbage objects and use a color range for levels

This commit is contained in:
Lucwousin
2019-09-04 10:18:33 +02:00
parent 37db102ebf
commit f4ce10e394
5 changed files with 82 additions and 21 deletions

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.client.plugins.agility;
import com.google.common.primitives.Ints;
import com.google.inject.Provides;
import java.awt.Color;
import java.util.ArrayList;
@@ -507,21 +508,17 @@ public class AgilityPlugin extends Plugin
return;
}
final int entryId = event.getIdentifier();
MenuEntry[] menuEntries = client.getMenuEntries();
for (Obstacle nearbyObstacle : getObstacles().values())
{
AgilityShortcut shortcut = nearbyObstacle.getShortcut();
if (shortcut != null && Arrays.stream(shortcut.getObstacleIds()).anyMatch(i -> i == entryId))
if (shortcut != null && Ints.contains(shortcut.getObstacleIds(), event.getIdentifier()))
{
MenuEntry entry = menuEntries[menuEntries.length - 1];
int level = shortcut.getLevel();
Color color = level <= getAgilityLevel() ? Color.GREEN : Color.RED;
String requirementText = " (level-" + level + ")";
final MenuEntry entry = event.getMenuEntry();
final int reqLevel = shortcut.getLevel();
final String requirementText = ColorUtil.getLevelColorString(reqLevel, getAgilityLevel()) + " (level-" + reqLevel + ")";
entry.setTarget(event.getTarget() + ColorUtil.prependColorTag(requirementText, color));
client.setMenuEntries(menuEntries);
entry.setTarget(event.getTarget() + requirementText);
event.setWasModified(true);
return;
}
}

View File

@@ -267,4 +267,65 @@ public class ColorUtil
}
return (color & 0x00ffffff) | (alpha << 24);
}
/**
* Returns the color a ' (level-xxx)' would have, based on
* the difference between your and their level.
* This method is the same as in rs-client.
*
* @param theirLvl The level you're comparing against
* @param yourLvl Your level
*/
public static String getLevelColorString(final int theirLvl, final int yourLvl)
{
final int diff = yourLvl - theirLvl;
if (diff < -9)
{
return colorStartTag(0xff0000);
}
else if (diff < -6)
{
return colorStartTag(0xff3000);
}
else if (diff < -3)
{
return colorStartTag(0xff7000);
}
else if (diff < 0)
{
return colorStartTag(0xffb000);
}
else if (diff > 9)
{
return colorStartTag(0x00ff00);
}
else if (diff > 6)
{
return colorStartTag(0x40ff00);
}
else if (diff > 3)
{
return colorStartTag(0x80ff00);
}
else if (diff > 0)
{
return colorStartTag(0xc0ff00);
}
else
{
return colorStartTag(0xffff00);
}
}
/**
* Creates a color start tag from a rgb color as a int value
*
* @param rgb the int value of a rgb color
* @return a color tag which can be put in front of stuff
*/
public static String colorStartTag(final int rgb)
{
return "<col=" + Integer.toHexString(rgb) + ">";
}
}