Add menu pagination callback (#420)

* Add menu pagination callback

* Update test plugin
This commit is contained in:
KliPPy
2017-04-04 10:29:18 +02:00
committed by Vincent Herbet
parent ff488dd81f
commit 2863455185
6 changed files with 112 additions and 1 deletions

View File

@ -1113,8 +1113,14 @@ void C_ClientCommand(edict_t *pEntity)
int item = pMenu->PagekeyToItem(pPlayer->page, pressed_key+1);
if (item == MENU_BACK)
{
if (pMenu->pageCallback >= 0)
executeForwards(pMenu->pageCallback, static_cast<cell>(pPlayer->index), static_cast<cell>(MENU_BACK));
pMenu->Display(pPlayer->index, pPlayer->page - 1);
} else if (item == MENU_MORE) {
if (pMenu->pageCallback >= 0)
executeForwards(pMenu->pageCallback, static_cast<cell>(pPlayer->index), static_cast<cell>(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));

View File

@ -92,7 +92,7 @@ bool CloseNewMenus(CPlayer *pPlayer)
Menu::Menu(const char *title, AMX *amx, int fid) : m_Title(title), m_ItemColor("\\r"),
m_NeverExit(false), m_AutoColors(g_coloredmenus), thisId(0), func(fid),
isDestroying(false), items_per_page(7)
isDestroying(false), pageCallback(-1), items_per_page(7)
{
CPluginMngr::CPlugin *pPlugin = g_plugins.findPluginFast(amx);
menuId = g_menucmds.registerMenuId(title, amx);
@ -125,6 +125,7 @@ Menu::~Menu()
}
unregisterSPForward(this->func);
unregisterSPForward(this->pageCallback);
m_Items.clear();
}
@ -954,6 +955,28 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params)
switch (params[2])
{
case MPROP_PAGE_CALLBACK:
{
const char *str = get_amxstring_null(amx, params[3], 0, len);
if (str == nullptr)
{
unregisterSPForward(pMenu->pageCallback);
pMenu->pageCallback = -1;
break;
}
int callback = registerSPForwardByName(amx, str, FP_CELL, FP_CELL, FP_DONE);
if (callback < 0)
{
LogError(amx, AMX_ERR_NATIVE, "Function %s not present", str);
return 0;
}
unregisterSPForward(pMenu->pageCallback);
pMenu->pageCallback = callback;
break;
}
case MPROP_SET_NUMBER_COLOR:
{
char *str = get_amxstring(amx, params[3], 0, len);

View File

@ -30,6 +30,7 @@
#define MPROP_NOCOLORS 8
#define MPROP_PADMENU 9
#define MPROP_SET_NUMBER_COLOR 10
#define MPROP_PAGE_CALLBACK 11
typedef int (*MENUITEM_CALLBACK)(int, int, int);
@ -123,6 +124,7 @@ public:
int thisId;
int func;
bool isDestroying;
int pageCallback;
public:
unsigned int items_per_page;
};