< 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:101
Uncovered lines:11
Coverable lines:112
Total lines:247
Line coverage:90.1% (101 of 112)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%220100%
Configure(...)0%2.032080%
RefreshControl()0%4.374071.43%
OnFocus()0%220100%
OnLoseFocus()0%220100%
Dispose()0%220100%
SetEmoteId(...)0%330100%
SetEmoteName(...)0%4.134080%
SetEmotePicture(...)0%4.054085.71%
SetEmotePicture(...)0%5.25080%
SetEmoteAsSelected(...)0%110100%
SetSlotNumber(...)0%330100%
SetSeparatorActive(...)0%2.032080%
SetRarity(...)0%3.033085.71%
OnEmoteImageLoaded(...)0%220100%
SetSelectedVisualsForClicking(...)0%10100100%
SetSelectedVisualsForHovering(...)0%11110100%

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
 128237        public Button.ButtonClickedEvent onClick => mainButton?.onClick;
 38
 39        public override void Awake()
 40        {
 89941            base.Awake();
 42
 89943            if (emoteImage != null)
 89944                emoteImage.OnLoaded += OnEmoteImageLoaded;
 89945        }
 46
 47        public void Configure(EmoteSlotCardComponentModel newModel)
 48        {
 149            if (model == newModel)
 050                return;
 51
 152            model = newModel;
 153            RefreshControl();
 154        }
 55
 56        public override void RefreshControl()
 57        {
 158            if (model == null)
 059                return;
 60
 161            if (model.pictureSprite != null)
 162                SetEmotePicture(model.pictureSprite);
 063            else if (!string.IsNullOrEmpty(model.pictureUri))
 064                SetEmotePicture(model.pictureUri);
 65            else
 066                OnEmoteImageLoaded(null);
 67
 168            SetEmoteId(model.emoteId);
 169            SetEmoteName(model.emoteName);
 170            SetEmoteAsSelected(model.isSelected);
 171            SetSlotNumber(model.slotNumber);
 172            SetSeparatorActive(model.hasSeparator);
 173            SetRarity(model.rarity);
 174        }
 75
 76        public override void OnFocus()
 77        {
 178            base.OnFocus();
 79
 180            if (!model.isSelected)
 81            {
 182                SetSelectedVisualsForHovering(true);
 83            }
 184        }
 85
 86        public override void OnLoseFocus()
 87        {
 176088            base.OnLoseFocus();
 89
 176090            if (!model.isSelected)
 91            {
 173992                SetSelectedVisualsForHovering(false);
 93            }
 176094        }
 95
 96        public override void Dispose()
 97        {
 94898            base.Dispose();
 99
 948100            if (emoteImage != null)
 101            {
 948102                emoteImage.OnLoaded -= OnEmoteImageLoaded;
 948103                emoteImage.Dispose();
 104            }
 948105        }
 106
 107        public void SetEmoteId(string id)
 108        {
 49109            model.emoteId = id;
 110
 49111            if (nonEmoteImage != null)
 49112                nonEmoteImage.gameObject.SetActive(string.IsNullOrEmpty(id));
 113
 49114            if (emoteImage != null)
 49115                emoteImage.gameObject.SetActive(!string.IsNullOrEmpty(id));
 49116        }
 117
 118        public void SetEmoteName(string name)
 119        {
 49120            model.emoteName = name;
 121
 49122            if (emoteNameText == null)
 0123                return;
 124
 49125            emoteNameText.text = string.IsNullOrEmpty(name) ? EMPTY_SLOT_TEXT : name;
 49126        }
 127
 128        public void SetEmotePicture(Sprite sprite)
 129        {
 15130            if (sprite == null && defaultEmotePicture != null)
 2131                sprite = defaultEmotePicture;
 132
 15133            model.pictureSprite = sprite;
 134
 15135            if (emoteImage == null)
 0136                return;
 137
 15138            emoteImage.SetImage(sprite);
 15139        }
 140
 141        public void SetEmotePicture(string uri)
 142        {
 5143            if (string.IsNullOrEmpty(uri) && defaultEmotePicture != null)
 144            {
 4145                SetEmotePicture(defaultEmotePicture);
 4146                return;
 147            }
 148
 1149            model.pictureUri = uri;
 150
 1151            if (!Application.isPlaying)
 0152                return;
 153
 1154            if (emoteImage == null)
 0155                return;
 156
 1157            emoteImage.SetImage(uri);
 1158        }
 159
 160        public void SetEmoteAsSelected(bool isSelected)
 161        {
 113162            model.isSelected = isSelected;
 163
 113164            SetSelectedVisualsForClicking(isSelected);
 113165        }
 166
 167        public void SetSlotNumber(int slotNumber)
 168        {
 2169            model.slotNumber = Mathf.Clamp(slotNumber, 0, 9);
 170
 2171            if (slotNumberText != null)
 2172                slotNumberText.text = model.slotNumber.ToString();
 173
 2174            if (slotViewerImage != null)
 2175                slotViewerImage.transform.rotation = Quaternion.Euler(0, 0, -model.slotNumber * SLOT_VIEWER_ROTATION_ANG
 2176        }
 177
 178        public void SetSeparatorActive(bool isActive)
 179        {
 3180            model.hasSeparator = isActive;
 181
 3182            if (separatorGO == null)
 0183                return;
 184
 3185            separatorGO.SetActive(isActive);
 3186        }
 187
 188        public void SetRarity(string rarity)
 189        {
 49190            model.rarity = rarity;
 191
 49192            if (rarityMark == null)
 0193                return;
 194
 362195            EmoteRarity emoteRarity = rarityColors.FirstOrDefault(x => x.rarity == rarity);
 49196            rarityMark.gameObject.SetActive(emoteRarity != null);
 49197            rarityMark.color = emoteRarity != null ? emoteRarity.markColor : Color.white;
 49198        }
 199
 200        internal void OnEmoteImageLoaded(Sprite sprite)
 201        {
 2202            if (sprite != null)
 1203                SetEmotePicture(sprite);
 204            else
 1205                SetEmotePicture(sprite: null);
 1206        }
 207
 208        internal void SetSelectedVisualsForClicking(bool isSelected)
 209        {
 115210            if (defaultBackgroundImage != null)
 211            {
 115212                defaultBackgroundImage.gameObject.SetActive(!isSelected);
 115213                defaultBackgroundImage.color = defaultBackgroundColor;
 214            }
 215
 115216            if (selectedBackgroundImage != null)
 217            {
 115218                selectedBackgroundImage.gameObject.SetActive(isSelected);
 115219                selectedBackgroundImage.color = selectedBackgroundColor;
 220            }
 221
 115222            if (slotNumberText != null)
 115223                slotNumberText.color = isSelected ? selectedSlotNumberColor : defaultSlotNumberColor;
 224
 115225            if (emoteNameText != null)
 115226                emoteNameText.color = isSelected ? selectedEmoteNameColor : defaultEmoteNameColor;
 227
 115228            if (slotViewerImage != null)
 115229                slotViewerImage.gameObject.SetActive(isSelected);
 115230        }
 231
 232        internal void SetSelectedVisualsForHovering(bool isSelected)
 233        {
 1742234            if (defaultBackgroundImage != null)
 1742235                defaultBackgroundImage.color = isSelected ? selectedBackgroundColor : defaultBackgroundColor;
 236
 1742237            if (slotNumberText != null)
 1742238                slotNumberText.color = isSelected ? selectedSlotNumberColor : defaultSlotNumberColor;
 239
 1742240            if (emoteNameText != null)
 1742241                emoteNameText.color = isSelected ? selectedEmoteNameColor : defaultEmoteNameColor;
 242
 1742243            if (slotViewerImage != null)
 1742244                slotViewerImage.gameObject.SetActive(isSelected);
 1742245        }
 246    }
 247}