diff options
Diffstat (limited to 'AnodyneArchipelago')
-rw-r--r-- | AnodyneArchipelago/Menu/InputHandler.cs | 99 | ||||
-rw-r--r-- | AnodyneArchipelago/Menu/MenuState.cs | 33 | ||||
-rw-r--r-- | AnodyneArchipelago/Menu/TextEntry.cs | 101 |
3 files changed, 232 insertions, 1 deletions
diff --git a/AnodyneArchipelago/Menu/InputHandler.cs b/AnodyneArchipelago/Menu/InputHandler.cs new file mode 100644 index 0000000..65605a2 --- /dev/null +++ b/AnodyneArchipelago/Menu/InputHandler.cs | |||
@@ -0,0 +1,99 @@ | |||
1 | using AnodyneSharp.Input; | ||
2 | using Microsoft.Xna.Framework.Input; | ||
3 | using System.Collections.Generic; | ||
4 | |||
5 | namespace AnodyneArchipelago.Menu | ||
6 | { | ||
7 | internal class InputCharacter | ||
8 | { | ||
9 | private readonly string _upper; | ||
10 | private readonly string _lower; | ||
11 | private readonly Keys _code; | ||
12 | |||
13 | public InputCharacter(string upper, string lower, Keys code) | ||
14 | { | ||
15 | _upper = upper; | ||
16 | _lower = lower; | ||
17 | _code = code; | ||
18 | } | ||
19 | |||
20 | public string ReturnCharacter(bool shiftDown) | ||
21 | { | ||
22 | return shiftDown ? _upper : _lower; | ||
23 | } | ||
24 | |||
25 | public Keys ReturnKey() | ||
26 | { | ||
27 | return _code; | ||
28 | } | ||
29 | } | ||
30 | |||
31 | internal class InputHandler | ||
32 | { | ||
33 | private static List<InputCharacter> _characters = new(); | ||
34 | |||
35 | static InputHandler() | ||
36 | { | ||
37 | _characters.Add(new InputCharacter("A", "a", Keys.A)); | ||
38 | _characters.Add(new InputCharacter("B", "b", Keys.B)); | ||
39 | _characters.Add(new InputCharacter("C", "c", Keys.C)); | ||
40 | _characters.Add(new InputCharacter("D", "d", Keys.D)); | ||
41 | _characters.Add(new InputCharacter("E", "e", Keys.E)); | ||
42 | _characters.Add(new InputCharacter("F", "f", Keys.F)); | ||
43 | _characters.Add(new InputCharacter("G", "g", Keys.G)); | ||
44 | _characters.Add(new InputCharacter("H", "h", Keys.H)); | ||
45 | _characters.Add(new InputCharacter("I", "i", Keys.I)); | ||
46 | _characters.Add(new InputCharacter("J", "j", Keys.J)); | ||
47 | _characters.Add(new InputCharacter("K", "k", Keys.K)); | ||
48 | _characters.Add(new InputCharacter("L", "l", Keys.L)); | ||
49 | _characters.Add(new InputCharacter("M", "m", Keys.M)); | ||
50 | _characters.Add(new InputCharacter("N", "n", Keys.N)); | ||
51 | _characters.Add(new InputCharacter("O", "o", Keys.O)); | ||
52 | _characters.Add(new InputCharacter("P", "p", Keys.P)); | ||
53 | _characters.Add(new InputCharacter("Q", "q", Keys.Q)); | ||
54 | _characters.Add(new InputCharacter("R", "r", Keys.R)); | ||
55 | _characters.Add(new InputCharacter("S", "s", Keys.S)); | ||
56 | _characters.Add(new InputCharacter("T", "t", Keys.T)); | ||
57 | _characters.Add(new InputCharacter("U", "u", Keys.U)); | ||
58 | _characters.Add(new InputCharacter("V", "v", Keys.V)); | ||
59 | _characters.Add(new InputCharacter("W", "w", Keys.W)); | ||
60 | _characters.Add(new InputCharacter("X", "x", Keys.X)); | ||
61 | _characters.Add(new InputCharacter("Y", "y", Keys.Y)); | ||
62 | _characters.Add(new InputCharacter("Z", "z", Keys.Z)); | ||
63 | |||
64 | _characters.Add(new InputCharacter("!", "1", Keys.D1)); | ||
65 | _characters.Add(new InputCharacter("@", "2", Keys.D2)); | ||
66 | _characters.Add(new InputCharacter("#", "3", Keys.D3)); | ||
67 | _characters.Add(new InputCharacter("$", "4", Keys.D4)); | ||
68 | _characters.Add(new InputCharacter("%", "5", Keys.D5)); | ||
69 | _characters.Add(new InputCharacter("^", "6", Keys.D6)); | ||
70 | _characters.Add(new InputCharacter("&", "7", Keys.D7)); | ||
71 | _characters.Add(new InputCharacter("*", "8", Keys.D8)); | ||
72 | _characters.Add(new InputCharacter("(", "9", Keys.D9)); | ||
73 | _characters.Add(new InputCharacter(")", "0", Keys.D0)); | ||
74 | |||
75 | _characters.Add(new InputCharacter(" ", " ", Keys.Space)); | ||
76 | _characters.Add(new InputCharacter("<", ",", Keys.OemComma)); | ||
77 | _characters.Add(new InputCharacter("+", "=", Keys.OemPlus)); | ||
78 | _characters.Add(new InputCharacter("?", "/", Keys.OemQuestion)); | ||
79 | _characters.Add(new InputCharacter(">", ".", Keys.OemPeriod)); | ||
80 | _characters.Add(new InputCharacter("_", "-", Keys.OemMinus)); | ||
81 | _characters.Add(new InputCharacter("{", "[", Keys.OemOpenBrackets)); | ||
82 | _characters.Add(new InputCharacter("|", "\"", Keys.OemBackslash)); | ||
83 | _characters.Add(new InputCharacter(":", ";", Keys.OemSemicolon)); | ||
84 | } | ||
85 | |||
86 | public static string ReturnCharacter() | ||
87 | { | ||
88 | foreach (InputCharacter inputCharacter in _characters) | ||
89 | { | ||
90 | if (KeyInput.JustPressedKey(inputCharacter.ReturnKey())) | ||
91 | { | ||
92 | return inputCharacter.ReturnCharacter(KeyInput.IsKeyPressed(Keys.LeftShift) || KeyInput.IsKeyPressed(Keys.RightShift)); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | return ""; | ||
97 | } | ||
98 | } | ||
99 | } | ||
diff --git a/AnodyneArchipelago/Menu/MenuState.cs b/AnodyneArchipelago/Menu/MenuState.cs index 08aa366..b9ee0dd 100644 --- a/AnodyneArchipelago/Menu/MenuState.cs +++ b/AnodyneArchipelago/Menu/MenuState.cs | |||
@@ -1,6 +1,7 @@ | |||
1 | using AnodyneSharp.Input; | 1 | using AnodyneSharp.Input; |
2 | using AnodyneSharp.Registry; | 2 | using AnodyneSharp.Registry; |
3 | using AnodyneSharp.Sounds; | 3 | using AnodyneSharp.Sounds; |
4 | using AnodyneSharp.States; | ||
4 | using AnodyneSharp.UI; | 5 | using AnodyneSharp.UI; |
5 | using AnodyneSharp.UI.PauseMenu; | 6 | using AnodyneSharp.UI.PauseMenu; |
6 | using AnodyneSharp.UI.PauseMenu.Config; | 7 | using AnodyneSharp.UI.PauseMenu.Config; |
@@ -24,6 +25,8 @@ namespace AnodyneArchipelago.Menu | |||
24 | private UILabel _settingsLabel; | 25 | private UILabel _settingsLabel; |
25 | private UILabel _quitLabel; | 26 | private UILabel _quitLabel; |
26 | 27 | ||
28 | private State _substate = null; | ||
29 | |||
27 | private string _apServer = ""; | 30 | private string _apServer = ""; |
28 | private string _apSlot = ""; | 31 | private string _apSlot = ""; |
29 | private string _apPassword = ""; | 32 | private string _apPassword = ""; |
@@ -62,6 +65,18 @@ namespace AnodyneArchipelago.Menu | |||
62 | 65 | ||
63 | public override void Update() | 66 | public override void Update() |
64 | { | 67 | { |
68 | if (_substate != null) | ||
69 | { | ||
70 | _substate.Update(); | ||
71 | |||
72 | if (_substate.Exit) | ||
73 | { | ||
74 | _substate = null; | ||
75 | } | ||
76 | |||
77 | return; | ||
78 | } | ||
79 | |||
65 | _selector.Update(); | 80 | _selector.Update(); |
66 | _selector.PostUpdate(); | 81 | _selector.PostUpdate(); |
67 | 82 | ||
@@ -92,6 +107,11 @@ namespace AnodyneArchipelago.Menu | |||
92 | _connectLabel.Draw(); | 107 | _connectLabel.Draw(); |
93 | _settingsLabel.Draw(); | 108 | _settingsLabel.Draw(); |
94 | _quitLabel.Draw(); | 109 | _quitLabel.Draw(); |
110 | |||
111 | if (_substate != null) | ||
112 | { | ||
113 | _substate.DrawUI(); | ||
114 | } | ||
95 | } | 115 | } |
96 | 116 | ||
97 | private void SetCursorPosition(int i) | 117 | private void SetCursorPosition(int i) |
@@ -159,7 +179,7 @@ namespace AnodyneArchipelago.Menu | |||
159 | { | 179 | { |
160 | label.SetText(text); | 180 | label.SetText(text); |
161 | } | 181 | } |
162 | 182 | ||
163 | label.Color = new Color(184, 32, 0); | 183 | label.Color = new Color(184, 32, 0); |
164 | } | 184 | } |
165 | } | 185 | } |
@@ -184,8 +204,19 @@ namespace AnodyneArchipelago.Menu | |||
184 | } | 204 | } |
185 | else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Accept)) | 205 | else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Accept)) |
186 | { | 206 | { |
207 | SoundManager.PlaySoundEffect("menu_select"); | ||
208 | |||
187 | switch (_selectorIndex) | 209 | switch (_selectorIndex) |
188 | { | 210 | { |
211 | case 0: | ||
212 | _substate = new TextEntry("Server:", _apServer, (string value) => { _apServer = value; UpdateLabels(); }); | ||
213 | break; | ||
214 | case 1: | ||
215 | _substate = new TextEntry("Slot:", _apSlot, (string value) => { _apSlot = value; UpdateLabels(); }); | ||
216 | break; | ||
217 | case 2: | ||
218 | _substate = new TextEntry("Password:", _apPassword, (string value) => { _apPassword = value; UpdateLabels(); }); | ||
219 | break; | ||
189 | case 6: | 220 | case 6: |
190 | GlobalState.ClosingGame = true; | 221 | GlobalState.ClosingGame = true; |
191 | break; | 222 | break; |
diff --git a/AnodyneArchipelago/Menu/TextEntry.cs b/AnodyneArchipelago/Menu/TextEntry.cs new file mode 100644 index 0000000..8be54f5 --- /dev/null +++ b/AnodyneArchipelago/Menu/TextEntry.cs | |||
@@ -0,0 +1,101 @@ | |||
1 | using AnodyneSharp.Input; | ||
2 | using AnodyneSharp.Sounds; | ||
3 | using AnodyneSharp.States; | ||
4 | using AnodyneSharp.UI; | ||
5 | using Microsoft.Xna.Framework; | ||
6 | |||
7 | namespace AnodyneArchipelago.Menu | ||
8 | { | ||
9 | internal class TextEntry : State | ||
10 | { | ||
11 | public delegate void CommitChange(string value); | ||
12 | |||
13 | private readonly string _header; | ||
14 | private readonly CommitChange _commitFunc; | ||
15 | |||
16 | private string _value; | ||
17 | |||
18 | private UILabel _headerLabel; | ||
19 | private UILabel _valueLabel; | ||
20 | private UIEntity _bgBox; | ||
21 | |||
22 | public TextEntry(string header, string value, CommitChange commitFunc) | ||
23 | { | ||
24 | _header = header; | ||
25 | _value = value; | ||
26 | _commitFunc = commitFunc; | ||
27 | |||
28 | _headerLabel = new(new Vector2(20f, 44f), false, _header, new Color(226, 226, 226), AnodyneSharp.Drawing.DrawOrder.TEXT); | ||
29 | _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); | ||
31 | |||
32 | UpdateDisplay(); | ||
33 | } | ||
34 | |||
35 | public override void Update() | ||
36 | { | ||
37 | string inputtedCharacter = InputHandler.ReturnCharacter(); | ||
38 | if (inputtedCharacter.Length > 0) | ||
39 | { | ||
40 | _value += inputtedCharacter; | ||
41 | UpdateDisplay(); | ||
42 | } | ||
43 | else if (KeyInput.JustPressedKey(Microsoft.Xna.Framework.Input.Keys.Back)) | ||
44 | { | ||
45 | if (_value.Length > 0) | ||
46 | { | ||
47 | _value = _value.Substring(0, _value.Length - 1); | ||
48 | UpdateDisplay(); | ||
49 | } | ||
50 | } | ||
51 | else if (KeyInput.JustPressedKey(Microsoft.Xna.Framework.Input.Keys.Escape) || (KeyInput.ControllerMode && KeyInput.JustPressedRebindableKey(KeyFunctions.Cancel))) | ||
52 | { | ||
53 | SoundManager.PlaySoundEffect("menu_select"); | ||
54 | this.Exit = true; | ||
55 | } | ||
56 | else if (KeyInput.JustPressedKey(Microsoft.Xna.Framework.Input.Keys.Enter) || (KeyInput.ControllerMode && KeyInput.JustPressedRebindableKey(KeyFunctions.Accept))) | ||
57 | { | ||
58 | SoundManager.PlaySoundEffect("menu_select"); | ||
59 | _commitFunc(_value); | ||
60 | this.Exit = true; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | public override void DrawUI() | ||
65 | { | ||
66 | _bgBox.Draw(); | ||
67 | _headerLabel.Draw(); | ||
68 | _valueLabel.Draw(); | ||
69 | } | ||
70 | |||
71 | private void UpdateDisplay() | ||
72 | { | ||
73 | if (_value.Length == 0) | ||
74 | { | ||
75 | _valueLabel.SetText("[empty]"); | ||
76 | _valueLabel.Color = new Color(116, 140, 144); | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | string finalText = ""; | ||
81 | string tempText = _value; | ||
82 | |||
83 | while (tempText.Length > 18) | ||
84 | { | ||
85 | finalText += tempText.Substring(0, 18); | ||
86 | finalText += "\n"; | ||
87 | tempText = tempText.Substring(18); | ||
88 | } | ||
89 | |||
90 | finalText += tempText; | ||
91 | |||
92 | _valueLabel.SetText(finalText); | ||
93 | _valueLabel.Color = new Color(184, 32, 0); | ||
94 | } | ||
95 | |||
96 | float innerHeight = 8f + _valueLabel.Writer.TotalTextHeight(); | ||
97 | |||
98 | _bgBox = new UIEntity(new Vector2(16f, 40f), "pop_menu", 136, (int)innerHeight + 8, AnodyneSharp.Drawing.DrawOrder.TEXTBOX); | ||
99 | } | ||
100 | } | ||
101 | } | ||