Merge branch 'DeadZone' into joycon
# Conflicts: # src/Ryujinx/Ryujinx.csproj
This commit is contained in:
commit
1e3718343c
@ -392,6 +392,11 @@ namespace Ryujinx.Input.HLE
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
public static JoystickPosition GetJoystickPosition(float x, float y, float deadzone, float range)
|
||||
{
|
||||
return ClampToCircle(ApplyDeadzone(x, y,deadzone), range);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static JoystickPosition ApplyDeadzone(float x, float y, float deadzone)
|
||||
|
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 68 KiB |
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 81 KiB |
@ -132,6 +132,8 @@
|
||||
<None Remove="Assets\Icons\Controller_JoyConLeft.svg" />
|
||||
<None Remove="Assets\Icons\Controller_JoyConPair.svg" />
|
||||
<None Remove="Assets\Icons\Controller_JoyConRight.svg" />
|
||||
<None Remove="Assets\Icons\Controller_JoyConLeft_Settings.svg" />
|
||||
<None Remove="Assets\Icons\Controller_JoyConRight_Settings.svg" />
|
||||
<None Remove="Assets\Icons\Controller_ProCon.svg" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -153,6 +155,8 @@
|
||||
<EmbeddedResource Include="Assets\Icons\Controller_JoyConLeft.svg" />
|
||||
<EmbeddedResource Include="Assets\Icons\Controller_JoyConPair.svg" />
|
||||
<EmbeddedResource Include="Assets\Icons\Controller_JoyConRight.svg" />
|
||||
<EmbeddedResource Include="Assets\Icons\Controller_JoyConLeft_Settings.svg" />
|
||||
<EmbeddedResource Include="Assets\Icons\Controller_JoyConRight_Settings.svg" />
|
||||
<EmbeddedResource Include="Assets\Icons\Controller_ProCon.svg" />
|
||||
<EmbeddedResource Include="Assets\UIImages\Icon_NCA.png" />
|
||||
<EmbeddedResource Include="Assets\UIImages\Icon_NRO.png" />
|
||||
|
@ -7,6 +7,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
public class ControllerInputViewModel : BaseModel
|
||||
{
|
||||
private GamepadInputConfig _config;
|
||||
|
||||
public GamepadInputConfig Config
|
||||
{
|
||||
get => _config;
|
||||
@ -18,6 +19,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
}
|
||||
|
||||
private bool _isLeft;
|
||||
|
||||
public bool IsLeft
|
||||
{
|
||||
get => _isLeft;
|
||||
@ -30,6 +32,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
}
|
||||
|
||||
private bool _isRight;
|
||||
|
||||
public bool IsRight
|
||||
{
|
||||
get => _isRight;
|
||||
@ -44,6 +47,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
public bool HasSides => IsLeft ^ IsRight;
|
||||
|
||||
private SvgImage _image;
|
||||
|
||||
public SvgImage Image
|
||||
{
|
||||
get => _image;
|
||||
@ -55,6 +59,30 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
}
|
||||
|
||||
public readonly InputViewModel ParentModel;
|
||||
|
||||
private string _leftStickPosition;
|
||||
|
||||
public string LeftStickPosition
|
||||
{
|
||||
get => _leftStickPosition;
|
||||
set
|
||||
{
|
||||
_leftStickPosition = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _rightStickPosition;
|
||||
|
||||
public string RightStickPosition
|
||||
{
|
||||
get => _rightStickPosition;
|
||||
set
|
||||
{
|
||||
_rightStickPosition = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public ControllerInputViewModel(InputViewModel model, GamepadInputConfig config)
|
||||
{
|
||||
|
@ -37,8 +37,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||
private const string Disabled = "disabled";
|
||||
private const string ProControllerResource = "Ryujinx/Assets/Icons/Controller_ProCon.svg";
|
||||
private const string JoyConPairResource = "Ryujinx/Assets/Icons/Controller_JoyConPair.svg";
|
||||
private const string JoyConLeftResource = "Ryujinx/Assets/Icons/Controller_JoyConLeft.svg";
|
||||
private const string JoyConRightResource = "Ryujinx/Assets/Icons/Controller_JoyConRight.svg";
|
||||
private const string JoyConLeftResource = "Ryujinx/Assets/Icons/Controller_JoyConLeft_Settings.svg";
|
||||
private const string JoyConRightResource = "Ryujinx/Assets/Icons/Controller_JoyConRight_Settings.svg";
|
||||
private const string KeyboardString = "keyboard";
|
||||
private const string ControllerString = "controller";
|
||||
private readonly MainWindow _mainWindow;
|
||||
|
@ -15,7 +15,9 @@
|
||||
x:DataType="viewModels:ControllerInputViewModel"
|
||||
x:CompileBindings="True"
|
||||
mc:Ignorable="d"
|
||||
Focusable="True">
|
||||
Focusable="True"
|
||||
Unloaded="Control_OnUnloaded"
|
||||
>
|
||||
<Design.DataContext>
|
||||
<viewModels:ControllerInputViewModel />
|
||||
</Design.DataContext>
|
||||
@ -183,6 +185,9 @@
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
Text="{ext:Locale ControllerSettingsStickDeadzone}" />
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
Text="{Binding LeftStickPosition }" />
|
||||
<StackPanel
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
@ -716,6 +721,9 @@
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
Text="{ext:Locale ControllerSettingsStickDeadzone}" />
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
Text="{Binding RightStickPosition }" />
|
||||
<StackPanel
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
|
@ -4,14 +4,13 @@ using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.LogicalTree;
|
||||
using DiscordRPC;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.UI.ViewModels.Input;
|
||||
using Ryujinx.Common.Configuration.Hid.Controller;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Input;
|
||||
using Ryujinx.Input.Assigner;
|
||||
using System;
|
||||
using Ryujinx.Input.HLE;
|
||||
using System.Threading.Tasks;
|
||||
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Views.Input
|
||||
@ -19,6 +18,7 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
public partial class ControllerInputView : UserControl
|
||||
{
|
||||
private ButtonKeyAssigner _currentAssigner;
|
||||
private volatile bool _isRunning = true;
|
||||
|
||||
public ControllerInputView()
|
||||
{
|
||||
@ -39,6 +39,8 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartUpdatingData();
|
||||
}
|
||||
|
||||
protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
||||
@ -85,7 +87,7 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
|
||||
private void Button_IsCheckedChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleButton button)
|
||||
if (sender is ToggleButton button)
|
||||
{
|
||||
if (button.IsChecked is true)
|
||||
{
|
||||
@ -106,7 +108,9 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
|
||||
var viewModel = (DataContext as ControllerInputViewModel);
|
||||
|
||||
IKeyboard keyboard = (IKeyboard)viewModel.ParentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
|
||||
IKeyboard keyboard =
|
||||
(IKeyboard)viewModel.ParentModel.AvaloniaKeyboardDriver
|
||||
.GetGamepad("0"); // Open Avalonia keyboard for cancel operations.
|
||||
IButtonAssigner assigner = CreateButtonAssigner(isStick);
|
||||
|
||||
_currentAssigner.ButtonAssigned += (sender, e) =>
|
||||
@ -237,5 +241,48 @@ namespace Ryujinx.Ava.UI.Views.Input
|
||||
_currentAssigner?.Cancel();
|
||||
_currentAssigner = null;
|
||||
}
|
||||
|
||||
private void Control_OnUnloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_isRunning = false;
|
||||
}
|
||||
|
||||
|
||||
private void StartUpdatingData()
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
while (_isRunning)
|
||||
{
|
||||
var viewModel = (DataContext as ControllerInputViewModel);
|
||||
if (viewModel != null)
|
||||
{
|
||||
IGamepad gamepad = viewModel.ParentModel.SelectedGamepad;
|
||||
var config = viewModel.Config;
|
||||
|
||||
if (config.LeftJoystick != StickInputId.Unbound)
|
||||
{
|
||||
var stickInputId = (Ryujinx.Input.StickInputId)(int)config.LeftJoystick;
|
||||
(float leftAxisX, float leftAxisY) =
|
||||
gamepad.GetStick(stickInputId);
|
||||
viewModel.LeftStickPosition = NpadController.GetJoystickPosition(leftAxisX, leftAxisY,
|
||||
config.DeadzoneLeft, config.RangeLeft)
|
||||
.ToString();
|
||||
}
|
||||
|
||||
if (config.RightJoystick != StickInputId.Unbound)
|
||||
{
|
||||
var stickInputId = (Ryujinx.Input.StickInputId)(int)config.RightJoystick;
|
||||
(float rightAxisX, float rightAxisY) = gamepad.GetStick(stickInputId);
|
||||
viewModel.RightStickPosition = NpadController
|
||||
.GetJoystickPosition(rightAxisX, rightAxisY, config.DeadzoneRight, config.RangeRight)
|
||||
.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(100);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user