コード例 #1
0
ファイル: NpcScript.cs プロジェクト: Tagette/WvsNpcSimulator
        /// <summary>
        /// Displays a dialog with text and Selections.
        /// </summary>
        /// <param name="selections">The selections for the menu. The first argument is 0.</param>
        public async Task <byte> SendMenu(params string[] selections)
        {
            ConsoleTools.PrintWithNpcColor(_textBuffer);
            ClearTextBuffer();

            if (selections == null || selections.Length == 0)
            {
                return(0);
            }

            byte selection = 0;
            await Task.Factory.StartNew(() =>
            {
                bool exit = false;
                while (!exit)
                {
                    for (int i = 0; i < selections.Length; i++)
                    {
                        ConsoleTools.PrintWithNpcColor((i + 1) + ") " + selections[i]);
                    }
                    Console.Write("Choose> ");
                    string input = Console.ReadLine();
                    if (byte.TryParse(input, out selection))
                    {
                        if (selection > 0 && selection <= selections.Length)
                        {
                            exit = true;
                        }
                        else
                        {
                            Console.WriteLine("Incorrect choice.");
                        }
                    }
                    else if (input.ToLower() == "exit")
                    {
                        Stop();
                    }
                    else
                    {
                        Console.WriteLine("Incorrect value.");
                    }
                }
            });

            Console.WriteLine();
            return(--selection);
        }