< Summary

Class:TeleportPromptHUDView
Assembly:TeleportPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TeleportPromptHUD/TeleportPromptHUDView.cs
Covered lines:28
Uncovered lines:42
Coverable lines:70
Total lines:175
Line coverage:40% (28 of 70)
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%5.264057.14%

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    IWebRequestAsyncOperation fetchParcelImageOp;
 54    Texture2D downloadedBanner;
 55    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 56
 57    private void Awake()
 58    {
 359        hudCanvasCameraModeController = new HUDCanvasCameraModeController(content.GetComponent<Canvas>(), DataStore.i.ca
 360        closeButton.onClick.AddListener(OnClosePressed);
 361        cancelButton.onClick.AddListener(OnClosePressed);
 362        continueButton.onClick.AddListener(OnTeleportPressed);
 463        contentAnimator.OnWillFinishHide += (animator) => Hide();
 364    }
 65
 66    public void Reset()
 67    {
 168        containerCoords.SetActive(false);
 169        containerCrowd.SetActive(false);
 170        containerMagic.SetActive(false);
 171        containerScene.SetActive(false);
 172        containerEvent.SetActive(false);
 73
 174        imageSceneThumbnail.gameObject.SetActive(false);
 175        imageGotoCrowd.gameObject.SetActive(false);
 176        imageGotoMagic.gameObject.SetActive(false);
 77
 178        spinnerImage.SetActive(false);
 179        spinnerGeneral.SetActive(false);
 180    }
 81
 82    public void ShowTeleportToMagic()
 83    {
 184        containerMagic.SetActive(true);
 185        imageGotoMagic.gameObject.SetActive(true);
 186    }
 87
 88    public void ShowTeleportToCrowd()
 89    {
 090        containerCrowd.SetActive(true);
 091        imageGotoCrowd.gameObject.SetActive(true);
 092    }
 93
 94    public void ShowTeleportToCoords(string coords, string sceneName, string sceneCreator, string previewImageUrl)
 95    {
 096        containerCoords.SetActive(true);
 097        containerScene.SetActive(true);
 98
 099        textCoords.text = coords;
 0100        textSceneName.text = sceneName;
 0101        textSceneOwner.text = sceneCreator;
 102
 0103        FetchScenePreviewImage(previewImageUrl);
 0104    }
 105
 106    public void SetEventInfo(string eventName, string eventStatus, int attendeesCount)
 107    {
 0108        containerEvent.SetActive(true);
 0109        textEventInfo.text = eventStatus;
 0110        textEventName.text = eventName;
 0111        textEventAttendees.text = string.Format("+{0}", attendeesCount);
 0112    }
 113
 114    private void Hide()
 115    {
 1116        content.SetActive(false);
 117
 1118        if (fetchParcelImageOp != null)
 0119            fetchParcelImageOp.Dispose();
 120
 1121        if (downloadedBanner != null)
 122        {
 0123            UnityEngine.Object.Destroy(downloadedBanner);
 0124            downloadedBanner = null;
 125        }
 1126    }
 127
 128    private void FetchScenePreviewImage(string previewImageUrl)
 129    {
 0130        if (string.IsNullOrEmpty(previewImageUrl))
 0131            return;
 132
 0133        spinnerImage.SetActive(true);
 0134        fetchParcelImageOp = Utils.FetchTexture(previewImageUrl, false, (texture) =>
 135        {
 0136            downloadedBanner = texture;
 0137            imageSceneThumbnail.texture = texture;
 138
 0139            RectTransform rt = (RectTransform)imageSceneThumbnail.transform.parent;
 0140            float h = rt.rect.height;
 0141            float w = h * (texture.width / (float)texture.height);
 0142            imageSceneThumbnail.rectTransform.sizeDelta = new Vector2(w, h);
 143
 0144            spinnerImage.SetActive(false);
 0145            imageSceneThumbnail.gameObject.SetActive(true);
 0146        });
 0147    }
 148
 149    private void OnClosePressed()
 150    {
 0151        OnCloseEvent?.Invoke();
 0152        contentAnimator.Hide(true);
 153
 0154        AudioScriptableObjects.dialogClose.Play(true);
 0155    }
 156
 157    private void OnTeleportPressed()
 158    {
 0159        OnTeleportEvent?.Invoke();
 0160        contentAnimator.Hide(true);
 0161    }
 162
 163    private void OnDestroy()
 164    {
 3165        hudCanvasCameraModeController?.Dispose();
 3166        if (downloadedBanner != null)
 167        {
 0168            UnityEngine.Object.Destroy(downloadedBanner);
 0169            downloadedBanner = null;
 170        }
 171
 3172        if (fetchParcelImageOp != null)
 0173            fetchParcelImageOp.Dispose();
 3174    }
 175}