< Summary

Class:DCLFeatures.CameraReel.ScreenshotViewer.ScreenshotVisiblePersonView
Assembly:CameraReel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/ScreenshotViewer/Scripts/ScreenshotVisiblePersonView.cs
Covered lines:0
Uncovered lines:52
Coverable lines:52
Total lines:135
Line coverage:0% (0 of 52)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:13
Method coverage:0% (0 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ScreenshotVisiblePersonView()0%2100%
ScreenshotVisiblePersonView()0%2100%
Awake()0%6200%
OnDestroy()0%2100%
Configure(...)0%12300%
ClearWearables()0%6200%
AddWearable(...)0%2100%
SetProfileName(...)0%2100%
SetProfileAddress(...)0%2100%
SetProfilePicture(...)0%2100%
SetGuestMode(...)0%2100%
ShowHideList()0%20400%
GetWearableEntryPool()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/ScreenshotViewer/Scripts/ScreenshotVisiblePersonView.cs

#LineLine coverage
 1using DCL;
 2using DCLServices.CameraReelService;
 3using System;
 4using System.Collections.Generic;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCLFeatures.CameraReel.ScreenshotViewer
 9{
 10    public class ScreenshotVisiblePersonView : MonoBehaviour
 11    {
 012        public static readonly BaseHashSet<ScreenshotVisiblePersonView> Instances = new ();
 13
 14        [Header("PROFILE")]
 15        [SerializeField] private ProfileCardComponentView profileCard;
 16        [SerializeField] private GameObject isGuestImage;
 17        [SerializeField] private Button wearablesListButton;
 18        [SerializeField] private Button userNameButton;
 19        [SerializeField] private Image dropdownArrow;
 20        [SerializeField] private Sprite arrowUp;
 21
 22        [Header("WEARABLES")]
 23        [SerializeField] private NFTIconComponentView wearableTemplate;
 24        [SerializeField] private Transform wearablesListContainer;
 25        [SerializeField] private GameObject emptyWearablesListMessage;
 26
 027        private readonly Dictionary<NFTIconComponentView, PoolableObject> wearables = new ();
 28
 29        private Sprite arrowDown;
 30        private bool isShowingWearablesList;
 31        private bool hasWearables;
 32
 33        public event Action<VisiblePerson> OnConfigureRequested;
 34        public event Action<NFTIconComponentModel> OnOpenWearableMarketplaceRequested;
 35        public event Action OnOpenProfileRequested;
 36
 37        private void Awake()
 38        {
 039            wearablesListButton.onClick.AddListener(ShowHideList);
 040            userNameButton.onClick.AddListener(() => OnOpenProfileRequested?.Invoke());
 041            arrowDown = dropdownArrow.sprite;
 42
 043            if (!Instances.Contains(this))
 044                Instances.Add(this);
 045        }
 46
 47        private void OnDestroy()
 48        {
 049            Instances.Remove(this);
 050        }
 51
 52        public void Configure(VisiblePerson visiblePerson)
 53        {
 054            if (!Instances.Contains(this))
 055                Instances.Add(this);
 56
 057            wearablesListContainer.gameObject.SetActive(false);
 058            OnConfigureRequested?.Invoke(visiblePerson);
 059        }
 60
 61        public void ClearWearables()
 62        {
 063            foreach ((NFTIconComponentView _, PoolableObject poolObj) in wearables)
 064                poolObj.Release();
 65
 066            wearables.Clear();
 067        }
 68
 69        public void AddWearable(NFTIconComponentModel nftModel)
 70        {
 071            wearablesListContainer.gameObject.SetActive(false);
 072            hasWearables = true;
 73
 074            Pool wearablePool = GetWearableEntryPool();
 075            PoolableObject poolObj = wearablePool.Get();
 076            NFTIconComponentView wearableEntry = poolObj.gameObject.GetComponent<NFTIconComponentView>();
 077            wearableEntry.transform.SetParent(wearablesListContainer, false);
 078            wearableEntry.Configure(nftModel);
 079            Button equipButton = wearableEntry.GetComponent<Button>();
 080            equipButton.onClick.RemoveAllListeners();
 081            equipButton.onClick.AddListener(() => OnOpenWearableMarketplaceRequested?.Invoke(nftModel));
 082            wearableEntry.gameObject.SetActive(true);
 083            wearables[wearableEntry] = poolObj;
 084        }
 85
 86        public void SetProfileName(string userName)
 87        {
 088            profileCard.SetProfileName(userName);
 089        }
 90
 91        public void SetProfileAddress(string address)
 92        {
 093            profileCard.SetProfileAddress(address);
 094        }
 95
 96        public void SetProfilePicture(string url)
 97        {
 098            profileCard.SetProfilePicture(url);
 099        }
 100
 101        public void SetGuestMode(bool isGuest)
 102        {
 0103            isGuestImage.SetActive(isGuest);
 0104            wearablesListButton.interactable = !isGuest;
 0105        }
 106
 107        private void ShowHideList()
 108        {
 0109            isShowingWearablesList = !isShowingWearablesList;
 0110            dropdownArrow.sprite = isShowingWearablesList ? arrowUp : arrowDown;
 111
 0112            if (hasWearables)
 0113                wearablesListContainer.gameObject.SetActive(isShowingWearablesList);
 114            else
 0115                emptyWearablesListMessage.SetActive(isShowingWearablesList);
 116
 0117            LayoutRebuilder.ForceRebuildLayoutImmediate(transform as RectTransform);
 0118        }
 119
 120        private Pool GetWearableEntryPool()
 121        {
 122            const string POOL_ID = "CameraReelPictureDetailProfileWearables";
 0123            var entryPool = PoolManager.i.GetPool(POOL_ID);
 0124            if (entryPool != null) return entryPool;
 125
 0126            entryPool = PoolManager.i.AddPool(
 127                POOL_ID,
 128                Instantiate(wearableTemplate).gameObject,
 129                maxPrewarmCount: 10,
 130                isPersistent: true);
 131
 0132            return entryPool;
 133        }
 134    }
 135}