#include < amxmodx >
#pragma semicolon 1
#define ITEMS_PER_MENU_PAGE 8
#define MAX_ITEM_LENGTH 64
new const MENU_IDENT_STRING[ ] = "test_menu";
enum { KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0 }
enum { INVALID_PAGE = -1, PAGE_1, PAGE_2, PAGE_3, PAGE_4, PAGE_5, PAGE_6, PAGE_7, PAGE_8, PAGE_9, PAGE_10 }
enum _: MENU_STRUCT
{
MENU_ITEM_NAME[ MAX_ITEM_LENGTH ],
MENU_ITEM_ACCESS
}
new const MENU[ ][ MENU_STRUCT ] =
{
{ "Админ меню", ADMIN_BAN, },
{ "Вип меню", ADMIN_LEVEL_A, },
{ "Юзер меню", ADMIN_IMMUNITY }
};
new g_iMenuPage[ MAX_PLAYERS + 1 ];
new g_aMenuItems[ MAX_PLAYERS + 1 ][ sizeof( MENU ) ];
public plugin_init( )
{
register_plugin( "Menu Test", "1.0.0", "Javekson" );
register_menu_ex( MENU_IDENT_STRING, "callback_test_menu" );
register_clcmd( "say /menu", "clcmd_show_test_menu" );
}
public clcmd_show_test_menu( const id )
{
// Допустим проверки кому открыть меню и так далее
show_test_menu( id );
}
show_test_menu( const id, const page = PAGE_1 )
{
if( page == INVALID_PAGE ){
return PLUGIN_CONTINUE;
}
new total = get_menu_items( id );
new start = page * ITEMS_PER_MENU_PAGE;
new end = min( start + ITEMS_PER_MENU_PAGE, total );
new pages = max( 1, total / ITEMS_PER_MENU_PAGE + ( total % ITEMS_PER_MENU_PAGE ? 1 : 0 ) );
new menu[ MAX_MENU_LENGTH ];
new len = formatex( menu, charsmax( menu ), "\yМеню для теста \d( %i/%i )^n", page + 1, pages );
new key, keys, item;
while( start < end ){
keys |= ( 1 << key );
key++;
item = g_aMenuItems[ id ][ start ];
len += formatex( menu[ len ], charsmax( menu ) - len, "\y%d. \w%s^n", key, MENU[ item ][ MENU_ITEM_NAME ] );
start++;
}
if( !key ) {
if( page != PAGE_1 ){
show_test_menu( id, pages - 1 );
return PLUGIN_CONTINUE;
}
len += formatex( menu[ len ], charsmax( menu ) - len, "\rНет подходящих данных^n" );
}
if( end < total ) {
keys |= MENU_KEY_0 | MENU_KEY_9;
formatex( menu[ len ], charsmax( menu ) - len, "^n\y9. \wДалее^n\y0. \w%s", page ? "Назад" : "Выход" );
} else {
keys |= MENU_KEY_0;
formatex( menu[ len ], charsmax( menu ) - len, "^n\y0. \w%s", page ? "Назад" : "Выход" );
}
show_menu_ex( id, keys, menu, page, MENU_IDENT_STRING );
return PLUGIN_CONTINUE;
}
get_menu_items( const id )
{
new count, itemAccess;
new size = sizeof( MENU );
new flags = get_user_flags( id );
for( new i; i < size; i++ ) {
itemAccess = MENU[ i ][ MENU_ITEM_ACCESS ];
if( !( itemAccess & flags ) ) {
continue;
}
g_aMenuItems[ id ][ count ] = i;
count++;
}
return count;
}
public callback_test_menu( const id, const key )
{
new page = g_iMenuPage[ id ];
switch( key ) {
case KEY_9: show_test_menu( id, page + 1 );
case KEY_0: show_test_menu( id, page - 1 );
default: {
new target = page * ITEMS_PER_MENU_PAGE + key;
new item = g_aMenuItems[ id ][ target ];
switch( item ) {
case KEY_1: client_print_color( 0, 0, "%s", MENU[ item ][ MENU_ITEM_NAME ] );
case KEY_2: client_print_color( 0, 0, "%s", MENU[ item ][ MENU_ITEM_NAME ] );
case KEY_3: client_print_color( 0, 0, "%s", MENU[ item ][ MENU_ITEM_NAME ] );
}
}
}
}
stock register_menu_ex( const title[ ], const callback[ ], const keys = 1023, const outside = 0 )
{
new menuid = register_menuid( title, outside );
register_menucmd( menuid, keys, callback );
return menuid;
}
stock show_menu_ex( const id, const keys, const menu[ ], const page, const title[ ], const time = -1 )
{
g_iMenuPage[ id ] = page;
show_menu( id, keys, menu, time, title );
}