Example #1
0
 public Controller(ControllerIndex index)
 {
     playerIndex   = (Microsoft.Xna.Framework.PlayerIndex)Enum.Parse(typeof(Microsoft.Xna.Framework.PlayerIndex), Enum.GetName(typeof(ControllerIndex), index));
     monitorThread = new Thread(new ThreadStart(ControllerMonitor));
     monitorThread.IsBackground = true;
     monitorThread.Start();
 }
Example #2
0
        /// <summary>
        ///     プレイヤーの初期設定
        /// </summary>
        /// <param name="player"></param>
        /// <param name="index"></param>
        private void PlayerSetup(PlayerCore player, ControllerIndex index)
        {
            player.transform.SetParent(_transformCache);
            player.gameObject.AddComponent <PlayerStateChanger>();

            switch (index)
            {
            // コントローラー入力
            case ControllerIndex.One:
            case ControllerIndex.Two:
            case ControllerIndex.Three:
            case ControllerIndex.Four:
            {
                player.InputEventProvider = new InputController((int)index.ToGamePadIndex());
                break;
            }

            // キーボード入力
            case ControllerIndex.Keyboard:
            {
                player.InputEventProvider = new InputKeyBoard();
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(index), index, null);
            }
        }
        public static Texture2D ConvertToTexture(ControllerIndex c)
        {
            switch (c)
            {
            case ControllerIndex.ControllerOne:
                return(XboxControllerTextures[0]);

            case ControllerIndex.ControllerTwo:
                return(XboxControllerTextures[1]);

            case ControllerIndex.ControllerThree:
                return(XboxControllerTextures[2]);

            case ControllerIndex.ControllerFour:
                return(XboxControllerTextures[3]);

            case ControllerIndex.Keyboard:
                return(KeyboardTexture);

            case ControllerIndex.AI:
                return(AITexture);

            case ControllerIndex.Online:
                return(OnlineTexture);
            }

            return(null);
        }
Example #4
0
        public static PlayerIndex[] GetPlayers(this ControllerIndex index)
        {
            switch (index)
            {
            case ControllerIndex.None:
                return(ControllerIndexExtensions.None);

            case ControllerIndex.One:
                return(ControllerIndexExtensions.One);

            case ControllerIndex.Two:
                return(ControllerIndexExtensions.Two);

            case ControllerIndex.Three:
                return(ControllerIndexExtensions.Three);

            case ControllerIndex.Four:
                return(ControllerIndexExtensions.Four);

            case ControllerIndex.Any:
                return(ControllerIndexExtensions.Any);

            default:
                return(ControllerIndexExtensions.None);
            }
        }
        public PlayerProfile(SignedInGamer MyGamer, BasicController MyController, ControllerIndex controllerIndex)
        {
            if (MyGamer != null)
            {
                PlayerName = MyGamer.DisplayName;
            }

            this.MyGamer         = MyGamer;
            this.MyController    = MyController;
            this.controllerIndex = controllerIndex;
        }
        public static GamePad.Index ToGamePadIndex(this ControllerIndex index)
        {
            if (index == ControllerIndex.Invalid)
            {
                throw new ArgumentException("Invalid argument.", nameof(index));
            }
            if (index == ControllerIndex.Keyboard)
            {
                throw new ArgumentException("Keyboard can't convert GamePad.Index.", nameof(index));
            }

            return((GamePad.Index)index);
        }
Example #7
0
    public static PlayerIndex GetPlayer(this ControllerIndex index)
    {
        switch (index)
        {
        case ControllerIndex.One:   return(PlayerIndex.One);

        case ControllerIndex.Two:   return(PlayerIndex.Two);

        case ControllerIndex.Three: return(PlayerIndex.Three);

        case ControllerIndex.Four:  return(PlayerIndex.Four);
        }
        //throw new InvalidOperationException("This controller index corresponds to no player or more than one player");
        return(PlayerIndex.One);
    }
Example #8
0
        public virtual void Init(ControllerIndex controllerIndex)
        {
            ControllerIndex = controllerIndex;
            foreach (object b in Enum.GetValues(typeof(ControlButtons)))
            {
                ControlButtons btn = (ControlButtons)b;
                ButtonPressedLastFrame.Add(btn, false);
                ButtonPressed.Add(btn, false);
                ButtonDown.Add(btn, false);
                ButtonUp.Add(btn, false);
            }

            foreach (object b in Enum.GetValues(typeof(ControlAxis)))
            {
                ControlAxis ca = (ControlAxis)b;
                Axises.Add(ca, 0);
            }
        }
