Merge pull request #3204 from Owain94/upstream-2405

upstream: merge
This commit is contained in:
Justin
2022-05-26 20:22:41 +10:00
committed by GitHub
27 changed files with 365 additions and 123 deletions

View File

@@ -123,6 +123,27 @@ public interface MenuEntry
@Nullable @Nullable
Widget getWidget(); Widget getWidget();
/**
* Get the {@link NPC} this menu entry is targeting, if any.
* @return
*/
@Nullable
NPC getNpc();
/**
* Get the {@link Player} this menu entry is targeting, if any.
* @return
*/
@Nullable
Player getPlayer();
/**
* Get the {@link Actor} this menu entry is targeting, if any.
* @return
*/
@Nullable
Actor getActor();
@Deprecated @Deprecated
int getOpcode(); int getOpcode();
@Deprecated @Deprecated
@@ -140,4 +161,4 @@ public interface MenuEntry
@Deprecated @Deprecated
MenuAction getMenuAction(); MenuAction getMenuAction();
} }

View File

@@ -24,58 +24,77 @@
*/ */
package net.runelite.api.events; package net.runelite.api.events;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
/** /**
* An event when a new entry is added to a right-click menu. * An event when a new entry is added to a right-click menu.
*/ */
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString(onlyExplicitlyIncluded = true)
public class MenuEntryAdded public class MenuEntryAdded
{ {
// Here for RuneLite compatibility (different parameter order) // Here for RuneLite compatibility (different parameter order)
public MenuEntryAdded(String option, String target, int type, int identifier, int actionParam0, int actionParam1) public MenuEntryAdded(MenuEntry menuEntry)
{ {
this(option, target, identifier, type, actionParam0, actionParam1, false); this.menuEntry = menuEntry;
}
public MenuEntryAdded(String option, String target, int identifier, int type, int param0, int param1, boolean forceLeftClick) this.option = menuEntry.getOption();
{ this.target = menuEntry.getTarget();
this.option = option; this.identifier = menuEntry.getIdentifier();
this.target = target; this.type = menuEntry.getType().getId();
this.identifier = identifier; this.actionParam0 = menuEntry.getParam0();
this.type = type; this.actionParam1 = menuEntry.getParam1();
this.actionParam0 = param0; this.forceLeftClick = false;
this.actionParam1 = param1;
this.forceLeftClick = forceLeftClick;
} }
@Getter
private final MenuEntry menuEntry;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private String option; private String option;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private String target; private String target;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private int type; private int type;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private int identifier; private int identifier;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private int actionParam0; private int actionParam0;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private int actionParam1; private int actionParam1;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private boolean forceLeftClick; private boolean forceLeftClick;
/** /**
@@ -87,6 +106,8 @@ public class MenuEntryAdded
*/ */
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode.Include
@ToString.Include
private boolean modified; private boolean modified;
public void setModified() public void setModified()
@@ -134,4 +155,4 @@ public class MenuEntryAdded
{ {
return MenuAction.of(type); return MenuAction.of(type);
} }
} }

View File

