From ff18b032503bc757dc3998335e734918edff8f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Gr=C3=BCnbacher?= Date: Wed, 21 May 2014 22:18:48 +0200 Subject: [PATCH 1/2] Newmenus: Add MEXIT_FORCE for proper exit button on non-paginated menus --- amxmodx/newmenus.cpp | 47 +++++++++++++++++++++--------------- amxmodx/newmenus.h | 1 + plugins/include/newmenus.inc | 4 +++ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index 26ceeef4..681fcea1 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -560,27 +560,31 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) /* Keep padding */ option += 2; } - - if (!m_NeverExit) + } + + if ((items_per_page && !m_NeverExit) || (m_ForceExit && numItems < 10)) + { + /* Visual pad has not been added yet */ + if (!items_per_page) + m_Text.append("\n"); + + keys |= (1<m_NeverExit = false; + pMenu->m_ForceExit = false; + } else if (ans == 2) { + pMenu->m_NeverExit = false; + pMenu->m_ForceExit = true; } else if (ans == -1) { pMenu->m_NeverExit = true; + pMenu->m_ForceExit = false; } break; } diff --git a/amxmodx/newmenus.h b/amxmodx/newmenus.h index d759dcf2..558bd770 100755 --- a/amxmodx/newmenus.h +++ b/amxmodx/newmenus.h @@ -138,6 +138,7 @@ public: String m_ItemColor; bool m_NeverExit; + bool m_ForceExit; bool m_AutoColors; int menuId; diff --git a/plugins/include/newmenus.inc b/plugins/include/newmenus.inc index 1da1ec76..3ef69f4d 100644 --- a/plugins/include/newmenus.inc +++ b/plugins/include/newmenus.inc @@ -12,6 +12,10 @@ #define _newmenus_included #define MEXIT_ALL 1 /* Menu will have an exit option (default)*/ +#define MEXIT_FORCE 2 /* Menu will have an exit option, even when pagination is disabled. + * There have to be less than 10 items in the menu or it won't appear. The exit + * option will be appended to the last item with no extra slot padding. If you + * want it in the 10th slot you have to pad it manually with menu_addblank2 */ #define MEXIT_NEVER -1 /* Menu will not have an exit option */ #define MPROP_PERPAGE 1 /* Number of items per page (param1 = number, 0=no paginating, 7=default) */ From 50fbf29b3b0ffabf0600e1f419acea304825966d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Gr=C3=BCnbacher?= Date: Thu, 22 May 2014 00:07:37 +0200 Subject: [PATCH 2/2] Newmenus: Fix unsigned underflow on "end" variable --- amxmodx/newmenus.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index 681fcea1..0cbba984 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -361,13 +361,13 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) { if (start + items_per_page >= numItems) { - end = numItems - 1; + end = numItems; flags &= ~Display_Next; } else { - end = start + items_per_page - 1; + end = start + items_per_page; } } else { - end = numItems - 1; + end = numItems; if (end > 10) { end = 10; @@ -388,7 +388,7 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) int slots = 0; int option_display = 0; - for (item_t i = start; i <= end; i++) + for (item_t i = start; i < end; i++) { // reset enabled enabled = true;