示例#1
0
文件: Menu.cs 项目: K-Cully/SticKart
        /// <summary>
        /// Checks if the selection made is in the menu.
        /// </summary>
        /// <param name="name">The name of the object to try to select.</param>
        /// <returns>The name of the selected item or null if not found.</returns>
        public string CheckForSelection(string name)
        {
            if (name == null)
            {
                return(null);
            }
            else
            {
                int    selectableCount = 1;
                string itemFound       = null;
                foreach (MenuItem menuItem in this.menuItems)
                {
                    if (selectableCount > this.selectablesActive)
                    {
                        break;
                    }
                    else if (typeof(MenuSelectableItem).IsAssignableFrom(menuItem.Type))
                    {
                        selectableCount++;
                        try
                        {
                            int level = int.Parse((menuItem as MenuSelectableItem).Name);
                            if (name.ToUpperInvariant() == ConvertToWords.ConvertIntToWords(level).ToUpperInvariant())
                            {
                                itemFound = (menuItem as MenuSelectableItem).Name;
                                break;
                            }
                        }
                        catch
                        {
                            if (name.ToUpperInvariant() == (menuItem as MenuSelectableItem).Name.ToUpperInvariant())
                            {
                                itemFound = (menuItem as MenuSelectableItem).Name;
                                break;
                            }
                        }
                    }
                }

                return(itemFound);
            }
        }
示例#2
0
        /// <summary>
        /// Retrieves the list of words which can be used to select menu items.
        /// </summary>
        /// <returns>The list of words which can be used to select menu items</returns>
        public List <string> GetAllSelectableNames()
        {
            List <string> selectableNames = new List <string>();

            foreach (MenuType menuType in this.menus.Keys)
            {
                switch (menuType)
                {
                case MenuType.LevelSelect:
                    foreach (string name in this.menus[menuType].SelectableItemNames)
                    {
                        if (name == MenuConstants.BackButtonName)
                        {
                            selectableNames.Add(name);
                        }
                        else
                        {
                            selectableNames.Add(ConvertToWords.ConvertIntToWords(int.Parse(name)));
                        }
                    }

                    break;

                case MenuType.LeaderboardSelect:
                    // Names will be identical to level select.
                    break;

                default:
                    if (this.menus[menuType] != null)
                    {
                        selectableNames.AddRange(this.menus[menuType].SelectableItemNames);
                    }

                    break;
                }
            }

            return(selectableNames);
        }