Ejemplo n.º 1
0
        public MapEdit(JoyManager _manager, List <DefaultMapConfig> _configs, BTDeviceInfo _device)
        {
            InitializeComponent();
            this.manager      = _manager;
            this.configs      = _configs;
            this.device       = _device;
            allXinputBtEnum   = GetEnumArray <Xbox360Buttons>();
            allXinputAxesEnum = GetEnumArray <Xbox360Axes>();
            allScripts        = new List <ButtonEnumModel>();
            allKeysEnum       = GetEnumArray <Keys>();
            allMixBt          = new List <ButtonEnumModel>();
            allMixBt.AddRange(this.allXinputBtEnum.Select(i => new ButtonEnumModel("360:" + i.ToString(), (int)i, 65535)));
            allMixBt.AddRange(this.allKeysEnum.Select(i => new ButtonEnumModel(i.ToString(), (int)i)));
            allMixBt.Add(new ButtonEnumModel("未设定", (int)TimeBoxButton.NONE));

            if (!Directory.Exists("joyScripts"))
            {
                Directory.CreateDirectory("joyScripts");
            }
            foreach (var file in Directory.GetFiles("joyScripts"))
            {
                var name     = System.IO.Path.GetFileNameWithoutExtension(file);
                var nameHash = name.GetHashCode();
                allScripts.Add(new ButtonEnumModel(name, nameHash));
            }
        }
Ejemplo n.º 2
0
 public MapEdit(JoyManager _manager, List <DefaultMapConfig> _configs, BTDeviceInfo _device)
 {
     InitializeComponent();
     this.manager      = _manager;
     this.configs      = _configs;
     this.device       = _device;
     allXinputBtEnum   = GetEnumArray <Xbox360Buttons>();
     allXinputAxesEnum = GetEnumArray <Xbox360Axes>();
     allKeysEnum       = GetEnumArray <Keys>();
     allMixBt          = new List <ButtonEnumModel>();
     allMixBt.AddRange(this.allXinputBtEnum.Select(i => new ButtonEnumModel("Xinput:" + i.ToString(), (int)i, 65535)));
     allMixBt.AddRange(this.allKeysEnum.Select(i => new ButtonEnumModel("键盘:" + i.ToString(), (int)i)));
     allMixBt.Add(new ButtonEnumModel("未设定", (int)TimeBoxButton.NONE));
 }
Ejemplo n.º 3
0
 private void MainWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     try
     {
         manager = new JoyManager(
             OnJoyMessageReceive: buffer => {
             this.Invoke(new Action(() => {
                 string text = HexHelper.byteToHexStr(buffer, buffer.Length);
                 mainWebBrowser.Document.InvokeScript("addCommit", new object[] { text });
             }));
         },
             OnMessage: msg => {
             this.Invoke(new Action(() => {
                 mainWebBrowser.Document.InvokeScript("addCommit", new object[] { msg });
             }));
         },
             OnJoyStateChange: joys => {
             this.Invoke(new Action(() => {
                 var lists = joys.Select(i => i.ToString());
                 var str   = string.Join(";", lists);
                 mainWebBrowser.Document.InvokeScript("onlistChange", new object[] { str });
             }));
         },
             OnStartScanDevice: () => {
             this.Invoke(new Action(() => {
                 mainWebBrowser.Document.InvokeScript("changeScanState", new object[] { "扫描中....." });
             }));
         },
             OnEndScanDevice: () => {
             this.Invoke(new Action(() => {
                 mainWebBrowser.Document.InvokeScript("changeScanState", new object[] { "重新扫描" });
             }));
         }
             );
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         //ShowMsg(ex.Message);
         System.Environment.Exit(0);
     }
 }
Ejemplo n.º 4
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         manager = new JoyManager(
             OnJoyMessageReceive: buffer => {
             string text = HexHelper.byteToHexStr(buffer, buffer.Length);
             ShowMsg(text);
         },
             OnMessage: msg => {
             ShowMsg(msg);
         },
             OnJoyStateChange: joys => {
             this.Invoke(new Action(() => {
                 this.listBox1.Items.Clear();
                 foreach (var joy in joys)
                 {
                     this.listBox1.Items.Add(joy);
                 }
                 if (SelectIndex >= 0 && SelectIndex < this.listBox1.Items.Count)
                 {
                     this.listBox1.SetSelected(SelectIndex, true);
                 }
             }));
         },
             OnStartScanDevice: () => {
             this.button2.Text = "扫描中......";
         },
             OnEndScanDevice: () => {
             this.button2.Text = "重新扫描设备";
         }
             );
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         System.Environment.Exit(0);
     }
 }
Ejemplo n.º 5
0
        public void SetJoyMap(JoyManager manager, DefaultMapConfig config = null)
        {
            IJoyMap map = new KeyBoardJoyMap();

            if (config != null)
            {
                switch (config.MapType)
                {
                case MapType.KEYBOARD:
                    if (this.joyMap != null)
                    {
                        this.joyMap.Dispose();
                    }
                    this.mapConfig = config;
                    this.joyMap    = new KeyBoardJoyMap(config);
                    this.joyMap.Initialize(f => { });
                    this.joyStick.SetJoyMap(this.joyMap);
                    return;

                case MapType.XINPUT:
                    if (this.joyMap != null)
                    {
                        this.joyMap.Dispose();
                    }
                    this.mapConfig = config;
                    this.joyMap    = new VitualXinputJoyMap(config);
                    if (!this.joyMap.Initialize(ex => {
                        manager.WriteLog(ex.Message + "\r\n已切换回键盘映射模式");
                    }))
                    {
                        map = new KeyBoardJoyMap();
                    }
                    this.joyStick.SetJoyMap(this.joyMap);
                    return;

                case MapType.MIX:
                    if (this.joyMap != null)
                    {
                        this.joyMap.Dispose();
                    }
                    this.mapConfig = config;
                    this.joyMap    = new MixModeJoyMap(config);
                    if (!this.joyMap.Initialize(ex => {
                        manager.WriteLog(ex.Message + "\r\n已切换回键盘映射模式");
                    }))
                    {
                        map = new KeyBoardJoyMap();
                    }
                    this.joyStick.SetJoyMap(this.joyMap);
                    return;
                }
            }

            map = new VitualXinputJoyMap();
            if (!map.Initialize(ex => {
                manager.WriteLog(ex.Message + "\r\n已切换回键盘映射模式");
                //MessageBox.Show(ex.Message + "\r\n已切换回键盘映射模式");
            }))
            {
                map = new KeyBoardJoyMap();
            }
            this.joyMap    = map;
            this.mapConfig = map.config;
            this.joyStick.SetJoyMap(map);
        }