.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using Engine.Scene;
|
||||
using System.Globalization;
|
||||
using Engine.Scene;
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
namespace Engine.Input;
|
||||
|
||||
public interface IInputHandler : IUpdate
|
||||
{
|
||||
CultureInfo CurrentInputLanguage { get; }
|
||||
|
||||
Vector2 MousePosition { get; }
|
||||
|
||||
bool IsKeyPressed(KeyboardButtonCode parKeyboardButtonCode);
|
||||
|
||||
@@ -74,6 +74,16 @@ public static class KeyboardButtonCodeHelper
|
||||
or >= KeyboardButtonCode.D1 and <= KeyboardButtonCode.D0 or KeyboardButtonCode.Space;
|
||||
|
||||
public static char GetChar(this KeyboardButtonCode parKey)
|
||||
{
|
||||
return Engine.Instance.InputHandler!.CurrentInputLanguage.Name switch
|
||||
{
|
||||
"en-US" => GetEnChar(parKey),
|
||||
"ru-RU" => GetRuChar(parKey),
|
||||
_ => GetEnChar(parKey)
|
||||
};
|
||||
}
|
||||
|
||||
private static char GetEnChar(this KeyboardButtonCode parKey)
|
||||
{
|
||||
return parKey switch
|
||||
{
|
||||
@@ -119,4 +129,51 @@ public static class KeyboardButtonCodeHelper
|
||||
_ => '\0'
|
||||
};
|
||||
}
|
||||
|
||||
private static char GetRuChar(this KeyboardButtonCode parKey)
|
||||
{
|
||||
return parKey switch
|
||||
{
|
||||
KeyboardButtonCode.A => 'Ф',
|
||||
KeyboardButtonCode.B => 'И',
|
||||
KeyboardButtonCode.C => 'С',
|
||||
KeyboardButtonCode.D => 'В',
|
||||
KeyboardButtonCode.E => 'У',
|
||||
KeyboardButtonCode.F => 'А',
|
||||
KeyboardButtonCode.G => 'П',
|
||||
KeyboardButtonCode.H => 'Р',
|
||||
KeyboardButtonCode.I => 'Ш',
|
||||
KeyboardButtonCode.J => 'О',
|
||||
KeyboardButtonCode.K => 'Л',
|
||||
KeyboardButtonCode.L => 'Д',
|
||||
KeyboardButtonCode.M => 'Ь',
|
||||
KeyboardButtonCode.N => 'Т',
|
||||
KeyboardButtonCode.O => 'Щ',
|
||||
KeyboardButtonCode.P => 'З',
|
||||
KeyboardButtonCode.Q => 'Й',
|
||||
KeyboardButtonCode.R => 'К',
|
||||
KeyboardButtonCode.S => 'Ы',
|
||||
KeyboardButtonCode.T => 'Е',
|
||||
KeyboardButtonCode.U => 'Г',
|
||||
KeyboardButtonCode.V => 'М',
|
||||
KeyboardButtonCode.W => 'Ц',
|
||||
KeyboardButtonCode.X => 'Ч',
|
||||
KeyboardButtonCode.Y => 'Н',
|
||||
KeyboardButtonCode.Z => 'Я',
|
||||
|
||||
KeyboardButtonCode.D1 => '1',
|
||||
KeyboardButtonCode.D2 => '2',
|
||||
KeyboardButtonCode.D3 => '3',
|
||||
KeyboardButtonCode.D4 => '4',
|
||||
KeyboardButtonCode.D5 => '5',
|
||||
KeyboardButtonCode.D6 => '6',
|
||||
KeyboardButtonCode.D7 => '7',
|
||||
KeyboardButtonCode.D8 => '8',
|
||||
KeyboardButtonCode.D9 => '9',
|
||||
KeyboardButtonCode.D0 => '0',
|
||||
|
||||
KeyboardButtonCode.Space => ' ',
|
||||
_ => '\0'
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using OpenTK.Mathematics;
|
||||
using System.Globalization;
|
||||
using OpenTK.Mathematics;
|
||||
using OpenTK.Windowing.GraphicsLibraryFramework;
|
||||
|
||||
namespace Engine.Input;
|
||||
|
||||
public class WindowInputHandler(Window parWindow) : IInputHandler
|
||||
{
|
||||
public CultureInfo CurrentInputLanguage => new(1033);
|
||||
public Vector2 MousePosition => parWindow.NativeWindow.MouseState.Position;
|
||||
|
||||
private KeyboardState _previousKeyboardState = parWindow.NativeWindow.KeyboardState.GetSnapshot();
|
||||
|
||||
Reference in New Issue
Block a user