Exemplo n.º 1
0
        public static async Task <Keys> WaitForKey(this IXleGameControl gameControl, bool showPrompt, params Keys[] keys)
        {
            Keys result = Keys.None;

            do
            {
                result = await gameControl.WaitForKey(showPrompt);
            } while (!keys.Contains(result));

            return(result);
        }
Exemplo n.º 2
0
        public override async Task Execute()
        {
            await TextArea.PrintLine();

            var player = GameState.Player;

            renderer.InventoryScreen = 0;

            using (gameControl.PushRenderer(renderer))
            {
                while (renderer.InventoryScreen < 2)
                {
                    await gameControl.WaitAsync(150);

                    await gameControl.WaitForKey();

                    renderer.InventoryScreen++;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Asks the user to choose a number.
        /// </summary>
        /// <param name="max">The maximum value the user is allowed to select.</param>
        /// <returns></returns>
        public async Task <int> ChooseNumber(int max)
        {
            int method = 0;
            int amount = 0;

            await TextArea.PrintLine();

            await TextArea.Print("Enter number by ", XleColor.White);

            await TextArea.Print("keyboard", XleColor.Yellow);

            await TextArea.Print(" or ", XleColor.White);

            await TextArea.Print("joystick", XleColor.Cyan);

            await TextArea.PrintLine();

            await TextArea.PrintLine();

            Keys key;

            do
            {
                key = await gameControl.WaitForKey(showPrompt : false);

                if (method == 0)
                {
                    switch (key)
                    {
                    case Keys.None:
                        break;

                    case Keys.Right:
                    case Keys.Up:
                    case Keys.Left:
                    case Keys.Down:

                        await TextArea.PrintLine("Use joystick - press button when done");

                        await TextArea.PrintLine();

                        await TextArea.PrintLine("  Horizontal - Slow change", XleColor.Cyan);

                        await TextArea.PrintLine("  Vertical   - Fast change", XleColor.Cyan);

                        await TextArea.PrintLine("                          - 0 -");

                        method = 2;

                        break;

                    default:
                        await TextArea.PrintLine("Keyboard entry-press return when done", XleColor.Yellow);

                        await TextArea.PrintLine();

                        await TextArea.PrintLine();

                        await TextArea.PrintLine("                          - 0 -");

                        method = 1;

                        break;
                    }
                }

                if (method == 1)
                {
                    if (key >= Keys.D0 && key <= Keys.D9)
                    {
                        amount = 10 * amount + key - Keys.D0;
                    }

                    if (key == Keys.Back)
                    {
                        amount /= 10;
                    }

                    amount = Math.Min(amount, max);
                    amount = Math.Max(amount, 0);

                    await TextArea.RewriteLine(4, "                          - " + amount.ToString() + " -");
                }
                else if (method == 2)
                {
                    switch (key)
                    {
                    case Keys.Right:
                        amount++;
                        break;

                    case Keys.Up:
                        amount += 20;
                        break;

                    case Keys.Left:
                        amount--;
                        break;

                    case Keys.Down:
                        amount -= 20;
                        break;
                    }

                    if (amount > max)
                    {
                        amount = max;
                    }

                    if (amount < 0)
                    {
                        amount = 0;
                    }

                    await TextArea.RewriteLine(4, "                          - " + amount.ToString() + " -");
                }
            } while (key != Keys.Enter);

            await TextArea.PrintLine();

            return(amount);
        }
Exemplo n.º 4
0
        public async Task <int> QuickMenuCore(MenuItemList items, int spaces, int value, Color clrInit, Color clrChanged)
        {
            Require.That <ArgumentOutOfRangeException>(value >= 0, "value should be positive");
            Require.That <ArgumentOutOfRangeException>(value < items.Count, "value should be less than items.Count");

            int    result = value;
            string topLine;
            string bulletLine;
            int    lineIndex = TextArea.CursorLocation.Y;

            Color[] colors = new Color[40];

            if (lineIndex >= 4)
            {
                lineIndex = 3;
            }

            for (int i = 0; i < 40; i++)
            {
                colors[i] = clrChanged;
            }

            int[] spacing = new int[items.Count];
            int   last    = 0;

            spacing[0] = 8;

            // Construct the temporary line
            string tempLine = "Choose: ";

            for (int i = 0; i < items.Count; i++)
            {
                bulletLine = items[i];

                tempLine += bulletLine + new string(' ', spaces);

                spacing[i] += last + bulletLine.Length - 1;
                last        = spacing[i] + spaces + 1;
            }

            await TextArea.PrintLine(tempLine, clrInit);

            await TextArea.PrintLine();

            topLine  = tempLine;
            tempLine = new string(' ', spacing[result]) + "`";

            await TextArea.RewriteLine(lineIndex + 1, tempLine, clrInit);

            Keys key;

            do
            {
                key = await gameControl.WaitForKey(showPrompt : false);

                if (key == Keys.Left)
                {
                    result--;
                    if (result < 0)
                    {
                        result = 0;
                    }
                }
                if (key == Keys.Right)
                {
                    result++;
                    if (result >= items.Count)
                    {
                        result = items.Count - 1;
                    }
                }
                else if (key >= Keys.D0)
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        bulletLine = items[i];

                        if (key - Keys.A ==
                            char.ToUpperInvariant(bulletLine[0]) - 'A')
                        {
                            result = i;
                            key    = Keys.Enter;
                        }
                    }
                }

                tempLine = new string(' ', spacing[result]) + "`";

                if (key != Keys.None)
                {
                    await TextArea.RewriteLine(lineIndex, topLine, clrChanged);

                    await TextArea.RewriteLine(lineIndex + 1, tempLine, clrChanged);
                }
            } while (key != Keys.Enter);

            await gameControl.WaitAsync(100);

            await TextArea.PrintLine();

            return(result);
        }
Exemplo n.º 5
0
        private async Task <int> RunSubMenu(SubMenu menu)
        {
            this.menu = menu;

            menuRenderer.Menu = menu;

            for (int i = 0; i < menu.theList.Count; i++)
            {
                if (menu.theList[i].Length + 6 > menu.width)
                {
                    menu.width = menu.theList[i].Length + 6;
                }
            }

            string displayTitle = "Choose " + menu.title;

            if (displayTitle.Length + 2 > menu.width)
            {
                menu.width = displayTitle.Length + 2;
            }

            try
            {
                gameControl.PushRenderer(menuRenderer);

                Keys key;

                do
                {
                    key = await gameControl.WaitForKey(showPrompt : false);

                    if (key == Keys.Up)
                    {
                        menu.value--;
                        if (menu.value < 0)
                        {
                            menu.value = 0;
                        }
                    }
                    if (key == Keys.Down)
                    {
                        menu.value++;
                        if (menu.value >= menu.theList.Count)
                        {
                            menu.value = menu.theList.Count - 1;
                        }
                    }
                    else if (key >= Keys.D0)
                    {
                        int v;

                        if (key >= Keys.A)
                        {
                            v  = (int)(key) - (int)(Keys.A);
                            v += 10;
                        }
                        else
                        {
                            v = key - Keys.D0;
                        }

                        if (v < menu.theList.Count)
                        {
                            menu.value = v;
                            key        = Keys.Enter;
                        }
                    }
                } while (key != Keys.Enter);

                await gameControl.WaitAsync(300);
            }
            finally
            {
                gameControl.PopRenderer(menuRenderer);
            }

            return(menu.value);
        }