Exemplo n.º 1
0
        public int ComboBox(List <string> items, CursorPoint cursor, string blankString)
        {
            int choice = 0, inputKey;

            while (true)
            {
                // 현재 선택 중인 문자열을 출력
                Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop);
                Console.Write(blankString);
                Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop);
                Console.Write(items[choice]);

                inputKey = inputProcessor.PressDirectionKey();
                switch (inputKey)
                {
                case ConstNumber.LEFT:
                case ConstNumber.UP:
                    choice--;
                    break;

                case ConstNumber.RIGHT:
                case ConstNumber.DOWN:
                    choice++;
                    break;

                case ConstNumber.ESC:
                    return(ConstNumber.ESC);

                // Enter가 입력되면 선택 인덱스를 출력
                default:
                    return(choice);
                }

                // 선택 범위 제한
                if (choice < 0)
                {
                    choice = 0;
                }
                if (choice >= items.Count)
                {
                    choice = items.Count - 1;
                }
            }
        }
Exemplo n.º 2
0
        // 문자열을 읽어오면서 동시에 문자열이 조건을 충족하는지 확인하여 반환한다.
        // letterLimit : 최대 글자 수, screenHeight : 출력화면 높이
        // cursorLeft : 입력받기 시작하는 위치(x좌표), cursorTop : 입력받기 시작하는 위치(y좌표)
        // format : 포맷에 따라 문자 입력에 제한을 둠
        public string ReadAndCheckString(int letterLimit, int screenHeight, CursorPoint cursor, int format)
        {
            string         input = "";
            ConsoleKeyInfo inputKey;

            // 이전 출력된 글자 지우기
            for (int iter = 0; iter < letterLimit; iter++)
            {
                Console.Write(" ");
            }
            Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop);

            while (true)
            {
                // 문자열을 입력받으며 각각의 문자에 대해 검사함
                while (true)
                {
                    inputKey = Console.ReadKey(true);
                    if (inputKey.Key == ConsoleKey.Escape)
                    {
                        return(null);
                    }
                    else if (inputKey.Key == ConsoleKey.Enter)
                    {
                        break;
                    }
                    else if (inputKey.Key == ConsoleKey.Backspace)
                    {
                        int bytes;
                        if (input.Length != 0)
                        {
                            bytes = Encoding.Default.GetBytes(input.Last() + "").Length;

                            Console.SetCursorPosition(Console.CursorLeft - bytes, Console.CursorTop);
                            if (bytes == 2)
                            {
                                Console.Write("  ");
                            }
                            else
                            {
                                Console.Write(" ");
                            }
                            Console.SetCursorPosition(Console.CursorLeft - bytes, Console.CursorTop);
                            if (input.Length > 0)
                            {
                                input = input.Remove(input.Length - 1);
                            }
                            if (cursor.CursorLeft > Console.CursorLeft)
                            {
                                Console.SetCursorPosition(cursor.CursorLeft, Console.CursorTop);
                            }
                        }
                    }
                    else
                    {
                        // 글자 수가 제한 수를 넘지 않았다면
                        if (input.Length < letterLimit)
                        {
                            // 포맷 제한에 따라 문자를 입력받는다
                            if (format == ConstNumber.GENERAL_LIMIT)
                            {
                                if (inputKey.KeyChar >= 33 && inputKey.KeyChar <= 126 || IsPerfectHangleChar(inputKey.KeyChar))
                                {
                                    Console.Write(inputKey.KeyChar);
                                    input += inputKey.KeyChar;
                                }
                            }
                            else if (format == ConstNumber.NUMBER_LIMIT)
                            {
                                if (inputKey.KeyChar >= '0' && inputKey.KeyChar <= '9')
                                {
                                    Console.Write(inputKey.KeyChar);
                                    input += inputKey.KeyChar;
                                }
                            }
                        }
                    }
                }

                // 입력되지 않은 경우 다시 입력
                if (input.Length == 0)
                {
                    // 입력되면서 화면에 표시되었던 문자열을 지우고 커서를 다시 위치시킨다.
                    Console.SetCursorPosition(5, screenHeight - 2);
                    Console.WriteLine("잘못된 입력 : 입력되지 않음");
                    Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop);
                    Console.Write("                 ");
                    Console.SetCursorPosition(cursor.CursorLeft, cursor.CursorTop);
                    continue;
                }

                // 입력된 문자열을 반환한다.
                return(input);
            }
        }
