< 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:166
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    [SerializeField] Image imageGotoCrowd;
 16    [SerializeField] Image imageGotoMagic;
 17
 18    [Header("Containers")]
 19    [SerializeField] GameObject containerCoords;
 20    [SerializeField] GameObject containerMagic;
 21    [SerializeField] GameObject containerCrowd;
 22    [SerializeField] GameObject containerScene;
 23    [SerializeField] GameObject containerEvent;
 24
 25    [Header("Scene info")]
 26    [SerializeField] TextMeshProUGUI textCoords;
 27    [SerializeField] TextMeshProUGUI textSceneName;
 28    [SerializeField] TextMeshProUGUI textSceneOwner;
 29
 30    [Header("Event info")]
 31    [SerializeField] TextMeshProUGUI textEventInfo;
 32    [SerializeField] TextMeshProUGUI textEventName;
 33    [SerializeField] TextMeshProUGUI textEventAttendees;
 34
 35    [Header("Buttons")]
 36    [SerializeField] Button closeButton;
 37    [SerializeField] Button continueButton;
 38    [SerializeField] Button cancelButton;
 39
 40    [Header("Spinners")]
 41    [SerializeField] GameObject spinnerGeneral;
 42    [SerializeField] GameObject spinnerImage;
 43
 44    public event Action OnCloseEvent;
 45    public event Action OnTeleportEvent;
 46
 47    WebRequestAsyncOperation fetchParcelImageOp;
 48    Texture2D downloadedBanner;
 49
 50    private void Awake()
 51    {
 352        closeButton.onClick.AddListener(OnClosePressed);
 353        cancelButton.onClick.AddListener(OnClosePressed);
 354        continueButton.onClick.AddListener(OnTeleportPressed);
 455        contentAnimator.OnWillFinishHide += (animator) => Hide();
 356    }
 57
 58    public void Reset()
 59    {
 160        containerCoords.SetActive(false);
 161        containerCrowd.SetActive(false);
 162        containerMagic.SetActive(false);
 163        containerScene.SetActive(false);
 164        containerEvent.SetActive(false);
 65
 166        imageSceneThumbnail.gameObject.SetActive(false);
 167        imageGotoCrowd.gameObject.SetActive(false);
 168        imageGotoMagic.gameObject.SetActive(false);
 69
 170        spinnerImage.SetActive(false);
 171        spinnerGeneral.SetActive(false);
 172    }
 73
 74    public void ShowTeleportToMagic()
 75    {
 176        containerMagic.SetActive(true);
 177        imageGotoMagic.gameObject.SetActive(true);
 178    }
 79
 80    public void ShowTeleportToCrowd()
 81    {
 082        containerCrowd.SetActive(true);
 083        imageGotoCrowd.gameObject.SetActive(true);
 084    }
 85
 86    public void ShowTeleportToCoords(string coords, string sceneName, string sceneCreator, string previewImageUrl)
 87    {
 088        containerCoords.SetActive(true);
 089        containerScene.SetActive(true);
 90
 091        textCoords.text = coords;
 092        textSceneName.text = sceneName;
 093        textSceneOwner.text = sceneCreator;
 94
 095        FetchScenePreviewImage(previewImageUrl);
 096    }
 97
 98    public void SetEventInfo(string eventName, string eventStatus, int attendeesCount)
 99    {
 0100        containerEvent.SetActive(true);
 0101        textEventInfo.text = eventStatus;
 0102        textEventName.text = eventName;
 0103        textEventAttendees.text = string.Format("+{0}", attendeesCount);
 0104    }
 105
 106    private void Hide()
 107    {
 1108        content.SetActive(false);
 109
 1110        if (fetchParcelImageOp != null)
 0111            fetchParcelImageOp.Dispose();
 112
 1113        if (downloadedBanner != null)
 114        {
 0115            UnityEngine.Object.Destroy(downloadedBanner);
 0116            downloadedBanner = null;
 117        }
 1118    }
 119
 120    private void FetchScenePreviewImage(string previewImageUrl)
 121    {
 0122        if (string.IsNullOrEmpty(previewImageUrl))
 0123            return;
 124
 0125        spinnerImage.SetActive(true);
 0126        fetchParcelImageOp = Utils.FetchTexture(previewImageUrl, (texture) =>
 127        {
 0128            downloadedBanner = texture;
 0129            imageSceneThumbnail.texture = texture;
 130
 0131            RectTransform rt = (RectTransform)imageSceneThumbnail.transform.parent;
 0132            float h = rt.rect.height;
 0133            float w = h * (texture.width / (float)texture.height);
 0134            imageSceneThumbnail.rectTransform.sizeDelta = new Vector2(w, h);
 135
 0136            spinnerImage.SetActive(false);
 0137            imageSceneThumbnail.gameObject.SetActive(true);
 0138        });
 0139    }
 140
 141    private void OnClosePressed()
 142    {
 0143        OnCloseEvent?.Invoke();
 0144        contentAnimator.Hide(true);
 145
 0146        AudioScriptableObjects.dialogClose.Play(true);
 0147    }
 148
 149    private void OnTeleportPressed()
 150    {
 0151        OnTeleportEvent?.Invoke();
 0152        contentAnimator.Hide(true);
 0153    }
 154
 155    private void OnDestroy()
 156    {
 3157        if (downloadedBanner != null)
 158        {
 0159            UnityEngine.Object.Destroy(downloadedBanner);
 0160            downloadedBanner = null;
 161        }
 162
 3163        if (fetchParcelImageOp != null)
 0164            fetchParcelImageOp.Dispose();
 3165    }
 166}