From 2a13d923fab479f6fdf590f7d70e9e94428e608c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 8 Feb 2006 22:09:31 +0000 Subject: [PATCH] committed menu padding and title setting --- amxmodx/newmenus.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- amxmodx/newmenus.h | 16 +++------------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index 8d620ebb..d8f62000 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -88,6 +88,8 @@ Menu::Menu(const char *title, int mid, int tid) m_AutoColors = g_coloredmenus; items_per_page = 7; + func = 0; + padding = 0; } Menu::~Menu() @@ -257,6 +259,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) keys = 0; bool enabled = true; int ret = 0; + int slots = 0; for (item_t i = start; i <= end; i++) { @@ -299,6 +302,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) option++; } } + slots++; m_Text.append(buffer); @@ -310,10 +314,27 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (pItem->blanks[j] == 1) option++; m_Text.append("\n"); + slots++; } } } + if (padding == 1 && items_per_page) + { + int pad = items_per_page; + if (flags & Display_Back) + pad--; + if (flags & Display_Next) + pad--; + if (flags & Display_Exit) + pad--; + for (int i=slots+1; i<=pad; i++) + { + m_Text.append("\n"); + option++; + } + } + for (int i=0; i<3; i++) { switch (m_OptOrders[i]) @@ -395,6 +416,9 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params) g_menucmds.registerMenuCmd(g_plugins.findPluginFast(amx), id, 1023, func); Menu *pMenu = new Menu(title, id, (int)g_NewMenus.size()); + + pMenu->func = func; + g_NewMenus.push_back(pMenu); return (int)g_NewMenus.size() - 1; @@ -639,8 +663,15 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params) } case MPROP_TITLE: { - LogError(amx, AMX_ERR_NATIVE, "Title changing not implemented."); - return 0; + char *str = get_amxstring(amx, params[3], 0, len); + g_menucmds.removeMenuId(pMenu->menuId); + pMenu->m_Title.assign(str); + pMenu->menuId = g_menucmds.registerMenuId(str, amx); + g_menucmds.registerMenuCmd( + g_plugins.findPluginFast(amx), + pMenu->menuId, + 1023, + pMenu->func); break; } case MPROP_EXITALL: @@ -672,6 +703,11 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params) pMenu->m_AutoColors = *get_amxaddr(amx, params[3]) ? true : false; break; } + case MPROP_PADMENU: + { + pMenu->padding = *get_amxaddr(amx, params[3]); + break; + } default: { LogError(amx, AMX_ERR_NATIVE, "Invalid menu setting: %d", params[1]); diff --git a/amxmodx/newmenus.h b/amxmodx/newmenus.h index c764307d..fd6c8986 100755 --- a/amxmodx/newmenus.h +++ b/amxmodx/newmenus.h @@ -48,6 +48,7 @@ #define MPROP_EXITALL 6 #define MPROP_ORDER 7 #define MPROP_NOCOLORS 8 +#define MPROP_PADMENU 9 typedef int (*MENUITEM_CALLBACK)(int, int, int); @@ -99,23 +100,12 @@ public: int menuId; int thisId; + int func; + int padding; public: unsigned int items_per_page; }; -/*Menu *CreateMenu(const char *title); -Menu *GetMenuById(menu_t menu); -menuitem *GetMenuItem(menu_t menu, item_t item); -size_t GetMenuPages(menu_t menu); -size_t GetMenuItems(menu_t menu); -menuitem *AddMenuItem(menu_t menu, const char *name, const char *cmd, int access); -bool DisplayMenu(menu_t menu, int player, page_t page); -int MenuPagekeyToItem(menu_t menu, page_t page, int key); -int FindByMenuid(int menuid); -int GetMenuMenuid(menu_t menu); -const char *GetItemName(menu_t menu, item_t item); -const char *GetItemCmd(menu_t menu, item_t item);*/ - void ClearMenus(); extern CVector g_NewMenus;