diff --git a/extensions/topmenus/TopMenu.cpp b/extensions/topmenus/TopMenu.cpp index a9d2bcd3..ee4f1eb5 100644 --- a/extensions/topmenus/TopMenu.cpp +++ b/extensions/topmenus/TopMenu.cpp @@ -462,6 +462,12 @@ void TopMenu::OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, uns obj = *pObject; + style = obj->callbacks->OnTopMenuDrawOption(this, client, obj->object_id); + if (style != ITEMDRAW_DEFAULT) + { + return; + } + if (obj->cmdname[0] == '\0') { return; @@ -496,7 +502,7 @@ unsigned int TopMenu::OnMenuDisplayItem(IBaseMenu *menu, /* Ask the object to render the text for this client */ char renderbuf[64]; - obj->callbacks->OnTopMenuDrawOption(this, client, obj->object_id, renderbuf, sizeof(renderbuf)); + obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, renderbuf, sizeof(renderbuf)); /* Build the new draw info */ ItemDrawInfo new_dr = dr; @@ -584,7 +590,7 @@ void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer) { obj_by_name_t *temp_obj = &item_list[i]; topmenu_object_t *obj = m_Categories[m_UnsortedCats[i]]->obj; - obj->callbacks->OnTopMenuDrawOption(this, + obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, temp_obj->name, @@ -610,7 +616,7 @@ void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer) /* Set the menu's title */ char renderbuf[128]; - m_pTitle->OnTopMenuDrawTitle(this, client, 0, renderbuf, sizeof(renderbuf)); + m_pTitle->OnTopMenuDisplayTitle(this, client, 0, renderbuf, sizeof(renderbuf)); root_menu->SetDefaultTitle(renderbuf); /* The client is now fully updated */ @@ -676,7 +682,7 @@ void TopMenu::UpdateClientCategory(int client, unsigned int category) { obj_by_name_t *item = &item_list[i]; topmenu_object_t *obj = cat->unsorted[i]; - obj->callbacks->OnTopMenuDrawOption(this, + obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, item->name, @@ -698,7 +704,7 @@ void TopMenu::UpdateClientCategory(int client, unsigned int category) /* Set the menu's title */ char renderbuf[128]; - cat->obj->callbacks->OnTopMenuDrawTitle(this, + cat->obj->callbacks->OnTopMenuDisplayTitle(this, client, cat->obj->object_id, renderbuf, diff --git a/extensions/topmenus/smn_topmenus.cpp b/extensions/topmenus/smn_topmenus.cpp index e9ecc39a..53733937 100644 --- a/extensions/topmenus/smn_topmenus.cpp +++ b/extensions/topmenus/smn_topmenus.cpp @@ -63,9 +63,10 @@ void Shutdown_Natives() enum TopMenuAction { - TopMenuAction_DrawOption = 0, - TopMenuAction_DrawTitle = 1, + TopMenuAction_DisplayOption = 0, + TopMenuAction_DisplayTitle = 1, TopMenuAction_SelectOption = 2, + TopMenuAction_DrawOption = 3, }; class TopMenuCallbacks : public ITopMenuObjectCallbacks @@ -76,32 +77,43 @@ public: } unsigned int OnTopMenuDrawOption(ITopMenu *menu, + int client, + unsigned int object_id) + { + char buffer[2] = {ITEMDRAW_DEFAULT, 0x0}; + m_pFunction->PushCell(m_hMenuHandle); + m_pFunction->PushCell(TopMenuAction_DrawOption); + m_pFunction->PushCell(object_id); + m_pFunction->PushCell(client); + m_pFunction->PushStringEx(buffer, sizeof(buffer), 0, SM_PARAM_COPYBACK); + m_pFunction->PushCell(sizeof(buffer)); + m_pFunction->Execute(NULL); + return (unsigned int)buffer[0]; + } + + void OnTopMenuDisplayOption(ITopMenu *menu, int client, unsigned int object_id, char buffer[], size_t maxlength) { - cell_t result = ITEMDRAW_DEFAULT; - m_pFunction->PushCell(m_hMenuHandle); - m_pFunction->PushCell(TopMenuAction_DrawOption); + m_pFunction->PushCell(TopMenuAction_DisplayOption); m_pFunction->PushCell(object_id); m_pFunction->PushCell(client); m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK); m_pFunction->PushCell(maxlength); - m_pFunction->Execute(&result); - - return result; + m_pFunction->Execute(NULL); } - void OnTopMenuDrawTitle(ITopMenu *menu, + void OnTopMenuDisplayTitle(ITopMenu *menu, int client, unsigned int object_id, char buffer[], size_t maxlength) { m_pFunction->PushCell(m_hMenuHandle); - m_pFunction->PushCell(TopMenuAction_DrawTitle); + m_pFunction->PushCell(TopMenuAction_DisplayTitle); m_pFunction->PushCell(object_id); m_pFunction->PushCell(client); m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK); diff --git a/plugins/basecommands/cancelvote.sp b/plugins/basecommands/cancelvote.sp index 17f51572..d7f91339 100644 --- a/plugins/basecommands/cancelvote.sp +++ b/plugins/basecommands/cancelvote.sp @@ -28,6 +28,10 @@ public AdminMenu_CancelVote(Handle:topmenu, PerformCancelVote(param); RedisplayAdminMenu(topmenu, param); } + else if (action == TopMenuAction_DrawOption) + { + buffer[0] = IsVoteInProgress() ? ITEMDRAW_DEFAULT : ITEMDRAW_IGNORE; + } } public Action:Command_CancelVote(client, args) diff --git a/plugins/include/topmenus.inc b/plugins/include/topmenus.inc index a780c551..a99b834f 100644 --- a/plugins/include/topmenus.inc +++ b/plugins/include/topmenus.inc @@ -45,7 +45,7 @@ enum TopMenuAction /** * An option is being drawn for a menu (or for sorting purposes). * - * INPUT : TopMenu Handle, object ID, client index in extra parameter. + * INPUT : TopMenu Handle, object ID, client index. * OUTPUT: Buffer for rendering, maxlength of buffer. */ TopMenuAction_DisplayOption = 0, @@ -56,7 +56,7 @@ enum TopMenuAction * Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the * root title. Otherwise, the Object ID is a category. * - * INPUT : TopMenu Handle, object ID, client index in extra parameter. + * INPUT : TopMenu Handle, object ID, client index. * OUTPUT: Buffer for rendering, maxlength of buffer. */ TopMenuAction_DisplayTitle = 1, @@ -66,9 +66,19 @@ enum TopMenuAction * * The Object ID will always be an item (not a category). * - * INPUT : TopMenu Handle, object ID, client index in extra parameter. + * INPUT : TopMenu Handle, object ID, client index. */ TopMenuAction_SelectOption = 2, + + /** + * A menu option is being drawn and its flags can be overridden. + * + * INPUT : TopMenu Handle, object ID, client index. + * OUTPUT: The first byte of the 'buffer' string should be set + * to the desired flags. By default, it will contain + * ITEMDRAW_DEFAULT. + */ + TopMenuAction_DrawOption = 3, }; /** diff --git a/public/extensions/ITopMenus.h b/public/extensions/ITopMenus.h index 06b00fef..02f4bd35 100644 --- a/public/extensions/ITopMenus.h +++ b/public/extensions/ITopMenus.h @@ -43,7 +43,7 @@ */ #define SMINTERFACE_TOPMENUS_NAME "ITopMenus" -#define SMINTERFACE_TOPMENUS_VERSION 1 +#define SMINTERFACE_TOPMENUS_VERSION 2 namespace SourceMod { @@ -87,22 +87,42 @@ namespace SourceMod /** * @brief Requests how the given item should be drawn for a client. * + * Unlike the other callbacks, this is only called in determining + * whether to enable, disable, or ignore an item on a client's menu. + * + * @param menu A pointer to the parent ITopMenu. + * @param client Client index. + * @param object_id Object ID returned from ITopMenu::AddToMenu(). + * @return ITEMDRAW flags to disable or not draw the + * option for this operation. + */ + virtual unsigned int OnTopMenuDrawOption(ITopMenu *menu, + int client, + unsigned int object_id) + { + return ITEMDRAW_DEFAULT; + } + + /** + * @brief Requests how the given item should be displayed for a client. + * + * This can be called either while drawing a menu or to decide how to + * sort a menu for a player. + * * @param menu A pointer to the parent ITopMenu. * @param client Client index. * @param object_id Object ID returned from ITopMenu::AddToMenu(). * @param buffer Buffer to store rendered text. * @param maxlength Maximum length of the rendering buffer. - * @return ITEMDRAW flags to disable or not draw the - * option for this operation. */ - virtual unsigned int OnTopMenuDrawOption(ITopMenu *menu, + virtual void OnTopMenuDisplayOption(ITopMenu *menu, int client, unsigned int object_id, char buffer[], size_t maxlength) =0; /** - * @brief Requests how the given item's title should be drawn for + * @brief Requests how the given item's title should be displayed for * a client. This is called on any object_id that is a category. * * @param menu A pointer to the parent ITopMenu. @@ -112,7 +132,7 @@ namespace SourceMod * @param buffer Buffer to store rendered text. * @param maxlength Maximum length of the rendering buffer. */ - virtual void OnTopMenuDrawTitle(ITopMenu *menu, + virtual void OnTopMenuDisplayTitle(ITopMenu *menu, int client, unsigned int object_id, char buffer[], @@ -223,6 +243,14 @@ namespace SourceMod public: virtual const char *GetInterfaceName() =0; virtual unsigned int GetInterfaceVersion() =0; + virtual bool IsVersionCompatible(unsigned int version) + { + if (version < 2) + { + return false; + } + return SMInterface::IsVersionCompatible(version); + } public: /** * @brief Creates a new top-level menu. @@ -243,3 +271,4 @@ namespace SourceMod } #endif //_INCLUDE_SOURCEMOD_MAIN_MENU_INTERFACE_H_ + diff --git a/translations/common.phrases.txt b/translations/common.phrases.txt index 481101f9..03f05595 100644 --- a/translations/common.phrases.txt +++ b/translations/common.phrases.txt @@ -203,6 +203,11 @@ { "en" "Cancelled the vote." } + + "Cancel vote" + { + "en" "Cancel vote" + } "Vote Select" { @@ -261,6 +266,11 @@ { "en" "Server Commands" } + + "Voting Commands" + { + "en" "Voting Commands" + } "Reload admins" {