< Summary

Class:TaskbarButton
Assembly:TaskbarHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/TaskbarButton.cs
Covered lines:39
Uncovered lines:3
Coverable lines:42
Total lines:102
Line coverage:92.8% (39 of 42)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TaskbarButton()0%110100%
Initialize()0%220100%
OnDestroy()0%110100%
AppMode_OnChange(...)0%2.032080%
OnToggleButtonClick()0%110100%
SetToggleState(...)0%8.028093.33%
SetLineIndicator(...)0%4.054085.71%
SetInteractable(...)0%440100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/TaskbarButton.cs

#LineLine coverage
 1using DCL;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.Serialization;
 5using UnityEngine.UI;
 6
 7public class TaskbarButton : MonoBehaviour
 8{
 9    [FormerlySerializedAs("openButton")]
 10    public Button toggleButton;
 11
 12    public GameObject lineOffIndicator;
 13    public ShowHideAnimator lineOnIndicator;
 14    public Image iconImage;
 15    public Color notInteractableColor;
 16    public List<AppMode> compatibleModes;
 17    public GameObject firstTimeLabelIndicator;
 18
 19    public event System.Action<TaskbarButton> OnToggleOn;
 20    public event System.Action<TaskbarButton> OnToggleOff;
 21
 1722    public bool toggledOn { get; private set; } = true;
 23
 24    private Color originalIconColor;
 25
 26    public void Initialize()
 27    {
 1328        toggleButton.onClick.RemoveAllListeners();
 1329        toggleButton.onClick.AddListener(OnToggleButtonClick);
 1330        SetToggleState(false, useCallback: false);
 31
 1332        if (iconImage != null)
 1233            originalIconColor = iconImage.color;
 34
 1335        DataStore.i.common.appMode.OnChange += AppMode_OnChange;
 1336        AppMode_OnChange(DataStore.i.common.appMode.Get(), AppMode.DEFAULT);
 1337    }
 38
 2439    private void OnDestroy() { DataStore.i.common.appMode.OnChange -= AppMode_OnChange; }
 40
 41    private void AppMode_OnChange(AppMode currentMode, AppMode previousMode)
 42    {
 1343        bool isCompatible = compatibleModes.Contains(currentMode);
 44
 1345        SetInteractable(isCompatible);
 46
 1347        if (!isCompatible)
 048            SetToggleState(false);
 1349    }
 50
 1051    private void OnToggleButtonClick() { SetToggleState(!toggledOn); }
 52
 53    public void SetToggleState(bool on, bool useCallback = true)
 54    {
 4355        if (toggledOn == on)
 1956            return;
 57
 2458        if (on && firstTimeLabelIndicator != null)
 059            firstTimeLabelIndicator.SetActive(false);
 60
 2461        SetLineIndicator(on);
 62
 2463        if (!useCallback)
 64        {
 1365            toggledOn = on;
 1366            return;
 67        }
 68
 1169        if (on)
 70        {
 671            OnToggleOn?.Invoke(this);
 672            toggledOn = on;
 673        }
 74        else
 75        {
 576            toggledOn = on;
 577            OnToggleOff?.Invoke(this);
 78        }
 579    }
 80
 81    public void SetLineIndicator(bool on)
 82    {
 2483        if (lineOnIndicator != null)
 84        {
 2485            if (on)
 686                lineOnIndicator.Show();
 87            else
 1888                lineOnIndicator.Hide();
 89        }
 90
 2491        if (lineOffIndicator != null)
 092            lineOffIndicator.SetActive(!on);
 2493    }
 94
 95    private void SetInteractable(bool isInteractable)
 96    {
 1397        toggleButton.interactable = isInteractable;
 98
 1399        if (iconImage != null)
 12100            iconImage.color = isInteractable ? originalIconColor : notInteractableColor;
 13101    }
 102}