Beispiel #1
0
        /// <summary>
        /// Displays a menu of options for selection with a prompt message
        /// </summary>
        /// <param name="menu">Max 9 menu options allowed</param>
        public void PrintMenuSelections(object sender, IMenu menu)
        {
            var optionWidth = selectionWidth - 2;

            if (previousMenuOptions == null || previousMenuOptions != menu || forceRefresh)
            {
                PrintMenuPrompt(menu.Prompt, optionWidth);
                if (!forceRefresh)
                {
                    previousSelection = currentSelection = 0;
                }
            }

            for (int i = 0; i < menu.Options.Count; i++)
            {
                Console.SetCursorPosition(origin.X + 1, origin.Y - 9 + i);

                if (previousMenuOptions == null || previousMenuOptions != menu || forceRefresh)
                {
                    if (menu.Options[i].IsSelected)
                    {
                        previousSelection = i;
                        PrintSelectedOption(menu.Options[i].Title, optionWidth);
                    }
                    else
                    {
                        PrintUnselectedOption(menu.Options[i].Title, optionWidth);
                    }
                }
                else
                {
                    if (previousSelection == i && menu.Options.Count > 1)
                    {
                        PrintUnselectedOption(menu.Options[i].Title, optionWidth);
                    }

                    if (menu.Options[i].IsSelected)
                    {
                        PrintSelectedOption(menu.Options[i].Title, optionWidth);
                        currentSelection = i;
                    }
                }
            }

            if (previousMenuOptions != null &&
                previousMenuOptions != menu &&
                previousMenuOptions.Options.Count > menu.Options.Count)
            {
                Console.BackgroundColor = Write.ColorDisplayBG;

                for (int i = menu.Options.Count; i < previousMenuOptions.Options.Count; i++)
                {
                    Console.SetCursorPosition(origin.X + 1, origin.Y - 9 + i);
                    Write.EmptySpace(optionWidth);
                }
            }

            forceRefresh        = false;
            previousSelection   = currentSelection;
            previousMenuOptions = menu;
        }