コード例 #1
0
ファイル: SettingsScreen.cs プロジェクト: TakenouchiTR/Sanmai
 public override void Setup()
 {
     spn_speed.SetIndexToItem(Settings.GetString("speed"), false);
     spn_mute.SetIndexToItem(Settings.GetString("is_muted"), false);
     spn_slowOpen.SetIndexToItem(Settings.GetString("do_slow_open"), false);
     chr_mute.ChangeCharacter(Settings.GetChar("mute_key"), false);
     chr_speedUp.ChangeCharacter(Settings.GetChar("speed_up_key"), false);
     chr_speedDown.ChangeCharacter(Settings.GetChar("speed_down_key"), false);
 }
コード例 #2
0
ファイル: SettingsScreen.cs プロジェクト: TakenouchiTR/Sanmai
        public override bool Play()
        {
            foreach (UIObject obj in elements)
            {
                obj.Draw();
            }

            for (int i = 0; i < LABELS.Length; i++)
            {
                Painter.Write(LABELS[i], Console.WindowWidth / 2 - 13, 3 + i * 2, ConsoleColor.White);
            }

            textBox.DrawBorder();
            textBox.WriteText("Settings", TextAlign.Center);
            textBox.WriteText("------------", TextAlign.Center);
            textBox.WriteText(DESCRIPTIONS[index], TextAlign.Center);
            textBox.WriteText();
            textBox.WriteText(INSTRUCTIONS[(int)prevUIType], TextAlign.Center);
            textBox.WriteText("Press esc to return to the title screen", TextAlign.Center);

            Console.SetCursorPosition(0, 0);

            while (true)
            {
                Console.SetCursorPosition(0, 0);
                ConsoleKeyInfo key = Input.GetKey(false);
                Spinner        spn;

                switch (key.Key)
                {
                //Selects the next item down
                case ConsoleKey.DownArrow:
                    elements[index].Toggle();
                    index = (index + 1) % elements.Length;
                    elements[index].Toggle();

                    UpdateTextBox();
                    break;

                //Selects the next item up
                case ConsoleKey.UpArrow:
                    elements[index].Toggle();
                    index = index == 0 ? elements.Length - 1 : index - 1;
                    elements[index].Toggle();

                    UpdateTextBox();
                    break;

                //If the player selects a Character Display, allow them to enter a new character
                case ConsoleKey.Enter:
                    if (!(elements[index] is CharacterDisplay))
                    {
                        break;
                    }

                    CharacterDisplay cd = (CharacterDisplay)elements[index];
                    cd.ToggleChanging();

                    char c = ' ';

                    //Loops until the player enters a valid character (alphanumeric + most punctuation)
                    while (!VALID_CHARS.IsMatch(c.ToString()))
                    {
                        c = Input.GetKey().KeyChar;
                    }

                    cd.ToggleChanging(false);
                    cd.ChangeCharacter(c);

                    Settings.SetValue(KEYS[index], c.ToString());
                    break;

                //Is a spinner is selected, goes to the spinner's previous item
                case ConsoleKey.LeftArrow:
                    if (!(elements[index] is Spinner))
                    {
                        break;
                    }

                    spn = (Spinner)elements[index];

                    spn.Prev();

                    Settings.SetValue(KEYS[index], spn.SelectedItem);
                    break;

                //If a spinner is selected, goes to the spinner's next item
                case ConsoleKey.RightArrow:
                    if (!(elements[index] is Spinner))
                    {
                        break;
                    }

                    spn = (Spinner)elements[index];

                    spn.Next();

                    Settings.SetValue(KEYS[index], spn.SelectedItem);
                    break;

                case ConsoleKey.Escape:
                    //This line fixes an issue with the title screen
                    //  It appears that using a non-character key causes issues with writing to the console
                    //  This line will be invisible, as the background and forground are both black.
                    Painter.Write("This fixes a problem", 0, 0);
                    return(false);
                }
            }
        }