< Summary

Class:NFTIconComponentView
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/NFTIcons/NFTIconComponentView.cs
Covered lines:23
Uncovered lines:56
Coverable lines:79
Total lines:175
Line coverage:29.1% (23 of 79)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Configure(...)0%6200%
RefreshControl()0%6200%
SetName(...)0%330100%
SetMarketplaceURI(...)0%110100%
SetImageURI(...)0%12300%
SetShowType(...)0%2100%
SetType(...)0%2100%
SetRarity(...)0%2100%
SetShowMarketplaceButton(...)0%110100%
OnFocus()0%2.032080%
OnLoseFocus()0%330100%
ConfigureNFTItemInfo(...)0%2100%
SetNFTItemInfoActive(...)0%20400%
SetNFTIconAsSelected(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/NFTIcons/NFTIconComponentView.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public class NFTIconComponentView : BaseComponentView, INFTIconComponentView, IComponentModelConfig<NFTIconComponentMode
 6{
 7
 8    [SerializeField] internal ButtonComponentView marketplaceButton;
 9    [SerializeField] internal Button detailInfoButton;
 10    [SerializeField] internal TMP_Text nftName;
 11    [SerializeField] internal TMP_Text nftNameMarketPlace;
 12    [SerializeField] internal GameObject marketplaceSection;
 13    [SerializeField] internal GameObject outline;
 14    [SerializeField] internal ImageComponentView nftImage;
 15    [SerializeField] internal TMP_Text nftTextInsteadOfImage;
 16    [SerializeField] internal ImageComponentView typeImage;
 17    [SerializeField] internal Image backgroundImage;
 18    [SerializeField] internal Image rarityBackgroundImage;
 19    [SerializeField] internal NFTTypeIconsAndColors nftTypesIcons;
 20    [SerializeField] internal NFTSkinFactory skinFactory;
 21    [SerializeField] internal SizeOnHover sizeOnHoverComponent;
 22    [SerializeField] internal Transform nftItemInfoPositionRightRef;
 23    [SerializeField] internal Transform nftItemInfoPositionLeftRef;
 24
 25    [SerializeField] internal NFTIconComponentModel model;
 26
 027    public Button.ButtonClickedEvent onMarketplaceButtonClick => marketplaceButton.onClick;
 028    public Button.ButtonClickedEvent onDetailInfoButtonClick => detailInfoButton.onClick;
 29
 30    private NFTItemInfo nftItemInfo;
 31    private NFTItemInfo.Model nftItemInfoCurrentModel;
 32    private bool showCategoryInfoOnNftItem;
 33    private string nftItemInfoRarity;
 34
 35    public void Configure(NFTIconComponentModel newModel)
 36    {
 037        if (model == newModel)
 038            return;
 39
 040        model = newModel;
 041        RefreshControl();
 042    }
 43
 44    public override void RefreshControl()
 45    {
 046        if (model == null)
 047            return;
 48
 049        SetName(model.name);
 050        SetShowMarketplaceButton(model.showMarketplaceButton);
 051        SetMarketplaceURI(model.marketplaceURI);
 052        SetImageURI(model.imageURI);
 053        SetShowType(model.showType);
 054        SetType(model.type);
 055        SetRarity(model.rarity);
 056    }
 57
 58    public void SetName(string name)
 59    {
 160        model.name = name;
 61
 162        if (nftName != null)
 163            nftName.text = name;
 64
 165        if(nftNameMarketPlace != null)
 166            nftNameMarketPlace.text = name;
 167    }
 68
 69    public void SetMarketplaceURI(string marketplaceURI)
 70    {
 171        model.marketplaceURI = marketplaceURI;
 172    }
 73
 74    public void SetImageURI(string imageURI)
 75    {
 076        model.imageURI = imageURI;
 77
 078        if (nftImage != null)
 79        {
 080            nftImage.SetImage(imageURI);
 081            nftImage.gameObject.SetActive(!string.IsNullOrEmpty(imageURI));
 82        }
 83
 084        if (nftTextInsteadOfImage != null)
 85        {
 086            nftTextInsteadOfImage.text = model.name;
 087            nftTextInsteadOfImage.gameObject.SetActive(string.IsNullOrEmpty(imageURI));
 88        }
 089    }
 90
 91    public void SetShowType(bool showType)
 92    {
 093        model.showType = showType;
 94
 095        typeImage.gameObject.SetActive(showType);
 096        rarityBackgroundImage.gameObject.SetActive(showType);
 097    }
 98
 99    public void SetType(string type)
 100    {
 0101        model.type = type;
 102
 0103        typeImage.SetImage(nftTypesIcons.GetTypeImage(type));
 0104    }
 105
 106    public void SetRarity(string rarity)
 107    {
 0108        model.rarity = rarity;
 0109        Color rarityColor = nftTypesIcons.GetColor(rarity);
 0110        backgroundImage.color = new Color(rarityColor.r, rarityColor.g, rarityColor.b, 1f);
 0111        rarityBackgroundImage.color = rarityColor;
 0112    }
 113
 114    public void SetShowMarketplaceButton(bool showMarketplaceButton)
 115    {
 2116        model.showMarketplaceButton = showMarketplaceButton;
 2117    }
 118
 119    public override void OnFocus()
 120    {
 1121        if (!sizeOnHoverComponent.enabled)
 0122            return;
 123
 1124        base.OnFocus();
 125
 1126        SetNFTIconAsSelected(true);
 1127    }
 128
 129    public override void OnLoseFocus()
 130    {
 5131        base.OnLoseFocus();
 132
 5133        if (nftItemInfo == null || !nftItemInfo.gameObject.activeSelf)
 5134            SetNFTIconAsSelected(false);
 5135    }
 136
 137    public void ConfigureNFTItemInfo(NFTItemInfo nftItemInfoModal, WearableItem wearableItem, bool showCategoryInfo)
 138    {
 0139        nftItemInfo = nftItemInfoModal;
 0140        nftItemInfo.OnCloseButtonClick.RemoveAllListeners();
 0141        nftItemInfo.OnCloseButtonClick.AddListener(() => SetNFTItemInfoActive(false));
 0142        nftItemInfoCurrentModel = NFTItemInfo.Model.FromWearableItem(wearableItem);
 0143        showCategoryInfoOnNftItem = showCategoryInfo;
 0144        nftItemInfoRarity = wearableItem.rarity;
 0145    }
 146
 147    public void SetNFTItemInfoActive(bool isActive, bool showInLeftSide = false)
 148    {
 0149        SetNFTIconAsSelected(isActive);
 0150        sizeOnHoverComponent.enabled = !isActive;
 151
 0152        if (nftItemInfo != null)
 153        {
 0154            nftItemInfo.SetActive(isActive);
 155
 0156            if (isActive)
 157            {
 0158                nftItemInfo.SetModel(nftItemInfoCurrentModel);
 0159                nftItemInfo.SetSkin(nftItemInfoRarity, skinFactory.GetSkinForRarity(nftItemInfoRarity));
 0160                nftItemInfo.SetSellButtonActive(false);
 0161                nftItemInfo.SetCategoryInfoActive(showCategoryInfoOnNftItem);
 0162                nftItemInfo.transform.position = showInLeftSide ? nftItemInfoPositionLeftRef.position : nftItemInfoPosit
 163            }
 164        }
 0165    }
 166
 167    private void SetNFTIconAsSelected(bool isSelected)
 168    {
 6169        if (!model.showMarketplaceButton)
 2170            return;
 171
 4172        marketplaceSection.SetActive(isSelected);
 4173        outline.SetActive(isSelected);
 4174    }
 175}