diff --git a/core/MenuManager.cpp b/core/MenuManager.cpp index 2b0aa9df..a3e2d794 100644 --- a/core/MenuManager.cpp +++ b/core/MenuManager.cpp @@ -468,7 +468,7 @@ skip_search: /* Now, we need to check if we need to add anything extra */ if (pgn != MENU_NO_PAGINATION) { - bool canDrawDisabled = display->CanDrawItem(ITEMDRAW_DISABLED); + bool canDrawDisabled = display->CanDrawItem(ITEMDRAW_DISABLED|ITEMDRAW_CONTROL); bool exitButton = menu->GetExitButton(); char text[50]; @@ -517,34 +517,48 @@ skip_search: display->DrawItem(draw); } - /* PREVIOUS */ ItemDrawInfo dr(text, 0); - if (displayPrev || canDrawDisabled) + /** + * If we have one or the other, we need to have spacers for both. + */ + if (displayPrev || displayNext) { - CorePlayerTranslate(client, text, sizeof(text), "Back", NULL); - dr.style = displayPrev ? 0 : ITEMDRAW_DISABLED; - position = display->DrawItem(dr); - slots[position].type = ItemSel_Back; - } else if ((displayNext || canDrawDisabled) || exitButton) { - /* If we can't display this, - * but there is a "next" or "exit" button, we need to pad! - */ - position = display->DrawItem(padItem); - slots[position].type = ItemSel_None; - } + /* PREVIOUS */ + ItemDrawInfo padCtrlItem(NULL, ITEMDRAW_SPACER|ITEMDRAW_CONTROL); + if (displayPrev || canDrawDisabled) + { + CorePlayerTranslate(client, text, sizeof(text), "Back", NULL); + dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL; + position = display->DrawItem(dr); + slots[position].type = ItemSel_Back; + } else if (displayNext || exitButton) { + /* If we can't display this, and there is an exit button, + * we need to pad! + */ + position = display->DrawItem(padCtrlItem); + slots[position].type = ItemSel_None; + } - /* NEXT */ - if (displayNext || canDrawDisabled) - { - CorePlayerTranslate(client, text, sizeof(text), "Next", NULL); - dr.style = displayNext ? 0 : ITEMDRAW_DISABLED; - position = display->DrawItem(dr); - slots[position].type = ItemSel_Next; - } else if (exitButton) { - /* If we can't display this, - * but there is an exit button, we need to pad! - */ - position = display->DrawItem(padItem); + /* NEXT */ + if (displayNext || canDrawDisabled) + { + CorePlayerTranslate(client, text, sizeof(text), "Next", NULL); + dr.style = (displayNext ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL; + position = display->DrawItem(dr); + slots[position].type = ItemSel_Next; + } else if (exitButton) { + /* If we can't display this, + * but there is an "exit" button, we need to pad! + */ + position = display->DrawItem(padCtrlItem); + slots[position].type = ItemSel_None; + } + } else { + /* Otherwise, bump to two slots! */ + ItemDrawInfo numBump(NULL, ITEMDRAW_NOTEXT); + position = display->DrawItem(numBump); + slots[position].type = ItemSel_None; + position = display->DrawItem(numBump); slots[position].type = ItemSel_None; } @@ -552,7 +566,7 @@ skip_search: if (exitButton) { CorePlayerTranslate(client, text, sizeof(text), "Exit", NULL); - dr.style = 0; + dr.style = ITEMDRAW_CONTROL; position = display->DrawItem(dr); slots[position].type = ItemSel_Exit; } diff --git a/core/MenuStyle_Base.cpp b/core/MenuStyle_Base.cpp index acc7a111..02531725 100644 --- a/core/MenuStyle_Base.cpp +++ b/core/MenuStyle_Base.cpp @@ -200,7 +200,7 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) if (states.menu == NULL) { item = key_press; - } else if (key_press < 1 || key_press > 8) { + } else if (key_press < 1 || key_press > GetMaxPageItems()) { cancel = true; } else { ItemSelection type = states.slots[key_press].type; diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index 1c6d485d..60c386e9 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -20,13 +20,20 @@ extern const char *g_RadioNumTable[]; CRadioStyle g_RadioMenuStyle; int g_ShowMenuId = -1; +bool g_bRadioInit = false; CRadioStyle::CRadioStyle() : m_players(new CBaseMenuPlayer[256+1]) { } -void CRadioStyle::OnSourceModAllInitialized() +void CRadioStyle::OnSourceModLevelChange(const char *mapName) { + if (g_bRadioInit) + { + return; + } + + g_bRadioInit = true; const char *msg = g_pGameConf->GetKeyValue("HudRadioMenuMsg"); if (!msg || msg[0] == '\0') { @@ -66,8 +73,10 @@ bool CRadioStyle::OnClientCommand(int client) { return false; } + int arg = atoi(engine->Cmd_Argv(1)); ClientPressedKey(client, arg); + return true; } return false; @@ -161,6 +170,7 @@ void CRadioDisplay::Reset() m_BufferText.assign(""); m_Title.assign(""); m_NextPos = 1; + keys = 0; } bool CRadioDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned int time) @@ -198,25 +208,27 @@ unsigned int CRadioDisplay::DrawItem(const ItemDrawInfo &item) { if (item.style & ITEMDRAW_SPACER) { - m_BufferText.append("\n"); + m_BufferText.append(" \n"); } else { m_BufferText.append(item.display); m_BufferText.append("\n"); } return 0; } else if (item.style & ITEMDRAW_SPACER) { - m_BufferText.append("\n"); + m_BufferText.append(" \n"); + return m_NextPos++; + } else if (item.style & ITEMDRAW_NOTEXT) { return m_NextPos++; } if (item.style & ITEMDRAW_DISABLED) { m_BufferText.append(g_RadioNumTable[m_NextPos]); - m_BufferText.append(". "); m_BufferText.append(item.display); m_BufferText.append("\n"); } else { - m_BufferText.append("->. "); + m_BufferText.append("->"); + m_BufferText.append(g_RadioNumTable[m_NextPos]); m_BufferText.append(item.display); m_BufferText.append("\n"); keys |= (1<<(m_NextPos-1)); @@ -232,6 +244,11 @@ bool CRadioDisplay::CanDrawItem(unsigned int drawFlags) return false; } + if ((drawFlags & ITEMDRAW_DISABLED) && (drawFlags & ITEMDRAW_CONTROL)) + { + return false; + } + return true; } @@ -301,5 +318,5 @@ void CRadioMenu::Cancel_Finally() const char *g_RadioNumTable[11] = { - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" + "0. ", "1. ", "2. ", "3. ", "4. ", "5. ", "6. ", "7. ", "8. ", "9. ", "0. " }; diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index dd25e1ea..da6bd5e2 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -33,7 +33,7 @@ class CRadioStyle : public: CRadioStyle(); public: //SMGlobalClass - void OnSourceModAllInitialized(); + void OnSourceModLevelChange(const char *mapName); void OnSourceModShutdown(); public: //BaseMenuStyle CBaseMenuPlayer *GetMenuPlayer(int client); diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index 2d052234..74d4e4d3 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -27,15 +27,6 @@ extern const char *g_OptionCmdTable[]; IServerPluginCallbacks *g_pVSPHandle = NULL; CallClass *g_pSPHCC = NULL; -class TestHandler : public IMenuHandler -{ -public: - virtual void OnMenuEnd(IBaseMenu *menu) - { - menu->Destroy(); - } -}; - ValveMenuStyle::ValveMenuStyle() : m_players(new CValveMenuPlayer[256+1]) { } diff --git a/public/IMenuManager.h b/public/IMenuManager.h index b48479a8..3819d644 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -84,6 +84,7 @@ namespace SourceMod #define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */ #define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */ #define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */ + #define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */ /** * @brief Information about item drawing.