Пример #1
0
        public bool processWiimoteState(WiimoteState wiimoteState) //Returns true if anything has changed from last report.
        {
            ButtonState buttonState = wiimoteState.ButtonState;
            bool        significant = false;

            foreach (IOutputHandler handler in outputHandlers)
            {
                handler.startUpdate();
            }

            CursorPos cursorPos = this.screenPositionCalculator.CalculateCursorPos(wiimoteState);

            this.KeyMap.updateCursorPosition(cursorPos);
            this.KeyMap.updateAccelerometer(wiimoteState.AccelState);

            if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.Nunchuk)
            {
                this.KeyMap.updateNunchuk(wiimoteState.NunchukState);

                if (wiimoteState.NunchukState.C && !PressedButtons["Nunchuk.C"])
                {
                    PressedButtons["Nunchuk.C"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.C);
                }
                else if (!wiimoteState.NunchukState.C && PressedButtons["Nunchuk.C"])
                {
                    PressedButtons["Nunchuk.C"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.C);
                }

                if (wiimoteState.NunchukState.Z && !PressedButtons["Nunchuk.Z"])
                {
                    PressedButtons["Nunchuk.Z"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.Z);
                }
                else if (!wiimoteState.NunchukState.Z && PressedButtons["Nunchuk.Z"])
                {
                    PressedButtons["Nunchuk.Z"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.Z);
                }
            }

            if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.ClassicController)
            {
                this.KeyMap.updateClassicController(wiimoteState.ClassicControllerState);

                ClassicControllerButtonState classicButtonState = wiimoteState.ClassicControllerState.ButtonState;

                FieldInfo[] cbuttons = classicButtonState.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
                foreach (FieldInfo button in cbuttons)
                {
                    string buttonName = "Classic." + button.Name;
                    if (button.Name == "TriggerL")
                    {
                        buttonName = "Classic.L";
                    }
                    else if (button.Name == "TriggerR")
                    {
                        buttonName = "Classic.R";
                    }

                    bool pressedNow    = (bool)button.GetValue(classicButtonState);
                    bool pressedBefore = PressedButtons[buttonName];

                    if (pressedNow && !pressedBefore)
                    {
                        PressedButtons[buttonName] = true;
                        significant = true;
                        this.KeyMap.executeButtonDown(buttonName);
                    }
                    else if (!pressedNow && pressedBefore)
                    {
                        PressedButtons[buttonName] = false;
                        significant = true;
                        this.KeyMap.executeButtonUp(buttonName);
                    }
                }
            }

            if (this.releaseHomeOnNextUpdate)
            {
                this.releaseHomeOnNextUpdate = false;
                this.KeyMap.executeButtonUp("Home");
            }

            FieldInfo[] buttons = buttonState.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (FieldInfo button in buttons)
            {
                bool pressedNow    = (bool)button.GetValue(buttonState);
                bool pressedBefore = PressedButtons[button.Name];

                if (pressedNow && !pressedBefore)
                {
                    PressedButtons[button.Name] = true;
                    significant = true;
                    if (button.Name == "Home")
                    {
                        this.homeButtonTimer.Start();
                        if (OverlayWindow.Current.OverlayIsOn())
                        {
                            this.hideOverlayOnUp = true;
                        }
                    }
                    else
                    {
                        this.KeyMap.executeButtonDown(button.Name);
                    }
                }
                else if (!pressedNow && pressedBefore)
                {
                    PressedButtons[button.Name] = false;
                    significant = true;
                    if (button.Name == "Home")
                    {
                        this.homeButtonTimer.Stop();

                        if (this.hideOverlayOnUp)
                        {
                            this.hideOverlayOnUp = false;
                            OverlayWindow.Current.HideOverlay();
                        }
                        else if (OverlayWindow.Current.OverlayIsOn())
                        {
                        }
                        else
                        {
                            this.KeyMap.executeButtonDown("Home");
                            this.releaseHomeOnNextUpdate = true;
                        }
                    }
                    else
                    {
                        this.KeyMap.executeButtonUp(button.Name);
                    }
                }
            }

            foreach (IOutputHandler handler in outputHandlers)
            {
                handler.endUpdate();
            }


            return(significant);
        }
