From ce1b013e8971abafaecb2033b98c917729391df8 Mon Sep 17 00:00:00 2001 From: Mistrick Date: Mon, 27 Aug 2018 21:00:59 +0700 Subject: [PATCH] Add menu number format --- amxmodx/newmenus.cpp | 66 +++++++++++++++++++++++++----------- amxmodx/newmenus.h | 2 ++ plugins/include/newmenus.inc | 5 +++ 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index b16b9b57..ca18ef44 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -90,7 +90,7 @@ bool CloseNewMenus(CPlayer *pPlayer) return true; } -Menu::Menu(const char *title, AMX *amx, int fid) : m_Title(title), m_ItemColor("\\r"), +Menu::Menu(const char *title, AMX *amx, int fid) : m_Title(title), m_ItemColor("\\r"), m_NumberFormat("%d."), m_NeverExit(false), m_AutoColors(g_coloredmenus), thisId(0), func(fid), isDestroying(false), pageCallback(-1), showPageNumber(true), items_per_page(7) { @@ -413,6 +413,8 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) int slots = 0; int option_display = 0; + char number_format[16]; + for (item_t i = start; i < end; i++) { // reset enabled @@ -462,6 +464,8 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) option_display = 0; } + ke::SafeSprintf(number_format, sizeof(number_format), m_NumberFormat.chars(), option_display); + if (pItem->isBlank) { ke::SafeSprintf(buffer, sizeof(buffer), "%s\n", pItem->name.chars()); @@ -470,14 +474,15 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) { if (m_AutoColors) { - ke::SafeSprintf(buffer, sizeof(buffer), "%s%d.\\w %s\n", m_ItemColor.chars(),option_display, pItem->name.chars()); + + ke::SafeSprintf(buffer, sizeof(buffer), "%s%s\\w %s\n", m_ItemColor.chars(), number_format, pItem->name.chars()); } else { - ke::SafeSprintf(buffer, sizeof(buffer), "%d. %s\n", option_display, pItem->name.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "%s %s\n", number_format, pItem->name.chars()); } } else { if (m_AutoColors) { - ke::SafeSprintf(buffer, sizeof(buffer), "\\d%d. %s\n\\w", option_display, pItem->name.chars()); + ke::SafeSprintf(buffer, sizeof(buffer), "\\d%s\\d %s\n\\w", number_format, pItem->name.chars()); } else { ke::SafeSprintf(buffer, sizeof(buffer), "#. %s\n", pItem->name.chars()); } @@ -519,29 +524,31 @@ const char *Menu::GetTextString(int player, page_t page, int &keys) if (flags & Display_Back) { keys |= (1<m_NumberFormat = str; + + break; + } case MPROP_PAGE_CALLBACK: { const char *str = get_amxstring_null(amx, params[3], 0, len); diff --git a/amxmodx/newmenus.h b/amxmodx/newmenus.h index df132df1..c640088b 100755 --- a/amxmodx/newmenus.h +++ b/amxmodx/newmenus.h @@ -32,6 +32,7 @@ #define MPROP_SET_NUMBER_COLOR 10 #define MPROP_PAGE_CALLBACK 11 #define MPROP_SHOWPAGE 12 +#define MPROP_NUMBER_FORMAT 13 typedef int (*MENUITEM_CALLBACK)(int, int, int); @@ -116,6 +117,7 @@ public: ke::AutoString m_Text; ke::AString m_OptNames[4]; ke::AString m_ItemColor; + ke::AString m_NumberFormat; bool m_NeverExit; bool m_ForceExit; diff --git a/plugins/include/newmenus.inc b/plugins/include/newmenus.inc index 9485ab2f..0786c977 100644 --- a/plugins/include/newmenus.inc +++ b/plugins/include/newmenus.inc @@ -86,6 +86,11 @@ */ #define MPROP_SHOWPAGE 12 +/* + * Number format (param1 = string, "#num."=default, should contain "#num") + */ +#define MPROP_NUMBER_FORMAT 13 + /** * @deprecated */