コード例 #1
0
        private static OptionsScreenType?ShowEditableOptions(OptionsScreenType currentScreen, string title, IList <OptionEditInfo> options)
        {
            while (true)
            {
                Screen.HoldUpdates();
                DrawCommonSections(currentScreen);
                Screen.Write(RowOffset, ColOffset, title);
                Screen.Write(RowOffset + 1, ColOffset, SeparatorBar);
                Screen.WriteListOfChoices(RowOffset + 2, ColOffset, options.Select(o => o.Text).ToArray());
                for (int i = 0; i < options.Count; ++i)
                {
                    string value = options[i].GetValue.Invoke();
                    Screen.Write(RowOffset + 2 + i, ColOffset + Width - value.Length, value);
                }
                Screen.Write(RowOffset + 2 + options.Count, ColOffset, SeparatorBar);
                Screen.ResumeUpdates();
                Screen.SetCursorPosition(RowOffset, ColOffset + title.Length);
                ConsoleKeyInfo key   = Input.ReadKey();
                bool           shift = (key.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift;
                switch (key.Key)
                {
                case ConsoleKey.Tab:
                    int nextScreenIdx = shift? (int)currentScreen - 1 : (int)currentScreen + 1;
                    if (nextScreenIdx < 0)
                    {
                        nextScreenIdx = 3;
                    }
                    if (nextScreenIdx > 3)
                    {
                        nextScreenIdx = 0;
                    }
                    return((OptionsScreenType)nextScreenIdx);

                case ConsoleKey.Escape:
                    // todo, space too? case ConsoleKey.Spacebar:
                    return(null);

                //todo, help?
                default:
                    int letterIndex = key.KeyChar - 'a';
                    if (letterIndex >= 0 && letterIndex < options.Count)
                    {
                        options[letterIndex].EditValue.Invoke(RowOffset + 2 + letterIndex, ColOffset + Width);
                    }
                    break;
                }
            }
        }
コード例 #2
0
        private static void DrawCommonSections(OptionsScreenType currentScreen)
        {
            const int   row     = 0;
            const int   col     = ColOffset;
            const Color bgColor = Color.Black;

            Screen.Clear();
            Screen.Write(row, col, "Game Interface    Controls    Display    Other", Color.DarkGray, bgColor);
            Screen.Write(row, col + 50, "[   ] to switch", Color.Gray, bgColor);
            Screen.Write(row, col + 51, "Tab", Color.Cyan, bgColor);
            int    highlightOffset;
            string highlightLabel;

            switch (currentScreen)
            {
            case OptionsScreenType.Interface:
                highlightOffset = 0;
                highlightLabel  = "Game Interface";
                break;

            case OptionsScreenType.Controls:
                highlightOffset = 18;
                highlightLabel  = "Controls";
                break;

            case OptionsScreenType.Display:
                highlightOffset = 30;
                highlightLabel  = "Display";
                break;

            case OptionsScreenType.Other:
                highlightOffset = 41;
                highlightLabel  = "Other";
                break;

            default: throw new InvalidOperationException("Invalid screen");
            }
            Screen.Write(row, col + highlightOffset, highlightLabel, Color.Green, bgColor);
        }