< Summary

Class:TaskbarHUDView
Assembly:TaskbarHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/TaskbarHUDView.cs
Covered lines:77
Uncovered lines:8
Coverable lines:85
Total lines:198
Line coverage:90.5% (77 of 85)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TaskbarHUDView()0%110100%
GetButtonList()0%110100%
Create(...)0%110100%
Initialize(...)0%110100%
OnWindowToggleOff(...)0%8.068090%
AllButtonsToggledOff()0%3.023087.5%
OnWindowToggleOn(...)0%7.17087.5%
SelectButton(...)0%330100%
OnAddChatWindow()0%110100%
OnAddFriendsWindow()0%110100%
OnAddExperiencesWindow()0%2100%
OnAddVoiceChat()0%2100%
ShowBar(...)0%2.032080%
SetVisibility(...)0%110100%
SetExperiencesVisbility(...)0%110100%
OnDestroy()0%550100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public class TaskbarHUDView : MonoBehaviour
 6{
 7    const string VIEW_PATH = "Taskbar";
 8
 9    [Header("Taskbar Animation")]
 10    [SerializeField] internal ShowHideAnimator taskbarAnimator;
 11
 12    [Header("Left Side Config")]
 13    [SerializeField] internal RectTransform leftWindowContainer;
 14
 15    [SerializeField] internal ShowHideAnimator leftWindowContainerAnimator;
 16    [SerializeField] internal LayoutGroup leftWindowContainerLayout;
 17    [SerializeField] internal GameObject voiceChatButtonPlaceholder;
 18    [SerializeField] internal VoiceChatButton voiceChatButton;
 19    [SerializeField] internal TaskbarButton chatButton;
 20    [SerializeField] internal TaskbarButton friendsButton;
 21    [SerializeField] internal ChatHeadGroupView chatHeadsGroup;
 22
 23    [SerializeField] internal GameObject experiencesContainer;
 24    [SerializeField] internal TaskbarButton experiencesButton;
 25
 26    [SerializeField] internal RectTransform socialTooltipReference;
 27
 28    [Header("Old TaskbarCompatibility (temporal)")]
 29    [SerializeField] internal RectTransform taskbarPanelTransf;
 30
 31    [SerializeField] internal Image taskbarPanelImage;
 32
 33    internal TaskbarHUDController controller;
 534    internal bool isBarVisible = true;
 35
 36    public event System.Action OnChatToggleOn;
 37    public event System.Action OnChatToggleOff;
 38    public event System.Action OnFriendsToggleOn;
 39    public event System.Action OnFriendsToggleOff;
 40    public event System.Action OnExperiencesToggleOn;
 41    public event System.Action OnExperiencesToggleOff;
 42
 43    internal List<TaskbarButton> GetButtonList()
 44    {
 1445        var taskbarButtonList = new List<TaskbarButton>();
 1446        taskbarButtonList.Add(chatButton);
 1447        taskbarButtonList.Add(friendsButton);
 1448        taskbarButtonList.AddRange(chatHeadsGroup.chatHeads);
 1449        taskbarButtonList.Add(experiencesButton);
 50
 1451        return taskbarButtonList;
 52    }
 53
 54    internal static TaskbarHUDView Create(TaskbarHUDController controller, IChatController chatController,
 55        IFriendsController friendsController)
 56    {
 457        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<TaskbarHUDView>();
 458        view.Initialize(controller, chatController, friendsController);
 459        return view;
 60    }
 61
 62    public void Initialize(TaskbarHUDController controller, IChatController chatController,
 63        IFriendsController friendsController)
 64    {
 465        this.controller = controller;
 66
 467        ShowBar(true, true);
 468        chatButton.transform.parent.gameObject.SetActive(false);
 469        friendsButton.transform.parent.gameObject.SetActive(false);
 470        experiencesButton.transform.parent.gameObject.SetActive(false);
 471        voiceChatButtonPlaceholder.SetActive(false);
 472        voiceChatButton.gameObject.SetActive(false);
 73
 474        chatHeadsGroup.Initialize(chatController, friendsController);
 475        chatButton.Initialize();
 476        friendsButton.Initialize();
 477        experiencesButton.Initialize();
 78
 479        chatHeadsGroup.OnHeadToggleOn += OnWindowToggleOn;
 480        chatHeadsGroup.OnHeadToggleOff += OnWindowToggleOff;
 81
 482        chatButton.OnToggleOn += OnWindowToggleOn;
 483        chatButton.OnToggleOff += OnWindowToggleOff;
 84
 485        friendsButton.OnToggleOn += OnWindowToggleOn;
 486        friendsButton.OnToggleOff += OnWindowToggleOff;
 87
 488        experiencesButton.OnToggleOn += OnWindowToggleOn;
 489        experiencesButton.OnToggleOff += OnWindowToggleOff;
 490    }
 91
 92    private void OnWindowToggleOff(TaskbarButton obj)
 93    {
 594        if (obj == friendsButton)
 295            OnFriendsToggleOff?.Invoke();
 396        else if (obj == chatButton)
 297            OnChatToggleOff?.Invoke();
 198        else if (obj == experiencesButton)
 099            OnExperiencesToggleOff?.Invoke();
 100
 5101        if (AllButtonsToggledOff())
 102        {
 5103            chatButton.SetToggleState(false, useCallback: false);
 5104            controller.worldChatWindowHud.SetVisibility(true);
 105        }
 5106    }
 107
 108    public bool AllButtonsToggledOff()
 109    {
 7110        var btns = GetButtonList();
 111
 7112        bool allToggledOff = true;
 113
 62114        foreach (var btn in btns)
 115        {
 24116            if (btn.toggledOn)
 0117                allToggledOff = false;
 118        }
 119
 7120        return allToggledOff;
 121    }
 122
 123    private void OnWindowToggleOn(TaskbarButton obj)
 124    {
 6125        if (obj == friendsButton)
 2126            OnFriendsToggleOn?.Invoke();
 4127        else if (obj == chatButton)
 3128            OnChatToggleOn?.Invoke();
 1129        else if (obj == experiencesButton)
 0130            OnExperiencesToggleOn?.Invoke();
 131
 6132        SelectButton(obj);
 6133    }
 134
 135    public void SelectButton(TaskbarButton obj)
 136    {
 6137        var taskbarButtonList = GetButtonList();
 138
 56139        foreach (var btn in taskbarButtonList)
 140        {
 22141            if (btn != obj)
 16142                btn.SetToggleState(false, useCallback: true);
 143        }
 6144    }
 145
 4146    internal void OnAddChatWindow() { chatButton.transform.parent.gameObject.SetActive(true); }
 147
 6148    internal void OnAddFriendsWindow() { friendsButton.transform.parent.gameObject.SetActive(true); }
 149
 0150    internal void OnAddExperiencesWindow() { experiencesButton.transform.parent.gameObject.SetActive(true); }
 151
 152    internal void OnAddVoiceChat()
 153    {
 0154        voiceChatButtonPlaceholder.SetActive(true);
 0155        voiceChatButton.gameObject.SetActive(true);
 0156    }
 157
 158    internal void ShowBar(bool visible, bool instant = false)
 159    {
 4160        if (visible)
 4161            taskbarAnimator.Show(instant);
 162        else
 0163            taskbarAnimator.Hide(instant);
 164
 4165        isBarVisible = visible;
 4166    }
 167
 2168    public void SetVisibility(bool visible) { gameObject.SetActive(visible); }
 169
 8170    public void SetExperiencesVisbility(bool visible) { experiencesContainer.SetActive(visible); }
 171
 172    private void OnDestroy()
 173    {
 4174        if (chatHeadsGroup != null)
 175        {
 4176            chatHeadsGroup.OnHeadToggleOn -= OnWindowToggleOn;
 4177            chatHeadsGroup.OnHeadToggleOff -= OnWindowToggleOff;
 178        }
 179
 4180        if (chatButton != null)
 181        {
 4182            chatButton.OnToggleOn -= OnWindowToggleOn;
 4183            chatButton.OnToggleOff -= OnWindowToggleOff;
 184        }
 185
 4186        if (friendsButton != null)
 187        {
 4188            friendsButton.OnToggleOn -= OnWindowToggleOn;
 4189            friendsButton.OnToggleOff -= OnWindowToggleOff;
 190        }
 191
 4192        if (experiencesButton != null)
 193        {
 4194            experiencesButton.OnToggleOn -= OnWindowToggleOn;
 4195            experiencesButton.OnToggleOff -= OnWindowToggleOff;
 196        }
 4197    }
 198}