Esempio n. 1
0
    public bool GetButtonDown(Config.Device device)
    {
        if (device == Config.Device.Keyboard && ButtonMouse != MouseKey.None)
        {
            bool mouse;
            int  buttonNumber = (int)ButtonMouse;

            if (ButtonMouse == MouseKey.WheelUp)
            {
                mouse = Input.GetAxis("Mouse ScrollWheel") > 0;
            }
            else if (ButtonMouse == MouseKey.WheelDown)
            {
                mouse = Input.GetAxis("Mouse ScrollWheel") < 0;
            }
            else
            {
                mouse = Input.GetMouseButtonDown(buttonNumber);
            }

            return(Input.GetButtonDown(ButtonKeyboard) || mouse);
        }

        string button = GetCurrentButton(device);

        if (button.Length == 0)
        {
            return(false);
        }

        return(Input.GetButtonDown(button));
    }
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode tn = e.Node;

            if (tn.Level == 0) //服务
            {
                string        serverId = tn.Tag.ToString();
                Config.Server server   = _config.Servers.FirstOrDefault(s => s.ServerConfig.ServerSession == serverId);
                if (server != null)
                {
                    this.propertyGrid1.SelectedObject = server.ServerConfig;
                    this.WriteLog("选择服务:" + server.ServerConfig.ServerName);
                }
            }
            else if (tn.Level == 2) //设备
            {
                string        serverId = GetRootNode(tn).Tag.ToString();
                Config.Server server   = _config.Servers.FirstOrDefault(s => s.ServerConfig.ServerSession == serverId);
                if (server != null)
                {
                    string        deviceId = tn.Tag.ToString();
                    Config.Device device   = server.Devices.FirstOrDefault(d => d.DeviceID == deviceId);
                    if (device != null)
                    {
                        this.propertyGrid1.SelectedObject = device;
                        this.WriteLog("选择设备:" + device.Caption);
                    }
                }
            }
        }
