< Summary

Class:DCL.EmotesCustomization.EmoteSlotCardComponentView
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/EmotesCustomization/EmoteSlotCardComponentView.cs
Covered lines:0
Uncovered lines:112
Coverable lines:112
Total lines:247
Line coverage:0% (0 of 112)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:18
Method coverage:0% (0 of 18)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%6200%
Configure(...)0%6200%
RefreshControl()0%20400%
OnFocus()0%6200%
OnLoseFocus()0%6200%
Dispose()0%6200%
SetEmoteId(...)0%12300%
SetEmoteName(...)0%20400%
SetEmotePicture(...)0%20400%
SetEmotePicture(...)0%30500%
SetEmoteAsSelected(...)0%2100%
SetSlotNumber(...)0%12300%
SetSeparatorActive(...)0%6200%
SetRarity(...)0%12300%
OnEmoteImageLoaded(...)0%6200%
SetSelectedVisualsForClicking(...)0%1101000%
SetSelectedVisualsForHovering(...)0%1321100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7namespace DCL.EmotesCustomization
 8{
 9    public class EmoteSlotCardComponentView : BaseComponentView, IEmoteSlotCardComponentView, IComponentModelConfig<Emot
 10    {
 11        internal const int SLOT_VIEWER_ROTATION_ANGLE = 36;
 12        internal const string EMPTY_SLOT_TEXT = "None";
 13
 14        [Header("Prefab References")]
 15        [SerializeField] internal ImageComponentView emoteImage;
 16        [SerializeField] internal Image nonEmoteImage;
 17        [SerializeField] internal TMP_Text emoteNameText;
 18        [SerializeField] internal TMP_Text slotNumberText;
 19        [SerializeField] internal Image slotViewerImage;
 20        [SerializeField] internal ButtonComponentView mainButton;
 21        [SerializeField] internal Image defaultBackgroundImage;
 22        [SerializeField] internal Image selectedBackgroundImage;
 23        [SerializeField] internal GameObject separatorGO;
 24        [SerializeField] internal Image rarityMark;
 25
 26        [Header("Configuration")]
 27        [SerializeField] internal Sprite defaultEmotePicture;
 28        [SerializeField] internal Color defaultBackgroundColor;
 29        [SerializeField] internal Color selectedBackgroundColor;
 30        [SerializeField] internal Color defaultSlotNumberColor;
 31        [SerializeField] internal Color selectedSlotNumberColor;
 32        [SerializeField] internal Color defaultEmoteNameColor;
 33        [SerializeField] internal Color selectedEmoteNameColor;
 34        [SerializeField] internal List<EmoteRarity> rarityColors;
 35        [SerializeField] internal EmoteSlotCardComponentModel model;
 36
 037        public Button.ButtonClickedEvent onClick => mainButton?.onClick;
 38
 39        public override void Awake()
 40        {
 041            base.Awake();
 42
 043            if (emoteImage != null)
 044                emoteImage.OnLoaded += OnEmoteImageLoaded;
 045        }
 46
 47        public void Configure(EmoteSlotCardComponentModel newModel)
 48        {
 049            if (model == newModel)
 050                return;
 51
 052            model = newModel;
 053            RefreshControl();
 054        }
 55
 56        public override void RefreshControl()
 57        {
 058            if (model == null)
 059                return;
 60
 061            if (model.pictureSprite != null)
 062                SetEmotePicture(model.pictureSprite);
 063            else if (!string.IsNullOrEmpty(model.pictureUri))
 064                SetEmotePicture(model.pictureUri);
 65            else
 066                OnEmoteImageLoaded(null);
 67
 068            SetEmoteId(model.emoteId);
 069            SetEmoteName(model.emoteName);
 070            SetEmoteAsSelected(model.isSelected);
 071            SetSlotNumber(model.slotNumber);
 072            SetSeparatorActive(model.hasSeparator);
 073            SetRarity(model.rarity);
 074        }
 75
 76        public override void OnFocus()
 77        {
 078            base.OnFocus();
 79
 080            if (!model.isSelected)
 81            {
 082                SetSelectedVisualsForHovering(true);
 83            }
 084        }
 85
 86        public override void OnLoseFocus()
 87        {
 088            base.OnLoseFocus();
 89
 090            if (!model.isSelected)
 91            {
 092                SetSelectedVisualsForHovering(false);
 93            }
 094        }
 95
 96        public override void Dispose()
 97        {
 098            base.Dispose();
 99
 0100            if (emoteImage != null)
 101            {
 0102                emoteImage.OnLoaded -= OnEmoteImageLoaded;
 0103                emoteImage.Dispose();
 104            }
 0105        }
 106
 107        public void SetEmoteId(string id)
 108        {
 0109            model.emoteId = id;
 110
 0111            if (nonEmoteImage != null)
 0112                nonEmoteImage.gameObject.SetActive(string.IsNullOrEmpty(id));
 113
 0114            if (emoteImage != null)
 0115                emoteImage.gameObject.SetActive(!string.IsNullOrEmpty(id));
 0116        }
 117
 118        public void SetEmoteName(string name)
 119        {
 0120            model.emoteName = name;
 121
 0122            if (emoteNameText == null)
 0123                return;
 124
 0125            emoteNameText.text = string.IsNullOrEmpty(name) ? EMPTY_SLOT_TEXT : name;
 0126        }
 127
 128        public void SetEmotePicture(Sprite sprite)
 129        {
 0130            if (sprite == null && defaultEmotePicture != null)
 0131                sprite = defaultEmotePicture;
 132
 0133            model.pictureSprite = sprite;
 134
 0135            if (emoteImage == null)
 0136                return;
 137
 0138            emoteImage.SetImage(sprite);
 0139        }
 140
 141        public void SetEmotePicture(string uri)
 142        {
 0143            if (string.IsNullOrEmpty(uri) && defaultEmotePicture != null)
 144            {
 0145                SetEmotePicture(defaultEmotePicture);
 0146                return;
 147            }
 148
 0149            model.pictureUri = uri;
 150
 0151            if (!Application.isPlaying)
 0152                return;
 153
 0154            if (emoteImage == null)
 0155                return;
 156
 0157            emoteImage.SetImage(uri);
 0158        }
 159
 160        public void SetEmoteAsSelected(bool isSelected)
 161        {
 0162            model.isSelected = isSelected;
 163
 0164            SetSelectedVisualsForClicking(isSelected);
 0165        }
 166
 167        public void SetSlotNumber(int slotNumber)
 168        {
 0169            model.slotNumber = Mathf.Clamp(slotNumber, 0, 9);
 170
 0171            if (slotNumberText != null)
 0172                slotNumberText.text = model.slotNumber.ToString();
 173
 0174            if (slotViewerImage != null)
 0175                slotViewerImage.transform.rotation = Quaternion.Euler(0, 0, -model.slotNumber * SLOT_VIEWER_ROTATION_ANG
 0176        }
 177
 178        public void SetSeparatorActive(bool isActive)
 179        {
 0180            model.hasSeparator = isActive;
 181
 0182            if (separatorGO == null)
 0183                return;
 184
 0185            separatorGO.SetActive(isActive);
 0186        }
 187
 188        public void SetRarity(string rarity)
 189        {
 0190            model.rarity = rarity;
 191
 0192            if (rarityMark == null)
 0193                return;
 194
 0195            EmoteRarity emoteRarity = rarityColors.FirstOrDefault(x => x.rarity == rarity);
 0196            rarityMark.gameObject.SetActive(emoteRarity != null);
 0197            rarityMark.color = emoteRarity != null ? emoteRarity.markColor : Color.white;
 0198        }
 199
 200        internal void OnEmoteImageLoaded(Sprite sprite)
 201        {
 0202            if (sprite != null)
 0203                SetEmotePicture(sprite);
 204            else
 0205                SetEmotePicture(sprite: null);
 0206        }
 207
 208        internal void SetSelectedVisualsForClicking(bool isSelected)
 209        {
 0210            if (defaultBackgroundImage != null)
 211            {
 0212                defaultBackgroundImage.gameObject.SetActive(!isSelected);
 0213                defaultBackgroundImage.color = defaultBackgroundColor;
 214            }
 215
 0216            if (selectedBackgroundImage != null)
 217            {
 0218                selectedBackgroundImage.gameObject.SetActive(isSelected);
 0219                selectedBackgroundImage.color = selectedBackgroundColor;
 220            }
 221
 0222            if (slotNumberText != null)
 0223                slotNumberText.color = isSelected ? selectedSlotNumberColor : defaultSlotNumberColor;
 224
 0225            if (emoteNameText != null)
 0226                emoteNameText.color = isSelected ? selectedEmoteNameColor : defaultEmoteNameColor;
 227
 0228            if (slotViewerImage != null)
 0229                slotViewerImage.gameObject.SetActive(isSelected);
 0230        }
 231
 232        internal void SetSelectedVisualsForHovering(bool isSelected)
 233        {
 0234            if (defaultBackgroundImage != null)
 0235                defaultBackgroundImage.color = isSelected ? selectedBackgroundColor : defaultBackgroundColor;
 236
 0237            if (slotNumberText != null)
 0238                slotNumberText.color = isSelected ? selectedSlotNumberColor : defaultSlotNumberColor;
 239
 0240            if (emoteNameText != null)
 0241                emoteNameText.color = isSelected ? selectedEmoteNameColor : defaultEmoteNameColor;
 242
 0243            if (slotViewerImage != null)
 0244                slotViewerImage.gameObject.SetActive(isSelected);
 0245        }
 246    }
 247}