コード例 #1
0
        void CurvitureSelectionChanged(object sender, EventArgs e)
        {
            TextBox cx   = (TextBox)sender;
            int     indx = Convert.ToInt32(cx.Name.Replace("txrlsacv", ""));
            Bind    cr   = MainStructure.GetBindForRelation(CURRENTDISPLAYEDRELATION[indx].NAME);

            if (cr == null)
            {
                if (cx.Text.Length > 0)
                {
                    MessageBox.Show("Please set first the button or the axis.");
                }
                else
                {
                    MainStructure.ResyncRelations();
                }
                return;
            }
            if (cx.Text.Length < 1 || cx.Text.Replace(" ", "") == ".")
            {
                return;
            }
            double curv    = double.NaN;
            string cleaned = cx.Text.Replace(',', '.');
            bool   succ    = false;

            try
            {
                curv = Convert.ToDouble(cleaned, System.Globalization.CultureInfo.InvariantCulture);
                succ = true;
            }
            catch
            {
                MessageBox.Show("Given Curviture not a valid double");
            }
            if (succ == true)
            {
                if (cr.Curviture.Count > 0)
                {
                    cr.Curviture[0] = curv;
                }
                else
                {
                    cr.Curviture.Add(curv);
                }
            }
        }
コード例 #2
0
        void modSet(object sender, EventArgs e)
        {
            ActivateInputs();
            int indx = buttonSetting;

            buttonSetting = -1;
            Bind cr = MainStructure.GetBindForRelation(CURRENTDISPLAYEDRELATION[indx].NAME);

            if (joyReader == null || cr == null)
            {
                MessageBox.Show("Something went wrong when setting a modifier. Either listener was not started correctly or the main button was not assigend beforehand.");
                return;
            }
            if (modToEdit != "None" && modToEdit.Length > 0)
            {
                cr.deleteReformer(modToEdit);
                modToEdit = "";
            }
            if (joyReader.result == null)
            {
                MainStructure.ResyncRelations();
                return;
            }
            string device;

            if (joyReader.result.Device == "Keyboard")
            {
                device = "Keyboard";
            }
            else
            {
                device = "m" + joyReader.result.Device.Split('{')[1].Split('}')[0].GetHashCode().ToString().Substring(0, 5);
            }
            string nameToShow   = device + joyReader.result.AxisButton;
            string moddedDevice = cr.JoystickGuidToModifierGuid(joyReader.result.Device);
            string toAdd        = nameToShow + "§" + moddedDevice + "§" + joyReader.result.AxisButton;

            if (!cr.AllReformers.Contains(toAdd))
            {
                cr.AllReformers.Add(toAdd);
            }
            MainStructure.ResyncRelations();
        }
コード例 #3
0
        void AxisSet(object sender, EventArgs e)
        {
            ActivateInputs();
            int indx = buttonSetting;

            buttonSetting            = -1;
            setBtns[indx].Background = Brushes.White;
            if (e == null)
            {
                setBtns[indx].Content     = "None";
                stickLabels[indx].Content = "None";
                return;
            }
            Bind cr = MainStructure.GetBindForRelation(CURRENTDISPLAYEDRELATION[indx].NAME);

            if (cr == null)
            {
                cr = new Bind(CURRENTDISPLAYEDRELATION[indx]);
                MainStructure.AddBind(cr.Rl.NAME, cr);
            }
            if (joyReader == null)
            {
                MessageBox.Show("Something went wrong. Joyreader is null try again.");
                return;
            }
            if (joyReader.result == null)
            {
                //Delete Bind
                MainStructure.DeleteBind(cr.Rl.NAME);
                MainStructure.ResyncRelations();
                return;
            }
            cr.Joystick               = joyReader.result.Device;
            cr.JAxis                  = joyReader.result.AxisButton;
            setBtns[indx].Content     = joyReader.result.AxisButton;
            stickLabels[indx].Content = joyReader.result.Device;
            joyReader                 = null;
            Console.WriteLine(setBtns[indx].Content);
        }
