fixed inheritance not being used in the base menu style when removing clients from the watch list
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "sm_globals.h"
17 #include "MenuManager.h"
18 #include "MenuStyle_Valve.h"
19 #include "MenuStyle_Radio.h"
20 #include "HandleSys.h"
21 #include "PluginSys.h"
23 #if defined CreateMenu
28 * And God said, "let there be menus," and behold, there were menus.
29 * God saw the menus and they were good. And the evening and the morning
35 MenuAction_Start = (1<<0), /**< A menu has been started (nothing passed) */
36 MenuAction_Display = (1<<1), /**< A menu is about to be displayed (param1=client, param2=MenuPanel Handle) */
37 MenuAction_Select = (1<<2), /**< An item was selected (param1=client, param2=item) */
38 MenuAction_Cancel = (1<<3), /**< The menu was cancelled (param1=client, param2=item) */
39 MenuAction_End = (1<<4), /**< A menu's display/selection cycle is complete (nothing passed). */
40 MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has ended (param1=chosen item) */
41 MenuAction_VoteStart = (1<<6), /**< (VOTE ONLY): A vote sequence has started */
44 class CPanelHandler : public IMenuHandler
46 friend class MenuNativeHelpers;
51 void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
52 void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item);
54 IPluginFunction *m_pFunc;
58 class CMenuHandler : public IMenuHandler
60 friend class MenuNativeHelpers;
62 CMenuHandler(IPluginFunction *pBasic, int flags);
64 void OnMenuStart(IBaseMenu *menu);
65 void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display);
66 void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item);
67 void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
68 void OnMenuEnd(IBaseMenu *menu);
69 void OnMenuDestroy(IBaseMenu *menu);
70 void OnMenuVoteStart(IBaseMenu *menu);
71 void OnMenuVoteEnd(IBaseMenu *menu, unsigned int item);
73 void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);
74 void OnMenuDisplayItem(IBaseMenu *menu, int client, unsigned int item, const char **display);
77 void DoAction(IBaseMenu *menu, MenuAction action, cell_t param1, cell_t param2);
79 IPluginFunction *m_pBasic;
84 * GLOBAL CLASS FOR HELPERS
87 class MenuNativeHelpers :
89 public IHandleTypeDispatch,
90 public IPluginsListener
93 virtual void OnSourceModAllInitialized()
95 m_PanelType = g_HandleSys.CreateType("IMenuPanel", this, 0, NULL, NULL, g_pCoreIdent, NULL);
96 g_PluginSys.AddPluginsListener(this);
99 virtual void OnSourceModShutdown()
101 g_HandleSys.RemoveType(m_PanelType, g_pCoreIdent);
103 while (!m_FreePanelHandlers.empty())
105 delete m_FreePanelHandlers.front();
106 m_FreePanelHandlers.pop();
109 while (!m_FreeMenuHandlers.empty())
111 delete m_FreeMenuHandlers.front();
112 m_FreeMenuHandlers.pop();
116 virtual void OnHandleDestroy(HandleType_t type, void *object)
118 IMenuPanel *panel = (IMenuPanel *)object;
123 * It is extremely important that unloaded plugins don't crash.
124 * Thus, if a plugin unloads, we run through every handler we have.
125 * This means we do almost no runtime work for keeping track of
126 * our panel handlers (we don't have to store a list of the running
127 * ones), but when push comes to shove, we have to scan them all
128 * in case any of them are active.
130 virtual void OnPluginUnloaded(IPlugin *plugin)
132 for (size_t i = 0; i < m_PanelHandlers.size(); i++)
134 if (m_PanelHandlers[i]->m_pPlugin == plugin)
136 m_PanelHandlers[i]->m_pPlugin = NULL;
137 m_PanelHandlers[i]->m_pFunc = NULL;
142 inline HandleType_t GetPanelType()
147 CPanelHandler *GetPanelHandler(IPluginFunction *pFunction)
149 CPanelHandler *handler;
150 if (m_FreePanelHandlers.empty())
152 handler = new CPanelHandler;
153 m_PanelHandlers.push_back(handler);
155 handler = m_FreePanelHandlers.front();
156 m_FreePanelHandlers.pop();
158 handler->m_pFunc = pFunction;
159 handler->m_pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
163 void FreePanelHandler(CPanelHandler *handler)
165 handler->m_pFunc = NULL;
166 handler->m_pPlugin = NULL;
167 m_FreePanelHandlers.push(handler);
170 CMenuHandler *GetMenuHandler(IPluginFunction *pFunction, int flags)
172 CMenuHandler *handler;
173 if (m_FreeMenuHandlers.empty())
175 handler = new CMenuHandler(pFunction, flags);
177 handler = m_FreeMenuHandlers.front();
178 m_FreeMenuHandlers.pop();
179 handler->m_pBasic = pFunction;
180 handler->m_Flags = flags;
185 void FreeMenuHandler(CMenuHandler *handler)
187 m_FreeMenuHandlers.push(handler);
191 HandleType_t m_PanelType;
192 CStack<CPanelHandler *> m_FreePanelHandlers;
193 CStack<CMenuHandler *> m_FreeMenuHandlers;
194 CVector<CPanelHandler *> m_PanelHandlers;
198 * BASIC PANEL HANDLER WRAPPER
201 void CPanelHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
205 m_pFunc->PushCell(BAD_HANDLE);
206 m_pFunc->PushCell(MenuAction_Cancel);
207 m_pFunc->PushCell(client);
208 m_pFunc->PushCell(reason);
209 m_pFunc->Execute(NULL);
211 g_MenuHelpers.FreePanelHandler(this);
214 void CPanelHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
218 m_pFunc->PushCell(BAD_HANDLE);
219 m_pFunc->PushCell(MenuAction_Select);
220 m_pFunc->PushCell(client);
221 m_pFunc->PushCell(item);
222 m_pFunc->Execute(NULL);
224 g_MenuHelpers.FreePanelHandler(this);
228 * MENU HANDLER WRAPPER
230 CMenuHandler::CMenuHandler(IPluginFunction *pBasic, int flags) :
231 m_pBasic(pBasic), m_Flags(flags)
233 /* :TODO: We can probably cache the handle ahead of time */
236 void CMenuHandler::OnMenuStart(IBaseMenu *menu)
238 if ((m_Flags & (int)MenuAction_Start) == (int)MenuAction_Start)
240 DoAction(menu, MenuAction_Start, 0, 0);
244 void CMenuHandler::OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *panel)
246 if ((m_Flags & (int)MenuAction_Display) == (int)MenuAction_Display)
249 sec.pIdentity = m_pBasic->GetParentContext()->GetIdentity();
250 sec.pOwner = g_pCoreIdent;
253 g_HandleSys.InitAccessDefaults(NULL, &access);
254 access.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY|HANDLE_RESTRICT_OWNER;
256 Handle_t hndl = g_HandleSys.CreateHandleEx(g_MenuHelpers.GetPanelType(), panel, &sec, &access, NULL);
258 DoAction(menu, MenuAction_Display, client, hndl);
260 g_HandleSys.FreeHandle(hndl, &sec);
264 void CMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
266 DoAction(menu, MenuAction_Select, client, item);
269 void CMenuHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
271 DoAction(menu, MenuAction_Cancel, client, (cell_t)reason);
274 void CMenuHandler::OnMenuEnd(IBaseMenu *menu)
276 DoAction(menu, MenuAction_End, 0, 0);
279 void CMenuHandler::OnMenuDestroy(IBaseMenu *menu)
281 g_MenuHelpers.FreeMenuHandler(this);
284 void CMenuHandler::OnMenuVoteStart(IBaseMenu *menu)
286 DoAction(menu, MenuAction_VoteStart, 0, 0);
289 void CMenuHandler::OnMenuVoteEnd(IBaseMenu *menu, unsigned int item)
291 DoAction(menu, MenuAction_VoteEnd, item, 0);
294 void CMenuHandler::DoAction(IBaseMenu *menu, MenuAction action, cell_t param1, cell_t param2)
296 m_pBasic->PushCell(menu->GetHandle());
297 m_pBasic->PushCell((cell_t)action);
298 m_pBasic->PushCell(param1);
299 m_pBasic->PushCell(param2);
300 m_pBasic->Execute(NULL);
304 * INLINE FUNCTIONS FOR NATIVES
307 inline Handle_t MakePanelHandle(IMenuPanel *panel, IPluginContext *pContext)
309 return g_HandleSys.CreateHandle(g_MenuHelpers.GetPanelType(), panel, pContext->GetIdentity(), g_pCoreIdent, NULL);
312 inline HandleError ReadPanelHandle(Handle_t hndl, IMenuPanel **panel)
315 sec.pIdentity = g_pCoreIdent;
317 return g_HandleSys.ReadHandle(hndl, g_MenuHelpers.GetPanelType(), &sec, (void **)panel);
320 inline IMenuStyle *GetStyleFromCell(cell_t cell)
324 MenuStyle_Default = 0, /**< The "default" menu style for the mod */
325 MenuStyle_Valve = 1, /**< The Valve provided menu style (Used on HL2DM) */
326 MenuStyle_Radio = 2, /**< The simpler menu style commonly used on CS:S */
329 if (cell == MenuStyle_Valve)
331 return &g_ValveMenuStyle;
332 } else if (cell == MenuStyle_Radio
333 && g_RadioMenuStyle.IsSupported())
335 return &g_RadioMenuStyle;
338 return g_Menus.GetDefaultStyle();
341 /***********************************
342 **** NATIVE DEFINITIONS ***********
343 ***********************************/
345 static cell_t CreateMenu(IPluginContext *pContext, const cell_t *params)
347 IMenuStyle *style = g_Menus.GetDefaultStyle();
348 IPluginFunction *pFunction;
350 if ((pFunction=pContext->GetFunctionById(params[1])) == NULL)
352 return pContext->ThrowNativeError("Function id %x is invalid", params[1]);
355 CMenuHandler *handler = g_MenuHelpers.GetMenuHandler(pFunction, params[2]);
356 IBaseMenu *menu = style->CreateMenu(handler, pContext->GetIdentity());
358 Handle_t hndl = menu->GetHandle();
368 static cell_t DisplayMenu(IPluginContext *pContext, const cell_t *params)
370 Handle_t hndl = (Handle_t)params[1];
374 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
376 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
379 return menu->Display(params[2], params[3]) ? 1 : 0;
382 static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params)
384 Handle_t hndl = (Handle_t)params[1];
388 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
390 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
394 pContext->LocalToPhysAddr(params[2], &addr);
396 return menu->BroadcastVote(addr, params[3], params[4]) ? 1 : 0;
399 static cell_t AddMenuItem(IPluginContext *pContext, const cell_t *params)
401 Handle_t hndl = (Handle_t)params[1];
405 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
407 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
413 pContext->LocalToString(params[2], &info);
414 pContext->LocalToString(params[3], (char **)&dr.display);
415 dr.style = params[4];
417 return menu->AppendItem(info, dr) ? 1 : 0;
420 static cell_t InsertMenuItem(IPluginContext *pContext, const cell_t *params)
422 Handle_t hndl = (Handle_t)params[1];
426 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
428 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
434 pContext->LocalToString(params[3], &info);
435 pContext->LocalToString(params[4], (char **)&dr.display);
436 dr.style = params[5];
438 return menu->InsertItem(params[2], info, dr) ? 1 : 0;
441 static cell_t RemoveMenuItem(IPluginContext *pContext, const cell_t *params)
443 Handle_t hndl = (Handle_t)params[1];
447 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
449 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
452 return menu->RemoveItem(params[2]) ? 1 : 0;
455 static cell_t RemoveAllMenuItems(IPluginContext *pContext, const cell_t *params)
457 Handle_t hndl = (Handle_t)params[1];
461 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
463 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
466 menu->RemoveAllItems();
471 static cell_t GetMenuItem(IPluginContext *pContext, const cell_t *params)
473 Handle_t hndl = (Handle_t)params[1];
477 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
479 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
485 if ((info=menu->GetItemInfo(params[2], &dr)) == NULL)
490 pContext->StringToLocalUTF8(params[3], params[4], info, NULL);
491 pContext->StringToLocalUTF8(params[6], params[7], dr.display ? dr.display : "", NULL);
494 pContext->LocalToPhysAddr(params[5], &addr);
500 static cell_t SetMenuPagination(IPluginContext *pContext, const cell_t *params)
502 Handle_t hndl = (Handle_t)params[1];
506 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
508 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
511 return menu->SetPagination(params[2]) ? 1 : 0;
514 static cell_t GetMenuPagination(IPluginContext *pContext, const cell_t *params)
516 Handle_t hndl = (Handle_t)params[1];
520 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
522 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
525 return menu->GetPagination();
528 static cell_t GetMenuItemCount(IPluginContext *pContext, const cell_t *params)
530 Handle_t hndl = (Handle_t)params[1];
534 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
536 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
539 return menu->GetItemCount();
542 static cell_t SetMenuTitle(IPluginContext *pContext, const cell_t *params)
544 Handle_t hndl = (Handle_t)params[1];
548 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
550 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
554 g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
556 menu->SetDefaultTitle(buffer);
561 static cell_t CreatePanelFromMenu(IPluginContext *pContext, const cell_t *params)
563 Handle_t hndl = (Handle_t)params[1];
567 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
569 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
572 IMenuPanel *panel = menu->CreatePanel();
573 hndl = MakePanelHandle(panel, pContext);
582 static cell_t GetMenuExitButton(IPluginContext *pContext, const cell_t *params)
584 Handle_t hndl = (Handle_t)params[1];
588 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
590 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
593 return menu->GetExitButton() ? 1 : 0;
596 static cell_t SetMenuExitButton(IPluginContext *pContext, const cell_t *params)
598 Handle_t hndl = (Handle_t)params[1];
602 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
604 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
607 return menu->SetExitButton(params[2] ? true : false) ? 1 : 0;
610 static cell_t CancelMenu(IPluginContext *pContext, const cell_t *params)
612 Handle_t hndl = (Handle_t)params[1];
616 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
618 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
626 static cell_t GetMenuStyle(IPluginContext *pContext, const cell_t *params)
628 Handle_t hndl = (Handle_t)params[1];
632 if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
634 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
637 return menu->GetDrawStyle()->GetHandle();
640 static cell_t GetMenuStyleHandle(IPluginContext *pContext, const cell_t *params)
642 IMenuStyle *style = GetStyleFromCell(params[1]);
648 return style->GetHandle();
651 static cell_t CreatePanel(IPluginContext *pContext, const cell_t *params)
653 Handle_t hndl = (Handle_t)params[1];
659 if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None)
661 return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
664 style = g_Menus.GetDefaultStyle();
667 IMenuPanel *panel = style->CreatePanel();
669 hndl = MakePanelHandle(panel, pContext);
679 static cell_t CreateMenuEx(IPluginContext *pContext, const cell_t *params)
681 Handle_t hndl = (Handle_t)params[1];
687 if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None)
689 return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
692 style = g_Menus.GetDefaultStyle();
695 IPluginFunction *pFunction;
696 if ((pFunction=pContext->GetFunctionById(params[2])) == NULL)
698 return pContext->ThrowNativeError("Function id %x is invalid", params[2]);
701 CMenuHandler *handler = g_MenuHelpers.GetMenuHandler(pFunction, params[3]);
703 IBaseMenu *pMenu = style->CreateMenu(handler, pContext->GetIdentity());
704 hndl = pMenu->GetHandle();
714 static cell_t GetClientMenu(IPluginContext *pContext, const cell_t *params)
716 Handle_t hndl = (Handle_t)params[2];
722 if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None)
724 return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
727 style = g_Menus.GetDefaultStyle();
730 return style->GetClientMenu(params[1], NULL);
733 static cell_t CancelClientMenu(IPluginContext *pContext, const cell_t *params)
735 Handle_t hndl = (Handle_t)params[3];
741 if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None)
743 return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
746 style = g_Menus.GetDefaultStyle();
749 return style->CancelClientMenu(params[1], params[2] ? true : false) ? 1 : 0;
752 static cell_t GetMaxPageItems(IPluginContext *pContext, const cell_t *params)
754 Handle_t hndl = (Handle_t)params[1];
760 if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None)
762 return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
765 style = g_Menus.GetDefaultStyle();
768 return style->GetMaxPageItems();
771 static cell_t GetPanelStyle(IPluginContext *pContext, const cell_t *params)
773 Handle_t hndl = (Handle_t)params[1];
777 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
779 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
782 return panel->GetParentStyle()->GetHandle();
785 static cell_t SetPanelTitle(IPluginContext *pContext, const cell_t *params)
787 Handle_t hndl = (Handle_t)params[1];
791 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
793 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
797 pContext->LocalToString(params[2], &text);
799 panel->DrawTitle(text, params[3] ? true : false);
804 static cell_t DrawPanelItem(IPluginContext *pContext, const cell_t *params)
806 Handle_t hndl = (Handle_t)params[1];
810 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
812 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
816 pContext->LocalToString(params[2], (char **)&dr.display);
817 dr.style = params[3];
819 return panel->DrawItem(dr);
822 static cell_t DrawPanelText(IPluginContext *pContext, const cell_t *params)
824 Handle_t hndl = (Handle_t)params[1];
828 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
830 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
834 pContext->LocalToString(params[2], &text);
836 return panel->DrawRawLine(text) ? 1 : 0;
839 static cell_t CanPanelDrawFlags(IPluginContext *pContext, const cell_t *params)
841 Handle_t hndl = (Handle_t)params[1];
845 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
847 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
850 return panel->CanDrawItem(params[2]);
853 static cell_t SendPanelToClient(IPluginContext *pContext, const cell_t *params)
855 Handle_t hndl = (Handle_t)params[1];
859 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
861 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
864 IPluginFunction *pFunction;
865 if ((pFunction=pContext->GetFunctionById(params[3])) == NULL)
867 return pContext->ThrowNativeError("Function id %x is invalid", params[3]);
870 CPanelHandler *handler = g_MenuHelpers.GetPanelHandler(pFunction);
871 if (!panel->SendDisplay(params[2], handler, params[4]))
873 g_MenuHelpers.FreePanelHandler(handler);
879 static cell_t SetPanelKeys(IPluginContext *pContext, const cell_t *params)
881 Handle_t hndl = (Handle_t)params[1];
885 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
887 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
890 return panel->SetSelectableKeys(params[2]);
893 static cell_t GetPanelCurrentKey(IPluginContext *pContext, const cell_t *params)
895 Handle_t hndl = (Handle_t)params[1];
899 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
901 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
904 return panel->GetCurrentKey();
907 static cell_t SetPanelCurrentKey(IPluginContext *pContext, const cell_t *params)
909 Handle_t hndl = (Handle_t)params[1];
913 if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None)
915 return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
918 return panel->SetCurrentKey(params[2]) ? 1 : 0;
921 REGISTER_NATIVES(menuNatives)
923 {"AddMenuItem", AddMenuItem},
924 {"CanPanelDrawFlags", CanPanelDrawFlags},
925 {"CancelClientMenu", CancelClientMenu},
926 {"CancelMenu", CancelMenu},
927 {"CreateMenu", CreateMenu},
928 {"CreateMenuEx", CreateMenuEx},
929 {"CreatePanel", CreatePanel},
930 {"CreatePanelFromMenu", CreatePanelFromMenu},
931 {"DisplayMenu", DisplayMenu},
932 {"DrawPanelItem", DrawPanelItem},
933 {"DrawPanelText", DrawPanelText},
934 {"GetClientMenu", GetClientMenu},
935 {"GetMaxPageItems", GetMaxPageItems},
936 {"GetMenuExitButton", GetMenuExitButton},
937 {"GetMenuItem", GetMenuItem},
938 {"GetMenuItemCount", GetMenuItemCount},
939 {"GetMenuPagination", GetMenuPagination},
940 {"GetMenuStyle", GetMenuStyle},
941 {"GetMenuStyleHandle", GetMenuStyleHandle},
942 {"GetPanelCurrentKey", GetPanelCurrentKey},
943 {"GetPanelStyle", GetPanelStyle},
944 {"InsertMenuItem", InsertMenuItem},
945 {"RemoveAllMenuItems", RemoveAllMenuItems},
946 {"RemoveMenuItem", RemoveMenuItem},
947 {"SendPanelToClient", SendPanelToClient},
948 {"SetMenuExitButton", SetMenuExitButton},
949 {"SetMenuPagination", SetMenuPagination},
950 {"SetMenuTitle", SetMenuTitle},
951 {"SetPanelCurrentKey", SetPanelCurrentKey},
952 {"SetPanelTitle", SetPanelTitle},
953 {"SetPanelKeys", SetPanelKeys},
954 {"VoteMenu", VoteMenu},