Skip to content

Commit 73a2e3f

Browse files
Move current category and hardcoding to Buttons
1 parent 66090f6 commit 73a2e3f

File tree

14 files changed

+219
-205
lines changed

14 files changed

+219
-205
lines changed

Managers/AchievementManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void EnterAchievementTab()
5757
{
5858
int achievementCount = Achievements.Count;
5959

60-
List<ButtonInfo> achievementButtons = new List<ButtonInfo> { new ButtonInfo { buttonText = "Exit Achievements", method = () => currentCategoryName = "Main", isTogglable = false, toolTip = "Returns you back to the main page." } };
60+
List<ButtonInfo> achievementButtons = new List<ButtonInfo> { new ButtonInfo { buttonText = "Exit Achievements", method = () => Buttons.CurrentCategoryName = "Main", isTogglable = false, toolTip = "Returns you back to the main page." } };
6161

6262
if (achievementCount <= 0)
6363
achievementButtons.Add(
@@ -82,7 +82,7 @@ public static void EnterAchievementTab()
8282
}
8383

8484
Buttons.buttons[Buttons.GetCategory("Achievements")] = achievementButtons.ToArray();
85-
currentCategoryName = "Achievements";
85+
Buttons.CurrentCategoryName = "Achievements";
8686
}
8787

8888
public static bool HasAchievement(string name) =>

Managers/FriendManager.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ public static void FriendsListUpdated()
977977
List<ButtonInfo> buttons = new List<ButtonInfo> {
978978
new ButtonInfo {
979979
buttonText = "Exit Friends",
980-
method =() => currentCategoryName = "Main",
980+
method =() => Buttons.CurrentCategoryName = "Main",
981981
isTogglable = false,
982982
toolTip = "Returns you back to the main page."
983983
}
@@ -1000,15 +1000,15 @@ public static void FriendsListUpdated()
10001000
toolTip = "Use this tab to add people as friends."
10011001
});
10021002

1003-
Buttons.buttons[34] = buttons.ToArray();
1003+
Buttons.buttons[Buttons.GetCategory("Friends")] = buttons.ToArray();
10041004
}
10051005

10061006
public static void AddFriendsUI()
10071007
{
10081008
List<ButtonInfo> buttons = new List<ButtonInfo> {
10091009
new ButtonInfo {
10101010
buttonText = "Return to Friends",
1011-
method =() => currentCategoryName = "Friends",
1011+
method =() => Buttons.CurrentCategoryName = "Friends",
10121012
isTogglable = false,
10131013
toolTip = "Returns you back to the friends page."
10141014
},
@@ -1041,7 +1041,7 @@ public static void AddFriendsUI()
10411041

10421042
Buttons.buttons[Buttons.GetCategory("Temporary Category")] = buttons.ToArray();
10431043

1044-
currentCategoryName = "Temporary Category";
1044+
Buttons.CurrentCategoryName = "Temporary Category";
10451045
}
10461046

10471047
public static void IncomingFriendRequests()
@@ -1070,7 +1070,7 @@ public static void IncomingFriendRequests()
10701070

10711071
Buttons.buttons[Buttons.GetCategory("Temporary Category")] = buttons.ToArray();
10721072

1073-
currentCategoryName = "Temporary Category";
1073+
Buttons.CurrentCategoryName = "Temporary Category";
10741074
}
10751075

10761076
public static void OutgoingFriendRequests()
@@ -1099,7 +1099,7 @@ public static void OutgoingFriendRequests()
10991099

11001100
Buttons.buttons[Buttons.GetCategory("Temporary Category")] = buttons.ToArray();
11011101

1102-
currentCategoryName = "Temporary Category";
1102+
Buttons.CurrentCategoryName = "Temporary Category";
11031103
}
11041104

11051105
public static void InspectFriend(string friendTarget)
@@ -1108,7 +1108,7 @@ public static void InspectFriend(string friendTarget)
11081108
List<ButtonInfo> buttons = new List<ButtonInfo> {
11091109
new ButtonInfo {
11101110
buttonText = "Return to Friends",
1111-
method =() => currentCategoryName = "Friends",
1111+
method =() => Buttons.CurrentCategoryName = "Friends",
11121112
isTogglable = false,
11131113
toolTip = "Returns you back to the friends page."
11141114
}
@@ -1205,7 +1205,7 @@ public static void InspectFriend(string friendTarget)
12051205

12061206
Buttons.buttons[Buttons.GetCategory("Temporary Category")] = buttons.ToArray();
12071207

1208-
currentCategoryName = "Temporary Category";
1208+
Buttons.CurrentCategoryName = "Temporary Category";
12091209
}
12101210

