Пример #1
0
        private void Nintroller_StateUpdate(object sender, NintrollerStateEventArgs e)
        {
#if DEBUG
            var wgt = new WiiGuitar();

            var sb = new StringBuilder();

            if (!Cancelled)
            {
                if (e.state is WiiGuitar)
                {
                    wgt = (WiiGuitar)e.state;

                    sb.Clear();

                    for (int i = 0; i < wgt.DebugLastData.Length; i++)
                    {
                        sb.Append(wgt.DebugLastData[i].ToString("X2"));
                        sb.Append(" ");
                    }

                    Prompt(sb.ToString(), isBold: true, isItalic: false, isSmall: false, isDebug: false);

                    //System.Threading.Thread.Sleep(16);
                }
            }
#endif
        }
Пример #2
0
        void device_StateChange(object sender, NintrollerStateEventArgs e)
        {
            // Makes the timer wait
            if (updateTimer != null)
            {
                updateTimer.Change(1000, UPDATE_SPEED);
            }

            if (holder == null)
            {
                return;
            }

//            float intensity = 0;
//            if (holder.Values.TryGetValue(Inputs.Flags.RUMBLE, out intensity))
//            {
//                rumbleAmount = (int)intensity;
            RumbleStep();
//            }

            holder.ClearAllValues();

            switch (e.controllerType)
            {
            // TODO: Motion Plus Reading (not for 1st release)
            // TODO: Balance Board Reading (not for 1st release)
            // TODO: Musical Extension readings (not for 1st release)
            case ControllerType.ProController:
                #region Pro Controller
                ProController pro = (ProController)e.state;

                holder.SetValue(Inputs.ProController.A, pro.A);
                holder.SetValue(Inputs.ProController.B, pro.B);
                holder.SetValue(Inputs.ProController.X, pro.X);
                holder.SetValue(Inputs.ProController.Y, pro.Y);

                holder.SetValue(Inputs.ProController.UP, pro.Up);
                holder.SetValue(Inputs.ProController.DOWN, pro.Down);
                holder.SetValue(Inputs.ProController.LEFT, pro.Left);
                holder.SetValue(Inputs.ProController.RIGHT, pro.Right);

                holder.SetValue(Inputs.ProController.L, pro.L);
                holder.SetValue(Inputs.ProController.R, pro.R);
                holder.SetValue(Inputs.ProController.ZL, pro.ZL);
                holder.SetValue(Inputs.ProController.ZR, pro.ZR);

                holder.SetValue(Inputs.ProController.START, pro.Plus);
                holder.SetValue(Inputs.ProController.SELECT, pro.Minus);
                holder.SetValue(Inputs.ProController.HOME, pro.Home);
                holder.SetValue(Inputs.ProController.LS, pro.LStick);
                holder.SetValue(Inputs.ProController.RS, pro.RStick);

                holder.SetValue(Inputs.ProController.LRIGHT, pro.LJoy.X > 0 ? pro.LJoy.X : 0f);
                holder.SetValue(Inputs.ProController.LLEFT, pro.LJoy.X < 0 ? pro.LJoy.X * -1 : 0f);
                holder.SetValue(Inputs.ProController.LUP, pro.LJoy.Y > 0 ? pro.LJoy.Y : 0f);
                holder.SetValue(Inputs.ProController.LDOWN, pro.LJoy.Y < 0 ? pro.LJoy.Y * -1 : 0f);

                holder.SetValue(Inputs.ProController.RRIGHT, pro.RJoy.X > 0 ? pro.RJoy.X : 0f);
                holder.SetValue(Inputs.ProController.RLEFT, pro.RJoy.X < 0 ? pro.RJoy.X * -1 : 0f);
                holder.SetValue(Inputs.ProController.RUP, pro.RJoy.Y > 0 ? pro.RJoy.Y : 0f);
                holder.SetValue(Inputs.ProController.RDOWN, pro.RJoy.Y < 0 ? pro.RJoy.Y * -1 : 0f);
                #endregion
                break;

            case ControllerType.Wiimote:
                Wiimote wm = (Wiimote)e.state;
                SetWiimoteInputs(wm);
                break;

            case ControllerType.Nunchuk:
            case ControllerType.NunchukB:
                #region Nunchuk
                Nunchuk nun = (Nunchuk)e.state;

                SetWiimoteInputs(nun.wiimote);

                holder.SetValue(Inputs.Nunchuk.C, nun.C);
                holder.SetValue(Inputs.Nunchuk.Z, nun.Z);

                holder.SetValue(Inputs.Nunchuk.RIGHT, nun.joystick.X > 0 ? nun.joystick.X : 0f);
                holder.SetValue(Inputs.Nunchuk.LEFT, nun.joystick.X < 0 ? nun.joystick.X * -1 : 0f);
                holder.SetValue(Inputs.Nunchuk.UP, nun.joystick.Y > 0 ? nun.joystick.Y : 0f);
                holder.SetValue(Inputs.Nunchuk.DOWN, nun.joystick.Y < 0 ? nun.joystick.Y * -1 : 0f);

                //TODO: Nunchuk Accelerometer (not for 1st release)
                holder.SetValue(Inputs.Nunchuk.TILT_RIGHT, nun.accelerometer.X > 0 ? nun.accelerometer.X : 0f);
                holder.SetValue(Inputs.Nunchuk.TILT_LEFT, nun.accelerometer.X < 0 ? nun.accelerometer.X * -1 : 0f);
                holder.SetValue(Inputs.Nunchuk.TILT_UP, nun.accelerometer.Y > 0 ? nun.accelerometer.Y : 0f);
                holder.SetValue(Inputs.Nunchuk.TILT_DOWN, nun.accelerometer.Y < 0 ? nun.accelerometer.Y * -1 : 0f);

                holder.SetValue(Inputs.Nunchuk.ACC_SHAKE_X, nun.accelerometer.X > 1.15f);
                holder.SetValue(Inputs.Nunchuk.ACC_SHAKE_Y, nun.accelerometer.Y > 1.15f);
                holder.SetValue(Inputs.Nunchuk.ACC_SHAKE_Z, nun.accelerometer.Z > 1.15f);
                #endregion
                break;

            case ControllerType.ClassicController:
                #region Classic Controller
                ClassicController cc = (ClassicController)e.state;

                SetWiimoteInputs(cc.wiimote);

                holder.SetValue(Inputs.ClassicController.A, cc.A);
                holder.SetValue(Inputs.ClassicController.B, cc.B);
                holder.SetValue(Inputs.ClassicController.X, cc.X);
                holder.SetValue(Inputs.ClassicController.Y, cc.Y);

                holder.SetValue(Inputs.ClassicController.UP, cc.Up);
                holder.SetValue(Inputs.ClassicController.DOWN, cc.Down);
                holder.SetValue(Inputs.ClassicController.LEFT, cc.Left);
                holder.SetValue(Inputs.ClassicController.RIGHT, cc.Right);

                holder.SetValue(Inputs.ClassicController.L, cc.L.value > 0);
                holder.SetValue(Inputs.ClassicController.R, cc.R.value > 0);
                holder.SetValue(Inputs.ClassicController.ZL, cc.ZL);
                holder.SetValue(Inputs.ClassicController.ZR, cc.ZR);

                holder.SetValue(Inputs.ClassicController.START, cc.Start);
                holder.SetValue(Inputs.ClassicController.SELECT, cc.Select);
                holder.SetValue(Inputs.ClassicController.HOME, cc.Home);

                holder.SetValue(Inputs.ClassicController.LFULL, cc.LFull);
                holder.SetValue(Inputs.ClassicController.RFULL, cc.RFull);
                holder.SetValue(Inputs.ClassicController.LT, cc.L.value > 0.1f ? cc.L.value : 0f);
                holder.SetValue(Inputs.ClassicController.RT, cc.R.value > 0.1f ? cc.R.value : 0f);

                holder.SetValue(Inputs.ClassicController.LRIGHT, cc.LJoy.X > 0 ? cc.LJoy.X : 0f);
                holder.SetValue(Inputs.ClassicController.LLEFT, cc.LJoy.X < 0 ? cc.LJoy.X * -1 : 0f);
                holder.SetValue(Inputs.ClassicController.LUP, cc.LJoy.Y > 0 ? cc.LJoy.Y : 0f);
                holder.SetValue(Inputs.ClassicController.LDOWN, cc.LJoy.Y < 0 ? cc.LJoy.Y * -1 : 0f);

                holder.SetValue(Inputs.ClassicController.RRIGHT, cc.RJoy.X > 0 ? cc.RJoy.X : 0f);
                holder.SetValue(Inputs.ClassicController.RLEFT, cc.RJoy.X < 0 ? cc.RJoy.X * -1 : 0f);
                holder.SetValue(Inputs.ClassicController.RUP, cc.RJoy.Y > 0 ? cc.RJoy.Y : 0f);
                holder.SetValue(Inputs.ClassicController.RDOWN, cc.RJoy.Y < 0 ? cc.RJoy.Y * -1 : 0f);
                #endregion
                break;

            case ControllerType.ClassicControllerPro:
                #region Classic Controller Pro
                ClassicControllerPro ccp = (ClassicControllerPro)e.state;

                SetWiimoteInputs(ccp.wiimote);

                holder.SetValue(Inputs.ClassicControllerPro.A, ccp.A);
                holder.SetValue(Inputs.ClassicControllerPro.B, ccp.B);
                holder.SetValue(Inputs.ClassicControllerPro.X, ccp.X);
                holder.SetValue(Inputs.ClassicControllerPro.Y, ccp.Y);

                holder.SetValue(Inputs.ClassicControllerPro.UP, ccp.Up);
                holder.SetValue(Inputs.ClassicControllerPro.DOWN, ccp.Down);
                holder.SetValue(Inputs.ClassicControllerPro.LEFT, ccp.Left);
                holder.SetValue(Inputs.ClassicControllerPro.RIGHT, ccp.Right);

                holder.SetValue(Inputs.ClassicControllerPro.L, ccp.L);
                holder.SetValue(Inputs.ClassicControllerPro.R, ccp.R);
                holder.SetValue(Inputs.ClassicControllerPro.ZL, ccp.ZL);
                holder.SetValue(Inputs.ClassicControllerPro.ZR, ccp.ZR);

                holder.SetValue(Inputs.ClassicControllerPro.START, ccp.Start);
                holder.SetValue(Inputs.ClassicControllerPro.SELECT, ccp.Select);
                holder.SetValue(Inputs.ClassicControllerPro.HOME, ccp.Home);

                holder.SetValue(Inputs.ClassicControllerPro.LRIGHT, ccp.LJoy.X > 0 ? ccp.LJoy.X : 0f);
                holder.SetValue(Inputs.ClassicControllerPro.LLEFT, ccp.LJoy.X < 0 ? ccp.LJoy.X * -1 : 0f);
                holder.SetValue(Inputs.ClassicControllerPro.LUP, ccp.LJoy.Y > 0 ? ccp.LJoy.Y : 0f);
                holder.SetValue(Inputs.ClassicControllerPro.LDOWN, ccp.LJoy.Y < 0 ? ccp.LJoy.Y * -1 : 0f);

                holder.SetValue(Inputs.ClassicControllerPro.RRIGHT, ccp.RJoy.X > 0 ? ccp.RJoy.X : 0f);
                holder.SetValue(Inputs.ClassicControllerPro.RLEFT, ccp.RJoy.X < 0 ? ccp.RJoy.X * -1 : 0f);
                holder.SetValue(Inputs.ClassicControllerPro.RUP, ccp.RJoy.Y > 0 ? ccp.RJoy.Y : 0f);
                holder.SetValue(Inputs.ClassicControllerPro.RDOWN, ccp.RJoy.Y < 0 ? ccp.RJoy.Y * -1 : 0f);
                #endregion
                break;

            case ControllerType.Guitar:
                #region Wii Guitar
                WiiGuitar wgt = (WiiGuitar)e.state;

                //SetWiimoteInputs(wgt.wiimote);

                holder.SetValue(Inputs.WiiGuitar.G, wgt.G);
                holder.SetValue(Inputs.WiiGuitar.R, wgt.R);
                holder.SetValue(Inputs.WiiGuitar.Y, wgt.Y);
                holder.SetValue(Inputs.WiiGuitar.B, wgt.B);
                holder.SetValue(Inputs.WiiGuitar.O, wgt.O);

                holder.SetValue(Inputs.WiiGuitar.UP, wgt.Up);
                holder.SetValue(Inputs.WiiGuitar.DOWN, wgt.Down);
                holder.SetValue(Inputs.WiiGuitar.LEFT, wgt.Left);
                holder.SetValue(Inputs.WiiGuitar.RIGHT, wgt.Right);

                holder.SetValue(Inputs.WiiGuitar.WHAMMYHIGH, wgt.WhammyHigh);
                holder.SetValue(Inputs.WiiGuitar.WHAMMYLOW, wgt.WhammyLow);

                holder.SetValue(Inputs.WiiGuitar.TILTHIGH, wgt.TiltHigh);
                holder.SetValue(Inputs.WiiGuitar.TILTLOW, wgt.TiltLow);

                holder.SetValue(Inputs.WiiGuitar.START, wgt.Start);
                holder.SetValue(Inputs.WiiGuitar.SELECT, wgt.Select);
                #endregion
                break;

            case ControllerType.Drums:
                #region Wii Drums
                WiiDrums wdr = (WiiDrums)e.state;

                holder.SetValue(Inputs.WiiDrums.G, wdr.G);
                holder.SetValue(Inputs.WiiDrums.R, wdr.R);
                holder.SetValue(Inputs.WiiDrums.Y, wdr.Y);
                holder.SetValue(Inputs.WiiDrums.B, wdr.B);
                holder.SetValue(Inputs.WiiDrums.O, wdr.O);
                holder.SetValue(Inputs.WiiDrums.BASS, wdr.Bass);

                holder.SetValue(Inputs.WiiDrums.UP, wdr.Up);
                holder.SetValue(Inputs.WiiDrums.DOWN, wdr.Down);
                holder.SetValue(Inputs.WiiDrums.LEFT, wdr.Left);
                holder.SetValue(Inputs.WiiDrums.RIGHT, wdr.Right);

                holder.SetValue(Inputs.WiiDrums.START, wdr.Start);
                holder.SetValue(Inputs.WiiDrums.SELECT, wdr.Select);
                #endregion
                break;
            }

            holder.Update();

            // Resumes the timer in case this method is not called withing 100ms
            if (updateTimer != null)
            {
                updateTimer.Change(100, UPDATE_SPEED);
            }
        }