added API for menus to re-display from a previous page

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401480
This commit is contained in:
David Anderson 2007-09-26 01:04:22 +00:00
parent 69c65a848b
commit efbf57ac90
10 changed files with 97 additions and 10 deletions

View File

@ -366,7 +366,9 @@ IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder ord
}
}
}
} else if (order == ItemOrder_Ascending) {
}
else if (order == ItemOrder_Ascending)
{
lastItem = drawItems[0].position;
if (lastItem == 0)
{

View File

@ -288,6 +288,8 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
IMenuHandler *mh = states.mh;
IBaseMenu *menu = states.menu;
unsigned int item_on_page = states.firstItem;
assert(mh != NULL);
if (menu == NULL)
@ -380,6 +382,10 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
mh->OnMenuCancel(menu, client, reason);
} else {
mh->OnMenuSelect(menu, client, item);
if (mh->GetMenuAPIVersion2() >= 13)
{
mh->OnMenuSelect2(menu, client, item, item_on_page);
}
}
/* Only fire end for valid menus */
@ -448,7 +454,11 @@ bool BaseMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh,
return true;
}
bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time)
bool BaseMenuStyle::DoClientMenu(int client,
CBaseMenu *menu,
unsigned int first_item,
IMenuHandler *mh,
unsigned int time)
{
#if defined MENU_DEBUG
g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (menu %p) (mh %p) (time %d)",
@ -498,7 +508,7 @@ bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh,
_CancelClientMenu(client, MenuCancel_Interrupted, true);
}
states.firstItem = 0;
states.firstItem = first_item;
states.lastItem = 0;
states.menu = menu;
states.mh = mh;

View File

@ -91,7 +91,11 @@ public: //what derived must implement
virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
virtual void SendDisplay(int client, IMenuPanel *display) =0;
public: //what derived may implement
virtual bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time);
virtual bool DoClientMenu(int client,
CBaseMenu *menu,
unsigned int first_item,
IMenuHandler *mh,
unsigned int time);
virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
virtual void AddClientToWatch(int client);
virtual void RemoveClientFromWatch(int client);

View File

@ -398,6 +398,14 @@ IMenuPanel *CRadioMenu::CreatePanel()
}
bool CRadioMenu::Display(int client, unsigned int time, IMenuHandler *alt_handler)
{
return DisplayAtItem(client, time, 0, alt_handler);
}
bool CRadioMenu::DisplayAtItem(int client,
unsigned int time,
unsigned int start_item,
IMenuHandler *alt_handler)
{
#if defined MENU_DEBUG
g_Logger.LogMessage("[SM_MENU] CRadioMenu::Display(%p) (client %d) (time %d)",
@ -410,7 +418,11 @@ bool CRadioMenu::Display(int client, unsigned int time, IMenuHandler *alt_handle
return false;
}
return g_RadioMenuStyle.DoClientMenu(client, this, alt_handler ? alt_handler : m_pHandler, time);
return g_RadioMenuStyle.DoClientMenu(client,
this,
start_item,
alt_handler ? alt_handler : m_pHandler,
time);
}
void CRadioMenu::Cancel_Finally()

View File

@ -115,6 +115,10 @@ public:
bool SetExtOption(MenuOption option, const void *valuePtr);
IMenuPanel *CreatePanel();
bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL);
bool DisplayAtItem(int client,
unsigned int time,
unsigned int start_item,
IMenuHandler *alt_handler/* =NULL */);
void Cancel_Finally();
};

View File

@ -156,7 +156,7 @@ bool ValveMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh
return BaseMenuStyle::DoClientMenu(client, menu, mh, time);
}
bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time)
bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, unsigned int first_item, IMenuHandler *mh, unsigned int time)
{
if (!g_pVSPHandle)
{
@ -166,7 +166,7 @@ bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh,
return false;
}
return BaseMenuStyle::DoClientMenu(client, menu, mh, time);
return BaseMenuStyle::DoClientMenu(client, menu, first_item, mh, time);
}
CValveMenuDisplay::CValveMenuDisplay()
@ -387,13 +387,21 @@ bool CValveMenu::SetExtOption(MenuOption option, const void *valuePtr)
}
bool CValveMenu::Display(int client, unsigned int time, IMenuHandler *alt_handler)
{
return DisplayAtItem(client, time, 0, alt_handler);
}
bool CValveMenu::DisplayAtItem(int client,
unsigned int time,
unsigned int start_item,
IMenuHandler *alt_handler/* =NULL */)
{
if (m_bCancelling)
{
return false;
}
return g_ValveMenuStyle.DoClientMenu(client, this, alt_handler ? alt_handler : m_pHandler, time);
return g_ValveMenuStyle.DoClientMenu(client, this, start_item, alt_handler ? alt_handler : m_pHandler, time);
}
IMenuPanel *CValveMenu::CreatePanel()

View File

@ -63,7 +63,7 @@ public:
public: //BaseMenuStyle
CBaseMenuPlayer *GetMenuPlayer(int client);
void SendDisplay(int client, IMenuPanel *display);
bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time);
bool DoClientMenu(int client, CBaseMenu *menu, unsigned int first_item, IMenuHandler *mh, unsigned int time);
bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
public: //SMGlobalClass
void OnSourceModAllInitialized();
@ -121,6 +121,10 @@ public: //IBaseMenu
bool SetExitButton(bool set);
bool SetPagination(unsigned int itemsPerPage);
bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL);
bool DisplayAtItem(int client,
unsigned int time,
unsigned int start_item,
IMenuHandler *alt_handler/* =NULL */);
void SetMenuOptionFlags(unsigned int flags);
public: //CBaseMenu
void Cancel_Finally();

View File

@ -365,6 +365,14 @@ void VoteMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int ite
m_pHandler->OnMenuSelect(menu, client, item);
}
void VoteMenuHandler::OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page)
{
if (m_pHandler->GetMenuAPIVersion2() >= 13)
{
m_pHandler->OnMenuSelect2(menu, client, item, item_on_page);
}
}
void VoteMenuHandler::InternalReset()
{
m_Clients = 0;

View File

@ -56,6 +56,7 @@ public: //IMenuHandler
void OnMenuStart(IBaseMenu *menu);
void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display);
void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item);
void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page);
void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason);
void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);

View File

@ -36,7 +36,7 @@
#include <IHandleSys.h>
#define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
#define SMINTERFACE_MENUMANAGER_VERSION 12
#define SMINTERFACE_MENUMANAGER_VERSION 13
/**
* @file IMenuManager.h
@ -572,6 +572,22 @@ namespace SourceMod
* @return IMenuHandler of the menu.
*/
virtual IMenuHandler *GetHandler() =0;
/**
* @brief Sends the menu to a client, starting from the given item number.
*
* Note: this API call was added in v13.
*
* @param client Client index to display to.
* @param time Time to hold menu for.
* @param start_item Starting item to draw.
* @param alt_handler Alternate IMenuHandler.
* @return True on success, false otherwise.
*/
virtual bool DisplayAtItem(int client,
unsigned int time,
unsigned int start_item,
IMenuHandler *alt_handler=NULL) =0;
};
/**
@ -731,6 +747,24 @@ namespace SourceMod
{
return false;
}
/**
* @brief Called when an item is selected.
*
* Note: This callback was added in v13. It is called after OnMenuSelect().
*
* @param menu Menu pointer.
* @param client Client that selected the item.
* @param item Item number.
* @param item_on_page The first item on the page the player was last
* viewing.
*/
virtual void OnMenuSelect2(IBaseMenu *menu,
int client,
unsigned int item,
unsigned int item_on_page)
{
}
};
/**