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/AnodyneArchipelago.csproj | 3 + AnodyneArchipelago/Menu/MenuState.cs | 204 +++++++++++++++++++++++++++ AnodyneArchipelago/Patches/StatePatches.cs | 47 ++++++ AnodyneArchipelago/Plugin.cs | 8 +- 4 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 AnodyneArchipelago/Menu/MenuState.cs (limited to 'AnodyneArchipelago') diff --git a/AnodyneArchipelago/AnodyneArchipelago.csproj b/AnodyneArchipelago/AnodyneArchipelago.csproj index abe6c23..a5780a0 100644 --- a/AnodyneArchipelago/AnodyneArchipelago.csproj +++ b/AnodyneArchipelago/AnodyneArchipelago.csproj @@ -35,5 +35,8 @@ ..\..\..\SteamLibrary\steamapps\common\Anodyne\Remake\FNA.dll + + ..\..\BepInEx\bin\NET.Framework\net462\SemanticVersioning.dll + 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) + { + + } + } +} diff --git a/AnodyneArchipelago/Patches/StatePatches.cs b/AnodyneArchipelago/Patches/StatePatches.cs index f6acc62..4b29295 100644 --- a/AnodyneArchipelago/Patches/StatePatches.cs +++ b/AnodyneArchipelago/Patches/StatePatches.cs @@ -4,6 +4,10 @@ using AnodyneSharp.States; using AnodyneSharp; using HarmonyLib; using System.Reflection; +using AnodyneSharp.Drawing.Effects; +using AnodyneSharp.States.MainMenu; +using static AnodyneSharp.AnodyneGame; +using AnodyneSharp.Drawing; namespace AnodyneArchipelago.Patches { @@ -16,6 +20,49 @@ namespace AnodyneArchipelago.Patches } } + [HarmonyPatch(typeof(AnodyneGame), "SetState")] + class SetStatePatch + { + // Pretty much rewrite this whole method, so that we can swap out some states. + static bool Prefix(AnodyneGame __instance, GameState state) + { + foreach (IFullScreenEffect effect in GlobalState.AllEffects) + { + effect.Deactivate(); + } + + State new_state = CreateState(__instance, state); + + if (new_state != null) + { + new_state.Create(); + + MethodInfo setStateMethod = typeof(AnodyneGame).GetMethod("SetState", BindingFlags.NonPublic | BindingFlags.Instance); + new_state.ChangeStateEvent = (ChangeState)setStateMethod.CreateDelegate(typeof(ChangeState), __instance); + } + + FieldInfo stateField = typeof(AnodyneGame).GetField("_currentState", BindingFlags.NonPublic | BindingFlags.Instance); + stateField.SetValue(__instance, new_state); + + return false; + } + + static State CreateState(AnodyneGame __instance, GameState state) + { + switch (state) + { + case GameState.TitleScreen: return new TitleState(); + case GameState.MainMenu: return new Menu.MenuState(); + case GameState.Intro: return new IntroState(); + case GameState.Game: + FieldInfo cameraField = typeof(AnodyneGame).GetField("_camera", BindingFlags.NonPublic | BindingFlags.Instance); + return new PlayState((Camera)cameraField.GetValue(__instance)); + case GameState.Credits: return new CreditsState(); + default: return null; + } + } + } + [HarmonyPatch(typeof(PlayState), nameof(PlayState.Create))] class PlayStateCreatePatch { diff --git a/AnodyneArchipelago/Plugin.cs b/AnodyneArchipelago/Plugin.cs index 1f6e7ea..66f020d 100644 --- a/AnodyneArchipelago/Plugin.cs +++ b/AnodyneArchipelago/Plugin.cs @@ -3,16 +3,22 @@ using BepInEx; using BepInEx.NET.Common; using HarmonyLib; using HarmonyLib.Tools; +using System; using System.Reflection; namespace AnodyneArchipelago { - [BepInPlugin("com.fourisland.plugins.anodyne.archipelago", "Anodyne Archipelago", "1.0.0.0")] + [BepInPlugin("com.fourisland.plugins.anodyne.archipelago", "Anodyne Archipelago", "0.1.0")] public class Plugin : BasePlugin { public static Plugin Instance = null; public static Player Player = null; + public static string GetVersion() + { + return ((BepInPlugin)Attribute.GetCustomAttribute(typeof(Plugin), typeof(BepInPlugin))).Version.ToString(); + } + public override void Load() { Instance = this; -- cgit 1.4.1