about summary refs log tree commit diff stats
path: root/AnodyneArchipelago/Menu/TextEntry.cs
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/TextEntry.cs
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/TextEntry.cs')
-rw-r--r--AnodyneArchipelago/Menu/TextEntry.cs45
1 files changed, 35 insertions, 10 deletions
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()