Пример #1
0
        /// <summary>
        /// Removes all popups from this menu.
        /// </summary>
        /// <param name="afterHidden"></param>
        public void RemoveAllPopups(UnityAction afterHidden)
        {
            // Create a copy to not edit the list while looping through it.
            List <MCMenu> popupMenuCopy = new List <MCMenu>(PopupMenus);

            for (int i = 0; i < popupMenuCopy.Count; i++)
            {
                int currentIndex = i;

                // Hide each popupMenu.
                popupMenuCopy[i].Hide(() =>
                {
                    // Called when this popup menu is closed.
                    PopupMenus.Remove(popupMenuCopy[currentIndex]);

                    if (PopupMenus.Count <= 0)
                    {
                        if (afterHidden != null)
                        {
                            afterHidden();
                        }
                    }
                });
            }
        }
Пример #2
0
        /// <summary>
        /// Add a popup to this menu and assign this menu as the parent for the popup.
        /// </summary>
        /// <param name="mcMenu">The new popup object.</param>
        /// <param name="data">Data that is passed to the popup that is created.</param>
        public MCMenu AddPopup(MCMenu mcMenu, object data = null)
        {
            PopupMenus.Add(mcMenu);
            mcMenu.Parent = this;
            mcMenu.Show(data);

            _menuController.OnMenuAdded(mcMenu);
            return(mcMenu);
        }
Пример #3
0
 public bool NodeWasAddedToPopupMenu(int nodeid)
 {
     try
     {
         return(PopupMenus.Select(x => x.Node.Id == nodeid).Count() > 0 ? true : false);
     }
     catch
     {
         return(false);
     }
 }
Пример #4
0
        /// <summary>
        /// Called when this menu should be hidden.
        /// </summary>
        /// <param name="afterHidden">A function that should be called when this menu is hidden.</param>
        public void Hide(UnityAction afterHidden)
        {
            if (_callBackHide != null)
            {
                afterHidden += _callBackHide;
            }

            // Remove all null values for popupMenus that are destroyed.
            PopupMenus.RemoveAll(menu => !menu);

            if (PopupMenus.Count <= 0)
            {
                // There are no popups to take care of, increase performance and skip those.
                OnHide(afterHidden);
            }
            else
            {
                RemoveAllPopups(() =>
                {
                    // There are no popupMenus left, we can actually hide the parent menu.
                    OnHide(afterHidden);
                });
            }
        }
Пример #5
0
 public PopupMenu GetPopupMenu(int id)
 {
     return(PopupMenus.Single <PopupMenu>(x => x.Id == id));
 }
Пример #6
0
 /// <summary>
 /// Remove a specific popup menu.
 /// </summary>
 /// <param name="mcMenu"></param>
 public void RemovePopup(MCMenu mcMenu)
 {
     PopupMenus.Remove(mcMenu);
     mcMenu.Parent = null;
     mcMenu.Hide();
 }