Example #9
0
    public static IEnumerable <PlayerIndex> GetPlayers(this ControllerIndex index)
    {
        switch (index)
        {
        case ControllerIndex.None:  return(None);

        case ControllerIndex.One:   return(One);

        case ControllerIndex.Two:   return(Two);

        case ControllerIndex.Three: return(Three);

        case ControllerIndex.Four:  return(Four);

        case ControllerIndex.Any:   return(Any);
        }
        return(None);
    }
Example #10
0
        public void Init()
        {
            PlayerControllerMap.Clear();
            Controllers.Clear();
            foreach (object o in Enum.GetValues(typeof(ControllerIndex)))
            {
                ControllerIndex ci = (ControllerIndex)o;
                if ((int)ci <= 4)
                {
                    Controllers.Add(ci, new XBoxController());
                }
                else
                {
                    Controllers.Add(ci, new KeyBoardController());
                }

                Controllers[ci].Init(ci);
            }
        }
        public static PlayerIndex Convert(ControllerIndex c)
        {
            switch (c)
            {
            case ControllerIndex.ControllerOne:
                return(PlayerIndex.One);

            case ControllerIndex.ControllerTwo:
                return(PlayerIndex.Two);

            case ControllerIndex.ControllerThree:
                return(PlayerIndex.Three);

            case ControllerIndex.ControllerFour:
                return(PlayerIndex.Four);
            }

            return(PlayerIndex.One);
        }
Example #12
0
        public static PlayerIndex GetPlayer(this ControllerIndex index)
        {
            switch (index)
            {
            case ControllerIndex.One:
                return(PlayerIndex.One);

            case ControllerIndex.Two:
                return(PlayerIndex.Two);

            case ControllerIndex.Three:
                return(PlayerIndex.Three);

            case ControllerIndex.Four:
                return(PlayerIndex.Four);

            default:
                return(PlayerIndex.One);
            }
        }
Example #13
0
        private void Update()
        {
            foreach (KeyValuePair <ControllerIndex, Controller> kv in Controllers)
            {
                kv.Value.Update();
            }

            foreach (object o in Enum.GetValues(typeof(ControllerIndex)))
            {
                ControllerIndex ci = (ControllerIndex)o;
                Controller      c  = Controllers[ci];
                if (c.ButtonDown[c.AddPlayerButton])
                {
                    if (!PlayerControllerMap.Values.Contains(ci))
                    {
                        OnAddPlayer?.Invoke(ci);
                    }
                }
            }
        }
Example #14
0
 public Player(ControllerIndex _number)
 {
     justUnpaused = false;
     isPaused = false;
     teamNotSet = true;
     number = _number;
     if (_number != ControllerIndex.Keyboard)
     {
         keyboardControlled = false;
     }
     else
     {
         keyboardControlled = true;
     }
     playerCamera = null;
     currentState = new MenuPlayerState(this);
     playerHUD = new PlayerHUD(this);
     playerHUDActive = false;
     objectivesDrawActive = true;
     pausedState = new PausedPlayerState(this);
 }
        private static void TestSignIn(object o, SignedInEventArgs e)
        {
            BasicController b = null;
            ControllerIndex c = ControllerIndex.Keyboard;

#if EDITOR && WINDOWS
            if (signInState == SignInState.Controller)
            {
#endif
            b = new XboxController(e.Gamer.PlayerIndex);
            c = Convert(e.Gamer.PlayerIndex);
#if EDITOR && WINDOWS
        }

        else
        {
            b = new KeyboardController();
        }
#endif

            AddPlayer(b, e.Gamer, c);
        }
 public void InitKeyMapDictionary(ControllerIndex index)
 {
     Index            = index;
     KeyMapDictionary = new Dictionary <NesKeys, KeyMap>()
     {
         { NesKeys.a, KeyMap.A(
               Config.GetKeyMapConfig(index, NesKeys.a),
               lblA
               ) },
         { NesKeys.b, KeyMap.B(
               Config.GetKeyMapConfig(index, NesKeys.b),
               lblB
               ) },
         { NesKeys.select, KeyMap.Select(
               Config.GetKeyMapConfig(index, NesKeys.select),
               lblSelect
               ) },
         { NesKeys.start, KeyMap.Start(
               Config.GetKeyMapConfig(index, NesKeys.start),
               lblStart
               ) },
         { NesKeys.up, KeyMap.Up(
               Config.GetKeyMapConfig(index, NesKeys.up),
               lblUp
               ) },
         { NesKeys.down, KeyMap.Down(
               Config.GetKeyMapConfig(index, NesKeys.down),
               lblDown
               ) },
         { NesKeys.left, KeyMap.Left(
               Config.GetKeyMapConfig(index, NesKeys.left),
               lblLeft
               ) },
         { NesKeys.right, KeyMap.Right(
               Config.GetKeyMapConfig(index, NesKeys.right),
               lblRight
               ) }
     };
 }
