< Summary

Class:DCL.Social.Passports.PassportNavigationComponentView
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PassportNavigation/PassportNavigationComponentView.cs
Covered lines:0
Uncovered lines:100
Coverable lines:100
Total lines:259
Line coverage:0% (0 of 100)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PassportNavigationComponentView()0%2100%
PassportNavigationComponentView()0%2100%
Start()0%2100%
InitializeView()0%2100%
SetGuestUser(...)0%2100%
SetName(...)0%2100%
SetDescription(...)0%12300%
SetEquippedWearables(...)0%12300%
SetCollectibleWearables(...)0%30500%
SetCollectibleEmotes(...)0%30500%
SetInitialTab()0%2100%
ClickOnBuyWearable(...)0%6200%
CleanEquippedWearables()0%6200%
CleanWearables()0%6200%
GetNftIconEntryPool()0%6200%
GetNftPagesEntryPool()0%6200%
RefreshControl()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PassportNavigation/PassportNavigationComponentView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5using TMPro;
 6
 7namespace DCL.Social.Passports
 8{
 9    public class PassportNavigationComponentView : BaseComponentView, IPassportNavigationComponentView
 10    {
 11        private const string GUEST_TEXT = "is a guest";
 12        private const string TEMPLATE_DESCRIPTION_TEXT = "This person doesn't have an about description yet.";
 13        private const int ABOUT_SUB_SECTION_INDEX = 0;
 14        private const int COLLECTIBLES_SUB_SECTION_INDEX = 1;
 15
 16        [SerializeField] private GameObject aboutPanel;
 17        [SerializeField] private GameObject wearablesPanel;
 18        [SerializeField] private SectionSelectorComponentView subSectionSelector;
 19        [SerializeField] private GameObject guestPanel;
 20        [SerializeField] private GameObject normalPanel;
 21        [SerializeField] private Transform equippedWearablesContainer;
 22        [SerializeField] private TextMeshProUGUI usernameText;
 23        [SerializeField] private TextMeshProUGUI descriptionText;
 24        [SerializeField] private CarouselComponentView nftWearablesCarousel;
 25        [SerializeField] private CarouselComponentView nftEmotesCarousel;
 26        [SerializeField] private Transform nftWearablesCarouselContent;
 27        [SerializeField] private Transform nftEmotesCarouselContent;
 28        [SerializeField] private GameObject wearableUIReferenceObject;
 29        [SerializeField] private GameObject nftPageUIReferenceObject;
 30
 31        public event Action<string> OnClickBuyNft;
 32
 33        private const string NFT_ICON_POOL_NAME_PREFIX = "NFTIconsEntriesPool_";
 34        private const string NFT_PAGES_POOL_NAME_PREFIX = "NFTPagesEntriesPool_";
 35        private const int MAX_NFT_ICON_ENTRIES = 20;
 36        private const int MAX_NFT_PAGES_ENTRIES = 20;
 037        private static readonly Vector3 NFT_ICON_SCALE = new Vector3(0.7f, 0.7f, 0.7f);
 38
 039        private List<PoolableObject> nftIconPoolableQueue = new List<PoolableObject>();
 040        private List<PoolableObject> nftPagesPoolableQueue = new List<PoolableObject>();
 41        private Pool nftIconsEntryPool;
 42        private Pool nftPagesEntryPool;
 43
 44        public override void Start()
 45        {
 046            subSectionSelector.GetSection(ABOUT_SUB_SECTION_INDEX).onSelect.RemoveAllListeners();
 047            subSectionSelector.GetSection(COLLECTIBLES_SUB_SECTION_INDEX).onSelect.RemoveAllListeners();
 048            subSectionSelector.GetSection(ABOUT_SUB_SECTION_INDEX).onSelect.AddListener((isActive) => aboutPanel.SetActi
 049            subSectionSelector.GetSection(COLLECTIBLES_SUB_SECTION_INDEX).onSelect.AddListener((isActive) => wearablesPa
 050        }
 51
 52        public void InitializeView()
 53        {
 054            nftPagesEntryPool = GetNftPagesEntryPool();
 055            nftIconsEntryPool = GetNftIconEntryPool();
 056            CleanWearables();
 057            CleanEquippedWearables();
 058            SetInitialTab();
 059        }
 60
 61        public void SetGuestUser(bool isGuest)
 62        {
 063            guestPanel.SetActive(isGuest);
 064            normalPanel.SetActive(!isGuest);
 065        }
 66
 67        public void SetName(string username)
 68        {
 069            usernameText.text = $"{username} {GUEST_TEXT}";
 070        }
 71
 72        public void SetDescription(string description)
 73        {
 074            descriptionText.text = string.IsNullOrEmpty(description) ? TEMPLATE_DESCRIPTION_TEXT : description;
 075        }
 76
 77        public void SetEquippedWearables(WearableItem[] wearables, string bodyShapeId)
 78        {
 079            HashSet<string> hidesList = WearableItem.ComposeHiddenCategories(bodyShapeId, wearables.ToList());
 80
 081            foreach (var wearable in wearables)
 82            {
 083                if (!hidesList.Contains(wearable.data.category))
 84                {
 085                    PoolableObject poolableObject = nftIconsEntryPool.Get();
 086                    nftIconPoolableQueue.Add(poolableObject);
 087                    poolableObject.gameObject.transform.SetParent(equippedWearablesContainer, false);
 088                    poolableObject.gameObject.transform.localScale = NFT_ICON_SCALE;
 089                    NFTIconComponentView nftIconComponentView = poolableObject.gameObject.GetComponent<NFTIconComponentV
 090                    nftIconComponentView.onMarketplaceButtonClick.RemoveAllListeners();
 091                    nftIconComponentView.onMarketplaceButtonClick.AddListener(() => ClickOnBuyWearable(wearable.id));
 92
 093                    NFTIconComponentModel nftModel = new NFTIconComponentModel()
 94                    {
 95                        showMarketplaceButton = wearable.IsCollectible(),
 96                        showType = wearable.IsCollectible(),
 97                        type = wearable.data.category,
 98                        marketplaceURI = "",
 99                        name = wearable.GetName(),
 100                        rarity = wearable.rarity,
 101                        imageURI = wearable.ComposeThumbnailUrl()
 102                    };
 103
 0104                    nftIconComponentView.Configure(nftModel);
 105                }
 106            }
 0107        }
 108
 109        public void SetCollectibleWearables(WearableItem[] wearables)
 110        {
 0111            nftWearablesCarousel.CleanInstantiatedItems();
 0112            for (int i = 0; i < wearables.Length; i += 4)
 113            {
 0114                PoolableObject nftPagePoolElement = nftPagesEntryPool.Get();
 0115                nftPagesPoolableQueue.Add(nftPagePoolElement);
 0116                nftPagePoolElement.gameObject.transform.SetParent(nftWearablesCarouselContent, false);
 0117                NftPageView nftPageView = nftPagePoolElement.gameObject.GetComponent<NftPageView>();
 0118                nftPageView.OnClickBuyNft -= ClickOnBuyWearable;
 0119                NFTIconComponentModel[] pageElements = new NFTIconComponentModel[4];
 0120                string[] nftIds = new string[4];
 0121                for (int j = 0; j < 4; j++)
 122                {
 0123                    if (wearables.Length > i + j && wearables[i + j] != null)
 124                    {
 0125                        pageElements[j] = new ()
 126                        {
 127                            showMarketplaceButton = true,
 128                            showType = true,
 129                            type = wearables[i+j].data.category,
 130                            marketplaceURI = "",
 131                            name = wearables[i+j].GetName(),
 132                            rarity = wearables[i+j].rarity,
 133                            imageURI = wearables[i+j].ComposeThumbnailUrl()
 134                        };
 135
 0136                        nftIds[j] = wearables[i + j].id;
 137                    }
 138                    else
 139                    {
 0140                        pageElements[j] = null;
 0141                        nftIds[j] = "";
 142                    }
 143                }
 0144                nftPageView.SetPageElementsContent(pageElements, nftIds);
 0145                nftPageView.OnClickBuyNft += ClickOnBuyWearable;
 0146                nftWearablesCarousel.AddItem(nftPageView);
 147            }
 0148            nftWearablesCarousel.GenerateDotsSelector();
 0149            nftWearablesCarousel.ResetManualCarousel();
 0150        }
 151
 152        public void SetCollectibleEmotes(WearableItem[] wearables)
 153        {
 0154            nftEmotesCarousel.CleanInstantiatedItems();
 0155            for (int i = 0; i < wearables.Length; i += 4)
 156            {
 0157                PoolableObject nftPagePoolElement = nftPagesEntryPool.Get();
 0158                nftPagesPoolableQueue.Add(nftPagePoolElement);
 0159                nftPagePoolElement.gameObject.transform.SetParent(nftEmotesCarouselContent, false);
 0160                NftPageView nftPageView = nftPagePoolElement.gameObject.GetComponent<NftPageView>();
 0161                nftPageView.OnClickBuyNft -= ClickOnBuyWearable;
 0162                NFTIconComponentModel[] pageElements = new NFTIconComponentModel[4];
 0163                string[] nftIds = new string[4];
 0164                for (int j = 0; j < 4; j++)
 165                {
 0166                    if (wearables.Length > i + j && wearables[i + j] != null)
 167                    {
 0168                        pageElements[j] = new ()
 169                        {
 170                            showMarketplaceButton = true,
 171                            showType = true,
 172                            type = "emote",
 173                            marketplaceURI = "",
 174                            name = wearables[i+j].GetName(),
 175                            rarity = wearables[i+j].rarity,
 176                            imageURI = wearables[i+j].ComposeThumbnailUrl()
 177                        };
 178
 0179                        nftIds[j] = wearables[i + j].id;
 180                    }
 181                    else
 182                    {
 0183                        pageElements[j] = null;
 0184                        nftIds[j] = "";
 185                    }
 186                }
 0187                nftPageView.SetPageElementsContent(pageElements, nftIds);
 0188                nftPageView.OnClickBuyNft += ClickOnBuyWearable;
 0189                nftEmotesCarousel.AddItem(nftPageView);
 190            }
 0191            nftEmotesCarousel.GenerateDotsSelector();
 0192            nftEmotesCarousel.ResetManualCarousel();
 0193        }
 194
 195        public void SetInitialTab()
 196        {
 0197            subSectionSelector.GetSection(ABOUT_SUB_SECTION_INDEX).SelectToggle();
 0198            subSectionSelector.GetSection(COLLECTIBLES_SUB_SECTION_INDEX).SetUnselectedVisuals();
 0199        }
 200
 201        private void ClickOnBuyWearable(string wearableId)
 202        {
 0203            OnClickBuyNft?.Invoke(wearableId);
 0204        }
 205
 206        private void CleanEquippedWearables()
 207        {
 0208            foreach (var poolObject in nftIconPoolableQueue)
 209            {
 0210                nftIconsEntryPool.Release(poolObject);
 211            }
 0212            nftIconPoolableQueue = new List<PoolableObject>();
 0213        }
 214
 215        private void CleanWearables()
 216        {
 0217            foreach (var poolObject in nftPagesPoolableQueue)
 218            {
 0219                nftPagesEntryPool.Release(poolObject);
 220            }
 0221            nftPagesPoolableQueue = new List<PoolableObject>();
 0222        }
 223
 224        private Pool GetNftIconEntryPool()
 225        {
 0226            var pool = PoolManager.i.GetPool(NFT_ICON_POOL_NAME_PREFIX + name + GetInstanceID());
 0227            if (pool != null) return pool;
 228
 0229            pool = PoolManager.i.AddPool(
 230                NFT_ICON_POOL_NAME_PREFIX + name + GetInstanceID(),
 231                Instantiate(wearableUIReferenceObject).gameObject,
 232                maxPrewarmCount: MAX_NFT_ICON_ENTRIES,
 233                isPersistent: true);
 0234            pool.ForcePrewarm();
 235
 0236            return pool;
 237        }
 238
 239        private Pool GetNftPagesEntryPool()
 240        {
 0241            var pool = PoolManager.i.GetPool(NFT_PAGES_POOL_NAME_PREFIX + name + GetInstanceID());
 0242            if (pool != null) return pool;
 243
 0244            pool = PoolManager.i.AddPool(
 245                NFT_PAGES_POOL_NAME_PREFIX + name + GetInstanceID(),
 246                Instantiate(nftPageUIReferenceObject).gameObject,
 247                maxPrewarmCount: MAX_NFT_PAGES_ENTRIES,
 248                isPersistent: true);
 0249            pool.ForcePrewarm();
 250
 0251            return pool;
 252        }
 253
 254        public override void RefreshControl()
 255        {
 0256        }
 257
 258    }
 259}