@@ -24,9 +24,12 @@
*/ */
package net.runelite.api.events; package net.runelite.api.events;
import javax.annotation.Nullable;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.ToString;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry; import net.runelite.api.MenuEntry;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
@@ -43,12 +46,16 @@ import net.runelite.api.widgets.Widget;
* it seems that this event still triggers with the "Cancel" action. * it seems that this event still triggers with the "Cancel" action.
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString(onlyExplicitlyIncluded = true)
public class MenuOptionClicked public class MenuOptionClicked
{ {
/** /**
* The clicked menu entry * The clicked menu entry
*/ */
@Getter
private final MenuEntry menuEntry; private final MenuEntry menuEntry;
/** /**
* Whether or not the event has been consumed by a subscriber. * Whether or not the event has been consumed by a subscriber.
*/ */
@@ -59,6 +66,8 @@ public class MenuOptionClicked
/** /**
* Action parameter 0. Its value depends on the menuAction. * Action parameter 0. Its value depends on the menuAction.
*/ */
@EqualsAndHashCode.Include
@ToString.Include
public int getParam0() public int getParam0()
{ {
return menuEntry.getParam0(); return menuEntry.getParam0();
@@ -72,6 +81,8 @@ public class MenuOptionClicked
/** /**
* Action parameter 1. Its value depends on the menuAction. * Action parameter 1. Its value depends on the menuAction.
*/ */
@EqualsAndHashCode.Include
@ToString.Include
public int getParam1() public int getParam1()
{ {
return menuEntry.getParam1(); return menuEntry.getParam1();
@@ -85,6 +96,8 @@ public class MenuOptionClicked
/** /**
* The option text added to the menu. * The option text added to the menu.
*/ */
@EqualsAndHashCode.Include
@ToString.Include
public String getMenuOption() public String getMenuOption()
{ {
return menuEntry.getOption(); return menuEntry.getOption();
@@ -98,6 +111,8 @@ public class MenuOptionClicked
/** /**
* The target of the action. * The target of the action.
*/ */
@EqualsAndHashCode.Include
@ToString.Include
public String getMenuTarget() public String getMenuTarget()
{ {
return menuEntry.getTarget(); return menuEntry.getTarget();
@@ -111,6 +126,8 @@ public class MenuOptionClicked
/** /**
* The action performed. * The action performed.
*/ */
@EqualsAndHashCode.Include
@ToString.Include
public MenuAction getMenuAction() public MenuAction getMenuAction()
{ {
return menuEntry.getType(); return menuEntry.getType();
@@ -124,6 +141,8 @@ public class MenuOptionClicked
/** /**
* The ID of the object, actor, or item that the interaction targets. * The ID of the object, actor, or item that the interaction targets.
*/ */
@EqualsAndHashCode.Include
@ToString.Include
public int getId() public int getId()
{ {
return menuEntry.getIdentifier(); return menuEntry.getIdentifier();
@@ -168,6 +187,7 @@ public class MenuOptionClicked
* with an associated widget. Such as eg, CC_OP. * with an associated widget. Such as eg, CC_OP.
* @return * @return
*/ */
@Nullable
public Widget getWidget() public Widget getWidget()
{ {
return menuEntry.getWidget(); return menuEntry.getWidget();

View File

@@ -183,6 +183,17 @@ public interface Widget
@Deprecated @Deprecated
void setRelativeY(int y); void setRelativeY(int y);
/**
* Set a forced position for the widget. This position overrides the relative x/y for the
* widget, even if the widget is revalidated. To clear the forced position pass -1 for x/y.
* @param x x pos relative to the parent
* @param y y pos relative to the parent
*/
void setForcedPosition(int x, int y);
void setForcedX();
void setForcedY();
/** /**
* Gets the text displayed on this widget. * Gets the text displayed on this widget.
* *

View File

@@ -118,9 +118,8 @@ public class CrowdsourcingThieving
{ {
if (event.getMenuOption().equals("Pickpocket") || event.getMenuOption().equals("Knock-Out")) if (event.getMenuOption().equals("Pickpocket") || event.getMenuOption().equals("Knock-Out"))
{ {
NPC[] cachedNPCs = client.getCachedNPCs(); NPC npc = event.getMenuEntry().getNpc();
NPC npc = cachedNPCs[event.getId()]; lastPickpocketTarget = npc != null ? npc.getId() : -1;
lastPickpocketTarget = npc.getId();
} }
} }
} }

View File

@@ -476,7 +476,8 @@ public class DevToolsPlugin extends Plugin
if (action == MenuAction.EXAMINE_NPC) if (action == MenuAction.EXAMINE_NPC)
{ {
NPC npc = client.getCachedNPCs()[identifier]; NPC npc = entry.getNpc();
assert npc != null;
info += npc.getId(); info += npc.getId();
} }
else else

View File

@@ -50,7 +50,7 @@ class SceneUploader
@Inject @Inject
private Client client; private Client client;
int sceneId = (int) (System.currentTimeMillis() / 1000L); int sceneId = (int) System.nanoTime();
private int offset; private int offset;
private int uvoffset; private int uvoffset;

View File

@@ -185,9 +185,7 @@ public class HiscorePlugin extends Plugin
{ {
if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER && event.getMenuOption().equals(LOOKUP)) if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER && event.getMenuOption().equals(LOOKUP))
{ {
// The player id is included in the event, so we can use that to get the player name, Player player = event.getMenuEntry().getPlayer();
// which avoids having to parse out the combat level and any icons preceding the name.
Player player = client.getCachedPlayers()[event.getId()];
if (player == null) if (player == null)
{ {
return; return;

View File

@@ -114,8 +114,7 @@ class InteractHighlightOverlay extends Overlay
case NPC_FIFTH_OPTION: case NPC_FIFTH_OPTION:
case EXAMINE_NPC: case EXAMINE_NPC:
{ {
int id = entry.getIdentifier(); NPC npc = entry.getNpc();
NPC npc = plugin.findNpc(id);
if (npc != null && config.npcShowHover() && (npc != plugin.getInteractedTarget() || !config.npcShowInteract())) if (npc != null && config.npcShowHover() && (npc != plugin.getInteractedTarget() || !config.npcShowInteract()))
{ {
Color highlightColor = menuAction == MenuAction.NPC_SECOND_OPTION Color highlightColor = menuAction == MenuAction.NPC_SECOND_OPTION

View File

@@ -167,9 +167,8 @@ public class InteractHighlightPlugin extends Plugin
case NPC_FOURTH_OPTION: case NPC_FOURTH_OPTION:
case NPC_FIFTH_OPTION: case NPC_FIFTH_OPTION:
{ {
int id = menuOptionClicked.getId();
interactedObject = null; interactedObject = null;
interactedNpc = findNpc(id); interactedNpc = menuOptionClicked.getMenuEntry().getNpc();
attacked = menuOptionClicked.getMenuAction() == MenuAction.NPC_SECOND_OPTION || attacked = menuOptionClicked.getMenuAction() == MenuAction.NPC_SECOND_OPTION ||
menuOptionClicked.getMenuAction() == MenuAction.WIDGET_TARGET_ON_NPC && WidgetInfo.TO_GROUP(client.getSelectedWidget().getId()) == WidgetID.SPELLBOOK_GROUP_ID; menuOptionClicked.getMenuAction() == MenuAction.WIDGET_TARGET_ON_NPC && WidgetInfo.TO_GROUP(client.getSelectedWidget().getId()) == WidgetID.SPELLBOOK_GROUP_ID;
clickTick = client.getTickCount(); clickTick = client.getTickCount();
@@ -242,11 +241,6 @@ public class InteractHighlightPlugin extends Plugin
return null; return null;
} }
NPC findNpc(int id)
{
return client.getCachedNPCs()[id];
}
@Nullable @Nullable
Actor getInteractedTarget() Actor getInteractedTarget()
{ {

View File

@@ -723,11 +723,11 @@ public class MenuEntrySwapperPlugin extends Plugin
{ {
final MenuEntry entry = entries[idx]; final MenuEntry entry = entries[idx];
final MenuAction type = entry.getType(); final MenuAction type = entry.getType();
final int id = entry.getIdentifier();
if (type == MenuAction.EXAMINE_NPC) if (type == MenuAction.EXAMINE_NPC)
{ {
final NPC npc = client.getCachedNPCs()[id]; final NPC npc = entry.getNpc();
assert npc != null;
final NPCComposition composition = npc.getTransformedComposition(); final NPCComposition composition = npc.getTransformedComposition();
final String[] actions = composition.getActions(); final String[] actions = composition.getActions();
@@ -977,7 +977,8 @@ public class MenuEntrySwapperPlugin extends Plugin
if (NPC_MENU_TYPES.contains(menuAction)) if (NPC_MENU_TYPES.contains(menuAction))
{ {
final NPC npc = client.getCachedNPCs()[eventId]; final NPC npc = menuEntry.getNpc();
assert npc != null;
final NPCComposition composition = npc.getTransformedComposition(); final NPCComposition composition = npc.getTransformedComposition();
Integer customOption = getNpcSwapConfig(composition.getId()); Integer customOption = getNpcSwapConfig(composition.getId());

View File

@@ -26,7 +26,6 @@
package net.runelite.client.plugins.npchighlight; package net.runelite.client.plugins.npchighlight;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color; import java.awt.Color;
import java.time.Instant; import java.time.Instant;
@@ -48,7 +47,6 @@ import net.runelite.api.GraphicID;
import net.runelite.api.GraphicsObject; import net.runelite.api.GraphicsObject;
import net.runelite.api.KeyCode; import net.runelite.api.KeyCode;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
import net.runelite.api.MenuEntry; import net.runelite.api.MenuEntry;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
@@ -89,10 +87,6 @@ public class NpcIndicatorsPlugin extends Plugin
private static final String TAG_ALL = "Tag-All"; private static final String TAG_ALL = "Tag-All";
private static final String UNTAG_ALL = "Un-tag-All"; private static final String UNTAG_ALL = "Un-tag-All";
private static final Set<MenuAction> NPC_MENU_ACTIONS = ImmutableSet.of(MenuAction.NPC_FIRST_OPTION, MenuAction.NPC_SECOND_OPTION,
MenuAction.NPC_THIRD_OPTION, MenuAction.NPC_FOURTH_OPTION, MenuAction.NPC_FIFTH_OPTION, MenuAction.WIDGET_TARGET_ON_NPC,
MenuAction.ITEM_USE_ON_NPC);
@Inject @Inject
private Client client; private Client client;
@@ -239,46 +233,19 @@ public class NpcIndicatorsPlugin extends Plugin
@Subscribe @Subscribe
public void onMenuEntryAdded(MenuEntryAdded event) public void onMenuEntryAdded(MenuEntryAdded event)
{ {
int type = event.getType(); final MenuEntry menuEntry = event.getMenuEntry();
final MenuAction menuAction = menuEntry.getType();
final NPC npc = menuEntry.getNpc();
if (type >= MENU_ACTION_DEPRIORITIZE_OFFSET) if (npc == null)
{ {
type -= MENU_ACTION_DEPRIORITIZE_OFFSET; return;
} }
final MenuAction menuAction = MenuAction.of(type); if (menuAction == MenuAction.EXAMINE_NPC && client.isKeyPressed(KeyCode.KC_SHIFT))
if (NPC_MENU_ACTIONS.contains(menuAction))
{
NPC npc = client.getCachedNPCs()[event.getIdentifier()];
Color color = null;
if (npc.isDead())
{
color = config.deadNpcMenuColor();
}
if (color == null && highlightedNpcs.containsKey(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
{
color = config.highlightColor();
}
if (color != null)
{
MenuEntry[] menuEntries = client.getMenuEntries();
final MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), color);
menuEntry.setTarget(target);
}
}
else if (menuAction == MenuAction.EXAMINE_NPC && client.isKeyPressed(KeyCode.KC_SHIFT))
{ {
// Add tag and tag-all options // Add tag and tag-all options
final int id = event.getIdentifier(); if (npc.getName() == null)
final NPC[] cachedNPCs = client.getCachedNPCs();
final NPC npc = cachedNPCs[id];
if (npc == null || npc.getName() == null)
{ {
return; return;
} }
@@ -306,6 +273,25 @@ public class NpcIndicatorsPlugin extends Plugin
.setType(MenuAction.RUNELITE) .setType(MenuAction.RUNELITE)
.onClick(this::tag); .onClick(this::tag);
} }
else
{
Color color = null;
if (npc.isDead())
{
color = config.deadNpcMenuColor();
}
if (color == null && highlightedNpcs.containsKey(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
{
color = config.highlightColor();
}
if (color != null)
{
final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), color);
menuEntry.setTarget(target);
}
}
} }
private void tag(MenuEntry entry) private void tag(MenuEntry entry)

View File

@@ -159,8 +159,7 @@ public class OpponentInfoPlugin extends Plugin
return; return;
} }
int npcIndex = menuEntryAdded.getIdentifier(); NPC npc = menuEntryAdded.getMenuEntry().getNpc();
NPC npc = client.getCachedNPCs()[npcIndex];
if (npc == null) if (npc == null)
{ {
return; return;

View File

@@ -116,7 +116,7 @@ class PrayerBarOverlay extends Overlay
graphics.fillRect(barX + xOffset, barY + HD_PRAYER_BAR_PADDING, 1, barHeight - HD_PRAYER_BAR_PADDING * 2); graphics.fillRect(barX + xOffset, barY + HD_PRAYER_BAR_PADDING, 1, barHeight - HD_PRAYER_BAR_PADDING * 2);
} }
return new Dimension(barWidth, barHeight); return null;
} }
// Draw bar // Draw bar
@@ -145,7 +145,7 @@ class PrayerBarOverlay extends Overlay
graphics.fillRect(barX + xOffset, barY, 1, barHeight); graphics.fillRect(barX + xOffset, barY, 1, barHeight);
} }
return new Dimension(barWidth, barHeight); return null;
} }
void onTick() void onTick()

View File

@@ -151,8 +151,7 @@ class PrayerDoseOverlay extends Overlay
graphics.setColor(ColorUtil.colorLerp(START_COLOR, END_COLOR, Math.sin(t))); graphics.setColor(ColorUtil.colorLerp(START_COLOR, END_COLOR, Math.sin(t)));
graphics.setStroke(new BasicStroke(2)); graphics.setStroke(new BasicStroke(2));
graphics.drawOval(orbInnerX, orbInnerY, orbInnerSize, orbInnerSize); graphics.drawOval(orbInnerX, orbInnerY, orbInnerSize, orbInnerSize);
return null;
return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());
} }
} }

View File

@@ -91,7 +91,6 @@ class PrayerFlickOverlay extends Overlay
graphics.setColor(Color.cyan); graphics.setColor(Color.cyan);
graphics.fillRect(orbInnerX + xOffset, orbInnerY + yOffset, 1, indicatorHeight); graphics.fillRect(orbInnerX + xOffset, orbInnerY + yOffset, 1, indicatorHeight);
return null;
return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());
} }
} }

View File

@@ -160,7 +160,7 @@ public class RandomEventPlugin extends Plugin
&& event.getType() <= MenuAction.NPC_FIFTH_OPTION.getId() && event.getType() <= MenuAction.NPC_FIFTH_OPTION.getId()
&& EVENT_OPTIONS.contains(event.getOption())) && EVENT_OPTIONS.contains(event.getOption()))
{ {
NPC npc = client.getCachedNPCs()[event.getIdentifier()]; NPC npc = event.getMenuEntry().getNpc();
if (npc != null && EVENT_NPCS.contains(npc.getId()) && npc != currentRandomEvent && config.removeMenuOptions()) if (npc != null && EVENT_NPCS.contains(npc.getId()) && npc != currentRandomEvent && config.removeMenuOptions())
{ {
client.setMenuEntries(Arrays.copyOf(client.getMenuEntries(), client.getMenuEntries().length - 1)); client.setMenuEntries(Arrays.copyOf(client.getMenuEntries(), client.getMenuEntries().length - 1));

View File

@@ -279,7 +279,8 @@ public class WikiPlugin extends Plugin
case WIDGET_TARGET_ON_NPC: case WIDGET_TARGET_ON_NPC:
{ {
type = "npc"; type = "npc";
NPC npc = client.getCachedNPCs()[ev.getId()]; NPC npc = ev.getMenuEntry().getNpc();
assert npc != null;
NPCComposition nc = npc.getTransformedComposition(); NPCComposition nc = npc.getTransformedComposition();
id = nc.getId(); id = nc.getId();
name = nc.getName(); name = nc.getName();

View File

@@ -357,7 +357,7 @@ public class OverlayRenderer extends MouseAdapter
if (!bounds.isEmpty()) if (!bounds.isEmpty())
{ {
if (inOverlayManagingMode) if (inOverlayManagingMode && overlay.isMovable())
{ {
Color boundsColor; Color boundsColor;
if (inOverlayResizingMode && currentManagedOverlay == overlay) if (inOverlayResizingMode && currentManagedOverlay == overlay)
@@ -407,7 +407,7 @@ public class OverlayRenderer extends MouseAdapter
// See if we've clicked on an overlay // See if we've clicked on an overlay
currentManagedOverlay = lastHoveredOverlay; currentManagedOverlay = lastHoveredOverlay;
if (currentManagedOverlay == null) if (currentManagedOverlay == null || !currentManagedOverlay.isMovable())
{ {
return mouseEvent; return mouseEvent;
} }

View File

@@ -136,8 +136,7 @@ public class WidgetOverlay extends Overlay
if (getPreferredLocation() != null || getPreferredPosition() != null) if (getPreferredLocation() != null || getPreferredPosition() != null)
{ {
// The widget relative pos is relative to the parent // The widget relative pos is relative to the parent
widget.setRelativeX(bounds.x - parent.x); widget.setForcedPosition(bounds.x - parent.x, bounds.y - parent.y);
widget.setRelativeY(bounds.y - parent.y);
} }
else else
{ {
@@ -145,6 +144,7 @@ public class WidgetOverlay extends Overlay
{ {
revalidate = false; revalidate = false;
log.debug("Revalidating {}", widgetInfo); log.debug("Revalidating {}", widgetInfo);
widget.setForcedPosition(-1, -1);
// Revalidate the widget to reposition it back to its normal location after an overlay reset // Revalidate the widget to reposition it back to its normal location after an overlay reset
widget.revalidate(); widget.revalidate();
} }

View File

@@ -33,7 +33,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import static net.runelite.api.MenuAction.CC_OP;
import static net.runelite.api.MenuAction.RUNELITE; import static net.runelite.api.MenuAction.RUNELITE;
import net.runelite.api.MenuEntry; import net.runelite.api.MenuEntry;
import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuEntryAdded;
@@ -99,13 +98,7 @@ public class MenuManagerTest
menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null); menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null);
menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null); menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null);
menuManager.onMenuEntryAdded(new MenuEntryAdded( menuManager.onMenuEntryAdded(new MenuEntryAdded(createMenuEntry("Cancel", "", MenuAction.CC_OP, MINIMAP_WORLDMAP_OPTIONS.getPackedId())));
CANCEL.getOption(),
CANCEL.getTarget(),
CC_OP.getId(),
CANCEL.getIdentifier(),
CANCEL.getParam0(),
CANCEL.getParam1()));
verify(client, times(3)).createMenuEntry(anyInt()); verify(client, times(3)).createMenuEntry(anyInt());

View File

@@ -28,8 +28,11 @@ import java.util.function.Consumer;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Setter; import lombok.Setter;
import net.runelite.api.Actor;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry; import net.runelite.api.MenuEntry;
import net.runelite.api.NPC;
import net.runelite.api.Player;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@@ -48,6 +51,8 @@ public class TestMenuEntry implements MenuEntry
private int itemId = -1; private int itemId = -1;
@Setter @Setter
private Widget widget; private Widget widget;
@Setter
private Actor actor;
@Override @Override
public String getOption() public String getOption()
@@ -239,4 +244,25 @@ public class TestMenuEntry implements MenuEntry
{ {
return widget; return widget;
} }
@Nullable
@Override
public NPC getNpc()
{
return actor instanceof NPC ? (NPC) actor : null;
}
@Nullable
@Override
public Player getPlayer()
{
return actor instanceof Player ? (Player) actor : null;
}
@Nullable
@Override
public Actor getActor()
{
return actor;
}
} }

View File

@@ -86,6 +86,7 @@ public class MenuEntrySwapperPluginTest
@Inject @Inject
MenuEntrySwapperPlugin menuEntrySwapperPlugin; MenuEntrySwapperPlugin menuEntrySwapperPlugin;
private NPC npc;
private MenuEntry[] entries; private MenuEntry[] entries;
@Before @Before
@@ -96,10 +97,9 @@ public class MenuEntrySwapperPluginTest
when(client.getGameState()).thenReturn(GameState.LOGGED_IN); when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
when(client.getObjectDefinition(anyInt())).thenReturn(mock(ObjectComposition.class)); when(client.getObjectDefinition(anyInt())).thenReturn(mock(ObjectComposition.class));
NPC npc = mock(NPC.class); npc = mock(NPC.class);
NPCComposition composition = mock(NPCComposition.class); NPCComposition composition = mock(NPCComposition.class);
when(npc.getTransformedComposition()).thenReturn(composition); when(npc.getTransformedComposition()).thenReturn(composition);
when(client.getCachedNPCs()).thenReturn(new NPC[] { npc });
when(client.getMenuEntries()).thenAnswer((Answer<MenuEntry[]>) invocationOnMock -> when(client.getMenuEntries()).thenAnswer((Answer<MenuEntry[]>) invocationOnMock ->
{ {
@@ -117,18 +117,19 @@ public class MenuEntrySwapperPluginTest
menuEntrySwapperPlugin.setupSwaps(); menuEntrySwapperPlugin.setupSwaps();
} }
private static MenuEntry menu(String option, String target, MenuAction menuAction) private MenuEntry menu(String option, String target, MenuAction menuAction)
{ {
return menu(option, target, menuAction, 0); return menu(option, target, menuAction, 0);
} }
private static MenuEntry menu(String option, String target, MenuAction menuAction, int identifier) private MenuEntry menu(String option, String target, MenuAction menuAction, int identifier)
{ {
MenuEntry menuEntry = new TestMenuEntry(); TestMenuEntry menuEntry = new TestMenuEntry();
menuEntry.setOption(option); menuEntry.setOption(option);
menuEntry.setTarget(target); menuEntry.setTarget(target);
menuEntry.setType(menuAction); menuEntry.setType(menuAction);
menuEntry.setIdentifier(identifier); menuEntry.setIdentifier(identifier);
menuEntry.setActor(npc);
return menuEntry; return menuEntry;
} }

View File

@@ -34,7 +34,6 @@ import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.NpcChanged; import net.runelite.api.events.NpcChanged;
@@ -109,11 +108,12 @@ public class NpcIndicatorsPluginTest
when(npc.isDead()).thenReturn(true); when(npc.isDead()).thenReturn(true);
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0 TestMenuEntry entry = new TestMenuEntry();
entry.setTarget("Goblin");
entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId());
entry.setActor(npc);
MenuEntry entry = new TestMenuEntry(); MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry);
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry});
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
assertEquals("<col=ff0000>Goblin", entry.getTarget()); // red assertEquals("<col=ff0000>Goblin", entry.getTarget()); // red
@@ -133,11 +133,12 @@ public class NpcIndicatorsPluginTest
when(npc.getName()).thenReturn("Goblin"); when(npc.getName()).thenReturn("Goblin");
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0 TestMenuEntry entry = new TestMenuEntry();
entry.setTarget("Goblin");
entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId());
entry.setActor(npc);
MenuEntry entry = new TestMenuEntry(); MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry);
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry});
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
assertEquals("<col=0000ff>Goblin", entry.getTarget()); // blue assertEquals("<col=0000ff>Goblin", entry.getTarget()); // blue

View File

@@ -1089,13 +1089,6 @@ public abstract class RSClientMixin implements RSClient
client.getMenuTargets()[tmpOptionsCount] = "null"; client.getMenuTargets()[tmpOptionsCount] = "null";
} }
String menuOption = client.getMenuOptions()[tmpOptionsCount];
String menuTarget = client.getMenuTargets()[tmpOptionsCount];
int menuOpcode = client.getMenuOpcodes()[tmpOptionsCount];
int menuIdentifier = client.getMenuIdentifiers()[tmpOptionsCount];
int menuArgument1 = client.getMenuArguments1()[tmpOptionsCount];
int menuArgument2 = client.getMenuArguments2()[tmpOptionsCount];
if (rl$menuEntries[tmpOptionsCount] == null) if (rl$menuEntries[tmpOptionsCount] == null)
{ {
rl$menuEntries[tmpOptionsCount] = newRuneliteMenuEntry(tmpOptionsCount); rl$menuEntries[tmpOptionsCount] = newRuneliteMenuEntry(tmpOptionsCount);
@@ -1106,13 +1099,9 @@ public abstract class RSClientMixin implements RSClient
} }
MenuEntryAdded menuEntryAdded = new MenuEntryAdded( MenuEntryAdded menuEntryAdded = new MenuEntryAdded(
menuOption, rl$menuEntries[tmpOptionsCount]
menuTarget,
menuOpcode,
menuIdentifier,
menuArgument1,
menuArgument2
); );
client.getCallbacks().post(menuEntryAdded); client.getCallbacks().post(menuEntryAdded);
if (menuEntryAdded.isModified() && client.getMenuOptionCount() == optionCount) if (menuEntryAdded.isModified() && client.getMenuOptionCount() == optionCount)

View File

@@ -44,6 +44,7 @@ import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetInfo.TO_CHILD; import static net.runelite.api.widgets.WidgetInfo.TO_CHILD;
import static net.runelite.api.widgets.WidgetInfo.TO_GROUP; import static net.runelite.api.widgets.WidgetInfo.TO_GROUP;
import net.runelite.api.widgets.WidgetItem; import net.runelite.api.widgets.WidgetItem;
import net.runelite.api.widgets.WidgetPositionMode;
import net.runelite.rs.api.RSClient; import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSModel; import net.runelite.rs.api.RSModel;
import net.runelite.rs.api.RSNode; import net.runelite.rs.api.RSNode;
@@ -66,6 +67,10 @@ public abstract class RSWidgetMixin implements RSWidget
private int rl$x; private int rl$x;
@Inject @Inject
private int rl$y; private int rl$y;
@Inject
private short forcedX;
@Inject
private short forcedY;
@Inject @Inject
RSWidgetMixin() RSWidgetMixin()
@@ -73,6 +78,8 @@ public abstract class RSWidgetMixin implements RSWidget
rl$parentId = -1; rl$parentId = -1;
rl$x = -1; rl$x = -1;
rl$y = -1; rl$y = -1;
forcedX = -1;
forcedY = -1;
} }
@Inject @Inject
@@ -642,4 +649,99 @@ public abstract class RSWidgetMixin implements RSWidget
return new Point(dragOffsetX, dragOffsetY); return new Point(dragOffsetX, dragOffsetY);
} }
@Inject
public void setForcedX()
{
if (this.forcedX > -1)
{
this.setRelativeX(this.forcedX);
}
}
@Inject
public void setForcedY()
{
if (this.forcedY > -1)
{
this.setRelativeY(this.forcedY);
}
}
@Inject
@Override
public void setForcedPosition(int x, int y)
{
this.forcedX = (short) x;
this.forcedY = (short) y;
this.setRelativeX(x);
this.setRelativeY(y);
}
@Copy("alignWidgetPosition")
@Replace("alignWidgetPosition")
public static void alignWidgetPosition(Widget widget, int x, int y)
{
if (widget.getXPositionMode() == WidgetPositionMode.ABSOLUTE_LEFT)
{
widget.setRelativeX(widget.getOriginalX());
widget.setForcedX();
}
else if (widget.getXPositionMode() == WidgetPositionMode.ABSOLUTE_CENTER)
{
widget.setRelativeX(widget.getOriginalX() + (x - widget.getWidth()) / 2);
widget.setForcedX();
}
else if (widget.getXPositionMode() == WidgetPositionMode.ABSOLUTE_RIGHT)
{
widget.setRelativeX(x - widget.getWidth() - widget.getOriginalX());
widget.setForcedX();
}
else if (widget.getXPositionMode() == WidgetPositionMode.LEFT_16384THS)
{
widget.setRelativeX(widget.getOriginalX() * x >> 14);
widget.setForcedX();
}
else if (widget.getXPositionMode() == WidgetPositionMode.CENTER_16384THS)
{
widget.setRelativeX((widget.getOriginalX() * x >> 14) + (x - widget.getWidth()) / 2);
widget.setForcedX();
}
else
{
widget.setRelativeX(x - widget.getWidth() - (widget.getOriginalX() * x >> 14));
widget.setForcedX();
}
if (widget.getYPositionMode() == WidgetPositionMode.ABSOLUTE_TOP)
{
widget.setRelativeY(widget.getOriginalY());
widget.setForcedY();
}
else if (widget.getYPositionMode() == WidgetPositionMode.ABSOLUTE_CENTER)
{
widget.setRelativeY((y - widget.getHeight()) / 2 + widget.getOriginalY());
widget.setForcedY();
}
else if (widget.getYPositionMode() == WidgetPositionMode.ABSOLUTE_BOTTOM)
{
widget.setRelativeY(y - widget.getHeight() - widget.getOriginalY());
widget.setForcedY();
}
else if (widget.getYPositionMode() == WidgetPositionMode.TOP_16384THS)
{
widget.setRelativeY(y * widget.getOriginalY() >> 14);
widget.setForcedY();
}
else if (widget.getYPositionMode() == WidgetPositionMode.CENTER_16384THS)
{
widget.setRelativeY((y - widget.getHeight()) / 2 + (y * widget.getOriginalY() >> 14));
widget.setForcedY();
}
else
{
widget.setRelativeY(y - widget.getHeight() - (y * widget.getOriginalY() >> 14));
widget.setForcedY();
}
}
} }

View File

@@ -1,8 +1,13 @@
import java.util.function.Consumer; import java.util.function.Consumer;
import net.runelite.api.Actor;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry; import net.runelite.api.MenuEntry;
import net.runelite.api.NPC;
import net.runelite.api.Player;
import net.runelite.api.events.NpcSpawned;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.rs.api.RSClient; import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSNPC;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import sun.reflect.generics.reflectiveObjects.NotImplementedException;
public class RuneLiteMenuEntry implements MenuEntry public class RuneLiteMenuEntry implements MenuEntry
@@ -455,6 +460,82 @@ public class RuneLiteMenuEntry implements MenuEntry
return widget; return widget;
} }
@Override
public NPC getNpc()
{
NPC[] npcs = client.getCachedNPCs();
NPC npc = null;
MenuAction menuAction = this.getType();
if (menuAction == MenuAction.NPC_FIRST_OPTION ||
menuAction == MenuAction.NPC_SECOND_OPTION ||
menuAction == MenuAction.NPC_THIRD_OPTION ||
menuAction == MenuAction.NPC_FOURTH_OPTION ||
menuAction == MenuAction.NPC_FIFTH_OPTION ||
menuAction == MenuAction.WIDGET_TARGET_ON_NPC)
{
int identifier = this.getIdentifier();
if (identifier >= 0 && identifier < npcs.length)
{
npc = npcs[identifier];
}
}
return npc;
}
@Override
public Player getPlayer()
{
Player[] players = client.getCachedPlayers();
Player player = null;
MenuAction menuAction = this.getType();
if (menuAction == MenuAction.PLAYER_FIRST_OPTION ||
menuAction == MenuAction.PLAYER_SECOND_OPTION ||
menuAction == MenuAction.PLAYER_THIRD_OPTION ||
menuAction == MenuAction.PLAYER_FOURTH_OPTION ||
menuAction == MenuAction.PLAYER_FIFTH_OPTION ||
menuAction == MenuAction.PLAYER_SIXTH_OPTION ||
menuAction == MenuAction.PLAYER_SEVENTH_OPTION ||
menuAction == MenuAction.PLAYER_EIGTH_OPTION ||
menuAction == MenuAction.WIDGET_TARGET_ON_PLAYER ||
menuAction == MenuAction.RUNELITE_PLAYER)
{
int identifier = this.getIdentifier();
if (identifier >= 0 && identifier < players.length)
{
player = players[identifier];
}
}
return player;
}
@Override
public Actor getActor()
{
NPC npc = getNpc();
if (npc != null)
{
return npc;
}
Player player = getPlayer();
if (player != null)
{
return player;
}
return null;
}
@Override @Override
public int hashCode() public int hashCode()
{ {