api: pass menu entry to menu clicked event and forward accessors
This commit is contained in:
@@ -24,8 +24,11 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.api.events;
|
package net.runelite.api.events;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.runelite.api.MenuAction;
|
import net.runelite.api.MenuAction;
|
||||||
|
import net.runelite.api.MenuEntry;
|
||||||
|
import net.runelite.api.widgets.Widget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An event where a menu option has been clicked.
|
* An event where a menu option has been clicked.
|
||||||
@@ -38,42 +41,77 @@ import net.runelite.api.MenuAction;
|
|||||||
* By default, when there is no action performed when left-clicking,
|
* By default, when there is no action performed when left-clicking,
|
||||||
* it seems that this event still triggers with the "Cancel" action.
|
* it seems that this event still triggers with the "Cancel" action.
|
||||||
*/
|
*/
|
||||||
@Data
|
@RequiredArgsConstructor
|
||||||
public class MenuOptionClicked
|
public class MenuOptionClicked
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Action parameter 0. Its value depends on the menuAction.
|
* The clicked menu entry
|
||||||
*/
|
*/
|
||||||
private int param0;
|
private final MenuEntry menuEntry;
|
||||||
/**
|
|
||||||
* Action parameter 1. Its value depends on the menuAction.
|
|
||||||
*/
|
|
||||||
private int param1;
|
|
||||||
/**
|
|
||||||
* The option text added to the menu.
|
|
||||||
*/
|
|
||||||
private String menuOption;
|
|
||||||
/**
|
|
||||||
* The target of the action.
|
|
||||||
*/
|
|
||||||
private String menuTarget;
|
|
||||||
/**
|
|
||||||
* The action performed.
|
|
||||||
*/
|
|
||||||
private MenuAction menuAction;
|
|
||||||
/**
|
|
||||||
* The ID of the object, actor, or item that the interaction targets.
|
|
||||||
*/
|
|
||||||
private int id;
|
|
||||||
/**
|
|
||||||
* The selected item index at the time of the option click.
|
|
||||||
*/
|
|
||||||
private int selectedItemIndex;
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the event has been consumed by a subscriber.
|
* Whether or not the event has been consumed by a subscriber.
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
private boolean consumed;
|
private boolean consumed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action parameter 0. Its value depends on the menuAction.
|
||||||
|
*/
|
||||||
|
public int getParam0()
|
||||||
|
{
|
||||||
|
return menuEntry.getParam0();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action parameter 1. Its value depends on the menuAction.
|
||||||
|
*/
|
||||||
|
public int getParam1()
|
||||||
|
{
|
||||||
|
return menuEntry.getParam1();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The option text added to the menu.
|
||||||
|
*/
|
||||||
|
public String getMenuOption()
|
||||||
|
{
|
||||||
|
return menuEntry.getOption();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The target of the action.
|
||||||
|
*/
|
||||||
|
public String getMenuTarget()
|
||||||
|
{
|
||||||
|
return menuEntry.getTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action performed.
|
||||||
|
*/
|
||||||
|
public MenuAction getMenuAction()
|
||||||
|
{
|
||||||
|
return menuEntry.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the object, actor, or item that the interaction targets.
|
||||||
|
*/
|
||||||
|
public int getId()
|
||||||
|
{
|
||||||
|
return menuEntry.getIdentifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the widget this menu entry is on, if this is a menu entry
|
||||||
|
* with an associated widget. Such as eg, CC_OP.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Widget getWidget()
|
||||||
|
{
|
||||||
|
return menuEntry.getWidget();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the event as having been consumed.
|
* Marks the event as having been consumed.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -89,12 +127,12 @@ public class MenuOptionClicked
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public int getActionParam()
|
public int getActionParam()
|
||||||
{
|
{
|
||||||
return param0;
|
return menuEntry.getParam0();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int getWidgetId()
|
public int getWidgetId()
|
||||||
{
|
{
|
||||||
return param1;
|
return menuEntry.getParam1();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ public class CannonPlugin extends Plugin
|
|||||||
// Check if cannonballs are being used on the cannon
|
// Check if cannonballs are being used on the cannon
|
||||||
if (event.getMenuAction() == MenuAction.ITEM_USE_ON_GAME_OBJECT)
|
if (event.getMenuAction() == MenuAction.ITEM_USE_ON_GAME_OBJECT)
|
||||||
{
|
{
|
||||||
final int idx = event.getSelectedItemIndex();
|
final int idx = client.getSelectedItemIndex();
|
||||||
final ItemContainer items = client.getItemContainer(InventoryID.INVENTORY);
|
final ItemContainer items = client.getItemContainer(InventoryID.INVENTORY);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -703,7 +703,7 @@ public class GroundItemsPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Item clickedItem = inventory.getItem(menuOptionClicked.getSelectedItemIndex());
|
final Item clickedItem = inventory.getItem(client.getSelectedItemIndex());
|
||||||
if (clickedItem == null)
|
if (clickedItem == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import static org.mockito.Mockito.lenient;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -164,10 +165,10 @@ public class ClueScrollPluginTest
|
|||||||
plugin.onGameTick(new GameTick());
|
plugin.onGameTick(new GameTick());
|
||||||
|
|
||||||
// Simulate clicking on the STASH
|
// Simulate clicking on the STASH
|
||||||
MenuOptionClicked menuOptionClicked = new MenuOptionClicked();
|
MenuOptionClicked menuOptionClicked = mock(MenuOptionClicked.class);
|
||||||
menuOptionClicked.setMenuOption("Search");
|
when(menuOptionClicked.getMenuOption()).thenReturn("Search");
|
||||||
menuOptionClicked.setMenuTarget("<col=ffff>STASH unit (easy)");
|
lenient().when(menuOptionClicked.getMenuTarget()).thenReturn("<col=ffff>STASH unit (easy)");
|
||||||
menuOptionClicked.setId(NullObjectID.NULL_28983);
|
when(menuOptionClicked.getId()).thenReturn(NullObjectID.NULL_28983);
|
||||||
plugin.onMenuOptionClicked(menuOptionClicked);
|
plugin.onMenuOptionClicked(menuOptionClicked);
|
||||||
|
|
||||||
// Check that the STASH is stored after withdrawing
|
// Check that the STASH is stored after withdrawing
|
||||||
|
|||||||
Reference in New Issue
Block a user