using GiraffeRoller.Utility;
using Otter;
using System.Collections;

namespace GiraffeRoller.ui.PauseMenu
{
    public class PauseMenuBubble : Entity
    {
        private Spritemap<string> _spriteMap;
        private int _y = -8;//was2 //offset?
        private int _x = 16;//offset?
        private int _row = 1;
        private bool _isAudioOptionsActive;
        private bool _isControlOptionsActive;
        private Key _key;
        private int _anyJoyButton;
        private MouseButton _mouseButton;
        private bool _keyPressed;
        private string _controlType;
        private Session _cp;//current player
        private Session _fake;//fake player
        private string _b;//the prefix
        private string _c;//the fake prefix
        private int _joystickNumber;
        private bool _isChangingStart;
        private bool _changeStartToFalse;
        private int _changeStartTimer;
        private bool _changeEscapeToFalse;
        private int _changeEscapeTimer;

        public static bool IsChangingEscape;

        //private List<ControllerXbox360> _xBoxControllerList = new List<ControllerXbox360>();

        public PauseMenuBubble(float x, float y)
        {
            X = x;
            Y = y;
            SetHitbox(16, 16, (int)Global.Type.MENUBUBBLE);
            _spriteMap = new Spritemap<string>(Assets.MENUBUBBLE, 16, 16);
            _spriteMap.Add("move", new int[] { 0 }, new float[] { 1f, 1f });
            Graphic = _spriteMap;
            _spriteMap.Play("move");
            Layer = -11;
            Group = 100;
        }

