IEnumerator ChangeKeyConfig(int _num)
    {
        Debug.Log("ChangeKeyConfig:" + _num.ToString());
        while (true)
        {
            yield return(null);

            if (Input.anyKeyDown)
            {
                foreach (KeyCode code in System.Enum.GetValues(typeof(KeyCode)))
                {
                    if (Input.GetKeyDown(code))
                    {
                        KeyConfig.KeyCodes[_num] = code;
                    }
                }
                KeyConfig.Save();
                KeyConfigButtonText[_num].text = System.Enum.GetName(typeof(KeyConfig.Key), _num).ToString() + ":" + KeyConfig.KeyCodes[_num];
                break;
            }
        }
    }
        public override void HandleInput(GamePadState gamePadState, KeyboardState keyboardState, MouseState mouseState)
        {
            if (!isSelectingKey)
            {
                if (InputHandler.WasKeyPressed(keyboardState, KeyConfig.KeyList[1], 10))
                {
                    if (!inKeyMenu)
                    {
                        optionsMenu.SelectionDown();
                    }
                    else
                    {
                        if (!isSelectingKey)
                        {
                            keyconfigMenu.SelectionDown();
                        }
                    }
                }
                if (InputHandler.WasKeyPressed(keyboardState, KeyConfig.KeyList[2], 10))
                {
                    if (!inKeyMenu)
                    {
                        switch (optionsMenu.GetSelection())
                        {
                        case 0: ScreenHandler.GameOptions.TextSpeed = ScreenHandler.GameOptions.TextSpeed > 0 ? (byte)(ScreenHandler.GameOptions.TextSpeed - 1) : (byte)2; break;

                        case 1: ScreenHandler.GameOptions.BattleScene = ScreenHandler.GameOptions.BattleScene ? false : true; break;

                        case 2: ScreenHandler.GameOptions.BattleStyle = ScreenHandler.GameOptions.BattleStyle ? false : true; break;

                        case 3: ScreenHandler.GameOptions.Sound = ScreenHandler.GameOptions.Sound ? false : true; break;
                        }
                    }
                    UpdateBaseOption(optionsMenu.GetSelection());
                }
                if (InputHandler.WasKeyPressed(keyboardState, KeyConfig.KeyList[3], 10))
                {
                    if (!inKeyMenu)
                    {
                        switch (optionsMenu.GetSelection())
                        {
                        case 0: ScreenHandler.GameOptions.TextSpeed = ScreenHandler.GameOptions.TextSpeed < 2 ? (byte)(ScreenHandler.GameOptions.TextSpeed + 1): (byte)0; break;

                        case 1: ScreenHandler.GameOptions.BattleScene = ScreenHandler.GameOptions.BattleScene ? false : true; break;

                        case 2: ScreenHandler.GameOptions.BattleStyle = ScreenHandler.GameOptions.BattleStyle ? false : true; break;

                        case 3: ScreenHandler.GameOptions.Sound = ScreenHandler.GameOptions.Sound ? false : true; break;
                        }
                        UpdateBaseOption(optionsMenu.GetSelection());
                    }
                }
                if (InputHandler.WasKeyPressed(keyboardState, KeyConfig.KeyList[0], 10))
                {
                    if (!inKeyMenu)
                    {
                        optionsMenu.SelectionUp();
                    }
                    else
                    {
                        if (!isSelectingKey)
                        {
                            keyconfigMenu.SelectionUp();
                        }
                    }
                }
                if (InputHandler.WasKeyPressed(keyboardState, KeyConfig.KeyList[5], 10))
                {
                    if (!inKeyMenu)
                    {
                        Close();
                    }
                    else
                    {
                        if (!isSelectingKey)
                        {
                            inKeyMenu = false;
                        }
                    }
                }
                if (InputHandler.WasKeyPressed(keyboardState, KeyConfig.KeyList[4], 10))
                {
                    if (!inKeyMenu)
                    {
                        switch (optionsMenu.GetSelection())
                        {
                        case 4: inKeyMenu = true; break;

                        case 6: ScreenHandler.GameOptions.Save(); break;

                        case 7: Close(); break;
                        }
                    }
                    else
                    {
                        if (!isSelectingKey)
                        {
                            int i = keyconfigMenu.GetSelection();
                            if (i < keyconfigMenu.GetOptionList().Count - 3)
                            {
                                isSelectingKey = true;
                            }
                            else if (i == keyconfigMenu.GetOptionList().Count - 3)
                            {
                                KeyConfig.Save();
                            }
                            else
                            {
                                inKeyMenu = false;
                            }
                        }
                    }
                }
            }
            else
            {
                int i = keyconfigMenu.GetSelection();

                Keys[] selectedKeys = InputHandler.GetSelectedKeys(keyboardState, 10);
                if (selectedKeys.Length > 0 && !selectedKeys[0].Equals(Keys.None) && !checkIfKeyExists(selectedKeys[0]))
                {
                    KeyConfig.KeyList[i] = selectedKeys[0];
                    UpdateKeyOption(i);
                    isSelectingKey = false;
                }
            }
        }