Search in sources :

Example 6 with MenuEntry

use of net.runelite.api.MenuEntry in project runelite by runelite.

the class PlayerIndicatorsPlugin method onMenuEntryAdd.

@Subscribe
public void onMenuEntryAdd(MenuEntryAdded menuEntryAdded) {
    int type = menuEntryAdded.getType();
    int identifier = menuEntryAdded.getIdentifier();
    if (type == FOLLOW.getId() || type == TRADE.getId() || type == SPELL_CAST_ON_PLAYER.getId() || type == ITEM_USE_ON_PLAYER.getId() || type == PLAYER_FIRST_OPTION.getId() || type == PLAYER_SECOND_OPTION.getId() || type == PLAYER_THIRD_OPTION.getId() || type == PLAYER_FOURTH_OPTION.getId() || type == PLAYER_FIFTH_OPTION.getId() || type == PLAYER_SIXTH_OPTION.getId() || type == PLAYER_SEVENTH_OPTION.getId() || type == PLAYER_EIGTH_OPTION.getId()) {
        final Player localPlayer = client.getLocalPlayer();
        Player[] players = client.getCachedPlayers();
        Player player = null;
        if (identifier >= 0 && identifier < players.length) {
            player = players[identifier];
        }
        if (player == null) {
            return;
        }
        int image = -1;
        Color color = null;
        if (config.drawFriendNames() && player.isFriend()) {
            color = config.getFriendNameColor();
        } else if (config.drawClanMemberNames() && player.isClanMember()) {
            color = config.getClanMemberColor();
            ClanMemberRank rank = clanManager.getRank(player.getName());
            if (rank != UNRANKED) {
                image = clanManager.getIconNumber(rank);
            }
        } else if (config.drawTeamMemberNames() && player.getTeam() > 0 && localPlayer.getTeam() == player.getTeam()) {
            color = config.getTeamMemberColor();
        } else if (config.drawNonClanMemberNames() && !player.isClanMember()) {
            color = config.getNonClanMemberColor();
        }
        if (image != -1 || color != null) {
            MenuEntry[] menuEntries = client.getMenuEntries();
            MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
            if (color != null) {
                // strip out existing <col...
                String target = lastEntry.getTarget();
                int idx = target.indexOf('>');
                if (idx != -1) {
                    target = target.substring(idx + 1);
                }
                lastEntry.setTarget("<col=" + Integer.toHexString(color.getRGB() & 0xFFFFFF) + ">" + target);
            }
            if (image != -1) {
                lastEntry.setTarget("<img=" + image + ">" + lastEntry.getTarget());
            }
            client.setMenuEntries(menuEntries);
        }
    }
}
Also used : Player(net.runelite.api.Player) MenuEntry(net.runelite.api.MenuEntry) Color(java.awt.Color) ClanMemberRank(net.runelite.api.ClanMemberRank) Subscribe(com.google.common.eventbus.Subscribe)

Example 7 with MenuEntry

use of net.runelite.api.MenuEntry in project runelite by runelite.

the class RSClientMixin method setMenuEntries.

@Inject
@Override
public void setMenuEntries(MenuEntry[] entries) {
    int count = 0;
    String[] menuOptions = getMenuOptions();
    String[] menuTargets = getMenuTargets();
    int[] menuIdentifiers = getMenuIdentifiers();
    int[] menuTypes = getMenuTypes();
    int[] params0 = getMenuActionParams0();
    int[] params1 = getMenuActionParams1();
    for (MenuEntry entry : entries) {
        menuOptions[count] = entry.getOption();
        menuTargets[count] = entry.getTarget();
        menuIdentifiers[count] = entry.getIdentifier();
        menuTypes[count] = entry.getType();
        params0[count] = entry.getParam0();
        params1[count] = entry.getParam1();
        ++count;
    }
    setMenuOptionCount(count);
}
Also used : MenuEntry(net.runelite.api.MenuEntry) LocalPoint(net.runelite.api.coords.LocalPoint) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Example 8 with MenuEntry

use of net.runelite.api.MenuEntry in project runelite by runelite.

the class MenuManager method menuContainsCustomMenu.

private boolean menuContainsCustomMenu(WidgetMenuOption customMenuOption) {
    Client client = clientProvider.get();
    if (client == null) {
        return false;
    }
    for (MenuEntry menuEntry : client.getMenuEntries()) {
        String option = menuEntry.getOption();
        String target = menuEntry.getTarget();
        if (option.equals(customMenuOption.getMenuOption()) && target.equals(customMenuOption.getMenuTarget())) {
            return true;
        }
    }
    return false;
}
Also used : MenuEntry(net.runelite.api.MenuEntry) Client(net.runelite.api.Client)