        public override void Update()
        {
            base.Update();
            var cn = Global.PausePersonSession.Controller;
            if (!IsChangingEscape && cn.Button("PPEscape").Pressed)//if you need an ("is Destroy") add it here.
                Destroy();
            if (cn.Button("PPUp").Pressed)//UP
            {
                //System.Console.WriteLine("y: {0}", Y);
                if (_isAudioOptionsActive)
                {
                    if (Y - 20 < Scene.CameraY + 190 - _y)
                        Y = Scene.CameraY + 230 - _y;
                    else
                        Y -= 20;
                }
                else if (_isControlOptionsActive)
                {
                    if (Y == Scene.CameraY + 370 - _y)
                    {
                        if (_row == 1)
                        {
                            Y = Scene.CameraY + 350 - _y;
                            X = Scene.CameraX + 25 - _x;
                        }
                        else if (_row == 2)
                        {
                            Y = Scene.CameraY + 350 - _y;
                            X = Scene.CameraX + 200 - _x;
                        }
                        else if (_row == 3)
                        {
                            Y = Scene.CameraY + 350 - _y;
                            X = Scene.CameraX + 375 - _x;
                        }
                        else
                        {
                            Y = Scene.CameraY + 350 - _y;
                            X = Scene.CameraX + 550 - _x;
                        }
                    }
                    else if (Y == Scene.CameraY + 350 - _y)
                    {
                        if (_row == 1)
                        {
                            Y = Scene.CameraY + 310 - _y;
                            X = Scene.CameraX + 25 - _x;
                        }
                        else if (_row == 2)
                        {
                            Y = Scene.CameraY + 270 - _y;
                            X = Scene.CameraX + 200 - _x;
                        }
                        else if (_row == 3)
                        {
                            Y = Scene.CameraY + 270 - _y;
                            X = Scene.CameraX + 375 - _x;
                        }
                        else
                        {
                            Y = Scene.CameraY + 270 - _y;
                            X = Scene.CameraX + 550 - _x;
                        }
                    }
                    else
                    {
                        if (Y - 20 < Scene.CameraY + 170 - _y)
                        {
                            if (X == Scene.CameraX + 25 - _x)
                                _row = 1;
                            else if (X == Scene.CameraX + 200 - _x)
                                _row = 2;
                            else if (X == Scene.CameraX + 375 - _x)
                                _row = 3;
                            else
                                _row = 4;
                            Y = Scene.CameraY + 370 - _y;
                            X = Scene.CameraX + 325 - _x;
                        }
                        else
                            Y -= 20;
                    }
                }
                else
                {
                    if (Y - 20 < Scene.CameraY + 190 - _y)
                        Y = Scene.CameraY + 250 - _y;
                    else
                        Y -= 20;
                }
            }
            else if (cn.Button("PPDown").Pressed)//DOWN
            {
                if (_isAudioOptionsActive)
                {
                    if (Y + 20 > Scene.CameraY + 230 - _y)
                        Y = Scene.CameraY + 190 - _y;
                    else
                        Y += 20;
                }
                else if (_isControlOptionsActive)
                {
                    if (Y == Scene.CameraY + 370 - _y)
                    {
                        if (_row == 1)
                            X = Scene.CameraX + 25 - _x;
                        else if (_row == 2)
                            X = Scene.CameraX + 200 - _x;
                        else if (_row == 3)
                            X = Scene.CameraX + 375 - _x;
                        else
                            X = Scene.CameraX + 550 - _x;
                        Y = Scene.CameraY + 170 - _y;
                    }
                    else if (X != Scene.CameraX + 25 - _x)//any row but the first
                    {
                        if (Y >= Scene.CameraY + 270 - _y && Y < Scene.CameraY + 350 - _y)
                        {
                            if (X == Scene.CameraX + 200 - _x)
                                _row = 2;
                            else if (X == Scene.CameraX + 375 - _x)
                                _row = 3;
                            else
                                _row = 4;
                            Y = Scene.CameraY + 350 - _y;
                        }
                        else if (Y + 20 > Scene.CameraY + 350 - _y)
                        {
                            if (X == Scene.CameraX + 200 - _x)
                                _row = 2;
                            else if (X == Scene.CameraX + 375 - _x)
                                _row = 3;
                            else
                                _row = 4;
                            Y = Scene.CameraY + 370 - _y;
                            X = Scene.CameraX + 325 - _x;
                        }
                        else
                            Y += 20;
                    }
                    else//this is the first row
                    {
                        if (Y + 20 >= Scene.CameraY + 330 - _y && Y + 20 < Scene.CameraY + 350 - _y)//there is nothing at 330. so go to 350.
                        {
                            Y = Scene.CameraY + 350 - _y;
                            _row = 1;
                        }
                        else if (Y + 20 > Scene.CameraY + 350 - _y)
                        {
                            Y = Scene.CameraY + 370 - _y;
                            X = Scene.CameraY + 325 - _x;
                            _row = 1;
                        }
                        else
                            Y += 20;
                    }
                }
                else
                {
                    if (Y + 20 > Scene.CameraY + 250 - _y)
                        Y = Scene.CameraY + 190 - _y;
                    else
                        Y += 20;
                }
            }
            if (cn.Button("PPRight").Pressed && _isControlOptionsActive)
            {
                /*if (Y == 290 - _y || Y == 310 - _y)
                {
                    Y = 270 - _y;
                    if (X + 175 > 550 - _x)
                        X = 25 - _x;
                    else
                        X += 175;
                }
                else if (Y == 370 - _y)
                {
                    Y = 350 - _y;
                    X = 550 - _x;
                    _row = 4;
                }
                else
                {
                    if (X + 175 > 550 - _x)
                        X = 25 - _x;
                    else
                        X += 175;
                }
                if (X == 25 - _x)
                    _row = 1;
                else if (X == 200 - _x)
                    _row = 2;
                else if (X == 375 - _x)
                    _row = 3;
                else if (X == 550 - _x)
                    _row = 4;*/
            }
            else if (cn.Button("PPLeft").Pressed && _isControlOptionsActive)
            {
                /*if (Y == 290 - _y)
                {
                    Y = 270 - _y;
                    if (X - 175 < 25 - _x)
                        X = 550 - _x;
                    else
                        X -= 175;
                }
                else if (Y == 370 - _y)
                {
                    Y = 350 - _y;
                    X = 25 - _x;
                    _row = 1;
                }
                else
                {
                    if (X - 175 < 25 - _x)
                        X = 550 - _x;
                    else
                        X -= 175;
                }
                if (X == 25 - _x)
                    _row = 1;
                else if (X == 200 - _x)
                    _row = 2;
                else if (X == 375 - _x)
                    _row = 3;
                else if (X == 550 - _x)
                    _row = 4;*/
            }
            if (!_isAudioOptionsActive && !_isControlOptionsActive)//this is the main menu
            {
                if (Y == Scene.CameraY + 190 - _y && cn.Button("PPStart").Pressed)
                {
                    PauseMenuAudioOptions.IsDestroy = false;
                    PauseMenuBackground.IsDestroy = true;
                    Scene.Add(new PauseMenuAudioOptions(Scene.CameraX + 100, Scene.CameraY + 100));
                    if (Sound.GlobalVolume == 0)
                        Scene.Add(new PauseMenuAudioX(Scene.CameraX + 451, Scene.CameraY + 190));
                    if (Music.GlobalVolume == 0)
                        Scene.Add(new PauseMenuMusicX(Scene.CameraX + 451, Scene.CameraY + 210));
                    _isAudioOptionsActive = true;
                    _isControlOptionsActive = false;
                }
                else if (Y == Scene.CameraY + 210 - _y && cn.Button("PPStart").Pressed)
                {
                    PauseMenuControlOptions.IsDestroy = false;
                    PauseMenuBackground.IsDestroy = true;
                    Scene.Add(new PauseMenuControlOptions(Scene.CameraX + 10, Scene.CameraY + 10));
                    X = Scene.CameraX + 25 - _x;
                    Y = Scene.CameraY + 170 - _y;
                    _isAudioOptionsActive = false;
                    _isControlOptionsActive = true;
                }
                else if (Y == Scene.CameraY + 230 - _y && cn.Button("PPStart").Pressed)
                    cn.Button("PPEscape").ForceState(true);
                else if (Y == Scene.CameraY + 250 - _y && cn.Button("PPStart").Pressed)
                    Global.GAME.Close();//well, that was easy. lol
            }
            else if (_isAudioOptionsActive)//audio menu
            {
                if (Y == Scene.CameraY + 190 - _y && cn.Button("PPStart").Pressed)
                {
                    if (Sound.GlobalVolume == 1)
                    {
                        Scene.Add(new PauseMenuAudioX(Scene.CameraX + 457, Scene.CameraY + 200));
                        Sound.GlobalVolume = 0;
                    }
                    else
                    {
                        var pauseX = GetEntities<PauseMenuAudioX>();
                        foreach (var x in pauseX)
                        {
                            x.Destroy();
                        }
                        Sound.GlobalVolume = 1;
                    }
                }
                else if (Y == Scene.CameraY + 210 - _y && cn.Button("PPStart").Pressed)
                {
                    if (Music.GlobalVolume == 1)
                    {
                        Scene.Add(new PauseMenuMusicX(Scene.CameraX + 457, Scene.CameraY + 220));
                        Music.GlobalVolume = 0;
                    }
                    else
                    {
                        var pauseX = GetEntities<PauseMenuMusicX>();
                        foreach (var x in pauseX)
                        {
                            x.Destroy();
                        }
                        Music.GlobalVolume = 1;
                    }
                }
                else if (Y == Scene.CameraY + 230 - _y && cn.Button("PPStart").Pressed)
                {
                    PauseMenuBackground.IsDestroy = false;
                    PauseMenuAudioOptions.IsDestroy = true;
                    var pauseAudioX = GetEntities<PauseMenuAudioX>();
                    foreach (var x in pauseAudioX)
                    {
                        x.Destroy();
                    }
                    var pauseX = GetEntities<PauseMenuMusicX>();
                    foreach (var x in pauseX)
                    {
                        x.Destroy();
                    }
                    Scene.Add(new PauseMenuBackground(Scene.CameraX + 100, Scene.CameraY + 100));
                    _isAudioOptionsActive = false;
                    _isControlOptionsActive = false;
                }
            }
            else if (_isControlOptionsActive)//controls menu
            {
                //Otter.Axis
                //Axis.JoyButtons();
                //_axisButton = AxisButton.Any;
                //joystick.GetAxis(_axisButton);
                /*foreach(var item in Input.LastButton)
                {
                    Console.WriteLine("item in lastbutton: {0}", item);
                    //Console.WriteLine("Input.LastButton.checking: {0}", Input.LastButton.IndexOf(0));
                }*/

                if (X == Scene.CameraX + 25 - _x && cn.Button("PPStart").Pressed)//player1
                {
                    if (Y == Scene.CameraY + 170 - _y)//Up
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Up"));//this key needs to be EXACTLY the same as the save key.
                    else if (Y == Scene.CameraY + 190 - _y)//Down
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Down"));
                    else if (Y == Scene.CameraY + 210 - _y)//Left
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Left"));
                    else if (Y == Scene.CameraY + 230 - _y)//Right
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Right"));
                    else if (Y == Scene.CameraY + 250 - _y)//Jump
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Jump"));
                    else if (Y == Scene.CameraY + 270 - _y)//Fire
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Fire"));
                    else if (!_isChangingStart && Y == Scene.CameraY + 290 - _y)//Start
                    {
                        _isChangingStart = true;
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Start"));
                    }
                    else if (Y == Scene.CameraY + 310 - _y)//Escape
                    {
                        IsChangingEscape = true;
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(1, "Escape"));
                    }
                    else if (Y == Scene.CameraY + 350 - _y)//Set to Defaults
                        SetDefaults(1);
                }
                else if (X == Scene.CameraX + 200 - _x && cn.Button("PPStart").Pressed)//player2
                {
                    if (Y == Scene.CameraY + 170 - _y)//Up
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(2, "Up"));//this key needs to be EXACTLY the same as the save key.
                    else if (Y == Scene.CameraY + 190 - _y)//Down
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(2, "Down"));
                    else if (Y == Scene.CameraY + 210 - _y)//Left
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(2, "Left"));
                    else if (Y == Scene.CameraY + 230 - _y)//Right
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(2, "Right"));
                    else if (Y == Scene.CameraY + 250 - _y)//Jump
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(2, "Jump"));
                    else if (Y == Scene.CameraY + 270 - _y)//Fire
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(2, "Fire"));
                    else if (Y == Scene.CameraY + 350 - _y)//Set to Defaults
                        SetDefaults(2);
                }
                else if (X == Scene.CameraX + 375 - _x && cn.Button("PPStart").Pressed)//player3
                {
                    if (Y == Scene.CameraY + 170 - _y)//Up
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(3, "Up"));//this key needs to be EXACTLY the same as the save key.
                    else if (Y == Scene.CameraY + 190 - _y)//Down
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(3, "Down"));
                    else if (Y == Scene.CameraY + 210 - _y)//Left
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(3, "Left"));
                    else if (Y == Scene.CameraY + 230 - _y)//Right
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(3, "Right"));
                    else if (Y == Scene.CameraY + 250 - _y)//Jump
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(3, "Jump"));
                    else if (Y == Scene.CameraY + 270 - _y)//Fire
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(3, "Fire"));
                    else if (Y == Scene.CameraY + 350 - _y)//Set to Defaults
                        SetDefaults(3);
                }
                else if (X == Scene.CameraX + 550 - _x && cn.Button("PPStart").Pressed)//player4
                {
                    if (Y == Scene.CameraY + 170 - _y)//Up
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(4, "Up"));//this key needs to be EXACTLY the same as the save key.
                    else if (Y == Scene.CameraY + 190 - _y)//Down
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(4, "Down"));
                    else if (Y == Scene.CameraY + 210 - _y)//Left
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(4, "Left"));
                    else if (Y == Scene.CameraY + 230 - _y)//Right
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(4, "Right"));
                    else if (Y == Scene.CameraY + 250 - _y)//Jump
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(4, "Jump"));
                    else if (Y == Scene.CameraY + 270 - _y)//Fire
                        Global.GAME.Coroutine.Start(WaitForKeyRoutine(4, "Fire"));
                    else if (Y == Scene.CameraY + 350 - _y)//Set to Defaults
                        SetDefaults(4);
                }
                else if (Y == Scene.CameraY + 370 - _y && cn.Button("PPStart").Pressed)
                {
                    PauseMenuBackground.IsDestroy = false;
                    PauseMenuControlOptions.IsDestroy = true;
                    Scene.Add(new PauseMenuBackground(Scene.CameraX + 100, Scene.CameraY + 100));
                    _isAudioOptionsActive = false;
                    _isControlOptionsActive = false;
                    X = Scene.CameraX + 255;
                    Y = Scene.CameraY + 230 - _y;
                }
            }
            if (_changeStartTimer > 0 && _changeStartToFalse)
                _changeStartTimer--;
            if (_changeStartTimer <= 0 && _changeStartToFalse)
            {
                _changeStartToFalse = false;
                _isChangingStart = false;
            }
            if (_changeEscapeTimer > 0 && _changeEscapeToFalse)
                _changeEscapeTimer--;
            if (_changeEscapeTimer <= 0 && _changeEscapeToFalse)
            {
                _changeEscapeToFalse = false;
                IsChangingEscape = false;
            }
        }//end of update

        private void SetDefaults(int player)
        {
            if (player == 1)
            {
                #region playerOneDataDefaultsSet
                _cp = Global.PlayerSession;
                _fake = Global.PausePersonSession;
                _fake.Data.Import();//don't need this unless P1 was true anyway.
                _cp.Data.Import();
                _cp.Data.SetData("P1Up", "Key.W");
                _fake.Data.SetData("PPUp", "Key.W");
                _cp.Data.SetData("P1Down", "Key.S");
                _fake.Data.SetData("PPDown", "Key.S");
                _cp.Data.SetData("P1Left", "Key.A");
                _fake.Data.SetData("PPLeft", "Key.A");
                _cp.Data.SetData("P1Right", "Key.D");
                _fake.Data.SetData("PPRight", "Key.D");
                _cp.Data.SetData("P1Fire", "Key.Z");
                _fake.Data.SetData("PPFire", "Key.Z");
                _cp.Data.SetData("P1Jump", "Key.X");
                _fake.Data.SetData("PPJump", "Key.X");
                _cp.Data.SetData("P1Start", "Key.Return");
                _fake.Data.SetData("PPStart", "Key.Return");
                _cp.Data.SetData("P1Mute", "Key.M");
                _fake.Data.SetData("PPMute", "Key.M");
                _cp.Data.SetData("P1Testing", "Key.R");
                _fake.Data.SetData("PPTesting", "Key.R");
                _cp.Data.SetData("P1Testing2", "Key.Q");
                _fake.Data.SetData("PPTesting2", "Key.Q");
                _cp.Data.SetData("P1Escape", "Key.Escape");
                _fake.Data.SetData("PPEscape", "Key.Escape");
                _cp.Data.SetData("P1JoystickNumber", "0");
                _fake.Data.SetData("PPJoystickNumber", "0");
                #endregion
                _cp.Data.Export();
                _fake.Data.Export();
                #region playerOneControllerDefaultsSet
                Global.PlayerSession.Controller.Button("P1Up").Clear();
                Global.PlayerSession.Controller.Button("P1Up").AddKey(Key.W);
                Global.PausePersonSession.Controller.Button("PPUp").Clear();
                Global.PausePersonSession.Controller.Button("PPUp").AddKey(Key.W);
                Global.PlayerSession.Controller.Button("P1Down").Clear();
                Global.PlayerSession.Controller.Button("P1Down").AddKey(Key.S);
                Global.PausePersonSession.Controller.Button("PPDown").Clear();
                Global.PausePersonSession.Controller.Button("PPDown").AddKey(Key.S);
                Global.PlayerSession.Controller.Button("P1Left").Clear();
                Global.PlayerSession.Controller.Button("P1Left").AddKey(Key.A);
                Global.PausePersonSession.Controller.Button("PPLeft").Clear();
                Global.PausePersonSession.Controller.Button("PPLeft").AddKey(Key.A);
                Global.PlayerSession.Controller.Button("P1Right").Clear();
                Global.PlayerSession.Controller.Button("P1Right").AddKey(Key.D);
                Global.PausePersonSession.Controller.Button("PPRight").Clear();
                Global.PausePersonSession.Controller.Button("PPRight").AddKey(Key.D);
                Global.PlayerSession.Controller.Button("P1Fire").Clear();
                Global.PlayerSession.Controller.Button("P1Fire").AddKey(Key.Z);
                Global.PausePersonSession.Controller.Button("PPFire").Clear();
                Global.PausePersonSession.Controller.Button("PPFire").AddKey(Key.Z);
                Global.PlayerSession.Controller.Button("P1Jump").Clear();
                Global.PlayerSession.Controller.Button("P1Jump").AddKey(Key.X);
                Global.PausePersonSession.Controller.Button("PPJump").Clear();
                Global.PausePersonSession.Controller.Button("PPJump").AddKey(Key.X);
                Global.PlayerSession.Controller.Button("P1Start").Clear();
                Global.PlayerSession.Controller.Button("P1Start").AddKey(Key.Return);
                Global.PausePersonSession.Controller.Button("PPStart").Clear();
                Global.PausePersonSession.Controller.Button("PPStart").AddKey(Key.Return);
                Global.PlayerSession.Controller.Button("P1Mute").Clear();
                Global.PlayerSession.Controller.Button("P1Mute").AddKey(Key.M);
                Global.PausePersonSession.Controller.Button("PPMute").Clear();
                Global.PausePersonSession.Controller.Button("PPMute").AddKey(Key.M);
                Global.PlayerSession.Controller.Button("P1Testing").Clear();
                Global.PlayerSession.Controller.Button("P1Testing").AddKey(Key.R);
                Global.PausePersonSession.Controller.Button("PPTesting").Clear();
                Global.PausePersonSession.Controller.Button("PPTesting").AddKey(Key.R);
                Global.PlayerSession.Controller.Button("P1Testing2").Clear();
                Global.PlayerSession.Controller.Button("P1Testing2").AddKey(Key.Q);
                Global.PausePersonSession.Controller.Button("PPTesting2").Clear();
                Global.PausePersonSession.Controller.Button("PPTesting2").AddKey(Key.Q);
                Global.PlayerSession.Controller.Button("P1Escape").Clear();
                Global.PlayerSession.Controller.Button("P1Escape").AddKey(Key.Escape);
                Global.PausePersonSession.Controller.Button("PPEscape").Clear();
                Global.PausePersonSession.Controller.Button("PPEscape").AddKey(Key.Escape);
                #endregion

            }
            //refresh the screen, by kill it and redrawing it.
            var pausemenu = GetEntities<PauseMenuControlOptions>();
            foreach (var m in pausemenu)
            {
                m.Destroy();
            }
            PauseMenuControlOptions.IsDestroy = false;
            PauseMenuBackground.IsDestroy = true;
            Scene.Add(new PauseMenuControlOptions(10, 10));
            SoundManager.PlayRequestedSound("_badPassword");
        }

        public static IEnumerator Wait(Input input)
        {
            yield return Coroutine.Instance.WaitForFrames(150);
            //Console.WriteLine("Delayed Change Up here: {0}", input.LastKey);
            //Console.WriteLine("Delayed Change Up here: {0}", input.LastMouseButton);
            //Console.WriteLine("Delayed Change Up here: {0}", input.LastButton[0]);
        }

        private IEnumerator WaitForKeyRoutine(int player, string controlToUpdate)
        {
            _key = Key.Unknown;
            for (int i = 0; i < Input.JoysticksConnected; i++)
            {//set all joysticks to -1.
                Input.LastButton[i] = -1;
            }
            _mouseButton = MouseButton.Any;
            Scene.Add(new PressKeyMessage(player, controlToUpdate));

            yield return Coroutine.Instance.WaitForFrames(5);

            while (!_keyPressed)
            {
                if (Input.KeyPressed(Key.Any))
                {
                    _key = Input.LastKey;
                    _keyPressed = true;
                    _controlType = "key";
                }
                if (Input.MouseButtonPressed(MouseButton.Any))
                {
                    _mouseButton = Input.LastMouseButton;
                    _keyPressed = true;
                    _controlType = "mouse";
                }
                for (int i = 0; i < Input.JoysticksConnected; i++)
                {
                    if (Input.LastButton[i] != -1 && Input.LastButton[i] < 100)//it defaults to -1 for no button pressed
                    {//should be regular joystick buttons
                        _anyJoyButton = Input.LastButton[i];
                        _keyPressed = true;
                        _controlType = "joystickButton";
                        _joystickNumber = i;
                        Input.LastButton[i] = -1;//reset it back to no button.
                    }
                    if (Input.LastButton[i] != -1 && Input.LastButton[i] >= 100) //adding correct axis that the person selects on his controller. 
                    {//should be axis buttons! should be. :/
                        _anyJoyButton = Input.LastButton[i];
                        _keyPressed = true;
                        _controlType = "joystickAxis";
                        _joystickNumber = i;
                        Input.LastButton[i] = -1;
                    }
                    Input.LastButton[i] = -1;
                }

                yield return 0;
            }

            UpdateKeyData(player, controlToUpdate);
            Scene.GetEntity<PressKeyMessage>().Destroy();
            _keyPressed = false;
        }

        private void UpdateKeyData(int player, string controlToUpdate)
        {
            //update the backened data to have the new key (1,2,3,4 and/or fake)
            //import player data
            if (player == 1)
            {
                _cp = Global.PlayerSession;
                _b = "P1";
                _fake = Global.PausePersonSession;
                _c = "PP";
                _fake.Data.Import();//don't need this unless P1 was true anyway.
            }
            _cp.Data.Import();
            if (_controlType == "joystickButton")
            {
                _cp.Data.SetData(_b + controlToUpdate, GetProperJoystickButtonValue());
                _cp.Data.SetData(_b + "JoystickNumber", _joystickNumber);
                if (player == 1)
                {
                    _fake.Data.SetData(_c + controlToUpdate, GetProperJoystickButtonValue());
                    _fake.Data.SetData(_c + "JoystickNumber", _joystickNumber);
                }
            }
            if (_controlType == "joystickAxis")
            {
                _cp.Data.SetData(_b + controlToUpdate, GetProperJoystickAxisValue());
                _cp.Data.SetData(_b + "JoystickNumber", _joystickNumber);
                if (player == 1)
                {
                    _fake.Data.SetData(_c + controlToUpdate, GetProperJoystickAxisValue());
                    _fake.Data.SetData(_c + "JoystickNumber", _joystickNumber);
                }
            }
            if (_controlType == "key")
            {
                _cp.Data.SetData(_b + controlToUpdate, "Key." + _key.ToString());
                if (player == 1)
                    _fake.Data.SetData(_c + controlToUpdate, "Key." + _key.ToString());
            }
            if (_controlType == "mouse")
            {
                _cp.Data.SetData(_b + controlToUpdate, "MouseButton." + _mouseButton.ToString());
                if (player == 1)
                    _fake.Data.SetData(_c + controlToUpdate, "MouseButton." + _mouseButton.ToString());
            }
            _cp.Data.Export();
            if (player == 1)
                _fake.Data.Export();

            /*update current player controller to use the new key. //this doesn't work right. It isn't refreshing the right and left buttons.
            The problem is with the axis. The player axis doesn't update the new button change till the player is readded and refreshed next level.
            */
            //update the fake screen user key if player one was updated as well.
            if (_controlType == "joystickButton")
            {
                if (player == 1)
                {
                    var temp = GetProperJoystickButtonValue();
                    var app = Global.PlayerSession;
                    var pp = Global.PausePersonSession;
                    if (_joystickNumber == 0)
                    {
                        if (Global.xBoxController == null)
                            Global.xBoxController = new ControllerXbox360(0);//what controller to pick
                        if (temp == "JoyButtonA")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.A);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.A);
                        }
                        if (temp == "JoyButtonB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.B);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.B);
                        }
                        if (temp == "JoyButtonX")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.X);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.X);
                        }
                        if (temp == "JoyButtonY")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Y);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Y);
                        }
                        if (temp == "JoyButtonLB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.LB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.LB);
                        }
                        if (temp == "JoyButtonRB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.RB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.RB);
                        }
                        if (temp == "JoyButtonBack")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Back);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Back);
                        }
                        if (temp == "JoyButtonStart")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Start);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Start);
                        }
                        if (temp == "JoyButtonLSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.LeftStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.LeftStickClick);
                        }
                        if (temp == "JoyButtonRSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.RightStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.RightStickClick);
                        }
                        if (temp == "JoyButton10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Button10);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Button10);
                        }
                        if (temp == "JoyButton11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Button11);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Button11);
                        }
                        if (temp == "JoyButton12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Button12);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Button12);
                        }
                        if (temp == "JoyButton13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Button13);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Button13);
                        }
                        if (temp == "JoyButton14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Button14);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Button14);
                        }
                        if (temp == "JoyButton15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Button15);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Button15);
                        }
                    }
                    else if (_joystickNumber == 1)
                    {
                        if (Global.xBoxController2 == null)
                            Global.xBoxController2 = new ControllerXbox360(1);//what controller to pick
                        if (temp == "JoyButtonA")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.A);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.A);
                        }
                        if (temp == "JoyButtonB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.B);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.B);
                        }
                        if (temp == "JoyButtonX")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.X);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.X);
                        }
                        if (temp == "JoyButtonY")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Y);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Y);
                        }
                        if (temp == "JoyButtonLB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.LB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.LB);
                        }
                        if (temp == "JoyButtonRB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.RB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.RB);
                        }
                        if (temp == "JoyButtonBack")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Back);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Back);
                        }
                        if (temp == "JoyButtonStart")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Start);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Start);
                        }
                        if (temp == "JoyButtonLSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.LeftStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.LeftStickClick);
                        }
                        if (temp == "JoyButtonRSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.RightStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.RightStickClick);
                        }
                        if (temp == "JoyButton10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Button10);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Button10);
                        }
                        if (temp == "JoyButton11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Button11);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Button11);
                        }
                        if (temp == "JoyButton12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Button12);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Button12);
                        }
                        if (temp == "JoyButton13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Button13);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Button13);
                        }
                        if (temp == "JoyButton14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Button14);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Button14);
                        }
                        if (temp == "JoyButton15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Button15);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Button15);
                        }
                    }
                    else if (_joystickNumber == 2)
                    {
                        if (Global.xBoxController3 == null)
                            Global.xBoxController3 = new ControllerXbox360(2);//what controller to pick
                        if (temp == "JoyButtonA")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.A);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.A);
                        }
                        if (temp == "JoyButtonB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.B);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.B);
                        }
                        if (temp == "JoyButtonX")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.X);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.X);
                        }
                        if (temp == "JoyButtonY")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Y);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Y);
                        }
                        if (temp == "JoyButtonLB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.LB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.LB);
                        }
                        if (temp == "JoyButtonRB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.RB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.RB);
                        }
                        if (temp == "JoyButtonBack")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Back);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Back);
                        }
                        if (temp == "JoyButtonStart")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Start);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Start);
                        }
                        if (temp == "JoyButtonLSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.LeftStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.LeftStickClick);
                        }
                        if (temp == "JoyButtonRSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.RightStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.RightStickClick);
                        }
                        if (temp == "JoyButton10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Button10);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Button10);
                        }
                        if (temp == "JoyButton11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Button11);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Button11);
                        }
                        if (temp == "JoyButton12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Button12);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Button12);
                        }
                        if (temp == "JoyButton13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Button13);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Button13);
                        }
                        if (temp == "JoyButton14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Button14);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Button14);
                        }
                        if (temp == "JoyButton15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Button15);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Button15);
                        }
                    }
                    else if (_joystickNumber == 3)
                    {
                        if (Global.xBoxController4 == null)
                            Global.xBoxController4 = new ControllerXbox360(3);//what controller to pick
                        if (temp == "JoyButtonA")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.A);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.A);
                        }
                        if (temp == "JoyButtonB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.B);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.B);
                        }
                        if (temp == "JoyButtonX")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.X);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.X);
                        }
                        if (temp == "JoyButtonY")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Y);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Y);
                        }
                        if (temp == "JoyButtonLB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.LB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.LB);
                        }
                        if (temp == "JoyButtonRB")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.RB);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.RB);
                        }
                        if (temp == "JoyButtonBack")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Back);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Back);
                        }
                        if (temp == "JoyButtonStart")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Start);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Start);
                        }
                        if (temp == "JoyButtonLSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.LeftStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.LeftStickClick);
                        }
                        if (temp == "JoyButtonRSC")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.RightStickClick);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.RightStickClick);
                        }
                        if (temp == "JoyButton10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Button10);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Button10);
                        }
                        if (temp == "JoyButton11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Button11);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Button11);
                        }
                        if (temp == "JoyButton12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Button12);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Button12);
                        }
                        if (temp == "JoyButton13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Button13);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Button13);
                        }
                        if (temp == "JoyButton14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Button14);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Button14);
                        }
                        if (temp == "JoyButton15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Button15);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Button15);
                        }
                    }
                    Global.IsPlayerOneAxisReset = true;
                }
            }
            if (_controlType == "joystickAxis")
            {
                if (player == 1)
                {
                    var temp = GetProperJoystickAxisValue();
                    var app = Global.PlayerSession;
                    var pp = Global.PausePersonSession;
                    if (_joystickNumber == 0)
                    {
                        if (Global.xBoxController == null)
                            Global.xBoxController = new ControllerXbox360(0);//what controller to pick
                        if (temp == "JoyAxis0")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.RSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.RSRight);
                        }
                        if (temp == "JoyAxis1")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.RSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.RSLeft);
                        }
                        if (temp == "JoyAxis2")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.RSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.RSDown);
                        }
                        if (temp == "JoyAxis3")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.RSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.RSUp);
                        }
                        if (temp == "JoyAxis4")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.LT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.LT);
                        }
                        if (temp == "JoyAxis5")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.RT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.RT);
                        }
                        if (temp == "JoyAxis6")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.LSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.LSRight);
                        }
                        if (temp == "JoyAxis7")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.LSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.LSLeft);
                        }
                        if (temp == "JoyAxis8")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.LSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.LSDown);
                        }
                        if (temp == "JoyAxis9")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.LSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.LSUp);
                        }
                        if (temp == "JoyAxis10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Vlt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Vlt);
                        }
                        if (temp == "JoyAxis11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.Vrt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.Vrt);
                        }
                        if (temp == "JoyAxis12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.PovRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.PovRight);
                        }
                        if (temp == "JoyAxis13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.PovLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.PovLeft);
                        }
                        if (temp == "JoyAxis14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.PovDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.PovDown);
                        }
                        if (temp == "JoyAxis15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController.PovUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController.PovUp);
                        }
                    }
                    else if (_joystickNumber == 1)
                    {
                        if (Global.xBoxController2 == null)
                            Global.xBoxController2 = new ControllerXbox360(1);//what controller to pick
                        if (temp == "JoyAxis0")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.RSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.RSRight);
                        }
                        if (temp == "JoyAxis1")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.RSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.RSLeft);
                        }
                        if (temp == "JoyAxis2")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.RSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.RSDown);
                        }
                        if (temp == "JoyAxis3")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.RSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.RSUp);
                        }
                        if (temp == "JoyAxis4")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.LT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.LT);
                        }
                        if (temp == "JoyAxis5")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.RT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.RT);
                        }
                        if (temp == "JoyAxis6")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.LSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.LSRight);
                        }
                        if (temp == "JoyAxis7")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.LSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.LSLeft);
                        }
                        if (temp == "JoyAxis8")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.LSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.LSDown);
                        }
                        if (temp == "JoyAxis9")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.LSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.LSUp);
                        }
                        if (temp == "JoyAxis10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Vlt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Vlt);
                        }
                        if (temp == "JoyAxis11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.Vrt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.Vrt);
                        }
                        if (temp == "JoyAxis12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.PovRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.PovRight);
                        }
                        if (temp == "JoyAxis13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.PovLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.PovLeft);
                        }
                        if (temp == "JoyAxis14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.PovDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.PovDown);
                        }
                        if (temp == "JoyAxis15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController2.PovUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController2.PovUp);
                        }
                    }
                    else if (_joystickNumber == 2)
                    {
                        if (Global.xBoxController3 == null)
                            Global.xBoxController3 = new ControllerXbox360(2);//what controller to pick
                        if (temp == "JoyAxis0")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.RSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.RSRight);
                        }
                        if (temp == "JoyAxis1")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.RSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.RSLeft);
                        }
                        if (temp == "JoyAxis2")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.RSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.RSDown);
                        }
                        if (temp == "JoyAxis3")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.RSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.RSUp);
                        }
                        if (temp == "JoyAxis4")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.LT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.LT);
                        }
                        if (temp == "JoyAxis5")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.RT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.RT);
                        }
                        if (temp == "JoyAxis6")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.LSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.LSRight);
                        }
                        if (temp == "JoyAxis7")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.LSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.LSLeft);
                        }
                        if (temp == "JoyAxis8")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.LSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.LSDown);
                        }
                        if (temp == "JoyAxis9")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.LSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.LSUp);
                        }
                        if (temp == "JoyAxis10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Vlt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Vlt);
                        }
                        if (temp == "JoyAxis11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.Vrt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.Vrt);
                        }
                        if (temp == "JoyAxis12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.PovRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.PovRight);
                        }
                        if (temp == "JoyAxis13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.PovLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.PovLeft);
                        }
                        if (temp == "JoyAxis14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.PovDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.PovDown);
                        }
                        if (temp == "JoyAxis15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController3.PovUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController3.PovUp);
                        }
                    }
                    else if (_joystickNumber == 3)
                    {
                        if (Global.xBoxController4 == null)
                            Global.xBoxController4 = new ControllerXbox360(3);//what controller to pick
                        if (temp == "JoyAxis0")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.RSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.RSRight);
                        }
                        if (temp == "JoyAxis1")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.RSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.RSLeft);
                        }
                        if (temp == "JoyAxis2")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.RSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.RSDown);
                        }
                        if (temp == "JoyAxis3")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.RSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.RSUp);
                        }
                        if (temp == "JoyAxis4")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.LT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.LT);
                        }
                        if (temp == "JoyAxis5")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.RT);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.RT);
                        }
                        if (temp == "JoyAxis6")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.LSRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.LSRight);
                        }
                        if (temp == "JoyAxis7")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.LSLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.LSLeft);
                        }
                        if (temp == "JoyAxis8")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.LSDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.LSDown);
                        }
                        if (temp == "JoyAxis9")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.LSUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.LSUp);
                        }
                        if (temp == "JoyAxis10")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Vlt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Vlt);
                        }
                        if (temp == "JoyAxis11")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.Vrt);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.Vrt);
                        }
                        if (temp == "JoyAxis12")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.PovRight);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.PovRight);
                        }
                        if (temp == "JoyAxis13")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.PovLeft);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.PovLeft);
                        }
                        if (temp == "JoyAxis14")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.PovDown);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.PovDown);
                        }
                        if (temp == "JoyAxis15")
                        {
                            app.Controller.Button(_b + controlToUpdate).Clear();
                            app.Controller.Button(_b + controlToUpdate).AddButton(Global.xBoxController4.PovUp);
                            pp.Controller.Button("PP" + controlToUpdate).Clear();
                            pp.Controller.Button("PP" + controlToUpdate).AddButton(Global.xBoxController4.PovUp);
                        }
                    }
                    Global.IsPlayerOneAxisReset = true;
                }
            }
            if (_controlType == "key")
            {
                if (player == 1)
                {
                    Global.PlayerSession.Controller.Button(_b + controlToUpdate).Clear();
                    Global.PlayerSession.Controller.Button(_b + controlToUpdate).AddKey(_key);
                    Global.PausePersonSession.Controller.Button("PP" + controlToUpdate).Clear();
                    Global.PausePersonSession.Controller.Button("PP" + controlToUpdate).AddKey(_key);
                    Global.IsPlayerOneAxisReset = true;
                }
            }
            if (_controlType == "mouse")
            {
                if (player == 1)
                {
                    Global.PlayerSession.Controller.Button(_b + controlToUpdate).Clear();
                    Global.PlayerSession.Controller.Button(_b + controlToUpdate).AddMouseButton(_mouseButton);
                    Global.PausePersonSession.Controller.Button("PP" + controlToUpdate).Clear();
                    Global.PausePersonSession.Controller.Button("PP" + controlToUpdate).AddMouseButton(_mouseButton);
                    Global.IsPlayerOneAxisReset = true;
                }
            }
            //refresh the screen, by kill it and redrawing it.
            var pausemenu = GetEntities<PauseMenuControlOptions>();
            foreach (var m in pausemenu)
            {
                m.Destroy();
            }
            PauseMenuControlOptions.IsDestroy = false;
            PauseMenuBackground.IsDestroy = true;
            Scene.Add(new PauseMenuControlOptions(10, 10));
            _changeStartToFalse = true;
            _changeStartTimer = 10;
            _changeEscapeToFalse = true;
            _changeEscapeTimer = 10;
            SoundManager.PlayRequestedSound("_openTwo");
        }

        private string GetProperJoystickButtonValue()
        {
            if (_anyJoyButton == 0)
                return "JoyButtonA";
            else if (_anyJoyButton == 1)
                return "JoyButtonB";
            else if (_anyJoyButton == 2)
                return "JoyButtonX";
            else if (_anyJoyButton == 3)
                return "JoyButtonY";
            else if (_anyJoyButton == 4)
                return "JoyButtonLB";
            else if (_anyJoyButton == 5)
                return "JoyButtonRB";
            else if (_anyJoyButton == 6)
                return "JoyButtonBack";
            else if (_anyJoyButton == 7)
                return "JoyButtonStart";
            else if (_anyJoyButton == 8)
                return "JoyButtonLSC";
            else if (_anyJoyButton == 9)
                return "JoyButtonRSC";
            else if (_anyJoyButton == 10)
                return "JoyButton10";
            else if (_anyJoyButton == 11)
                return "JoyButton11";
            else if (_anyJoyButton == 12)
                return "JoyButton12";
            else if (_anyJoyButton == 13)
                return "JoyButton13";
            else if (_anyJoyButton == 14)
                return "JoyButton14";
            else if (_anyJoyButton == 15)
                return "JoyButton15";
            else
                return "unknown";
        }

        private string GetProperJoystickAxisValue()
        {
            if (_anyJoyButton == 100)
                return "JoyAxis0";
            else if (_anyJoyButton == 101)
                return "JoyAxis1";
            else if (_anyJoyButton == 102)
                return "JoyAxis2";
            else if (_anyJoyButton == 103)
                return "JoyAxis3";
            else if (_anyJoyButton == 104)
                return "JoyAxis4";
            else if (_anyJoyButton == 105)
                return "JoyAxis5";
            else if (_anyJoyButton == 106)
                return "JoyAxis6";
            else if (_anyJoyButton == 107)
                return "JoyAxis7";
            else if (_anyJoyButton == 108)
                return "JoyAxis8";
            else if (_anyJoyButton == 109)
                return "JoyAxis9";
            else if (_anyJoyButton == 110)
                return "JoyAxis10";
            else if (_anyJoyButton == 111)
                return "JoyAxis11";
            else if (_anyJoyButton == 112)
                return "JoyAxis12";
            else if (_anyJoyButton == 113)
                return "JoyAxis13";
            else if (_anyJoyButton == 114)
                return "JoyAxis14";
            else if (_anyJoyButton == 115)
                return "JoyAxis15";
            else
                return "unknown";
        }

        public void Destroy()
        {
            var pauseAudioX = GetEntities<PauseMenuAudioX>();
            foreach (var x in pauseAudioX)
            {
                x.Destroy();
            }
            var pauseX = GetEntities<PauseMenuMusicX>();
            foreach (var x in pauseX)
            {
                x.Destroy();
            }
            Global.PausePersonSession.Controller.Button("PPEscape").ReleaseState();//this is so i can press it again. (it locks it out otherwise)
            RemoveSelf();
        }

        public override void Render()
        {
            base.Render();
            //Collider.Render();
        }


    }
}
