| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | using UnityEngine; | 
					
						
							|  |  |  | using UnityEngine.UI; | 
					
						
							|  |  |  | using TMPro; | 
					
						
							|  |  |  | using System; | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  | using Cysharp.Threading.Tasks; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace BulletHellTemplate | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /// <summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |     /// Popup that displays pending "first completion" map rewards and lets the player redeem them. | 
					
						
							|  |  |  |     ///  | 
					
						
							|  |  |  |     /// Relies on RewardManagerPopup for pending + claimed state. | 
					
						
							|  |  |  |     /// When the player clicks Redeem, we call the authoritative server endpoint | 
					
						
							|  |  |  |     /// (via BackendManager.Service.ApplyMapRewardsAsync); on success we mark claimed locally | 
					
						
							|  |  |  |     /// and update UI/economy using the server echo already applied in the backend service extension. | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |     /// </summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |     public sealed class UIRewardManagerPopup : MonoBehaviour | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |     { | 
					
						
							|  |  |  |         public static UIRewardManagerPopup Singleton; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         [Header("UI Components")] | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Root popup GameObject.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public GameObject rewardPopupMenu; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Prefab used for each reward entry row.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public RewardPopupEntry rewardEntryPrefab; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Parent container that holds spawned reward entry rows.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public Transform entryContainer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Button that redeems all pending map rewards.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public Button redeemButton; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Text field used to display temporary error messages.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public TextMeshProUGUI errorText; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Header("Icons for EXP types")] | 
					
						
							|  |  |  |         [Tooltip("Icon representing Account EXP.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public Sprite ExpAccountIcon; | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Icon representing Mastery EXP.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public Sprite ExpMasteryIcon; | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Icon representing Character EXP.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public Sprite ExpCharacterIcon; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         [Header("Settings")] | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Seconds to display transient error messages.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public float errorDisplayTime = 1.5f; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Fallback error prefix if translation unavailable.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public string errorMessage = "Error loading rewards:"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         [Tooltip("Translated versions of the fallback error message.")] | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         public NameTranslatedByLanguage[] errorMessageTranslated; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         private readonly List<MapInfoData> _pendingRewards = new(); | 
					
						
							|  |  |  |         private string _currentLang; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         private void Awake() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (Singleton == null) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 Singleton = this; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 Destroy(gameObject); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void Start() | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             _currentLang = LanguageManager.LanguageManager.Instance.GetCurrentLanguage(); | 
					
						
							|  |  |  |             if (rewardPopupMenu != null) | 
					
						
							|  |  |  |                 rewardPopupMenu.SetActive(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ShowPendingRewards(); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         /// Query pending maps from RewardManagerPopup and rebuild the popup UI. | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         /// </summary> | 
					
						
							|  |  |  |         public void ShowPendingRewards() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             _pendingRewards.Clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             var unclaimed = RewardManagerPopup.Singleton?.GetLocalUnclaimedMaps(); | 
					
						
							|  |  |  |             if (unclaimed == null || unclaimed.Count == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 HidePopup(); | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             foreach (var mapId in unclaimed) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                 var mapData = GetMapDataById(mapId); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |                 if (IsValidRewardMap(mapData)) | 
					
						
							|  |  |  |                     _pendingRewards.Add(mapData); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (_pendingRewards.Count == 0) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                 HidePopup(); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             ShowPopup(); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |             PopulateRewardEntries(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         private void ShowPopup() | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (rewardPopupMenu != null) | 
					
						
							|  |  |  |                 rewardPopupMenu.SetActive(true); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         private void HidePopup() | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (rewardPopupMenu != null) | 
					
						
							|  |  |  |                 rewardPopupMenu.SetActive(false); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         /// Builds the UI rows for all pending rewards. | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         /// </summary> | 
					
						
							|  |  |  |         private void PopulateRewardEntries() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ClearEntries(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             foreach (var mapData in _pendingRewards) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                 // Currency / EXP rewards | 
					
						
							|  |  |  |                 if (mapData.WinMapRewards != null) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                     foreach (var r in mapData.WinMapRewards) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |                     { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                         if (r.currency != null) | 
					
						
							|  |  |  |                             CreateEntry(r.currency.icon, r.amount.ToString()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         if (r.accountExp > 0) | 
					
						
							|  |  |  |                             CreateEntry(ExpAccountIcon, r.accountExp.ToString()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         if (r.characterExp > 0) | 
					
						
							|  |  |  |                             CreateEntry(ExpCharacterIcon, r.characterExp.ToString()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         if (r.characterMasteryAmount > 0) | 
					
						
							|  |  |  |                             CreateEntry(ExpMasteryIcon, r.characterMasteryAmount.ToString()); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                 // Special reward | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |                 if (mapData.rewardType != MapRewardType.None) | 
					
						
							|  |  |  |                     CreateSpecialRewardEntry(mapData); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (redeemButton != null) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 redeemButton.onClick.RemoveAllListeners(); | 
					
						
							|  |  |  |                 redeemButton.onClick.AddListener(() => ClaimAllRewards().Forget()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void ClearEntries() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (entryContainer == null) return; | 
					
						
							|  |  |  |             foreach (Transform child in entryContainer) | 
					
						
							|  |  |  |                 Destroy(child.gameObject); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void CreateEntry(Sprite icon, string amount) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (rewardEntryPrefab == null || entryContainer == null) return; | 
					
						
							|  |  |  |             var entry = Instantiate(rewardEntryPrefab, entryContainer); | 
					
						
							|  |  |  |             entry.Setup(icon, amount); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void CreateSpecialRewardEntry(MapInfoData mapData) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             switch (mapData.rewardType) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 case MapRewardType.Icon when mapData.iconItem != null: | 
					
						
							|  |  |  |                     CreateEntry(mapData.iconItem.icon, "1"); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case MapRewardType.Frame when mapData.frameItem != null: | 
					
						
							|  |  |  |                     CreateEntry(mapData.frameItem.icon, "1"); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case MapRewardType.Character when mapData.characterData != null: | 
					
						
							|  |  |  |                     CreateEntry(mapData.characterData.icon, "1"); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case MapRewardType.InventoryItem when mapData.inventoryItem != null: | 
					
						
							|  |  |  |                     CreateEntry(mapData.inventoryItem.itemIcon, "1"); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         /// Redeems all pending map rewards sequentially (await each to avoid request burst). | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         /// </summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         private async UniTaskVoid ClaimAllRewards() | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (redeemButton != null) | 
					
						
							|  |  |  |                 redeemButton.interactable = false; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             foreach (var mapData in _pendingRewards) | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                 await ClaimSingleMapRewardAsync(mapData); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             // refresh after claims | 
					
						
							|  |  |  |             HidePopup(); | 
					
						
							|  |  |  |             if (redeemButton != null) | 
					
						
							|  |  |  |                 redeemButton.interactable = true; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             UIMainMenu.Singleton?.LoadPlayerInfo(); | 
					
						
							|  |  |  |             UIMainMenu.Singleton?.LoadCharacterInfo(); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         /// Claim a single map reward from the server; mark local on success. | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         /// </summary> | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         private async UniTask ClaimSingleMapRewardAsync(MapInfoData mapData) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (mapData == null) return; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             int characterId = PlayerSave.GetSelectedCharacter(); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             var result = await BackendManager.Service.ApplyMapRewardsAsync( | 
					
						
							|  |  |  |                 new MapCompletionRewardData | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     mapId = mapData.mapId, | 
					
						
							|  |  |  |                     characterId = characterId | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (!result.Success) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                 Debug.LogWarning($"[UIRewardManagerPopup] Map {mapData.mapId} claim failed (code:{result.Reason})."); | 
					
						
							|  |  |  |                 ShowError($"Reward {mapData.mapId} failed ({result.Reason})"); | 
					
						
							|  |  |  |                 return; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             RewardManagerPopup.Singleton?.MarkRewardClaimed(mapData.mapId); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         private bool IsValidRewardMap(MapInfoData mapData) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (mapData == null) return false; | 
					
						
							|  |  |  |             bool hasList = mapData.WinMapRewards != null && mapData.WinMapRewards.Count > 0; | 
					
						
							|  |  |  |             bool hasSpecial = mapData.rewardType != MapRewardType.None; | 
					
						
							|  |  |  |             return mapData.isRewardOnCompleteFirstTime && (hasList || hasSpecial); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |         private MapInfoData GetMapDataById(int mapId) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             var maps = GameInstance.Singleton?.mapInfoData; | 
					
						
							|  |  |  |             if (maps == null) return null; | 
					
						
							|  |  |  |             return Array.Find(maps, m => m != null && m.mapId == mapId); | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void ShowError(string message) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (errorText == null) return; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |             errorText.text = message; | 
					
						
							|  |  |  |             CancelInvoke(nameof(ClearError)); | 
					
						
							|  |  |  |             Invoke(nameof(ClearError), errorDisplayTime); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void ClearError() | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |             if (errorText != null) | 
					
						
							|  |  |  |                 errorText.text = string.Empty; | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public string GetTranslatedString(NameTranslatedByLanguage[] translations, string fallback, string currentLang) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (translations != null) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 foreach (var trans in translations) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2025-09-19 19:43:49 +05:00
										 |  |  |                     if (!string.IsNullOrEmpty(trans.LanguageId) && | 
					
						
							|  |  |  |                         trans.LanguageId.Equals(currentLang, StringComparison.OrdinalIgnoreCase) && | 
					
						
							|  |  |  |                         !string.IsNullOrEmpty(trans.Translate)) | 
					
						
							| 
									
										
										
										
											2025-09-19 14:56:58 +05:00
										 |  |  |                     { | 
					
						
							|  |  |  |                         return trans.Translate; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return fallback; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |