Skip to content

Commit

Permalink
Extend menu handler & item callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaroq7 committed Apr 11, 2016
1 parent ffa4e05 commit 70adea7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
25 changes: 21 additions & 4 deletions amxmodx/meta_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,14 +1072,31 @@ void C_ClientCommand(edict_t *pEntity)
if (item == MENU_BACK)
{
pMenu->Display(pPlayer->index, pPlayer->page - 1);
} else if (item == MENU_MORE) {
}
else if (item == MENU_MORE)
{
pMenu->Display(pPlayer->index, pPlayer->page + 1);
} else {
ret = executeForwards(pMenu->func, static_cast<cell>(pPlayer->index), static_cast<cell>(menu), static_cast<cell>(item));
}
else
{
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(item));

if (pItem)
{
ret = executeForwards(pMenu->func, static_cast<cell>(pPlayer->index), static_cast<cell>(menu), static_cast<cell>(item),
static_cast<cell>(pItem->access), pItem->cmd.chars(), pItem->name.chars(), static_cast<cell>(pItem->handler));
}
else
{
ret = executeForwards(pMenu->func, static_cast<cell>(pPlayer->index), static_cast<cell>(menu), static_cast<cell>(item), 0, "", "", 0);
}

if (ret & 2)
{
result = MRES_SUPERCEDE;
} else if (ret & 1) {
}
else if (ret & 1)
{
RETURN_META(MRES_SUPERCEDE);
}
}
Expand Down
11 changes: 7 additions & 4 deletions amxmodx/newmenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)

if (pItem->handler != -1)
{
ret = executeForwards(pItem->handler, static_cast<cell>(player), static_cast<cell>(thisId), static_cast<cell>(i));
ret = executeForwards(pItem->handler, static_cast<cell>(player), static_cast<cell>(thisId), static_cast<cell>(i),
static_cast<cell>(pItem->access), pItem->cmd.chars(), pItem->name.chars(), static_cast<cell>(pItem->handler));

if (ret == ITEM_ENABLED)
{
enabled = true;
Expand All @@ -441,7 +443,8 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)

if (pItem->pfn)
{
ret = (pItem->pfn)(player, thisId, i);
ret = (pItem->pfn)(player, thisId, i, pItem->access, pItem->cmd.chars(), pItem->name.chars(), pItem->handler);

if (ret == ITEM_ENABLED)
{
enabled = true;
Expand Down Expand Up @@ -633,7 +636,7 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
validate_menu_text(title);
char *handler = get_amxstring(amx, params[2], 1, len);

int func = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
int func = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_STRING, FP_STRING, FP_CELL, FP_DONE);

if (func == -1)
{
Expand Down Expand Up @@ -878,7 +881,7 @@ static cell AMX_NATIVE_CALL menu_makecallback(AMX *amx, cell *params)
int len;
char *name = get_amxstring(amx, params[1], 0, len);

int id = registerSPForwardByName(amx, name, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
int id = registerSPForwardByName(amx, name, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_STRING, FP_STRING, FP_CELL, FP_DONE);

if (id == -1)
{
Expand Down
2 changes: 1 addition & 1 deletion amxmodx/newmenus.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define MPROP_PADMENU 9
#define MPROP_SET_NUMBER_COLOR 10

typedef int (*MENUITEM_CALLBACK)(int, int, int);
typedef int (*MENUITEM_CALLBACK)(int, int, int, int, const char *, const char *, int);

class BlankItem
{
Expand Down
34 changes: 21 additions & 13 deletions plugins/include/newmenus.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@
*
* The handler function should be prototyped as:
*
* public <function>(id, menu, item)
* id - Client the menu is being acted upon.
* menu - Menu resource identifier.
* item - Item the client selected. If less than 0, the menu was
* cancelled and the item is a status code. menu_display
* should never be called immediately if the item is a status
* code, for re-entrancy reasons.
* public <function>(id, menu, item, access, const info[], const name[], callback)
* id - Client the menu is being acted upon.
* menu - Menu resource identifier.
* item - Item the client selected. If less than 0, the menu was
* cancelled and the item is a status code. menu_display
* should never be called immediately if the item is a status
* code, for re-entrancy reasons.
* access - Access of the selected item.
* info - Info string of the selected item.
* name - Name of the selected item.
* callback - Callback ID of the selected item.
*
* The handler function should always return PLUGIN_HANDLED to block
* any old menu handlers from potentially feeding on the menu, unless
Expand All @@ -67,12 +71,16 @@ native menu_create(const title[], const handler[], ml=0);
*
* The handler function should be prototyped as:
*
* public <function>(id, menu, item)
* id - Client index being displayed to.
* menu - Menu resource identifier.
* item - Item being drawn.
* <return> - ITEM_IGNORE to use the default functionality. ITEM_ENABLED to
* explicitly enable or ITEM_DISABLED to explicitly disable.
* public <function>(id, menu, item, access, const info[], const name[], callback)
* id - Client index being displayed to.
* menu - Menu resource identifier.
* item - Item being drawn.
* access - Item access.
* info - Item info string.
* name - Item name.
* callback - Item callback ID.
* <return> - ITEM_IGNORE to use the default functionality. ITEM_ENABLED to
* explicitly enable or ITEM_DISABLED to explicitly disable.
*
* @param function Function name.
* @return Menu callback ID.
Expand Down

0 comments on commit 70adea7

Please sign in to comment.