Beispiel #1
0
        private static void HandleKeyInputEvent(KeyInputEvent keyInputEvent)
        {
            var manager = GlobalManager.GetManager <KeyInputManager>();

            switch ((KeyInputEvent.Events)keyInputEvent.Action)
            {
            case KeyInputEvent.Events.KeyPressDown:
                manager.SetKeyPressDown((EventKeyPressDown)keyInputEvent);
                break;

            case KeyInputEvent.Events.KeyPressUp:
                manager.SetKeyPressUp((EventKeyPressUp)keyInputEvent);
                break;

            default:
                throw new ArgumentOutOfRangeException(string.Format("KeyInputEvent '{0}' is not handled in the EventDispatcher.", keyInputEvent.Action));
            }
        }
Beispiel #2
0
        public virtual void ReadPage(IPage page)
        {
            if (page is KeyInputEvent)
            {
                KeyInputEvent keyEvent = page as KeyInputEvent;
                if (keyEvent.BindKey.ToString() == JoystickID + "TopFace")
                {
                    if (OnTopButton != null)
                    {
                        OnTopButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "LeftFace")
                {
                    if (OnLeftButton != null)
                    {
                        OnLeftButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "RightFace")
                {
                    if (OnRightButton != null)
                    {
                        OnRightButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "BottomFace")
                {
                    if (OnBottomButton != null)
                    {
                        OnBottomButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "LeftBump")
                {
                    if (OnLeftBumper != null)
                    {
                        OnLeftBumper.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "RightBump")
                {
                    if (OnRightBumper != null)
                    {
                        OnRightBumper.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "Start")
                {
                    if (OnStart != null)
                    {
                        OnStart.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "Select")
                {
                    if (OnSelect != null)
                    {
                        OnSelect.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "Home")
                {
                    if (OnHome != null)
                    {
                        OnHome.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "LeftAnalogClick")
                {
                    if (OnLeftAnalogButton != null)
                    {
                        OnLeftAnalogButton.Invoke(keyEvent.KeyHitState);
                    }
                }
                if (keyEvent.BindKey.ToString() == JoystickID + "RightAnalogClick")
                {
                    if (OnRightAnalogButton != null)
                    {
                        OnRightAnalogButton.Invoke(keyEvent.KeyHitState);
                    }
                }

                {
                    // handle customs
                    foreach (KeyValuePair <string, KeyBind> pair in LayoutMap.CustomKeyBind.D)
                    {
                        if (keyEvent.BindKey.ToString() == JoystickID + pair.Key)
                        {
                            if (OnCustomKey != null)
                            {
                                OnCustomKey.Invoke(pair.Key, keyEvent.KeyHitState);
                            }
                        }
                    }
                }
            }
            else if (page is AxisInputEvent)
            {
                AxisInputEvent AxisEvent = page as AxisInputEvent;
                if (AxisEvent.BindKey.ToString() == JoystickID + "LeftAnalog")
                {
                    if (OnLeftAnalog != null)
                    {
                        OnLeftAnalog.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.LeftAnalogAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.LeftAnalogAxisY]));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "RightAnalog")
                {
                    if (OnRightAnalog != null)
                    {
                        OnRightAnalog.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.RightAnalogAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.RightAnalogAxisY]));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "DPad")
                {
                    if (OnDPad != null)
                    {
                        OnDPad.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.DirectionAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.DirectionAxisY]));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "LeftTrigger")
                {
                    if (OnLeftTrigger != null)
                    {
                        OnLeftTrigger.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.LeftTriggerAxis], 0.0f));
                    }
                }
                else if (AxisEvent.BindKey.ToString() == JoystickID + "RightTrigger")
                {
                    if (OnRightTrigger != null)
                    {
                        OnRightTrigger.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.RightTriggerAxis], 0.0f));
                    }
                }
                else
                {
                    // handle customs
                    foreach (KeyValuePair <string, AxisBind> pair in LayoutMap.CustomAxisBind.D)
                    {
                        if (AxisEvent.BindKey.ToString() == JoystickID + pair.Key)
                        {
                            if (OnCustomAxis != null)
                            {
                                OnCustomAxis.Invoke(pair.Key, new Vector2(AxisEvent.AxisMap[JoystickID + pair.Value.PlatformAxisID], 0.0f));
                            }
                        }
                    }
                }
            }
        }