runelite-client: add menu action enum

This commit is contained in:
Adam
2017-07-08 13:33:09 -04:00
parent 24a6291145
commit 10b4ce6f0f
4 changed files with 95 additions and 18 deletions

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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);
}