| | 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 ShowHideAnimator contentAnimator; |
| | 12 | |
|
| | 13 | | [Header("Images")] |
| | 14 | | [SerializeField] RawImage imageSceneThumbnail; |
| | 15 | |
|
| | 16 | | [SerializeField] Image imageGotoCrowd; |
| | 17 | | [SerializeField] Image imageGotoMagic; |
| | 18 | |
|
| | 19 | | [Header("Containers")] |
| | 20 | | [SerializeField] GameObject containerCoords; |
| | 21 | |
|
| | 22 | | [SerializeField] GameObject containerMagic; |
| | 23 | | [SerializeField] GameObject containerCrowd; |
| | 24 | | [SerializeField] GameObject containerScene; |
| | 25 | | [SerializeField] GameObject containerEvent; |
| | 26 | |
|
| | 27 | | [Header("Scene info")] |
| | 28 | | [SerializeField] TextMeshProUGUI textCoords; |
| | 29 | |
|
| | 30 | | [SerializeField] TextMeshProUGUI textSceneName; |
| | 31 | | [SerializeField] TextMeshProUGUI textSceneOwner; |
| | 32 | |
|
| | 33 | | [Header("Event info")] |
| | 34 | | [SerializeField] TextMeshProUGUI textEventInfo; |
| | 35 | |
|
| | 36 | | [SerializeField] TextMeshProUGUI textEventName; |
| | 37 | | [SerializeField] TextMeshProUGUI textEventAttendees; |
| | 38 | |
|
| | 39 | | [Header("Buttons")] |
| | 40 | | [SerializeField] Button closeButton; |
| | 41 | |
|
| | 42 | | [SerializeField] Button continueButton; |
| | 43 | | [SerializeField] Button cancelButton; |
| | 44 | |
|
| | 45 | | [Header("Spinners")] |
| | 46 | | [SerializeField] GameObject spinnerGeneral; |
| | 47 | |
|
| | 48 | | [SerializeField] GameObject spinnerImage; |
| | 49 | |
|
| | 50 | | public event Action OnCloseEvent; |
| | 51 | | public event Action OnTeleportEvent; |
| | 52 | |
|
| | 53 | | WebRequestAsyncOperation fetchParcelImageOp; |
| | 54 | | Texture2D downloadedBanner; |
| | 55 | |
|
| | 56 | | private void Awake() |
| | 57 | | { |
| 3 | 58 | | closeButton.onClick.AddListener(OnClosePressed); |
| 3 | 59 | | cancelButton.onClick.AddListener(OnClosePressed); |
| 3 | 60 | | continueButton.onClick.AddListener(OnTeleportPressed); |
| 4 | 61 | | contentAnimator.OnWillFinishHide += (animator) => Hide(); |
| 3 | 62 | | } |
| | 63 | |
|
| | 64 | | public void Reset() |
| | 65 | | { |
| 1 | 66 | | containerCoords.SetActive(false); |
| 1 | 67 | | containerCrowd.SetActive(false); |
| 1 | 68 | | containerMagic.SetActive(false); |
| 1 | 69 | | containerScene.SetActive(false); |
| 1 | 70 | | containerEvent.SetActive(false); |
| | 71 | |
|
| 1 | 72 | | imageSceneThumbnail.gameObject.SetActive(false); |
| 1 | 73 | | imageGotoCrowd.gameObject.SetActive(false); |
| 1 | 74 | | imageGotoMagic.gameObject.SetActive(false); |
| | 75 | |
|
| 1 | 76 | | spinnerImage.SetActive(false); |
| 1 | 77 | | spinnerGeneral.SetActive(false); |
| 1 | 78 | | } |
| | 79 | |
|
| | 80 | | public void ShowTeleportToMagic() |
| | 81 | | { |
| 1 | 82 | | containerMagic.SetActive(true); |
| 1 | 83 | | imageGotoMagic.gameObject.SetActive(true); |
| 1 | 84 | | } |
| | 85 | |
|
| | 86 | | public void ShowTeleportToCrowd() |
| | 87 | | { |
| 0 | 88 | | containerCrowd.SetActive(true); |
| 0 | 89 | | imageGotoCrowd.gameObject.SetActive(true); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | public void ShowTeleportToCoords(string coords, string sceneName, string sceneCreator, string previewImageUrl) |
| | 93 | | { |
| 0 | 94 | | containerCoords.SetActive(true); |
| 0 | 95 | | containerScene.SetActive(true); |
| | 96 | |
|
| 0 | 97 | | textCoords.text = coords; |
| 0 | 98 | | textSceneName.text = sceneName; |
| 0 | 99 | | textSceneOwner.text = sceneCreator; |
| | 100 | |
|
| 0 | 101 | | FetchScenePreviewImage(previewImageUrl); |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | public void SetEventInfo(string eventName, string eventStatus, int attendeesCount) |
| | 105 | | { |
| 0 | 106 | | containerEvent.SetActive(true); |
| 0 | 107 | | textEventInfo.text = eventStatus; |
| 0 | 108 | | textEventName.text = eventName; |
| 0 | 109 | | textEventAttendees.text = string.Format("+{0}", attendeesCount); |
| 0 | 110 | | } |
| | 111 | |
|
| | 112 | | private void Hide() |
| | 113 | | { |
| 1 | 114 | | content.SetActive(false); |
| | 115 | |
|
| 1 | 116 | | if (fetchParcelImageOp != null) |
| 0 | 117 | | fetchParcelImageOp.Dispose(); |
| | 118 | |
|
| 1 | 119 | | if (downloadedBanner != null) |
| | 120 | | { |
| 0 | 121 | | UnityEngine.Object.Destroy(downloadedBanner); |
| 0 | 122 | | downloadedBanner = null; |
| | 123 | | } |
| 1 | 124 | | } |
| | 125 | |
|
| | 126 | | private void FetchScenePreviewImage(string previewImageUrl) |
| | 127 | | { |
| 0 | 128 | | if (string.IsNullOrEmpty(previewImageUrl)) |
| 0 | 129 | | return; |
| | 130 | |
|
| 0 | 131 | | spinnerImage.SetActive(true); |
| 0 | 132 | | fetchParcelImageOp = Utils.FetchTexture(previewImageUrl, false, (texture) => |
| | 133 | | { |
| 0 | 134 | | downloadedBanner = texture; |
| 0 | 135 | | imageSceneThumbnail.texture = texture; |
| | 136 | |
|
| 0 | 137 | | RectTransform rt = (RectTransform)imageSceneThumbnail.transform.parent; |
| 0 | 138 | | float h = rt.rect.height; |
| 0 | 139 | | float w = h * (texture.width / (float)texture.height); |
| 0 | 140 | | imageSceneThumbnail.rectTransform.sizeDelta = new Vector2(w, h); |
| | 141 | |
|
| 0 | 142 | | spinnerImage.SetActive(false); |
| 0 | 143 | | imageSceneThumbnail.gameObject.SetActive(true); |
| 0 | 144 | | }); |
| 0 | 145 | | } |
| | 146 | |
|
| | 147 | | private void OnClosePressed() |
| | 148 | | { |
| 0 | 149 | | OnCloseEvent?.Invoke(); |
| 0 | 150 | | contentAnimator.Hide(true); |
| | 151 | |
|
| 0 | 152 | | AudioScriptableObjects.dialogClose.Play(true); |
| 0 | 153 | | } |
| | 154 | |
|
| | 155 | | private void OnTeleportPressed() |
| | 156 | | { |
| 0 | 157 | | OnTeleportEvent?.Invoke(); |
| 0 | 158 | | contentAnimator.Hide(true); |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | private void OnDestroy() |
| | 162 | | { |
| 3 | 163 | | if (downloadedBanner != null) |
| | 164 | | { |
| 0 | 165 | | UnityEngine.Object.Destroy(downloadedBanner); |
| 0 | 166 | | downloadedBanner = null; |
| | 167 | | } |
| | 168 | |
|
| 3 | 169 | | if (fetchParcelImageOp != null) |
| 0 | 170 | | fetchParcelImageOp.Dispose(); |
| 3 | 171 | | } |
| | 172 | | } |