From 5333aa07cc16069ffac105716aea2027a90221be Mon Sep 17 00:00:00 2001 From: Ilusion9 <40362576+Ilusion9@users.noreply.github.com> Date: Sat, 4 Mar 2023 19:59:04 +0200 Subject: [PATCH 1/5] Update smn_topmenus.cpp --- extensions/topmenus/smn_topmenus.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/extensions/topmenus/smn_topmenus.cpp b/extensions/topmenus/smn_topmenus.cpp index 3dc0e38034..2fbb00bc21 100644 --- a/extensions/topmenus/smn_topmenus.cpp +++ b/extensions/topmenus/smn_topmenus.cpp @@ -300,6 +300,24 @@ static cell_t FindTopMenuCategory(IPluginContext *pContext, const cell_t *params return pMenu->FindCategory(name); } +static cell_t FindTopMenuItem(IPluginContext *pContext, const cell_t *params) +{ + HandleError err; + ITopMenu *pMenu; + HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); + + if ((err = handlesys->ReadHandle(params[1], hTopMenuType, &sec, (void **)&pMenu)) + != HandleError_None) + { + return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); + } + + char *name; + pContext->LocalToString(params[2], &name); + + return pMenu->FindItem(name); +} + static cell_t DisplayTopMenu(IPluginContext *pContext, const cell_t *params) { HandleError err; @@ -486,6 +504,7 @@ sp_nativeinfo_t g_TopMenuNatives[] = {"TopMenu.LoadConfig", LoadTopMenuConfig}, {"TopMenu.Remove", RemoveFromTopMenu}, {"TopMenu.FindCategory", FindTopMenuCategory}, + {"TopMenu.FindItem", FindTopMenuItem}, {"TopMenu.GetInfoString", GetTopMenuInfoString}, {"TopMenu.GetObjName", GetTopMenuName}, {"TopMenu.CacheTitles.set", SetTopMenuTitleCaching}, From 1121cb6ef041d49c521c5ec4da72fea395d395e7 Mon Sep 17 00:00:00 2001 From: Ilusion9 <40362576+Ilusion9@users.noreply.github.com> Date: Sat, 4 Mar 2023 20:00:15 +0200 Subject: [PATCH 2/5] Add function to find a TopMenu Item From a3411df89ba6aba6e5220a28d9601d8218a3fb29 Mon Sep 17 00:00:00 2001 From: Ilusion9 <40362576+Ilusion9@users.noreply.github.com> Date: Sat, 4 Mar 2023 20:02:56 +0200 Subject: [PATCH 3/5] Add function to find a TopMenu Item --- extensions/topmenus/TopMenu.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extensions/topmenus/TopMenu.cpp b/extensions/topmenus/TopMenu.cpp index 28a173913e..4ed0bcfe2f 100644 --- a/extensions/topmenus/TopMenu.cpp +++ b/extensions/topmenus/TopMenu.cpp @@ -1239,6 +1239,18 @@ unsigned int TopMenu::FindCategory(const char *name) return obj->object_id; } +unsigned int TopMenu::FindItem(const char *name) +{ + topmenu_object_t *obj; + if (!m_ObjLookup.retrieve(name, &obj)) + return 0; + + if (obj->type != TopMenuObject_Item) + return 0; + + return obj->object_id; +} + void TopMenu::OnMaxPlayersChanged( int newvalue ) { m_max_clients = newvalue; From b70243f469c7e1eae4241961c55a0fb060fb3996 Mon Sep 17 00:00:00 2001 From: Ilusion9 <40362576+Ilusion9@users.noreply.github.com> Date: Sat, 4 Mar 2023 20:21:36 +0200 Subject: [PATCH 4/5] Add function to find a TopMenu Item --- plugins/include/topmenus.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/include/topmenus.inc b/plugins/include/topmenus.inc index abdddc3347..e6b986fbc2 100644 --- a/plugins/include/topmenus.inc +++ b/plugins/include/topmenus.inc @@ -244,7 +244,14 @@ methodmap TopMenu < Handle // @return TopMenuObject ID on success, or // INVALID_TOPMENUOBJECT on failure. public native TopMenuObject FindCategory(const char[] name); - + + // Finds an item's topobj ID in a TopMenu. + // + // @param name Object's unique name. + // @return TopMenuObject ID on success, or + // INVALID_TOPMENUOBJECT on failure. + public native TopMenuObject FindItem(const char[] name); + // Set the menu title caching behavior of the TopMenu. By default titles // are cached to reduce overhead. If you need dynamic menu titles which // change each time the menu is displayed to a user, set this to false. @@ -441,6 +448,7 @@ public void __ext_topmenus_SetNTVOptional() MarkNativeAsOptional("TopMenu.Display"); MarkNativeAsOptional("TopMenu.DisplayCategory"); MarkNativeAsOptional("TopMenu.FindCategory"); + MarkNativeAsOptional("TopMenu.FindItem"); MarkNativeAsOptional("TopMenu.CacheTitles.set"); } #endif From 3a68eeba42d24054880586f6606614c2e5d53b4f Mon Sep 17 00:00:00 2001 From: Ilusion9 <40362576+Ilusion9@users.noreply.github.com> Date: Thu, 30 Mar 2023 16:57:23 +0300 Subject: [PATCH 5/5] Add function to find a TopMenu Item --- extensions/topmenus/TopMenu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/topmenus/TopMenu.h b/extensions/topmenus/TopMenu.h index 298c7f58a4..038e61d4fe 100644 --- a/extensions/topmenus/TopMenu.h +++ b/extensions/topmenus/TopMenu.h @@ -142,6 +142,7 @@ class TopMenu : TopMenuPosition position); virtual bool LoadConfiguration(const char *file, char *error, size_t maxlength); virtual unsigned int FindCategory(const char *name); + virtual unsigned int FindItem(const char *name); const char *GetObjectInfoString(unsigned int object_id); const char *GetObjectName(unsigned int object_id); public: //IMenuHandler