Exemplo n.º 3
0
        public string[] LectureListHeaderScreen()
        {
            int choice = 0, screenHeight;

            string[] conditions = new string[] { "전체", "전체", "전체", "전체", "전체" };

            // 커서 좌표 배열
            CursorPoint[] titlePosition = new CursorPoint[] {
                new CursorPoint(17, 1), new CursorPoint(46, 1), new CursorPoint(95, 1), new CursorPoint(117, 1),
                new CursorPoint(131, 1), new CursorPoint(169, 1)
            };
            // 전공 목록 생성
            List <string> majorItems = new List <string>(new string[] { "전체", "컴퓨터공학과", "정보보호학과", "디지털콘텐츠학과", "소프트웨어학과" });
            // 학년 목록 생성
            List <string> gradeItems = new List <string>(new string[] { "전체", "1", "2", "3", "4" });

            screenHeight = ConsoleUI.PrintLectureListHeader();

            while (true)
            {
                while (true)
                {
                    // 엔터가 눌렸는지에 대한 상태변수
                    bool isPressedEnter = false;
                    // 선택된 위치로 커서 이동
                    Console.SetCursorPosition(titlePosition[choice].CursorLeft, titlePosition[choice].CursorTop);

                    switch (inputProcessor.PressDirectionKey())
                    {
                    case ConstNumber.ESC:
                        return(null);

                    case ConstNumber.UP:
                    case ConstNumber.LEFT:
                        choice--;
                        break;

                    case ConstNumber.DOWN:
                    case ConstNumber.RIGHT:
                        choice++;
                        break;

                    case ConstNumber.ENTER:
                        isPressedEnter = true;
                        break;
                    }

                    if (isPressedEnter)
                    {
                        break;
                    }

                    // 선택 범위 제한
                    if (choice < 0)
                    {
                        choice = 0;
                    }
                    if (choice >= 6)
                    {
                        choice = 5;
                    }
                }

                // 현재 커서 위치
                CursorPoint presentCursor = new CursorPoint(Console.CursorLeft, Console.CursorTop);
                int         itemIndex;
                switch (choice)
                {
                case ConstNumber.MENULIST_1:
                    itemIndex = ComboBox(majorItems, presentCursor, "                ");
                    if (itemIndex == -1)
                    {
                        return(null);
                    }
                    conditions[0] = majorItems[itemIndex];
                    break;

                case ConstNumber.MENULIST_2:
                    conditions[1] = inputProcessor.ReadAndCheckString(30, screenHeight, presentCursor, ConstNumber.GENERAL_LIMIT);
                    if (conditions[1] == null)
                    {
                        return(null);
                    }
                    break;

                case ConstNumber.MENULIST_3:
                    conditions[2] = inputProcessor.ReadAndCheckString(6, screenHeight, presentCursor, ConstNumber.NUMBER_LIMIT);
                    if (conditions[2] == null)
                    {
                        return(null);
                    }
                    break;

                case ConstNumber.MENULIST_4:
                    itemIndex = ComboBox(gradeItems, presentCursor, "   ");
                    if (itemIndex == -1)
                    {
                        return(null);
                    }
                    conditions[3] = gradeItems[itemIndex];
                    break;

                case ConstNumber.MENULIST_5:
                    conditions[4] = inputProcessor.ReadAndCheckString(30, screenHeight, presentCursor, ConstNumber.GENERAL_LIMIT);
                    if (conditions[4] == null)
                    {
                        return(null);
                    }
                    break;

                case ConstNumber.MENULIST_6:
                    return(conditions);
                }
            }
        }