| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | | using TMPro; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using DCL; |
| | 7 | |
|
| | 8 | | public class TeleportPromptHUDView : MonoBehaviour |
| | 9 | | { |
| | 10 | | [SerializeField] internal GameObject content; |
| | 11 | | [SerializeField] internal Animator teleportHUDAnimator; |
| | 12 | | [SerializeField] internal GraphicRaycaster teleportRaycaster; |
| | 13 | |
|
| | 14 | | [Header("Images")] |
| | 15 | | [SerializeField] private RawImage imageSceneThumbnail; |
| | 16 | |
|
| | 17 | | [SerializeField] private Image imageGotoCrowd; |
| | 18 | | [SerializeField] internal Image imageGotoMagic; |
| | 19 | | [SerializeField] private Texture2D nullImage; |
| | 20 | |
|
| | 21 | | [Header("Containers")] |
| | 22 | | [SerializeField] private GameObject containerCoords; |
| | 23 | |
|
| | 24 | | [SerializeField] private GameObject containerMagic; |
| | 25 | | [SerializeField] private GameObject containerCrowd; |
| | 26 | | [SerializeField] private GameObject containerScene; |
| | 27 | | [SerializeField] private GameObject containerEvent; |
| | 28 | | [SerializeField] private GameObject creatorContainer; |
| | 29 | |
|
| | 30 | | [Header("Scene info")] |
| | 31 | | [SerializeField] private TextMeshProUGUI textCoords; |
| | 32 | |
|
| | 33 | | [SerializeField] private TextMeshProUGUI textSceneName; |
| | 34 | | [SerializeField] private TextMeshProUGUI textSceneOwner; |
| | 35 | |
|
| | 36 | | [Header("Event info")] |
| | 37 | | [SerializeField] private TextMeshProUGUI textEventInfo; |
| | 38 | |
|
| | 39 | | [SerializeField] private TextMeshProUGUI textEventName; |
| | 40 | | [SerializeField] private TextMeshProUGUI textEventAttendees; |
| | 41 | |
|
| | 42 | | [SerializeField] private Button continueButton; |
| | 43 | | [SerializeField] private Button cancelButton; |
| | 44 | | [SerializeField] private Button backgroundCatcher; |
| | 45 | |
|
| | 46 | | public event Action OnCloseEvent; |
| | 47 | | public event Action OnTeleportEvent; |
| | 48 | |
|
| | 49 | | IWebRequestAsyncOperation fetchParcelImageOp; |
| | 50 | | Texture2D downloadedBanner; |
| | 51 | | private HUDCanvasCameraModeController hudCanvasCameraModeController; |
| 1 | 52 | | private static readonly int IDLE = Animator.StringToHash("Idle"); |
| 1 | 53 | | private static readonly int OUT = Animator.StringToHash("Out"); |
| 1 | 54 | | private static readonly int IN = Animator.StringToHash("In"); |
| | 55 | |
|
| | 56 | | private void Awake() |
| | 57 | | { |
| 2 | 58 | | hudCanvasCameraModeController = new HUDCanvasCameraModeController(content.GetComponent<Canvas>(), DataStore.i.ca |
| 2 | 59 | | cancelButton.onClick.AddListener(OnClosePressed); |
| 2 | 60 | | backgroundCatcher.onClick.AddListener(OnClosePressed); |
| 2 | 61 | | continueButton.onClick.AddListener(OnTeleportPressed); |
| 2 | 62 | | teleportRaycaster.enabled = false; |
| 2 | 63 | | } |
| | 64 | |
|
| | 65 | | public void Reset() |
| | 66 | | { |
| 1 | 67 | | containerCoords.SetActive(false); |
| 1 | 68 | | containerCrowd.SetActive(false); |
| 1 | 69 | | containerMagic.SetActive(false); |
| 1 | 70 | | containerScene.SetActive(false); |
| 1 | 71 | | containerEvent.SetActive(false); |
| | 72 | |
|
| 1 | 73 | | imageSceneThumbnail.gameObject.SetActive(false); |
| 1 | 74 | | imageGotoCrowd.gameObject.SetActive(false); |
| 1 | 75 | | imageGotoMagic.gameObject.SetActive(false); |
| 1 | 76 | | } |
| | 77 | |
|
| | 78 | | public void SetLoadingCompleted() |
| | 79 | | { |
| 0 | 80 | | teleportHUDAnimator.SetTrigger(IDLE); |
| 0 | 81 | | } |
| | 82 | |
|
| | 83 | | public void SetInAnimation() |
| | 84 | | { |
| 1 | 85 | | teleportRaycaster.enabled = true; |
| 1 | 86 | | teleportHUDAnimator.SetTrigger(IN); |
| 1 | 87 | | } |
| | 88 | |
|
| | 89 | | public void SetOutAnimation() |
| | 90 | | { |
| 0 | 91 | | teleportRaycaster.enabled = false; |
| 0 | 92 | | teleportHUDAnimator.SetTrigger(OUT); |
| 0 | 93 | | } |
| | 94 | |
|
| | 95 | | public void ShowTeleportToMagic() |
| | 96 | | { |
| 1 | 97 | | containerMagic.SetActive(true); |
| 1 | 98 | | imageGotoMagic.gameObject.SetActive(true); |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | public void ShowTeleportToCrowd() |
| | 102 | | { |
| 0 | 103 | | containerCrowd.SetActive(true); |
| 0 | 104 | | imageGotoCrowd.gameObject.SetActive(true); |
| 0 | 105 | | } |
| | 106 | |
|
| | 107 | | public void ShowTeleportToCoords(string coords, string sceneName, string sceneCreator, string previewImageUrl) |
| | 108 | | { |
| 0 | 109 | | containerCoords.SetActive(true); |
| 0 | 110 | | containerScene.SetActive(true); |
| | 111 | |
|
| 0 | 112 | | textCoords.text = coords; |
| 0 | 113 | | textSceneName.text = !string.IsNullOrEmpty(sceneName) ? sceneName : "Untitled Scene"; |
| 0 | 114 | | creatorContainer.SetActive(!string.IsNullOrEmpty(sceneCreator)); |
| 0 | 115 | | textSceneOwner.text = sceneCreator; |
| 0 | 116 | | SetParcelImage(previewImageUrl); |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | public void SetEventInfo(string eventName, string eventStatus, int attendeesCount) |
| | 120 | | { |
| 0 | 121 | | containerEvent.SetActive(true); |
| 0 | 122 | | textEventInfo.text = eventStatus; |
| 0 | 123 | | textEventName.text = eventName; |
| 0 | 124 | | textEventAttendees.text = $"+{attendeesCount}"; |
| 0 | 125 | | } |
| | 126 | |
|
| | 127 | | private AssetPromise_Texture texturePromise; |
| | 128 | |
|
| | 129 | | public void SetParcelImage(string imageUrl) |
| | 130 | | { |
| 0 | 131 | | containerMagic.SetActive(false); |
| 0 | 132 | | imageSceneThumbnail.gameObject.SetActive(true); |
| | 133 | |
|
| 0 | 134 | | if (string.IsNullOrEmpty(imageUrl)) |
| | 135 | | { |
| 0 | 136 | | DisplayThumbnail(nullImage); |
| 0 | 137 | | return; |
| | 138 | | } |
| | 139 | |
|
| 0 | 140 | | if (texturePromise != null) |
| 0 | 141 | | AssetPromiseKeeper_Texture.i.Forget(texturePromise); |
| | 142 | |
|
| 0 | 143 | | texturePromise = new AssetPromise_Texture(imageUrl, storeTexAsNonReadable: false); |
| 0 | 144 | | texturePromise.OnSuccessEvent += (textureAsset) => { DisplayThumbnail(textureAsset.texture); }; |
| 0 | 145 | | texturePromise.OnFailEvent += (x, e) => DisplayThumbnail(nullImage); |
| 0 | 146 | | AssetPromiseKeeper_Texture.i.Keep(texturePromise); |
| 0 | 147 | | } |
| | 148 | |
|
| | 149 | | private void DisplayThumbnail(Texture2D texture) |
| | 150 | | { |
| 0 | 151 | | imageSceneThumbnail.texture = texture; |
| 0 | 152 | | } |
| | 153 | |
|
| | 154 | | private void OnClosePressed() |
| | 155 | | { |
| 0 | 156 | | OnCloseEvent?.Invoke(); |
| 0 | 157 | | } |
| | 158 | |
|
| | 159 | | private void OnTeleportPressed() |
| | 160 | | { |
| 0 | 161 | | OnTeleportEvent?.Invoke(); |
| 0 | 162 | | } |
| | 163 | |
|
| | 164 | | private void OnDestroy() |
| | 165 | | { |
| 2 | 166 | | hudCanvasCameraModeController?.Dispose(); |
| | 167 | |
|
| 2 | 168 | | if (downloadedBanner != null) |
| | 169 | | { |
| 0 | 170 | | UnityEngine.Object.Destroy(downloadedBanner); |
| 0 | 171 | | downloadedBanner = null; |
| | 172 | | } |
| | 173 | |
|
| 2 | 174 | | if (fetchParcelImageOp != null) |
| 0 | 175 | | fetchParcelImageOp.Dispose(); |
| 2 | 176 | | } |
| | 177 | | } |