experimental changes to topmenu api -- drawing/displaying is now properly abstracted
experimental changes to topmenu api -- drawing/displaying is now properly abstracted
1.1 --- a/extensions/topmenus/TopMenu.cpp Tue Oct 02 14:48:44 2007 +0000
1.2 +++ b/extensions/topmenus/TopMenu.cpp Tue Oct 02 15:13:13 2007 +0000
1.3 @@ -462,6 +462,12 @@
1.4
1.5 obj = *pObject;
1.6
1.7 + style = obj->callbacks->OnTopMenuDrawOption(this, client, obj->object_id);
1.8 + if (style != ITEMDRAW_DEFAULT)
1.9 + {
1.10 + return;
1.11 + }
1.12 +
1.13 if (obj->cmdname[0] == '\0')
1.14 {
1.15 return;
1.16 @@ -496,7 +502,7 @@
1.17
1.18 /* Ask the object to render the text for this client */
1.19 char renderbuf[64];
1.20 - obj->callbacks->OnTopMenuDrawOption(this, client, obj->object_id, renderbuf, sizeof(renderbuf));
1.21 + obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, renderbuf, sizeof(renderbuf));
1.22
1.23 /* Build the new draw info */
1.24 ItemDrawInfo new_dr = dr;
1.25 @@ -584,7 +590,7 @@
1.26 {
1.27 obj_by_name_t *temp_obj = &item_list[i];
1.28 topmenu_object_t *obj = m_Categories[m_UnsortedCats[i]]->obj;
1.29 - obj->callbacks->OnTopMenuDrawOption(this,
1.30 + obj->callbacks->OnTopMenuDisplayOption(this,
1.31 client,
1.32 obj->object_id,
1.33 temp_obj->name,
1.34 @@ -610,7 +616,7 @@
1.35
1.36 /* Set the menu's title */
1.37 char renderbuf[128];
1.38 - m_pTitle->OnTopMenuDrawTitle(this, client, 0, renderbuf, sizeof(renderbuf));
1.39 + m_pTitle->OnTopMenuDisplayTitle(this, client, 0, renderbuf, sizeof(renderbuf));
1.40 root_menu->SetDefaultTitle(renderbuf);
1.41
1.42 /* The client is now fully updated */
1.43 @@ -676,7 +682,7 @@
1.44 {
1.45 obj_by_name_t *item = &item_list[i];
1.46 topmenu_object_t *obj = cat->unsorted[i];
1.47 - obj->callbacks->OnTopMenuDrawOption(this,
1.48 + obj->callbacks->OnTopMenuDisplayOption(this,
1.49 client,
1.50 obj->object_id,
1.51 item->name,
1.52 @@ -698,7 +704,7 @@
1.53
1.54 /* Set the menu's title */
1.55 char renderbuf[128];
1.56 - cat->obj->callbacks->OnTopMenuDrawTitle(this,
1.57 + cat->obj->callbacks->OnTopMenuDisplayTitle(this,
1.58 client,
1.59 cat->obj->object_id,
1.60 renderbuf,
2.1 --- a/extensions/topmenus/smn_topmenus.cpp Tue Oct 02 14:48:44 2007 +0000
2.2 +++ b/extensions/topmenus/smn_topmenus.cpp Tue Oct 02 15:13:13 2007 +0000
2.3 @@ -63,9 +63,10 @@
2.4
2.5 enum TopMenuAction
2.6 {
2.7 - TopMenuAction_DrawOption = 0,
2.8 - TopMenuAction_DrawTitle = 1,
2.9 + TopMenuAction_DisplayOption = 0,
2.10 + TopMenuAction_DisplayTitle = 1,
2.11 TopMenuAction_SelectOption = 2,
2.12 + TopMenuAction_DrawOption = 3,
2.13 };
2.14
2.15 class TopMenuCallbacks : public ITopMenuObjectCallbacks
2.16 @@ -76,32 +77,43 @@
2.17 }
2.18
2.19 unsigned int OnTopMenuDrawOption(ITopMenu *menu,
2.20 + int client,
2.21 + unsigned int object_id)
2.22 + {
2.23 + char buffer[2] = {ITEMDRAW_DEFAULT, 0x0};
2.24 + m_pFunction->PushCell(m_hMenuHandle);
2.25 + m_pFunction->PushCell(TopMenuAction_DrawOption);
2.26 + m_pFunction->PushCell(object_id);
2.27 + m_pFunction->PushCell(client);
2.28 + m_pFunction->PushStringEx(buffer, sizeof(buffer), 0, SM_PARAM_COPYBACK);
2.29 + m_pFunction->PushCell(sizeof(buffer));
2.30 + m_pFunction->Execute(NULL);
2.31 + return (unsigned int)buffer[0];
2.32 + }
2.33 +
2.34 + void OnTopMenuDisplayOption(ITopMenu *menu,
2.35 int client,
2.36 unsigned int object_id,
2.37 char buffer[],
2.38 size_t maxlength)
2.39 {
2.40 - cell_t result = ITEMDRAW_DEFAULT;
2.41 -
2.42 m_pFunction->PushCell(m_hMenuHandle);
2.43 - m_pFunction->PushCell(TopMenuAction_DrawOption);
2.44 + m_pFunction->PushCell(TopMenuAction_DisplayOption);
2.45 m_pFunction->PushCell(object_id);
2.46 m_pFunction->PushCell(client);
2.47 m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK);
2.48 m_pFunction->PushCell(maxlength);
2.49 - m_pFunction->Execute(&result);
2.50 -
2.51 - return result;
2.52 + m_pFunction->Execute(NULL);
2.53 }
2.54
2.55 - void OnTopMenuDrawTitle(ITopMenu *menu,
2.56 + void OnTopMenuDisplayTitle(ITopMenu *menu,
2.57 int client,
2.58 unsigned int object_id,
2.59 char buffer[],
2.60 size_t maxlength)
2.61 {
2.62 m_pFunction->PushCell(m_hMenuHandle);
2.63 - m_pFunction->PushCell(TopMenuAction_DrawTitle);
2.64 + m_pFunction->PushCell(TopMenuAction_DisplayTitle);
2.65 m_pFunction->PushCell(object_id);
2.66 m_pFunction->PushCell(client);
2.67 m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK);
3.1 --- a/plugins/basecommands/cancelvote.sp Tue Oct 02 14:48:44 2007 +0000
3.2 +++ b/plugins/basecommands/cancelvote.sp Tue Oct 02 15:13:13 2007 +0000
3.3 @@ -28,6 +28,10 @@
3.4 PerformCancelVote(param);
3.5 RedisplayAdminMenu(topmenu, param);
3.6 }
3.7 + else if (action == TopMenuAction_DrawOption)
3.8 + {
3.9 + buffer[0] = IsVoteInProgress() ? ITEMDRAW_DEFAULT : ITEMDRAW_IGNORE;
3.10 + }
3.11 }
3.12
3.13 public Action:Command_CancelVote(client, args)
4.1 --- a/plugins/include/topmenus.inc Tue Oct 02 14:48:44 2007 +0000
4.2 +++ b/plugins/include/topmenus.inc Tue Oct 02 15:13:13 2007 +0000
4.3 @@ -45,7 +45,7 @@
4.4 /**
4.5 * An option is being drawn for a menu (or for sorting purposes).
4.6 *
4.7 - * INPUT : TopMenu Handle, object ID, client index in extra parameter.
4.8 + * INPUT : TopMenu Handle, object ID, client index.
4.9 * OUTPUT: Buffer for rendering, maxlength of buffer.
4.10 */
4.11 TopMenuAction_DisplayOption = 0,
4.12 @@ -56,7 +56,7 @@
4.13 * Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the
4.14 * root title. Otherwise, the Object ID is a category.
4.15 *
4.16 - * INPUT : TopMenu Handle, object ID, client index in extra parameter.
4.17 + * INPUT : TopMenu Handle, object ID, client index.
4.18 * OUTPUT: Buffer for rendering, maxlength of buffer.
4.19 */
4.20 TopMenuAction_DisplayTitle = 1,
4.21 @@ -66,9 +66,19 @@
4.22 *
4.23 * The Object ID will always be an item (not a category).
4.24 *
4.25 - * INPUT : TopMenu Handle, object ID, client index in extra parameter.
4.26 + * INPUT : TopMenu Handle, object ID, client index.
4.27 */
4.28 TopMenuAction_SelectOption = 2,
4.29 +
4.30 + /**
4.31 + * A menu option is being drawn and its flags can be overridden.
4.32 + *
4.33 + * INPUT : TopMenu Handle, object ID, client index.
4.34 + * OUTPUT: The first byte of the 'buffer' string should be set
4.35 + * to the desired flags. By default, it will contain
4.36 + * ITEMDRAW_DEFAULT.
4.37 + */
4.38 + TopMenuAction_DrawOption = 3,
4.39 };
4.40
4.41 /**
5.1 --- a/public/extensions/ITopMenus.h Tue Oct 02 14:48:44 2007 +0000
5.2 +++ b/public/extensions/ITopMenus.h Tue Oct 02 15:13:13 2007 +0000
5.3 @@ -43,7 +43,7 @@
5.4 */
5.5
5.6 #define SMINTERFACE_TOPMENUS_NAME "ITopMenus"
5.7 -#define SMINTERFACE_TOPMENUS_VERSION 1
5.8 +#define SMINTERFACE_TOPMENUS_VERSION 2
5.9
5.10 namespace SourceMod
5.11 {
5.12 @@ -87,22 +87,42 @@
5.13 /**
5.14 * @brief Requests how the given item should be drawn for a client.
5.15 *
5.16 + * Unlike the other callbacks, this is only called in determining
5.17 + * whether to enable, disable, or ignore an item on a client's menu.
5.18 + *
5.19 + * @param menu A pointer to the parent ITopMenu.
5.20 + * @param client Client index.
5.21 + * @param object_id Object ID returned from ITopMenu::AddToMenu().
5.22 + * @return ITEMDRAW flags to disable or not draw the
5.23 + * option for this operation.
5.24 + */
5.25 + virtual unsigned int OnTopMenuDrawOption(ITopMenu *menu,
5.26 + int client,
5.27 + unsigned int object_id)
5.28 + {
5.29 + return ITEMDRAW_DEFAULT;
5.30 + }
5.31 +
5.32 + /**
5.33 + * @brief Requests how the given item should be displayed for a client.
5.34 + *
5.35 + * This can be called either while drawing a menu or to decide how to
5.36 + * sort a menu for a player.
5.37 + *
5.38 * @param menu A pointer to the parent ITopMenu.
5.39 * @param client Client index.
5.40 * @param object_id Object ID returned from ITopMenu::AddToMenu().
5.41 * @param buffer Buffer to store rendered text.
5.42 * @param maxlength Maximum length of the rendering buffer.
5.43 - * @return ITEMDRAW flags to disable or not draw the
5.44 - * option for this operation.
5.45 */
5.46 - virtual unsigned int OnTopMenuDrawOption(ITopMenu *menu,
5.47 + virtual void OnTopMenuDisplayOption(ITopMenu *menu,
5.48 int client,
5.49 unsigned int object_id,
5.50 char buffer[],
5.51 size_t maxlength) =0;
5.52
5.53 /**
5.54 - * @brief Requests how the given item's title should be drawn for
5.55 + * @brief Requests how the given item's title should be displayed for
5.56 * a client. This is called on any object_id that is a category.
5.57 *
5.58 * @param menu A pointer to the parent ITopMenu.
5.59 @@ -112,7 +132,7 @@
5.60 * @param buffer Buffer to store rendered text.
5.61 * @param maxlength Maximum length of the rendering buffer.
5.62 */
5.63 - virtual void OnTopMenuDrawTitle(ITopMenu *menu,
5.64 + virtual void OnTopMenuDisplayTitle(ITopMenu *menu,
5.65 int client,
5.66 unsigned int object_id,
5.67 char buffer[],
5.68 @@ -223,6 +243,14 @@
5.69 public:
5.70 virtual const char *GetInterfaceName() =0;
5.71 virtual unsigned int GetInterfaceVersion() =0;
5.72 + virtual bool IsVersionCompatible(unsigned int version)
5.73 + {
5.74 + if (version < 2)
5.75 + {
5.76 + return false;
5.77 + }
5.78 + return SMInterface::IsVersionCompatible(version);
5.79 + }
5.80 public:
5.81 /**
5.82 * @brief Creates a new top-level menu.
5.83 @@ -243,3 +271,4 @@
5.84 }
5.85
5.86 #endif //_INCLUDE_SOURCEMOD_MAIN_MENU_INTERFACE_H_
5.87 +
6.1 --- a/translations/common.phrases.txt Tue Oct 02 14:48:44 2007 +0000
6.2 +++ b/translations/common.phrases.txt Tue Oct 02 15:13:13 2007 +0000
6.3 @@ -203,6 +203,11 @@
6.4 {
6.5 "en" "Cancelled the vote."
6.6 }
6.7 +
6.8 + "Cancel vote"
6.9 + {
6.10 + "en" "Cancel vote"
6.11 + }
6.12
6.13 "Vote Select"
6.14 {
6.15 @@ -261,6 +266,11 @@
6.16 {
6.17 "en" "Server Commands"
6.18 }
6.19 +
6.20 + "Voting Commands"
6.21 + {
6.22 + "en" "Voting Commands"
6.23 + }
6.24
6.25 "Reload admins"
6.26 {