diff --git a/configs/cfg/sourcemod.cfg b/configs/cfg/sourcemod.cfg index 06ec42f2..59228419 100644 --- a/configs/cfg/sourcemod.cfg +++ b/configs/cfg/sourcemod.cfg @@ -13,6 +13,12 @@ // Default: 13 (1+4+8) sm_show_activity 13 +// Specifies whether menu sounds are enabled for menus created by SourceMod. +// Menu sounds can be further configured in addons/sourcemod/configs/core.cfg. +// -- +// Default: 1 +sm_menu_sounds 1 + // Specifies the amount of time that is allowed between chat messages. This // includes the say and say_team commands. If a client sends a message faster // than this time, they receive a flood token. When the client has accumulated diff --git a/configs/core.cfg b/configs/core.cfg index 5e2091d3..fecd11f0 100644 --- a/configs/core.cfg +++ b/configs/core.cfg @@ -52,4 +52,16 @@ * passwords to work, for security reasons. */ "PassInfoVar" "_password" + + /** + * Specifies the sound that gets played when an item is selected from a menu. + */ + "MenuItemSound" "buttons/button14.wav" + + /** + * Specifies the sound that gets played when an "Exit Back" button is selected + * from a menu. This is the special "Back" button that is intended to roll back + * to a previous menu. + */ + "MenuExitBackSound" "buttons/combine_button7.wav" } diff --git a/core/MenuManager.cpp b/core/MenuManager.cpp index d6e5f207..95f8520c 100644 --- a/core/MenuManager.cpp +++ b/core/MenuManager.cpp @@ -22,9 +22,12 @@ #include "MenuStyle_Valve.h" #include "ShareSys.h" #include "HandleSys.h" +#include "sourcemm_api.h" MenuManager g_Menus; +ConVar sm_menu_sounds("sm_menu_sounds", "1", 0, "Sets whether SourceMod menus play trigger sounds"); + /******************************* ******************************* ******** VOTE HANDLER ********* @@ -803,3 +806,60 @@ void MenuManager::ReleaseVoteWrapper(IVoteMenuHandler *mh) m_VoteHandlers.push((VoteMenuHandler *)mh); } + +bool MenuManager::MenuSoundsEnabled() +{ + return (sm_menu_sounds.GetInt() != 0); +} + +ConfigResult MenuManager::OnSourceModConfigChanged(const char *key, + const char *value, + ConfigSource source, + char *error, + size_t maxlength) +{ + if (strcmp(key, "MenuItemSound") == 0) + { + m_SelectSound.assign(value); + return ConfigResult_Accept; + } else if (strcmp(key, "MenuExitBackSound") == 0) { + m_ExitBackSound.assign(value); + return ConfigResult_Accept; + } + + return ConfigResult_Ignore; +} + +const char *MenuManager::GetMenuSound(ItemSelection sel) +{ + const char *sound = NULL; + + switch (sel) + { + case ItemSel_Back: + case ItemSel_Next: + case ItemSel_Exit: + case ItemSel_Item: + { + if (m_SelectSound.size() > 0) + { + sound = m_SelectSound.c_str(); + } + break; + } + case ItemSel_ExitBack: + { + if (m_ExitBackSound.size() > 0) + { + sound = m_ExitBackSound.c_str(); + } + break; + } + default: + { + break; + } + } + + return sound; +} diff --git a/core/MenuManager.h b/core/MenuManager.h index a79e4e6a..91f7e366 100644 --- a/core/MenuManager.h +++ b/core/MenuManager.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "sm_memtable.h" #include "sm_globals.h" @@ -72,6 +73,11 @@ public: public: //SMGlobalClass void OnSourceModAllInitialized(); void OnSourceModAllShutdown(); + ConfigResult OnSourceModConfigChanged(const char *key, + const char *value, + ConfigSource source, + char *error, + size_t maxlength); public: //IMenuManager virtual const char *GetInterfaceName() { @@ -96,6 +102,9 @@ public: //IHandleTypeDispatch public: HandleError ReadMenuHandle(Handle_t handle, IBaseMenu **menu); HandleError ReadStyleHandle(Handle_t handle, IMenuStyle **style); +public: + bool MenuSoundsEnabled(); + const char *GetMenuSound(ItemSelection sel); protected: Handle_t CreateMenuHandle(IBaseMenu *menu, IdentityToken_t *pOwner); Handle_t CreateStyleHandle(IMenuStyle *style); @@ -106,6 +115,8 @@ private: CVector m_Styles; HandleType_t m_StyleType; HandleType_t m_MenuType; + String m_SelectSound; + String m_ExitBackSound; }; extern MenuManager g_Menus; diff --git a/core/MenuStyle_Base.cpp b/core/MenuStyle_Base.cpp index 477b036a..aa20409b 100644 --- a/core/MenuStyle_Base.cpp +++ b/core/MenuStyle_Base.cpp @@ -18,6 +18,7 @@ #include "PlayerManager.h" #include "MenuManager.h" #include "HandleSys.h" +#include "CellRecipientFilter.h" #if defined MENU_DEBUG #include "Logger.h" #endif @@ -276,6 +277,42 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) } else { ItemSelection type = states.slots[key_press].type; + /* Check if we should play a sound about the type */ + if (g_Menus.MenuSoundsEnabled()) + { + CellRecipientFilter filter; + cell_t clients[1]; + + clients[0] = client; + filter.Initialize(clients, 1); + + const char *sound = g_Menus.GetMenuSound(type); + + if (sound != NULL) + { + edict_t *pEdict = engine->PEntityOfEntIndex(client); + if (pEdict) + { + ICollideable *pCollideable = pEdict->GetCollideable(); + + if (pCollideable) + { + const Vector & pos = pCollideable->GetCollisionOrigin(); + + enginesound->EmitSound(filter, + client, + CHAN_AUTO, + sound, + VOL_NORM, + ATTN_NORM, + 0, + PITCH_NORM, + &pos); + } + } + } + } + /* For navigational items, we're going to redisplay */ if (type == ItemSel_Back) {