diff --git a/Reactor.Example/ExamplePlugin.cs b/Reactor.Example/ExamplePlugin.cs index 8a2c23b..c14e8b9 100644 --- a/Reactor.Example/ExamplePlugin.cs +++ b/Reactor.Example/ExamplePlugin.cs @@ -25,7 +25,7 @@ public partial class ExamplePlugin : BasePlugin public override void Load() { - ReactorPingTracker.Register(ReactorPingTracker.AlwaysShow); + ReactorCredits.Register(ReactorCredits.AlwaysShow); this.AddComponent(); diff --git a/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs b/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs index 071dc3f..0662758 100644 --- a/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs +++ b/Reactor/Patches/Miscellaneous/PingTrackerPatch.cs @@ -11,7 +11,7 @@ internal static class PingTrackerPatch [HarmonyPriority(Priority.Last)] public static void Postfix(PingTracker __instance) { - var extraText = ReactorPingTracker.GetText(); + var extraText = ReactorCredits.GetText(ReactorCredits.Location.PingTracker); if (extraText != null) { if (!__instance.text.text.EndsWith("\n", StringComparison.InvariantCulture)) __instance.text.text += "\n"; diff --git a/Reactor/Patches/ReactorVersionShower.cs b/Reactor/Patches/ReactorVersionShower.cs index 16c47df..d6b0559 100644 --- a/Reactor/Patches/ReactorVersionShower.cs +++ b/Reactor/Patches/ReactorVersionShower.cs @@ -2,6 +2,7 @@ using BepInEx; using BepInEx.Unity.IL2CPP; using HarmonyLib; +using Reactor.Utilities; using Reactor.Utilities.Extensions; using TMPro; using UnityEngine; @@ -98,6 +99,13 @@ public static void UpdateText() Text.text = "Reactor " + Version.Parse(ReactorPlugin.Version).WithoutBuild(); Text.text += "\nBepInEx " + Paths.BepInExVersion.WithoutBuild(); Text.text += "\nMods: " + IL2CPPChainloader.Instance.Plugins.Count; + + var creditsText = ReactorCredits.GetText(ReactorCredits.Location.MainMenu); + if (creditsText != null) + { + Text.text += "\n" + creditsText; + } + TextUpdated?.Invoke(Text); } diff --git a/Reactor/Utilities/ReactorPingTracker.cs b/Reactor/Utilities/ReactorCredits.cs similarity index 55% rename from Reactor/Utilities/ReactorPingTracker.cs rename to Reactor/Utilities/ReactorCredits.cs index 0c6d29d..7a574c8 100644 --- a/Reactor/Utilities/ReactorPingTracker.cs +++ b/Reactor/Utilities/ReactorCredits.cs @@ -2,57 +2,78 @@ using System.Collections.Generic; using System.Linq; using BepInEx.Unity.IL2CPP; +using Reactor.Patches; using Reactor.Utilities.Extensions; namespace Reactor.Utilities; /// -/// Controls the PingTracker. +/// Provides a way for mods to show their version information in-game. /// -public static class ReactorPingTracker +public static class ReactorCredits { - private readonly struct ModIdentifier(string name, string version, Func? shouldShow, bool isPreRelease) + private readonly struct ModIdentifier(string name, string version, Func? shouldShow, bool isPreRelease) { private const string NormalColor = "#fff"; private const string PreReleaseColor = "#f00"; public string Name => name; - public bool ShouldShow => shouldShow == AlwaysShow || shouldShow(); public string Text { get; } = $"{name} {version}".EscapeRichText().Color(isPreRelease ? PreReleaseColor : NormalColor); + + public bool ShouldShow(Location location) + { + return shouldShow == AlwaysShow || shouldShow(location); + } } private static readonly List _modIdentifiers = []; + /// + /// Represents the location of where the credit is shown. + /// + public enum Location + { + /// + /// In the main menu under Reactor/BepInEx versions. + /// + MainMenu, + + /// + /// During game under the ping tracker. + /// + PingTracker, + } + /// /// A special value indicating a mod should always show. /// - public const Func? AlwaysShow = null; + public const Func? AlwaysShow = null; /// - /// Registers a mod with the , adding it to the list of mods that will be displayed in the PingTracker. + /// Registers a mod with the , adding it to the list of mods that will be displayed. /// /// The user-friendly name of the mod. Can contain spaces or special characters. /// The version of the mod. - /// If this version is a development or beta version. If true, it will display the mod in red in the PingTracker. + /// If this version is a development or beta version. If true, it will display the mod in red. /// /// This function will be called every frame to determine if the mod should be displayed or not. /// This function should return false if your mod is currently disabled or has no effect on gameplay at the time. - /// If you want the mod to be displayed at all times, you can set this parameter to . + /// If you want the mod to be displayed at all times, you can set this parameter to . /// - public static void Register(string name, string version, bool isPreRelease, Func? shouldShow) + public static void Register(string name, string version, bool isPreRelease, Func? shouldShow) { const int MaxLength = 60; if (name.Length + version.Length > MaxLength) { - Error($"Not registering mod \"{name}\" with version \"{version}\" in {nameof(ReactorPingTracker)} because the combined length of the mod name and version is greater than {MaxLength} characters."); + Error($"Not registering mod \"{name}\" with version \"{version}\" in {nameof(ReactorCredits)} because the combined length of the mod name and version is greater than {MaxLength} characters."); return; } if (_modIdentifiers.Any(m => m.Name == name)) { - Error($"Mod \"{name}\" is already registered in {nameof(ReactorPingTracker)}."); + Error($"Mod \"{name}\" is already registered in {nameof(ReactorCredits)}."); return; } @@ -62,20 +83,22 @@ public static void Register(string name, string version, bool isPreRelease, Func if (!isPreRelease) { - Info($"Mod \"{name}\" registered in {nameof(ReactorPingTracker)} with version {version}."); + Info($"Mod \"{name}\" registered in {nameof(ReactorCredits)} with version {version}."); } else { - Warning($"Mod \"{name}\" registered in {nameof(ReactorPingTracker)} with DEVELOPMENT/BETA version {version}."); + Warning($"Mod \"{name}\" registered in {nameof(ReactorCredits)} with DEVELOPMENT/BETA version {version}."); } + + ReactorVersionShower.UpdateText(); } /// - /// Registers a mod with the , adding it to the list of mods that will be displayed in the PingTracker. + /// Registers a mod with the , adding it to the list of mods that will be displayed. /// /// The BepInEx plugin type to get the name and version from. - /// - public static void Register(Func? shouldShow) where T : BasePlugin + /// + public static void Register(Func? shouldShow) where T : BasePlugin { var pluginInfo = IL2CPPChainloader.Instance.Plugins.Values.SingleOrDefault(p => p.TypeName == typeof(T).FullName) ?? throw new ArgumentException("Couldn't find the metadata for the provided plugin type", nameof(T)); @@ -85,14 +108,16 @@ public static void Register(Func? shouldShow) where T : BasePlugin Register(metadata.Name, metadata.Version.WithoutBuild().Clean(), metadata.Version.IsPreRelease, shouldShow); } - internal static string? GetText() + internal static string? GetText(Location location) { - var mods = _modIdentifiers.Where(m => m.ShouldShow).Select(m => m.Text).ToArray(); - if (mods.Length == 0) - { - return null; - } + var modTexts = _modIdentifiers.Where(m => m.ShouldShow(location)).Select(m => m.Text).ToArray(); + if (modTexts.Length == 0) return null; - return ("" + string.Join(", ", mods)).Size("50%").Align("center"); + return location switch + { + Location.MainMenu => string.Join('\n', modTexts), + Location.PingTracker => ("" + string.Join(", ", modTexts)).Size("50%").Align("center"), + _ => throw new ArgumentOutOfRangeException(nameof(location), location, null), + }; } }