< Summary

Class:DCL.Backpack.WearableGridItemComponentView
Assembly:BackpackEditorHUDV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/WearableGridItemComponentView.cs
Covered lines:46
Uncovered lines:9
Coverable lines:55
Total lines:133
Line coverage:83.6% (46 of 55)
Covered branches:0
Total branches:0
Covered methods:9
Total methods:10
Method coverage:90% (9 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
InitializeInteractButton()0%110100%
Dispose()0%110100%
OnFocus()0%110100%
OnLoseFocus()0%110100%
RefreshControl()0%44095.24%
PlayLoadingSound(...)0%2100%
Unselect()0%110100%
Select()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/WearableGridItemComponentView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UIComponents.Scripts.Components;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7namespace DCL.Backpack
 8{
 9    public class WearableGridItemComponentView : BaseComponentView<WearableGridItemModel>
 10    {
 11        [SerializeField] internal NftRarityBackgroundSO rarityNftBackgrounds;
 12        [SerializeField] internal NFTTypeIconsAndColors nftTypesIcons;
 13        [SerializeField] internal Image nftBackground;
 14        [SerializeField] internal Image categoryImage;
 15        [SerializeField] internal Image categoryBackground;
 16        [SerializeField] internal GameObject selectedContainer;
 17        [SerializeField] internal GameObject equippedContainer;
 18        [SerializeField] internal GameObject isNewContainer;
 19        [SerializeField] internal ImageComponentView image;
 20        [SerializeField] internal Button interactButton;
 21        [SerializeField] internal Material grayScaleMaterial;
 22        [SerializeField] internal GameObject incompatibleContainer;
 23        [SerializeField] internal GameObject incompatibleTooltip;
 24        [SerializeField] internal GameObject smartWearableFlag;
 25        [SerializeField] internal GameObject secondaryItem;
 26        [SerializeField] internal GameObject amountLabel;
 27        [SerializeField] internal TMP_Text amountText;
 28
 29        private IButtonDoubleClick interactDoubleClick;
 30        private string lastThumbnailUrl;
 31
 332        public WearableGridItemModel Model => model;
 33
 34        private int clicked = 0;
 35        private float clickTime = 0;
 36
 37        public event Action<WearableGridItemModel> OnSelected;
 38        public event Action<WearableGridItemModel> OnEquipped;
 39        public event Action<WearableGridItemModel> OnUnequipped;
 40
 41        public override void Awake()
 42        {
 6543            base.Awake();
 6544            image.OnLoaded += PlayLoadingSound;
 6545            InitializeInteractButton();
 6546        }
 47
 48        private void InitializeInteractButton()
 49        {
 6550            interactDoubleClick = interactButton.gameObject.GetComponent<IButtonDoubleClick>();
 6551            interactDoubleClick.AlwaysPerformSingleClick = true;
 7352            interactDoubleClick.OnClick += () => { OnSelected?.Invoke(model); };
 6553            interactDoubleClick.OnDoubleClick += () =>
 54            {
 055                if (model.IsEquipped)
 56                {
 057                    if (!model.UnEquipAllowed)
 058                        return;
 59
 060                    OnUnequipped?.Invoke(model);
 61                }
 62                else
 063                    OnEquipped?.Invoke(model);
 064            };
 6565        }
 66
 67        public override void Dispose() =>
 8668            image.OnLoaded -= PlayLoadingSound;
 69
 70        public override void OnFocus()
 71        {
 172            base.OnFocus();
 173            RefreshControl();
 174            selectedContainer.SetActive(true);
 175        }
 76
 77        public override void OnLoseFocus()
 78        {
 8379            base.OnLoseFocus();
 8380            selectedContainer.SetActive(false);
 8381            RefreshControl();
 8382            incompatibleTooltip.SetActive(false);
 8383        }
 84
 85        public override void RefreshControl()
 86        {
 11787            amountText.text = model.Amount;
 11788            secondaryItem.SetActive(!string.IsNullOrEmpty(amountText.text));
 11789            amountLabel.SetActive(!string.IsNullOrEmpty(amountText.text));
 11790            selectedContainer.SetActive(model.IsSelected);
 11791            equippedContainer.SetActive(model.IsEquipped);
 11792            isNewContainer.SetActive(model.IsNew);
 11793            smartWearableFlag.SetActive(model.IsSmartWearable);
 94            // we gotta check for url changes, otherwise the image component will start a "loading" state, even if the u
 11795            if (lastThumbnailUrl != model.ImageUrl)
 96            {
 3097                image.SetImage(model.ImageUrl);
 3098                lastThumbnailUrl = model.ImageUrl;
 99            }
 100
 117101            string nftRarity = model.Rarity.ToString().ToLower();
 117102            nftBackground.sprite = rarityNftBackgrounds.GetRarityImage(nftRarity);
 117103            categoryBackground.color = nftTypesIcons.GetColor(nftRarity);
 117104            categoryImage.sprite = nftTypesIcons.GetTypeImage(model.Category);
 105
 117106            if (model.IsCompatibleWithBodyShape)
 117107                image.ImageComponent.material = null;
 108            else
 0109                image.ImageComponent.material = grayScaleMaterial;
 110
 117111            incompatibleContainer.SetActive(!model.IsCompatibleWithBodyShape);
 117112            interactButton.interactable = model.IsCompatibleWithBodyShape;
 117113            incompatibleTooltip.SetActive(!model.IsCompatibleWithBodyShape && isFocused);
 117114        }
 115
 116        private void PlayLoadingSound(Sprite sprt)
 117        {
 0118            AudioScriptableObjects.listItemAppear.Play(true);
 0119        }
 120
 121        public void Unselect()
 122        {
 2123            model.IsSelected = false;
 2124            RefreshControl();
 2125        }
 126
 127        public void Select()
 128        {
 1129            model.IsSelected = true;
 1130            RefreshControl();
 1131        }
 132    }
 133}