< 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:0
Uncovered lines:140
Coverable lines:140
Total lines:301
Line coverage:0% (0 of 140)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:29
Method coverage:0% (0 of 29)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmoteCardComponentView()0%2100%
Awake()0%12300%
Configure(...)0%6200%
RefreshControl()0%20400%
OnEnable()0%2100%
OnFocus()0%6200%
OnLoseFocus()0%6200%
Dispose()0%6200%
SetEmoteId(...)0%12300%
SetEmoteName(...)0%6200%
SetEmoteDescription(...)0%2100%
SetEmotePicture(...)0%20400%
SetEmotePicture(...)0%30500%
SetEmoteAsAssignedInSelectedSlot(...)0%2100%
AssignSlot(...)0%6200%
UnassignSlot()0%2100%
SetEmoteAsSelected(...)0%30500%
SetRarity(...)0%12300%
SetIsInL2(...)0%2100%
SetIsCollectible(...)0%2100%
SetAsLoading(...)0%12300%
RefreshVisualCardStatus()0%2100%
RefreshAssignedSlotTextVisibility()0%6200%
RefreshSelectionFrameVisibility()0%20400%
RefreshCardButtonsVisibility()0%6200%
OnEmoteImageLoaded(...)0%6200%
SetSoundIcon(...)0%2100%

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    {
 012        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        [SerializeField] internal GameObject soundIcon;
 27        [SerializeField] internal GameObject secondaryItem;
 28        [SerializeField] internal GameObject amountLabel;
 29        [SerializeField] internal TMP_Text amountText;
 30
 31        [Header("Configuration")]
 32        [SerializeField] internal Sprite defaultEmotePicture;
 33        [SerializeField] internal Sprite nonEmoteAssignedPicture;
 34        [SerializeField] internal List<EmoteRarity> rarityColors;
 35        [SerializeField] internal EmoteCardComponentModel model;
 36
 037        public Button.ButtonClickedEvent onMainClick => mainButton?.onClick;
 038        public Button.ButtonClickedEvent onInfoClick => infoButton?.onClick;
 39
 40        public event Action<string> onEmoteSelected;
 41
 42        public override void Awake()
 43        {
 044            base.Awake();
 45
 046            if (emoteImage != null)
 047                emoteImage.OnLoaded += OnEmoteImageLoaded;
 48
 049            if (cardSelectionFrame != null)
 050                cardSelectionFrame.SetActive(false);
 51
 052            SetSoundIcon(false);
 053        }
 54
 55        public void Configure(EmoteCardComponentModel newModel)
 56        {
 057            if (model == newModel)
 058                return;
 59
 060            model = newModel;
 061            RefreshControl();
 062        }
 63
 64        public override void RefreshControl()
 65        {
 066            if (model == null)
 067                return;
 68
 069            amountText.text = model.amount;
 070            secondaryItem.SetActive(!string.IsNullOrEmpty(amountText.text));
 071            amountLabel.SetActive(!string.IsNullOrEmpty(amountText.text));
 072            SetEmoteId(model.id);
 073            SetEmoteName(model.name);
 074            SetEmoteDescription(model.description);
 75
 076            if (model.pictureSprite != null)
 077                SetEmotePicture(model.pictureSprite);
 078            else if (!string.IsNullOrEmpty(model.pictureUri))
 079                SetEmotePicture(model.pictureUri);
 80            else
 081                OnEmoteImageLoaded(null);
 82
 083            SetEmoteAsAssignedInSelectedSlot(model.isAssignedInSelectedSlot);
 084            AssignSlot(model.assignedSlot);
 085            SetEmoteAsSelected(model.isSelected);
 086            SetRarity(model.rarity);
 087            SetIsInL2(model.isInL2);
 088            SetIsCollectible(model.isCollectible);
 089            SetAsLoading(model.isLoading);
 090        }
 91
 92        public override void OnEnable()
 93        {
 094            base.OnEnable();
 95
 096            RefreshControl();
 097        }
 98
 99        public override void OnFocus()
 100        {
 0101            base.OnFocus();
 102
 0103            if (emoteNameContainer != null)
 0104                emoteNameContainer.SetActive(true);
 105
 0106            SetEmoteAsSelected(true);
 0107        }
 108
 109        public override void OnLoseFocus()
 110        {
 0111            base.OnLoseFocus();
 112
 0113            if (emoteNameContainer != null)
 0114                emoteNameContainer.SetActive(false);
 115
 0116            SetEmoteAsSelected(false);
 0117        }
 118
 119        public override void Dispose()
 120        {
 0121            base.Dispose();
 122
 0123            if (emoteImage != null)
 124            {
 0125                emoteImage.OnLoaded -= OnEmoteImageLoaded;
 0126                emoteImage.Dispose();
 127            }
 0128        }
 129
 130        public void SetEmoteId(string id)
 131        {
 0132            model.id = id;
 133
 0134            if (string.IsNullOrEmpty(id))
 135            {
 0136                if (nonEmoteAssignedPicture != null)
 0137                    SetEmotePicture(nonEmoteAssignedPicture);
 138            }
 0139        }
 140
 141        public void SetEmoteName(string name)
 142        {
 0143            model.name = name;
 144
 0145            if (emoteNameText == null)
 0146                return;
 147
 0148            emoteNameText.text = name;
 0149        }
 150
 151        public void SetEmoteDescription(string description)
 152        {
 0153            model.description = description;
 0154        }
 155
 156        public void SetEmotePicture(Sprite sprite)
 157        {
 0158            if (sprite == null && defaultEmotePicture != null)
 0159                sprite = defaultEmotePicture;
 160
 0161            model.pictureSprite = sprite;
 162
 0163            if (emoteImage == null)
 0164                return;
 165
 0166            emoteImage.SetImage(sprite);
 0167        }
 168
 169        public void SetEmotePicture(string uri)
 170        {
 0171            if (string.IsNullOrEmpty(uri) && defaultEmotePicture != null)
 172            {
 0173                SetEmotePicture(defaultEmotePicture);
 0174                return;
 175            }
 176
 0177            model.pictureUri = uri;
 178
 0179            if (!Application.isPlaying)
 0180                return;
 181
 0182            if (emoteImage == null)
 0183                return;
 184
 0185            emoteImage.SetImage(uri);
 0186        }
 187
 188        public void SetEmoteAsAssignedInSelectedSlot(bool isAssigned)
 189        {
 0190            model.isAssignedInSelectedSlot = isAssigned;
 191
 0192            RefreshVisualCardStatus();
 0193        }
 194
 195        public void AssignSlot(int slotNumber)
 196        {
 0197            model.assignedSlot = slotNumber;
 198
 0199            if (assignedSlotNumberText == null)
 0200                return;
 201
 0202            assignedSlotNumberText.text = slotNumber.ToString();
 203
 0204            RefreshVisualCardStatus();
 0205        }
 206
 0207        public void UnassignSlot() { AssignSlot(-1); }
 208
 209        public void SetEmoteAsSelected(bool isSelected)
 210        {
 0211            model.isSelected = isSelected;
 212
 0213            if (selectionAnimator != null)
 0214                selectionAnimator.SetBool(ON_SELECTED_CARD_COMPONENT_BOOL, isSelected);
 215
 0216            RefreshVisualCardStatus();
 217
 0218            if (isSelected)
 0219                onEmoteSelected?.Invoke(model.id);
 220            else
 0221                onEmoteSelected?.Invoke(null);
 0222        }
 223
 224        public void SetRarity(string rarity)
 225        {
 0226            model.rarity = rarity;
 227
 0228            if (rarityMark == null)
 0229                return;
 230
 0231            EmoteRarity emoteRarity = rarityColors.FirstOrDefault(x => x.rarity == rarity);
 0232            rarityMark.gameObject.SetActive(emoteRarity != null);
 0233            rarityMark.color = emoteRarity != null ? emoteRarity.markColor : Color.white;
 0234        }
 235
 236        public void SetIsInL2(bool isInL2)
 237        {
 0238            model.isInL2 = isInL2;
 0239        }
 240
 241        public void SetIsCollectible(bool isCollectible)
 242        {
 0243            model.isCollectible = isCollectible;
 244
 0245            RefreshVisualCardStatus();
 0246        }
 247
 248        public void SetAsLoading(bool isLoading)
 249        {
 0250            model.isLoading = isLoading;
 251
 0252            if (loadingSpinnerGO != null)
 0253                loadingSpinnerGO.SetActive(isLoading);
 254
 0255            if (mainButton != null)
 0256                mainButton.gameObject.SetActive(!isLoading);
 0257        }
 258
 259        internal void RefreshVisualCardStatus()
 260        {
 0261            RefreshAssignedSlotTextVisibility();
 0262            RefreshSelectionFrameVisibility();
 0263            RefreshCardButtonsVisibility();
 0264        }
 265
 266        internal void RefreshAssignedSlotTextVisibility()
 267        {
 0268            if (assignedSlotNumberText == null)
 0269                return;
 270
 0271            assignedSlotNumberText.gameObject.SetActive(model.assignedSlot >= 0);
 0272        }
 273
 274        internal void RefreshSelectionFrameVisibility()
 275        {
 0276            if (cardSelectionFrame == null)
 0277                return;
 278
 0279            cardSelectionFrame.SetActive(model.isSelected || model.isAssignedInSelectedSlot);
 0280        }
 281
 282        internal void RefreshCardButtonsVisibility()
 283        {
 0284            if (infoButton != null)
 0285                infoButton.gameObject.SetActive(model.isCollectible);
 0286        }
 287
 288        internal void OnEmoteImageLoaded(Sprite sprite)
 289        {
 0290            if (sprite != null)
 0291                SetEmotePicture(sprite);
 292            else
 0293                SetEmotePicture(sprite: null);
 0294        }
 295
 296        public void SetSoundIcon(bool active)
 297        {
 0298            soundIcon.gameObject.SetActive(active);
 0299        }
 300    }
 301}