< Summary

Class:DCL.SettingsPanelHUD.Sections.SettingsButtonEntry
Assembly:SettingsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SectionsModule/SettingsButtonEntry.cs
Covered lines:12
Uncovered lines:13
Coverable lines:25
Total lines:88
Line coverage:48% (12 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%110100%
ConfigureAction(...)0%110100%
MarkAsSelected(...)0%770100%
OnPointerEnter(...)0%6200%
OnPointerExit(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SectionsModule/SettingsButtonEntry.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.Events;
 4using UnityEngine.EventSystems;
 5using UnityEngine.UI;
 6
 7namespace DCL.SettingsPanelHUD.Sections
 8{
 9    /// <summary>
 10    /// MonoBehaviour that represents a template for a menu button.
 11    /// It will be instantiated on the left part of the main settings panel and will be associated to a specific SECTION
 12    /// </summary>
 13    public class SettingsButtonEntry : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 14    {
 15        [SerializeField]
 16        private Image icon;
 17
 18        [SerializeField]
 19        private TextMeshProUGUI text;
 20
 21        [SerializeField]
 22        private Button button;
 23
 24        [SerializeField]
 25        private Image backgroundImage;
 26
 27        [SerializeField]
 28        private Color textColorOnSelect;
 29
 30        [SerializeField]
 31        private Color backgroundColorOnSelect;
 32
 33        private Color originalIconColor;
 34        private Color originalTextColor;
 35        private Color originalBackgroundColor;
 36        private bool isSelected;
 37
 038        public string settingName { get => text.text; }
 39
 40        public void Initialize(Sprite icon, string text)
 41        {
 342            this.icon.sprite = icon;
 343            this.text.text = text;
 44
 345            originalIconColor = this.icon.color;
 346            originalTextColor = this.text.color;
 347            originalBackgroundColor = backgroundImage.color;
 348        }
 49
 50        /// <summary>
 51        /// Adds an action to execute when the button is clicked.
 52        /// </summary>
 53        /// <param name="action">Action to execute.</param>
 654        public void ConfigureAction(UnityAction action) { button.onClick.AddListener(action); }
 55
 56        /// <summary>
 57        /// Mark this button as selected. It will change the visual aspect of the button.
 58        /// </summary>
 59        /// <param name="isSelected">True for select the button.</param>
 60        public void MarkAsSelected(bool isSelected)
 61        {
 662            icon.color = isSelected ? textColorOnSelect : originalIconColor;
 663            text.color = isSelected ? textColorOnSelect : originalTextColor;
 664            backgroundImage.color = isSelected ? backgroundColorOnSelect : originalBackgroundColor;
 665            this.isSelected = isSelected;
 666        }
 67
 68        public void OnPointerEnter(PointerEventData eventData)
 69        {
 070            if (isSelected)
 071                return;
 72
 073            icon.color = textColorOnSelect;
 074            backgroundImage.color = backgroundColorOnSelect;
 075            text.color = textColorOnSelect;
 076        }
 77
 78        public void OnPointerExit(PointerEventData eventData)
 79        {
 080            if (isSelected)
 081                return;
 82
 083            icon.color = originalTextColor;
 084            backgroundImage.color = originalBackgroundColor;
 085            text.color = originalTextColor;
 086        }
 87    }
 88}