Ejemplo n.º 1
0
 public XInputButton(GamepadButtonFlags f)
 {
     ButtonFlag = f;
     IsAnalog   = false;
     Index      = ButtonFlag == 0 ? 0 : (int)Math.Pow(2, 1.0 / (int)ButtonFlag);
     Name       = f.ToString();
 }
Ejemplo n.º 2
0
        public JoystickButtonTrigger(Core coordinator, XmlNode node)
            : base(coordinator, GetName(node, "Joystick Button Trigger"))
        {
            GamepadButtonFlags b = GamepadButtonFlags.A;

            if (Enum.TryParse <GamepadButtonFlags>(GetString(node, mButton.ToString(), "Button"), out b))
            {
                mButton = b;
            }
        }
Ejemplo n.º 3
0
        private void HandleButton(GamepadButtonFlags buttonFlag, TextBox txt)
        {
            var button = new XInputButton
            {
                IsButton   = true,
                ButtonCode = (short)buttonFlag
            };

            txt.Text = buttonFlag.ToString();
            txt.Tag  = button;
        }
        void UpdateImage()
        {
            var name = GamepadButton.ToString();

            name = name.Replace("DPad", "D-Pad ");
            name = name.Replace("Shoulder", " Bumper");
            name = name.Replace("Thumb", " Stick Button");
            if (name.Length == 1)
            {
                name += " Button";
            }
            ButtonNameLabel.Text = name + ":";
            switch (GamepadButton)
            {
            case GamepadButtonFlags.A: enabledImage = Properties.Resources.Button_A; break;

            case GamepadButtonFlags.B: enabledImage = Properties.Resources.Button_B; break;

            case GamepadButtonFlags.X: enabledImage = Properties.Resources.Button_X; break;

            case GamepadButtonFlags.Y: enabledImage = Properties.Resources.Button_Y; break;

            case GamepadButtonFlags.Start: enabledImage = Properties.Resources.Button_Start; break;

            case GamepadButtonFlags.Back: enabledImage = Properties.Resources.Button_Back; break;

            case GamepadButtonFlags.DPadDown: enabledImage = Properties.Resources.Button_DPadDown; break;

            case GamepadButtonFlags.DPadLeft: enabledImage = Properties.Resources.Button_DPadLeft; break;

            case GamepadButtonFlags.DPadRight: enabledImage = Properties.Resources.Button_DPadRight; break;

            case GamepadButtonFlags.DPadUp: enabledImage = Properties.Resources.Button_DPadUp; break;

            case GamepadButtonFlags.LeftShoulder: enabledImage = Properties.Resources.Button_LeftShoulder; break;

            case GamepadButtonFlags.LeftThumb: enabledImage = Properties.Resources.Button_LeftThumb; break;

            case GamepadButtonFlags.RightShoulder: enabledImage = Properties.Resources.Button_RightShoulder; break;

            case GamepadButtonFlags.RightThumb: enabledImage = Properties.Resources.Button_RightThumb; break;

            default: enabledImage = null; break;
            }
            if (enabledImage != null)
            {
                disabledImage = AppHelper.GetDisabledImage(enabledImage);
            }
            ButtonImagePictureBox.BackgroundImage = ButtonImagePictureBox.Enabled ? enabledImage : disabledImage;
        }
Ejemplo n.º 5
0
        private Mapping GetMappingFor(GamepadButtonFlags control)
        {
            Mapping temp = null;

            foreach (Mapping m in _controlMapping)
            {
                if (m.Control.ToString() == control.ToString())
                {
                    temp = m;
                }
            }

            return(temp);
        }
Ejemplo n.º 6
0
        //Returns pressed button as a string
        public string getPressedButton(GamepadButtonFlags e)
        {
            string buttons = e.ToString();

            //Get the first button
            int index = buttons.IndexOf(',');

            if (buttons.Contains(","))
            {
                if (index > 0)
                {
                    return(buttons.Substring(0, index));
                }
                return(null);
            }
            return(buttons);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 读取方向键信息
        /// </summary>
        /// <returns></returns>
        public void GetDirection(out float tLeft, out float tRight, out mypoint pLeft, out mypoint pRight, out string returnFlag)
        {
            pLeft  = new mypoint(0, 0);
            pRight = new mypoint(0, 0);
            if (!controller.IsConnected)
            {
                returnFlag = null;
            }
            gamepad = controller.GetState().Gamepad;

            leftThumb.X  = (Math.Abs((float)gamepad.LeftThumbX) < deadband) ? 0 : (float)gamepad.LeftThumbX / short.MinValue * -100;
            leftThumb.Y  = (Math.Abs((float)gamepad.LeftThumbY) < deadband) ? 0 : (float)gamepad.LeftThumbY / short.MaxValue * 100;
            rightThumb.Y = (Math.Abs((float)gamepad.RightThumbX) < deadband) ? 0 : (float)gamepad.RightThumbX / short.MinValue * -100;
            rightThumb.X = (Math.Abs((float)gamepad.RightThumbY) < deadband) ? 0 : (float)gamepad.RightThumbY / short.MaxValue * 100;
            pLeft        = leftThumb;
            pRight       = rightThumb;
            leftTrigger  = (float)Math.Ceiling((float)gamepad.LeftTrigger / 256 * 90);
            rightTrigger = (float)Math.Ceiling((float)gamepad.RightTrigger / 256 * 90);
            tLeft        = leftTrigger;
            tRight       = rightTrigger;


            GamepadButtonFlags flag = gamepad.Buttons;
            int resultStart         = ((int)flag) & 0x10;
            int resultBack          = ((int)flag) & 0x20;
            int resultUp            = ((int)flag) & 0x01;
            int resultDown          = ((int)flag) & 0x02;
            int resultLeft          = ((int)flag) & 0x04;
            int resultRight         = ((int)flag) & 0x08;
            int resultLS            = ((int)flag) & 0x40;
            int resultRS            = ((int)flag) & 0x80;
            int resultLB            = ((int)flag) & 0x100;
            int resultRB            = ((int)flag) & 0x200;
            int resultA             = ((int)flag) & 0x1000;
            int resultB             = ((int)flag) & 0x2000;
            int resultX             = ((int)flag) & 0x4000;
            int resultY             = ((int)flag) & 0x8000;

            // int result
            if (resultStart != 0)
            {
                returnFlag = "start";
            }
            else if (resultBack != 0)
            {
                returnFlag = "back";
            }
            else if (resultUp != 0)
            {
                returnFlag = "up";
            }
            else if (resultDown != 0)
            {
                returnFlag = "down";
            }
            else if (resultLeft != 0)
            {
                returnFlag = "left";
            }
            else if (resultRight != 0)
            {
                returnFlag = "right";
            }
            else if (resultLS != 0)
            {
                returnFlag = "LS";
            }
            else if (resultRS != 0)
            {
                returnFlag = "RS";
            }
            else if (resultLB != 0)
            {
                returnFlag = "OL";
            }
            else if (resultRB != 0)
            {
                returnFlag = "OR";
            }
            else if (resultA != 0)
            {
                returnFlag = "sa";
            }
            else if (resultB != 0)
            {
                returnFlag = "sr";
            }
            else if (resultX != 0)
            {
                returnFlag = "st";
            }
            else if (resultY != 0)
            {
                returnFlag = "li";
            }
            else
            {
                returnFlag = flag.ToString();
            }
        }