From 1ec73259768c9d8ecdf89a9968188d28c9e52808 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 25 May 2024 00:10:57 -0400 Subject: Started new main menu --- AnodyneArchipelago/Menu/MenuState.cs | 204 +++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 AnodyneArchipelago/Menu/MenuState.cs (limited to 'AnodyneArchipelago/Menu/MenuState.cs') 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 @@ +using AnodyneSharp.Input; +using AnodyneSharp.Registry; +using AnodyneSharp.Sounds; +using AnodyneSharp.UI; +using AnodyneSharp.UI.PauseMenu; +using AnodyneSharp.UI.PauseMenu.Config; +using Microsoft.Xna.Framework; + +namespace AnodyneArchipelago.Menu +{ + internal class MenuState : AnodyneSharp.States.State + { + private MenuSelector _selector; + private UILabel _versionLabel1; + private UILabel _versionLabel2; + private UILabel _serverLabel; + private UILabel _serverValue; + private UILabel _slotLabel; + private UILabel _slotValue; + private UILabel _passwordLabel; + private UILabel _passwordValue; + private TextSelector _connectionSwitcher; + private UILabel _connectLabel; + private UILabel _settingsLabel; + private UILabel _quitLabel; + + private string _apServer = ""; + private string _apSlot = ""; + private string _apPassword = ""; + + private int _selectorIndex = 0; + + public override void Create() + { + _selector = new(); + _selector.Play("enabledRight"); + + _versionLabel1 = new(new Vector2(10f, 7f), false, "AnodyneArchipelago", new Color(116, 140, 144)); + _versionLabel2 = new(new Vector2(10f, 15f), false, $"v{Plugin.GetVersion()}", new Color(116, 140, 144)); + _serverLabel = new(new Vector2(10f, 31f), false, $"Server:", new Color(226, 226, 226)); + _serverValue = new(new Vector2(18f, 39f), false, "", new Color()); + _slotLabel = new(new Vector2(10f, 51f), false, $"Slot:", new Color(226, 226, 226)); + _slotValue = new(new Vector2(18f, 59f), false, "", new Color()); + _passwordLabel = new(new Vector2(10f, 71f), false, $"Password:", new Color(226, 226, 226)); + _passwordValue = new(new Vector2(18f, 79f), false, "", new Color()); + _connectLabel = new(new Vector2(60f, 115f), false, $"Connect", new Color(116, 140, 144)); + _settingsLabel = new(new Vector2(60f, 131f), false, $"Config", new Color(116, 140, 144)); + _quitLabel = new(new Vector2(60f, 147f), false, $"Quit", new Color(116, 140, 144)); + + _connectionSwitcher = new(new Vector2(60f, 95f), 32f, 0, true, new string[1] { "1/1" }); + _connectionSwitcher.noConfirm = true; + _connectionSwitcher.noLoop = true; + _connectionSwitcher.ValueChangedEvent = PageValueChanged; + + SetCursorPosition(0); + UpdateLabels(); + } + + public override void Initialize() + { + } + + public override void Update() + { + _selector.Update(); + _selector.PostUpdate(); + + if (_selectorIndex == 3) + { + _connectionSwitcher.Update(); + } + + BrowseInput(); + } + + public override void Draw() + { + } + + public override void DrawUI() + { + _selector.Draw(); + _versionLabel1.Draw(); + _versionLabel2.Draw(); + _serverLabel.Draw(); + _serverValue.Draw(); + _slotLabel.Draw(); + _slotValue.Draw(); + _passwordLabel.Draw(); + _passwordValue.Draw(); + _connectionSwitcher.Draw(); + _connectLabel.Draw(); + _settingsLabel.Draw(); + _quitLabel.Draw(); + } + + private void SetCursorPosition(int i) + { + _selectorIndex = i; + + if (_selectorIndex == 0) + { + _selector.Position = new(2f, 34f); + } + else if (_selectorIndex == 1) + { + _selector.Position = new(2f, 54f); + } + else if (_selectorIndex == 2) + { + _selector.Position = new(2f, 74f); + } + else if (_selectorIndex == 4) + { + _selector.Position = new(52f, 118f); + } + else if (_selectorIndex == 5) + { + _selector.Position = new(52f, 134f); + } + else if (_selectorIndex == 6) + { + _selector.Position = new(52f, 150f); + } + + if (_selectorIndex == 3) + { + _selector.visible = false; + _connectionSwitcher.GetControl(); + } + else + { + _selector.visible = true; + _connectionSwitcher.LoseControl(); + } + } + + private void UpdateLabels() + { + UpdateLabel(_serverValue, _apServer); + UpdateLabel(_slotValue, _apSlot); + UpdateLabel(_passwordValue, _apPassword); + } + + private void UpdateLabel(UILabel label, string text) + { + if (text.Length == 0) + { + label.SetText("[empty]"); + label.Color = new Color(116, 140, 144); + } + else + { + if (text.Length > 20) + { + label.SetText(text.Substring(0, 17) + "..."); + } + else + { + label.SetText(text); + } + + label.Color = new Color(184, 32, 0); + } + } + + private void BrowseInput() + { + if (KeyInput.JustPressedRebindableKey(KeyFunctions.Up)) + { + SoundManager.PlaySoundEffect("menu_move"); + if (_selectorIndex > 0) + { + SetCursorPosition(_selectorIndex - 1); + } + } + else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Down)) + { + SoundManager.PlaySoundEffect("menu_move"); + if (_selectorIndex < 6) + { + SetCursorPosition(_selectorIndex + 1); + } + } + else if (KeyInput.JustPressedRebindableKey(KeyFunctions.Accept)) + { + switch (_selectorIndex) + { + case 6: + GlobalState.ClosingGame = true; + break; + default: + // Hi + break; + } + } + } + + private void PageValueChanged(string value, int index) + { + + } + } +} -- cgit 1.4.1