Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.Popups.PopupMenu"/> class with specified menu items.
        /// </summary>
        /// <param name="items">Items.</param>
        public PopupMenu(TreeNode<CustomMenuItem> items)
        {
            mItems          = items;
            mGameObject     = null;
            mOnDestroy      = new UnityEvent();

            mChildPopupMenu = null;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.Popups.PopupMenu"/> class with specified menu items.
        /// </summary>
        /// <param name="items">Items.</param>
        public PopupMenu(TreeNode<CustomMenuItem> items)
        {
            DebugEx.VerboseFormat("Created PopupMenu(items = {0}) object", items);

            mItems     = items;
            mOnDestroy = new UnityEvent();

            mGameObject     = null;
            mChildPopupMenu = null;
        }
 /// <summary>
 /// Deregisters specified popup menu.
 /// </summary>
 /// <param name="menu">Popup menu.</param>
 public static void DeregisterPopupMenu(PopupMenu menu)
 {
     if (instance != null)
     {
         if (instance.mPopupMenus.Remove(menu))
         {
             if (instance.mPopupMenus.Count == 0)
             {
                 instance.enabled = false;
                 instance.mAutoPopupItem = null;
                 instance.StopTimer();
             }
         }
         else
         {
             Debug.LogError("Failed to deregister popup menu");
         }
     }
     else
     {
         Debug.LogError("There is no PopupMenuAreaScript instance");
     }
 }
Example #4
0
        /// <summary>
        /// Script starting callback.
        /// </summary>
        void Start()
        {
            mUi        = new MainMenuUI(this);
            mShortcuts = new List<MenuItem>();
            mPopupMenu = null;

            mUi.SetupUI();
        }
Example #5
0
        /// <summary>
        /// Creates and displays popup menu for specified menu item.
        /// </summary>
        /// <param name="node"><see cref="Common.TreeNode`1"/> instance.</param>
        public void OnShowMenuSubItems(TreeNode<CustomMenuItem> node)
        {
            if (node.data is MenuItem)
            {
                MenuItem item = node.data as MenuItem;
                Debug.Log("MainMenuScript.OnShowMenuSubItems(" + item.name + ")");

                if (mPopupMenu != null)
                {
                    mPopupMenu.Destroy();
                }

                mPopupMenu = new PopupMenu(node);
                mPopupMenu.OnDestroy.AddListener(OnPopupMenuDestroyed);

                int index = node.parent.children.IndexOf(node);

                RectTransform menuItemTransform = transform.GetChild(0).GetChild(0).GetChild(index).transform as RectTransform; // ScrollArea/Content/NODE
                Vector3[] menuItemCorners = Utils.GetWindowCorners(menuItemTransform);

                mPopupMenu.Show(menuItemCorners[2].x, menuItemCorners[2].y);
            }
            else
            {
                Debug.LogError("Unknown menu item type");
            }
        }
Example #6
0
        /// <summary>
        /// Handler for popup menu destroy event.
        /// </summary>
        public void OnPopupMenuDestroyed()
        {
            Debug.Log("MainMenuScript.OnPopupMenuDestroyed");

            mPopupMenu = null;
        }
Example #7
0
        /// <summary>
        /// Handler for popup menu destroy event.
        /// </summary>
        public void OnPopupMenuDestroyed()
        {
            Debug.Log("PopupMenu.OnPopupMenuDestroyed");

            mChildPopupMenu = null;
        }
Example #8
0
        /// <summary>
        /// Destroy this instance.
        /// </summary>
        public void Destroy()
        {
            if (mChildPopupMenu != null)
            {
                mChildPopupMenu.Destroy();
                mChildPopupMenu = null;
            }

            if (mGameObject != null)
            {
                UnityEngine.Object.Destroy(mGameObject);
                mGameObject = null;
            }

            PopupMenuAreaScript.DeregisterPopupMenu(this);

            mOnDestroy.Invoke();
        }
Example #9
0
        /// <summary>
        /// Handler for popup menu destroy event.
        /// </summary>
        public void OnPopupMenuDestroyed()
        {
            DebugEx.Verbose("PopupMenu.OnPopupMenuDestroyed()");

            mChildPopupMenu = null;
        }
        /// <summary>
        /// Creates and displays popup menu for specified menu item.
        /// </summary>
        /// <param name="node"><see cref="Common.TreeNode`1"/> instance.</param>
        public void OnShowMenuSubItems(TreeNode<CustomMenuItem> node)
        {
            DebugEx.VerboseFormat("PopupMenu.OnShowMenuSubItems(node = {0})", node);

            if (node.data is MenuItem)
            {
                MenuItem item = node.data as MenuItem;
                DebugEx.UserInteractionFormat("PopupMenu.OnShowMenuSubItems({0})", item.name);

                if (mChildPopupMenu != null)
                {
                    mChildPopupMenu.Destroy();
                }

                mChildPopupMenu = new PopupMenu(node);
                mChildPopupMenu.mOnDestroy.AddListener(OnPopupMenuDestroyed);

                int index = node.parent.children.IndexOf(node);

                RectTransform menuItemTransform = mGameObject.transform.GetChild(0).GetChild(0).GetChild(index).transform as RectTransform; // ScrollArea/Content/NODE
                Vector3[] menuItemCorners = Utils.GetWindowCorners(menuItemTransform);

                mChildPopupMenu.Show(
                                     menuItemCorners[1].x,
                                     menuItemCorners[1].y,
                                     menuItemCorners[2].x,
                                     menuItemCorners[2].y
                                    );
            }
            else
            {
                DebugEx.Error("Unknown menu item type");
            }
        }
        /// <summary>
        /// Handler for popup menu destroy event.
        /// </summary>
        public void OnPopupMenuDestroyed()
        {
            DebugEx.Verbose("PopupMenu.OnPopupMenuDestroyed()");

            mChildPopupMenu = null;
        }
 /// <summary>
 /// Registers specified popup menu.
 /// </summary>
 /// <param name="menu">Popup menu.</param>
 public static void RegisterPopupMenu(PopupMenu menu)
 {
     if (instance != null)
     {
         instance.mPopupMenus.Add(menu);
         instance.enabled = true;
     }
     else
     {
         Debug.LogError("There is no PopupMenuAreaScript instance");
     }
 }