about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-25 00:10:57 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-25 00:10:57 -0400
commit1ec73259768c9d8ecdf89a9968188d28c9e52808 (patch)
tree8d31dfea7247230457c248cf8180d1c66d5ae02d
parent5d33345b598e2107df3763f09af3a06a84d65a93 (diff)
downloadanodyne-archipelago-1ec73259768c9d8ecdf89a9968188d28c9e52808.tar.gz
anodyne-archipelago-1ec73259768c9d8ecdf89a9968188d28c9e52808.tar.bz2
anodyne-archipelago-1ec73259768c9d8ecdf89a9968188d28c9e52808.zip
Started new main menu
-rw-r--r--AnodyneArchipelago/AnodyneArchipelago.csproj3
-rw-r--r--AnodyneArchipelago/Menu/MenuState.cs204
-rw-r--r--AnodyneArchipelago/Patches/StatePatches.cs47
-rw-r--r--AnodyneArchipelago/Plugin.cs8
4 files changed, 261 insertions, 1 deletions
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 @@
35 <Reference Include="FNA"> 35 <Reference Include="FNA">
36 <HintPath>..\..\..\SteamLibrary\steamapps\common\Anodyne\Remake\FNA.dll</HintPath> 36 <HintPath>..\..\..\SteamLibrary\steamapps\common\Anodyne\Remake\FNA.dll</HintPath>
37 </Reference> 37 </Reference>
38 <Reference Include="SemanticVersioning">
39 <HintPath>..\..\BepInEx\bin\NET.Framework\net462\SemanticVersioning.dll</HintPath>
40 </Reference>
38 </ItemGroup> 41 </ItemGroup>
39</Project> 42</Project>
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 @@
1using AnodyneSharp.Input;
2using AnodyneSharp.Registry;
3using AnodyneSharp.Sounds;
4using AnodyneSharp.UI;
5using AnodyneSharp.UI.PauseMenu;
6using AnodyneSharp.UI.PauseMenu.Config;
7using Microsoft.Xna.Framework;
8
9namespace 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}
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;
4using AnodyneSharp; 4using AnodyneSharp;
5using HarmonyLib; 5using HarmonyLib;
6using System.Reflection; 6using System.Reflection;
7using AnodyneSharp.Drawing.Effects;
8using AnodyneSharp.States.MainMenu;
9using static AnodyneSharp.AnodyneGame;
10using AnodyneSharp.Drawing;
7 11
8namespace AnodyneArchipelago.Patches 12namespace AnodyneArchipelago.Patches
9{ 13{
@@ -16,6 +20,49 @@ namespace AnodyneArchipelago.Patches
16 } 20 }
17 } 21 }
18 22
23 [HarmonyPatch(typeof(AnodyneGame), "SetState")]
24 class SetStatePatch
25 {
26 // Pretty much rewrite this whole method, so that we can swap out some states.
27 static bool Prefix(AnodyneGame __instance, GameState state)
28 {
29 foreach (IFullScreenEffect effect in GlobalState.AllEffects)
30 {
31 effect.Deactivate();
32 }
33
34 State new_state = CreateState(__instance, state);
35
36 if (new_state != null)
37 {
38 new_state.Create();
39
40 MethodInfo setStateMethod = typeof(AnodyneGame).GetMethod("SetState", BindingFlags.NonPublic | BindingFlags.Instance);
41 new_state.ChangeStateEvent = (ChangeState)setStateMethod.CreateDelegate(typeof(ChangeState), __instance);
42 }
43
44 FieldInfo stateField = typeof(AnodyneGame).GetField("_currentState", BindingFlags.NonPublic | BindingFlags.Instance);
45 stateField.SetValue(__instance, new_state);
46
47 return false;
48 }
49
50 static State CreateState(AnodyneGame __instance, GameState state)
51 {
52 switch (state)
53 {
54 case GameState.TitleScreen: return new TitleState();
55 case GameState.MainMenu: return new Menu.MenuState();
56 case GameState.Intro: return new IntroState();
57 case GameState.Game:
58 FieldInfo cameraField = typeof(AnodyneGame).GetField("_camera", BindingFlags.NonPublic | BindingFlags.Instance);
59 return new PlayState((Camera)cameraField.GetValue(__instance));
60 case GameState.Credits: return new CreditsState();
61 default: return null;
62 }
63 }
64 }
65
19 [HarmonyPatch(typeof(PlayState), nameof(PlayState.Create))] 66 [HarmonyPatch(typeof(PlayState), nameof(PlayState.Create))]
20 class PlayStateCreatePatch 67 class PlayStateCreatePatch
21 { 68 {
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;
3using BepInEx.NET.Common; 3using BepInEx.NET.Common;
4using HarmonyLib; 4using HarmonyLib;
5using HarmonyLib.Tools; 5using HarmonyLib.Tools;
6using System;
6using System.Reflection; 7using System.Reflection;
7 8
8namespace AnodyneArchipelago 9namespace AnodyneArchipelago
9{ 10{
10 [BepInPlugin("com.fourisland.plugins.anodyne.archipelago", "Anodyne Archipelago", "1.0.0.0")] 11 [BepInPlugin("com.fourisland.plugins.anodyne.archipelago", "Anodyne Archipelago", "0.1.0")]
11 public class Plugin : BasePlugin 12 public class Plugin : BasePlugin
12 { 13 {
13 public static Plugin Instance = null; 14 public static Plugin Instance = null;
14 public static Player Player = null; 15 public static Player Player = null;
15 16
17 public static string GetVersion()
18 {
19 return ((BepInPlugin)Attribute.GetCustomAttribute(typeof(Plugin), typeof(BepInPlugin))).Version.ToString();
20 }
21
16 public override void Load() 22 public override void Load()
17 { 23 {
18 Instance = this; 24 Instance = this;