xptrackerplugin: Add canvas menu options to skill tab

This commit adds a configuration option to display menu options to add
or remove a skill from the canvas from the skill tab.
This commit is contained in:
Jordan Atwood
2019-07-12 22:29:12 -07:00
committed by Adam
parent c6149f0db0
commit ae8379b08a
2 changed files with 88 additions and 1 deletions

View File

@@ -94,6 +94,17 @@ public interface XpTrackerConfig extends Config
@ConfigItem(
position = 4,
keyName = "skillTabOverlayMenuOptions",
name = "Add skill tab canvas menu option",
description = "Configures whether a menu option to show/hide canvas XP trackers will be added to skills on the skill tab"
)
default boolean skillTabOverlayMenuOptions()
{
return true;
}
@ConfigItem(
position = 5,
keyName = "onScreenDisplayMode",
name = "On-screen tracker display mode (top)",
description = "Configures the information displayed in the first line of on-screen XP overlays"
@@ -104,7 +115,7 @@ public interface XpTrackerConfig extends Config
}
@ConfigItem(
position = 4,
position = 6,
keyName = "onScreenDisplayModeBottom",
name = "On-screen tracker display mode (bottom)",
description = "Configures the information displayed in the second line of on-screen XP overlays"

View File

@@ -31,6 +31,7 @@ import com.google.inject.Binder;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
@@ -40,6 +41,8 @@ import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.Experience;
import net.runelite.api.GameState;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPC;
import net.runelite.api.Player;
import net.runelite.api.Skill;
@@ -48,7 +51,11 @@ import net.runelite.api.WorldType;
import net.runelite.api.events.ExperienceChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.widgets.WidgetID;
import static net.runelite.api.widgets.WidgetInfo.TO_GROUP;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.NPCManager;
@@ -61,6 +68,7 @@ import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.Text;
import net.runelite.http.api.xp.XpClient;
@PluginDescriptor(
@@ -76,6 +84,9 @@ public class XpTrackerPlugin extends Plugin
*/
private static final int XP_THRESHOLD = 10_000;
private static final String MENUOP_ADD_CANVAS_TRACKER = "Add to canvas";
private static final String MENUOP_REMOVE_CANVAS_TRACKER = "Remove from canvas";
static final List<Skill> COMBAT = ImmutableList.of(
Skill.ATTACK,
Skill.STRENGTH,
@@ -375,6 +386,66 @@ public class XpTrackerPlugin extends Plugin
}
}
@Subscribe
public void onMenuEntryAdded(final MenuEntryAdded event)
{
int widgetID = event.getActionParam1();
if (TO_GROUP(widgetID) != WidgetID.SKILLS_GROUP_ID
|| !event.getOption().startsWith("View")
|| !xpTrackerConfig.skillTabOverlayMenuOptions())
{
return;
}
// Get skill from menu option, eg. "View <col=ff981f>Attack</col> guide"
final String skillText = event.getOption().split(" ")[1];
final Skill skill = Skill.valueOf(Text.removeTags(skillText).toUpperCase());
MenuEntry[] menuEntries = client.getMenuEntries();
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1);
MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry();
menuEntry.setTarget(skillText);
menuEntry.setOption(hasOverlay(skill) ? MENUOP_REMOVE_CANVAS_TRACKER : MENUOP_ADD_CANVAS_TRACKER);
menuEntry.setParam0(event.getActionParam0());
menuEntry.setParam1(widgetID);
menuEntry.setType(MenuAction.RUNELITE.getId());
client.setMenuEntries(menuEntries);
}
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
if (event.getMenuAction().getId() != MenuAction.RUNELITE.getId()
|| TO_GROUP(event.getWidgetId()) != WidgetID.SKILLS_GROUP_ID)
{
return;
}
final Skill skill;
try
{
skill = Skill.valueOf(Text.removeTags(event.getMenuTarget()).toUpperCase());
}
catch (IllegalArgumentException ex)
{
log.debug(null, ex);
return;
}
switch (event.getMenuOption())
{
case MENUOP_ADD_CANVAS_TRACKER:
addOverlay(skill);
break;
case MENUOP_REMOVE_CANVAS_TRACKER:
removeOverlay(skill);
break;
}
}
XpSnapshotSingle getSkillSnapshot(Skill skill)
{
return xpState.getSkillSnapshot(skill);
@@ -561,4 +632,9 @@ public class XpTrackerPlugin extends Plugin
pauseSkill(skill, pause);
}
}
private boolean hasOverlay(final Skill skill)
{
return overlayManager.anyMatch(o -> o instanceof XpInfoBoxOverlay && ((XpInfoBoxOverlay) o).getSkill() == skill);
}
}