< Summary

Class:GotoPanel.GotoPanelHUDView
Assembly:GotoHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/GotoPanelHUD/GotoPanelHUDView.cs
Covered lines:24
Uncovered lines:34
Coverable lines:58
Total lines:134
Line coverage:41.3% (24 of 58)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
CreateView()0%2100%
TeleportTo()0%6200%
SetVisible(...)0%110100%
SetPanelInfo(...)0%2.152066.67%
SetParcelImage(...)0%12300%
DisplayThumbnail(...)0%110100%
ClosePanel()0%6200%
Hide()0%2100%
OnDestroy()0%110100%
Dispose()0%6200%
ClearPromise()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/GotoPanelHUD/GotoPanelHUDView.cs

#LineLine coverage
 1using UnityEngine;
 2using TMPro;
 3using UnityEngine.UI;
 4using DCL.Interface;
 5using DCL;
 6using System;
 7
 8namespace GotoPanel
 9{
 10    public class GotoPanelHUDView : MonoBehaviour, IGotoPanelHUDView
 11    {
 12        [SerializeField] private Button teleportButton;
 13        [SerializeField] private TextMeshProUGUI panelText;
 14        [SerializeField] public GameObject container;
 15        [SerializeField] internal TextMeshProUGUI sceneTitleText;
 16        [SerializeField] internal TextMeshProUGUI sceneOwnerText;
 17        [SerializeField] internal Sprite scenePreviewFailImage;
 18        [SerializeField] internal RawImageFillParent scenePreviewImage;
 19        [SerializeField] internal GameObject loadingSpinner;
 20        [SerializeField] internal Button closeButton;
 21        [SerializeField] internal Button cancelButton;
 22        [SerializeField] internal ShowHideAnimator contentAnimator;
 23
 24        private bool isDestroyed = false;
 25
 26        internal ParcelCoordinates targetCoordinates;
 27
 28        AssetPromise_Texture texturePromise = null;
 29
 30        public event Action<ParcelCoordinates> OnTeleportPressed;
 31        public event Action OnClosePressed;
 32
 33        private void Start()
 34        {
 335            teleportButton.onClick.RemoveAllListeners();
 336            teleportButton.onClick.AddListener(TeleportTo);
 337            closeButton.onClick.AddListener(ClosePanel);
 338            cancelButton.onClick.AddListener(ClosePanel);
 339            container.SetActive(false);
 340            contentAnimator.OnWillFinishHide += (animator) => Hide();
 341        }
 42
 43        public static IGotoPanelHUDView CreateView()
 44        {
 045            GotoPanelHUDView view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("GotoPanelHUD")).GetCompon
 046            view.name = "_GotoPanelHUD";
 047            return view;
 48        }
 49
 50        private void TeleportTo()
 51        {
 052            OnTeleportPressed?.Invoke(targetCoordinates);
 053            ClosePanel();
 054        }
 55
 56        public void SetVisible(bool isVisible)
 57        {
 258            container.SetActive(isVisible);
 259            contentAnimator.Show(!isVisible);
 260            loadingSpinner.SetActive(isVisible);
 261            scenePreviewImage.texture = null;
 262        }
 63
 64        public void SetPanelInfo(ParcelCoordinates parcelCoordinates)
 65        {
 166            MinimapMetadata.MinimapSceneInfo sceneInfo = MinimapMetadata.GetMetadata().GetSceneInfo(parcelCoordinates.x,
 167            if (sceneInfo != null)
 68            {
 069                sceneTitleText.text = sceneInfo.name;
 070                sceneOwnerText.text = sceneInfo.owner;
 071                SetParcelImage(sceneInfo);
 072            }
 73            else
 74            {
 175                sceneTitleText.text = "Untitled Scene";
 176                sceneOwnerText.text = "Unknown";
 177                DisplayThumbnail(scenePreviewFailImage.texture);
 78            }
 179            targetCoordinates = parcelCoordinates;
 180            panelText.text = parcelCoordinates.ToString();
 181        }
 82
 83        private void SetParcelImage(MinimapMetadata.MinimapSceneInfo sceneInfo)
 84        {
 085            DisplayThumbnail(scenePreviewFailImage.texture);
 086            if (!string.IsNullOrEmpty(sceneInfo.previewImageUrl))
 87            {
 088                if (texturePromise != null)
 089                    AssetPromiseKeeper_Texture.i.Forget(texturePromise);
 90
 091                texturePromise = new AssetPromise_Texture(sceneInfo.previewImageUrl, storeTexAsNonReadable: false);
 092                texturePromise.OnSuccessEvent += (textureAsset) => { DisplayThumbnail(textureAsset.texture); };
 093                texturePromise.OnFailEvent += (textureAsset, error) => { DisplayThumbnail(scenePreviewFailImage.texture)
 094                AssetPromiseKeeper_Texture.i.Keep(texturePromise);
 95            }
 096        }
 97
 98        private void DisplayThumbnail(Texture2D texture)
 99        {
 1100            loadingSpinner.SetActive(false);
 1101            scenePreviewImage.texture = texture;
 1102        }
 103
 104        private void ClosePanel()
 105        {
 0106            OnClosePressed?.Invoke();
 0107            contentAnimator.Hide(true);
 0108        }
 109
 0110        private void Hide() => container.SetActive(false);
 111
 6112        private void OnDestroy() { isDestroyed = true; }
 113
 114        public void Dispose()
 115        {
 0116            if (isDestroyed)
 0117                return;
 0118            isDestroyed = true;
 0119            ClearPromise();
 0120            Destroy(gameObject);
 0121        }
 122
 123        private void ClearPromise()
 124        {
 0125            if (texturePromise != null)
 126            {
 0127                texturePromise.ClearEvents();
 0128                AssetPromiseKeeper_Texture.i.Forget(texturePromise);
 0129                texturePromise = null;
 130            }
 0131        }
 132
 133    }
 134}