experimental changes to topmenu api -- drawing/displaying is now properly abstracted

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401532
This commit is contained in:
David Anderson 2007-10-02 15:13:13 +00:00
parent bd89b6d126
commit 5fa3cbf134
6 changed files with 95 additions and 24 deletions

View File

@ -462,6 +462,12 @@ void TopMenu::OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, uns
obj = *pObject; obj = *pObject;
style = obj->callbacks->OnTopMenuDrawOption(this, client, obj->object_id);
if (style != ITEMDRAW_DEFAULT)
{
return;
}
if (obj->cmdname[0] == '\0') if (obj->cmdname[0] == '\0')
{ {
return; return;
@ -496,7 +502,7 @@ unsigned int TopMenu::OnMenuDisplayItem(IBaseMenu *menu,
/* Ask the object to render the text for this client */ /* Ask the object to render the text for this client */
char renderbuf[64]; 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 */ /* Build the new draw info */
ItemDrawInfo new_dr = dr; ItemDrawInfo new_dr = dr;
@ -584,7 +590,7 @@ void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer)
{ {
obj_by_name_t *temp_obj = &item_list[i]; obj_by_name_t *temp_obj = &item_list[i];
topmenu_object_t *obj = m_Categories[m_UnsortedCats[i]]->obj; topmenu_object_t *obj = m_Categories[m_UnsortedCats[i]]->obj;
obj->callbacks->OnTopMenuDrawOption(this, obj->callbacks->OnTopMenuDisplayOption(this,
client, client,
obj->object_id, obj->object_id,
temp_obj->name, temp_obj->name,
@ -610,7 +616,7 @@ void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer)
/* Set the menu's title */ /* Set the menu's title */
char renderbuf[128]; 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); root_menu->SetDefaultTitle(renderbuf);
/* The client is now fully updated */ /* 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]; obj_by_name_t *item = &item_list[i];
topmenu_object_t *obj = cat->unsorted[i]; topmenu_object_t *obj = cat->unsorted[i];
obj->callbacks->OnTopMenuDrawOption(this, obj->callbacks->OnTopMenuDisplayOption(this,
client, client,
obj->object_id, obj->object_id,
item->name, item->name,
@ -698,7 +704,7 @@ void TopMenu::UpdateClientCategory(int client, unsigned int category)
/* Set the menu's title */ /* Set the menu's title */
char renderbuf[128]; char renderbuf[128];
cat->obj->callbacks->OnTopMenuDrawTitle(this, cat->obj->callbacks->OnTopMenuDisplayTitle(this,
client, client,
cat->obj->object_id, cat->obj->object_id,
renderbuf, renderbuf,

View File

@ -63,9 +63,10 @@ void Shutdown_Natives()
enum TopMenuAction enum TopMenuAction
{ {
TopMenuAction_DrawOption = 0, TopMenuAction_DisplayOption = 0,
TopMenuAction_DrawTitle = 1, TopMenuAction_DisplayTitle = 1,
TopMenuAction_SelectOption = 2, TopMenuAction_SelectOption = 2,
TopMenuAction_DrawOption = 3,
}; };
class TopMenuCallbacks : public ITopMenuObjectCallbacks class TopMenuCallbacks : public ITopMenuObjectCallbacks
@ -77,31 +78,42 @@ public:
unsigned int OnTopMenuDrawOption(ITopMenu *menu, unsigned int OnTopMenuDrawOption(ITopMenu *menu,
int client, int client,
unsigned int object_id, unsigned int object_id)
char buffer[],
size_t maxlength)
{ {
cell_t result = ITEMDRAW_DEFAULT; char buffer[2] = {ITEMDRAW_DEFAULT, 0x0};
m_pFunction->PushCell(m_hMenuHandle); m_pFunction->PushCell(m_hMenuHandle);
m_pFunction->PushCell(TopMenuAction_DrawOption); m_pFunction->PushCell(TopMenuAction_DrawOption);
m_pFunction->PushCell(object_id); m_pFunction->PushCell(object_id);
m_pFunction->PushCell(client); m_pFunction->PushCell(client);
m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK); m_pFunction->PushStringEx(buffer, sizeof(buffer), 0, SM_PARAM_COPYBACK);
m_pFunction->PushCell(maxlength); m_pFunction->PushCell(sizeof(buffer));
m_pFunction->Execute(&result); m_pFunction->Execute(NULL);
return (unsigned int)buffer[0];
return result;
} }
void OnTopMenuDrawTitle(ITopMenu *menu, void OnTopMenuDisplayOption(ITopMenu *menu,
int client, int client,
unsigned int object_id, unsigned int object_id,
char buffer[], char buffer[],
size_t maxlength) size_t maxlength)
{ {
m_pFunction->PushCell(m_hMenuHandle); m_pFunction->PushCell(m_hMenuHandle);
m_pFunction->PushCell(TopMenuAction_DrawTitle); 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(NULL);
}
void OnTopMenuDisplayTitle(ITopMenu *menu,
int client,
unsigned int object_id,
char buffer[],
size_t maxlength)
{
m_pFunction->PushCell(m_hMenuHandle);
m_pFunction->PushCell(TopMenuAction_DisplayTitle);
m_pFunction->PushCell(object_id); m_pFunction->PushCell(object_id);
m_pFunction->PushCell(client); m_pFunction->PushCell(client);
m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK); m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK);

View File

@ -28,6 +28,10 @@ public AdminMenu_CancelVote(Handle:topmenu,
PerformCancelVote(param); PerformCancelVote(param);
RedisplayAdminMenu(topmenu, param); RedisplayAdminMenu(topmenu, param);
} }
else if (action == TopMenuAction_DrawOption)
{
buffer[0] = IsVoteInProgress() ? ITEMDRAW_DEFAULT : ITEMDRAW_IGNORE;
}
} }
public Action:Command_CancelVote(client, args) public Action:Command_CancelVote(client, args)

View File

@ -45,7 +45,7 @@ enum TopMenuAction
/** /**
* An option is being drawn for a menu (or for sorting purposes). * 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. * OUTPUT: Buffer for rendering, maxlength of buffer.
*/ */
TopMenuAction_DisplayOption = 0, TopMenuAction_DisplayOption = 0,
@ -56,7 +56,7 @@ enum TopMenuAction
* Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the * Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the
* root title. Otherwise, the Object ID is a category. * 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. * OUTPUT: Buffer for rendering, maxlength of buffer.
*/ */
TopMenuAction_DisplayTitle = 1, TopMenuAction_DisplayTitle = 1,
@ -66,9 +66,19 @@ enum TopMenuAction
* *
* The Object ID will always be an item (not a category). * 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, 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,
}; };
/** /**

View File

@ -43,7 +43,7 @@
*/ */
#define SMINTERFACE_TOPMENUS_NAME "ITopMenus" #define SMINTERFACE_TOPMENUS_NAME "ITopMenus"
#define SMINTERFACE_TOPMENUS_VERSION 1 #define SMINTERFACE_TOPMENUS_VERSION 2
namespace SourceMod namespace SourceMod
{ {
@ -87,22 +87,42 @@ namespace SourceMod
/** /**
* @brief Requests how the given item should be drawn for a client. * @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 menu A pointer to the parent ITopMenu.
* @param client Client index. * @param client Client index.
* @param object_id Object ID returned from ITopMenu::AddToMenu(). * @param object_id Object ID returned from ITopMenu::AddToMenu().
* @param buffer Buffer to store rendered text. * @param buffer Buffer to store rendered text.
* @param maxlength Maximum length of the rendering buffer. * @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, int client,
unsigned int object_id, unsigned int object_id,
char buffer[], char buffer[],
size_t maxlength) =0; 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. * a client. This is called on any object_id that is a category.
* *
* @param menu A pointer to the parent ITopMenu. * @param menu A pointer to the parent ITopMenu.
@ -112,7 +132,7 @@ namespace SourceMod
* @param buffer Buffer to store rendered text. * @param buffer Buffer to store rendered text.
* @param maxlength Maximum length of the rendering buffer. * @param maxlength Maximum length of the rendering buffer.
*/ */
virtual void OnTopMenuDrawTitle(ITopMenu *menu, virtual void OnTopMenuDisplayTitle(ITopMenu *menu,
int client, int client,
unsigned int object_id, unsigned int object_id,
char buffer[], char buffer[],
@ -223,6 +243,14 @@ namespace SourceMod
public: public:
virtual const char *GetInterfaceName() =0; virtual const char *GetInterfaceName() =0;
virtual unsigned int GetInterfaceVersion() =0; virtual unsigned int GetInterfaceVersion() =0;
virtual bool IsVersionCompatible(unsigned int version)
{
if (version < 2)
{
return false;
}
return SMInterface::IsVersionCompatible(version);
}
public: public:
/** /**
* @brief Creates a new top-level menu. * @brief Creates a new top-level menu.
@ -243,3 +271,4 @@ namespace SourceMod
} }
#endif //_INCLUDE_SOURCEMOD_MAIN_MENU_INTERFACE_H_ #endif //_INCLUDE_SOURCEMOD_MAIN_MENU_INTERFACE_H_

View File

@ -204,6 +204,11 @@
"en" "Cancelled the vote." "en" "Cancelled the vote."
} }
"Cancel vote"
{
"en" "Cancel vote"
}
"Vote Select" "Vote Select"
{ {
"#format" "{1:s},{2:s}" "#format" "{1:s},{2:s}"
@ -262,6 +267,11 @@
"en" "Server Commands" "en" "Server Commands"
} }
"Voting Commands"
{
"en" "Voting Commands"
}
"Reload admins" "Reload admins"
{ {
"en" "Reload admins" "en" "Reload admins"