コード例 #1
0
ファイル: Map.cs プロジェクト: vuvuvu/FGInputLogger
        private void LoadConfig(string file = "")
        {
            FileStream stream = null;


            if (file == "")
            {
                var dialog = new OpenFileDialog();
                dialog.Filter = "JSON|*.json";
                dialog.Title  = "Load config file";
                dialog.ShowDialog();
                file = dialog.FileName;
                if (file != "")
                {
                    stream = (FileStream)dialog.OpenFile();
                }
            }
            else
            {
                stream = new FileStream(file, FileMode.Open, FileAccess.ReadWrite);
            }

            try
            {
                if (file != "")
                {
                    using (var fs = new StreamReader(stream))
                    {
                        dynamic obj = JObject.Parse(fs.ReadToEnd());

                        Program.controller    = obj.Buttons.ToObject <ControlMap>();
                        IconSize              = (int)obj.IconSize;
                        cmbTheme.SelectedItem = obj.Theme.ToString();
                        ImageMap              = obj.Images.ToObject <Dictionary <int, List <int> > >();
                        lblColor.BackColor    = obj.Color.ToObject <Color>();
                        chkFrames.Checked     = obj.ShowFrames.ToObject <bool>();
                        chkDirColumn.Checked  = obj.SeparateDirections.ToObject <bool>();
                        chkSound.Checked      = obj.Sounds.ToObject <bool>();
                        rdbVertical.Checked   = obj.Vertical.ToObject <bool>();
                        rdbHorizontal.Checked = !obj.Vertical.ToObject <bool>();


                        try
                        {
                            DeviceId = Guid.Parse(obj.deviceId.ToString());
                            SlimWrapper.Acquire(this, DeviceId);
                        }
                        catch
                        {
                            MessageBox.Show("Cant find the controller used in this config, please select another");
                            btnSelect_Click(null, EventArgs.Empty);
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("Cant load this config file.");
            }
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: vuvuvu/FGInputLogger
        private void btnSelect_Click(object sender, EventArgs e)
        {
            DeviceId = (Guid)cmdDevices.SelectedValue;

            SlimWrapper.Acquire(this, DeviceId);
            // Program.controller = new ControlMap();
            timer.Enabled       = true;
            pictureBox1.Visible = false;
        }
コード例 #3
0
ファイル: Map.cs プロジェクト: vuvuvu/FGInputLogger
        private void Map_Load(object sender, EventArgs e)
        {
            var controls = SlimWrapper.Available();
            var names    = controls.Select(c => c.Name).ToArray();

            if (controls.Count == 0)
            {
                MessageBox.Show("Connect a controller and restart the application");
                Environment.Exit(0);
            }

            for (int i = 1; i < 9; i++)
            {
                ImageMap.Add(i, new List <int> {
                    i
                });
            }

            cmnButtons.SelectedIndex = 0;
            fillImageBox();
            refreshList();


            cmdDevices.DataSource    = controls;
            cmdDevices.DisplayMember = "Name";
            cmdDevices.ValueMember   = "Guid";


            timer.Tick += Timer_Tick;

            cmbTheme.DataSource    = Directory.GetDirectories("themes").Select(x => x.Split('\\')[1]).ToArray();
            cmbTheme.SelectedIndex = 0;

            foreach (Control item in this.Controls)
            {
                if (item is Button)
                {
                    var but = (Button)item;
                    if (but.Tag != null && but.Tag.ToString() == "-")
                    {
                        item.Click += set_click;
                    }
                }
            }


            btnSelect_Click(sender, e);


            if (File.Exists("Config.json"))
            {
                LoadConfig("Config.json");
            }
        }
コード例 #4
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;
                }
            }
        }
コード例 #5
0
ファイル: Map.cs プロジェクト: vuvuvu/FGInputLogger
        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);
        }