99using LevelImposter . DB ;
1010using LevelImposter . FileIO ;
1111using LevelImposter . Networking . API ;
12+ using TMPro ;
1213using UnityEngine ;
1314
1415namespace LevelImposter . Shop ;
@@ -37,16 +38,31 @@ public class ShopManager(IntPtr intPtr) : MonoBehaviour(intPtr)
3738 public Il2CppReferenceField < GameObjectGrid > mapBannerGrid ;
3839 public Il2CppReferenceField < PassiveButton > exitButton ;
3940 public Il2CppReferenceField < PassiveButton > openMapsFolderButton ;
41+ public Il2CppReferenceField < GameObject > loadingOverlay ;
42+ public Il2CppReferenceField < TextMeshPro > loadingText ;
43+ public Il2CppReferenceField < GameObject > errorOverlay ;
44+ public Il2CppReferenceField < TextMeshPro > errorText ;
4045
4146 public static ShopManager ? Instance { get ; private set ; }
4247
4348 private const string CONTROLLER_OVERLAY_ID = "LIShop" ;
4449
4550 /// If true, re-runs the map randomization when the shop is closed
4651 private bool _randomizeMapsOnClose ;
47-
4852 private ShopTab _currentTab = ShopTab . None ;
4953 private ShopTabButton [ ] ? _shopTabButtons ;
54+ private readonly string [ ] _funLoadingTexts =
55+ [
56+ "Searching dropship..." ,
57+ "Calibrating engines..." ,
58+ "Searching for habitable planets..." ,
59+ "Stabilizing reactor..." ,
60+ "Scanning for planetary systems..." ,
61+ "Aligning telescope..." ,
62+ "Navigating asteroids..." ,
63+ "Diverting power..." ,
64+ "Doing card swipe..."
65+ ] ;
5066
5167 public void Awake ( )
5268 {
@@ -131,13 +147,22 @@ public void SetTab(ShopTab tab, Sprite? titleSprite = null)
131147 SetMaps ( lobbyMaps ) ;
132148 break ;
133149 case ShopTab . FeaturedWorkshopMaps :
134- LevelImposterAPI . GetFeatured ( m => OnWorkshopLoaded ( m , tab ) , LILogger . Error ) ;
150+ SetLoadingVisible ( true ) ;
151+ LevelImposterAPI . GetFeatured (
152+ m => OnWorkshopLoaded ( m , tab ) ,
153+ error => OnError ( tab , error ) ) ;
135154 break ;
136155 case ShopTab . TopWorkshopMaps :
137- LevelImposterAPI . GetTop ( m => OnWorkshopLoaded ( m , tab ) , LILogger . Error ) ;
156+ SetLoadingVisible ( true ) ;
157+ LevelImposterAPI . GetTop (
158+ m => OnWorkshopLoaded ( m , tab ) ,
159+ error => OnError ( tab , error ) ) ;
138160 break ;
139161 case ShopTab . RecentWorkshopMaps :
140- LevelImposterAPI . GetRecent ( m => OnWorkshopLoaded ( m , tab ) , LILogger . Error ) ;
162+ SetLoadingVisible ( true ) ;
163+ LevelImposterAPI . GetRecent (
164+ m => OnWorkshopLoaded ( m , tab ) ,
165+ error => OnError ( tab , error ) ) ;
141166 break ;
142167 case ShopTab . None :
143168 break ;
@@ -146,6 +171,33 @@ public void SetTab(ShopTab tab, Sprite? titleSprite = null)
146171 }
147172 }
148173
174+ [ HideFromIl2Cpp ]
175+ private void OnWorkshopLoaded ( LIMetadata [ ] maps , ShopTab targetTab )
176+ {
177+ if ( _currentTab != targetTab )
178+ return ;
179+
180+ SetMaps ( maps ) ;
181+ }
182+ [ HideFromIl2Cpp ]
183+ private void OnError ( ShopTab tab , string message )
184+ {
185+ if ( _currentTab != tab )
186+ return ;
187+
188+ SetErrorVisible ( true , message ) ;
189+ }
190+ private void SetErrorVisible ( bool isVisible , string message = "" )
191+ {
192+ errorOverlay . Value . SetActive ( isVisible ) ;
193+ errorText . Value . text = message ;
194+ if ( ! isVisible )
195+ return ;
196+
197+ // Disable loading overlay
198+ SetLoadingVisible ( false ) ;
199+ }
200+
149201 /// <summary>
150202 /// Updates the visual state of the tab buttons
151203 /// </summary>
@@ -157,29 +209,19 @@ private void UpdateTabButtonState()
157209 foreach ( var tabButton in _shopTabButtons )
158210 tabButton . SetTabSelected ( tabButton . TabType == _currentTab ) ;
159211 }
160-
161- /// <summary>
162- /// Called when workshop maps are loaded.
163- /// Just checks if the current tab is still the target tab before setting the maps.
164- /// </summary>
165- /// <param name="maps">The loaded maps</param>
166- /// <param name="targetTab">The target tab</param>
167- [ HideFromIl2Cpp ]
168- private void OnWorkshopLoaded ( LIMetadata [ ] maps , ShopTab targetTab )
169- {
170- if ( _currentTab != targetTab )
171- return ;
172-
173- SetMaps ( maps ) ;
174- }
175212
213+
176214 /// <summary>
177215 /// Sets the maps to display in the shop
178216 /// </summary>
179217 /// <param name="maps">The maps to display</param>
180218 [ HideFromIl2Cpp ]
181219 private void SetMaps ( LIMetadata [ ] maps )
182220 {
221+ // Hide Overlays
222+ SetLoadingVisible ( false ) ;
223+ SetErrorVisible ( false ) ;
224+
183225 // Clear Existing Banners
184226 mapBannerGrid . Value . DestroyAll ( ) ;
185227
@@ -204,6 +246,24 @@ public void RandomizeMapOnClose()
204246 {
205247 _randomizeMapsOnClose = true ;
206248 }
249+
250+ /// <summary>
251+ /// Shows or hides the loading overlay
252+ /// </summary>
253+ /// <param name="isVisible">Whether the loading overlay should be visible</param>
254+ public void SetLoadingVisible ( bool isVisible )
255+ {
256+ loadingOverlay . Value . SetActive ( isVisible ) ;
257+ if ( ! isVisible )
258+ return ;
259+
260+ // Disable error overlay
261+ SetErrorVisible ( false ) ;
262+
263+ // Randomize loading text
264+ var randomIndex = UnityEngine . Random . Range ( 0 , _funLoadingTexts . Length ) ;
265+ loadingText . Value . text = _funLoadingTexts [ randomIndex ] ;
266+ }
207267
208268 private void AddStarField ( )
209269 {
0 commit comments