Merge pull request #9359 from Nightfirecat/add-skill-xp-tracker-menu-options
Add skill tab canvas menu options
This commit is contained in:
@@ -94,6 +94,17 @@ public interface XpTrackerConfig extends Config
|
|||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 4,
|
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",
|
keyName = "onScreenDisplayMode",
|
||||||
name = "On-screen tracker display mode (top)",
|
name = "On-screen tracker display mode (top)",
|
||||||
description = "Configures the information displayed in the first line of on-screen XP overlays"
|
description = "Configures the information displayed in the first line of on-screen XP overlays"
|
||||||
@@ -104,7 +115,7 @@ public interface XpTrackerConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 4,
|
position = 6,
|
||||||
keyName = "onScreenDisplayModeBottom",
|
keyName = "onScreenDisplayModeBottom",
|
||||||
name = "On-screen tracker display mode (bottom)",
|
name = "On-screen tracker display mode (bottom)",
|
||||||
description = "Configures the information displayed in the second line of on-screen XP overlays"
|
description = "Configures the information displayed in the second line of on-screen XP overlays"
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.google.inject.Binder;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -40,6 +41,8 @@ import net.runelite.api.Actor;
|
|||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Experience;
|
import net.runelite.api.Experience;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.MenuAction;
|
||||||
|
import net.runelite.api.MenuEntry;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.Skill;
|
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.ExperienceChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
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.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.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.game.NPCManager;
|
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.NavigationButton;
|
||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
import net.runelite.client.util.ImageUtil;
|
import net.runelite.client.util.ImageUtil;
|
||||||
|
import net.runelite.client.util.Text;
|
||||||
import net.runelite.http.api.xp.XpClient;
|
import net.runelite.http.api.xp.XpClient;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
@@ -76,6 +84,9 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
private static final int XP_THRESHOLD = 10_000;
|
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(
|
static final List<Skill> COMBAT = ImmutableList.of(
|
||||||
Skill.ATTACK,
|
Skill.ATTACK,
|
||||||
Skill.STRENGTH,
|
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)
|
XpSnapshotSingle getSkillSnapshot(Skill skill)
|
||||||
{
|
{
|
||||||
return xpState.getSkillSnapshot(skill);
|
return xpState.getSkillSnapshot(skill);
|
||||||
@@ -561,4 +632,9 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
pauseSkill(skill, pause);
|
pauseSkill(skill, pause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasOverlay(final Skill skill)
|
||||||
|
{
|
||||||
|
return overlayManager.anyMatch(o -> o instanceof XpInfoBoxOverlay && ((XpInfoBoxOverlay) o).getSkill() == skill);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,17 @@ public class OverlayManager
|
|||||||
return removeIf;
|
return removeIf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether an overlay exists which matches the given predicate.
|
||||||
|
*
|
||||||
|
* @param filter Filter predicate function
|
||||||
|
* @return {@code true} if any overlays match the given filter, {@code false} otherwise
|
||||||
|
*/
|
||||||
|
public synchronized boolean anyMatch(Predicate<Overlay> filter)
|
||||||
|
{
|
||||||
|
return overlays.stream().anyMatch(filter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all overlays
|
* Clear all overlays
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user