MrGravity.LevelSelect.HandleDirectionKeys C# (CSharp) Method

HandleDirectionKeys() private method

Handle actions for each direction the player may press on their controller
private HandleDirectionKeys ( ) : void
return void
        private void HandleDirectionKeys()
        {
            var max = new Vector2(10, 11);

            var countOnPage = 11;
            if (_mCurrentPage + 1 == _mPageCount)
                countOnPage = (_mLevels.Count - 1) % 12;

            var row = countOnPage / 4;
            var col = countOnPage % 4;

            max.X = max.Y = row * 4 + Math.Min(2,col);
            if (col == 1) max.Y = ++max.X;
            if(col >= 2) max.Y++;

            if (_mControls.IsLeftPressed(false))
            {
                _mCurrentIndex = (_mCurrentIndex - 1);
                if (_mCurrentIndex + 12 * _mCurrentPage > _mLevels.Count && _mCurrentIndex < Previous) _mCurrentIndex = _mLevels.Count % 12;
            }
            else if (_mControls.IsRightPressed(false))
            {
                _mCurrentIndex = (_mCurrentIndex + 1) % 15;
                if (_mCurrentIndex + 12 * _mCurrentPage > _mLevels.Count && _mCurrentIndex < Previous) _mCurrentIndex = Previous;
            }
            else if (_mControls.IsUpPressed(false))
            {
                if (_mCurrentIndex > Back && _mCurrentIndex <= 4) _mCurrentIndex = Back;
                else if (_mCurrentIndex == Back) _mCurrentIndex = Next;
                else if (_mCurrentIndex == Next) _mCurrentIndex = (int)max.Y;
                else if (_mCurrentIndex == Previous) _mCurrentIndex = (int)max.X;
                else _mCurrentIndex = (_mCurrentIndex - 4);
            }
            else if (_mControls.IsDownPressed(false))
            {
                if (_mCurrentIndex < countOnPage + 2 && _mCurrentIndex > max.X) _mCurrentIndex = Next;
                else if (_mCurrentIndex < max.X + 1 && _mCurrentIndex > row * 4) _mCurrentIndex = Previous;
                else if (_mCurrentIndex == Back) _mCurrentIndex = 1;
                else if (_mCurrentIndex == Next || _mCurrentIndex == Previous) _mCurrentIndex = Back;
                else _mCurrentIndex = (_mCurrentIndex+ 4);

                if (_mCurrentIndex > row * 4 + col + 1 && _mCurrentIndex < Previous) _mCurrentIndex = row * 4 + col + 1;

            }

            if (_mControls.IsLeftShoulderPressed(false))
                if (--_mCurrentPage < 0) _mCurrentPage = 0;
            if (_mControls.IsRightShoulderPressed(false))
                if (++_mCurrentPage == _mPageCount) _mCurrentPage = _mPageCount - 1;

            if (_mCurrentIndex < 0) _mCurrentIndex += 15;
        }