2014-08-04 08:36:20 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
2005-09-10 20:09:14 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
#include "amxmodx.h"
|
2007-09-02 18:35:53 +00:00
|
|
|
#include "CMenu.h"
|
2005-07-29 06:33:57 +00:00
|
|
|
#include "newmenus.h"
|
2018-09-28 14:46:52 +00:00
|
|
|
#include "format.h"
|
2005-07-29 06:33:57 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
ke::Vector<Menu *> g_NewMenus;
|
2006-02-09 11:53:22 +00:00
|
|
|
CStack<int> g_MenuFreeStack;
|
2005-07-29 06:33:57 +00:00
|
|
|
|
|
|
|
void ClearMenus()
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t i = 0; i < g_NewMenus.length(); i++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2005-07-29 06:33:57 +00:00
|
|
|
delete g_NewMenus[i];
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
g_NewMenus.clear();
|
2006-02-09 11:53:22 +00:00
|
|
|
while (!g_MenuFreeStack.empty())
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2006-02-09 11:53:22 +00:00
|
|
|
g_MenuFreeStack.pop();
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
void validate_menu_text(char *str)
|
|
|
|
{
|
|
|
|
if (!g_coloredmenus)
|
|
|
|
{
|
|
|
|
size_t offs = 0;
|
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
if (*str == '\\')
|
|
|
|
{
|
|
|
|
str++;
|
|
|
|
char c = tolower(*str);
|
|
|
|
if (c == 'r' || c == 'w'
|
2008-05-07 04:58:32 +00:00
|
|
|
|| c== 'y' || c == 'd')
|
2006-02-03 03:00:48 +00:00
|
|
|
{
|
|
|
|
str++;
|
|
|
|
offs += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (offs)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
*(str-offs) = *str;
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
str++;
|
|
|
|
}
|
|
|
|
if (offs)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
*(str-offs) = '\0';
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
2015-03-10 15:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Menu *get_menu_by_id(int id)
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
if (id < 0 || size_t(id) >= g_NewMenus.length() || !g_NewMenus[id])
|
2015-03-10 15:51:45 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_NewMenus[id];
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 16:50:25 +00:00
|
|
|
bool CloseNewMenus(CPlayer *pPlayer)
|
|
|
|
{
|
|
|
|
// If the stupid handler keeps drawing menus,
|
|
|
|
// We need to keep cancelling them. But we put in a quick infinite loop
|
|
|
|
// counter to prevent this from going nuts.
|
|
|
|
|
|
|
|
int loops = 0;
|
|
|
|
Menu *pMenu;
|
|
|
|
|
|
|
|
while ((pMenu = get_menu_by_id(pPlayer->newmenu)))
|
|
|
|
{
|
|
|
|
pMenu->Close(pPlayer->index);
|
|
|
|
|
|
|
|
if (++loops >= 10)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-28 14:46:52 +00:00
|
|
|
Menu::Menu(const char *title, AMX *amx, int fid, bool use_ml) : m_Title(title), m_ItemColor("\\r"),
|
2007-09-02 18:35:53 +00:00
|
|
|
m_NeverExit(false), m_AutoColors(g_coloredmenus), thisId(0), func(fid),
|
2018-09-28 14:46:52 +00:00
|
|
|
isDestroying(false), pageCallback(-1), showPageNumber(true), useMultilingual(use_ml), amx(amx), items_per_page(7)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2007-09-02 18:35:53 +00:00
|
|
|
CPluginMngr::CPlugin *pPlugin = g_plugins.findPluginFast(amx);
|
|
|
|
menuId = g_menucmds.registerMenuId(title, amx);
|
|
|
|
|
|
|
|
if (strcmp(pPlugin->getName(), "war3ft.amxx") == 0)
|
|
|
|
{
|
|
|
|
const char *version = pPlugin->getVersion();
|
|
|
|
if (strncmp(pPlugin->getVersion(), "3.0 RC", 6) == 0
|
|
|
|
&& atoi(&version[6]) <= 8)
|
|
|
|
{
|
|
|
|
g_menucmds.registerMenuCmd(
|
|
|
|
g_plugins.findPluginFast(amx),
|
|
|
|
menuId,
|
|
|
|
-1,
|
|
|
|
g_forwards.duplicateSPForward(fid),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_BACK)] = "Back";
|
|
|
|
m_OptNames[abs(MENU_MORE)] = "More";
|
|
|
|
m_OptNames[abs(MENU_EXIT)] = "Exit";
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Menu::~Menu()
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t i = 0; i < m_Items.length(); i++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2005-07-29 06:33:57 +00:00
|
|
|
delete m_Items[i];
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2006-02-09 11:19:57 +00:00
|
|
|
|
|
|
|
unregisterSPForward(this->func);
|
2017-04-04 08:29:18 +00:00
|
|
|
unregisterSPForward(this->pageCallback);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
m_Items.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
menuitem *Menu::AddItem(const char *name, const char *cmd, int access)
|
|
|
|
{
|
|
|
|
menuitem *pItem = new menuitem;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
pItem->name = name;
|
|
|
|
pItem->cmd = cmd;
|
2005-07-29 06:33:57 +00:00
|
|
|
pItem->access = access;
|
2015-07-11 08:37:36 +00:00
|
|
|
pItem->id = m_Items.length();
|
2005-07-29 06:33:57 +00:00
|
|
|
pItem->handler = -1;
|
2013-07-02 12:54:07 +00:00
|
|
|
pItem->isBlank = false;
|
2005-07-29 06:33:57 +00:00
|
|
|
pItem->pfn = NULL;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Items.append(pItem);
|
2005-07-29 06:33:57 +00:00
|
|
|
|
|
|
|
return pItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
menuitem *Menu::GetMenuItem(item_t item)
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
if (item >= m_Items.length())
|
2005-07-29 06:33:57 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return m_Items[item];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Menu::GetItemCount()
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
return m_Items.length();
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t Menu::GetPageCount()
|
|
|
|
{
|
|
|
|
size_t items = GetItemCount();
|
2006-02-03 03:00:48 +00:00
|
|
|
if (items_per_page == 0)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
return 1;
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
return ((items/items_per_page) + ((items % items_per_page) ? 1 : 0));
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Menu::PagekeyToItem(page_t page, item_t key)
|
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
size_t start = page * items_per_page;
|
|
|
|
size_t num_pages = GetPageCount();
|
2005-07-29 06:33:57 +00:00
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
if (num_pages == 1 || !items_per_page)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
if (key > m_Items.length())
|
2007-04-16 06:58:28 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
return MENU_EXIT;
|
2007-04-16 06:58:28 +00:00
|
|
|
} else {
|
2006-02-03 03:00:48 +00:00
|
|
|
return key-1;
|
2007-04-16 06:58:28 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
} else {
|
|
|
|
//first page
|
|
|
|
if (page == 0)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2006-10-21 21:13:39 +00:00
|
|
|
/* The algorithm for spaces here is same as a middle page. */
|
|
|
|
item_t new_key = key;
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t i=start; i<(start+key-1) && i<m_Items.length(); i++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t j=0; j<m_Items[i]->blanks.length(); j++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2008-04-27 19:19:53 +00:00
|
|
|
if (m_Items[i]->blanks[j].EatNumber())
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
|
|
|
if (!new_key)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
new_key--;
|
|
|
|
}
|
|
|
|
if (!new_key)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
key = new_key;
|
2007-04-16 06:58:28 +00:00
|
|
|
if (key == items_per_page + 2)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2005-07-29 06:33:57 +00:00
|
|
|
return MENU_MORE;
|
2007-04-16 06:58:28 +00:00
|
|
|
} else if (key == items_per_page + 3) {
|
2006-02-03 03:00:48 +00:00
|
|
|
return MENU_EXIT;
|
2006-10-21 21:13:39 +00:00
|
|
|
} else {
|
2006-02-03 03:00:48 +00:00
|
|
|
return (start + key - 1);
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
} else if (page == num_pages - 1) {
|
|
|
|
//last page
|
2007-04-20 15:27:04 +00:00
|
|
|
item_t item_tracker = 0; // tracks how many valid items we have passed so far.
|
2015-07-11 08:37:36 +00:00
|
|
|
size_t remaining = m_Items.length() - start;
|
2007-04-20 15:27:04 +00:00
|
|
|
item_t new_key = key;
|
|
|
|
|
|
|
|
// For every item that takes up a slot (item or padded blank)
|
|
|
|
// we subtract one from new key.
|
|
|
|
// For every item (not blanks), we increase item_tracker.
|
|
|
|
// When new_key equals 0, item_tracker will then be set to
|
|
|
|
// whatever valid item was selected.
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t i=m_Items.length() - remaining; i<m_Items.length(); i++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2007-04-20 15:27:04 +00:00
|
|
|
item_tracker++;
|
2007-04-20 15:47:55 +00:00
|
|
|
|
|
|
|
if (new_key<=1) // If new_key is 0, or will be 0 after the next decrease
|
2007-04-20 15:27:04 +00:00
|
|
|
{
|
2007-04-20 15:47:55 +00:00
|
|
|
new_key=0;
|
2007-04-20 15:27:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-04-20 15:47:55 +00:00
|
|
|
|
|
|
|
new_key--;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t j=0; j<m_Items[i]->blanks.length(); j++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2008-04-27 19:19:53 +00:00
|
|
|
if (m_Items[i]->blanks[j].EatNumber())
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2007-04-20 15:27:04 +00:00
|
|
|
new_key--;
|
|
|
|
}
|
|
|
|
if (!new_key)
|
|
|
|
{
|
|
|
|
break;
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-20 15:27:04 +00:00
|
|
|
// If new_key doesn't equal zero, then a back/exit button was pressed.
|
|
|
|
if (new_key!=0)
|
2006-02-03 03:00:48 +00:00
|
|
|
{
|
2007-04-20 15:27:04 +00:00
|
|
|
if (key == items_per_page + 1)
|
|
|
|
{
|
|
|
|
return MENU_BACK;
|
|
|
|
}
|
|
|
|
else if (key == items_per_page + 3)
|
|
|
|
{
|
|
|
|
return MENU_EXIT;
|
|
|
|
}
|
|
|
|
// MENU_MORE should never happen here.
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
2007-04-20 15:27:04 +00:00
|
|
|
// otherwise our item is now start + item_tracker - 1
|
|
|
|
return (start + item_tracker - 1);
|
2006-02-03 03:00:48 +00:00
|
|
|
} else {
|
2006-10-21 21:13:39 +00:00
|
|
|
/* The algorithm for spaces here is a bit harder. We have to subtract
|
|
|
|
* one from the key for each space we find along the way.
|
|
|
|
*/
|
|
|
|
item_t new_key = key;
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t i=start; i<(start+items_per_page-1) && i<m_Items.length(); i++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t j=0; j<m_Items[i]->blanks.length(); j++)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2008-04-27 19:19:53 +00:00
|
|
|
if (m_Items[i]->blanks[j].EatNumber())
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
|
|
|
if (!new_key)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
new_key--;
|
|
|
|
}
|
|
|
|
if (!new_key)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
key = new_key;
|
2007-04-20 02:59:35 +00:00
|
|
|
if (key > items_per_page && (key-items_per_page<=3))
|
2006-02-03 03:00:48 +00:00
|
|
|
{
|
2007-04-16 06:58:28 +00:00
|
|
|
unsigned int num = key - items_per_page - 1;
|
|
|
|
static int map[] = {MENU_BACK, MENU_MORE, MENU_EXIT};
|
|
|
|
return map[num];
|
2006-02-03 03:00:48 +00:00
|
|
|
} else {
|
|
|
|
return (start + key - 1);
|
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Menu::Display(int player, page_t page)
|
|
|
|
{
|
|
|
|
int keys = 0;
|
|
|
|
const char *str = GetTextString(player, page, keys);
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
static char buffer[2048];
|
2015-10-05 17:06:38 +00:00
|
|
|
int len = ke::SafeSprintf(buffer, sizeof(buffer), "%s", str);
|
2005-07-29 06:33:57 +00:00
|
|
|
|
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER_I(player);
|
|
|
|
|
|
|
|
pPlayer->keys = keys;
|
|
|
|
pPlayer->menu = menuId;
|
2005-07-29 19:13:55 +00:00
|
|
|
pPlayer->newmenu = thisId;
|
|
|
|
pPlayer->page = (int)page;
|
2005-07-29 06:33:57 +00:00
|
|
|
|
|
|
|
UTIL_ShowMenu(pPlayer->pEdict, keys, -1, buffer, len);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-21 16:51:55 +00:00
|
|
|
void Menu::Close(int player)
|
|
|
|
{
|
|
|
|
CPlayer *pPlayer = GET_PLAYER_POINTER_I(player);
|
2015-03-10 15:51:45 +00:00
|
|
|
|
|
|
|
int status;
|
|
|
|
if (gpGlobals->time > pPlayer->menuexpire)
|
|
|
|
status = MENU_TIMEOUT;
|
|
|
|
else
|
2014-05-21 16:51:55 +00:00
|
|
|
status = MENU_EXIT;
|
|
|
|
|
|
|
|
pPlayer->keys = 0;
|
|
|
|
pPlayer->menu = 0;
|
|
|
|
pPlayer->newmenu = -1;
|
|
|
|
|
|
|
|
executeForwards(func,
|
|
|
|
static_cast<cell>(player),
|
|
|
|
static_cast<cell>(thisId),
|
|
|
|
static_cast<cell>(status));
|
|
|
|
}
|
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
const char *Menu::GetTextString(int player, page_t page, int &keys)
|
|
|
|
{
|
|
|
|
page_t pages = GetPageCount();
|
|
|
|
item_t numItems = GetItemCount();
|
|
|
|
|
|
|
|
if (page >= pages)
|
|
|
|
return NULL;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = nullptr;
|
2005-07-29 06:33:57 +00:00
|
|
|
|
2018-09-28 14:46:52 +00:00
|
|
|
|
|
|
|
auto title = m_Title.chars();
|
|
|
|
|
|
|
|
if (this->useMultilingual)
|
|
|
|
{
|
|
|
|
const auto language = playerlang(player);
|
|
|
|
const auto definition = translate(this->amx, language, title);
|
|
|
|
|
|
|
|
if (definition)
|
|
|
|
{
|
|
|
|
title = definition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
char buffer[255];
|
2018-07-18 15:10:37 +00:00
|
|
|
if (showPageNumber && items_per_page && (pages != 1))
|
2006-03-29 22:48:45 +00:00
|
|
|
{
|
|
|
|
if (m_AutoColors)
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "\\y%s %d/%d\n\\w\n", title, page + 1, pages);
|
2006-03-29 22:48:45 +00:00
|
|
|
else
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "%s %d/%d\n\n", title, page + 1, pages);
|
2006-03-29 22:48:45 +00:00
|
|
|
} else {
|
|
|
|
if (m_AutoColors)
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "\\y%s\n\\w\n", title);
|
2006-03-29 22:48:45 +00:00
|
|
|
else
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "%s\n\n", title);
|
2006-03-29 22:48:45 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + buffer;
|
2005-07-29 06:33:57 +00:00
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
Display_Back = (1<<0),
|
|
|
|
Display_Next = (1<<1),
|
|
|
|
};
|
|
|
|
|
|
|
|
int flags = Display_Back|Display_Next;
|
2007-04-16 06:58:28 +00:00
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
item_t start = page * items_per_page;
|
2005-07-29 06:33:57 +00:00
|
|
|
item_t end = 0;
|
2006-02-03 03:00:48 +00:00
|
|
|
if (items_per_page)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
if (start + items_per_page >= numItems)
|
|
|
|
{
|
2014-05-21 22:07:37 +00:00
|
|
|
end = numItems;
|
2006-02-03 03:00:48 +00:00
|
|
|
flags &= ~Display_Next;
|
|
|
|
} else {
|
2014-05-21 22:07:37 +00:00
|
|
|
end = start + items_per_page;
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
} else {
|
2014-05-21 22:07:37 +00:00
|
|
|
end = numItems;
|
2006-02-03 03:00:48 +00:00
|
|
|
if (end > 10)
|
2007-04-16 06:58:28 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
end = 10;
|
2007-04-16 06:58:28 +00:00
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
if (page == 0)
|
2007-04-16 06:58:28 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
flags &= ~Display_Back;
|
2007-04-16 06:58:28 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
menuitem *pItem = NULL;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
int option = 0;
|
|
|
|
keys = 0;
|
|
|
|
bool enabled = true;
|
|
|
|
int ret = 0;
|
2006-02-08 22:09:31 +00:00
|
|
|
int slots = 0;
|
2006-12-19 02:24:09 +00:00
|
|
|
int option_display = 0;
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2014-05-21 22:07:37 +00:00
|
|
|
for (item_t i = start; i < end; i++)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2007-04-13 23:57:14 +00:00
|
|
|
// reset enabled
|
|
|
|
enabled = true;
|
2005-07-29 06:33:57 +00:00
|
|
|
pItem = m_Items[i];
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
if (pItem->access && !(pItem->access & g_players[player].flags[0]))
|
2006-12-19 02:24:09 +00:00
|
|
|
{
|
2005-07-29 06:33:57 +00:00
|
|
|
enabled = false;
|
2006-12-19 02:24:09 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
if (pItem->handler != -1)
|
|
|
|
{
|
2005-10-18 21:05:52 +00:00
|
|
|
ret = executeForwards(pItem->handler, static_cast<cell>(player), static_cast<cell>(thisId), static_cast<cell>(i));
|
2005-07-29 06:33:57 +00:00
|
|
|
if (ret == ITEM_ENABLED)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2005-07-29 06:33:57 +00:00
|
|
|
enabled = true;
|
2006-10-21 21:13:39 +00:00
|
|
|
} else if (ret == ITEM_DISABLED) {
|
2005-07-29 06:33:57 +00:00
|
|
|
enabled = false;
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
if (pItem->pfn)
|
|
|
|
{
|
|
|
|
ret = (pItem->pfn)(player, thisId, i);
|
|
|
|
if (ret == ITEM_ENABLED)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2005-07-29 06:33:57 +00:00
|
|
|
enabled = true;
|
2006-10-21 21:13:39 +00:00
|
|
|
} else if (ret == ITEM_DISABLED) {
|
2005-07-29 06:33:57 +00:00
|
|
|
enabled = false;
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
2006-12-19 02:24:09 +00:00
|
|
|
|
2013-07-02 12:54:07 +00:00
|
|
|
if (pItem->isBlank)
|
|
|
|
{
|
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
|
2006-12-19 02:24:09 +00:00
|
|
|
if (enabled)
|
|
|
|
{
|
|
|
|
keys |= (1<<option);
|
|
|
|
}
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2006-12-19 02:24:09 +00:00
|
|
|
option_display = ++option;
|
|
|
|
if (option_display == 10)
|
|
|
|
{
|
|
|
|
option_display = 0;
|
|
|
|
}
|
|
|
|
|
2018-09-28 14:46:52 +00:00
|
|
|
auto itemName = pItem->name.chars();
|
|
|
|
|
|
|
|
if (this->useMultilingual)
|
|
|
|
{
|
|
|
|
const auto language = playerlang(player);
|
|
|
|
const auto definition = translate(this->amx, language, itemName);
|
|
|
|
|
|
|
|
if (definition)
|
|
|
|
{
|
|
|
|
itemName = definition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 12:54:07 +00:00
|
|
|
if (pItem->isBlank)
|
|
|
|
{
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "%s\n", itemName);
|
2013-07-02 12:54:07 +00:00
|
|
|
}
|
|
|
|
else if (enabled)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2018-09-28 14:46:52 +00:00
|
|
|
if (m_AutoColors)
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "%s%d.\\w %s\n", m_ItemColor.chars(),option_display, itemName);
|
2006-10-21 21:13:39 +00:00
|
|
|
} else {
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "%d. %s\n", option_display, itemName);
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
} else {
|
2006-02-08 05:39:03 +00:00
|
|
|
if (m_AutoColors)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "\\d%d. %s\n\\w", option_display, itemName);
|
2005-07-29 06:33:57 +00:00
|
|
|
} else {
|
2018-09-28 14:46:52 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "#. %s\n", itemName);
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-08 22:09:31 +00:00
|
|
|
slots++;
|
2006-02-03 03:00:48 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + buffer;
|
2006-02-08 05:39:03 +00:00
|
|
|
|
|
|
|
//attach blanks
|
2015-07-11 08:37:36 +00:00
|
|
|
if (pItem->blanks.length())
|
2006-02-08 05:39:03 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
for (size_t j=0; j<pItem->blanks.length(); j++)
|
2006-02-08 05:39:03 +00:00
|
|
|
{
|
2008-04-27 19:19:53 +00:00
|
|
|
if (pItem->blanks[j].EatNumber())
|
2006-10-21 21:13:39 +00:00
|
|
|
{
|
2006-02-08 05:39:03 +00:00
|
|
|
option++;
|
2006-10-21 21:13:39 +00:00
|
|
|
}
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + pItem->blanks[j].GetDisplay();
|
|
|
|
m_Text = m_Text + "\n";
|
2006-02-08 22:09:31 +00:00
|
|
|
slots++;
|
2006-02-08 05:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
|
2007-04-16 06:58:28 +00:00
|
|
|
if (items_per_page)
|
2006-02-08 22:09:31 +00:00
|
|
|
{
|
2007-04-16 06:58:28 +00:00
|
|
|
/* Pad spaces until we reach the end of the max possible items */
|
|
|
|
for (unsigned int i=(unsigned)slots; i<items_per_page; i++)
|
2006-02-08 22:09:31 +00:00
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + "\n";
|
2006-02-08 22:09:31 +00:00
|
|
|
option++;
|
|
|
|
}
|
2007-04-16 06:58:28 +00:00
|
|
|
/* Make sure there is at least one visual pad */
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + "\n";
|
2006-02-08 22:09:31 +00:00
|
|
|
|
2007-04-16 06:58:28 +00:00
|
|
|
/* Don't bother if there is only one page */
|
|
|
|
if (pages > 1)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2007-04-16 06:58:28 +00:00
|
|
|
if (flags & Display_Back)
|
2006-02-03 03:00:48 +00:00
|
|
|
{
|
2007-04-16 06:58:28 +00:00
|
|
|
keys |= (1<<option++);
|
2007-04-18 04:20:48 +00:00
|
|
|
if (m_AutoColors)
|
|
|
|
{
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2007-04-18 04:20:48 +00:00
|
|
|
"%s%d. \\w%s\n",
|
2015-07-11 08:37:36 +00:00
|
|
|
m_ItemColor.chars(),
|
2007-04-18 04:20:48 +00:00
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_BACK)].chars());
|
2007-04-18 04:20:48 +00:00
|
|
|
} else {
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2007-04-18 04:20:48 +00:00
|
|
|
"%d. %s\n",
|
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_BACK)].chars());
|
2007-04-18 04:20:48 +00:00
|
|
|
}
|
2007-04-16 06:58:28 +00:00
|
|
|
} else {
|
|
|
|
option++;
|
|
|
|
if (m_AutoColors)
|
2006-02-03 03:00:48 +00:00
|
|
|
{
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2007-04-16 06:58:28 +00:00
|
|
|
"\\d%d. %s\n\\w",
|
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_BACK)].chars());
|
2007-04-16 06:58:28 +00:00
|
|
|
} else {
|
2015-10-05 17:06:38 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "#. %s\n", m_OptNames[abs(MENU_BACK)].chars());
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-29 22:28:18 +00:00
|
|
|
m_Text = m_Text + buffer;
|
2007-04-16 06:58:28 +00:00
|
|
|
|
|
|
|
if (flags & Display_Next)
|
2006-02-03 03:00:48 +00:00
|
|
|
{
|
2007-04-16 06:58:28 +00:00
|
|
|
keys |= (1<<option++);
|
2007-04-18 04:20:48 +00:00
|
|
|
if (m_AutoColors)
|
|
|
|
{
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2007-04-18 04:20:48 +00:00
|
|
|
"%s%d. \\w%s\n",
|
2015-07-11 08:37:36 +00:00
|
|
|
m_ItemColor.chars(),
|
2007-04-18 04:20:48 +00:00
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_MORE)].chars());
|
2007-04-18 04:20:48 +00:00
|
|
|
} else {
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2007-04-18 04:20:48 +00:00
|
|
|
"%d. %s\n",
|
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_MORE)].chars());
|
2007-04-18 04:20:48 +00:00
|
|
|
}
|
2007-04-16 06:58:28 +00:00
|
|
|
} else {
|
|
|
|
option++;
|
|
|
|
if (m_AutoColors)
|
2006-02-03 03:00:48 +00:00
|
|
|
{
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2007-04-16 06:58:28 +00:00
|
|
|
"\\d%d. %s\n\\w",
|
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_MORE)].chars());
|
2007-04-16 06:58:28 +00:00
|
|
|
} else {
|
2015-10-05 17:06:38 +00:00
|
|
|
ke::SafeSprintf(buffer, sizeof(buffer), "#. %s\n", m_OptNames[abs(MENU_MORE)].chars());
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + buffer;
|
2007-04-16 06:58:28 +00:00
|
|
|
} else {
|
|
|
|
/* Keep padding */
|
|
|
|
option += 2;
|
|
|
|
}
|
2014-05-21 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((items_per_page && !m_NeverExit) || (m_ForceExit && numItems < 10))
|
|
|
|
{
|
|
|
|
/* Visual pad has not been added yet */
|
|
|
|
if (!items_per_page)
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + "\n";
|
2014-05-21 20:18:48 +00:00
|
|
|
|
|
|
|
keys |= (1<<option++);
|
|
|
|
if (m_AutoColors)
|
2007-04-16 06:58:28 +00:00
|
|
|
{
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2014-05-21 20:18:48 +00:00
|
|
|
"%s%d. \\w%s\n",
|
2015-07-11 08:37:36 +00:00
|
|
|
m_ItemColor.chars(),
|
2014-05-21 20:18:48 +00:00
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_EXIT)].chars());
|
2014-05-21 20:18:48 +00:00
|
|
|
} else {
|
2015-10-01 09:06:04 +00:00
|
|
|
ke::SafeSprintf(buffer,
|
2015-10-05 17:06:38 +00:00
|
|
|
sizeof(buffer),
|
2014-05-21 20:18:48 +00:00
|
|
|
"%d. %s\n",
|
|
|
|
option == 10 ? 0 : option,
|
2015-07-11 08:37:36 +00:00
|
|
|
m_OptNames[abs(MENU_EXIT)].chars());
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
2015-07-11 08:37:36 +00:00
|
|
|
m_Text = m_Text + buffer;
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
return m_Text.ptr();
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 08:33:53 +00:00
|
|
|
#define GETMENU(p) Menu *pMenu = get_menu_by_id(p); \
|
|
|
|
if (pMenu == NULL || pMenu->isDestroying) { \
|
2015-07-11 08:37:36 +00:00
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d(%d)", p, g_NewMenus.length()); \
|
2014-05-27 08:33:53 +00:00
|
|
|
return 0; }
|
2005-07-29 06:33:57 +00:00
|
|
|
|
2018-09-28 14:46:52 +00:00
|
|
|
// native menu_create(const title[], const handler[], bool:ml = false);
|
2005-07-29 06:33:57 +00:00
|
|
|
static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
|
|
|
|
{
|
2018-09-28 14:46:52 +00:00
|
|
|
enum args { arg_count, arg_title, arg_handler, arg_ml };
|
2005-07-29 06:33:57 +00:00
|
|
|
|
2018-09-28 14:46:52 +00:00
|
|
|
int length;
|
|
|
|
const auto title = get_amxstring(amx, params[arg_title], 0, length);
|
|
|
|
const auto handler = get_amxstring(amx, params[arg_handler], 1, length);
|
|
|
|
const auto callback = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_CELL, FP_DONE);
|
|
|
|
|
|
|
|
if (callback == -1)
|
2005-07-29 06:33:57 +00:00
|
|
|
{
|
2018-09-28 14:46:52 +00:00
|
|
|
LogError(amx, AMX_ERR_NOTFOUND, R"(Invalid function "%s")", handler);
|
2005-07-29 06:33:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-28 14:46:52 +00:00
|
|
|
validate_menu_text(title);
|
|
|
|
|
|
|
|
auto pMenu = new Menu(title, amx, callback, params[arg_ml] != 0);
|
2006-02-08 22:09:31 +00:00
|
|
|
|
2006-02-09 11:53:22 +00:00
|
|
|
if (g_MenuFreeStack.empty())
|
|
|
|
{
|
2015-07-11 08:37:36 +00:00
|
|
|
g_NewMenus.append(pMenu);
|
2018-09-28 14:46:52 +00:00
|
|
|
|
|
|
|
pMenu->thisId = static_cast<int>(g_NewMenus.length()) - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto position = g_MenuFreeStack.front();
|
|
|
|
|
2006-02-09 11:53:22 +00:00
|
|
|
g_MenuFreeStack.pop();
|
2018-09-28 14:46:52 +00:00
|
|
|
g_NewMenus[position] = pMenu;
|
|
|
|
|
|
|
|
pMenu->thisId = position;
|
2006-02-09 11:53:22 +00:00
|
|
|
}
|
2007-04-16 18:00:54 +00:00
|
|
|
|
|
|
|
return pMenu->thisId;
|
2005-07-29 06:33:57 +00:00
|
|
|
}
|
2018-09-28 14:46:52 +00:00
|
|
|
|
2006-02-08 05:39:03 +00:00
|
|
|
static cell AMX_NATIVE_CALL menu_addblank(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
if (params[2] && (!pMenu->items_per_page && pMenu->GetItemCount() >= 10))
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
if (!pMenu->m_Items.length())
|
2006-02-08 05:39:03 +00:00
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Blanks can only be added after items.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
menuitem *item = pMenu->m_Items[pMenu->m_Items.length() - 1];
|
2008-04-27 19:19:53 +00:00
|
|
|
|
|
|
|
BlankItem a;
|
|
|
|
|
|
|
|
a.SetBlank();
|
|
|
|
|
|
|
|
if (params[2] == 1)
|
|
|
|
a.SetEatNumber(true);
|
|
|
|
|
|
|
|
else
|
|
|
|
a.SetEatNumber(false);
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
item->blanks.append(ke::Move(a));
|
2008-04-27 19:19:53 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static cell AMX_NATIVE_CALL menu_addtext(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
if (params[2] && (!pMenu->items_per_page && pMenu->GetItemCount() >= 10))
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
if (!pMenu->m_Items.length())
|
2008-04-27 19:19:53 +00:00
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Blanks can only be added after items.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
menuitem *item = pMenu->m_Items[pMenu->m_Items.length() - 1];
|
2008-04-27 19:19:53 +00:00
|
|
|
|
|
|
|
BlankItem a;
|
|
|
|
|
|
|
|
int len;
|
|
|
|
a.SetText(get_amxstring(amx, params[2], 0, len));
|
|
|
|
|
|
|
|
if (params[3] == 1)
|
|
|
|
a.SetEatNumber(true);
|
|
|
|
|
|
|
|
else
|
|
|
|
a.SetEatNumber(false);
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
item->blanks.append(ke::Move(a));
|
2006-02-08 05:39:03 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-03-10 15:51:45 +00:00
|
|
|
static cell AMX_NATIVE_CALL menu_addblank2(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
if (!pMenu->items_per_page && pMenu->GetItemCount() >= 10)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
menuitem *pItem = pMenu->AddItem("", "", 0);
|
|
|
|
pItem->isBlank = true;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static cell AMX_NATIVE_CALL menu_addtext2(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
if (!pMenu->items_per_page && pMenu->GetItemCount() >= 10)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = get_amxstring(amx, params[2], 0, len);
|
|
|
|
validate_menu_text(name);
|
|
|
|
|
|
|
|
menuitem *pItem = pMenu->AddItem(name, "", 0);
|
|
|
|
pItem->isBlank = true;
|
|
|
|
|
2013-07-02 12:54:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
//Adds an item to the menu (returns current item count - 1)
|
|
|
|
//native menu_additem(menu, const name[], const command[]="", access=0);
|
|
|
|
static cell AMX_NATIVE_CALL menu_additem(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *name, *cmd;
|
|
|
|
int access;
|
|
|
|
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
if (!pMenu->items_per_page && pMenu->GetItemCount() >= 10)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
name = get_amxstring(amx, params[2], 0, len);
|
2006-02-03 03:00:48 +00:00
|
|
|
validate_menu_text(name);
|
2005-07-29 06:33:57 +00:00
|
|
|
cmd = get_amxstring(amx, params[3], 1, len);
|
|
|
|
access = params[4];
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
menuitem *pItem = pMenu->AddItem(name, cmd, access);
|
|
|
|
|
|
|
|
pItem->handler = params[5];
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Returns the number of pages in a menu
|
|
|
|
//native csdm_menu_pages(menu);
|
|
|
|
static cell AMX_NATIVE_CALL menu_pages(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
return pMenu->GetPageCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Returns the number of items in a menu
|
|
|
|
//native csdm_menu_items(menu);
|
|
|
|
static cell AMX_NATIVE_CALL menu_items(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
return pMenu->GetItemCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Builds the menu string for a specific page (set title to 0 to not include title)
|
|
|
|
//page indices start at 0!
|
|
|
|
static cell AMX_NATIVE_CALL menu_display(AMX *amx, cell *params)
|
|
|
|
{
|
2017-10-03 18:43:30 +00:00
|
|
|
auto handle = params[2];
|
|
|
|
GETMENU(handle);
|
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
int player = params[1];
|
|
|
|
int page = params[3];
|
2019-01-30 14:19:30 +00:00
|
|
|
|
|
|
|
if (player < 1 || player > gpGlobals->maxClients)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d.", player);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-13 20:33:30 +00:00
|
|
|
CPlayer* pPlayer = GET_PLAYER_POINTER_I(player);
|
2019-01-30 14:19:30 +00:00
|
|
|
|
|
|
|
if (!pPlayer->ingame)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Player %d is not in game.", player);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-03 18:43:30 +00:00
|
|
|
|
2016-01-14 16:50:25 +00:00
|
|
|
if (!CloseNewMenus(pPlayer))
|
2007-04-16 18:00:54 +00:00
|
|
|
{
|
2016-01-14 16:50:25 +00:00
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Plugin called menu_display when item=MENU_EXIT");
|
|
|
|
return 0;
|
2007-04-16 18:00:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 18:43:30 +00:00
|
|
|
if (!g_NewMenus[handle])
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d (was previously destroyed).", handle);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-10 10:09:20 +00:00
|
|
|
if (g_bmod_cstrike)
|
|
|
|
{
|
2018-09-03 16:39:08 +00:00
|
|
|
enum JoinState { Joined = 0 };
|
|
|
|
enum MenuState { Menu_OFF = 0, Menu_ChooseTeam = 1, Menu_ChooseAppearance = 3 };
|
|
|
|
|
|
|
|
GET_OFFSET("CBasePlayer", m_iJoiningState);
|
2018-07-10 10:09:20 +00:00
|
|
|
GET_OFFSET("CBasePlayer", m_iMenu);
|
2018-09-03 16:39:08 +00:00
|
|
|
|
|
|
|
if (get_pdata<int>(pPlayer->pEdict, m_iJoiningState) == Joined || (get_pdata<int>(pPlayer->pEdict, m_iMenu) != Menu_ChooseTeam && get_pdata<int>(pPlayer->pEdict, m_iMenu) != Menu_ChooseAppearance))
|
|
|
|
{
|
|
|
|
set_pdata<int>(pPlayer->pEdict, m_iMenu, Menu_OFF);
|
|
|
|
}
|
2018-07-10 10:09:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 17:17:04 +00:00
|
|
|
int time = -1;
|
|
|
|
if (params[0] / sizeof(cell) >= 4)
|
|
|
|
time = params[4];
|
|
|
|
|
|
|
|
if (time < 0)
|
|
|
|
pPlayer->menuexpire = INFINITE;
|
2015-03-10 15:51:45 +00:00
|
|
|
else
|
2014-05-21 17:17:04 +00:00
|
|
|
pPlayer->menuexpire = gpGlobals->time + static_cast<float>(time);
|
2005-07-29 06:33:57 +00:00
|
|
|
|
|
|
|
return pMenu->Display(player, page);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Finds the id of a menu item for a specific page and key value.
|
|
|
|
//Note that key should be from 0-6, as it only displays 7 per page.
|
|
|
|
//page indices start at 0
|
|
|
|
//native menu_keyid(menu, page, key);
|
|
|
|
static cell AMX_NATIVE_CALL menu_find_id(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
page_t page = static_cast<page_t>(params[2]);
|
|
|
|
item_t key = static_cast<item_t>(params[3]);
|
|
|
|
|
|
|
|
return pMenu->PagekeyToItem(page, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Gets info about a menu option
|
|
|
|
//native menu_item_getinfo(menu, item, &access, command[], cmdlen, name[]="", namelen=0, &callback);
|
|
|
|
static cell AMX_NATIVE_CALL menu_item_getinfo(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
|
|
|
|
|
|
|
|
if (!pItem)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cell *addr = get_amxaddr(amx, params[3]);
|
|
|
|
addr[0] = pItem->access;
|
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
set_amxstring(amx, params[4], pItem->cmd.chars(), params[5]);
|
|
|
|
set_amxstring(amx, params[6], pItem->name.chars(), params[7]);
|
2005-07-29 06:33:57 +00:00
|
|
|
|
|
|
|
if (params[8])
|
|
|
|
{
|
|
|
|
addr = get_amxaddr(amx, params[8]);
|
|
|
|
if (addr)
|
|
|
|
addr[0] = pItem->handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (id == -1)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NOTFOUND, "Invalid function %s", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2005-08-17 16:12:45 +00:00
|
|
|
static cell AMX_NATIVE_CALL menu_item_setname(AMX *amx, cell *params)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
GETMENU(params[1]);
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
if (!pItem)
|
|
|
|
return 0;
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
int len;
|
|
|
|
char *name;
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
name = get_amxstring(amx, params[3], 0, len);
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
pItem->name = name;
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
return 1;
|
2005-08-17 16:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static cell AMX_NATIVE_CALL menu_item_setcmd(AMX *amx, cell *params)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
GETMENU(params[1]);
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
if (!pItem)
|
|
|
|
return 0;
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
int len;
|
|
|
|
char *cmd;
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
cmd = get_amxstring(amx, params[3], 0, len);
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2015-07-11 08:37:36 +00:00
|
|
|
pItem->cmd = cmd;
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
return 1;
|
2005-08-17 16:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static cell AMX_NATIVE_CALL menu_item_setcall(AMX *amx, cell *params)
|
|
|
|
{
|
2005-09-16 23:48:51 +00:00
|
|
|
GETMENU(params[1]);
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
if (!pItem)
|
|
|
|
return 0;
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
pItem->handler = params[3];
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-09-16 23:48:51 +00:00
|
|
|
return 1;
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
GETMENU(params[1]);
|
|
|
|
|
|
|
|
int len = params[0] / sizeof(cell);
|
|
|
|
if (len < 3)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Expected 3 parameters");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (params[2])
|
|
|
|
{
|
2017-04-04 08:29:18 +00:00
|
|
|
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;
|
|
|
|
|
2018-07-18 15:10:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_SHOWPAGE:
|
|
|
|
{
|
|
|
|
pMenu->showPageNumber = (get_amxaddr(amx, params[3]) != 0);
|
2017-04-04 08:29:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-04-18 04:20:48 +00:00
|
|
|
case MPROP_SET_NUMBER_COLOR:
|
|
|
|
{
|
|
|
|
char *str = get_amxstring(amx, params[3], 0, len);
|
|
|
|
validate_menu_text(str);
|
2015-07-11 08:37:36 +00:00
|
|
|
pMenu->m_ItemColor = str;
|
2007-04-18 04:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
case MPROP_PERPAGE:
|
|
|
|
{
|
|
|
|
cell count = *get_amxaddr(amx, params[3]);
|
|
|
|
if (count < 0 || count > 7)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Cannot set %d items per page", count);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pMenu->items_per_page = count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_BACKNAME:
|
|
|
|
{
|
|
|
|
char *str = get_amxstring(amx, params[3], 0, len);
|
|
|
|
validate_menu_text(str);
|
2015-07-11 08:37:36 +00:00
|
|
|
pMenu->m_OptNames[abs(MENU_BACK)] = str;
|
2006-02-03 03:00:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_NEXTNAME:
|
|
|
|
{
|
|
|
|
char *str = get_amxstring(amx, params[3], 0, len);
|
|
|
|
validate_menu_text(str);
|
2015-07-11 08:37:36 +00:00
|
|
|
pMenu->m_OptNames[abs(MENU_MORE)] = str;
|
2006-02-03 03:00:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_EXITNAME:
|
|
|
|
{
|
|
|
|
char *str = get_amxstring(amx, params[3], 0, len);
|
|
|
|
validate_menu_text(str);
|
2015-07-11 08:37:36 +00:00
|
|
|
pMenu->m_OptNames[abs(MENU_EXIT)] = str;
|
2006-02-03 03:00:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_TITLE:
|
|
|
|
{
|
2006-02-08 22:09:31 +00:00
|
|
|
char *str = get_amxstring(amx, params[3], 0, len);
|
2015-07-11 08:37:36 +00:00
|
|
|
pMenu->m_Title = str;
|
2006-02-03 03:00:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_EXITALL:
|
|
|
|
{
|
2006-02-06 13:22:33 +00:00
|
|
|
cell ans = *get_amxaddr(amx, params[3]);
|
2007-04-16 06:58:28 +00:00
|
|
|
if (ans == 1 || ans == 0)
|
2006-02-06 13:22:33 +00:00
|
|
|
{
|
|
|
|
pMenu->m_NeverExit = false;
|
2014-05-21 20:18:48 +00:00
|
|
|
pMenu->m_ForceExit = false;
|
|
|
|
} else if (ans == 2) {
|
|
|
|
pMenu->m_NeverExit = false;
|
|
|
|
pMenu->m_ForceExit = true;
|
2006-02-06 13:22:33 +00:00
|
|
|
} else if (ans == -1) {
|
|
|
|
pMenu->m_NeverExit = true;
|
2014-05-21 20:18:48 +00:00
|
|
|
pMenu->m_ForceExit = false;
|
2006-02-06 13:22:33 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_ORDER:
|
|
|
|
{
|
2007-04-16 06:58:28 +00:00
|
|
|
/* Ignored as of 1.8.0 */
|
2006-02-03 03:00:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MPROP_NOCOLORS:
|
|
|
|
{
|
2015-08-13 10:04:31 +00:00
|
|
|
pMenu->m_AutoColors = *get_amxaddr(amx, params[3]) ? false : true;
|
2006-02-03 03:00:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-08 22:09:31 +00:00
|
|
|
case MPROP_PADMENU:
|
|
|
|
{
|
2007-04-16 06:58:28 +00:00
|
|
|
/* Ignored as of 1.8.0 */
|
2006-02-08 22:09:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Invalid menu setting: %d", params[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-05-27 08:33:53 +00:00
|
|
|
#define GETMENU_R(p) Menu *pMenu = get_menu_by_id(p); \
|
|
|
|
if (pMenu == NULL) { \
|
2015-07-11 08:37:36 +00:00
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d(%d)", p, g_NewMenus.length()); \
|
2014-05-27 08:33:53 +00:00
|
|
|
return 0; }
|
2006-02-09 12:04:35 +00:00
|
|
|
|
2006-03-14 17:49:29 +00:00
|
|
|
static cell AMX_NATIVE_CALL menu_cancel(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index = params[1];
|
|
|
|
|
|
|
|
if (index < 1 || index > gpGlobals->maxClients)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Player %d is not valid", index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPlayer *player = GET_PLAYER_POINTER_I(index);
|
|
|
|
if (!player->ingame)
|
|
|
|
{
|
2014-05-27 08:38:25 +00:00
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Player %d is not in game", index);
|
2006-03-14 17:49:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-27 08:33:53 +00:00
|
|
|
if (Menu *pMenu = get_menu_by_id(player->newmenu)) {
|
|
|
|
pMenu->Close(player->index);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-03-14 17:49:29 +00:00
|
|
|
|
2014-05-27 08:33:53 +00:00
|
|
|
return 0;
|
2006-03-14 17:49:29 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params)
|
|
|
|
{
|
2006-02-09 12:04:35 +00:00
|
|
|
GETMENU_R(params[1]);
|
2006-02-03 03:00:48 +00:00
|
|
|
|
2006-02-09 11:53:22 +00:00
|
|
|
if (pMenu->isDestroying)
|
2007-03-09 03:04:40 +00:00
|
|
|
{
|
2006-02-09 11:53:22 +00:00
|
|
|
return 0; //prevent infinite recursion
|
2007-03-09 03:04:40 +00:00
|
|
|
}
|
2006-02-09 11:53:22 +00:00
|
|
|
|
|
|
|
pMenu->isDestroying = true;
|
2007-04-16 18:00:54 +00:00
|
|
|
|
2006-02-03 03:00:48 +00:00
|
|
|
CPlayer *player;
|
|
|
|
for (int i=1; i<=gpGlobals->maxClients; i++)
|
|
|
|
{
|
|
|
|
player = GET_PLAYER_POINTER_I(i);
|
2006-02-09 11:19:57 +00:00
|
|
|
if (player->newmenu == pMenu->thisId)
|
2015-03-10 15:51:45 +00:00
|
|
|
{
|
2014-05-21 16:58:51 +00:00
|
|
|
pMenu->Close(player->index);
|
2006-02-09 11:19:57 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
}
|
2006-02-09 12:04:35 +00:00
|
|
|
g_NewMenus[params[1]] = NULL;
|
2006-02-03 03:00:48 +00:00
|
|
|
delete pMenu;
|
2006-02-09 11:53:22 +00:00
|
|
|
g_MenuFreeStack.push(params[1]);
|
2006-02-03 03:00:48 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cell AMX_NATIVE_CALL player_menu_info(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
if (params[1] < 1 || params[1] > gpGlobals->maxClients)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Invalid player id %d", params[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPlayer *player = GET_PLAYER_POINTER_I(params[1]);
|
|
|
|
if (!player->ingame)
|
|
|
|
{
|
|
|
|
LogError(amx, AMX_ERR_NATIVE, "Player %d is not ingame", params[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell *m = get_amxaddr(amx, params[2]);
|
|
|
|
cell *n = get_amxaddr(amx, params[3]);
|
|
|
|
|
|
|
|
*m = player->menu;
|
|
|
|
*n = player->newmenu;
|
|
|
|
|
2007-03-09 03:04:40 +00:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
|
|
|
{
|
|
|
|
cell *addr = get_amxaddr(amx, params[4]);
|
|
|
|
*addr = player->page;
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:13:27 +00:00
|
|
|
if ( (*m != 0 && *m != -1) || (*n != -1))
|
2007-03-09 03:04:40 +00:00
|
|
|
{
|
2006-02-03 03:00:48 +00:00
|
|
|
return 1;
|
2007-03-09 03:04:40 +00:00
|
|
|
}
|
2006-02-03 03:00:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-08-17 16:12:45 +00:00
|
|
|
|
2005-07-29 06:33:57 +00:00
|
|
|
AMX_NATIVE_INFO g_NewMenuNatives[] =
|
|
|
|
{
|
|
|
|
{"menu_create", menu_create},
|
|
|
|
{"menu_additem", menu_additem},
|
2006-02-08 05:39:03 +00:00
|
|
|
{"menu_addblank", menu_addblank},
|
2008-04-27 19:19:53 +00:00
|
|
|
{"menu_addtext", menu_addtext},
|
2005-07-29 06:33:57 +00:00
|
|
|
{"menu_pages", menu_pages},
|
|
|
|
{"menu_items", menu_items},
|
|
|
|
{"menu_display", menu_display},
|
|
|
|
{"menu_find_id", menu_find_id},
|
|
|
|
{"menu_item_getinfo", menu_item_getinfo},
|
|
|
|
{"menu_makecallback", menu_makecallback},
|
2005-08-17 16:12:45 +00:00
|
|
|
{"menu_item_setcall", menu_item_setcall},
|
|
|
|
{"menu_item_setcmd", menu_item_setcmd},
|
|
|
|
{"menu_item_setname", menu_item_setname},
|
2006-02-03 03:00:48 +00:00
|
|
|
{"menu_destroy", menu_destroy},
|
|
|
|
{"menu_setprop", menu_setprop},
|
2006-03-14 17:49:29 +00:00
|
|
|
{"menu_cancel", menu_cancel},
|
2006-02-03 03:00:48 +00:00
|
|
|
{"player_menu_info", player_menu_info},
|
2013-07-02 12:54:07 +00:00
|
|
|
{"menu_addblank2", menu_addblank2},
|
|
|
|
{"menu_addtext2", menu_addtext2},
|
2005-07-29 06:33:57 +00:00
|
|
|
{NULL, NULL},
|
2005-07-29 19:13:55 +00:00
|
|
|
};
|