public void RefreshGameControllers() { IEnumerable <DirectDevice> devices = directInputDevices.GetInputDevices(); foreach (var controllerView in Model.Controllers.ToList()) { var controller = (controllerView.DataContext as ControllerViewModel).Model.Controller; if (controller.InputDevice is DirectDevice && !devices.Any(x => x.ToString() == controller.InputDevice.ToString())) { controller.Dispose(); Model.Controllers.Remove(controllerView); logger(string.Format(Message.ControllerDisconnected, controller.DisplayName)); } } foreach (var device in devices) { if (!Model.Controllers.Any(x => (x.DataContext as ControllerViewModel).Model.Controller.ToString() == device.ToString())) { InputMapperBase mapper = settings.GetMapper(device.Id.ToString()); GameController controller = new GameController(device, mapper); Model.Controllers.Add(new ControllerView(controller, logger)); device.StartCapturing(); logger(string.Format(Message.ControllerConnected, controller.DisplayName)); } else { device.Dispose(); } } }
/// <summary> /// Creates a new XDevice. /// </summary> /// <param name="source">Direct input device</param> /// <param name="mapper">DirectInput to XInput mapper</param> public XOutputDevice(IInputDevice source, Mapper.InputMapperBase mapper) { this.source = source; this.mapper = mapper; state = new DeviceState(XInputHelper.Instance.Values.OfType <Enum>().ToArray(), DPadCount); source.InputChanged += SourceInputChanged; }
public GameController(IInputDevice directInput, InputMapperBase mapper) { this.inputDevice = directInput; this.mapper = mapper; scpDevice = new ScpDevice(); xInput = new XDevice(directInput, mapper); running = false; }
public GameController(IInputDevice directInput, InputMapperBase mapper) { inputDevice = directInput; this.mapper = mapper; xOutputInterface = createXOutput(); xInput = new XOutputDevice(directInput, mapper); if (mapper.SelectedDPad == -1 && directInput.DPads.Any()) { mapper.SelectedDPad = 0; } running = false; }
public void RefreshGameControllers() { IEnumerable <SharpDX.DirectInput.DeviceInstance> instances = directInputDevices.GetInputDevices(Model.AllDevices); foreach (var controllerView in Model.Controllers.ToList()) { var controller = controllerView.ViewModel.Model.Controller; if (controller.InputDevice is DirectDevice && (!instances.Any(x => x.InstanceGuid == ((DirectDevice)controller.InputDevice).Id) || !controller.InputDevice.Connected)) { controllerView.ViewModel.Dispose(); controller.Dispose(); Model.Controllers.Remove(controllerView); logger.Info($"{controller.ToString()} is disconnected."); log(string.Format(LanguageModel.Instance.Translate("ControllerDisconnected"), controller.DisplayName)); } } foreach (var instance in instances) { if (!Model.Controllers.Select(c => c.ViewModel.Model.Controller.InputDevice).OfType <DirectDevice>().Any(d => d.Id == instance.InstanceGuid)) { var device = directInputDevices.CreateDirectDevice(instance); if (device == null) { continue; } InputMapperBase mapper = settings.GetMapper(device.ToString()); GameController controller = new GameController(device, mapper); var controllerView = new ControllerView(new ControllerViewModel(new ControllerModel(), controller, log)); controllerView.ViewModel.Model.CanStart = installed; Model.Controllers.Add(controllerView); device.Disconnected -= DispatchRefreshGameControllers; device.Disconnected += DispatchRefreshGameControllers; logger.Info($"{controller.ToString()} is connected."); log(string.Format(LanguageModel.Instance.Translate("ControllerConnected"), controller.DisplayName)); if (controller.Mapper.StartWhenConnected) { controllerView.ViewModel.Start(); logger.Info($"{controller.ToString()} controller is started automatically."); } } } }