use of org.powerbot.script.MenuCommand in project powerbot by powerbot.
the class Menu method items.
/**
* Returns an array of all the current menu items ([action_1 option_1, action_2 option_2, ...]).
*
* @return the array of menu items
*/
public String[] items() {
final MenuCommand[] m = commands();
final int len = m.length;
final String[] arr = new String[len];
for (int i = 0; i < len; i++) {
arr[i] = m[i].action + " " + m[i].option;
arr[i] = arr[i].trim();
}
return arr;
}
use of org.powerbot.script.MenuCommand in project powerbot by powerbot.
the class Menu method commands.
/**
* Returns an array of the current menu commands available.
*
* @return A MenuCommand array.
*/
public MenuCommand[] commands() {
final String[] actions = this.actions.get(), options = this.options.get();
final int len;
if ((len = actions.length) != options.length) {
return new MenuCommand[0];
}
final MenuCommand[] arr = new MenuCommand[len];
for (int i = 0; i < len; i++) {
arr[i] = new MenuCommand(actions[i], options[i]);
}
return arr;
}
use of org.powerbot.script.MenuCommand in project powerbot by powerbot.
the class Menu method indexOf.
/**
* Provides the index of the menu command given the specified filter.
*
* @param filter The filter to apply to the menu.
* @return The index of the menu command, or {@code -1} if it was not found.
*/
public int indexOf(final Filter<? super MenuCommand> filter) {
final String[] actions = this.actions.get(), options = this.options.get();
final int len;
if ((len = actions.length) != options.length) {
return -1;
}
for (int i = 0; i < len; i++) {
if (filter.accept(new MenuCommand(actions[i], options[i]))) {
return i;
}
}
return -1;
}
use of org.powerbot.script.MenuCommand in project powerbot by powerbot.
the class Menu method tooltip.
/**
* Returns the currently present tooltip command.
*
* @return the tooltip
*/
public MenuCommand tooltip() {
final Component comp = tooltipComp == null ? (tooltipComp = getTooltipComponent()) : tooltipComp;
if (comp == null || !comp.parent().visible()) {
return new MenuCommand("", "");
}
final String text = comp.text();
// index of the enclosing action tag
final int endActionIndex = text.indexOf("<", 1);
if (endActionIndex == -1) {
return new MenuCommand("", "");
}
final String action = text.substring(0, endActionIndex).trim();
int bracketCount = 0;
for (final char ch : text.toCharArray()) {
if (ch == '<') {
bracketCount++;
}
}
if (bracketCount <= 2) {
return new MenuCommand(action, "");
}
final String option = text.substring(endActionIndex - 1, text.length()).trim();
return new MenuCommand(action, option);
}
use of org.powerbot.script.MenuCommand in project powerbot by powerbot.
the class Menu method commands.
/**
* Returns an array of all the current menu commands.
*
* @return the array of menu commands
*/
public MenuCommand[] commands() {
final List<MenuItemNode> items = getMenuItemNodes();
final int size = items.size();
final MenuCommand[] arr = new MenuCommand[size];
for (int i = 0; i < size; i++) {
final MenuItemNode node = items.get(i);
arr[i] = new MenuCommand(node.getAction(), node.getOption());
}
return arr;
}
Aggregations