diff options
Diffstat (limited to 'AnodyneArchipelago/Menu')
| -rw-r--r-- | AnodyneArchipelago/Menu/MenuState.cs | 204 |
1 files changed, 204 insertions, 0 deletions
| diff --git a/AnodyneArchipelago/Menu/MenuState.cs b/AnodyneArchipelago/Menu/MenuState.cs new file mode 100644 index 0000000..08aa366 --- /dev/null +++ b/AnodyneArchipelago/Menu/MenuState.cs | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | using AnodyneSharp.Input; | ||
| 2 | using AnodyneSharp.Registry; | ||
| 3 | using AnodyneSharp.Sounds; | ||
| 4 | using AnodyneSharp.UI; | ||
| 5 | using AnodyneSharp.UI.PauseMenu; | ||
| 6 | using AnodyneSharp.UI.PauseMenu.Config; | ||
| 7 | using Microsoft.Xna.Framework; | ||
| 8 | |||
| 9 | namespace AnodyneArchipelago.Menu | ||
| 10 | { | ||
| 11 | internal class MenuState : AnodyneSharp.States.State | ||
| 12 | { | ||
| 13 | private MenuSelector _selector; | ||
| 14 | private UILabel _versionLabel1; | ||
| 15 | private UILabel _versionLabel2; | ||
| 16 | private UILabel _serverLabel; | ||
| 17 | private UILabel _serverValue; | ||
| 18 | private UILabel _slotLabel; | ||
| 19 | private UILabel _slotValue; | ||
| 20 | private UILabel _passwordLabel; | ||
| 21 | private UILabel _passwordValue; | ||
| 22 | private TextSelector _connectionSwitcher; | ||
| 23 | private UILabel _connectLabel; | ||
| 24 | private UILabel _settingsLabel; | ||
| 25 | private UILabel _quitLabel; | ||
| 26 | |||
| 27 | private string _apServer = ""; | ||
| 28 | private string _apSlot = ""; | ||
| 29 | private string _apPassword = ""; | ||
| 30 | |||
| 31 | private int _selectorIndex = 0; | ||
| 32 | |||
| 33 | public override void Create() | ||
| 34 | { | ||
| 35 | _selector = new(); | ||
| 36 | _selector.Play("enabledRight"); | ||
| 37 | |||
| 38 | _versionLabel1 = new(new Vector2(10f, 7f), false, "AnodyneArchipelago", new Color(116, 140, 144)); | ||
| 39 | _versionLabel2 = new(new Vector2(10f, 15f), false, $"v{Plugin.GetVersion()}", new Color(116, 140, 144)); | ||
| 40 | _serverLabel = new(new Vector2(10f, 31f), false, $"Server:", new Color(226, 226, 226)); | ||
| 41 | _serverValue = new(new Vector2(18f, 39f), false, "", new Color()); | ||
| 42 | _slotLabel = new(new Vector2(10f, 51f), false, $"Slot:", new Color(226, 226, 226)); | ||
| 43 | _slotValue = new(new Vector2(18f, 59f), false, "", new Color()); | ||
| 44 | _passwordLabel = new(new Vector2(10f, 71f), false, $"Password:", new Color(226, 226, 226)); | ||
| 45 | _passwordValue = new(new Vector2(18f, 79f), false, "", new Color()); | ||
| 46 | _connectLabel = new(new Vector2(60f, 115f), false, $"Connect", new Color(116, 140, 144)); | ||
| 47 | _settingsLabel = new(new Vector2(60f, 131f), false, $"Config", new Color(116, 140, 144)); | ||
| 48 | _quitLabel = new(new Vector2(60f, 147f), false, $"Quit", new Color(116, 140, 144)); | ||
| 49 | |||
| 50 | _connectionSwitcher = new(new Vector2(60f, 95f), 32f, 0, true, new string[1] { "1/1" }); | ||
| 51 | _connectionSwitcher.noConfirm = true; | ||
| 52 | _connectionSwitcher.noLoop = true; | ||
| 53 | _connectionSwitcher.ValueChangedEvent = PageValueChanged; | ||
| 54 | |||
| 55 | SetCursorPosition(0); | ||
| 56 | UpdateLabels(); | ||
| 57 | } | ||
| 58 | |||
| 59 | public override void Initialize() | ||
| 60 | { | ||
| 61 | } | ||
| 62 | |||
| 63 | public override void Update() | ||
| 64 | { | ||
| 65 | _selector.Update(); | ||
| 66 | _selector.PostUpdate(); | ||
| 67 | |||
| 68 | if (_selectorIndex == 3) | ||
| 69 | { | ||
| 70 | _connectionSwitcher.Update(); | ||
| 71 | } | ||
| 72 | |||
| 73 | BrowseInput(); | ||
| 74 | } | ||
| 75 | |||
| 76 | public override void Draw() | ||
| 77 | { | ||
| 78 | } | ||
| 79 | |||
| 80 | public override void DrawUI() | ||
| 81 | { | ||
| 82 | _selector.Draw(); | ||
| 83 | _versionLabel1.Draw(); | ||
| 84 | _versionLabel2.Draw(); | ||
| 85 | _serverLabel.Draw(); | ||
| 86 | _serverValue.Draw(); | ||
| 87 | _slotLabel.Draw(); | ||
| 88 | _slotValue.Draw(); | ||
| 89 | _passwordLabel.Draw(); | ||
| 90 | _passwordValue.Draw(); | ||
| 91 | _connectionSwitcher.Draw(); | ||
| 92 | _connectLabel.Draw(); | ||
| 93 | _settingsLabel.Draw(); | ||
| 94 | _quitLabel.Draw(); | ||
| 95 | } | ||
| 96 | |||
| 97 | private void SetCursorPosition(int i) | ||
| 98 | { | ||
| 99 | _selectorIndex = i; | ||
| 100 | |||
| 101 | if (_selectorIndex == 0) | ||
| 102 | { | ||
| 103 | _selector.Position = new(2f, 34f); | ||
| 104 | } | ||
| 105 | else if (_selectorIndex == 1) | ||
| 106 | { | ||
| 107 | _selector.Position = new(2f, 54f); | ||
| 108 | } | ||
| 109 | else if (_selectorIndex == 2) | ||
| 110 | { | ||
| 111 | _selector.Position = new(2f, 74f); | ||
| 112 | } | ||
| 113 | else if (_selectorIndex == 4) | ||
| 114 | { | ||
| 115 | _selector.Position = new(52f, 118f); | ||
| 116 | } | ||
| 117 | else if (_selectorIndex == 5) | ||
| 118 | { | ||
| 119 | _selector.Position = new(52f, 134f); | ||
| 120 | } | ||
| 121 | else if (_selectorIndex == 6) | ||
| 122 | { | ||
| 123 | _selector.Position = new(52f, 150f); | ||
| 124 | } | ||
| 125 | |||
| 126 | if (_selectorIndex == 3) | ||
| 127 | { | ||
| 128 | _selector.visible = false; | ||
| 129 | _connectionSwitcher.GetControl(); | ||
| 130 | } | ||
| 131 | else | ||
| 132 | { | ||
| 133 | _selector.visible = true; | ||
| 134 | _connectionSwitcher.LoseControl(); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | private void UpdateLabels() | ||
| 139 | { | ||
| 140 | UpdateLabel(_serverValue, _apServer); | ||
| 141 | UpdateLabel(_slotValue, _apSlot); | ||
| 142 | UpdateLabel(_passwordValue, _apPassword); | ||
| 143 | } | ||
| 144 | |||
| 145 | private void UpdateLabel(UILabel label, string text) | ||
| 146 | { | ||
| 147 | if (text.Length == 0) | ||
| 148 | { | ||
| 149 | label.SetText("[empty]"); | ||
| 150 | label.Color = new Color(116, 140, 144); | ||
| 151 | } | ||
| 152 | else | ||
| 153 | { | ||
| 154 | if (text.Length > 20) | ||
| 155 | { | ||
| 156 | label.SetText(text.Substring(0, 17) + "..."); | ||
| 157 | } | ||
| 158 | else | ||
| 159 | { | ||
| 160 | label.SetText(text); | ||
| 161 | } | ||
| 162 | |||
| 163 | label.Color = new Color(184, 32, 0); | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | private void BrowseInput() | ||
| 168 | { | ||
| 169 | if (KeyInput.JustPressedRebindableKey(KeyFunctions.Up)) | ||
| 170 | { | ||
| 171 | SoundManager.PlaySoundEffect("menu_move"); | ||
| 172 | if (_selectorIndex > 0) | ||
| 173 | { | ||
| 174 | SetCursorPosition(_selectorIndex - 1); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Down)) | ||
| 178 | { | ||
| 179 | SoundManager.PlaySoundEffect("menu_move"); | ||
| 180 | if (_selectorIndex < 6) | ||
| 181 | { | ||
| 182 | SetCursorPosition(_selectorIndex + 1); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Accept)) | ||
| 186 | { | ||
| 187 | switch (_selectorIndex) | ||
| 188 | { | ||
| 189 | case 6: | ||
| 190 | GlobalState.ClosingGame = true; | ||
| 191 | break; | ||
| 192 | default: | ||
| 193 | // Hi | ||
| 194 | break; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | private void PageValueChanged(string value, int index) | ||
| 200 | { | ||
| 201 | |||
| 202 | } | ||
| 203 | } | ||
| 204 | } | ||
