| | 1 | | using DCL; |
| | 2 | | using DCL.Interface; |
| | 3 | | using System; |
| | 4 | | using System.Collections; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | public class LoadingBridge : MonoBehaviour |
| | 8 | | { |
| | 9 | | private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen; |
| 0 | 10 | | private bool isDecoupledLoadingScreenEnabled => DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(DataStore.i.fe |
| | 11 | |
|
| | 12 | | [Serializable] |
| | 13 | | public class Payload |
| | 14 | | { |
| | 15 | | public bool isVisible; |
| 0 | 16 | | public string message = ""; |
| | 17 | | public bool showTips; |
| | 18 | | } |
| | 19 | |
|
| | 20 | | [Serializable] |
| | 21 | | public class PayloadCoords |
| | 22 | | { |
| | 23 | | public int xCoord; |
| | 24 | | public int yCoord; |
| | 25 | | public string message; |
| | 26 | | } |
| | 27 | |
|
| | 28 | | [Obsolete] |
| | 29 | | public void SetLoadingScreen(string jsonMessage) |
| | 30 | | { |
| 0 | 31 | | if (isDecoupledLoadingScreenEnabled) return; |
| | 32 | |
|
| 0 | 33 | | Payload payload = JsonUtility.FromJson<Payload>(jsonMessage); |
| | 34 | |
|
| 0 | 35 | | if (payload.isVisible && !dataStoreLoadingScreen.Ref.loadingHUD.fadeIn.Get() && !dataStoreLoadingScreen.Ref.load |
| 0 | 36 | | dataStoreLoadingScreen.Ref.loadingHUD.fadeIn.Set(true); |
| | 37 | |
|
| 0 | 38 | | if (!payload.isVisible && !dataStoreLoadingScreen.Ref.loadingHUD.fadeOut.Get()) |
| 0 | 39 | | dataStoreLoadingScreen.Ref.loadingHUD.fadeOut.Set(true); |
| | 40 | |
|
| 0 | 41 | | if (!string.IsNullOrEmpty(payload.message)) |
| 0 | 42 | | dataStoreLoadingScreen.Ref.loadingHUD.message.Set(payload.message); |
| | 43 | |
|
| 0 | 44 | | dataStoreLoadingScreen.Ref.loadingHUD.showTips.Set(payload.showTips); |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | [Obsolete] |
| | 48 | | public void FadeInLoadingHUD(string jsonMessage) |
| | 49 | | { |
| 0 | 50 | | if (isDecoupledLoadingScreenEnabled) return; |
| | 51 | |
|
| | 52 | | //TODO: Logic to be cleaned by the RFC-1 |
| 0 | 53 | | StartCoroutine(WaitForLoadingHUDVisible(jsonMessage)); |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | private IEnumerator WaitForLoadingHUDVisible(string jsonMessage) |
| | 57 | | { |
| | 58 | | //TODO: Logic to be cleaned by the RFC-1 |
| 0 | 59 | | WebInterface.ReportControlEvent(new WebInterface.DeactivateRenderingACK()); |
| | 60 | |
|
| 0 | 61 | | PayloadCoords payload = JsonUtility.FromJson<PayloadCoords>(jsonMessage); |
| | 62 | |
|
| 0 | 63 | | if (!string.IsNullOrEmpty(payload.message)) |
| 0 | 64 | | dataStoreLoadingScreen.Ref.loadingHUD.message.Set(payload.message); |
| | 65 | | else |
| 0 | 66 | | dataStoreLoadingScreen.Ref.loadingHUD.message.Set("Teleporting to " + payload.xCoord + ", " + payload.yCoord |
| | 67 | |
|
| 0 | 68 | | dataStoreLoadingScreen.Ref.loadingHUD.percentage.Set(0); |
| 0 | 69 | | dataStoreLoadingScreen.Ref.loadingHUD.fadeIn.Set(true); |
| | 70 | |
|
| 0 | 71 | | while (!dataStoreLoadingScreen.Ref.loadingHUD.visible.Get()) |
| 0 | 72 | | yield return null; |
| | 73 | |
|
| 0 | 74 | | WebInterface.LoadingHUDReadyForTeleport(payload.xCoord, payload.yCoord); |
| 0 | 75 | | } |
| | 76 | | } |