Example #1
0
        public Block(Position pos, Size size, ConsoleColor foreColor = ConsoleColor.Gray, ConsoleColor backColor = ConsoleColor.Black)
        {
            this.Position = pos;
            this.Size = size;

            this.BlockBackgroundColor = backColor;
            this.BlockForegorundColor = foreColor;

            this.Buffer = new string[this.Size.Height];
            this.IsSelectedBuffer = new bool[this.Size.Height];
            this.IsSelectableBuffer = new bool[this.Size.Height];

            this.IsVisible = true;

            Init();
        }
Example #2
0
        public FancyMenu(String title)
        {
            this.Title = title;
            Console.CursorVisible = false;

            Block titleBar = new Block(new Position(0, 0), new Size(1, Console.WindowWidth), ConsoleColor.Black, ConsoleColor.Gray);
            titleBar.WriteTextAt(new Position(1, 0), "Fancy menu");

            this.lManager.AddLayer(titleBar);

            Block menuBlock;
            Size menuSize = new Size(5, 35);
            Position menuPos = new Position((Console.WindowWidth - menuSize.Width) / 2, (Console.WindowHeight - menuSize.Height) / 2);

            menuBlock = new Block(menuPos, menuSize);

            menuBlock.WriteTextAt(new Position(0, 0), "What would you like to do?");
            menuBlock.WriteTextAt(new Position(0, 1), "$<Black,Gray,Gray,Black>Test");
            menuBlock.WriteTextAt(new Position(0, 2), "$<Black,Gray,Gray,Black>this");
            menuBlock.WriteTextAt(new Position(0, 3), "$<Black,Gray,Gray,Black>fancy");
            menuBlock.WriteTextAt(new Position(0, 4), "$<Black,Gray,Gray,Black>thing");

            menuBlock.IsSelectableBuffer[1] = true;
            menuBlock.IsSelectableBuffer[2] = true;
            menuBlock.IsSelectableBuffer[3] = true;
            menuBlock.IsSelectableBuffer[4] = true;

            menuBlock.SetSelectedLine(1);

            this.lManager.AddLayer(menuBlock);
            this.lManager.SetSelectedLayer(menuBlock);

            this.lManager.Draw();

            int selectedItem = -1;
            while(selectedItem == -1)
            {
                ConsoleKey pressedKey = Console.ReadKey().Key;
                if (pressedKey == ConsoleKey.DownArrow)
                {
                    int newSelectedIndex = menuBlock.GetSelectedLine() + 1;

                    if (menuBlock.IsSelectableBuffer.Length - 1 >= newSelectedIndex && menuBlock.IsSelectableBuffer[newSelectedIndex] == true)
                        menuBlock.SetSelectedLine(menuBlock.GetSelectedLine() + 1);

                }
                else if (pressedKey == ConsoleKey.UpArrow)
                {
                    int newSelectedIndex = menuBlock.GetSelectedLine() - 1;

                    if (menuBlock.IsSelectableBuffer.Length - 1 >= newSelectedIndex && menuBlock.IsSelectableBuffer[newSelectedIndex] == true)
                        menuBlock.SetSelectedLine(menuBlock.GetSelectedLine() - 1);

                }
                else if (pressedKey == ConsoleKey.Enter)
                {
                    selectedItem = menuBlock.GetSelectedLine();
                }
            }

            Block selectedText = new Block(new Position(0, Console.WindowHeight / 2), new Size(1, Console.WindowWidth));
            selectedText.WriteCenteredText(String.Format("You selected $<red>{0}", menuBlock.GetTextAt(selectedItem)));

            menuBlock.IsVisible = false;

            this.lManager.AddLayer(selectedText);
            this.lManager.Draw();
        }