forked from Mirror/Ryujinx
d306115750
* Logging: Refactor log targets into Ryujinx.Common * Logger: Implement JSON Log Target * Logger: Optimize Console/File logging targets Implement a simple ObjectPool to pool up StringBuilders to avoid causing excessive GCing of gen1/2 items when large amounts of log entries are being generated. We can also pre-determine the async overflow action at initialization time, allowing for an easy optimization in the message enqueue function, avoiding a number of comparisons. * Logger: Implement LogFormatters * Config: Refactor configuration file and loading * Config: Rename to .jsonc to avoid highlighting issues in VSC and GitHub * Resolve style nits * Config: Resolve incorrect default key binding * Config: Also update key binding default in schema * Tidy up namespace imports * Config: Update CONFIG.md to reflect new Config file
101 lines
3.8 KiB
C#
101 lines
3.8 KiB
C#
using OpenTK.Input;
|
|
using Ryujinx.HLE.Input;
|
|
|
|
namespace Ryujinx.UI.Input
|
|
{
|
|
public struct NpadKeyboardLeft
|
|
{
|
|
public Key StickUp;
|
|
public Key StickDown;
|
|
public Key StickLeft;
|
|
public Key StickRight;
|
|
public Key StickButton;
|
|
public Key DPadUp;
|
|
public Key DPadDown;
|
|
public Key DPadLeft;
|
|
public Key DPadRight;
|
|
public Key ButtonMinus;
|
|
public Key ButtonL;
|
|
public Key ButtonZl;
|
|
}
|
|
|
|
public struct NpadKeyboardRight
|
|
{
|
|
public Key StickUp;
|
|
public Key StickDown;
|
|
public Key StickLeft;
|
|
public Key StickRight;
|
|
public Key StickButton;
|
|
public Key ButtonA;
|
|
public Key ButtonB;
|
|
public Key ButtonX;
|
|
public Key ButtonY;
|
|
public Key ButtonPlus;
|
|
public Key ButtonR;
|
|
public Key ButtonZr;
|
|
}
|
|
|
|
public class NpadKeyboard
|
|
{
|
|
/// <summary>
|
|
/// Left JoyCon Keyboard Bindings
|
|
/// </summary>
|
|
public NpadKeyboardLeft LeftJoycon { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Right JoyCon Keyboard Bindings
|
|
/// </summary>
|
|
public NpadKeyboardRight RightJoycon { get; private set; }
|
|
|
|
public HidControllerButtons GetButtons(KeyboardState keyboard)
|
|
{
|
|
HidControllerButtons buttons = 0;
|
|
|
|
if (keyboard[(Key)LeftJoycon.StickButton]) buttons |= HidControllerButtons.StickLeft;
|
|
if (keyboard[(Key)LeftJoycon.DPadUp]) buttons |= HidControllerButtons.DpadUp;
|
|
if (keyboard[(Key)LeftJoycon.DPadDown]) buttons |= HidControllerButtons.DpadDown;
|
|
if (keyboard[(Key)LeftJoycon.DPadLeft]) buttons |= HidControllerButtons.DpadLeft;
|
|
if (keyboard[(Key)LeftJoycon.DPadRight]) buttons |= HidControllerButtons.DPadRight;
|
|
if (keyboard[(Key)LeftJoycon.ButtonMinus]) buttons |= HidControllerButtons.Minus;
|
|
if (keyboard[(Key)LeftJoycon.ButtonL]) buttons |= HidControllerButtons.L;
|
|
if (keyboard[(Key)LeftJoycon.ButtonZl]) buttons |= HidControllerButtons.Zl;
|
|
|
|
if (keyboard[(Key)RightJoycon.StickButton]) buttons |= HidControllerButtons.StickRight;
|
|
if (keyboard[(Key)RightJoycon.ButtonA]) buttons |= HidControllerButtons.A;
|
|
if (keyboard[(Key)RightJoycon.ButtonB]) buttons |= HidControllerButtons.B;
|
|
if (keyboard[(Key)RightJoycon.ButtonX]) buttons |= HidControllerButtons.X;
|
|
if (keyboard[(Key)RightJoycon.ButtonY]) buttons |= HidControllerButtons.Y;
|
|
if (keyboard[(Key)RightJoycon.ButtonPlus]) buttons |= HidControllerButtons.Plus;
|
|
if (keyboard[(Key)RightJoycon.ButtonR]) buttons |= HidControllerButtons.R;
|
|
if (keyboard[(Key)RightJoycon.ButtonZr]) buttons |= HidControllerButtons.Zr;
|
|
|
|
return buttons;
|
|
}
|
|
|
|
public (short, short) GetLeftStick(KeyboardState keyboard)
|
|
{
|
|
short dx = 0;
|
|
short dy = 0;
|
|
|
|
if (keyboard[(Key)LeftJoycon.StickUp]) dy = short.MaxValue;
|
|
if (keyboard[(Key)LeftJoycon.StickDown]) dy = -short.MaxValue;
|
|
if (keyboard[(Key)LeftJoycon.StickLeft]) dx = -short.MaxValue;
|
|
if (keyboard[(Key)LeftJoycon.StickRight]) dx = short.MaxValue;
|
|
|
|
return (dx, dy);
|
|
}
|
|
|
|
public (short, short) GetRightStick(KeyboardState keyboard)
|
|
{
|
|
short dx = 0;
|
|
short dy = 0;
|
|
|
|
if (keyboard[(Key)RightJoycon.StickUp]) dy = short.MaxValue;
|
|
if (keyboard[(Key)RightJoycon.StickDown]) dy = -short.MaxValue;
|
|
if (keyboard[(Key)RightJoycon.StickLeft]) dx = -short.MaxValue;
|
|
if (keyboard[(Key)RightJoycon.StickRight]) dx = short.MaxValue;
|
|
|
|
return (dx, dy);
|
|
}
|
|
}
|
|
}
|