Пример #2
0
        public bool processWiimoteState(WiimoteState wiimoteState) //Returns true if anything has changed from last report.
        {
            ButtonState buttonState = wiimoteState.ButtonState;
            bool        significant = false;

            this.KeyMap.updateAccelerometer(wiimoteState.AccelState);

            if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.Nunchuk)
            {
                this.KeyMap.updateNunchuk(wiimoteState.NunchukState);

                if (wiimoteState.NunchukState.C && !PressedButtons["Nunchuk.C"])
                {
                    PressedButtons["Nunchuk.C"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.C);
                }
                else if (!wiimoteState.NunchukState.C && PressedButtons["Nunchuk.C"])
                {
                    PressedButtons["Nunchuk.C"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.C);
                }

                if (wiimoteState.NunchukState.Z && !PressedButtons["Nunchuk.Z"])
                {
                    PressedButtons["Nunchuk.Z"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.Z);
                }
                else if (!wiimoteState.NunchukState.Z && PressedButtons["Nunchuk.Z"])
                {
                    PressedButtons["Nunchuk.Z"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.Z);
                }

                if (wiimoteState.NunchukState.Joystick.Y > 0.3 && !PressedButtons["Nunchuk.StickUp"])
                {
                    PressedButtons["Nunchuk.StickUp"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickUp);
                }
                else if (wiimoteState.NunchukState.Joystick.Y < 0.3 && PressedButtons["Nunchuk.StickUp"])
                {
                    PressedButtons["Nunchuk.StickUp"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickUp);
                }

                if (wiimoteState.NunchukState.Joystick.Y < -0.3 && !PressedButtons["Nunchuk.StickDown"])
                {
                    PressedButtons["Nunchuk.StickDown"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickDown);
                }
                else if (wiimoteState.NunchukState.Joystick.Y > -0.3 && PressedButtons["Nunchuk.StickDown"])
                {
                    PressedButtons["Nunchuk.StickDown"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickDown);
                }

                if (wiimoteState.NunchukState.Joystick.X < -0.3 && !PressedButtons["Nunchuk.StickLeft"])
                {
                    PressedButtons["Nunchuk.StickLeft"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickLeft);
                }
                else if (wiimoteState.NunchukState.Joystick.X > -0.3 && PressedButtons["Nunchuk.StickLeft"])
                {
                    PressedButtons["Nunchuk.StickLeft"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickLeft);
                }
                if (wiimoteState.NunchukState.Joystick.X > 0.3 && !PressedButtons["Nunchuk.StickRight"])
                {
                    PressedButtons["Nunchuk.StickRight"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(NunchukButton.StickRight);
                }
                else if (wiimoteState.NunchukState.Joystick.X < 0.3 && PressedButtons["Nunchuk.StickRight"])
                {
                    PressedButtons["Nunchuk.StickRight"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(NunchukButton.StickRight);
                }
            }

            if (wiimoteState.Extension && wiimoteState.ExtensionType == ExtensionType.ClassicController)
            {
                this.KeyMap.updateClassicController(wiimoteState.ClassicControllerState);

                ClassicControllerButtonState classicButtonState = wiimoteState.ClassicControllerState.ButtonState;

                FieldInfo[] cbuttons = classicButtonState.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
                foreach (FieldInfo button in cbuttons)
                {
                    string buttonName = "Classic." + button.Name;
                    if (button.Name == "TriggerL")
                    {
                        buttonName = "Classic.L";
                    }
                    else if (button.Name == "TriggerR")
                    {
                        buttonName = "Classic.R";
                    }

                    bool pressedNow    = (bool)button.GetValue(classicButtonState);
                    bool pressedBefore = PressedButtons[buttonName];

                    if (pressedNow && !pressedBefore)
                    {
                        PressedButtons[buttonName] = true;
                        significant = true;
                        this.KeyMap.executeButtonDown(buttonName);
                    }
                    else if (!pressedNow && pressedBefore)
                    {
                        PressedButtons[buttonName] = false;
                        significant = true;
                        this.KeyMap.executeButtonUp(buttonName);
                    }
                }
                if (wiimoteState.ClassicControllerState.JoystickL.Y > 0.3 && !PressedButtons["Classic.StickLUp"])
                {
                    PressedButtons["Classic.StickLUp"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLUp);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y < 0.3 && PressedButtons["Classic.StickLUp"])
                {
                    PressedButtons["Classic.StickLUp"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLUp);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.Y < -0.3 && !PressedButtons["Classic.StickLDown"])
                {
                    PressedButtons["Classic.StickLDown"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLDown);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y > -0.3 && PressedButtons["Classic.StickLDown"])
                {
                    PressedButtons["Classic.StickLDown"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLDown);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.X < -0.3 && !PressedButtons["Classic.StickLLeft"])
                {
                    PressedButtons["Classic.StickLLeft"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLLeft);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X > -0.3 && PressedButtons["Classic.StickLLeft"])
                {
                    PressedButtons["Classic.StickLLeft"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLLeft);
                }
                if (wiimoteState.ClassicControllerState.JoystickL.X > 0.3 && !PressedButtons["Classic.StickLRight"])
                {
                    PressedButtons["Classic.StickLRight"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickLRight);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X < 0.3 && PressedButtons["Classic.StickLRight"])
                {
                    PressedButtons["Classic.StickLRight"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickLRight);
                }
                if (wiimoteState.ClassicControllerState.JoystickL.Y > 0.3 && !PressedButtons["Classic.StickLUp"])
                {
                    PressedButtons["Classic.StickRUp"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRUp);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y < 0.3 && PressedButtons["Classic.StickRUp"])
                {
                    PressedButtons["Classic.StickRUp"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRUp);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.Y < -0.3 && !PressedButtons["Classic.StickRDown"])
                {
                    PressedButtons["Classic.StickRDown"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRDown);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.Y > -0.3 && PressedButtons["Classic.StickRDown"])
                {
                    PressedButtons["Classic.StickRDown"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRDown);
                }

                if (wiimoteState.ClassicControllerState.JoystickL.X < -0.3 && !PressedButtons["Classic.StickRLeft"])
                {
                    PressedButtons["Classic.StickRLeft"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRLeft);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X > -0.3 && PressedButtons["Classic.StickRLeft"])
                {
                    PressedButtons["Classic.StickRLeft"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRLeft);
                }
                if (wiimoteState.ClassicControllerState.JoystickL.X > 0.3 && !PressedButtons["Classic.StickRRight"])
                {
                    PressedButtons["Classic.StickRRight"] = true;
                    significant = true;
                    this.KeyMap.executeButtonDown(ClassicControllerButton.StickRRight);
                }
                else if (wiimoteState.ClassicControllerState.JoystickL.X < 0.3 && PressedButtons["Classic.StickRRight"])
                {
                    PressedButtons["Classic.StickRRight"] = false;
                    significant = true;
                    this.KeyMap.executeButtonUp(ClassicControllerButton.StickRRight);
                }
            }

            FieldInfo[] buttons = buttonState.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
            foreach (FieldInfo button in buttons)
            {
                bool pressedNow    = (bool)button.GetValue(buttonState);
                bool pressedBefore = PressedButtons[button.Name];

                if (pressedNow && !pressedBefore)
                {
                    PressedButtons[button.Name] = true;
                    significant = true;
                    if (button.Name == "Home")
                    {
                        this.homeButtonTimer.Start();
                        if (OverlayWindow.Current.OverlayIsOn())
                        {
                            this.hideOverlayOnUp = true;
                        }
                    }
                    else
                    {
                        this.KeyMap.executeButtonDown(button.Name);
                    }
                }
                else if (!pressedNow && pressedBefore)
                {
                    PressedButtons[button.Name] = false;
                    significant = true;
                    if (button.Name == "Home")
                    {
                        this.homeButtonTimer.Stop();

                        if (this.hideOverlayOnUp)
                        {
                            this.hideOverlayOnUp = false;
                            OverlayWindow.Current.HideOverlay();
                        }
                        else if (OverlayWindow.Current.OverlayIsOn())
                        {
                        }
                        else
                        {
                            this.KeyMap.executeButtonDown("Home");
                            this.KeyMap.executeButtonUp("Home");
                        }
                    }
                    else
                    {
                        this.KeyMap.executeButtonUp(button.Name);
                    }
                }
            }

            this.KeyMap.XinputDevice.Update(this.KeyMap.XinputReport);

            return(significant);
        }