コード例 #4
0
ファイル: Bind.cs プロジェクト: vonbane/JoystickProfiler
        public static Bind GetBindFromAxisElement(DCSAxisBind dab, string id, string joystick, string plane, bool inv = false, bool slid = false, bool curv = false, bool dz = false, bool sx = false, bool sy = false)
        {
            Relation r            = new Relation();
            Bind     b            = new Bind(r);
            string   shorten      = MainStructure.ShortenDeviceName(joystick);
            string   relationName = shorten + dab.key;

            r.ISAXIS   = true;
            b.JAxis    = dab.key;
            b.Joystick = joystick;
            if (dab.filter != null)
            {
                b.Inverted  = dab.filter.inverted;
                b.Curviture = dab.filter.curviture;
                if (b.Curviture == null)
                {
                    b.Curviture = new List <double>();
                }
                if (b.Curviture.Count < 1)
                {
                    b.Curviture.Add(0.0);
                }
                b.Deadzone    = dab.filter.deadzone;
                b.Slider      = dab.filter.slider;
                b.SaturationX = dab.filter.saturationX;
                b.SaturationY = dab.filter.saturationY;
            }
            else
            {
                b.Inverted  = false;
                b.Slider    = false;
                b.Curviture = new List <double>();
                b.Curviture.Add(0.0);
                b.SaturationX = 1.0;
                b.SaturationY = 1.0;
                b.Deadzone    = 0;
            }
            if (inv)
            {
                relationName = relationName + "i" + b.Inverted.ToString();
            }
            if (slid)
            {
                relationName = relationName + "s" + b.Slider.ToString();
            }
            if (curv && b.Curviture.Count > 0)
            {
                relationName = relationName + "c" + b.Curviture[0].ToString(new CultureInfo("en-US")).Substring(0, 4);
            }
            if (dz)
            {
                relationName = relationName + "d" + b.Deadzone.ToString(new CultureInfo("en-US")).Substring(0, 4);
            }
            if (sx)
            {
                relationName = relationName + "x" + b.SaturationX.ToString(new CultureInfo("en-US")).Substring(0, 4);
            }
            if (sy)
            {
                relationName = relationName + "y" + b.SaturationY.ToString(new CultureInfo("en-US")).Substring(0, 4);
            }
            r.NAME = relationName;
            r.AddNode(id, plane);
            return(b);
        }
