Exemplo n.º 1
0
        private void SubMenus()
        {
            if (activeMenu >= 0)
            {
                ActionOnRecursiveMenuItems(new List <MenuItem>()
                {
                    menus[activeMenu]
                }, menu =>
                {
                    if (menu.enabled && menu.menuItems.Count > 0)
                    {
                        Rect rect      = new Rect();
                        Vector2 origin = new Vector2(menu.parent == null ? menu.alignment : menu.parent.rect.x + menu.parent.rect.width + MENU_SPACING, menu.parent == null ? (MENU_BUTTON_HEIGHT + MENU_SPACING + MENU_BUTTON_SPACING) : (menu.parent.rect.y + menu.startHeight));
                        rect           = GUIExtensions.Dropdown(menu.index, origin, menu.menuItems.Select(x => x.name).ToArray(), menu.menuItems.Select(x => x.menuItems.Count > 0).ToArray(), index =>
                        {
                            if (menu.menuItems[index].menuType == MenuType.Action)
                            {
                                menu.menuItems[index].action?.Invoke();

                                // Close any sub menus
                                ActionOnRecursiveMenuItems(menus, x =>
                                {
                                    // Don't disable the current menu - toggle it below
                                    if (x != menu.menuItems[index] && x.menuItems.Count > 0)
                                    {
                                        x.enabled = false;
                                    }
                                });
                            }
                            else if (menu.menuItems[index].menuType == MenuType.Window)
                            {
                                menu.menuItems[index].enabled = !menu.menuItems[index].enabled;

                                // Close any sub menus
                                ActionOnRecursiveMenuItems(menus, x =>
                                {
                                    // Don't disable the current menu - toggle it below
                                    if (x != menu.menuItems[index] && x.menuItems.Count > 0)
                                    {
                                        x.enabled = false;
                                    }
                                });
                            }
                            else
                            {
                                menu.menuItems[index].enabled     = !menu.menuItems[index].enabled;
                                menu.menuItems[index].startHeight = (MENU_BUTTON_HEIGHT + MENU_BUTTON_SPACING) * index;
                            }

                            // Disable any other opened sub menus
                            ActionOnRecursiveMenuItems(menu.menuItems, x =>
                            {
                                // Don't disable the current menu - toggle it below
                                // Don't disable windows or actions
                                if (x != menu.menuItems[index] && x.menuItems.Count > 0)
                                {
                                    x.enabled = false;
                                }
                            });

                            menu.rect = rect;
                        });
                    }
                });
            }
        }