12111211
public static void InspectPendingFriend(string friendTarget)
@@ -1240,7 +1240,7 @@ public static void InspectPendingFriend(string friendTarget)
12401240

12411241
Buttons.buttons[Buttons.GetCategory("Temporary Category")] = buttons.ToArray();
12421242

1243-
currentCategoryName = "Temporary Category";
1243+
Buttons.CurrentCategoryName = "Temporary Category";
12441244
}
12451245

12461246
public static void ShowChatMessages(string friendTarget)
@@ -1299,8 +1299,8 @@ public static void ShowChatMessages(string friendTarget)
12991299
toolTip = $"Sends a message to {friend.currentName}."
13001300
});
13011301

1302-
Buttons.buttons[41] = buttons.ToArray();
1303-
currentCategoryName = "Chat Messages";
1302+
Buttons.buttons[Buttons.GetCategory("Chat Messages")] = buttons.ToArray();
1303+
Buttons.CurrentCategoryName = "Chat Messages";
13041304
}
13051305

13061306
public class FriendWebSocket : MonoBehaviour
@@ -1526,7 +1526,7 @@ public static void HandleJSON(string json)
15261526
NotificationManager.SendNotification($"<color=grey>[</color><color=#{color}>{friendName.ToUpper()}</color><color=grey>]</color> {Regex.Replace(message, @"<\s*https?://[^\s>]+\s*>", "[Media]")}", 5000);
15271527
UpdateFriendMessage(from, $"<color=grey>[</color><color=#{color}>{friendName.ToUpper()}</color><color=grey>]</color> {message} ");
15281528

1529-
if (currentCategoryIndex == 41)
1529+
if (Buttons.CurrentCategoryIndex == 41)
15301530
{
15311531
ShowChatMessages(from);
15321532
ReloadMenu();

Managers/PatreonManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ public static void SetupPatreonMods(string patreonName)
230230
{
231231
NotificationManager.SendNotification($"<color=grey>[</color><color=purple>PATREON</color><color=grey>]</color> Welcome, {patreonName}! Patreon mods have been enabled.", 10000);
232232

233-
List<ButtonInfo> buttons = Buttons.buttons[0].ToList();
234-
buttons.Add(new ButtonInfo { buttonText = "Patreon Mods", method = () => Main.currentCategoryName = "Patreon Mods", isTogglable = false, toolTip = "Opens the patreon mods." });
235-
Buttons.buttons[0] = buttons.ToArray();
233+
List<ButtonInfo> buttons = Buttons.buttons[Buttons.GetCategory("Main")].ToList();
234+
buttons.Add(new ButtonInfo { buttonText = "Patreon Mods", method = () => Buttons.CurrentCategoryName = "Patreon Mods", isTogglable = false, toolTip = "Opens the patreon mods." });
235+
Buttons.buttons[Buttons.GetCategory("Main")] = buttons.ToArray();
236236

237237
if (Main.dynamicSounds)
238238
LoadSoundFromURL($"{PluginInfo.ServerResourcePath}/Audio/Menu/patreon.ogg", "Audio/Menu/patreon.ogg").Play(Main.buttonClickVolume / 10f);

Managers/PluginManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class Plugin
4949
public static readonly List<Plugin> Plugins = new List<Plugin>();
5050
public static void LoadPlugins()
5151
{
52-
Buttons.buttons[Buttons.GetCategory("Plugin Settings")] = new[] { new ButtonInfo { buttonText = "Exit Plugin Settings", method = () => currentCategoryName = "Settings", isTogglable = false, toolTip = "Returns you back to the settings menu." } };
52+
Buttons.buttons[Buttons.GetCategory("Plugin Settings")] = new[] { new ButtonInfo { buttonText = "Exit Plugin Settings", method = () => Buttons.CurrentCategoryName = "Settings", isTogglable = false, toolTip = "Returns you back to the settings menu." } };
5353

5454
if (Plugins.Count > 0)
5555
{
@@ -109,14 +109,14 @@ public static void LoadPlugins()
109109
{
110110
try
111111
{
112-
Buttons.AddButton(33, new ButtonInfo { buttonText = Plugin.FileName, overlapText = (Plugin.Enabled ? "<color=grey>[</color><color=green>ON</color><color=grey>]</color>" : "<color=grey>[</color><color=red>OFF</color><color=grey>]</color>") + " " + Plugin.Name, method = () => TogglePlugin(Plugin), isTogglable = false, toolTip = Plugin.Description });
112+
Buttons.AddButton(Buttons.GetCategory("Plugin Settings"), new ButtonInfo { buttonText = Plugin.FileName, overlapText = (Plugin.Enabled ? "<color=grey>[</color><color=green>ON</color><color=grey>]</color>" : "<color=grey>[</color><color=red>OFF</color><color=grey>]</color>") + " " + Plugin.Name, method = () => TogglePlugin(Plugin), isTogglable = false, toolTip = Plugin.Description });
113113
}
114114
catch (Exception e) { LogManager.Log("Error with enabling plugin " + Plugin.Name + ": " + e); }
115115
}
116116

117-
Buttons.AddButton(33, new ButtonInfo { buttonText = "Open Plugins Folder", method = OpenPluginsFolder, isTogglable = false, toolTip = "Opens a folder containing all of your plugins." });
118-
Buttons.AddButton(33, new ButtonInfo { buttonText = "Reload Plugins", method = ReloadPlugins, isTogglable = false, toolTip = "Reloads all of your plugins." });
119-
Buttons.AddButton(33, new ButtonInfo { buttonText = "Get More Plugins", method = LoadPluginLibrary, isTogglable = false, toolTip = "Opens a public plugin library, where you can download your own plugins." });
117+
Buttons.AddButton(Buttons.GetCategory("Plugin Settings"), new ButtonInfo { buttonText = "Open Plugins Folder", method = OpenPluginsFolder, isTogglable = false, toolTip = "Opens a folder containing all of your plugins." });
118+
Buttons.AddButton(Buttons.GetCategory("Plugin Settings"), new ButtonInfo { buttonText = "Reload Plugins", method = ReloadPlugins, isTogglable = false, toolTip = "Reloads all of your plugins." });
119+
Buttons.AddButton(Buttons.GetCategory("Plugin Settings"), new ButtonInfo { buttonText = "Get More Plugins", method = LoadPluginLibrary, isTogglable = false, toolTip = "Opens a public plugin library, where you can download your own plugins." });
120120
}
121121

122122
public static void DownloadPlugin(string name, string url)
@@ -279,7 +279,7 @@ public static void ReloadPlugins()
279279
if (isSearching)
280280
Mods.Settings.Search();
281281

282-
currentCategoryName = "Main";
282+
Buttons.CurrentCategoryName = "Main";
283283
}
284284

285285
public static void OpenPluginsFolder() =>
@@ -290,7 +290,7 @@ public static void LoadPluginLibrary()
290290
string library = GetHttp($"{PluginInfo.ServerResourcePath}/Plugins/PluginLibrary.txt");
291291
string[] plugins = AlphabetizeNoSkip(library.Split("\n"));
292292

293-
List<ButtonInfo> buttonInfos = new List<ButtonInfo> { new ButtonInfo { buttonText = "Exit Plugin Library", method = () => currentCategoryName = "Plugin Settings", isTogglable = false, toolTip = "Returns you back to the plugin settings." } };
293+
List<ButtonInfo> buttonInfos = new List<ButtonInfo> { new ButtonInfo { buttonText = "Exit Plugin Library", method = () => Buttons.CurrentCategoryName = "Plugin Settings", isTogglable = false, toolTip = "Returns you back to the plugin settings." } };
294294
int index = 0;
295295

296296
foreach (string plugin in plugins)
@@ -302,7 +302,7 @@ public static void LoadPluginLibrary()
302302
}
303303

304304
Buttons.buttons[Buttons.GetCategory("Temporary Category")] = buttonInfos.ToArray();
305-
currentCategoryName = "Temporary Category";
305+
Buttons.CurrentCategoryName = "Temporary Category";
306306
}
307307
#endregion
308308
}

0 commit comments

Comments
 (0)