< Summary

Class:TaskbarMoreMenu
Assembly:TaskbarHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/TaskbarMoreMenu.cs
Covered lines:66
Uncovered lines:44
Coverable lines:110
Total lines:236
Line coverage:60% (66 of 110)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TaskbarMoreMenu()0%110100%
Initialize(...)0%110100%
OnAvatarNamesVisibleChanged(...)0%2.52050%
SortButtonsAnimations()0%110100%
OnChangeProfile(...)0%6.64045.45%
OnDestroy()0%110100%
TutorialActive_OnChange(...)0%2100%
ActivateControlsButton()0%110100%
ActivateHelpAndSupportButton()0%110100%
ShowMoreMenu(...)0%2.062075%
PlayMoreMenuAnimations()0%67.1313031.58%
ShowTutorialButton(...)0%2100%
ToggleCollapseBar()0%2.012088.89%
ToggleHideUI()0%6200%

File(s)

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

#LineLine coverage
 1using DCL;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Text.RegularExpressions;
 5using DCL.Interface;
 6using UnityEngine;
 7using UnityEngine.Networking;
 8
 9public class TaskbarMoreMenu : MonoBehaviour
 10{
 11    private const string HIDE_NAMES = "Hide Names";
 12    private const string SHOW_NAMES = "Show Names";
 13
 14    [Header("Menu Animation")]
 15    [SerializeField] internal ShowHideAnimator moreMenuAnimator;
 2216    [SerializeField] internal float timeBetweenAnimations = 0.01f;
 17
 18    [Header("Collapse Button Config")]
 19    [SerializeField] internal TaskbarMoreMenuButton collapseBarButton;
 20    [SerializeField] internal GameObject collapseIcon;
 21    [SerializeField] internal GameObject collapseText;
 22    [SerializeField] internal GameObject expandIcon;
 23    [SerializeField] internal GameObject expandText;
 24
 25    [Header("Other Buttons Config")]
 26    [SerializeField] internal TaskbarMoreMenuButton hideUIButton;
 27    [SerializeField] internal TaskbarMoreMenuButton toggleAvatarNamesButton;
 28    [SerializeField] internal TaskbarMoreMenuButton controlsButton;
 29    [SerializeField] internal InputAction_Trigger controlsToggleAction;
 30    [SerializeField] internal TaskbarMoreMenuButton helpAndSupportButton;
 31    [SerializeField] internal TaskbarMoreMenuButton tutorialButton;
 32    [SerializeField] internal TaskbarMoreMenuButton dayModeButton;
 33    [SerializeField] internal TaskbarMoreMenuButton nightModeButton;
 34    [SerializeField] internal TaskbarMoreMenuButton reportBugButton;
 35
 36    private TaskbarHUDView view;
 2237    protected internal List<TaskbarMoreMenuButton> sortedButtonsAnimations = new List<TaskbarMoreMenuButton>();
 38    internal Coroutine moreMenuAnimationsCoroutine;
 39
 040    private BaseVariable<bool> avatarNamesVisible => DataStore.i.HUDs.avatarNamesVisible;
 41
 42    public event System.Action<bool> OnMoreMenuOpened;
 43    public event System.Action OnRestartTutorial;
 44
 45    public virtual void Initialize(TaskbarHUDView view)
 46    {
 1147        this.view = view;
 48
 1149        CommonScriptableObjects.tutorialActive.OnChange += TutorialActive_OnChange;
 1150        avatarNamesVisible.OnChange += OnAvatarNamesVisibleChanged;
 51
 1152        collapseBarButton.gameObject.SetActive(true);
 1153        hideUIButton.gameObject.SetActive(true);
 1154        controlsButton.gameObject.SetActive(false);
 1155        helpAndSupportButton.gameObject.SetActive(false);
 1156        tutorialButton.gameObject.SetActive(true);
 1157        reportBugButton.gameObject.SetActive(true);
 1158        toggleAvatarNamesButton.gameObject.SetActive(true);
 59
 1160        SortButtonsAnimations();
 61
 1162        RenderProfileManifest.i.OnChangeProfile += OnChangeProfile;
 1163        OnChangeProfile(RenderProfileManifest.i.currentProfile);
 64
 1165        dayModeButton.mainButton.onClick.AddListener(() =>
 66        {
 067            RenderProfileManifest.i.currentProfile = RenderProfileManifest.i.defaultProfile;
 068            RenderProfileManifest.i.currentProfile.Apply();
 069            view.moreButton.SetToggleState(false);
 070        });
 71
 1172        nightModeButton.mainButton.onClick.AddListener(() =>
 73        {
 074            RenderProfileManifest.i.currentProfile = RenderProfileManifest.i.nightProfile;
 075            RenderProfileManifest.i.currentProfile.Apply();
 076            view.moreButton.SetToggleState(false);
 077        });
 78
 1179        toggleAvatarNamesButton.mainButton.onClick.AddListener(() => { avatarNamesVisible.Set(!avatarNamesVisible.Get())
 1180        OnAvatarNamesVisibleChanged(avatarNamesVisible.Get(), false);
 81
 1182        collapseBarButton.mainButton.onClick.AddListener(ToggleCollapseBar);
 83
 1184        hideUIButton.mainButton.onClick.AddListener(ToggleHideUI);
 85
 1186        tutorialButton.mainButton.onClick.AddListener(() => { OnRestartTutorial?.Invoke(); });
 1187    }
 88
 89    private void OnAvatarNamesVisibleChanged(bool current, bool previous)
 90    {
 1191        if (current)
 1192            toggleAvatarNamesButton.buttonText.SetText(HIDE_NAMES);
 93        else
 094            toggleAvatarNamesButton.buttonText.SetText(SHOW_NAMES);
 095    }
 96
 97    protected void SortButtonsAnimations()
 98    {
 1199        sortedButtonsAnimations.Add(helpAndSupportButton);
 11100        sortedButtonsAnimations.Add(reportBugButton);
 11101        sortedButtonsAnimations.Add(controlsButton);
 11102        sortedButtonsAnimations.Add(toggleAvatarNamesButton);
 11103        sortedButtonsAnimations.Add(hideUIButton);
 11104        sortedButtonsAnimations.Add(nightModeButton);
 11105        sortedButtonsAnimations.Add(dayModeButton);
 11106        sortedButtonsAnimations.Add(tutorialButton);
 11107        sortedButtonsAnimations.Add(collapseBarButton);
 11108    }
 109
 110    private void OnChangeProfile(RenderProfileWorld profile)
 111    {
 11112        if (profile == RenderProfileManifest.i.defaultProfile)
 113        {
 11114            dayModeButton.gameObject.SetActive(false);
 11115            nightModeButton.gameObject.SetActive(true);
 116
 11117            if (moreMenuAnimator.isVisible)
 0118                nightModeButton.PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Visible);
 0119        }
 120        else
 121        {
 0122            dayModeButton.gameObject.SetActive(true);
 0123            nightModeButton.gameObject.SetActive(false);
 124
 0125            if (moreMenuAnimator.isVisible)
 0126                dayModeButton.PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Visible);
 127        }
 11128    }
 129
 130    private void OnDestroy()
 131    {
 11132        CommonScriptableObjects.tutorialActive.OnChange -= TutorialActive_OnChange;
 11133        RenderProfileManifest.i.OnChangeProfile -= OnChangeProfile;
 11134        avatarNamesVisible.OnChange -= OnAvatarNamesVisibleChanged;
 11135    }
 136
 137    private void TutorialActive_OnChange(bool current, bool previous)
 138    {
 0139        collapseBarButton.gameObject.SetActive(!current);
 0140        hideUIButton.gameObject.SetActive(!current);
 0141    }
 142
 143    internal void ActivateControlsButton()
 144    {
 2145        controlsButton.gameObject.SetActive(true);
 146
 2147        controlsButton.mainButton.onClick.AddListener(() =>
 148        {
 0149            controlsToggleAction.RaiseOnTriggered();
 0150            view.moreButton.SetToggleState(false);
 0151        });
 2152    }
 153
 154    internal void ActivateHelpAndSupportButton()
 155    {
 2156        helpAndSupportButton.gameObject.SetActive(true);
 157
 2158        helpAndSupportButton.mainButton.onClick.AddListener(() =>
 159        {
 0160            view.controller.helpAndSupportHud.SetVisibility(true);
 0161            view.moreButton.SetToggleState(false);
 0162        });
 2163    }
 164
 165    internal void ShowMoreMenu(bool visible, bool instant = false)
 166    {
 11167        CoroutineStarter.Stop(moreMenuAnimationsCoroutine);
 11168        moreMenuAnimationsCoroutine = CoroutineStarter.Start(PlayMoreMenuAnimations(visible, instant));
 11169        OnMoreMenuOpened?.Invoke(visible);
 0170    }
 171
 172    private IEnumerator PlayMoreMenuAnimations(bool visible, bool instant = false)
 173    {
 11174        if (visible)
 175        {
 0176            moreMenuAnimator.Show(instant);
 177
 0178            for (int i = 0; i < sortedButtonsAnimations.Count; i++)
 179            {
 0180                if (!sortedButtonsAnimations[i].gameObject.activeInHierarchy ||
 181                    sortedButtonsAnimations[i].lastPlayedAnimation == TaskbarMoreMenuButton.AnimationStatus.In)
 182                {
 183                    continue;
 184                }
 185
 0186                sortedButtonsAnimations[i].PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.In);
 0187                yield return new WaitForSeconds(timeBetweenAnimations);
 188            }
 0189        }
 190        else
 191        {
 22192            for (int j = sortedButtonsAnimations.Count - 1; j >= 0; j--)
 193            {
 11194                if (!sortedButtonsAnimations[j].gameObject.activeInHierarchy ||
 195                    sortedButtonsAnimations[j].lastPlayedAnimation == TaskbarMoreMenuButton.AnimationStatus.Out)
 196                {
 197                    continue;
 198                }
 199
 11200                sortedButtonsAnimations[j].PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Out);
 11201                yield return new WaitForSeconds(timeBetweenAnimations);
 202            }
 203
 0204            if (sortedButtonsAnimations.Count > 0)
 0205                yield return new WaitForSeconds(sortedButtonsAnimations[0].GetAnimationLenght());
 206
 0207            moreMenuAnimator.Hide(instant);
 208        }
 0209    }
 210
 0211    internal void ShowTutorialButton(bool visible) { tutorialButton.gameObject.SetActive(visible); }
 212
 213    private void ToggleCollapseBar()
 214    {
 2215        if (CommonScriptableObjects.tutorialActive)
 0216            return;
 217
 2218        view.ShowBar(!view.isBarVisible);
 219
 2220        collapseIcon.SetActive(view.isBarVisible);
 2221        collapseText.SetActive(view.isBarVisible);
 2222        expandIcon.SetActive(!view.isBarVisible);
 2223        expandText.SetActive(!view.isBarVisible);
 224
 2225        view.moreButton.SetToggleState(false);
 2226    }
 227
 228    private void ToggleHideUI()
 229    {
 0230        if (CommonScriptableObjects.tutorialActive)
 0231            return;
 232
 0233        CommonScriptableObjects.allUIHidden.Set(!CommonScriptableObjects.allUIHidden.Get());
 0234        view.moreButton.SetToggleState(false);
 0235    }
 236}