Beispiel #1
0
        private void changeBtn_Click(object sender, EventArgs e)
        {
            if (buttonMappings.SelectedItem == null)
                return;

            var item = buttonMappings.SelectedItem as DeviceMappingItem;
            var cmf = new ChangeMappingDialog(mainForm, item.Mapping.Pad, item.Mapping.Source, item.Mapping.Gesture, item.Mapping.Destination);
            cmf.ShowDialog(this);

            if (cmf.DialogResult == DialogResult.OK) {
                bool isButton = item.Mapping.Source.StartsWith("button:");

                item.Mapping.Destination = cmf.Destination;
                if (isButton) item.Mapping.Gesture = cmf.Gesture;
                else item.Mapping.Gesture = "";

                if (isButton) {
                    int btn = int.Parse(item.Mapping.Source.Substring("button:".Length));
                    VirtualController.Button b = (VirtualController.Button)Enum.Parse(typeof(VirtualController.Button), cmf.Destination);
                    var ba = new VirtualController.ButtonAction(controller.Virtual, b);

                    if (cmf.Gesture != "Link" && cmf.Gesture != "" && cmf.Gesture != null) {
                        // We need to enable gesture support at the device level for this button
                        controller.Device.Buttons[btn].EnableGestures = true;
                    }

                    switch (cmf.Gesture) {
                        case "Link":
                        case null:
                        case "":
                            controller.Device.Buttons[btn].Link = ba;
                            break;
                        case "Tap":
                            controller.Device.Buttons[btn].Tap = ba;
                            break;
                        case "DoubleTap":
                            controller.Device.Buttons[btn].DoubleTap = ba;
                            break;
                        case "Hold":
                            controller.Device.Buttons[btn].Hold = ba;
                            break;
                    }
                } else {
                    int axis = int.Parse(item.Mapping.Source.Substring("axis:".Length));
                    VirtualController.Axis a = (VirtualController.Axis)Enum.Parse(typeof(VirtualController.Axis), cmf.Destination);
                    controller.Device.Axes[axis].Analog = new VirtualController.AxisAction(controller.Virtual, a);
                }

                mainForm.GlobalConfig.Save();
                RefreshDeviceMappings();
            }
        }
