Move menu sound selection from core config to gamedata. (#1896)

This commit is contained in:
Nicholas Hastings 2022-12-28 23:10:51 -05:00 committed by GitHub
parent 2130c60fd9
commit b0799d3336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 58 deletions

View File

@ -53,24 +53,6 @@
* 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" button is selected
* from a menu.
*/
"MenuExitSound" "buttons/combine_button7.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"
/**
* Enables or disables whether SourceMod reads a client's cl_language cvar to set

View File

@ -38,6 +38,7 @@
#include "sourcemm_api.h"
#include "PlayerManager.h"
#include "MenuStyle_Valve.h"
#include <IGameConfigs.h>
#include "sourcemm_api.h"
#include "logic_bridge.h"
@ -68,6 +69,29 @@ void MenuManager::OnSourceModAllInitialized()
m_StyleType = handlesys->CreateType("IMenuStyle", this, 0, NULL, &access, g_pCoreIdent, NULL);
}
void MenuManager::OnSourceModAllInitialized_Post()
{
const char* pTmp;
pTmp = g_pGameConf->GetKeyValue("MenuItemSound");
if (nullptr != pTmp)
{
m_SelectSound = pTmp;
}
pTmp = g_pGameConf->GetKeyValue("MenuExitSound");
if (nullptr != pTmp)
{
m_ExitSound = pTmp;
}
pTmp = g_pGameConf->GetKeyValue("MenuExitBackSound");
if (nullptr != pTmp)
{
m_ExitBackSound = pTmp;
}
}
void MenuManager::OnSourceModAllShutdown()
{
handlesys->RemoveType(m_MenuType, g_pCoreIdent);
@ -699,30 +723,9 @@ 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)
std::string *MenuManager::GetMenuSound(ItemSelection sel)
{
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;
} else if (strcmp(key, "MenuExitSound") == 0) {
m_ExitSound.assign(value);
return ConfigResult_Accept;
}
return ConfigResult_Ignore;
}
const char *MenuManager::GetMenuSound(ItemSelection sel)
{
const char *sound = NULL;
std::string *sound = nullptr;
switch (sel)
{
@ -732,7 +735,7 @@ const char *MenuManager::GetMenuSound(ItemSelection sel)
{
if (m_SelectSound.size() > 0)
{
sound = m_SelectSound.c_str();
sound = &m_SelectSound;
}
break;
}
@ -740,7 +743,7 @@ const char *MenuManager::GetMenuSound(ItemSelection sel)
{
if (m_ExitBackSound.size() > 0)
{
sound = m_ExitBackSound.c_str();
sound = &m_ExitBackSound;
}
break;
}
@ -748,7 +751,7 @@ const char *MenuManager::GetMenuSound(ItemSelection sel)
{
if (m_ExitSound.size() > 0)
{
sound = m_ExitSound.c_str();
sound = &m_ExitSound;
}
break;
}

View File

@ -36,8 +36,8 @@
#include <sh_vector.h>
#include <sh_stack.h>
#include <sh_list.h>
#include <sh_string.h>
#include "sm_globals.h"
#include <string>
using namespace SourceMod;
using namespace SourceHook;
@ -55,12 +55,8 @@ public:
MenuManager();
public: //SMGlobalClass
void OnSourceModAllInitialized();
void OnSourceModAllInitialized_Post();
void OnSourceModAllShutdown();
ConfigResult OnSourceModConfigChanged(const char *key,
const char *value,
ConfigSource source,
char *error,
size_t maxlength);
void OnSourceModLevelChange(const char *mapName);
public: //IMenuManager
virtual const char *GetInterfaceName()
@ -99,7 +95,7 @@ public:
HandleError ReadStyleHandle(Handle_t handle, IMenuStyle **style);
public:
bool MenuSoundsEnabled();
const char *GetMenuSound(ItemSelection sel);
std::string *GetMenuSound(ItemSelection sel);
protected:
Handle_t CreateMenuHandle(IBaseMenu *menu, IdentityToken_t *pOwner);
Handle_t CreateStyleHandle(IMenuStyle *style);
@ -109,9 +105,9 @@ private:
CVector<IMenuStyle *> m_Styles;
HandleType_t m_StyleType;
HandleType_t m_MenuType;
String m_SelectSound;
String m_ExitBackSound;
String m_ExitSound;
std::string m_SelectSound = "";
std::string m_ExitBackSound = "";
std::string m_ExitSound = "";
};
extern MenuManager g_Menus;

View File

@ -311,9 +311,9 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
clients[0] = client;
filter.Initialize(clients, 1);
const char *sound = g_Menus.GetMenuSound(type);
std::string *sound = g_Menus.GetMenuSound(type);
if (sound != NULL)
if (nullptr != sound && !sound->empty())
{
edict_t *pEdict = PEntityOfEntIndex(client);
if (pEdict)
@ -327,10 +327,10 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
client,
CHAN_AUTO,
#if SOURCE_ENGINE >= SE_PORTAL2
sound,
sound->c_str(),
-1,
#endif
sound,
sound->c_str(),
VOL_NORM,
ATTN_NORM,
#if SOURCE_ENGINE >= SE_PORTAL2

View File

@ -40,6 +40,7 @@
#include "UserMessages.h"
#include "sm_fastlink.h"
#include <sh_stack.h>
#include <sh_string.h>
#include <compat_wrappers.h>
#include "logic/common_logic.h"
#include "AutoHandleRooter.h"

View File

@ -387,4 +387,32 @@
"RadioMenuClosesOnInvalidSlot" "yes"
}
}
/**
* Menu Sounds
*/
"#default"
{
"Keys"
{
/**
* 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" button is selected
* from a menu.
*/
"MenuExitSound" "buttons/combine_button7.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"
}
}
}