menus: add widgetmenuoption constructor for widgetid

This is for pluginhub plugins which want to add a managed custom menu for a widget with no corresponding widgetinfo
This commit is contained in:
Adam
2021-03-22 19:53:01 -04:00
parent e7f50433a3
commit d629d422f7
3 changed files with 42 additions and 37 deletions

View File

@@ -24,11 +24,12 @@
*/
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 NOT fired for non-MenuManager menu options
* A MenuManager widget menu was clicked. This event is fired only for MenuManager managed custom menus.
*/
@Data
public class WidgetMenuOptionClicked
@@ -42,7 +43,12 @@ public class WidgetMenuOptionClicked
*/
private String menuTarget;
/**
* The type of widget that was clicked.
* 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;
}

View File

@@ -41,7 +41,6 @@ import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.PlayerMenuOptionsChanged;
import net.runelite.api.events.WidgetMenuOptionClicked;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
@@ -78,8 +77,7 @@ public class MenuManager
*/
public void addManagedCustomMenu(WidgetMenuOption customMenuOption)
{
WidgetInfo widget = customMenuOption.getWidget();
managedMenuOptions.put(widget.getId(), customMenuOption);
managedMenuOptions.put(customMenuOption.getWidgetId(), customMenuOption);
}
/**
@@ -89,8 +87,7 @@ public class MenuManager
*/
public void removeManagedCustomMenu(WidgetMenuOption customMenuOption)
{
WidgetInfo widget = customMenuOption.getWidget();
managedMenuOptions.remove(widget.getId(), customMenuOption);
managedMenuOptions.remove(customMenuOption.getWidgetId(), customMenuOption);
}
private boolean menuContainsCustomMenu(WidgetMenuOption customMenuOption)
@@ -208,6 +205,7 @@ public class MenuManager
customMenu.setMenuOption(event.getMenuOption());
customMenu.setMenuTarget(event.getMenuTarget());
customMenu.setWidget(curMenuOption.getWidget());
customMenu.setWidgetId(curMenuOption.getWidgetId());
eventBus.post(customMenu);
return;
}

View File

@@ -24,9 +24,11 @@
*/
package net.runelite.client.menus;
import net.runelite.api.widgets.WidgetInfo;
import java.awt.Color;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.ui.JagexColors;
import net.runelite.client.util.ColorUtil;
@@ -35,20 +37,33 @@ public final class WidgetMenuOption
/**
* The left hand text to be displayed on the menu option. (ex. the menuOption of "Drop Bones" is "Drop")
*/
@Getter
@Setter
private String menuOption;
/**
* The right hand text to be displayed on the menu option. (ex. the menuTarget of "Drop Bones" is "Bones")
*/
@Getter
private String menuTarget;
/**
* The color that the menuTarget should be. Defaults to the brownish color that most menu options have.
*/
@Getter
@Setter
private Color color = JagexColors.MENU_TARGET;
/**
* The widgetinfo to add the option to, if available
*/
@Nullable
@Getter
private final WidgetInfo widget;
/**
* The widget to add the option to
*/
private final WidgetInfo widget;
@Getter
private final int widgetId;
/**
* Creates a menu to be added to right click menus. The menu will only be added if match is found within the menu options
@@ -62,11 +77,22 @@ public final class WidgetMenuOption
this.menuOption = menuOption;
setMenuTarget(menuTarget);
this.widget = widget;
this.widgetId = widget.getId();
}
public void setMenuOption(String option)
/**
* Creates a menu to be added to right click menus. The menu will only be added if match is found within the menu options
*
* @param menuOption Option text of this right click option
* @param menuTarget Target text of this right click option
* @param widgetId The widget to attach this option to
*/
public WidgetMenuOption(String menuOption, String menuTarget, int widgetId)
{
menuOption = option;
this.menuOption = menuOption;
setMenuTarget(menuTarget);
this.widget = null;
this.widgetId = widgetId;
}
/**
@@ -78,29 +104,4 @@ public final class WidgetMenuOption
{
menuTarget = ColorUtil.wrapWithColorTag(target, color);
}
public String getMenuOption()
{
return menuOption;
}
public String getMenuTarget()
{
return menuTarget;
}
public WidgetInfo getWidget()
{
return widget;
}
public Color getColor()
{
return color;
}
public void setColor(Color col)
{
color = col;
}
}