Esempio n. 3
0
    public string GetCurrentButton(Config.Device device, string separator)
    {
        string button = "";

        // in case of NullReferenceException you forgot to call Initialize() perhaps
        switch (device)
        {
        case Config.Device.Spacepilot:
            button = ButtonSpacepilot;
            break;

        case Config.Device.Xbox:
            button = ButtonXbox;
            break;

        case Config.Device.Keyboard:
            button = ButtonKeyboard;
            if (ButtonMouse != MouseKey.None)
            {
                button += separator + "Mouse" + ButtonMouse;
            }
            break;
        }

        return(button);
    }
        private void AddDeviceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddForm addForm = new AddForm(new DeviceProperty());

            addForm.ShowDialog();
            if (addForm.ConfigObject != null)
            {
                TreeNode tn = this.treeView1.SelectedNode;
                if (tn != null)
                {
                    DeviceProperty property = (DeviceProperty)addForm.ConfigObject;
                    Config.Device  device   = new Config.Device
                    {
                        Caption         = property.Caption,
                        DeviceID        = property.DeviceID,
                        AssemblyFile    = property.AssemblyFile,
                        CommunicateType = property.CommunicateType,
                        DeviceType      = property.DeviceType,
                        Instance        = property.Instance,
                        Remarks         = property.Remarks
                    };

                    try
                    {
                        IObjectBuilder builder = new TypeCreator();
                        IRunDevice     runDev  = builder.BuildUp <IRunDevice>(property.AssemblyFile, property.Instance);

                        runDev.DeviceParameter.DeviceID = property.DeviceID;
                        runDev.DeviceDynamic.DeviceID   = property.DeviceID;
                        runDev.CommunicateType          = property.CommunicateType;
                        if (runDev.CommunicateType == CommunicateType.COM)
                        {
                            runDev.DeviceParameter.COM.Port = ComUtils.PortToInt(property.IoParameter1);
                            runDev.DeviceParameter.COM.Baud = property.IoParameter2;
                        }
                        else if (runDev.CommunicateType == CommunicateType.NET)
                        {
                            runDev.DeviceParameter.NET.RemoteIP   = property.IoParameter1;
                            runDev.DeviceParameter.NET.RemotePort = property.IoParameter2;
                        }
                        runDev.DeviceParameter.DeviceCode   = property.DeviceCode;
                        runDev.DeviceParameter.DeviceAddr   = property.DeviceAddr;
                        runDev.DeviceParameter.DeviceName   = property.DeviceName;
                        runDev.DeviceParameter.NET.WorkMode = property.WorkMode;
                        runDev.Initialize(runDev.DeviceParameter.DeviceID);

                        TreeNode parentNode = GetRootNode(tn);
                        AddDevice(parentNode.Tag.ToString(), device);
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.Message);
                    }
                }
            }
        }
 private void AddDevice(string serverId, Config.Device device)
 {
     Config.Server server = _config.Servers.FirstOrDefault(s => s.ServerConfig.ServerSession == serverId);
     if (server != null)
     {
         server.Devices.Add(device);
         this.SaveConfig();
         AddDeviceOfTree(serverId, device);
     }
 }
        private void propertyGrid1_PropertyValueChanged(object obj, PropertyValueChangedEventArgs e)
        {
            TreeNode tn = this.treeView1.SelectedNode;

            if (tn == null)
            {
                return;
            }

            if (tn.Level == 0) //服务
            {
                string        serverId = tn.Tag.ToString();
                Config.Server server   = _config.Servers.FirstOrDefault(s => s.ServerConfig.ServerSession == serverId);
                if (server != null)
                {
                    server.ServerConfig = (ServerConfig)this.propertyGrid1.SelectedObject;;

                    this.SaveConfig();

                    if (tn.Text != server.ServerConfig.ServerName)
                    {
                        tn.Text = server.ServerConfig.ServerName;
                    }
                    this.WriteLog("修改服务:" + server.ServerConfig.ServerName + ",属性:" + e.ChangedItem.Label);
                }
            }
            else if (tn.Level == 2) //设备
            {
                string        serverId = GetRootNode(tn).Tag.ToString();
                Config.Server server   = _config.Servers.FirstOrDefault(s => s.ServerConfig.ServerSession == serverId);
                if (server != null)
                {
                    string        deviceId = tn.Tag.ToString();
                    Config.Device device   = server.Devices.FirstOrDefault(d => d.DeviceID == deviceId);
                    if (device != null)
                    {
                        device = (Config.Device) this.propertyGrid1.SelectedObject;
                        this.SaveConfig();

                        if (tn.Text != device.Caption)
                        {
                            tn.Text = device.Caption;
                        }
                        this.WriteLog("修改设备:" + device.Caption + ",属性:" + e.ChangedItem.Label);
                    }
                }
            }
        }
 private void RemoveDevice(string serverId, string deviceId)
 {
     Config.Server server = _config.Servers.FirstOrDefault(s => s.ServerConfig.ServerSession == serverId);
     if (server != null)
     {
         Config.Device device = server.Devices.FirstOrDefault(d => d.DeviceID == deviceId);
         if (device != null)
         {
             if (server.Devices.Remove(device))
             {
                 this.SaveConfig();
                 RemoveDeviceOfTree(serverId, deviceId);
             }
         }
     }
 }
        private void AddDeviceOfTree(string serverId, Config.Device device)
        {
            TreeNode[] tnServers = this.treeView1.Nodes.Find(serverId, true);
            if (tnServers.Length > 0)
            {
                if (device.CommunicateType == CommunicateType.COM)
                {
                    tnServers[0].Nodes[0].Nodes.Add(NewNode(device.Caption, device.DeviceID, 3, 3));
                }
                else if (device.CommunicateType == CommunicateType.NET)
                {
                    tnServers[0].Nodes[1].Nodes.Add(NewNode(device.Caption, device.DeviceID, 3, 3));
                }

                tnServers[0].ExpandAll();
            }
        }
Esempio n. 9
0
    private static Config.Device ParseInputDevice(string text)
    {
        Debug.Log("ApplicationStarter::ParseInputDevice start");

        Config.Device device = Config.Device.None;

        if (text.Equals("Keyboard"))
        {
            device = Config.Device.Keyboard;
        }
        else if (text.Equals("Xbox"))
        {
            device = Config.Device.Xbox;
        }
        else if (text.Equals("Spacepilot"))
        {
            device = Config.Device.Spacepilot;
        }

        return(device);
    }
Esempio n. 10
0
 public string GetCurrentButton(Config.Device device)
 {
     return(GetCurrentButton(device, "  /  "));
 }