Beispiel #2
0
        private void startBtn_Click(object sender, EventArgs e)
        {
            if (page == 1) {
                page = 2;
                page2.BringToFront();
                pbar.Visible = true;
                startBtn.Enabled = false;
                startBtn.Text = "Finish";
                ButtonSpot[] buttonSpots = new[] {
                    new ButtonSpot(VirtualController.Button.Bl, 70, 119),
                    new ButtonSpot(VirtualController.Button.Br, 199, 119),
                    new ButtonSpot(VirtualController.Button.Tl, 70, 91),
                    new ButtonSpot(VirtualController.Button.Tr, 199, 91),
                    new ButtonSpot(VirtualController.Button.A, 204, 86),
                    new ButtonSpot(VirtualController.Button.B, 222, 67),
                    new ButtonSpot(VirtualController.Button.X, 185, 67),
                    new ButtonSpot(VirtualController.Button.Y, 204, 49),
                    new ButtonSpot(VirtualController.Button.Start, 160, 69),
                    new ButtonSpot(VirtualController.Button.Back, 110, 69),
                    new ButtonSpot(VirtualController.Button.System, 135, 69),
                    new ButtonSpot(VirtualController.Button.LeftAnalog, 67, 67),
                    new ButtonSpot(VirtualController.Button.RightAnalog, 167, 107),
                };

                AxisSpot[] axisSpots = new[] {
                    new AxisSpot(VirtualController.Axis.Trigger, 70, 91),
                    new AxisSpot(VirtualController.Axis.LeftY, 67, 53),
                    new AxisSpot(VirtualController.Axis.LeftX, 52, 65),
                    new AxisSpot(VirtualController.Axis.DigitalY, 99, 94),
                    new AxisSpot(VirtualController.Axis.DigitalX, 85, 108),
                    new AxisSpot(VirtualController.Axis.RightY, 167, 94),
                    new AxisSpot(VirtualController.Axis.RightX, 154, 107),
                };

                // Adjust by the design-time location of the image...
                var pos = new Point(13, 25);

                foreach (var spot in buttonSpots) {
                    spot.X -= pos.X;
                    spot.Y -= pos.Y;
                }

                foreach (var spot in axisSpots) {
                    spot.X -= pos.X;
                    spot.Y -= pos.Y;
                }

                front.Hide();
                remainingBtnSpots = new List<ButtonSpot>();
                remainingBtnSpots.AddRange(buttonSpots);
                remainingAxisSpots = new List<AxisSpot>();
                remainingAxisSpots.AddRange(axisSpots);

                foreach (var btn in Controller.Device.Buttons)
                    btn.PressReceived += buttonPressed;

                foreach (var axis in Controller.Device.Axes) {
                    axis.EnableGestures = true;
                    axis.PositivePress += axisPressed;
                    axis.NegativePress += axisPressed;
                }

                Controller.Virtual.Enabled = false;

                indicator.Tag = "on";
                indicator.Location = new Point(front.Left + remainingBtnSpots[0].X, front.Top + remainingBtnSpots[0].Y);

                progress.Text += " - Product: " + Controller.Device.ProductName + "\n";
                noHaveBtn.Enabled = true;
            } else {
                Controller.Virtual.Enabled = true;

                foreach (var btn in Controller.Device.Buttons)
                    btn.PressReceived -= buttonPressed;

                foreach (var axis in Controller.Device.Axes) {
                    axis.EnableGestures = false;
                    axis.PositivePress -= axisPressed;
                    axis.NegativePress -= axisPressed;
                }

                GamepadConfig gpc = new GamepadConfig();
                string deviceID = Controller.Device.VendorID.ToString("X4") + Controller.Device.ProductID.ToString("X4");
                gpc.DeviceID = "0x" + deviceID.ToLower();
                gpc.Mappings = mappings;
                gpc.Notes = "Created by Pad Tie's Mapping Wizard!";
                gpc.Product = Controller.Device.ProductName;
                gpc.Vendor = "";
                var myModcumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var gpcFolder = Path.Combine("Pad Tie", "gamepads");
                string fileName = Path.Combine(Path.Combine(myModcumentsFolder, gpcFolder), gpc.DeviceID + ".xml");

                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));

                if (File.Exists(fileName)) {
                    fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "gamepads");
                    fileName = Path.Combine(fileName, gpc.DeviceID + "-autogen.xml");
                }

                try {
                    gpc.Save(fileName);
                } catch (UnauthorizedAccessException e2) {
                    MessageBox.Show("Failed to save mapping for later use. Your gamepad will still work. Message: " + e2.Message);
                }

                if (sendPermission.Checked) {
                    SendConfig(gpc, fileName);
                }

                Controller.DeviceConfig.Mappings = gpc.Mappings;
                //Controller.Device.Reset();

                foreach (var dm in gpc.Mappings) {
                    if (dm.Source.StartsWith("button:")) {
                        int btn = int.Parse(dm.Source.Substring("button:".Length));
                        VirtualController.Button b = (VirtualController.Button)Enum.Parse(typeof(VirtualController.Button), dm.Destination);
                        var ba = new VirtualController.ButtonAction(Controller.Virtual, b);

                        if (dm.Gesture != "Link" && dm.Gesture != "" && dm.Gesture != null) {
                            // We need to enable gesture support at the device level for this button
                            Controller.Device.Buttons[btn].EnableGestures = true;
                        }

                        switch (dm.Gesture) {
                            case "Link":
                            case null:
                            case "":
                                Controller.Device.Buttons[btn].Link = ba;
                                break;
                            case "Tap":
                                Controller.Device.Buttons[btn].Tap = ba;
                                break;
                            case "DoubleTap":
                                Controller.Device.Buttons[btn].DoubleTap = ba;
                                break;
                            case "Hold":
                                Controller.Device.Buttons[btn].Hold = ba;
                                break;
                        }
                    } else {
                        int axis = int.Parse(dm.Source.Substring("axis:".Length));
                        VirtualController.Axis a = (VirtualController.Axis)Enum.Parse(typeof(VirtualController.Axis), dm.Destination);
                        Controller.Device.Axes[axis].Analog = new VirtualController.AxisAction(Controller.Virtual, a);
                    }
                }
                MainForm.GlobalConfig.Save();
                this.Close();
            }
        }