< Summary

Class:TaskbarMoreMenu
Assembly:TaskbarHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/TaskbarMoreMenu.cs
Covered lines:56
Uncovered lines:41
Coverable lines:97
Total lines:209
Line coverage:57.7% (56 of 97)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TaskbarMoreMenu()0%110100%
Initialize(...)0%110100%
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 UnityEngine;
 5
 6public class TaskbarMoreMenu : MonoBehaviour
 7{
 8    [Header("Menu Animation")]
 9    [SerializeField] internal ShowHideAnimator moreMenuAnimator;
 2210    [SerializeField] internal float timeBetweenAnimations = 0.01f;
 11
 12    [Header("Collapse Button Config")]
 13    [SerializeField] internal TaskbarMoreMenuButton collapseBarButton;
 14    [SerializeField] internal GameObject collapseIcon;
 15    [SerializeField] internal GameObject collapseText;
 16    [SerializeField] internal GameObject expandIcon;
 17    [SerializeField] internal GameObject expandText;
 18
 19    [Header("Other Buttons Config")]
 20    [SerializeField] internal TaskbarMoreMenuButton hideUIButton;
 21    [SerializeField] internal TaskbarMoreMenuButton controlsButton;
 22    [SerializeField] internal InputAction_Trigger controlsToggleAction;
 23    [SerializeField] internal TaskbarMoreMenuButton helpAndSupportButton;
 24    [SerializeField] internal TaskbarMoreMenuButton tutorialButton;
 25    [SerializeField] internal TaskbarMoreMenuButton dayModeButton;
 26    [SerializeField] internal TaskbarMoreMenuButton nightModeButton;
 27
 28    private TaskbarHUDView view;
 2229    protected internal List<TaskbarMoreMenuButton> sortedButtonsAnimations = new List<TaskbarMoreMenuButton>();
 30    internal Coroutine moreMenuAnimationsCoroutine;
 31
 32    public event System.Action<bool> OnMoreMenuOpened;
 33    public event System.Action OnRestartTutorial;
 34
 35    public virtual void Initialize(TaskbarHUDView view)
 36    {
 1137        this.view = view;
 38
 1139        CommonScriptableObjects.tutorialActive.OnChange += TutorialActive_OnChange;
 40
 1141        collapseBarButton.gameObject.SetActive(true);
 1142        hideUIButton.gameObject.SetActive(true);
 1143        controlsButton.gameObject.SetActive(false);
 1144        helpAndSupportButton.gameObject.SetActive(false);
 1145        tutorialButton.gameObject.SetActive(true);
 46
 1147        SortButtonsAnimations();
 48
 1149        RenderProfileManifest.i.OnChangeProfile += OnChangeProfile;
 1150        OnChangeProfile(RenderProfileManifest.i.currentProfile);
 51
 1152        dayModeButton.mainButton.onClick.AddListener(() =>
 53        {
 054            RenderProfileManifest.i.currentProfile = RenderProfileManifest.i.defaultProfile;
 055            RenderProfileManifest.i.currentProfile.Apply();
 056            view.moreButton.SetToggleState(false);
 057        });
 58
 1159        nightModeButton.mainButton.onClick.AddListener(() =>
 60        {
 061            RenderProfileManifest.i.currentProfile = RenderProfileManifest.i.nightProfile;
 062            RenderProfileManifest.i.currentProfile.Apply();
 063            view.moreButton.SetToggleState(false);
 064        });
 65
 1566        collapseBarButton.mainButton.onClick.AddListener(() => { ToggleCollapseBar(); });
 67
 1168        hideUIButton.mainButton.onClick.AddListener(() => { ToggleHideUI(); });
 69
 1170        tutorialButton.mainButton.onClick.AddListener(() => { OnRestartTutorial?.Invoke(); });
 1171    }
 72
 73    protected void SortButtonsAnimations()
 74    {
 1175        sortedButtonsAnimations.Add(helpAndSupportButton);
 1176        sortedButtonsAnimations.Add(controlsButton);
 1177        sortedButtonsAnimations.Add(hideUIButton);
 1178        sortedButtonsAnimations.Add(nightModeButton);
 1179        sortedButtonsAnimations.Add(dayModeButton);
 1180        sortedButtonsAnimations.Add(tutorialButton);
 1181        sortedButtonsAnimations.Add(collapseBarButton);
 1182    }
 83
 84    private void OnChangeProfile(RenderProfileWorld profile)
 85    {
 1186        if (profile == RenderProfileManifest.i.defaultProfile)
 87        {
 1188            dayModeButton.gameObject.SetActive(false);
 1189            nightModeButton.gameObject.SetActive(true);
 90
 1191            if (moreMenuAnimator.isVisible)
 092                nightModeButton.PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Visible);
 093        }
 94        else
 95        {
 096            dayModeButton.gameObject.SetActive(true);
 097            nightModeButton.gameObject.SetActive(false);
 98
 099            if (moreMenuAnimator.isVisible)
 0100                dayModeButton.PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Visible);
 101        }
 11102    }
 103
 104    private void OnDestroy()
 105    {
 11106        CommonScriptableObjects.tutorialActive.OnChange -= TutorialActive_OnChange;
 11107        RenderProfileManifest.i.OnChangeProfile -= OnChangeProfile;
 11108    }
 109
 110    private void TutorialActive_OnChange(bool current, bool previous)
 111    {
 0112        collapseBarButton.gameObject.SetActive(!current);
 0113        hideUIButton.gameObject.SetActive(!current);
 0114    }
 115
 116    internal void ActivateControlsButton()
 117    {
 2118        controlsButton.gameObject.SetActive(true);
 119
 2120        controlsButton.mainButton.onClick.AddListener(() =>
 121        {
 0122            controlsToggleAction.RaiseOnTriggered();
 0123            view.moreButton.SetToggleState(false);
 0124        });
 2125    }
 126
 127    internal void ActivateHelpAndSupportButton()
 128    {
 2129        helpAndSupportButton.gameObject.SetActive(true);
 130
 2131        helpAndSupportButton.mainButton.onClick.AddListener(() =>
 132        {
 0133            view.controller.helpAndSupportHud.SetVisibility(true);
 0134            view.moreButton.SetToggleState(false);
 0135        });
 2136    }
 137
 138    internal void ShowMoreMenu(bool visible, bool instant = false)
 139    {
 11140        CoroutineStarter.Stop(moreMenuAnimationsCoroutine);
 11141        moreMenuAnimationsCoroutine = CoroutineStarter.Start(PlayMoreMenuAnimations(visible, instant));
 11142        OnMoreMenuOpened?.Invoke(visible);
 0143    }
 144
 145    private IEnumerator PlayMoreMenuAnimations(bool visible, bool instant = false)
 146    {
 11147        if (visible)
 148        {
 0149            moreMenuAnimator.Show(instant);
 150
 0151            for (int i = 0; i < sortedButtonsAnimations.Count; i++)
 152            {
 0153                if (!sortedButtonsAnimations[i].gameObject.activeInHierarchy ||
 154                    sortedButtonsAnimations[i].lastPlayedAnimation == TaskbarMoreMenuButton.AnimationStatus.In)
 155                {
 156                    continue;
 157                }
 158
 0159                sortedButtonsAnimations[i].PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.In);
 0160                yield return new WaitForSeconds(timeBetweenAnimations);
 161            }
 0162        }
 163        else
 164        {
 22165            for (int j = sortedButtonsAnimations.Count - 1; j >= 0; j--)
 166            {
 11167                if (!sortedButtonsAnimations[j].gameObject.activeInHierarchy ||
 168                    sortedButtonsAnimations[j].lastPlayedAnimation == TaskbarMoreMenuButton.AnimationStatus.Out)
 169                {
 170                    continue;
 171                }
 172
 11173                sortedButtonsAnimations[j].PlayAnimation(TaskbarMoreMenuButton.AnimationStatus.Out);
 11174                yield return new WaitForSeconds(timeBetweenAnimations);
 175            }
 176
 0177            if (sortedButtonsAnimations.Count > 0)
 0178                yield return new WaitForSeconds(sortedButtonsAnimations[0].GetAnimationLenght());
 179
 0180            moreMenuAnimator.Hide(instant);
 181        }
 0182    }
 183
 0184    internal void ShowTutorialButton(bool visible) { tutorialButton.gameObject.SetActive(visible); }
 185
 186    private void ToggleCollapseBar()
 187    {
 2188        if (CommonScriptableObjects.tutorialActive)
 0189            return;
 190
 2191        view.ShowBar(!view.isBarVisible);
 192
 2193        collapseIcon.SetActive(view.isBarVisible);
 2194        collapseText.SetActive(view.isBarVisible);
 2195        expandIcon.SetActive(!view.isBarVisible);
 2196        expandText.SetActive(!view.isBarVisible);
 197
 2198        view.moreButton.SetToggleState(false);
 2199    }
 200
 201    private void ToggleHideUI()
 202    {
 0203        if (CommonScriptableObjects.tutorialActive)
 0204            return;
 205
 0206        CommonScriptableObjects.allUIHidden.Set(!CommonScriptableObjects.allUIHidden.Get());
 0207        view.moreButton.SetToggleState(false);
 0208    }
 209}