1.1 --- a/core/smn_menus.cpp Wed Sep 26 01:22:25 2007 +0000
1.2 +++ b/core/smn_menus.cpp Wed Sep 26 01:48:52 2007 +0000
1.3 @@ -89,7 +89,7 @@
1.4 public:
1.5 void OnMenuStart(IBaseMenu *menu);
1.6 void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display);
1.7 - void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item);
1.8 + void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page);
1.9 void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
1.10 void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason);
1.11 void OnMenuDestroy(IBaseMenu *menu);
1.12 @@ -273,6 +273,7 @@
1.13 static IMenuPanel *s_pCurPanel = NULL;
1.14 static unsigned int s_CurPanelReturn = 0;
1.15 static const ItemDrawInfo *s_CurDrawInfo = NULL;
1.16 +static unsigned int *s_CurSelectPosition = NULL;
1.17
1.18 /**
1.19 * MENU HANDLER WRAPPER
1.20 @@ -311,9 +312,17 @@
1.21 }
1.22 }
1.23
1.24 -void CMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
1.25 +void CMenuHandler::OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page)
1.26 {
1.27 + /* Save old position first. */
1.28 + unsigned int first_item = item_on_page;
1.29 + unsigned int *old_pos = s_CurSelectPosition;
1.30 +
1.31 + s_CurSelectPosition = &first_item;
1.32 +
1.33 DoAction(menu, MenuAction_Select, client, item);
1.34 +
1.35 + s_CurSelectPosition = old_pos;
1.36 }
1.37
1.38 void CMenuHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
1.39 @@ -620,6 +629,20 @@
1.40 return menu->Display(params[2], params[3]) ? 1 : 0;
1.41 }
1.42
1.43 +static cell_t DisplayMenuAtItem(IPluginContext *pContext, const cell_t *params)
1.44 +{
1.45 + Handle_t hndl = (Handle_t)params[1];
1.46 + HandleError err;
1.47 + IBaseMenu *menu;
1.48 +
1.49 + if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
1.50 + {
1.51 + return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
1.52 + }
1.53 +
1.54 + return menu->DisplayAtItem(params[2], params[4], params[3]) ? 1 : 0;
1.55 +}
1.56 +
1.57 static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params)
1.58 {
1.59 if (g_Menus.IsVoteInProgress())
1.60 @@ -1358,6 +1381,16 @@
1.61 return g_Menus.GetRemainingVoteDelay();
1.62 }
1.63
1.64 +static cell_t GetMenuSelectionPosition(IPluginContext *pContext, const cell_t *params)
1.65 +{
1.66 + if (!s_CurSelectPosition)
1.67 + {
1.68 + return pContext->ThrowNativeError("Can only be called from inside a MenuAction_Select callback");
1.69 + }
1.70 +
1.71 + return *s_CurSelectPosition;
1.72 +}
1.73 +
1.74 REGISTER_NATIVES(menuNatives)
1.75 {
1.76 {"AddMenuItem", AddMenuItem},
1.77 @@ -1371,6 +1404,7 @@
1.78 {"CreatePanel", CreatePanel},
1.79 {"CreatePanelFromMenu", CreatePanelFromMenu},
1.80 {"DisplayMenu", DisplayMenu},
1.81 + {"DisplayMenuAtItem", DisplayMenuAtItem},
1.82 {"DrawPanelItem", DrawPanelItem},
1.83 {"DrawPanelText", DrawPanelText},
1.84 {"GetClientMenu", GetClientMenu},
1.85 @@ -1381,6 +1415,7 @@
1.86 {"GetMenuItemCount", GetMenuItemCount},
1.87 {"GetMenuOptionFlags", GetMenuOptionFlags},
1.88 {"GetMenuPagination", GetMenuPagination},
1.89 + {"GetMenuSelectionPosition",GetMenuSelectionPosition},
1.90 {"GetMenuStyle", GetMenuStyle},
1.91 {"GetMenuStyleHandle", GetMenuStyleHandle},
1.92 {"GetMenuTitle", GetMenuTitle},