< Summary

Class:DCL.EmotesCustomization.EmoteCardComponentView
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/EmotesCustomization/EmoteCardComponentView.cs
Covered lines:124
Uncovered lines:10
Coverable lines:134
Total lines:287
Line coverage:92.5% (124 of 134)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmoteCardComponentView()0%110100%
Awake()0%330100%
Configure(...)0%2.032080%
RefreshControl()0%44094.44%
OnEnable()0%110100%
OnFocus()0%220100%
OnLoseFocus()0%220100%
Dispose()0%220100%
SetEmoteId(...)0%3.583060%
SetEmoteName(...)0%2.032080%
SetEmoteDescription(...)0%110100%
SetEmotePicture(...)0%4.054085.71%
SetEmotePicture(...)0%5.25080%
SetEmoteAsAssignedInSelectedSlot(...)0%110100%
AssignSlot(...)0%2.022083.33%
UnassignSlot()0%110100%
SetEmoteAsSelected(...)0%550100%
SetRarity(...)0%3.033085.71%
SetIsInL2(...)0%110100%
SetIsCollectible(...)0%110100%
SetAsLoading(...)0%330100%
RefreshVisualCardStatus()0%110100%
RefreshAssignedSlotTextVisibility()0%220100%
RefreshSelectionFrameVisibility()0%440100%
RefreshCardButtonsVisibility()0%220100%
OnEmoteImageLoaded(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/EmotesCustomization/EmoteCardComponentView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCL.EmotesCustomization
 9{
 10    public class EmoteCardComponentView : BaseComponentView, IEmoteCardComponentView, IComponentModelConfig<EmoteCardCom
 11    {
 112        internal static readonly int ON_SELECTED_CARD_COMPONENT_BOOL = Animator.StringToHash("OnSelected");
 13
 14        [Header("Prefab References")]
 15        [SerializeField] internal ImageComponentView emoteImage;
 16        [SerializeField] internal GameObject emoteNameContainer;
 17        [SerializeField] internal TMP_Text emoteNameText;
 18        [SerializeField] internal TMP_Text assignedSlotNumberText;
 19        [SerializeField] internal ButtonComponentView mainButton;
 20        [SerializeField] internal ButtonComponentView infoButton;
 21        [SerializeField] internal GameObject cardSelectionFrame;
 22        [SerializeField] internal Animator selectionAnimator;
 23        [SerializeField] internal Image rarityMark;
 24        [SerializeField] internal Transform emoteInfoAnchor;
 25        [SerializeField] internal GameObject loadingSpinnerGO;
 26
 27        [Header("Configuration")]
 28        [SerializeField] internal Sprite defaultEmotePicture;
 29        [SerializeField] internal Sprite nonEmoteAssignedPicture;
 30        [SerializeField] internal List<EmoteRarity> rarityColors;
 31        [SerializeField] internal EmoteCardComponentModel model;
 32
 186233        public Button.ButtonClickedEvent onMainClick => mainButton?.onClick;
 186234        public Button.ButtonClickedEvent onInfoClick => infoButton?.onClick;
 35
 36        public event Action<string> onEmoteSelected;
 37
 38        public override void Awake()
 39        {
 99740            base.Awake();
 41
 99742            if (emoteImage != null)
 99643                emoteImage.OnLoaded += OnEmoteImageLoaded;
 44
 99745            if (cardSelectionFrame != null)
 99646                cardSelectionFrame.SetActive(false);
 99747        }
 48
 49        public void Configure(EmoteCardComponentModel newModel)
 50        {
 93251            if (model == newModel)
 052                return;
 53
 93254            model = newModel;
 93255            RefreshControl();
 93256        }
 57
 58        public override void RefreshControl()
 59        {
 377260            if (model == null)
 161                return;
 62
 377163            SetEmoteId(model.id);
 377164            SetEmoteName(model.name);
 377165            SetEmoteDescription(model.description);
 66
 377167            if (model.pictureSprite != null)
 376468                SetEmotePicture(model.pictureSprite);
 769            else if (!string.IsNullOrEmpty(model.pictureUri))
 770                SetEmotePicture(model.pictureUri);
 71            else
 072                OnEmoteImageLoaded(null);
 73
 377174            SetEmoteAsAssignedInSelectedSlot(model.isAssignedInSelectedSlot);
 377175            AssignSlot(model.assignedSlot);
 377176            SetEmoteAsSelected(model.isSelected);
 377177            SetRarity(model.rarity);
 377178            SetIsInL2(model.isInL2);
 377179            SetIsCollectible(model.isCollectible);
 377180            SetAsLoading(model.isLoading);
 377181        }
 82
 83        public override void OnEnable()
 84        {
 284085            base.OnEnable();
 86
 284087            RefreshControl();
 284088        }
 89
 90        public override void OnFocus()
 91        {
 192            base.OnFocus();
 93
 194            if (emoteNameContainer != null)
 195                emoteNameContainer.SetActive(true);
 96
 197            SetEmoteAsSelected(true);
 198        }
 99
 100        public override void OnLoseFocus()
 101        {
 2841102            base.OnLoseFocus();
 103
 2841104            if (emoteNameContainer != null)
 2840105                emoteNameContainer.SetActive(false);
 106
 2841107            SetEmoteAsSelected(false);
 2841108        }
 109
 110        public override void Dispose()
 111        {
 1030112            base.Dispose();
 113
 1030114            if (emoteImage != null)
 115            {
 1029116                emoteImage.OnLoaded -= OnEmoteImageLoaded;
 1029117                emoteImage.Dispose();
 118            }
 1030119        }
 120
 121        public void SetEmoteId(string id)
 122        {
 3772123            model.id = id;
 124
 3772125            if (string.IsNullOrEmpty(id))
 126            {
 0127                if (nonEmoteAssignedPicture != null)
 0128                    SetEmotePicture(nonEmoteAssignedPicture);
 129            }
 3772130        }
 131
 132        public void SetEmoteName(string name)
 133        {
 3772134            model.name = name;
 135
 3772136            if (emoteNameText == null)
 0137                return;
 138
 3772139            emoteNameText.text = name;
 3772140        }
 141
 142        public void SetEmoteDescription(string description)
 143        {
 3772144            model.description = description;
 3772145        }
 146
 147        public void SetEmotePicture(Sprite sprite)
 148        {
 3769149            if (sprite == null && defaultEmotePicture != null)
 2150                sprite = defaultEmotePicture;
 151
 3769152            model.pictureSprite = sprite;
 153
 3769154            if (emoteImage == null)
 0155                return;
 156
 3769157            emoteImage.SetImage(sprite);
 3769158        }
 159
 160        public void SetEmotePicture(string uri)
 161        {
 9162            if (string.IsNullOrEmpty(uri) && defaultEmotePicture != null)
 163            {
 1164                SetEmotePicture(defaultEmotePicture);
 1165                return;
 166            }
 167
 8168            model.pictureUri = uri;
 169
 8170            if (!Application.isPlaying)
 0171                return;
 172
 8173            if (emoteImage == null)
 0174                return;
 175
 8176            emoteImage.SetImage(uri);
 8177        }
 178
 179        public void SetEmoteAsAssignedInSelectedSlot(bool isAssigned)
 180        {
 3787181            model.isAssignedInSelectedSlot = isAssigned;
 182
 3787183            RefreshVisualCardStatus();
 3787184        }
 185
 186        public void AssignSlot(int slotNumber)
 187        {
 3783188            model.assignedSlot = slotNumber;
 189
 3783190            if (assignedSlotNumberText == null)
 0191                return;
 192
 3783193            assignedSlotNumberText.text = slotNumber.ToString();
 194
 3783195            RefreshVisualCardStatus();
 3783196        }
 197
 2198        public void UnassignSlot() { AssignSlot(-1); }
 199
 200        public void SetEmoteAsSelected(bool isSelected)
 201        {
 6615202            model.isSelected = isSelected;
 203
 6615204            if (selectionAnimator != null)
 6614205                selectionAnimator.SetBool(ON_SELECTED_CARD_COMPONENT_BOOL, isSelected);
 206
 6615207            RefreshVisualCardStatus();
 208
 6615209            if (isSelected)
 84210                onEmoteSelected?.Invoke(model.id);
 211            else
 6531212                onEmoteSelected?.Invoke(null);
 2792213        }
 214
 215        public void SetRarity(string rarity)
 216        {
 3773217            model.rarity = rarity;
 218
 3773219            if (rarityMark == null)
 0220                return;
 221
 18534222            EmoteRarity emoteRarity = rarityColors.FirstOrDefault(x => x.rarity == rarity);
 3773223            rarityMark.gameObject.SetActive(emoteRarity != null);
 3773224            rarityMark.color = emoteRarity != null ? emoteRarity.markColor : Color.white;
 3773225        }
 226
 227        public void SetIsInL2(bool isInL2)
 228        {
 3773229            model.isInL2 = isInL2;
 3773230        }
 231
 232        public void SetIsCollectible(bool isCollectible)
 233        {
 3773234            model.isCollectible = isCollectible;
 235
 3773236            RefreshVisualCardStatus();
 3773237        }
 238
 239        public void SetAsLoading(bool isLoading)
 240        {
 4686241            model.isLoading = isLoading;
 242
 4686243            if (loadingSpinnerGO != null)
 4685244                loadingSpinnerGO.SetActive(isLoading);
 245
 4686246            if (mainButton != null)
 4685247                mainButton.gameObject.SetActive(!isLoading);
 4686248        }
 249
 250        internal void RefreshVisualCardStatus()
 251        {
 17958252            RefreshAssignedSlotTextVisibility();
 17958253            RefreshSelectionFrameVisibility();
 17958254            RefreshCardButtonsVisibility();
 17958255        }
 256
 257        internal void RefreshAssignedSlotTextVisibility()
 258        {
 17960259            if (assignedSlotNumberText == null)
 1260                return;
 261
 17959262            assignedSlotNumberText.gameObject.SetActive(model.assignedSlot >= 0);
 17959263        }
 264
 265        internal void RefreshSelectionFrameVisibility()
 266        {
 17960267            if (cardSelectionFrame == null)
 1268                return;
 269
 17959270            cardSelectionFrame.SetActive(model.isSelected || model.isAssignedInSelectedSlot);
 17959271        }
 272
 273        internal void RefreshCardButtonsVisibility()
 274        {
 17960275            if (infoButton != null)
 17959276                infoButton.gameObject.SetActive(model.isCollectible);
 17960277        }
 278
 279        internal void OnEmoteImageLoaded(Sprite sprite)
 280        {
 2281            if (sprite != null)
 1282                SetEmotePicture(sprite);
 283            else
 1284                SetEmotePicture(sprite: null);
 1285        }
 286    }
 287}