1- using IllusionPlugin ;
2- using IllusionInjector ;
3- using System ;
1+ using System ;
42using System . Globalization ;
53using System . Linq ;
64using TMPro ;
75using UnityEngine ;
86using UnityEngine . SceneManagement ;
97using HitScoreVisualizer ;
108using System . Text . RegularExpressions ;
9+ using IPA ;
10+ using IPA . Config ;
11+ using CustomUI . Utilities ;
12+ using System . Collections ;
1113
1214namespace PerfectionDisplay
1315{
14- public class Plugin : IPlugin
16+ public class Plugin : IBeatSaberPlugin
1517 {
16- public string Name => "Perfection Display" ;
17- public string Version => "1.5.1" ;
18-
1918 public static string lastText = "" ;
2019 public static string lastPercent = "" ;
2120 public static string lastCount = "" ;
@@ -30,8 +29,6 @@ public class Plugin : IPlugin
3029
3130 public void OnApplicationStart ( )
3231 {
33- SceneManager . activeSceneChanged += OnSceneChanged ;
34-
3532 if ( ModPrefs . GetString ( "PerfectionDisplay" , "Position" ) == "" )
3633 {
3734 ModPrefs . SetString ( "PerfectionDisplay" , "Position" , FormattableString . Invariant ( $ "{ PerfectDisplay . displayPosition . x : 0.00} ,{ PerfectDisplay . displayPosition . y : 0.00} ,{ PerfectDisplay . displayPosition . z : 0.00} ") ) ;
@@ -78,15 +75,20 @@ public void OnApplicationStart()
7875 PerfectDisplay . showNumbers = ModPrefs . GetBool ( "PerfectionDisplay" , "Show Count" , PerfectDisplay . showNumbers , true ) ;
7976 PerfectDisplay . showPercent = ModPrefs . GetBool ( "PerfectionDisplay" , "Show Percent" , PerfectDisplay . showPercent , true ) ;
8077 PerfectDisplay . shouldHitscore = ModPrefs . GetBool ( "PerfectionDisplay" , "HitScoreVisualizer Integration" , PerfectDisplay . shouldHitscore , true ) ;
78+
79+ BSEvents . menuSceneLoadedFresh += MenuSceneActive ;
80+ BSEvents . menuSceneActive += MenuSceneActive ;
81+ BSEvents . gameSceneActive += GameSceneActive ;
8182 }
8283
8384 public void OnApplicationQuit ( )
8485 {
85- SceneManager . activeSceneChanged -= OnSceneChanged ;
86+ BSEvents . menuSceneActive -= MenuSceneActive ;
87+ BSEvents . gameSceneActive -= GameSceneActive ;
8688 }
8789 private void LoadHitScore ( )
8890 {
89- Config . Judgment [ ] judgments = Config . instance . judgments ;
91+ HitScoreVisualizer . Config . Judgment [ ] judgments = HitScoreVisualizer . Config . instance . judgments ;
9092 PerfectDisplay . scoreRanges = new int [ judgments . Length - 1 ] ;
9193 PerfectDisplay . hitScoreNames = new string [ judgments . Length ] ;
9294 PerfectDisplay . colors = new string [ judgments . Length + 1 ] ;
@@ -100,56 +102,6 @@ private void LoadHitScore()
100102 }
101103 private void OnSceneChanged ( Scene _ , Scene scene )
102104 {
103- if ( gameScenesManager == null )
104- {
105- gameScenesManager = Resources . FindObjectsOfTypeAll < GameScenesManager > ( ) . FirstOrDefault ( ) ;
106- if ( gameScenesManager != null )
107- {
108- gameScenesManager . transitionDidFinishEvent += OnTransition ;
109- }
110- }
111- if ( init )
112- {
113- init = false ;
114- Console . WriteLine ( PluginManager . Plugins ) ;
115- if ( PerfectDisplay . shouldHitscore && PluginManager . Plugins . Any ( x => x . Name == "HitScoreVisualizer" ) ) LoadHitScore ( ) ;
116- else PerfectDisplay . shouldHitscore = false ;
117- }
118- if ( scene . name . Equals ( "MenuCore" ) )
119- {
120- mainFont = Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . First ( t => t . font ? . name == "Teko-Medium SDF No Glow" ) . font ;
121- if ( text != null ) MonoBehaviour . Destroy ( text ) ;
122- if ( percent != null ) MonoBehaviour . Destroy ( percent ) ;
123- if ( count != null ) MonoBehaviour . Destroy ( count ) ;
124- ResultsViewController results = Resources . FindObjectsOfTypeAll < ResultsViewController > ( ) . FirstOrDefault ( ) ;
125- int extraOffset = - 12 ;
126- text = MonoBehaviour . Instantiate ( Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . Last ( x => ( x . name == "Title" ) ) , results . transform , false ) ;
127- text . fontSize = 5 ;
128- text . color = Color . white ;
129- text . lineSpacing = - 15f ;
130- text . paragraphSpacing = - 15f ;
131- text . text = lastText ;
132- text . alignment = TextAlignmentOptions . TopLeft ;
133- text . rectTransform . localPosition = new Vector3 ( - 20 + extraOffset , 35 , 0 ) ;
134- percent = MonoBehaviour . Instantiate ( Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . Last ( x => ( x . name == "Title" ) ) , results . transform , false ) ;
135- percent . fontSize = 5 ;
136- percent . color = Color . white ;
137- percent . paragraphSpacing = - 15f ;
138- percent . lineSpacing = - 15f ;
139- percent . text = lastCount ;
140- percent . alignment = TextAlignmentOptions . TopLeft ;
141- percent . rectTransform . localPosition = new Vector3 ( 0 + extraOffset , 35 , 0 ) ;
142- count = MonoBehaviour . Instantiate ( Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . Last ( x => ( x . name == "Title" ) ) , results . transform , false ) ;
143- count . fontSize = 5 ;
144- count . color = Color . white ;
145- count . lineSpacing = - 15f ;
146- count . paragraphSpacing = - 15f ;
147- count . text = lastPercent ;
148- count . alignment = TextAlignmentOptions . TopLeft ;
149- count . rectTransform . localPosition = new Vector3 ( 15 + extraOffset , 35 , 0 ) ;
150- return ;
151- }
152- if ( scene . name . Equals ( "GameCore" ) ) new GameObject ( "PerfectDisplay" ) . AddComponent < PerfectDisplay > ( ) ;
153105 }
154106 private void OnSceneLoad ( Scene _ , LoadSceneMode mode )
155107 {
@@ -160,23 +112,95 @@ public void OnTransition()
160112 if ( percent != null ) percent . text = lastPercent ;
161113 if ( count != null ) count . text = lastCount ;
162114 }
115+
163116
164- public void OnLevelWasLoaded ( int level )
117+ public void OnUpdate ( )
165118 {
119+ }
166120
121+ public void OnFixedUpdate ( )
122+ {
167123 }
168124
169- public void OnLevelWasInitialized ( int level )
125+ public void OnSceneLoaded ( Scene scene , LoadSceneMode sceneMode )
170126 {
171127
172128 }
173129
174- public void OnUpdate ( )
130+ public void OnSceneUnloaded ( Scene scene )
175131 {
132+
176133 }
177134
178- public void OnFixedUpdate ( )
135+ public void OnActiveSceneChanged ( Scene _ , Scene scene )
179136 {
137+ if ( gameScenesManager == null )
138+ {
139+ gameScenesManager = Resources . FindObjectsOfTypeAll < GameScenesManager > ( ) . FirstOrDefault ( ) ;
140+ if ( gameScenesManager != null )
141+ {
142+ gameScenesManager . transitionDidFinishEvent += OnTransition ;
143+ }
144+ }
145+ if ( init )
146+ {
147+ init = false ;
148+ if ( PerfectDisplay . shouldHitscore && IPA . Loader . PluginManager . Plugins . Any ( x => x . Name == "HitScoreVisualizer" ) ) LoadHitScore ( ) ;
149+ else PerfectDisplay . shouldHitscore = false ;
150+ }
151+ }
152+
153+ public void GameSceneActive ( )
154+ {
155+ new GameObject ( "PerfectDisplay" ) . AddComponent < PerfectDisplay > ( ) ;
156+ }
157+ public void MenuSceneActive ( )
158+ {
159+ if ( mainFont == null ) gameScenesManager . StartCoroutine ( FontHunter ( ) ) ;
160+ if ( text != null ) MonoBehaviour . Destroy ( text ) ;
161+ if ( percent != null ) MonoBehaviour . Destroy ( percent ) ;
162+ if ( count != null ) MonoBehaviour . Destroy ( count ) ;
163+ ResultsViewController results = Resources . FindObjectsOfTypeAll < ResultsViewController > ( ) . FirstOrDefault ( ) ;
164+ int extraOffset = - 12 ;
165+ text = MonoBehaviour . Instantiate ( Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . Last ( x => ( x . name == "Title" ) ) , results . transform , false ) ;
166+ text . fontSize = 5 ;
167+ text . color = Color . white ;
168+ text . lineSpacing = - 15f ;
169+ text . paragraphSpacing = - 15f ;
170+ text . text = lastText ;
171+ text . alignment = TextAlignmentOptions . TopLeft ;
172+ text . rectTransform . localPosition = new Vector3 ( - 20 + extraOffset , 35 , 0 ) ;
173+ percent = MonoBehaviour . Instantiate ( Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . Last ( x => ( x . name == "Title" ) ) , results . transform , false ) ;
174+ percent . fontSize = 5 ;
175+ percent . color = Color . white ;
176+ percent . paragraphSpacing = - 15f ;
177+ percent . lineSpacing = - 15f ;
178+ percent . text = lastCount ;
179+ percent . alignment = TextAlignmentOptions . TopLeft ;
180+ percent . rectTransform . localPosition = new Vector3 ( 0 + extraOffset , 35 , 0 ) ;
181+ count = MonoBehaviour . Instantiate ( Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . Last ( x => ( x . name == "Title" ) ) , results . transform , false ) ;
182+ count . fontSize = 5 ;
183+ count . color = Color . white ;
184+ count . lineSpacing = - 15f ;
185+ count . paragraphSpacing = - 15f ;
186+ count . text = lastPercent ;
187+ count . alignment = TextAlignmentOptions . TopLeft ;
188+ count . rectTransform . localPosition = new Vector3 ( 15 + extraOffset , 35 , 0 ) ;
189+ }
190+ //For some reason can't find the font right when scene loads so this will hunt it down
191+ public IEnumerator FontHunter ( )
192+ {
193+ while ( mainFont == null )
194+ {
195+ try
196+ {
197+ mainFont = Resources . FindObjectsOfTypeAll < TextMeshProUGUI > ( ) . First ( t => t . font ? . name == "Teko-Medium SDF No Glow" ) . font ;
198+ } catch
199+ {
200+
201+ }
202+ yield return new WaitForSeconds ( 1f ) ;
203+ }
180204 }
181205 }
182206}
0 commit comments