< Summary

Class:TeleportPromptHUDView
Assembly:TeleportPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TeleportPromptHUD/TeleportPromptHUDView.cs
Covered lines:26
Uncovered lines:42
Coverable lines:68
Total lines:172
Line coverage:38.2% (26 of 68)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Reset()0%110100%
ShowTeleportToMagic()0%110100%
ShowTeleportToCrowd()0%2100%
ShowTeleportToCoords(...)0%2100%
SetEventInfo(...)0%2100%
Hide()0%3.713057.14%
FetchScenePreviewImage(...)0%6200%
OnClosePressed()0%6200%
OnTeleportPressed()0%6200%
OnDestroy()0%4.123050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TeleportPromptHUD/TeleportPromptHUDView.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.UI;
 4using TMPro;
 5using DCL.Helpers;
 6using DCL;
 7
 8public 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    {
 358        closeButton.onClick.AddListener(OnClosePressed);
 359        cancelButton.onClick.AddListener(OnClosePressed);
 360        continueButton.onClick.AddListener(OnTeleportPressed);
 461        contentAnimator.OnWillFinishHide += (animator) => Hide();
 362    }
 63
 64    public void Reset()
 65    {
 166        containerCoords.SetActive(false);
 167        containerCrowd.SetActive(false);
 168        containerMagic.SetActive(false);
 169        containerScene.SetActive(false);
 170        containerEvent.SetActive(false);
 71
 172        imageSceneThumbnail.gameObject.SetActive(false);
 173        imageGotoCrowd.gameObject.SetActive(false);
 174        imageGotoMagic.gameObject.SetActive(false);
 75
 176        spinnerImage.SetActive(false);
 177        spinnerGeneral.SetActive(false);
 178    }
 79
 80    public void ShowTeleportToMagic()
 81    {
 182        containerMagic.SetActive(true);
 183        imageGotoMagic.gameObject.SetActive(true);
 184    }
 85
 86    public void ShowTeleportToCrowd()
 87    {
 088        containerCrowd.SetActive(true);
 089        imageGotoCrowd.gameObject.SetActive(true);
 090    }
 91
 92    public void ShowTeleportToCoords(string coords, string sceneName, string sceneCreator, string previewImageUrl)
 93    {
 094        containerCoords.SetActive(true);
 095        containerScene.SetActive(true);
 96
 097        textCoords.text = coords;
 098        textSceneName.text = sceneName;
 099        textSceneOwner.text = sceneCreator;
 100
 0101        FetchScenePreviewImage(previewImageUrl);
 0102    }
 103
 104    public void SetEventInfo(string eventName, string eventStatus, int attendeesCount)
 105    {
 0106        containerEvent.SetActive(true);
 0107        textEventInfo.text = eventStatus;
 0108        textEventName.text = eventName;
 0109        textEventAttendees.text = string.Format("+{0}", attendeesCount);
 0110    }
 111
 112    private void Hide()
 113    {
 1114        content.SetActive(false);
 115
 1116        if (fetchParcelImageOp != null)
 0117            fetchParcelImageOp.Dispose();
 118
 1119        if (downloadedBanner != null)
 120        {
 0121            UnityEngine.Object.Destroy(downloadedBanner);
 0122            downloadedBanner = null;
 123        }
 1124    }
 125
 126    private void FetchScenePreviewImage(string previewImageUrl)
 127    {
 0128        if (string.IsNullOrEmpty(previewImageUrl))
 0129            return;
 130
 0131        spinnerImage.SetActive(true);
 0132        fetchParcelImageOp = Utils.FetchTexture(previewImageUrl, false, (texture) =>
 133        {
 0134            downloadedBanner = texture;
 0135            imageSceneThumbnail.texture = texture;
 136
 0137            RectTransform rt = (RectTransform)imageSceneThumbnail.transform.parent;
 0138            float h = rt.rect.height;
 0139            float w = h * (texture.width / (float)texture.height);
 0140            imageSceneThumbnail.rectTransform.sizeDelta = new Vector2(w, h);
 141
 0142            spinnerImage.SetActive(false);
 0143            imageSceneThumbnail.gameObject.SetActive(true);
 0144        });
 0145    }
 146
 147    private void OnClosePressed()
 148    {
 0149        OnCloseEvent?.Invoke();
 0150        contentAnimator.Hide(true);
 151
 0152        AudioScriptableObjects.dialogClose.Play(true);
 0153    }
 154
 155    private void OnTeleportPressed()
 156    {
 0157        OnTeleportEvent?.Invoke();
 0158        contentAnimator.Hide(true);
 0159    }
 160
 161    private void OnDestroy()
 162    {
 3163        if (downloadedBanner != null)
 164        {
 0165            UnityEngine.Object.Destroy(downloadedBanner);
 0166            downloadedBanner = null;
 167        }
 168
 3169        if (fetchParcelImageOp != null)
 0170            fetchParcelImageOp.Dispose();
 3171    }
 172}