Example #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            timeout += 1;
            if (timeout > 5000)
            {
                this.Close();
            }
            //Console.WriteLine(timeout);
            //state = controller.GetState();
            //GamepadButtonFlags = state.Gamepad.Buttons;

            //label1.Text = Convert.ToString(GamepadButtonFlags.HasFlag(GamepadButtonFlags.DPadUp));
            //label2.Text = Convert.ToString(GamepadButtonFlags.HasFlag(GamepadButtonFlags.DPadDown));

            GC.Collect();

            List <string> temp = new List <string>();

            for (int i = 0; i < buttton.Count; ++i)
            {
                temp.Add(buttton[i]);
            }

            pad.Checkstate(controller, stick);



            if (pad.Dleft)
            {
                if (!pad.Dup && !pad.Ddown)
                {
                    if (direction[0] != '←')
                    {
                        direction.Insert(0, '←');
                        direction.RemoveAt(direction.Count - 1);
                    }
                }
                else if (pad.Dup)
                {
                    if (direction[0] != '↖')
                    {
                        direction.Insert(0, '↖');
                        direction.RemoveAt(direction.Count - 1);
                    }
                }
                else
                {
                    if (direction[0] != '↙')
                    {
                        direction.Insert(0, '↙');
                        direction.RemoveAt(direction.Count - 1);
                    }
                }
            }
            else if (pad.Dright)
            {
                if (!pad.Dup && !pad.Ddown)
                {
                    if (direction[0] != '→')
                    {
                        direction.Insert(0, '→');
                        direction.RemoveAt(direction.Count - 1);
                    }
                }
                else if (pad.Dup)
                {
                    if (direction[0] != '↗')
                    {
                        direction.Insert(0, '↗');
                        direction.RemoveAt(direction.Count - 1);
                    }
                }
                else
                {
                    if (direction[0] != '↘')
                    {
                        direction.Insert(0, '↘');
                        direction.RemoveAt(direction.Count - 1);
                    }
                }
            }
            else if (pad.Ddown)
            {
                if (direction[0] != '↓')
                {
                    direction.Insert(0, '↓');
                    direction.RemoveAt(direction.Count - 1);
                }
            }
            else if (pad.Dup)
            {
                if (direction[0] != '↑')
                {
                    direction.Insert(0, '↑');
                    direction.RemoveAt(direction.Count - 1);
                }
            }

            if (!pad.Dup && !pad.Ddown && !pad.Dright && !pad.Dleft)
            {
                if (direction[0] != '☆')
                {
                    direction.Insert(0, '☆');
                    direction.RemoveAt(direction.Count - 1);
                }
            }


            if (pad.BindsPressed(stick))//1+2 1+3 1+4 2+3 2+4 3+4 1+2+3+4
            {
                if (pad.binds[6])
                {
                    if (buttton[0] != "1+2+3+4")
                    {
                        buttton.Insert(0, "1+2+3+4");
                        buttton.RemoveAt(buttton.Count - 1);
                    }
                }
                else if (pad.binds[0]) //1+2 !all
                {
                    if (pad.binds[5])  //1+2+3+4  !all
                    {
                        if (buttton[0] != "1+2+3+4")
                        {
                            buttton.Insert(0, "1+2+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else if (pad.three || pad.binds[1] || pad.binds[3]) //1+2+3  !all
                    {
                        if (pad.four || pad.binds[4] || pad.binds[2])   //1+2+3+4  !all
                        {
                            if (buttton[0] != "1+2+3+4")
                            {
                                buttton.Insert(0, "1+2+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else //1+2+3
                        {
                            if (buttton[0] != "1+2+3")
                            {
                                buttton.Insert(0, "1+2+3");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.four || pad.binds[4] || pad.binds[2])//1+2+4 !1+3 !2+3 !3+4 !all
                    {
                        if (buttton[0] != "1+2+4")
                        {
                            buttton.Insert(0, "1+2+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else//1+2 !3 !4  !all
                    {
                        if (buttton[0] != "1+2")
                        {
                            buttton.Insert(0, "1+2");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.binds[1]) //1+3 !1+2  !all
                {
                    if (pad.binds[4])  //1+2+3+4 !1+2  !all
                    {
                        if (buttton[0] != "1+2+3+4")
                        {
                            buttton.Insert(0, "1+2+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else if (pad.four || pad.binds[2] || pad.binds[5]) //1+3+4 !1+2 !2+4 !all
                    {
                        if (pad.two || pad.binds[3])                   //1+2+3+4 !1+2 !2+4 !all
                        {
                            if (buttton[0] != "1+2+3+4")
                            {
                                buttton.Insert(0, "1+2+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else if (buttton[0] != "1+3+4")
                        {
                            buttton.Insert(0, "1+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else if (pad.two || pad.binds[3])//1+2+3 !4 !1+2 !1+4 !2+4 !3+4 !all
                    {
                        if (buttton[0] != "1+2+3")
                        {
                            buttton.Insert(0, "1+2+3");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else //1+3
                    {
                        if (buttton[0] != "1+3")
                        {
                            buttton.Insert(0, "1+3");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.binds[2]) //1+4 !1+2 !1+3  !all
                {
                    if (pad.binds[3])  //1+2+3+4
                    {
                        if (buttton[0] != "1+2+3+4")
                        {
                            buttton.Insert(0, "1+2+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else if (pad.two || pad.binds[4])  //1+2+4 !1+2 !1+3 !2+3 !all
                    {
                        if (pad.three || pad.binds[5]) //1+2+3+4
                        {
                            if (buttton[0] != "1+2+3+4")
                            {
                                buttton.Insert(0, "1+2+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else
                        {
                            if (buttton[0] != "1+2+4")
                            {
                                buttton.Insert(0, "1+2+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.three || pad.binds[5])//1+3+4 !2 !1+2 !1+3 !2+3 !2+4 !all
                    {
                        if (buttton[0] != "1+3+4")
                        {
                            buttton.Insert(0, "1+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else
                    {
                        if (buttton[0] != "1+4")
                        {
                            buttton.Insert(0, "1+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.binds[3])                                //2+3 !1+2 !1+3 !1+4 !all
                {
                    if (pad.one)                                      //1+2+3 !1+2 !1+3 !1+4 !all
                    {
                        if (pad.four || pad.binds[4] || pad.binds[5]) //1+2+3+4
                        {
                            if (buttton[0] != "1+2+3+4")
                            {
                                buttton.Insert(0, "1+2+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else
                        {
                            if (buttton[0] != "1+2+3")
                            {
                                buttton.Insert(0, "1+2+3");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.four || pad.binds[4] || pad.binds[5])//2+3+4 !1 !1+2 !1+3 !1+4 !all
                    {
                        if (buttton[0] != "2+3+4")
                        {
                            buttton.Insert(0, "2+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else
                    {
                        if (buttton[0] != "2+3")
                        {
                            buttton.Insert(0, "2+3");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.binds[4])                 //2+4 !1+2 !1+3 !1+4 !2+3 !all
                {
                    if (pad.one)                       //1+2+4 !1+2 !1+3 !1+4 !2+3 !all
                    {
                        if (pad.three || pad.binds[5]) //1+2+3+4 !1+2 !1+3 !1+4 !2+3 !all
                        {
                            if (buttton[0] != "1+2+3+4")
                            {
                                buttton.Insert(0, "1+2+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else
                        {
                            if (buttton[0] != "1+2+4")
                            {
                                buttton.Insert(0, "1+2+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.three || pad.binds[5])//2+3+4 !1 !1+2 !1+3 !1+4 !2+3 !all
                    {
                        if (buttton[0] != "2+3+4")
                        {
                            buttton.Insert(0, "2+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else
                    {
                        if (buttton[0] != "2+4")
                        {
                            buttton.Insert(0, "2+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.binds[5]) //3+4 !1+2 !1+3 !1+4 !2+3 !2+4 !all
                {
                    if (pad.one)       //1+3+4 !1+2 !1+3 !1+4 !2+3 !2+4 !all
                    {
                        if (pad.two)   //1+2+3+4
                        {
                            if (buttton[0] != "1+2+3+4")
                            {
                                buttton.Insert(0, "1+2+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else
                        {
                            if (buttton[0] != "1+3+4")
                            {
                                buttton.Insert(0, "1+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.two)//2+3+4 !1 !1+2 !1+3 !1+4 !2+3 !2+4 !all
                    {
                        if (buttton[0] != "2+3+4")
                        {
                            buttton.Insert(0, "2+3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else
                    {
                        if (buttton[0] != "3+4")
                        {
                            buttton.Insert(0, "3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else
                {
                    if (buttton[0] != "☆")
                    {
                        buttton.Insert(0, "☆");
                        buttton.RemoveAt(buttton.Count - 1);
                    }
                }
            }
            else
            {
                if (pad.one)              //1
                {
                    if (pad.two)          //1+2
                    {
                        if (pad.three)    //1+2+3
                        {
                            if (pad.four) //1+2+3+4
                            {
                                if (buttton[0] != "1+2+3+4")
                                {
                                    buttton.Insert(0, "1+2+3+4");
                                    buttton.RemoveAt(buttton.Count - 1);
                                }
                            }
                            else//1+2+3
                            {
                                if (buttton[0] != "1+2+3")
                                {
                                    buttton.Insert(0, "1+2+3");
                                    buttton.RemoveAt(buttton.Count - 1);
                                }
                            }
                        }
                        else if (pad.four)//1+2+4 !3
                        {
                            if (buttton[0] != "1+2+4")
                            {
                                buttton.Insert(0, "1+2+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else//1+2 !3 !4
                        {
                            if (buttton[0] != "1+2")
                            {
                                buttton.Insert(0, "1+2");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.three) //1+3 !2
                    {
                        if (pad.four)   //1+3+4
                        {
                            if (buttton[0] != "1+3+4")
                            {
                                buttton.Insert(0, "1+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else//1+3
                        {
                            if (buttton[0] != "1+3")
                            {
                                buttton.Insert(0, "1+3");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.four)//1+4 !2 !3
                    {
                        if (buttton[0] != "1+4")
                        {
                            buttton.Insert(0, "1+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else//1
                    {
                        if (buttton[0] != "1")
                        {
                            buttton.Insert(0, "1");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.two)     //2 !1
                {
                    if (pad.three)    //2+3 !1
                    {
                        if (pad.four) //2+3+4
                        {
                            if (buttton[0] != "2+3+4")
                            {
                                buttton.Insert(0, "2+3+4");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                        else//2+3
                        {
                            if (buttton[0] != "2+3")
                            {
                                buttton.Insert(0, "2+3");
                                buttton.RemoveAt(buttton.Count - 1);
                            }
                        }
                    }
                    else if (pad.four)//2+4 !1 !3
                    {
                        if (buttton[0] != "2+4")
                        {
                            buttton.Insert(0, "2+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else//2
                    {
                        if (buttton[0] != "2")
                        {
                            buttton.Insert(0, "2");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.three) //3 !2 !1
                {
                    if (pad.four)   //3+4
                    {
                        if (buttton[0] != "3+4")
                        {
                            buttton.Insert(0, "3+4");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                    else//3
                    {
                        if (buttton[0] != "3")
                        {
                            buttton.Insert(0, "3");
                            buttton.RemoveAt(buttton.Count - 1);
                        }
                    }
                }
                else if (pad.four)//4 !3 !2 !1
                {
                    if (buttton[0] != "4")
                    {
                        buttton.Insert(0, "4");
                        buttton.RemoveAt(buttton.Count - 1);
                    }
                }
                else
                {
                    if (buttton[0] != "☆")
                    {
                        buttton.Insert(0, "☆");
                        buttton.RemoveAt(buttton.Count - 1);
                    }
                }
            }

            //todo datagridview
            if (pad.stateChanged)
            {
                if (pad.DstateChanged)
                {
                    dataGridView1.Rows.Clear();
                    //label1.Text = listtostring(direction);
                    buttton.Insert(0, buttton[0]);
                    buttton.RemoveAt(buttton.Count - 1);
                    //label2.Text = strlisttostr(buttton);

                    dataGridView1.Rows.Add(direction[0], direction[1], direction[2], direction[3], direction[4], direction[5], direction[6], direction[7], direction[8], direction[9], direction[10], direction[11], direction[12], direction[13], direction[14], direction[15], direction[16], direction[17], direction[18], direction[19]);
                    dataGridView1.Rows.Add(buttton[0], buttton[1], buttton[2], buttton[3], buttton[4], buttton[5], buttton[6], buttton[7], buttton[8], buttton[9], buttton[10], buttton[11], buttton[12], buttton[13], buttton[14], buttton[15], buttton[16], buttton[17], buttton[18], buttton[19]);
                }
                else if (pad.BindsPressed(stick))
                {
                    if (!equal(temp, buttton))
                    {
                        dataGridView1.Rows.Clear();
                        //label2.Text = strlisttostr(buttton);
                        direction.Insert(0, direction[0]);
                        direction.RemoveAt(direction.Count - 1);
                        //label1.Text = listtostring(direction);

                        dataGridView1.Rows.Add(direction[0], direction[1], direction[2], direction[3], direction[4], direction[5], direction[6], direction[7], direction[8], direction[9], direction[10], direction[11], direction[12], direction[13], direction[14], direction[15], direction[16], direction[17], direction[18], direction[19]);
                        dataGridView1.Rows.Add(buttton[0], buttton[1], buttton[2], buttton[3], buttton[4], buttton[5], buttton[6], buttton[7], buttton[8], buttton[9], buttton[10], buttton[11], buttton[12], buttton[13], buttton[14], buttton[15], buttton[16], buttton[17], buttton[18], buttton[19]);
                    }
                }
                else if (pad.BstateChanged)
                {
                    dataGridView1.Rows.Clear();
                    //label2.Text = strlisttostr(buttton);
                    direction.Insert(0, direction[0]);
                    direction.RemoveAt(direction.Count - 1);
                    //label1.Text = listtostring(direction);

                    dataGridView1.Rows.Add(direction[0], direction[1], direction[2], direction[3], direction[4], direction[5], direction[6], direction[7], direction[8], direction[9], direction[10], direction[11], direction[12], direction[13], direction[14], direction[15], direction[16], direction[17], direction[18], direction[19]);
                    dataGridView1.Rows.Add(buttton[0], buttton[1], buttton[2], buttton[3], buttton[4], buttton[5], buttton[6], buttton[7], buttton[8], buttton[9], buttton[10], buttton[11], buttton[12], buttton[13], buttton[14], buttton[15], buttton[16], buttton[17], buttton[18], buttton[19]);
                }
            }

            GC.Collect();
            //if (pad.BindsPressed(stick)) label1.Text = string.Join(".", pad.buttons);
        }