Ejemplo n.º 1
0
        public void Draw()
        {
            lock (_lock)
            {
                var buttons  = SlimWrapper.GetInputs();
                var theInput = new List <object>();

                if (Any(buttons.buttons, Program.controller.Clear))
                {
                    inputs     = new List <List <object> >();
                    inputsTime = new List <List <int> >();
                    old        = new List <int>();
                }

                #region "plink"
                //-------------------------------------------------------------


                if (buttons.buttons.Count() > 0 && buttons.buttons.Count() != old.Count())
                {
                    if (!inDelay)
                    {
                        inDelay = true;
                        delay   = new List <int>();
                        delay.AddRange(buttons.buttons);
                        delayBuff = old;
                        frame     = 0;
                    }
                    else
                    {
                        foreach (var b in buttons.buttons)
                        {
                            if (!delay.Contains(b) && !old.Contains(b))
                            {
                                HasDelayInput = true;
                                break;
                            }
                        }


                        if (HasDelayInput)
                        {
                            foreach (var b in delay)
                            {
                                if (!buttons.buttons.Contains(b))
                                {
                                    buttons.buttons.Add(b);
                                }
                            }



                            inDelay = false;
                            buttons.buttons.Sort();
                            old = new List <int>();

                            delay = new List <int>();
                            frame = -1;


                            /*for (int i = 0; i < delayBuff.Count(); i++)
                             * {
                             *  buttons.buttons.Remove(delayBuff[i]);
                             *  old.Add(delayBuff[i]);
                             * }*/
                        }

                        frame++;
                    }
                }
                else if (inDelay)
                {
                    frame++;
                }

                if (frame >= PlinkDelay)
                {
                    inDelay       = false;
                    delay         = new List <int>();
                    frame         = 0;
                    HasDelayInput = false;
                }

                //-------------------------------------------------------------
                #endregion

                if (!(old.All(x => buttons.buttons.Contains(x)) && buttons.buttons.All(x => old.Contains(x))) || buttons.buttons.Count > 0)
                {
                    var up    = Any(buttons.buttons, Program.controller.Up);
                    var down  = Any(buttons.buttons, Program.controller.Down);
                    var left  = Any(buttons.buttons, Program.controller.Left);
                    var right = Any(buttons.buttons, Program.controller.Right);

                    var vup    = !Any(old, Program.controller.Up) || ValidButtonChange(buttons.buttons, old);
                    var vdown  = !Any(old, Program.controller.Down) || ValidButtonChange(buttons.buttons, old);
                    var vleft  = !Any(old, Program.controller.Left) || ValidButtonChange(buttons.buttons, old);
                    var vright = !Any(old, Program.controller.Right) || ValidButtonChange(buttons.buttons, old);


                    var lastIsDiagonal = false;

                    if (inputs.Count > 0)
                    {
                        foreach (var i in inputs.First().ToList())
                        {
                            lastIsDiagonal = lastIsDiagonal || i.ToString().Contains("-");
                        }
                    }

                    if ((up && left) || (up && right) || (down && left) || (down && right))
                    {
                        lastIsDiagonal = false;
                    }

                    Action <object, List <int> > Add = (obj, lst) =>
                    {
                        theInput.Add(obj);

                        if (Sound && Sounds.ContainsKey(obj.ToString()))
                        {
                            Player.Play(Sounds[obj.ToString()]);
                        }

                        if (HasDelayInput && pressed.ContainsKey(obj) && pressed[obj] > 0 && lst != null && Any(delayBuff, lst))
                        {
                            theInput.Remove(obj);
                        }


                        int _;
                        if (pressed.ContainsKey(obj))
                        {
                            if (int.TryParse(obj.ToString(), out _))
                            {
                                pressed.Remove(obj);
                            }
                            else
                            {
                                if (!ValidButtonChange(buttons.buttons, old) && pressed[obj] > 0)
                                {
                                    pressed.Remove(obj);
                                }
                            }
                        }
                    };

                    if (up && left && (vup || vleft))
                    {
                        Add("up-left", null);
                    }
                    else if (up && right && (vup || vright))
                    {
                        Add("up-right", null);
                    }
                    else if (down && left && (vdown || vleft))
                    {
                        Add("down-left", null);
                    }
                    else if (down && right && (vdown || vright))
                    {
                        Add("down-right", null);
                    }
                    else
                    {
                        if (up && (vup || lastIsDiagonal))
                        {
                            Add("up", null);
                        }

                        if (down && (vdown || lastIsDiagonal))
                        {
                            Add("down", null);
                        }

                        if (left && (vleft || lastIsDiagonal))
                        {
                            Add("left", null);
                        }

                        if (right && (vright || lastIsDiagonal))
                        {
                            Add("right", null);
                        }
                    }


                    if (up && left && !(vup || vleft))
                    {
                        addTime("up-left");
                    }
                    else if (up && right && !(vup || vright))
                    {
                        addTime("up-right");
                    }
                    else if (down && left && !(vdown || vleft))
                    {
                        addTime("down-left");
                    }
                    else if (down && right && !(vdown || vright))
                    {
                        addTime("down-right");
                    }
                    else
                    {
                        if (up && !vup)
                        {
                            addTime("up");
                        }

                        if (down && !vdown)
                        {
                            addTime("down");
                        }

                        if (left && !vleft)
                        {
                            addTime("left");
                        }

                        if (right && !vright)
                        {
                            addTime("right");
                        }
                    }



                    if (Any(buttons.buttons, Program.controller.LP))
                    {
                        if (!Any(old, Program.controller.LP))
                        {
                            Add(1, Program.controller.LP);
                        }
                        else
                        {
                            addTime(1);
                        }
                    }


                    if (Any(buttons.buttons, Program.controller.MP))
                    {
                        if (!Any(old, Program.controller.MP))
                        {
                            Add(2, Program.controller.MP);
                        }
                        else
                        {
                            addTime(2);
                        }
                    }

                    if (Any(buttons.buttons, Program.controller.HP))
                    {
                        if (!Any(old, Program.controller.HP))
                        {
                            Add(3, Program.controller.HP);
                        }
                        else
                        {
                            addTime(3);
                        }
                    }

                    if (Any(buttons.buttons, Program.controller.PPP))
                    {
                        if (!Any(old, Program.controller.PPP))
                        {
                            Add(4, Program.controller.PPP);
                        }
                        else
                        {
                            addTime(4);
                        }
                    }

                    if (Any(buttons.buttons, Program.controller.LK))
                    {
                        if (!Any(old, Program.controller.LK))
                        {
                            Add(5, Program.controller.LK);
                        }
                        else
                        {
                            addTime(5);
                        }
                    }

                    if (Any(buttons.buttons, Program.controller.MK))
                    {
                        if (!Any(old, Program.controller.MK))
                        {
                            Add(6, Program.controller.MK);
                        }
                        else
                        {
                            addTime(6);
                        }
                    }

                    if (Any(buttons.buttons, Program.controller.HK))
                    {
                        if (!Any(old, Program.controller.HK))
                        {
                            Add(7, Program.controller.HK);
                        }
                        else
                        {
                            addTime(7);
                        }
                    }

                    if (Any(buttons.buttons, Program.controller.KKK))
                    {
                        if (!Any(old, Program.controller.KKK))
                        {
                            Add(8, Program.controller.KKK);
                        }
                        else
                        {
                            addTime(8);
                        }
                    }



                    if (theInput.Count > 0)
                    {
                        inputs.Insert(0, theInput);

                        var time = new List <int>();
                        for (int i = 0; i < theInput.Count(); i++)
                        {
                            if (pressed.ContainsKey(theInput[i]) && pressed[theInput[i]] > 0)
                            {
                                time.Add(-1);
                            }
                            else
                            {
                                time.Add(1);
                            }
                        }
                        inputsTime.Insert(0, time);
                    }



                    pictureBox1.BeginInvoke((Action)(() =>
                    {
                        pictureBox1.Refresh();
                    }));

                    old = buttons.buttons;
                }
                else
                {
                    if (buttons.buttons.Count == 0)
                    {
                        old = buttons.buttons;
                    }
                }

                if (HasDelayInput)
                {
                    HasDelayInput = false;
                }
            }
        }
