2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using BepInEx . Unity . IL2CPP ;
5
+ using Reactor . Patches ;
5
6
using Reactor . Utilities . Extensions ;
6
7
7
8
namespace Reactor . Utilities ;
8
9
9
10
/// <summary>
10
- /// Controls the PingTracker .
11
+ /// Provides a way for mods to show their version information in-game .
11
12
/// </summary>
12
- public static class ReactorPingTracker
13
+ public static class ReactorCredits
13
14
{
14
- private readonly struct ModIdentifier ( string name , string version , Func < bool > ? shouldShow , bool isPreRelease )
15
+ private readonly struct ModIdentifier ( string name , string version , Func < Location , bool > ? shouldShow , bool isPreRelease )
15
16
{
16
17
private const string NormalColor = "#fff" ;
17
18
private const string PreReleaseColor = "#f00" ;
18
19
19
20
public string Name => name ;
20
21
21
- public bool ShouldShow => shouldShow == AlwaysShow || shouldShow ( ) ;
22
22
public string Text { get ; } = $ "{ name } { version } ". EscapeRichText ( ) . Color ( isPreRelease ? PreReleaseColor : NormalColor ) ;
23
+
24
+ public bool ShouldShow ( Location location )
25
+ {
26
+ return shouldShow == AlwaysShow || shouldShow ( location ) ;
27
+ }
23
28
}
24
29
25
30
private static readonly List < ModIdentifier > _modIdentifiers = [ ] ;
26
31
32
+ /// <summary>
33
+ /// Represents the location of where the credit is shown.
34
+ /// </summary>
35
+ public enum Location
36
+ {
37
+ /// <summary>
38
+ /// In the main menu under Reactor/BepInEx versions.
39
+ /// </summary>
40
+ MainMenu ,
41
+
42
+ /// <summary>
43
+ /// During game under the ping tracker.
44
+ /// </summary>
45
+ PingTracker ,
46
+ }
47
+
27
48
/// <summary>
28
49
/// A special value indicating a mod should always show.
29
50
/// </summary>
30
- public const Func < bool > ? AlwaysShow = null ;
51
+ public const Func < Location , bool > ? AlwaysShow = null ;
31
52
32
53
/// <summary>
33
- /// Registers a mod with the <see cref="ReactorPingTracker "/>, adding it to the list of mods that will be displayed in the PingTracker .
54
+ /// Registers a mod with the <see cref="ReactorCredits "/>, adding it to the list of mods that will be displayed.
34
55
/// </summary>
35
56
/// <param name="name">The user-friendly name of the mod. Can contain spaces or special characters.</param>
36
57
/// <param name="version">The version of the mod.</param>
37
- /// <param name="isPreRelease">If this version is a development or beta version. If true, it will display the mod in red in the PingTracker .</param>
58
+ /// <param name="isPreRelease">If this version is a development or beta version. If true, it will display the mod in red.</param>
38
59
/// <param name="shouldShow">
39
60
/// This function will be called every frame to determine if the mod should be displayed or not.
40
61
/// This function should return false if your mod is currently disabled or has no effect on gameplay at the time.
41
- /// If you want the mod to be displayed at all times, you can set this parameter to <see cref="ReactorPingTracker .AlwaysShow"/>.
62
+ /// If you want the mod to be displayed at all times, you can set this parameter to <see cref="ReactorCredits .AlwaysShow"/>.
42
63
/// </param>
43
- public static void Register ( string name , string version , bool isPreRelease , Func < bool > ? shouldShow )
64
+ public static void Register ( string name , string version , bool isPreRelease , Func < Location , bool > ? shouldShow )
44
65
{
45
66
const int MaxLength = 60 ;
46
67
47
68
if ( name . Length + version . Length > MaxLength )
48
69
{
49
- 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.") ;
70
+ 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.") ;
50
71
return ;
51
72
}
52
73
53
74
if ( _modIdentifiers . Any ( m => m . Name == name ) )
54
75
{
55
- Error ( $ "Mod \" { name } \" is already registered in { nameof ( ReactorPingTracker ) } .") ;
76
+ Error ( $ "Mod \" { name } \" is already registered in { nameof ( ReactorCredits ) } .") ;
56
77
return ;
57
78
}
58
79
@@ -62,20 +83,22 @@ public static void Register(string name, string version, bool isPreRelease, Func
62
83
63
84
if ( ! isPreRelease )
64
85
{
65
- Info ( $ "Mod \" { name } \" registered in { nameof ( ReactorPingTracker ) } with version { version } .") ;
86
+ Info ( $ "Mod \" { name } \" registered in { nameof ( ReactorCredits ) } with version { version } .") ;
66
87
}
67
88
else
68
89
{
69
- Warning ( $ "Mod \" { name } \" registered in { nameof ( ReactorPingTracker ) } with DEVELOPMENT/BETA version { version } .") ;
90
+ Warning ( $ "Mod \" { name } \" registered in { nameof ( ReactorCredits ) } with DEVELOPMENT/BETA version { version } .") ;
70
91
}
92
+
93
+ ReactorVersionShower . UpdateText ( ) ;
71
94
}
72
95
73
96
/// <summary>
74
- /// Registers a mod with the <see cref="ReactorPingTracker "/>, adding it to the list of mods that will be displayed in the PingTracker .
97
+ /// Registers a mod with the <see cref="ReactorCredits "/>, adding it to the list of mods that will be displayed.
75
98
/// </summary>
76
99
/// <typeparam name="T">The BepInEx plugin type to get the name and version from.</typeparam>
77
- /// <param name="shouldShow"><inheritdoc cref="Register(string,string,bool,System.Func{bool})" path="/param[@name='shouldShow']"/></param>
78
- public static void Register < T > ( Func < bool > ? shouldShow ) where T : BasePlugin
100
+ /// <param name="shouldShow"><inheritdoc cref="Register(string,string,bool,System.Func{Location, bool})" path="/param[@name='shouldShow']"/></param>
101
+ public static void Register < T > ( Func < Location , bool > ? shouldShow ) where T : BasePlugin
79
102
{
80
103
var pluginInfo = IL2CPPChainloader . Instance . Plugins . Values . SingleOrDefault ( p => p . TypeName == typeof ( T ) . FullName )
81
104
?? throw new ArgumentException ( "Couldn't find the metadata for the provided plugin type" , nameof ( T ) ) ;
@@ -85,14 +108,16 @@ public static void Register<T>(Func<bool>? shouldShow) where T : BasePlugin
85
108
Register ( metadata . Name , metadata . Version . WithoutBuild ( ) . Clean ( ) , metadata . Version . IsPreRelease , shouldShow ) ;
86
109
}
87
110
88
- internal static string ? GetText ( )
111
+ internal static string ? GetText ( Location location )
89
112
{
90
- var mods = _modIdentifiers . Where ( m => m . ShouldShow ) . Select ( m => m . Text ) . ToArray ( ) ;
91
- if ( mods . Length == 0 )
92
- {
93
- return null ;
94
- }
113
+ var modTexts = _modIdentifiers . Where ( m => m . ShouldShow ( location ) ) . Select ( m => m . Text ) . ToArray ( ) ;
114
+ if ( modTexts . Length == 0 ) return null ;
95
115
96
- return ( "<space=3em>" + string . Join ( ", " , mods ) ) . Size ( "50%" ) . Align ( "center" ) ;
116
+ return location switch
117
+ {
118
+ Location . MainMenu => string . Join ( '\n ' , modTexts ) ,
119
+ Location . PingTracker => ( "<space=3em>" + string . Join ( ", " , modTexts ) ) . Size ( "50%" ) . Align ( "center" ) ,
120
+ _ => throw new ArgumentOutOfRangeException ( nameof ( location ) , location , null ) ,
121
+ } ;
97
122
}
98
123
}
0 commit comments