Example #17
0
        public Controller(ControllerIndex Index)
        {
            if (Index == ControllerIndex.Controller01)
            {
                ctrlHandle = DevicerHandle.Controller01;
                indexInt   = 0;
            }
            else
            {
                ctrlHandle = DevicerHandle.Controller02;
                indexInt   = 1;
            }

            m_state = (DeviceConnectionState)XDevicePlugin.GetInt(this.ctrlHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, (int)DeviceConnectionState.Disconnected);

            //Add LLAPI event listener:
            XDevicePlugin.RegisterObserver(ctrlHandle,
                                           XDevicePlugin.XControllerAttributes.kXCAttr_Int_ConnectionState,
                                           new XDevicePlugin.XDeviceConnectStateChangeDelegate(LLAPIConnectionStateChange),
                                           ctrlHandle);

            if (sAllButtons == null)
            {
                var controllerButtons = System.Enum.GetValues(typeof(ControllerButton));
                sAllButtons = new ControllerButton[controllerButtons.Length];
                for (int i = 0; i < controllerButtons.Length; i++)
                {
                    sAllButtons[i] = (ControllerButton)controllerButtons.GetValue(i);
                }
            }

            foreach (var button in sAllButtons)
            {
                buttonStates.Add(button, new ButtonState());
            }
        }
        public static PlayerProfile AddPlayer(BasicController controller, SignedInGamer gamer, ControllerIndex controllerIndex)
        {
            PlayerProfile newProfile = new PlayerProfile(gamer, controller, controllerIndex);

            bool Found = false;

            if (controllerIndex != ControllerIndex.AI && controllerIndex != ControllerIndex.Online)
            {
                for (int i = 0; i < Players.Count; i++)
                {
                    if (controllerIndex == Players[i].controllerIndex)
                    {
                        Players[i] = newProfile;
                        newProfile.SetPlayerNumber(i);
                        Found = true;
#if WINDOWS
                        if (!GameManager.GetLevel().LevelForEditing)
#endif
                        GameManager.GetLevel().PlayerJoinedEvent(newProfile);

                        PlayerJoinMessage(newProfile);
                        return(newProfile);
                    }
                }
            }

            if (!Found && Players.Count < MaxPlayers)
            {
                newProfile.SetPlayerNumber(Players.Count);
                Players.Add(newProfile);
#if WINDOWS
                if (!GameManager.GetLevel().LevelForEditing)
#endif
                GameManager.GetLevel().PlayerJoinedEvent(newProfile);

                PlayerJoinMessage(newProfile);
                return(newProfile);
            }
            return(null);
        }
 private static void PlayerNoJoinMessage(ControllerIndex c)
 {
     MessageTexture = ConvertToTexture(c);
     MessageAlpha   = 2;
     messageType    = MessageType.NotAllowed;
 }
Example #20
0
 public extern void orig_set_ActiveControllers(ControllerIndex value);
Example #21
0
 public Controller(ControllerIndex index)
 {
     playerIndex = (Microsoft.Xna.Framework.PlayerIndex)Enum.Parse(typeof(Microsoft.Xna.Framework.PlayerIndex), Enum.GetName(typeof(ControllerIndex), index));
     monitorThread = new Thread(new ThreadStart(ControllerMonitor));
     monitorThread.IsBackground = true;
     monitorThread.Start();
 }
Example #22
0
 public override void Init(ControllerIndex controllerIndex)
 {
     base.Init(controllerIndex);
     AddPlayerButton = ControlButtons.A;
 }
Example #23
0
 public void ForceActiveController(ControllerIndex ci)
 {
   this.ActiveControllers = ci;
 }
Example #24
0
 public void ForceActiveController(ControllerIndex ci)
 {
     this.ActiveControllers = ci;
 }