From 70f22ab3ab4cd84a154f264c50e0c94fdd2f5442 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 3 Aug 2007 11:40:21 +0000 Subject: [PATCH] implemented amb705 (you can now disable sounds per-menu) --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401265 --- core/MenuStyle_Base.cpp | 51 +++++++++++++++++++++++++++------------ core/MenuStyle_Base.h | 5 ++-- core/MenuStyle_Valve.cpp | 6 +++++ core/MenuStyle_Valve.h | 1 + core/smn_menus.cpp | 32 ++++++++++++++++++++++++ plugins/include/menus.inc | 26 ++++++++++++++++++++ public/IMenuManager.h | 20 ++++++++++++++- 7 files changed, 123 insertions(+), 18 deletions(-) diff --git a/core/MenuStyle_Base.cpp b/core/MenuStyle_Base.cpp index 10ce3d78..1325f7a3 100644 --- a/core/MenuStyle_Base.cpp +++ b/core/MenuStyle_Base.cpp @@ -285,9 +285,13 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) MenuEndReason end_reason = MenuEnd_Selected; menu_states_t &states = player->states; - assert(states.mh != NULL); + /* Save variables */ + IMenuHandler *mh = states.mh; + IBaseMenu *menu = states.menu; - if (states.menu == NULL) + assert(mh != NULL); + + if (menu == NULL) { item = key_press; } else if (key_press < 1 || key_press > GetMaxPageItems()) { @@ -296,7 +300,8 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) ItemSelection type = states.slots[key_press].type; /* Check if we should play a sound about the type */ - if (g_Menus.MenuSoundsEnabled()) + if (g_Menus.MenuSoundsEnabled() && + (!menu || (menu->GetMenuOptionFlags() & MENUFLAG_NO_SOUND) != MENUFLAG_NO_SOUND)) { CellRecipientFilter filter; cell_t clients[1]; @@ -364,10 +369,6 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) } } - /* Save variables */ - IMenuHandler *mh = states.mh; - IBaseMenu *menu = states.menu; - /* Clear states */ player->bInMenu = false; if (player->menuHoldTime) @@ -581,10 +582,10 @@ bool BaseMenuStyle::RedoClientMenu(int client, ItemOrder order) } CBaseMenu::CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner) : -m_pStyle(pStyle), m_Strings(512), m_Pagination(7), m_ExitButton(true), -m_bShouldDelete(false), m_bCancelling(false), m_pOwner(pOwner ? pOwner : g_pCoreIdent), -m_bDeleting(false), m_bWillFreeHandle(false), m_hHandle(BAD_HANDLE), m_pHandler(pHandler), -m_pVoteHandler(NULL), m_ExitBackButton(false) +m_pStyle(pStyle), m_Strings(512), m_Pagination(7), m_bShouldDelete(false), m_bCancelling(false), +m_pOwner(pOwner ? pOwner : g_pCoreIdent), m_bDeleting(false), m_bWillFreeHandle(false), +m_hHandle(BAD_HANDLE), m_pHandler(pHandler), m_pVoteHandler(NULL), +m_nFlags(MENUFLAG_BUTTON_EXIT) { } @@ -733,12 +734,17 @@ const char *CBaseMenu::GetDefaultTitle() bool CBaseMenu::GetExitButton() { - return m_ExitButton; + return ((m_nFlags & MENUFLAG_BUTTON_EXIT) == MENUFLAG_BUTTON_EXIT); } bool CBaseMenu::SetExitButton(bool set) { - m_ExitButton = set; + if (set) + { + m_nFlags |= MENUFLAG_BUTTON_EXIT; + } else { + m_nFlags &= ~MENUFLAG_BUTTON_EXIT; + } return true; } @@ -860,10 +866,25 @@ bool CBaseMenu::IsVoteInProgress() bool CBaseMenu::GetExitBackButton() { - return m_ExitBackButton; + return ((m_nFlags & MENUFLAG_BUTTON_EXITBACK) == MENUFLAG_BUTTON_EXITBACK); } void CBaseMenu::SetExitBackButton(bool set) { - m_ExitBackButton = set; + if (set) + { + m_nFlags |= MENUFLAG_BUTTON_EXITBACK; + } else { + m_nFlags &= ~MENUFLAG_BUTTON_EXITBACK; + } +} + +unsigned int CBaseMenu::GetMenuOptionFlags() +{ + return m_nFlags; +} + +void CBaseMenu::SetMenuOptionFlags(unsigned int flags) +{ + m_nFlags = flags; } diff --git a/core/MenuStyle_Base.h b/core/MenuStyle_Base.h index e46c1ff3..3e4f6a7c 100644 --- a/core/MenuStyle_Base.h +++ b/core/MenuStyle_Base.h @@ -138,6 +138,8 @@ public: virtual bool IsVoteInProgress(); virtual bool GetExitBackButton(); virtual void SetExitBackButton(bool set); + virtual unsigned int GetMenuOptionFlags(); + virtual void SetMenuOptionFlags(unsigned int flags); public: virtual void VoteDisplay(int client, unsigned int maxTime) =0; private: @@ -148,7 +150,6 @@ protected: BaseStringTable m_Strings; unsigned int m_Pagination; CVector m_items; - bool m_ExitButton; bool m_bShouldDelete; bool m_bCancelling; IdentityToken_t *m_pOwner; @@ -157,7 +158,7 @@ protected: Handle_t m_hHandle; IMenuHandler *m_pHandler; IVoteMenuHandler *m_pVoteHandler; - bool m_ExitBackButton; + unsigned int m_nFlags; }; #endif //_INCLUDE_MENUSTYLE_BASE_H diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index ae310678..5e4fc7a7 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -418,6 +418,12 @@ bool CValveMenu::SetExitButton(bool set) return false; } +void CValveMenu::SetMenuOptionFlags(unsigned int flags) +{ + flags &= ~MENUFLAG_BUTTON_EXIT; + CBaseMenu::SetMenuOptionFlags(flags); +} + const char *g_OptionNumTable[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" diff --git a/core/MenuStyle_Valve.h b/core/MenuStyle_Valve.h index 36ab1dc1..c4c7eb9f 100644 --- a/core/MenuStyle_Valve.h +++ b/core/MenuStyle_Valve.h @@ -122,6 +122,7 @@ public: //IBaseMenu bool SetPagination(unsigned int itemsPerPage); bool Display(int client, unsigned int time); void VoteDisplay(int client, unsigned int maxTime); + void SetMenuOptionFlags(unsigned int flags); public: //CBaseMenu void Cancel_Finally(); private: diff --git a/core/smn_menus.cpp b/core/smn_menus.cpp index c400b620..233cb7de 100644 --- a/core/smn_menus.cpp +++ b/core/smn_menus.cpp @@ -1092,6 +1092,36 @@ static cell_t RedrawMenuItem(IPluginContext *pContext, const cell_t *params) return s_CurPanelReturn; } +static cell_t GetMenuOptionFlags(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = (Handle_t)params[1]; + HandleError err; + IBaseMenu *menu; + + if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) + { + return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); + } + + return menu->GetMenuOptionFlags(); +} + +static cell_t SetMenuOptionFlags(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = (Handle_t)params[1]; + HandleError err; + IBaseMenu *menu; + + if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) + { + return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); + } + + menu->SetMenuOptionFlags(params[2]); + + return 1; +} + REGISTER_NATIVES(menuNatives) { {"AddMenuItem", AddMenuItem}, @@ -1111,6 +1141,7 @@ REGISTER_NATIVES(menuNatives) {"GetMenuExitButton", GetMenuExitButton}, {"GetMenuItem", GetMenuItem}, {"GetMenuItemCount", GetMenuItemCount}, + {"GetMenuOptionFlags", GetMenuOptionFlags}, {"GetMenuPagination", GetMenuPagination}, {"GetMenuStyle", GetMenuStyle}, {"GetMenuStyleHandle", GetMenuStyleHandle}, @@ -1124,6 +1155,7 @@ REGISTER_NATIVES(menuNatives) {"SendPanelToClient", SendPanelToClient}, {"SetMenuExitBackButton", SetMenuExitBackButton}, {"SetMenuExitButton", SetMenuExitButton}, + {"SetMenuOptionFlags", SetMenuOptionFlags}, {"SetMenuPagination", SetMenuPagination}, {"SetMenuTitle", SetMenuTitle}, {"SetPanelCurrentKey", SetPanelCurrentKey}, diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index dde6a96a..20e6b4a7 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -64,6 +64,10 @@ enum MenuAction #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) */ +#define MENUFLAG_BUTTON_EXIT (1<<0) /**< Menu has an "exit" button */ +#define MENUFLAG_BUTTON_EXITBACK (1<<1) /**< Menu has an "exit back" button */ +#define MENUFLAG_NO_SOUND (1<<2) /**< Menu will not have any select sounds */ + /** * Reasons a menu can be cancelled. */ @@ -324,6 +328,28 @@ native SetMenuExitBackButton(Handle:menu, bool:button); */ native CancelMenu(Handle:menu); +/** + * Retrieves a menu's option flags. + * + * @param menu Menu Handle. + * @return A bitstring of MENUFLAG bits. + * @error Invalid Handle. + */ +native GetMenuOptionFlags(Handle:menu); + +/** + * Sets a menu's option flags. + * + * If a certain bit is not supported, it will be stripped before + * being set. + * + * @param menu Menu Handle. + * @param flags A new bitstring of MENUFLAG bits. + * @noreturn + * @error Invalid Handle. + */ +native SetMenuOptionFlags(Handle:menu, flags); + /** * Returns whether a vote is in progress on the given menu. * diff --git a/public/IMenuManager.h b/public/IMenuManager.h index 7b6aab5c..7bbf954e 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -37,7 +37,7 @@ #include #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager" -#define SMINTERFACE_MENUMANAGER_VERSION 7 +#define SMINTERFACE_MENUMANAGER_VERSION 8 /** * @file IMenuManager.h @@ -147,6 +147,10 @@ namespace SourceMod #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */ #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */ + #define MENUFLAG_BUTTON_EXIT (1<<0) /**< Menu has an "exit" button */ + #define MENUFLAG_BUTTON_EXITBACK (1<<1) /**< Menu has an "exit back" button */ + #define MENUFLAG_NO_SOUND (1<<2) /**< Menu will not have any select sounds */ + /** * @brief Extended menu options. */ @@ -567,6 +571,20 @@ namespace SourceMod * @param set True to enable, false to disable. */ virtual void SetExitBackButton(bool set) =0; + + /** + * @brief Returns menu option flags. + * + * @return Menu option flags. + */ + virtual unsigned int GetMenuOptionFlags() =0; + + /** + * @brief Sets menu option flags. + * + * @param flags Menu option flags. + */ + virtual void SetMenuOptionFlags(unsigned int flags) =0; }; /**