- added request amb426

- "Back" is now "Previous" and "Back" is used for ExitBack
- menu api got bumped again, but will be compat

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401011
This commit is contained in:
David Anderson
2007-06-22 21:04:13 +00:00
parent efea4ebbcb
commit 38f95fc63d
9 changed files with 166 additions and 47 deletions
+24 -4
View File
@@ -625,6 +625,7 @@ skip_search:
{
bool canDrawDisabled = display->CanDrawItem(ITEMDRAW_DISABLED|ITEMDRAW_CONTROL);
bool exitButton = menu->GetExitButton();
bool exitBackButton = menu->GetExitBackButton();
char text[50];
/* Calculate how many items we are allowed for control stuff */
@@ -650,6 +651,17 @@ skip_search:
/* Subtract two slots for the displayNext/displayPrev padding */
padding -= 2;
/* If we have an "Exit Back" button and the space to draw it, do so. */
if (exitBackButton)
{
if (!displayPrev)
{
displayPrev = true;
} else {
exitBackButton = false;
}
}
/**
* We allow next/prev to be undrawn if neither exists.
* Thus, we only need padding if one of them will be drawn,
@@ -690,10 +702,18 @@ skip_search:
ItemDrawInfo padCtrlItem(NULL, ITEMDRAW_SPACER|ITEMDRAW_CONTROL);
if (displayPrev || canDrawDisabled)
{
CorePlayerTranslate(client, text, sizeof(text), "Back", NULL);
dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
position = display->DrawItem(dr);
slots[position].type = ItemSel_Back;
if (exitBackButton)
{
CorePlayerTranslate(client, text, sizeof(text), "Back", NULL);
dr.style = ITEMDRAW_CONTROL;
position = display->DrawItem(dr);
slots[position].type = ItemSel_ExitBack;
} else {
CorePlayerTranslate(client, text, sizeof(text), "Previous", NULL);
dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
position = display->DrawItem(dr);
slots[position].type = ItemSel_Back;
}
} else if (displayNext || exitButton) {
/* If we can't display this, and there is an exit button,
* we need to pad!
+27 -16
View File
@@ -53,7 +53,7 @@ void BaseMenuStyle::RemoveClientFromWatch(int client)
m_WatchList.remove(client);
}
void BaseMenuStyle::_CancelClientMenu(int client, bool bAutoIgnore/* =false */, MenuCancelReason reason/* =MenuCancel_Interrupt */)
void BaseMenuStyle::_CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore/* =false */)
{
#if defined MENU_DEBUG
g_Logger.LogMessage("[SM_MENU] _CancelClientMenu() (client %d) (bAutoIgnore %d) (reason %d)", client, bAutoIgnore, reason);
@@ -107,7 +107,7 @@ void BaseMenuStyle::CancelMenu(CBaseMenu *menu)
menu_states_t &states = player->states;
if (states.menu == menu)
{
_CancelClientMenu(i);
_CancelClientMenu(i, MenuCancel_Interrupted);
}
}
}
@@ -129,7 +129,7 @@ bool BaseMenuStyle::CancelClientMenu(int client, bool autoIgnore)
return false;
}
_CancelClientMenu(client, autoIgnore);
_CancelClientMenu(client, MenuCancel_Interrupted, autoIgnore);
return true;
}
@@ -180,7 +180,7 @@ void BaseMenuStyle::OnClientDisconnected(int client)
return;
}
_CancelClientMenu(client, true, MenuCancel_Disconnect);
_CancelClientMenu(client, MenuCancel_Disconnected, true);
player->bInMenu = false;
player->bInExternMenu = false;
@@ -232,7 +232,7 @@ void BaseMenuStyle::ProcessWatchList()
}
if (curTime > player->menuStartTime + player->menuHoldTime)
{
_CancelClientMenu(client, false);
_CancelClientMenu(client, MenuCancel_Timeout, false);
}
}
}
@@ -253,6 +253,7 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
bool cancel = false;
unsigned int item = 0;
MenuCancelReason reason = MenuCancel_Exit;
MenuEndReason end_reason = MenuEnd_Selected;
menu_states_t &states = player->states;
assert(states.mh != NULL);
@@ -272,6 +273,7 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
{
cancel = true;
reason = MenuCancel_NoDisplay;
end_reason = MenuEnd_Cancelled;
} else {
return;
}
@@ -280,11 +282,18 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
{
cancel = true; /* I like Saltines. */
reason = MenuCancel_NoDisplay;
end_reason = MenuEnd_Cancelled;
} else {
return;
}
} else if (type == ItemSel_Exit || type == ItemSel_None) {
cancel = true;
reason = MenuCancel_Exit;
end_reason = MenuEnd_Exit;
} else if (type == ItemSel_ExitBack) {
cancel = true;
reason = MenuCancel_ExitBack;
end_reason = MenuEnd_ExitBack;
} else {
item = states.slots[key_press].item;
}
@@ -311,14 +320,6 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
/* Only fire end for valid menus */
if (menu)
{
MenuEndReason end_reason =
(cancel ?
MenuEnd_Selected
:
(reason == MenuCancel_Exit ?
MenuEnd_Exit
:
MenuEnd_Cancelled));
mh->OnMenuEnd(menu, end_reason);
}
}
@@ -355,7 +356,7 @@ bool BaseMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh,
menu_states_t &states = player->states;
if (player->bInMenu)
{
_CancelClientMenu(client, true);
_CancelClientMenu(client, MenuCancel_Interrupted, true);
}
states.firstItem = 0;
@@ -429,7 +430,7 @@ bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh,
#if defined MENU_DEBUG
g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Cancelling old menu to client %d", client);
#endif
_CancelClientMenu(client, true);
_CancelClientMenu(client, MenuCancel_Interrupted, true);
}
states.firstItem = 0;
@@ -518,7 +519,7 @@ CBaseMenu::CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t
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_pVoteHandler(NULL), m_ExitBackButton(false)
{
}
@@ -789,3 +790,13 @@ bool CBaseMenu::IsVoteInProgress()
{
return (m_pVoteHandler && m_pVoteHandler->IsVoteInProgress());
}
bool CBaseMenu::GetExitBackButton()
{
return m_ExitBackButton;
}
void CBaseMenu::SetExitBackButton(bool set)
{
m_ExitBackButton = set;
}
+6 -3
View File
@@ -81,7 +81,7 @@ public: //helpers
void CancelMenu(CBaseMenu *menu);
void ClientPressedKey(int client, unsigned int key_press);
protected:
void _CancelClientMenu(int client, bool bAutoIgnore=false, MenuCancelReason reason=MenuCancel_Interrupt);
void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
bool RedoClientMenu(int client, ItemOrder order);
protected:
FastLink<int> m_WatchList;
@@ -111,11 +111,13 @@ public:
virtual void Destroy(bool releaseHandle);
virtual void Cancel_Finally() =0;
virtual Handle_t GetHandle();
bool BroadcastVote(int clients[],
virtual bool BroadcastVote(int clients[],
unsigned int numClients,
unsigned int maxTime,
unsigned int flags=0);
bool IsVoteInProgress();
virtual bool IsVoteInProgress();
virtual bool GetExitBackButton();
virtual void SetExitBackButton(bool set);
public:
virtual void VoteDisplay(int client, unsigned int maxTime) =0;
private:
@@ -135,6 +137,7 @@ protected:
Handle_t m_hHandle;
IMenuHandler *m_pHandler;
IVoteMenuHandler *m_pVoteHandler;
bool m_ExitBackButton;
};
#endif //_INCLUDE_MENUSTYLE_BASE_H
+1 -1
View File
@@ -130,7 +130,7 @@ void CRadioStyle::OnUserMessageSent(int msg_id)
#endif
if (m_players[client].bInMenu)
{
_CancelClientMenu(client, true);
_CancelClientMenu(client, MenuCancel_Interrupted, true);
}
m_players[client].bInExternMenu = true;
m_players[client].menuHoldTime = g_last_holdtime;
+1 -1
View File
@@ -95,7 +95,7 @@ void ValveMenuStyle::HookCreateMessage(edict_t *pEdict,
* day to avenge its grandfather, killed in the great Menu Interruption
* battle.
*/
_CancelClientMenu(client, true);
_CancelClientMenu(client, MenuCancel_Interrupted, true);
}
}
+32
View File
@@ -617,6 +617,20 @@ static cell_t GetMenuExitButton(IPluginContext *pContext, const cell_t *params)
return menu->GetExitButton() ? 1 : 0;
}
static cell_t GetMenuExitBackButton(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->GetExitBackButton() ? 1 : 0;
}
static cell_t SetMenuExitButton(IPluginContext *pContext, const cell_t *params)
{
Handle_t hndl = (Handle_t)params[1];
@@ -631,6 +645,22 @@ static cell_t SetMenuExitButton(IPluginContext *pContext, const cell_t *params)
return menu->SetExitButton(params[2] ? true : false) ? 1 : 0;
}
static cell_t SetMenuExitBackButton(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->SetExitBackButton(params[2] ? true : false);
return 1;
}
static cell_t CancelMenu(IPluginContext *pContext, const cell_t *params)
{
Handle_t hndl = (Handle_t)params[1];
@@ -971,6 +1001,7 @@ REGISTER_NATIVES(menuNatives)
{"DrawPanelText", DrawPanelText},
{"GetClientMenu", GetClientMenu},
{"GetMaxPageItems", GetMaxPageItems},
{"GetMenuExitBackButton", GetMenuExitBackButton},
{"GetMenuExitButton", GetMenuExitButton},
{"GetMenuItem", GetMenuItem},
{"GetMenuItemCount", GetMenuItemCount},
@@ -984,6 +1015,7 @@ REGISTER_NATIVES(menuNatives)
{"RemoveAllMenuItems", RemoveAllMenuItems},
{"RemoveMenuItem", RemoveMenuItem},
{"SendPanelToClient", SendPanelToClient},
{"SetMenuExitBackButton", SetMenuExitBackButton},
{"SetMenuExitButton", SetMenuExitButton},
{"SetMenuPagination", SetMenuPagination},
{"SetMenuTitle", SetMenuTitle},