Client LuaCsForBarotrauma
KeyboardDispatcher.cs
1 using Barotrauma;
2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Input;
4 
5 namespace EventInput
6 {
7  public interface IKeyboardSubscriber
8  {
9  void ReceiveTextInput(char inputChar);
10  void ReceiveTextInput(string text);
11  void ReceiveCommandInput(char command);
12  void ReceiveSpecialInput(Keys key);
13  void ReceiveEditingInput(string text, int start, int length);
14 
15  bool Selected { get; set; } //or Focused
16  }
17 
18  public class KeyboardDispatcher
19  {
20  public KeyboardDispatcher(GameWindow window)
21  {
22  EventInput.Initialize(window);
23  EventInput.CharEntered += EventInput_CharEntered;
24  EventInput.KeyDown += EventInput_KeyDown;
25  EventInput.EditingText += EventInput_TextEditing;
27  }
28 
29  public void EventInput_TextEditing(object sender, TextEditingEventArgs e)
30  {
31  _subscriber?.ReceiveEditingInput(e.Text, e.Start, e.Length);
32  }
33 
34  public void EventInput_KeyDown(object sender, KeyEventArgs e)
35  {
36  _subscriber?.ReceiveSpecialInput(e.KeyCode);
37  if (char.IsControl(e.Character))
38  {
39  _subscriber?.ReceiveCommandInput(e.Character);
40  }
41  }
42 
43  void EventInput_CharEntered(object sender, CharacterEventArgs e)
44  {
45  _subscriber?.ReceiveTextInput(e.Character);
46  }
47 
48  IKeyboardSubscriber _subscriber;
50  {
51  get { return _subscriber; }
52  set
53  {
54  if (_subscriber == value) { return; }
55 
56  if (_subscriber is GUITextBox)
57  {
58  TextInput.StopTextInput();
59  _subscriber.Selected = false;
60  }
61 
62  if (value is GUITextBox box)
63  {
64  TextInput.SetTextInputRect(box.MouseRect);
65  TextInput.StartTextInput();
66  TextInput.SetTextInputRect(box.MouseRect);
67  }
68 
69  _subscriber = value;
70  if (value != null)
71  {
72  value.Selected = true;
73  }
74  }
75  }
76  }
77 }
static void ResetIMEWorkaround()
Definition: GameMain.cs:1316
KeyboardDispatcher(GameWindow window)
void EventInput_TextEditing(object sender, TextEditingEventArgs e)
void EventInput_KeyDown(object sender, KeyEventArgs e)
void ReceiveTextInput(char inputChar)
void ReceiveEditingInput(string text, int start, int length)
void ReceiveSpecialInput(Keys key)
void ReceiveTextInput(string text)
void ReceiveCommandInput(char command)
readonly record struct KeyEventArgs(Keys KeyCode, char Character)
readonly record struct CharacterEventArgs(char Character, long Param)
Definition: EventInput.cs:6