runelite-client: add menu action enum
This commit is contained in:
61
runelite-api/src/main/java/net/runelite/api/MenuAction.java
Normal file
61
runelite-api/src/main/java/net/runelite/api/MenuAction.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public enum MenuAction
|
||||
{
|
||||
EXAMINE_OBJECT(1002),
|
||||
EXAMINE_NPC(1003),
|
||||
EXAMINE_ITEM(1005),
|
||||
/**
|
||||
* Menu action injected by runelite for its menu items
|
||||
*/
|
||||
RUNELITE(1500),
|
||||
UNKNOWN(-1);
|
||||
|
||||
private final int id;
|
||||
|
||||
MenuAction(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public static MenuAction of(int id)
|
||||
{
|
||||
for (MenuAction action : values())
|
||||
{
|
||||
if (action.id == id)
|
||||
{
|
||||
return action;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ package net.runelite.client.callback;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.events.*;
|
||||
@@ -136,7 +138,7 @@ public class Hooks
|
||||
}
|
||||
}
|
||||
|
||||
public static void menuActionHook(int var0, int var1, int menuAction, int var3, String menuOption, String menuTarget, int var6, int var7)
|
||||
public static void menuActionHook(int var0, int var1, int menuAction, int id, String menuOption, String menuTarget, int var6, int var7)
|
||||
{
|
||||
/* Along the way, the RuneScape client may change a menuAction by incrementing it with 2000.
|
||||
* I have no idea why, but it does. Their code contains the same conditional statement.
|
||||
@@ -146,18 +148,24 @@ public class Hooks
|
||||
menuAction -= 2000;
|
||||
}
|
||||
|
||||
logger.debug("Menu action clicked: {} ({}) on {}", menuOption, menuAction, menuTarget.isEmpty() ? "<nothing>" : menuTarget);
|
||||
logger.debug("Menu action clicked: {} ({}) on {} ({})", menuOption, menuAction, menuTarget.isEmpty() ? "<nothing>" : menuTarget, id);
|
||||
|
||||
MenuOptionClicked playerMenuOptionClicked = new MenuOptionClicked();
|
||||
playerMenuOptionClicked.setMenuOption(menuOption);
|
||||
playerMenuOptionClicked.setMenuTarget(menuTarget);
|
||||
playerMenuOptionClicked.setMenuAction(menuAction);
|
||||
MenuOptionClicked menuOptionClicked = new MenuOptionClicked();
|
||||
menuOptionClicked.setMenuOption(menuOption);
|
||||
menuOptionClicked.setMenuTarget(menuTarget);
|
||||
menuOptionClicked.setMenuAction(MenuAction.of(menuAction));
|
||||
menuOptionClicked.setId(id);
|
||||
|
||||
runelite.getEventBus().post(playerMenuOptionClicked);
|
||||
runelite.getEventBus().post(menuOptionClicked);
|
||||
}
|
||||
|
||||
public static void addChatMessage(int type, String sender, String message, String clan)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Chat message type {}: {}", ChatMessageType.of(type), message);
|
||||
}
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage(type, sender, message, clan);
|
||||
|
||||
runelite.getEventBus().post(chatMessage);
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package net.runelite.client.events;
|
||||
|
||||
import net.runelite.api.MenuAction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robin
|
||||
@@ -32,7 +34,8 @@ public class MenuOptionClicked
|
||||
{
|
||||
private String menuOption;
|
||||
private String menuTarget;
|
||||
private int menuAction;
|
||||
private MenuAction menuAction;
|
||||
private int id;
|
||||
|
||||
public String getMenuOption()
|
||||
{
|
||||
@@ -54,14 +57,24 @@ public class MenuOptionClicked
|
||||
this.menuTarget = menuTarget;
|
||||
}
|
||||
|
||||
public int getMenuAction()
|
||||
public MenuAction getMenuAction()
|
||||
{
|
||||
return menuAction;
|
||||
}
|
||||
|
||||
public void setMenuAction(int menuAction)
|
||||
public void setMenuAction(MenuAction menuAction)
|
||||
{
|
||||
this.menuAction = menuAction;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.google.common.eventbus.Subscribe;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.events.MenuOptionClicked;
|
||||
import net.runelite.client.events.PlayerMenuOptionClicked;
|
||||
@@ -40,12 +41,6 @@ public class MenuManager
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(MenuManager.class);
|
||||
|
||||
/* 1007 is the highest number the rs client uses for actions. There is no way to see which ones are used,
|
||||
* so im starting from 1500. Its just a number well over their maximum, so if a new action gets added, chances are little
|
||||
* it interferes with the action the MenuManager uses.
|
||||
*/
|
||||
private static final int MENU_ACTION = 1500;
|
||||
|
||||
/*
|
||||
* The index needs to be between 4 and 7,
|
||||
*/
|
||||
@@ -103,7 +98,7 @@ public class MenuManager
|
||||
@Subscribe
|
||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||
{
|
||||
if (event.getMenuAction() != MENU_ACTION)
|
||||
if (event.getMenuAction() != MenuAction.RUNELITE)
|
||||
{
|
||||
return; // not a player menu
|
||||
}
|
||||
@@ -124,7 +119,7 @@ public class MenuManager
|
||||
|
||||
client.getPlayerOptions()[playerOptionIndex] = menuText;
|
||||
client.getPlayerOptionsPriorities()[playerOptionIndex] = true;
|
||||
client.getPlayerMenuType()[playerOptionIndex] = MENU_ACTION;
|
||||
client.getPlayerMenuType()[playerOptionIndex] = MenuAction.RUNELITE.getId();
|
||||
|
||||
playerMenuIndexMap.put(playerOptionIndex, menuText);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user