Ejemplo n.º 2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            var buttons = SlimWrapper.GetInputs();

            if (getKeyState)
            {
                if (buttons.buttons.Count > 0)
                {
                    switch (selectedButton)
                    {
                    case "U":

                        Program.controller.Up = buttons.buttons;
                        lblPush.Visible       = false;
                        getKeyState           = false;
                        break;

                    case "R":

                        Program.controller.Right = buttons.buttons;
                        lblPush.Visible          = false;
                        getKeyState = false;
                        break;

                    case "D":
                        Program.controller.Down = buttons.buttons;
                        lblPush.Visible         = false;
                        getKeyState             = false;
                        break;

                    case "L":
                        Program.controller.Left = buttons.buttons;
                        lblPush.Visible         = false;
                        getKeyState             = false;
                        break;

                    case "LP":
                        Program.controller.LP = buttons.buttons;
                        lblPush.Visible       = false;
                        getKeyState           = false;
                        break;

                    case "MP":
                        Program.controller.MP = buttons.buttons;
                        lblPush.Visible       = false;
                        getKeyState           = false;
                        break;

                    case "HP":
                        Program.controller.HP = buttons.buttons;
                        lblPush.Visible       = false;
                        getKeyState           = false;
                        break;

                    case "PP":
                        Program.controller.PPP = buttons.buttons;
                        lblPush.Visible        = false;
                        getKeyState            = false;
                        break;

                    case "LK":
                        Program.controller.LK = buttons.buttons;
                        lblPush.Visible       = false;
                        getKeyState           = false;
                        break;

                    case "MK":
                        Program.controller.MK = buttons.buttons;
                        lblPush.Visible       = false;
                        getKeyState           = false;
                        break;

                    case "HK":
                        Program.controller.HK = buttons.buttons;
                        lblPush.Visible       = false;
                        getKeyState           = false;
                        break;

                    case "KK":
                        Program.controller.KKK = buttons.buttons;
                        lblPush.Visible        = false;
                        getKeyState            = false;
                        break;

                    case "Clear":
                        Program.controller.Clear = buttons.buttons;
                        lblPush.Visible          = false;
                        getKeyState = false;
                        break;
                    }
                }
            }
            else
            {
                if (Program.controller.Up.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("U", true);
                }
                else
                {
                    setButtonColor("U", false);
                }

                if (Program.controller.Down.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("D", true);
                }
                else
                {
                    setButtonColor("D", false);
                }

                if (Program.controller.Left.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("L", true);
                }
                else
                {
                    setButtonColor("L", false);
                }

                if (Program.controller.Right.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("R", true);
                }
                else
                {
                    setButtonColor("R", false);
                }



                if (Program.controller.LP.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("LP", true);
                }
                else
                {
                    setButtonColor("LP", false);
                }

                if (Program.controller.MP.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("MP", true);
                }
                else
                {
                    setButtonColor("MP", false);
                }

                if (Program.controller.HP.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("HP", true);
                }
                else
                {
                    setButtonColor("HP", false);
                }

                if (Program.controller.PPP.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("PP", true);
                }
                else
                {
                    setButtonColor("PP", false);
                }


                if (Program.controller.LK.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("LK", true);
                }
                else
                {
                    setButtonColor("LK", false);
                }

                if (Program.controller.MK.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("MK", true);
                }
                else
                {
                    setButtonColor("MK", false);
                }

                if (Program.controller.HK.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("HK", true);
                }
                else
                {
                    setButtonColor("HK", false);
                }

                if (Program.controller.KKK.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("KK", true);
                }
                else
                {
                    setButtonColor("KK", false);
                }

                if (Program.controller.Clear.Intersect(buttons.buttons).Any())
                {
                    setButtonColor("Clear", true);
                }
                else
                {
                    setButtonColor("Clear", false);
                }
            }

            txtInputs.Text = string.Join(",", buttons.buttons);
        }