コード例 #5
0
        void RefreshRelationsToShow()
        {
            Grid grid = BaseSetupRelationGrid();

            for (int i = 0; i < CURRENTDISPLAYEDRELATION.Count; i++)
            {
                Label lblName = new Label();
                lblName.Name                = "lblname" + i.ToString();
                lblName.Foreground          = Brushes.White;
                lblName.Content             = CURRENTDISPLAYEDRELATION[i].NAME;
                lblName.HorizontalAlignment = HorizontalAlignment.Center;
                lblName.VerticalAlignment   = VerticalAlignment.Center;
                Grid.SetColumn(lblName, 0);
                Grid.SetRow(lblName, i);
                grid.Children.Add(lblName);

                Button editBtn = new Button();
                editBtns[i]                 = editBtn;
                editBtn.Name                = "editBtn" + i.ToString();
                editBtn.Content             = "Edit";
                editBtn.Click              += new RoutedEventHandler(EditRelationButton);
                editBtn.HorizontalAlignment = HorizontalAlignment.Center;
                editBtn.VerticalAlignment   = VerticalAlignment.Center;
                editBtn.Width               = 50;
                Grid.SetColumn(editBtn, 1);
                Grid.SetRow(editBtn, i);
                grid.Children.Add(editBtn);

                Button deleteBtn = new Button();
                dltBtns[i]                    = deleteBtn;
                deleteBtn.Name                = "deleteBtn" + i.ToString();
                deleteBtn.Content             = "Delete Relation";
                deleteBtn.Click              += new RoutedEventHandler(DeleteRelationButton);
                deleteBtn.HorizontalAlignment = HorizontalAlignment.Center;
                deleteBtn.VerticalAlignment   = VerticalAlignment.Center;
                deleteBtn.Width               = 100;
                Grid.SetColumn(deleteBtn, 2);
                Grid.SetRow(deleteBtn, i);
                grid.Children.Add(deleteBtn);

                Bind currentBind = MainStructure.GetBindForRelation(CURRENTDISPLAYEDRELATION[i].NAME);

                Label joystickPick = new Label();
                joystickPick.Name       = "joyLbl" + i.ToString();
                joystickPick.Content    = "None";
                stickLabels[i]          = joystickPick;
                joystickPick.Foreground = Brushes.White;
                if (currentBind != null)
                {
                    joystickPick.Content = currentBind.Joystick;
                }
                joystickPick.Width = 500;
                joystickPick.HorizontalAlignment = HorizontalAlignment.Center;
                joystickPick.VerticalAlignment   = VerticalAlignment.Center;
                Grid.SetColumn(joystickPick, 3);
                Grid.SetRow(joystickPick, i);
                grid.Children.Add(joystickPick);

                Button joybtnin = new Button();
                joybtnin.Name                = "assignBtn" + i.ToString();
                joybtnin.Content             = "None";
                joybtnin.HorizontalAlignment = HorizontalAlignment.Center;
                joybtnin.VerticalAlignment   = VerticalAlignment.Center;
                joybtnin.Width               = 100;
                joybtnin.Click              += new RoutedEventHandler(SetBtnOrAxisEvent);
                setBtns[i] = joybtnin;
                Grid.SetColumn(joybtnin, 4);
                Grid.SetRow(joybtnin, i);
                grid.Children.Add(joybtnin);

                if (CURRENTDISPLAYEDRELATION[i].ISAXIS)
                {
                    CheckBox cbx = new CheckBox();
                    cbx.Name                = "cbxrel" + i.ToString();
                    cbx.Content             = "Inverted";
                    cbx.Foreground          = Brushes.White;
                    cbx.HorizontalAlignment = HorizontalAlignment.Center;
                    cbx.VerticalAlignment   = VerticalAlignment.Center;
                    Grid.SetColumn(cbx, 5);
                    Grid.SetRow(cbx, i);
                    grid.Children.Add(cbx);

                    CheckBox cbxs = new CheckBox();
                    cbxs.Name                = "cbxsrel" + i.ToString();
                    cbxs.Content             = "Slider";
                    cbxs.Foreground          = Brushes.White;
                    cbxs.HorizontalAlignment = HorizontalAlignment.Center;
                    cbxs.VerticalAlignment   = VerticalAlignment.Center;
                    Grid.SetColumn(cbxs, 6);
                    Grid.SetRow(cbxs, i);
                    grid.Children.Add(cbxs);

                    TextBox txrl = new TextBox();
                    txrl.Name   = "txrldz" + i.ToString();
                    txrl.Width  = 100;
                    txrl.Height = 24;
                    Grid.SetColumn(txrl, 7);
                    Grid.SetRow(txrl, i);
                    grid.Children.Add(txrl);

                    TextBox txrlsx = new TextBox();
                    txrlsx.Name   = "txrlsatx" + i.ToString();
                    txrlsx.Width  = 100;
                    txrlsx.Height = 24;
                    Grid.SetColumn(txrlsx, 8);
                    Grid.SetRow(txrlsx, i);
                    grid.Children.Add(txrlsx);

                    TextBox txrlsy = new TextBox();
                    txrlsy.Name   = "txrlsaty" + i.ToString();
                    txrlsy.Width  = 100;
                    txrlsy.Height = 24;
                    Grid.SetColumn(txrlsy, 9);
                    Grid.SetRow(txrlsy, i);
                    grid.Children.Add(txrlsy);

                    TextBox txrlcv = new TextBox();
                    txrlcv.Name   = "txrlsacv" + i.ToString();
                    txrlcv.Width  = 100;
                    txrlcv.Height = 24;
                    Grid.SetColumn(txrlcv, 10);
                    Grid.SetRow(txrlcv, i);
                    grid.Children.Add(txrlcv);

                    if (currentBind != null)
                    {
                        joybtnin.Content = currentBind.JAxis.ToString();
                        cbx.IsChecked    = currentBind.Inverted;
                        cbxs.IsChecked   = currentBind.Slider;
                        txrl.Text        = currentBind.Deadzone.ToString();
                        txrlsx.Text      = currentBind.SaturationX.ToString();
                        txrlsy.Text      = currentBind.SaturationY.ToString();
                        txrlcv.Text      = currentBind.Curviture[0].ToString();
                    }
                    else
                    {
                        txrl.Text   = "Deadzone (Dec)";
                        txrlsx.Text = "SatX (Dec)";
                        txrlsy.Text = "SatY (Dec)";
                        txrlcv.Text = "Curviture (Dec)";
                    }
                    txrlcv.TextChanged += new TextChangedEventHandler(CurvitureSelectionChanged);
                    txrlsy.TextChanged += new TextChangedEventHandler(SaturationYSelectionChanged);
                    txrlsx.TextChanged += new TextChangedEventHandler(SaturationXSelectionChanged);
                    txrl.TextChanged   += new TextChangedEventHandler(DeadzoneSelectionChanged);
                    cbxs.Click         += new RoutedEventHandler(SliderAxisSelection);
                    cbx.Click          += new RoutedEventHandler(InvertAxisSelection);

                    txrlcv.QueryCursor += new QueryCursorEventHandler(CleanText);
                    txrlsy.QueryCursor += new QueryCursorEventHandler(CleanText);
                    txrlsx.QueryCursor += new QueryCursorEventHandler(CleanText);
                    txrl.QueryCursor   += new QueryCursorEventHandler(CleanText);
                    txrlcv.QueryCursor += new QueryCursorEventHandler(CleanText);
                }
                else
                {
                    Button modBtn1 = new Button();
                    modBtn1.Name                = "modBtn1_" + i.ToString();
                    modBtn1.Content             = "None";
                    modBtn1.HorizontalAlignment = HorizontalAlignment.Center;
                    modBtn1.VerticalAlignment   = VerticalAlignment.Center;
                    modBtn1.Width               = 100;
                    modBtn1.Click              += new RoutedEventHandler(listenModBtn);
                    modBtns[1][i]               = modBtn1;
                    Grid.SetColumn(modBtn1, 7);
                    Grid.SetRow(modBtn1, i);
                    grid.Children.Add(modBtn1);

                    Button modBtn2 = new Button();
                    modBtn2.Name                = "modBtn2_" + i.ToString();
                    modBtn2.Content             = "None";
                    modBtn2.HorizontalAlignment = HorizontalAlignment.Center;
                    modBtn2.VerticalAlignment   = VerticalAlignment.Center;
                    modBtn2.Width               = 100;
                    modBtn2.Click              += new RoutedEventHandler(listenModBtn);
                    modBtns[2][i]               = modBtn2;
                    Grid.SetColumn(modBtn2, 8);
                    Grid.SetRow(modBtn2, i);
                    grid.Children.Add(modBtn2);

                    Button modBtn3 = new Button();
                    modBtn3.Name                = "modBtn3_" + i.ToString();
                    modBtn3.Content             = "None";
                    modBtn3.HorizontalAlignment = HorizontalAlignment.Center;
                    modBtn3.VerticalAlignment   = VerticalAlignment.Center;
                    modBtn3.Width               = 100;
                    modBtn3.Click              += new RoutedEventHandler(listenModBtn);
                    modBtns[3][i]               = modBtn3;
                    Grid.SetColumn(modBtn3, 9);
                    Grid.SetRow(modBtn3, i);
                    grid.Children.Add(modBtn3);

                    Button modBtn4 = new Button();
                    modBtn4.Name                = "modBtn4_" + i.ToString();
                    modBtn4.Content             = "None";
                    modBtn4.HorizontalAlignment = HorizontalAlignment.Center;
                    modBtn4.VerticalAlignment   = VerticalAlignment.Center;
                    modBtn4.Width               = 100;
                    modBtn4.Click              += new RoutedEventHandler(listenModBtn);
                    modBtns[4][i]               = modBtn4;
                    Grid.SetColumn(modBtn4, 10);
                    Grid.SetRow(modBtn4, i);
                    grid.Children.Add(modBtn4);

                    //Check against mod buttons needed
                    if (currentBind != null)
                    {
                        joybtnin.Content = currentBind.JButton;
                        modBtn1.Content  = currentBind.ModToDosplayString(1);
                        modBtn2.Content  = currentBind.ModToDosplayString(2);
                        modBtn3.Content  = currentBind.ModToDosplayString(3);
                        modBtn4.Content  = currentBind.ModToDosplayString(4);
                    }
                }
            }
            sv.Content = grid;
        }