From cfe977584dae1f5301adde38288073087f87990f Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 28 Jan 2018 15:14:16 -0600 Subject: [PATCH] Added function to guiMenuBar to find a menu by name. --- Engine/source/gui/editor/guiMenuBar.cpp | 23 ++++++++++++++++++++++- Engine/source/gui/editor/guiMenuBar.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Engine/source/gui/editor/guiMenuBar.cpp b/Engine/source/gui/editor/guiMenuBar.cpp index 0fe8c3c71..fc9623498 100644 --- a/Engine/source/gui/editor/guiMenuBar.cpp +++ b/Engine/source/gui/editor/guiMenuBar.cpp @@ -1472,6 +1472,17 @@ PopupMenu* GuiMenuBar::getMenu(U32 index) return mMenuList[index].popupMenu; } +PopupMenu* GuiMenuBar::findMenu(StringTableEntry barTitle) +{ + for (U32 i = 0; i < mMenuList.size(); i++) + { + if (mMenuList[i].text == barTitle) + return mMenuList[i].popupMenu; + } + + return nullptr; +} + //----------------------------------------------------------------------------- // Console Methods //----------------------------------------------------------------------------- @@ -1506,4 +1517,14 @@ DefineConsoleMethod(GuiMenuBar, getMenu, S32, (S32 index), (0), "(Index)") DefineConsoleMethod(GuiMenuBar, insert, void, (SimObject* pObject, S32 pos), (nullAsType(), -1), "(object, pos) insert object at position") { object->insert(pObject, pos); -} \ No newline at end of file +} + +DefineConsoleMethod(GuiMenuBar, findMenu, S32, (StringTableEntry barTitle), (""), "(barTitle)") +{ + PopupMenu* menu = object->findMenu(barTitle); + + if (menu) + return menu->getId(); + else + return 0; +} diff --git a/Engine/source/gui/editor/guiMenuBar.h b/Engine/source/gui/editor/guiMenuBar.h index d266378e3..054be37cc 100644 --- a/Engine/source/gui/editor/guiMenuBar.h +++ b/Engine/source/gui/editor/guiMenuBar.h @@ -116,6 +116,7 @@ public: U32 getMenuListCount() { return mMenuList.size(); } PopupMenu* getMenu(U32 index); + PopupMenu* findMenu(StringTableEntry barTitle); DECLARE_CONOBJECT(GuiMenuBar); DECLARE_CALLBACK( void, onMouseInMenu, ( bool hasLeftMenu ));