.
This commit is contained in:
@@ -10,9 +10,4 @@
|
||||
<ProjectReference Include="..\Engine\Engine.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="asset\model\" />
|
||||
<Folder Include="data\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 MiB |
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@
|
||||
using DoomDeathmatch.Component.MVC.Timer;
|
||||
using DoomDeathmatch.Component.UI;
|
||||
using DoomDeathmatch.Scene.GameOver;
|
||||
using DoomDeathmatch.Scene.Play;
|
||||
using Engine.Input;
|
||||
using Engine.Util;
|
||||
|
||||
|
||||
@@ -60,9 +60,13 @@ public class TextInputComponent : Engine.Scene.Component.Component
|
||||
}
|
||||
else
|
||||
{
|
||||
Input += key.GetChar();
|
||||
var charCode = key.GetChar();
|
||||
if (charCode != '\0')
|
||||
{
|
||||
Input += charCode;
|
||||
invoke = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (invoke)
|
||||
OnInput?.Invoke(Input);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using DoomDeathmatch.Scene;
|
||||
using DoomDeathmatch.Scene.Main;
|
||||
using DoomDeathmatch.Scene.Main;
|
||||
|
||||
namespace DoomDeathmatch;
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using DoomDeathmatch.Component.UI;
|
||||
using DoomDeathmatch.Component.Util;
|
||||
using DoomDeathmatch.Component.UI;
|
||||
using DoomDeathmatch.Scene.Play;
|
||||
using DoomDeathmatch.Script.Score;
|
||||
using DoomDeathmatch.Script.UI;
|
||||
using Engine.Graphics.Pipeline;
|
||||
using Engine.Scene;
|
||||
using Engine.Scene.Component.BuiltIn;
|
||||
using Engine.Scene.Component.BuiltIn.Renderer;
|
||||
using Engine.Util;
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using Engine.Input;
|
||||
using System.Globalization;
|
||||
using Engine.Input;
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
namespace PresenterConsole;
|
||||
|
||||
public class ConsoleInputHandler : IInputHandler
|
||||
{
|
||||
public CultureInfo CurrentInputLanguage => WindowsFFI.GetCurrentKeyboardLayout();
|
||||
|
||||
public Vector2 MousePosition => Vector2.Zero;
|
||||
|
||||
private readonly bool[] _currentKeys = new bool[256];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
@@ -67,4 +68,28 @@ public static partial class WindowsFFI
|
||||
|
||||
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetAsyncKeyState")]
|
||||
public static partial short GetAsyncKeyState(int parKeyCode);
|
||||
|
||||
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetForegroundWindow")]
|
||||
public static partial IntPtr GetForegroundWindow();
|
||||
|
||||
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowThreadProcessId")]
|
||||
public static partial uint GetWindowThreadProcessId(IntPtr parHwnd, IntPtr parLpdwProcessId);
|
||||
|
||||
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetKeyboardLayout")]
|
||||
public static partial IntPtr GetKeyboardLayout(uint parThreadId);
|
||||
|
||||
public static CultureInfo GetCurrentKeyboardLayout()
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr foregroundWindow = GetForegroundWindow();
|
||||
uint foregroundProcess = GetWindowThreadProcessId(foregroundWindow, IntPtr.Zero);
|
||||
int keyboardLayout = GetKeyboardLayout(foregroundProcess).ToInt32() & 0xFFFF;
|
||||
return new CultureInfo(keyboardLayout);
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
return new CultureInfo(1033); // Assume English if something went wrong.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Engine;
|
||||
using Engine.Graphics;
|
||||
@@ -55,6 +56,8 @@ public partial class App : Application
|
||||
|
||||
private class InputHandlerWrapper : IInputHandler
|
||||
{
|
||||
public CultureInfo CurrentInputLanguage => _inputHandler?.CurrentInputLanguage ?? new CultureInfo(1033);
|
||||
|
||||
public Vector2 MousePosition => _inputHandler?.MousePosition ?? Vector2.Zero;
|
||||
|
||||
private IInputHandler? _inputHandler;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Engine.Input;
|
||||
using OpenTK.Mathematics;
|
||||
@@ -7,6 +8,7 @@ namespace PresenterWpf;
|
||||
|
||||
public class WpfInputHandler : IInputHandler
|
||||
{
|
||||
public CultureInfo CurrentInputLanguage { get; private set; }
|
||||
public Vector2 MousePosition => _mousePosition;
|
||||
|
||||
private readonly Window _window;
|
||||
@@ -35,6 +37,11 @@ public class WpfInputHandler : IInputHandler
|
||||
|
||||
public void Update(double parDeltaTime)
|
||||
{
|
||||
_window.Dispatcher.Invoke(() =>
|
||||
{
|
||||
CurrentInputLanguage = InputLanguageManager.Current.CurrentInputLanguage;
|
||||
});
|
||||
|
||||
for (var i = 0; i < _currentKeys.Length; i++)
|
||||
{
|
||||
_previousKeys[i] = _currentKeys[i];
|
||||
|
||||
Reference in New Issue
Block a user