project: Implement the new menu entry handling

This commit is contained in:
Owain van Brakel
2021-12-16 09:45:44 +01:00
parent 7ef3e6b980
commit a42c845ad3
35 changed files with 665 additions and 402 deletions

View File

@@ -2124,24 +2124,6 @@ public interface Client extends GameEngine
*/
void scaleSprite(int[] canvas, int[] pixels, int color, int pixelX, int pixelY, int canvasIdx, int canvasOffset, int newWidth, int newHeight, int pixelWidth, int pixelHeight, int oldWidth);
/**
* Get the MenuEntry at client.getMenuOptionCount() - 1
* <p>
* This is useful so you don't have to use getMenuEntries,
* which will create a big array, when you only want to change
* the left click one.
*/
MenuEntry getLeftClickMenuEntry();
/**
* Set the MenuEntry at client.getMenuOptionCount() - 1
* <p>
* This is useful so you don't have to use setMenuEntries,
* which will arraycopy a big array to several smaller arrays lol,
* when you only want to change the left click one.
*/
void setLeftClickMenuEntry(MenuEntry entry);
/**
* If this field is set to true, getting 5 minute logged won't show
* the "You have been disconnected." message anymore.

View File

@@ -24,240 +24,72 @@
*/
package net.runelite.api;
import java.util.Arrays;
import java.util.function.Consumer;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* A menu entry in a right-click menu.
*/
@Data
@NoArgsConstructor
public class MenuEntry implements Cloneable
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.
* {@link MenuAction}
*/
private int opcode;
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;
public MenuEntry(String option, String target, int type, int opcode, int param0, int param1, boolean forceLeftClick)
{
this.option = option;
this.target = target;
this.identifier = type;
this.opcode = opcode;
this.param0 = param0;
this.param1 = param1;
this.forceLeftClick = forceLeftClick;
}
@Override
public MenuEntry clone()
{
try
{
return (MenuEntry) super.clone();
}
catch (CloneNotSupportedException ex)
{
throw new RuntimeException(ex);
}
}
public String getOption()
{
return option;
}
public MenuEntry setOption(String option)
{
this.option = option;
return this;
}
public String getTarget()
{
return target;
}
public MenuEntry setTarget(String target)
{
this.target = target;
return this;
}
public int getIdentifier()
{
return this.identifier;
}
public MenuEntry setIdentifier(int identifier)
{
this.identifier = identifier;
return this;
}
public MenuAction getType()
{
return MenuAction.of(this.opcode);
}
public MenuEntry setType(MenuAction type)
{
this.opcode = type.getId();
return this;
}
public int getParam0()
{
return this.param0;
}
public MenuEntry setParam0(int param0)
{
this.param0 = param0;
return this;
}
public int getParam1()
{
return this.param1;
}
public MenuEntry setParam1(int param1)
{
this.param1 = param1;
return this;
}
public boolean isForceLeftClick()
{
return this.forceLeftClick;
}
public MenuEntry setForceLeftClick(boolean forceLeftClick)
{
this.forceLeftClick = forceLeftClick;
return this;
}
public boolean isDeprioritized()
{
return opcode >= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
}
public MenuEntry setDeprioritized(boolean deprioritized)
{
if (deprioritized)
{
if (opcode < MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET)
{
opcode += MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
}
}
else
{
if (opcode >= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET)
{
opcode -= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
}
}
return this;
}
public MenuEntry onClick(Consumer<MenuEntry> callback)
{
return this;
}
public void setActionParam0(int i)
{
this.param0 = i;
}
public int getActionParam0()
{
return this.param0;
}
public void setActionParam1(int i)
{
this.param1 = i;
}
public int getActionParam1()
{
return this.param1;
}
public void setType(int i)
{
this.opcode = i;
}
public void setId(int i)
{
this.identifier = i;
}
public int getId()
{
return this.identifier;
}
boolean isForceLeftClick();
MenuEntry setForceLeftClick(boolean forceLeftClick);
/**
* Get opcode, but as it's enum counterpart
* Deprioritized menus are sorted in the menu to be below the other menu entries.
* @return
*/
public MenuAction getMenuAction()
{
return MenuAction.of(getOpcode());
}
boolean isDeprioritized();
MenuEntry setDeprioritized(boolean deprioritized);
// TODO: Remove this after properly implementing the menu
public void add(Client client)
{
MenuEntry[] menuEntries = client.getMenuEntries();
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1);
MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry();
menuEntry.setOption(option);
menuEntry.setTarget(target);
menuEntry.setParam0(param0);
menuEntry.setParam1(param1);
menuEntry.setIdentifier(identifier);
menuEntry.setType(MenuAction.of(getOpcode()));
client.setMenuEntries(menuEntries);
}
}
/**
* Set a callback to be called when this menu option is clicked
* @param callback
* @return
*/
MenuEntry onClick(Consumer<MenuEntry> callback);
}