about summary refs log tree commit diff stats
path: root/AnodyneArchipelago/Menu
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-26 16:26:23 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-26 16:26:23 -0400
commit73db3c666e078db25c3af6e54f2db066523e4298 (patch)
tree7b93af680b67654b8c81236d8352300b07092787 /AnodyneArchipelago/Menu
parent9b56f642406e4b8732e6078e77fcfc35c123f9bb (diff)
downloadanodyne-archipelago-73db3c666e078db25c3af6e54f2db066523e4298.tar.gz
anodyne-archipelago-73db3c666e078db25c3af6e54f2db066523e4298.tar.bz2
anodyne-archipelago-73db3c666e078db25c3af6e54f2db066523e4298.zip
Switch to using TextInputEXT
Diffstat (limited to 'AnodyneArchipelago/Menu')
-rw-r--r--AnodyneArchipelago/Menu/InputHandler.cs112
-rw-r--r--AnodyneArchipelago/Menu/TextEntry.cs45
2 files changed, 35 insertions, 122 deletions
diff --git a/AnodyneArchipelago/Menu/InputHandler.cs b/AnodyneArchipelago/Menu/InputHandler.cs deleted file mode 100644 index 432b40c..0000000 --- a/AnodyneArchipelago/Menu/InputHandler.cs +++ /dev/null
@@ -1,112 +0,0 @@
1using AnodyneSharp.Input;
2using Microsoft.Xna.Framework.Input;
3using System.Collections.Generic;
4using System.Threading;
5
6namespace AnodyneArchipelago.Menu
7{
8 internal class InputCharacter
9 {
10 private readonly string _upper;
11 private readonly string _lower;
12 private readonly Keys _code;
13
14 public InputCharacter(string upper, string lower, Keys code)
15 {
16 _upper = upper;
17 _lower = lower;
18 _code = code;
19 }
20
21 public string ReturnCharacter(bool shiftDown)
22 {
23 return shiftDown ? _upper : _lower;
24 }
25
26 public Keys ReturnKey()
27 {
28 return _code;
29 }
30 }
31
32 internal class InputHandler
33 {
34 private static List<InputCharacter> _characters = new();
35
36 static InputHandler()
37 {
38 _characters.Add(new InputCharacter("A", "a", Keys.A));
39 _characters.Add(new InputCharacter("B", "b", Keys.B));
40 _characters.Add(new InputCharacter("C", "c", Keys.C));
41 _characters.Add(new InputCharacter("D", "d", Keys.D));
42 _characters.Add(new InputCharacter("E", "e", Keys.E));
43 _characters.Add(new InputCharacter("F", "f", Keys.F));
44 _characters.Add(new InputCharacter("G", "g", Keys.G));
45 _characters.Add(new InputCharacter("H", "h", Keys.H));
46 _characters.Add(new InputCharacter("I", "i", Keys.I));
47 _characters.Add(new InputCharacter("J", "j", Keys.J));
48 _characters.Add(new InputCharacter("K", "k", Keys.K));
49 _characters.Add(new InputCharacter("L", "l", Keys.L));
50 _characters.Add(new InputCharacter("M", "m", Keys.M));
51 _characters.Add(new InputCharacter("N", "n", Keys.N));
52 _characters.Add(new InputCharacter("O", "o", Keys.O));
53 _characters.Add(new InputCharacter("P", "p", Keys.P));
54 _characters.Add(new InputCharacter("Q", "q", Keys.Q));
55 _characters.Add(new InputCharacter("R", "r", Keys.R));
56 _characters.Add(new InputCharacter("S", "s", Keys.S));
57 _characters.Add(new InputCharacter("T", "t", Keys.T));
58 _characters.Add(new InputCharacter("U", "u", Keys.U));
59 _characters.Add(new InputCharacter("V", "v", Keys.V));
60 _characters.Add(new InputCharacter("W", "w", Keys.W));
61 _characters.Add(new InputCharacter("X", "x", Keys.X));
62 _characters.Add(new InputCharacter("Y", "y", Keys.Y));
63 _characters.Add(new InputCharacter("Z", "z", Keys.Z));
64
65 _characters.Add(new InputCharacter("!", "1", Keys.D1));
66 _characters.Add(new InputCharacter("@", "2", Keys.D2));
67 _characters.Add(new InputCharacter("#", "3", Keys.D3));
68 _characters.Add(new InputCharacter("$", "4", Keys.D4));
69 _characters.Add(new InputCharacter("%", "5", Keys.D5));
70 _characters.Add(new InputCharacter("^", "6", Keys.D6));
71 _characters.Add(new InputCharacter("&", "7", Keys.D7));
72 _characters.Add(new InputCharacter("*", "8", Keys.D8));
73 _characters.Add(new InputCharacter("(", "9", Keys.D9));
74 _characters.Add(new InputCharacter(")", "0", Keys.D0));
75
76 _characters.Add(new InputCharacter(" ", " ", Keys.Space));
77 _characters.Add(new InputCharacter("<", ",", Keys.OemComma));
78 _characters.Add(new InputCharacter("+", "=", Keys.OemPlus));
79 _characters.Add(new InputCharacter("?", "/", Keys.OemQuestion));
80 _characters.Add(new InputCharacter(">", ".", Keys.OemPeriod));
81 _characters.Add(new InputCharacter("_", "-", Keys.OemMinus));
82 _characters.Add(new InputCharacter("{", "[", Keys.OemOpenBrackets));
83 _characters.Add(new InputCharacter("}", "]", Keys.OemCloseBrackets));
84 _characters.Add(new InputCharacter("|", "\"", Keys.OemBackslash));
85 _characters.Add(new InputCharacter(":", ";", Keys.OemSemicolon));
86 }
87
88 public static string ReturnCharacter()
89 {
90 if (KeyInput.JustPressedKey(Keys.V) && (KeyInput.IsKeyPressed(Keys.LeftControl) || KeyInput.IsKeyPressed(Keys.RightControl)))
91 {
92 string result = "";
93 Thread clipboardThread = new(() => result = System.Windows.Forms.Clipboard.GetText());
94 clipboardThread.SetApartmentState(ApartmentState.STA);
95 clipboardThread.Start();
96 clipboardThread.Join();
97
98 return result;
99 }
100
101 foreach (InputCharacter inputCharacter in _characters)
102 {
103 if (KeyInput.JustPressedKey(inputCharacter.ReturnKey()))
104 {
105 return inputCharacter.ReturnCharacter(KeyInput.IsKeyPressed(Keys.LeftShift) || KeyInput.IsKeyPressed(Keys.RightShift));
106 }
107 }
108
109 return "";
110 }
111 }
112}
diff --git a/AnodyneArchipelago/Menu/TextEntry.cs b/AnodyneArchipelago/Menu/TextEntry.cs index 8be54f5..2bcdf1b 100644 --- a/AnodyneArchipelago/Menu/TextEntry.cs +++ b/AnodyneArchipelago/Menu/TextEntry.cs
@@ -3,6 +3,8 @@ using AnodyneSharp.Sounds;
3using AnodyneSharp.States; 3using AnodyneSharp.States;
4using AnodyneSharp.UI; 4using AnodyneSharp.UI;
5using Microsoft.Xna.Framework; 5using Microsoft.Xna.Framework;
6using Microsoft.Xna.Framework.Input;
7using System.Threading;
6 8
7namespace AnodyneArchipelago.Menu 9namespace AnodyneArchipelago.Menu
8{ 10{
@@ -29,18 +31,15 @@ namespace AnodyneArchipelago.Menu
29 _valueLabel = new(new Vector2(20f, 52f), false, "", new Color(), AnodyneSharp.Drawing.DrawOrder.TEXT); 31 _valueLabel = new(new Vector2(20f, 52f), false, "", new Color(), AnodyneSharp.Drawing.DrawOrder.TEXT);
30 _bgBox = new UIEntity(new Vector2(16f, 40f), "pop_menu", 16, 16, AnodyneSharp.Drawing.DrawOrder.TEXTBOX); 32 _bgBox = new UIEntity(new Vector2(16f, 40f), "pop_menu", 16, 16, AnodyneSharp.Drawing.DrawOrder.TEXTBOX);
31 33
34 TextInputEXT.TextInput += OnTextInput;
35 TextInputEXT.StartTextInput();
36
32 UpdateDisplay(); 37 UpdateDisplay();
33 } 38 }
34 39
35 public override void Update() 40 private void OnTextInput(char ch)
36 { 41 {
37 string inputtedCharacter = InputHandler.ReturnCharacter(); 42 if (ch == '\b')
38 if (inputtedCharacter.Length > 0)
39 {
40 _value += inputtedCharacter;
41 UpdateDisplay();
42 }
43 else if (KeyInput.JustPressedKey(Microsoft.Xna.Framework.Input.Keys.Back))
44 { 43 {
45 if (_value.Length > 0) 44 if (_value.Length > 0)
46 { 45 {
@@ -48,17 +47,43 @@ namespace AnodyneArchipelago.Menu
48 UpdateDisplay(); 47 UpdateDisplay();
49 } 48 }
50 } 49 }
51 else if (KeyInput.JustPressedKey(Microsoft.Xna.Framework.Input.Keys.Escape) || (KeyInput.ControllerMode && KeyInput.JustPressedRebindableKey(KeyFunctions.Cancel))) 50 else if (ch == 22)
51 {
52 string result = "";
53 Thread clipboardThread = new(() => result = System.Windows.Forms.Clipboard.GetText());
54 clipboardThread.SetApartmentState(ApartmentState.STA);
55 clipboardThread.Start();
56 clipboardThread.Join();
57
58 _value += result;
59 UpdateDisplay();
60 }
61 else if (!char.IsControl(ch))
62 {
63 _value += ch;
64 UpdateDisplay();
65 }
66 }
67
68 public override void Update()
69 {
70 if (KeyInput.JustPressedKey(Keys.Escape) || (KeyInput.ControllerMode && KeyInput.JustPressedRebindableKey(KeyFunctions.Cancel)))
52 { 71 {
53 SoundManager.PlaySoundEffect("menu_select"); 72 SoundManager.PlaySoundEffect("menu_select");
54 this.Exit = true; 73 this.Exit = true;
55 } 74 }
56 else if (KeyInput.JustPressedKey(Microsoft.Xna.Framework.Input.Keys.Enter) || (KeyInput.ControllerMode && KeyInput.JustPressedRebindableKey(KeyFunctions.Accept))) 75 else if (KeyInput.JustPressedKey(Keys.Enter) || (KeyInput.ControllerMode && KeyInput.JustPressedRebindableKey(KeyFunctions.Accept)))
57 { 76 {
58 SoundManager.PlaySoundEffect("menu_select"); 77 SoundManager.PlaySoundEffect("menu_select");
59 _commitFunc(_value); 78 _commitFunc(_value);
60 this.Exit = true; 79 this.Exit = true;
61 } 80 }
81
82 if (this.Exit)
83 {
84 TextInputEXT.StopTextInput();
85 TextInputEXT.TextInput -= OnTextInput;
86 }
62 } 87 }
63 88
64 public override void DrawUI() 89 public override void DrawUI()