private void Button_Checked(object sender, RoutedEventArgs e) { if (sender is ToggleButton button) { if (_currentAssigner != null && button == _currentAssigner.ToggledButton) { return; } if (_currentAssigner == null && (bool)button.IsChecked) { _currentAssigner = new ButtonKeyAssigner(button); FocusManager.Instance.Focus(this, NavigationMethod.Pointer); PointerPressed += MouseClick; IKeyboard keyboard = (IKeyboard)ViewModel.AvaloniaKeyboardDriver.GetGamepad(ViewModel.AvaloniaKeyboardDriver.GamepadsIds[0]); IButtonAssigner assigner = new KeyboardKeyAssigner(keyboard); _currentAssigner.GetInputAndAssign(assigner); } else { if (_currentAssigner != null) { ToggleButton oldButton = _currentAssigner.ToggledButton; _currentAssigner.Cancel(); _currentAssigner = null; button.IsChecked = false; } } } }
private IButtonAssigner CreateButtonAssigner(bool forStick) { IButtonAssigner assigner; var device = ViewModel.Devices[ViewModel.Device]; if (device.Type == Models.DeviceType.Keyboard) { assigner = new KeyboardKeyAssigner((IKeyboard)ViewModel.SelectedGamepad); } else if (device.Type == Models.DeviceType.Controller) { assigner = new GamepadButtonAssigner(ViewModel.SelectedGamepad, (ViewModel.Config as StandardControllerInputConfig).TriggerThreshold, forStick); } else { throw new Exception("Controller not supported"); } return(assigner); }
private ButtonAssigner CreateButtonAssigner() { int index = int.Parse(_inputDevice.ActiveId.Split("/")[1]); ButtonAssigner assigner; if (_inputDevice.ActiveId.StartsWith("keyboard")) { assigner = new KeyboardKeyAssigner(index); } else if (_inputDevice.ActiveId.StartsWith("controller")) { // TODO: triggerThresold is passed but not used by JoystickButtonAssigner. Should it be used for key binding?. // Note that, like left and right sticks, ZL and ZR triggers are treated as axis. // The problem is then how to decide which axis should use triggerThresold. assigner = new JoystickButtonAssigner(index, _controllerTriggerThreshold.Value); } else { throw new Exception("Controller not supported"); } return(assigner); }