Faction Test 100.9.0.0

This commit is contained in:
Markus Isberg
2022-12-05 19:55:31 +02:00
parent f7f1ebd979
commit 55e1d3560a
55 changed files with 347 additions and 3512 deletions
@@ -1,72 +1,18 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace EventInput
{
public class CharacterEventArgs : EventArgs
public readonly record struct CharacterEventArgs(char Character, long Param)
{
private readonly char character;
private readonly long lParam;
public CharacterEventArgs(char character, long lParam)
{
this.character = character;
this.lParam = lParam;
}
public char Character
{
get { return character; }
}
public long Param
{
get { return lParam; }
}
public long RepeatCount
{
get { return lParam & 0xffff; }
}
public bool ExtendedKey
{
get { return (lParam & (1 << 24)) > 0; }
}
public bool AltPressed
{
get { return (lParam & (1 << 29)) > 0; }
}
public bool PreviousState
{
get { return (lParam & (1 << 30)) > 0; }
}
public bool TransitionState
{
get { return (lParam & (1 << 31)) > 0; }
}
public long RepeatCount => Param & 0xffff;
public bool ExtendedKey => (Param & (1 << 24)) > 0;
public bool AltPressed => (Param & (1 << 29)) > 0;
public bool PreviousState => (Param & (1 << 30)) > 0;
public bool TransitionState => (Param & (1 << 31)) > 0;
}
public class KeyEventArgs : EventArgs
{
private Keys keyCode;
public KeyEventArgs(Keys keyCode)
{
this.keyCode = keyCode;
}
public Keys KeyCode
{
get { return keyCode; }
}
}
public readonly record struct KeyEventArgs(Keys KeyCode, char Character);
public delegate void CharEnteredHandler(object sender, CharacterEventArgs e);
public delegate void KeyEventHandler(object sender, KeyEventArgs e);
@@ -89,14 +35,11 @@ namespace EventInput
/// </summary>
public static event KeyEventHandler KeyUp;
#if !WINDOWS
/// <summary>
/// Raised when the user is editing text and IME is in progress.
/// Windows build uses ImeSharp instead because SDL2's IME implementation is broken on Windows (https://github.com/libsdl-org/SDL/issues/2243)
/// </summary>
public static event EditingTextHandler EditingText;
#endif
static bool initialized;
@@ -110,11 +53,10 @@ namespace EventInput
{
return;
}
window.TextInput += ReceiveInput;
#if !WINDOWS
window.KeyDown += ReceiveKeyDown;
window.TextEditing += ReceiveTextEditing;
#endif
initialized = true;
}
@@ -122,15 +64,17 @@ namespace EventInput
private static void ReceiveInput(object sender, TextInputEventArgs e)
{
OnCharEntered(e.Character);
KeyDown?.Invoke(sender, new KeyEventArgs(e.Key));
}
#if !WINDOWS
private static void ReceiveKeyDown(object sender, TextInputEventArgs e)
{
KeyDown?.Invoke(sender, new KeyEventArgs(e.Key, e.Character));
}
private static void ReceiveTextEditing(object sender, TextEditingEventArgs e)
{
EditingText?.Invoke(sender, e);
}
#endif
public static void OnCharEntered(char character)
{
@@ -10,11 +10,7 @@ namespace EventInput
void ReceiveTextInput(string text);
void ReceiveCommandInput(char command);
void ReceiveSpecialInput(Keys key);
#if !WINDOWS
/// Windows build uses ImeSharp instead because SDL2's IME implementation is broken on Windows (https://github.com/libsdl-org/SDL/issues/2243)
void ReceiveEditingInput(string text, int start);
#endif
void ReceiveEditingInput(string text, int start, int length);
bool Selected { get; set; } //or Focused
}
@@ -26,59 +22,27 @@ namespace EventInput
EventInput.Initialize(window);
EventInput.CharEntered += EventInput_CharEntered;
EventInput.KeyDown += EventInput_KeyDown;
#if !WINDOWS
EventInput.EditingText += EventInput_TextEditing;
#endif
/*
* SDL by default starts in a state where it accepts IME inputs
* this is bad because this blocks keybinds since the IME thinks
* it's typing in a text box and not forwarding keybinds to the game.
*/
TextInput.StopTextInput();
GameMain.ResetIMEWorkaround();
}
#if !WINDOWS
public void EventInput_TextEditing(object sender, TextEditingEventArgs e)
{
_subscriber?.ReceiveEditingInput(e.Text, e.Start);
_subscriber?.ReceiveEditingInput(e.Text, e.Start, e.Length);
}
#endif
public void EventInput_KeyDown(object sender, KeyEventArgs e)
{
_subscriber?.ReceiveSpecialInput(e.KeyCode);
if (char.IsControl(e.Character))
{
_subscriber?.ReceiveCommandInput(e.Character);
}
}
void EventInput_CharEntered(object sender, CharacterEventArgs e)
{
if (_subscriber == null)
return;
if (char.IsControl(e.Character))
{
_subscriber.ReceiveCommandInput(e.Character);
// Doesn't work as expected. Not sure why this should be run in a separate thread.
//#if WINDOWS
// //ctrl-v
// if (e.Character == 0x16) // 22
// {
// //XNA runs in Multiple Thread Apartment state, which cannot recieve clipboard
// Thread thread = new Thread(PasteThread);
// thread.SetApartmentState(ApartmentState.STA);
// thread.Start();
// thread.Join();
// _subscriber.ReceiveTextInput(_pasteResult);
// }
// else
// {
// _subscriber.ReceiveCommandInput(e.Character);
// }
//#else
// _subscriber.ReceiveCommandInput(e.Character);
//#endif
}
else
{
_subscriber.ReceiveTextInput(e.Character);
}
_subscriber?.ReceiveTextInput(e.Character);
}
IKeyboardSubscriber _subscriber;
@@ -97,8 +61,9 @@ namespace EventInput
if (value is GUITextBox box)
{
TextInput.SetTextInputRect(box.Rect);
TextInput.SetTextInputRect(box.MouseRect);
TextInput.StartTextInput();
TextInput.SetTextInputRect(box.MouseRect);
}
_subscriber = value;