committed menu padding and title setting

This commit is contained in:
David Anderson 2006-02-08 22:09:31 +00:00
parent 3507155189
commit 2a13d923fa
2 changed files with 41 additions and 15 deletions

View File

@ -88,6 +88,8 @@ Menu::Menu(const char *title, int mid, int tid)
m_AutoColors = g_coloredmenus; m_AutoColors = g_coloredmenus;
items_per_page = 7; items_per_page = 7;
func = 0;
padding = 0;
} }
Menu::~Menu() Menu::~Menu()
@ -257,6 +259,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
keys = 0; keys = 0;
bool enabled = true; bool enabled = true;
int ret = 0; int ret = 0;
int slots = 0;
for (item_t i = start; i <= end; i++) for (item_t i = start; i <= end; i++)
{ {
@ -299,6 +302,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
option++; option++;
} }
} }
slots++;
m_Text.append(buffer); m_Text.append(buffer);
@ -310,10 +314,27 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
if (pItem->blanks[j] == 1) if (pItem->blanks[j] == 1)
option++; option++;
m_Text.append("\n"); 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++) for (int i=0; i<3; i++)
{ {
switch (m_OptOrders[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); g_menucmds.registerMenuCmd(g_plugins.findPluginFast(amx), id, 1023, func);
Menu *pMenu = new Menu(title, id, (int)g_NewMenus.size()); Menu *pMenu = new Menu(title, id, (int)g_NewMenus.size());
pMenu->func = func;
g_NewMenus.push_back(pMenu); g_NewMenus.push_back(pMenu);
return (int)g_NewMenus.size() - 1; return (int)g_NewMenus.size() - 1;
@ -639,8 +663,15 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params)
} }
case MPROP_TITLE: case MPROP_TITLE:
{ {
LogError(amx, AMX_ERR_NATIVE, "Title changing not implemented."); char *str = get_amxstring(amx, params[3], 0, len);
return 0; 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; break;
} }
case MPROP_EXITALL: 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; pMenu->m_AutoColors = *get_amxaddr(amx, params[3]) ? true : false;
break; break;
} }
case MPROP_PADMENU:
{
pMenu->padding = *get_amxaddr(amx, params[3]);
break;
}
default: default:
{ {
LogError(amx, AMX_ERR_NATIVE, "Invalid menu setting: %d", params[1]); LogError(amx, AMX_ERR_NATIVE, "Invalid menu setting: %d", params[1]);

View File

@ -48,6 +48,7 @@
#define MPROP_EXITALL 6 #define MPROP_EXITALL 6
#define MPROP_ORDER 7 #define MPROP_ORDER 7
#define MPROP_NOCOLORS 8 #define MPROP_NOCOLORS 8
#define MPROP_PADMENU 9
typedef int (*MENUITEM_CALLBACK)(int, int, int); typedef int (*MENUITEM_CALLBACK)(int, int, int);
@ -99,23 +100,12 @@ public:
int menuId; int menuId;
int thisId; int thisId;
int func;
int padding;
public: public:
unsigned int items_per_page; 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(); void ClearMenus();
extern CVector<Menu *> g_NewMenus; extern CVector<Menu *> g_NewMenus;