From be4fdb17767229d21e9e4cce71627297900e1925 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Fri, 20 Apr 2007 15:27:04 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20the=20completely=20b=C3=B6rked=20handli?= =?UTF-8?q?ng=20of=20the=20last=20page=20with=20newmenus.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- amxmodx/newmenus.cpp | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index e8f9b2af..5275e96d 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -199,26 +199,50 @@ int Menu::PagekeyToItem(page_t page, item_t key) } } else if (page == num_pages - 1) { //last page + item_t item_tracker = 0; // tracks how many valid items we have passed so far. size_t remaining = m_Items.size() - start; - /* We have to add one remaining for each "bumping" space */ + 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. for (size_t i=m_Items.size() - remaining; iblanks.size(); j++) { if (m_Items[i]->blanks[j] == 1) { - remaining++; + new_key--; + } + if (!new_key) + { + break; } } } - if (key == items_per_page + 1) + // If new_key doesn't equal zero, then a back/exit button was pressed. + if (new_key!=0) { - return MENU_BACK; - } else if (key == items_per_page + 3) { - return MENU_EXIT; - } else { - return (start + key - 1); + 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. } + // otherwise our item is now start + item_tracker - 1 + return (start + item_tracker - 1); } else { /* 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.