api: make MenuEntry an interface

This adds a new createMenuEntry api method to make MenuEntries instead.
Menu entries now have an associated callback called when they are
clicked on, avoiding most plugins from having to hook separately to
detect the menu click. Additionally get/set type has changed to take a
MenuAction.
This commit is contained in:
Adam
2021-12-04 15:28:27 -05:00
parent 479de04b73
commit 409d0dda76
38 changed files with 665 additions and 966 deletions

View File

@@ -593,6 +593,13 @@ public interface Client extends GameEngine
*/
World[] getWorldList();
/**
* Create a new menu entry
* @param idx the index to create the menu entry at. Accepts negative indexes eg. -1 inserts at the end.
* @return the newly created menu entry
*/
MenuEntry createMenuEntry(int idx);
/**
* Gets an array of currently open right-click menu entries that can be
* clicked and activated.

View File

@@ -24,46 +24,72 @@
*/
package net.runelite.api;
import lombok.Data;
import java.util.function.Consumer;
/**
* A menu entry in a right-click menu.
*/
@Data
public class MenuEntry
public interface MenuEntry
{
/**
* The option text added to the menu. (ie. "Walk here", "Use")
*/
private String option;
String getOption();
MenuEntry setOption(String option);
/**
* The target of the action. (ie. Item or Actor name)
* <p>
* If the option does not apply to any target, this field
* will be set to empty string.
*/
private String target;
String getTarget();
MenuEntry setTarget(String target);
/**
* An identifier value for the target of the action.
*/
private int identifier;
int getIdentifier();
MenuEntry setIdentifier(int identifier);
/**
* The action the entry will trigger.
*/
private int type;
MenuAction getType();
MenuEntry setType(MenuAction type);
/**
* An additional parameter for the action.
*/
private int param0;
int getParam0();
MenuEntry setParam0(int param0);
/**
* A second additional parameter for the action.
*/
private int param1;
int getParam1();
MenuEntry setParam1(int param1);
/**
* If this field is true and you have single mouse button on and this entry is
* If this is true and you have single mouse button on and this entry is
* the top entry the right click menu will not be opened when you left click
*
* This is used for shift click
*/
private boolean forceLeftClick;
boolean isForceLeftClick();
MenuEntry setForceLeftClick(boolean forceLeftClick);
/**
* Deprioritized menus are sorted in the menu to be below the other menu entries.
* @return
*/
boolean isDeprioritized();
void setDeprioritized(boolean deprioritized);
/**
* Set a callback to be called when this menu option is clicked
* @param callback
* @return
*/
MenuEntry onClick(Consumer<MenuEntry> callback);
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.api.events;
import javax.annotation.Nullable;
import lombok.Data;
import net.runelite.api.widgets.WidgetInfo;
/**
* A MenuManager widget menu was clicked. This event is fired only for MenuManager managed custom menus.
*/
@Data
public class WidgetMenuOptionClicked
{
/**
* The clicked menu option.
*/
private String menuOption;
/**
* The clicked menu target.
*/
private String menuTarget;
/**
* The WidgetInfo of the widget that was clicked, if available.
*/
@Nullable
private WidgetInfo widget;
/**
* The widget id of the widget that was clicked.
*/
private int widgetId;
}