JoyConPair setting

This commit is contained in:
madwind 2025-01-15 00:27:13 +08:00
parent b8b3767613
commit 992fe0e64f
4 changed files with 49 additions and 36 deletions

View File

@ -1,5 +1,6 @@
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Configuration.Hid.Controller;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
@ -127,7 +128,6 @@ namespace Ryujinx.Input.SDL3
lock (_userMappingLock)
{
_configuration = (StandardControllerInputConfig)configuration;
_buttonsUserMapping.Clear();
// First update sticks

View File

@ -14,9 +14,9 @@
<style
type="text/css"
id="style1">
.button{fill:#ffffff;}
.button2{fill:#44484c;}
</style>
.button-letter{fill:#ffffff;}
.button{fill:#44484c;}
</style>
<g
id="layer1">
<path
@ -33,7 +33,7 @@
style="fill:#44484c;fill-opacity:1;stroke:#000000;stroke-width:0.624212px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="LeftShoulder"
class="button2"
class="button"
d="M 71.141642,4.5840631 V 1.9701729 c 0,-0.7845694 -0.801336,-1.65806689 -1.658066,-1.65806689 H 53.097985 c -25.276611,0 -47.9020118,20.38799499 -51.7794075,34.85862199 -0.1769423,0.660145 -0.2403108,1.986235 0.910356,1.986235 h 2.9103949 z"
style="fill-opacity:1;stroke:#000000;stroke-width:0.624212px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
@ -69,7 +69,7 @@
<rect
style="fill-opacity:1;stroke:#000000;stroke-width:0.624212;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="Back"
class="button2"
class="button"
width="13.84973"
height="3.9793589"
x="64.770714"
@ -80,16 +80,14 @@
cx="45.459122"
cy="71.1408"
r="20.013832" />
<circle
style="fill:#44484c;fill-opacity:1;stroke:#000000;stroke-width:0.624212;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3909"
cx="45.459122"
cy="71.279633"
r="14.034906" />
<path
id="path3913"
d="m 45.283504,90.058853 c -0.243093,-0.02724 -0.452358,-0.208017 -0.528892,-0.456894 -0.01416,-0.04954 -0.01651,-0.20608 -0.01888,-2.021978 l -0.0023,-1.968328 0.14415,0.0081 c 0.07928,0.0039 0.358107,0.0081 0.619698,0.0081 h 0.475597 l -0.0023,1.970175 -0.0023,1.970162 -0.02123,0.06335 c -0.06511,0.190578 -0.215869,0.340259 -0.406589,0.404173 -0.06227,0.02072 -0.180481,0.03175 -0.254751,0.02338 v 0 z"
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.0195065;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
id="path3913-8"
d="m 45.434622,52.223145 c 0.247163,0.02887 0.459932,0.220525 0.537747,0.484365 0.0144,0.05251 0.01677,0.218471 0.0192,2.143553 l 0.0023,2.086678 -0.146563,-0.0084 c -0.0806,-0.0041 -0.364103,-0.0084 -0.630075,-0.0084 h -0.483559 l 0.0023,-2.088635 0.0023,-2.088621 0.02158,-0.06716 c 0.0662,-0.202038 0.219482,-0.360718 0.413396,-0.428476 0.0633,-0.02196 0.183503,-0.03366 0.259017,-0.02479 v 0 z"
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.0202518;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
id="path3915"
d="m 59.806505,71.322008 c 0,-0.221406 -0.0049,-0.500259 -0.007,-0.619683 l -0.007,-0.217117 2.017096,0.0027 2.017072,0.0026 0.07149,0.02617 c 0.269118,0.0983 0.436388,0.346437 0.418197,0.620415 -0.0094,0.151847 -0.0696,0.285696 -0.175291,0.393668 -0.0828,0.08475 -0.1609,0.129639 -0.304646,0.175783 -0.03113,0.0093 -0.444127,0.01328 -2.033563,0.01527 l -1.994565,0.0027 v -0.402555 0 z"
@ -98,6 +96,13 @@
id="path3917"
d="m 26.928027,71.713911 c -0.13424,-0.01766 -0.265319,-0.0854 -0.360891,-0.186526 -0.332557,-0.351564 -0.164911,-0.91291 0.307243,-1.028164 0.04412,-0.01067 0.430158,-0.01329 2.153412,-0.01342 l 2.099786,-3.59e-4 -0.007,0.207261 c -0.0049,0.113964 -0.007,0.392698 -0.007,0.619339 v 0.412078 l -2.062819,-0.0012 c -1.134577,-6.38e-4 -2.08917,-0.0054 -2.12135,-0.0093 z"
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.0195065;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
style="fill-opacity:1;stroke:#000000;stroke-width:0.624212;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="LeftStick"
class="button"
cx="45.459122"
cy="71.279633"
r="14.034906" />
<rect
style="fill:#44484c;fill-opacity:1;stroke:#000000;stroke-width:0.624212;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3919"
@ -147,7 +152,7 @@
<path
style="fill-opacity:1;stroke:#000000;stroke-width:0.623304px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 193.42147,4.577397 V 1.967308 c 0,-0.783429 0.80019,-1.655656 1.65568,-1.655656 h 16.36178 c 25.2398,0 47.83231,20.35834 51.70409,34.807924 0.17669,0.65918 0.23999,1.98334 -0.90903,1.98334 h -2.90616 z"
class="button2"
class="button"
id="RightShoulder" />
<path
style="fill:#ff5f53;fill-opacity:1;stroke:#000000;stroke-width:0.623304px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
@ -156,7 +161,7 @@
<path
style="fill-opacity:1;stroke:#000000;stroke-width:0.623304px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
d="m 186.21364,27.4046 h 4.74192 v -4.6829 h 3.93517 v 4.702571 h 4.66326 v 3.935212 h -4.64356 v 4.859983 h -3.99421 v -4.859983 h -4.68296 z"
class="button2"
class="button"
id="Start" />
<circle
style="fill:#44484c;fill-opacity:1;stroke:#000000;stroke-width:0.623304;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
@ -206,12 +211,6 @@
cx="219.03548"
cy="141.86038"
r="19.984724" />
<circle
id="path3892"
style="fill:#44484c;fill-opacity:1;stroke:#000000;stroke-width:0.623304;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
cx="219.03548"
cy="141.99901"
r="14.014492" />
<path
style="fill:#000000;stroke:#000000;stroke-width:0.0194783;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 218.31129,125.58354 c 1.4e-4,-1.33699 0.007,-2.12691 0.009,-2.16939 0.0188,-0.12886 0.082,-0.25202 0.18022,-0.35026 0.29619,-0.29619 0.79996,-0.20825 0.98258,0.1715 0.0686,0.14229 0.0636,-0.0302 0.0638,2.31736 l 1.4e-4,2.12043 -0.43719,-5.2e-4 c -0.24048,-2.8e-4 -0.51879,0.002 -0.61844,0.007 l -0.18116,0.007 1.9e-4,-2.1026 z"
@ -228,25 +227,32 @@
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.0194783;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 200.53132,142.43266 c -0.13405,-0.0188 -0.26496,-0.0853 -0.36039,-0.18634 -0.3321,-0.35104 -0.16467,-0.91158 0.30679,-1.02666 0.0443,-0.0118 0.42951,-0.0141 2.15028,-0.0141 l 2.09673,-3.6e-4 -0.007,0.20684 c -0.007,0.11379 -0.007,0.39212 -0.007,0.61845 v 0.41148 l -2.05984,-0.001 c -1.13291,-6.4e-4 -2.08613,-0.005 -2.11824,-0.009 z"
id="path3905" />
<circle
id="RightStick"
class="button"
style="fill-opacity:1;stroke:#000000;stroke-width:0.623304;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
cx="219.03548"
cy="141.99901"
r="14.014492" />
<path
style="stroke:none;stroke-width:0.623304"
d="m 214.35736,54.921716 c 0,-0.007 0.76648,-1.18123 1.70331,-2.61159 l 1.70329,-2.60093 -1.50957,-2.33178 c -0.83025,-1.28245 -1.52861,-2.35884 -1.55183,-2.39188 l -0.0424,-0.0598 h 1.16815 1.16812 l 1.00159,1.60601 c 0.55088,0.88334 1.01121,1.60283 1.02292,1.5989 0.0118,-0.007 0.46006,-0.72416 0.99629,-1.60052 l 0.97485,-1.59348 1.15081,-0.007 c 0.63291,-0.007 1.15073,0 1.15073,0.007 0,0.007 -0.69378,1.09458 -1.54187,2.41861 -0.88264,1.37819 -1.53793,2.42229 -1.5327,2.44236 0.007,0.0193 0.76773,1.17686 1.69483,2.5725 0.9271,1.39558 1.68567,2.54309 1.68567,2.55007 0,0.007 -0.53828,0.0118 -1.19625,0.0118 h -1.19625 l -1.11192,-1.73772 c -0.89798,-1.40349 -1.11707,-1.73229 -1.13877,-1.70891 -0.0141,0.0156 -0.52084,0.79826 -1.12449,1.73865 l -1.09766,1.70972 h -1.18846 c -0.65366,0 -1.1885,-0.007 -1.1885,-0.0106 z"
id="X"
class="button" />
class="button-letter" />
<path
style="stroke:none;stroke-width:0.623304"
d="m 233.66024,74.293476 c 0.0375,-0.0993 3.7808,-9.70953 3.82834,-9.82896 l 0.0542,-0.1365 h 1.0542 1.0542 l 1.99265,4.97454 c 1.09596,2.736 1.99762,4.98688 2.00375,5.00202 0.009,0.0219 -0.20896,0.0262 -1.07672,0.0212 l -1.08791,-0.006 -0.43799,-1.14115 -0.43799,-1.14114 -2.00924,0.006 -2.00921,0.006 -0.41427,1.14127 -0.41424,1.14121 h -1.05719 c -0.99785,0 -1.05644,-0.006 -1.0428,-0.038 z m 6.29682,-3.94253 c -0.007,-0.0151 -0.31794,-0.85573 -0.69393,-1.86829 -0.37591,-1.01256 -0.69006,-1.83327 -0.69802,-1.82386 -0.0118,0.0125 -0.81417,2.21149 -1.34922,3.69215 -0.007,0.0212 0.27556,0.0268 1.37084,0.0268 1.09559,0 1.37862,-0.006 1.37033,-0.0268 z"
id="A"
class="button" />
class="button-letter" />
<path
style="stroke:none;stroke-width:0.623304"
d="m 215.2136,89.120286 v -4.99274 l 2.4681,0.009 c 2.46075,0.0118 2.72639,0.0188 3.21986,0.0935 0.74879,0.11379 1.36342,0.49628 1.76906,1.10127 0.6167,0.91968 0.51717,2.11947 -0.24264,2.92491 -0.17716,0.18776 -0.3468,0.31926 -0.58323,0.45178 l -0.18352,0.10294 0.14866,0.0492 c 0.36246,0.11944 0.74591,0.33919 1.00328,0.57481 0.30204,0.27636 0.56214,0.71499 0.67522,1.13859 0.0518,0.19294 0.0573,0.25487 0.0591,0.61757 0,0.31452 -0.007,0.44272 -0.0379,0.58334 -0.1258,0.57277 -0.40347,1.10525 -0.77185,1.48074 -0.47147,0.48049 -1.04977,0.72422 -1.87578,0.79054 -0.41144,0.033 -2.41554,0.0643 -4.16112,0.065 h -1.48738 v -4.99274 z m 4.97634,3.2926 c 0.46106,-0.0379 0.70688,-0.13169 0.95047,-0.36149 0.25189,-0.23761 0.35622,-0.51213 0.35542,-0.9349 0,-0.65174 -0.35417,-1.10836 -0.9675,-1.25173 -0.35523,-0.0829 -0.56372,-0.0942 -1.95312,-0.10437 l -1.35664,-0.009 v 1.34229 1.34236 h 1.35664 c 0.74608,-1.9e-4 1.47275,-0.009 1.61473,-0.0212 v 0 z m -0.80295,-4.31363 c 0.72759,-0.0212 0.87325,-0.0417 1.13555,-0.16608 0.27438,-0.13004 0.46767,-0.34631 0.55898,-0.62519 0.0624,-0.19058 0.0624,-0.57978 -6.4e-4,-0.7735 -0.11755,-0.36345 -0.3875,-0.5975 -0.80238,-0.69581 -0.12934,-0.0306 -0.3557,-0.0368 -1.60531,-0.045 l -1.45466,-0.009 v 1.16751 1.16758 h 0.75724 c 0.41656,0 1.05152,-0.009 1.41111,-0.0188 v 0 z"
id="B"
class="button" />
class="button-letter" />
<path
style="stroke:none;stroke-width:0.623304"
d="m 198.44799,72.424996 v -2.1001 l -1.81569,-2.87051 c -0.99867,-1.57871 -1.81575,-2.8745 -1.81575,-2.87942 0,-0.006 0.52108,-0.009 1.15792,-0.009 l 1.15797,2.5e-4 1.17418,1.97688 c 0.87332,1.47019 1.18042,1.97033 1.19825,1.95138 0.0141,-0.0137 0.53524,-0.90373 1.16002,-1.97706 l 1.13592,-1.95163 h 1.14209 1.14202 l -0.0311,0.0492 c -0.0165,0.0268 -0.8403,1.32677 -1.82909,2.88865 l -1.79774,2.83972 v 2.09094 2.09094 h -0.98943 -0.98939 v -2.10017 z"
id="Y"
class="button" />
class="button-letter" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -70,7 +70,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
Image = ParentModel.Image;
}
public void UpdateImage(string css)
public void UpdateImageCss(string css)
{
Image = new SvgImage { Source = ParentModel.Image.Source, Css = css };
}

View File

@ -6,8 +6,10 @@ using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.Threading;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.Models.Input;
using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.HLE.HOS.Services.Hid;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using Ryujinx.Input.HLE;
@ -250,20 +252,24 @@ namespace Ryujinx.Ava.UI.Views.Input
_isRunning = false;
}
private string BuildSvgCss(IGamepad gamepad)
private string BuildSvgCss(IGamepad gamepad, GamepadInputConfig config, JoystickPosition leftPosition,
JoystickPosition rightPosition)
{
StringBuilder sb = new StringBuilder();
for(var i=0;i<(int)GamepadInputId.Count;i++)
gamepad.SetConfiguration(config.GetConfig());
StringBuilder sb = new();
for (var i = 0; i < (int)GamepadInputId.Count; i++)
{
var button = (GamepadButtonInputId)i;
if (gamepad.GetMappedStateSnapshot().IsPressed(button))
{
sb.Append($"#{button}{{fill:#00bbdb;}}");
}
}
Console.WriteLine(sb.ToString());
sb.Append(
$"#LeftStick{{transform: translate ({(float)leftPosition.Dx / short.MaxValue * 10} {-(float)leftPosition.Dy / short.MaxValue * 10});}}");
sb.Append(
$"#RightStick{{transform: translate ({(float)rightPosition.Dx / short.MaxValue * 10} {-(float)rightPosition.Dy / short.MaxValue * 10});}}");
return sb.ToString();
}
@ -277,26 +283,27 @@ namespace Ryujinx.Ava.UI.Views.Input
if (viewModel != null)
{
IGamepad gamepad = viewModel.ParentModel.SelectedGamepad;
viewModel.UpdateImage(BuildSvgCss(gamepad));
var config = viewModel.Config;
JoystickPosition leftPosition = default, rightposition = default;
if (config.LeftJoystick != StickInputId.Unbound)
{
var stickInputId = (Ryujinx.Input.StickInputId)(int)config.LeftJoystick;
(float leftAxisX, float leftAxisY) = gamepad.GetStick(stickInputId);
var position = NpadController.GetJoystickPosition(leftAxisX, leftAxisY,
leftPosition = NpadController.GetJoystickPosition(leftAxisX, leftAxisY,
config.DeadzoneLeft, config.RangeLeft);
viewModel.LeftStickPosition = $"{position.Dx}, {position.Dy}";
viewModel.LeftStickPosition = $"{leftPosition.Dx}, {leftPosition.Dy}";
}
if (config.RightJoystick != StickInputId.Unbound)
{
var stickInputId = (Ryujinx.Input.StickInputId)(int)config.RightJoystick;
(float rightAxisX, float rightAxisY) = gamepad.GetStick(stickInputId);
var position = NpadController.GetJoystickPosition(rightAxisX, rightAxisY,
rightposition = NpadController.GetJoystickPosition(rightAxisX, rightAxisY,
config.DeadzoneRight, config.RangeRight);
viewModel.RightStickPosition = $"{position.Dx}, {position.Dy}";
viewModel.RightStickPosition = $"{rightposition.Dx}, {rightposition.Dy}";
}
viewModel.UpdateImageCss(BuildSvgCss(gamepad, config, leftPosition, rightposition));
}
await Task.Delay(100);