PDA

View Full Version : Pagination in menu only if more than 9 entries


Chrisber
10-20-2014, 08:52
Hello,

is there a builtin function in the menus to say "only add pagination if absolutely necessary", so for CS:S if more than 9 entries and for CS:GO if more than 8 entries are available?

I'd like to ask before I manually count my entries and then call
SetMenuPagination(menu, MENU_NO_PAGINATION);
dependent on the count.

Oh, a second question comes into my mind. Am I able to display more metadata e. g. always before entry #5? To show metadata on the top, I use SetMenuTitle together with some \n for new lines. Are there better ways?

Thanks!

Root_
10-27-2014, 07:34
Maybe https://sm.alliedmods.net/api/index.php?fastload=show&id=190& (GetMenuItemCount) will help you.

Powerlord
10-27-2014, 12:57
I'm not somewhere where I can test this, but this should take into account all the weird corner cases.

stock AutoPaginate(Handle:menu)
{
if (menu == INVALID_HANDLE)
{
ThrowError("Invalid menu Handle");
return;
}

// GetMaxPageItems reads from GameData for game-specific corrections and should be correct for CS:GO
new itemsPerPage = GetMaxPageItems(GetMenuStyle(menu));

new bool:pageOneHasExtraItem = false;

if (GetMenuExitButton(menu))
{
itemsPerPage--;
}

if (GetMenuOptionFlags(menu) | MENUFLAG_BUTTON_NOVOTE)
{
pageOneHasExtraItem = true;
}

new count = GetMenuItemCount(menu);

if (count <= (pageOneHasExtraItem ? itemsPerPage - 1 : itemsPerPage ))
{
SetMenuPagination(menu, MENU_NO_PAGINATION);
}
else
{
SetMenuPagination(menu, itemsPerPage - 2);
}
}

As for meta-data, you can (probably) add it as an ITEMDRAW_RAWLINE and it will be printed without a number. However, it still counts as a menu item.

Edit: fixed the above since No Vote only appears on the first page of a vote.