From 601186fd6a01ac0414eeb5c514aaa9e2fbb3cb4e Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Mon, 2 Jul 2012 10:57:22 -0400 Subject: [PATCH] Added support for custom maxitems on radio menus (bug 5371, r=asherkin). --- core/MenuStyle_Radio.cpp | 38 +++++++++++++++++++++++++++++++++++--- core/MenuStyle_Radio.h | 1 + 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index de456e71..e8864560 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -45,6 +45,14 @@ int g_ShowMenuId = -1; bool g_bRadioInit = false; unsigned int g_RadioMenuTimeout = 0; +// back, next, exit +#define MAX_PAGINATION_OPTIONS 3 + +#define MAX_MENUSLOT_KEYS 10 + +static unsigned int s_RadioMaxPageItems = MAX_MENUSLOT_KEYS; + + CRadioStyle::CRadioStyle() { m_players = new CRadioMenuPlayer[256+1]; @@ -90,6 +98,18 @@ void CRadioStyle::OnSourceModLevelChange(const char *mapName) g_RadioMenuTimeout = 0; } + const char *items = g_pGameConf->GetKeyValue("RadioMenuMaxPageItems"); + if (items != NULL) + { + int value = atoi(items); + + // Only override the mostly-safe default if it's a sane value + if (value > MAX_PAGINATION_OPTIONS && value <= MAX_MENUSLOT_KEYS) + { + s_RadioMaxPageItems = value; + } + } + g_Menus.AddStyle(this); g_Menus.SetDefaultStyle(this); @@ -189,7 +209,7 @@ IBaseMenu *CRadioStyle::CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwn unsigned int CRadioStyle::GetMaxPageItems() { - return 10; + return s_RadioMaxPageItems; } const char *CRadioStyle::GetStyleName() @@ -307,7 +327,7 @@ unsigned int CRadioDisplay::GetCurrentKey() bool CRadioDisplay::SetCurrentKey(unsigned int key) { - if (key < m_NextPos || m_NextPos > 10) + if (key < m_NextPos || m_NextPos > s_RadioMaxPageItems) { return false; } @@ -343,7 +363,7 @@ void CRadioDisplay::DrawTitle(const char *text, bool onlyIfEmpty/* =false */) unsigned int CRadioDisplay::DrawItem(const ItemDrawInfo &item) { - if (m_NextPos > 10 || !CanDrawItem(item.style)) + if (m_NextPos > s_RadioMaxPageItems || !CanDrawItem(item.style)) { return 0; } @@ -511,6 +531,7 @@ unsigned int CRadioDisplay::GetApproxMemUsage() CRadioMenu::CRadioMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner) : CBaseMenu(pHandler, &g_RadioMenuStyle, pOwner) { + m_Pagination = s_RadioMaxPageItems - MAX_PAGINATION_OPTIONS; } bool CRadioMenu::SetExtOption(MenuOption option, const void *valuePtr) @@ -551,6 +572,17 @@ bool CRadioMenu::DisplayAtItem(int client, time); } +bool CRadioMenu::SetPagination(unsigned int itemsPerPage) +{ + const unsigned int maxPerPage = s_RadioMaxPageItems - MAX_PAGINATION_OPTIONS; + if (itemsPerPage > maxPerPage) + { + return false; + } + + return CBaseMenu::SetPagination(itemsPerPage); +} + void CRadioMenu::Cancel_Finally() { g_RadioMenuStyle.CancelMenu(this); diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index f9d1dd66..29349814 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -142,6 +142,7 @@ public: unsigned int time, unsigned int start_item, IMenuHandler *alt_handler/* =NULL */); + bool SetPagination(unsigned int itemsPerPage); void Cancel_Finally(); unsigned int GetApproxMemUsage(); };