Example 9 with MenuEntry

use of net.runelite.api.MenuEntry in project runelite by runelite.

the class MenuEntrySwapperPlugin method swap.

private void swap(String optionA, String optionB, String target, boolean strict) {
    MenuEntry[] entries = client.getMenuEntries();
    int idxA = searchIndex(entries, optionA, target, strict);
    int idxB = searchIndex(entries, optionB, target, strict);
    if (idxA >= 0 && idxB >= 0) {
        MenuEntry entry = entries[idxA];
        entries[idxA] = entries[idxB];
        entries[idxB] = entry;
        client.setMenuEntries(entries);
    }
}
Also used : MenuEntry(net.runelite.api.MenuEntry)

Example 10 with MenuEntry

use of net.runelite.api.MenuEntry in project runelite by runelite.

the class GroundItemsPlugin method onMenuEntryAdded.

@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event) {
    if ((config.highlightMenuOption() || config.highlightMenuItemName()) && event.getOption().equals("Take") && event.getType() == MenuAction.GROUND_ITEM_THIRD_OPTION.getId()) {
        int itemId = event.getIdentifier();
        ItemComposition itemComposition = client.getItemDefinition(itemId);
        if (isHidden(itemComposition.getName())) {
            return;
        }
        Region region = client.getRegion();
        Tile tile = region.getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()];
        ItemLayer itemLayer = tile.getItemLayer();
        if (itemLayer == null) {
            return;
        }
        MenuEntry[] menuEntries = client.getMenuEntries();
        MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
        int quantity = 1;
        Node current = itemLayer.getBottom();
        while (current instanceof Item) {
            Item item = (Item) current;
            if (item.getId() == itemId) {
                quantity = item.getQuantity();
            }
            current = current.getNext();
        }
        ItemPrice itemPrice = getItemPrice(itemComposition);
        int price = itemPrice == null ? itemComposition.getPrice() : itemPrice.getPrice();
        int cost = quantity * price;
        Color color = overlay.getCostColor(cost, isHighlighted(itemComposition.getName()), isHidden(itemComposition.getName()));
        if (!color.equals(config.defaultColor())) {
            String hexColor = Integer.toHexString(color.getRGB() & 0xFFFFFF);
            String colTag = "<col=" + hexColor + ">";
            if (config.highlightMenuOption()) {
                lastEntry.setOption(colTag + "Take");
            }
            if (config.highlightMenuItemName()) {
                String target = lastEntry.getTarget().substring(lastEntry.getTarget().indexOf(">") + 1);
                lastEntry.setTarget(colTag + target);
            }
        }
        if (config.showMenuItemQuantities() && itemComposition.isStackable() && quantity > 1) {
            lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")");
        }
        client.setMenuEntries(menuEntries);
    }
}
Also used : ItemLayer(net.runelite.api.ItemLayer) Item(net.runelite.api.Item) MenuEntry(net.runelite.api.MenuEntry) Node(net.runelite.api.Node) Color(java.awt.Color) ItemPrice(net.runelite.http.api.item.ItemPrice) ItemComposition(net.runelite.api.ItemComposition) Region(net.runelite.api.Region) Tile(net.runelite.api.Tile) LocalPoint(net.runelite.api.coords.LocalPoint) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

MenuEntry (net.runelite.api.MenuEntry)10 Subscribe (com.google.common.eventbus.Subscribe)3 LocalPoint (net.runelite.api.coords.LocalPoint)3 Color (java.awt.Color)2 Client (net.runelite.api.Client)2 Point (net.runelite.api.Point)2 Inject (net.runelite.api.mixins.Inject)2 Tooltip (net.runelite.client.ui.overlay.tooltip.Tooltip)2 ClanMemberRank (net.runelite.api.ClanMemberRank)1 Item (net.runelite.api.Item)1 ItemComposition (net.runelite.api.ItemComposition)1 ItemLayer (net.runelite.api.ItemLayer)1 MenuAction (net.runelite.api.MenuAction)1 Node (net.runelite.api.Node)1 Player (net.runelite.api.Player)1 Region (net.runelite.api.Region)1 Tile (net.runelite.api.Tile)1 Varcs (net.runelite.api.Varcs)1 Widget (net.runelite.api.widgets.Widget)1 ItemPrice (net.runelite.http.api.item.ItemPrice)1