< Summary

Class:UsersAroundListHUDListView
Assembly:UsersAroundListHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListView.cs
Covered lines:65
Uncovered lines:23
Coverable lines:88
Total lines:196
Line coverage:73.8% (65 of 88)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%330100%
OnDestroy()0%110100%
AddOrUpdatePlayer(...)0%4.024088.89%
RemoveUser(...)0%3.13077.78%
SetUserRecording(...)0%6200%
SetUserMuted(...)0%2.062075%
SetUserBlocked(...)0%2.062075%
SetVisibility(...)0%4.774063.64%
Dispose()0%220100%
OnMuteUser(...)0%6200%
OnMuteGlobal(...)0%6200%
OnUserContextMenu(...)0%2100%
PoolElementView(...)0%110100%
OnModifyListCount()0%110100%
CheckListEmptyState()0%110100%
OnVoiceChatSettingChanged(...)0%2100%
OnSettingsChanged(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.SettingsCommon;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7internal class UsersAroundListHUDListView : MonoBehaviour, IUsersAroundListHUDListView
 8{
 9    public event Action<string, bool> OnRequestMuteUser;
 10    public event Action<bool> OnRequestMuteGlobal;
 11    public event Action OnGoToCrowdPressed;
 12    public event Action OnOpen;
 13
 14    [SerializeField] private UsersAroundListHUDListElementView listElementView;
 15    [SerializeField] private ShowHideAnimator showHideAnimator;
 16    [SerializeField] internal TMPro.TextMeshProUGUI textPlayersTitle;
 17    [SerializeField] internal Transform contentPlayers;
 18    [SerializeField] internal Toggle muteAllToggle;
 19    [SerializeField] internal UserContextMenu contextMenu;
 20    [SerializeField] internal UserContextConfirmationDialog confirmationDialog;
 21    [SerializeField] internal GameObject emptyListGameObject;
 22    [SerializeField] internal Button gotoCrowdButton;
 23    [SerializeField] internal SpinBoxPresetted voiceChatSpinBox;
 24
 25    internal Queue<UsersAroundListHUDListElementView> availableElements;
 26    internal Dictionary<string, UsersAroundListHUDListElementView> userElementDictionary;
 27
 28    private string playersTextPattern;
 29    private bool isGameObjectDestroyed = false;
 30
 31    private void Awake()
 32    {
 433        availableElements = new Queue<UsersAroundListHUDListElementView>();
 434        userElementDictionary = new Dictionary<string, UsersAroundListHUDListElementView>();
 35
 436        playersTextPattern = textPlayersTitle.text;
 437        textPlayersTitle.text = string.Format(playersTextPattern, userElementDictionary?.Count ?? 0);
 38
 439        muteAllToggle.onValueChanged.AddListener(OnMuteGlobal);
 440        gotoCrowdButton.onClick.AddListener(() => OnGoToCrowdPressed?.Invoke());
 441        voiceChatSpinBox.onValueChanged.AddListener(OnVoiceChatSettingChanged);
 42
 443        listElementView.OnMuteUser += OnMuteUser;
 444        listElementView.OnShowUserContexMenu += OnUserContextMenu;
 445        listElementView.OnPoolRelease();
 446        availableElements.Enqueue(listElementView);
 47
 448        Settings.i.generalSettings.OnChanged += OnSettingsChanged;
 449    }
 50
 51    void OnDestroy()
 52    {
 453        isGameObjectDestroyed = true;
 454        Settings.i.generalSettings.OnChanged -= OnSettingsChanged;
 455    }
 56
 57    void IUsersAroundListHUDListView.AddOrUpdatePlayer(Player player)
 58    {
 359        if (userElementDictionary.ContainsKey(player.id))
 60        {
 061            return;
 62        }
 63
 364        var profile = UserProfileController.userProfilesCatalog.Get(player.id);
 65
 366        if (profile == null)
 067            return;
 68
 369        UsersAroundListHUDListElementView view = null;
 370        if (availableElements.Count > 0)
 71        {
 272            view = availableElements.Dequeue();
 273        }
 74        else
 75        {
 176            view = Instantiate(listElementView, contentPlayers);
 177            view.OnMuteUser += OnMuteUser;
 178            view.OnShowUserContexMenu += OnUserContextMenu;
 79        }
 80
 381        view.OnPoolGet();
 382        view.SetUserProfile(profile);
 383        userElementDictionary.Add(player.id, view);
 384        OnModifyListCount();
 385        CheckListEmptyState();
 386    }
 87
 88    void IUsersAroundListHUDListView.RemoveUser(string userId)
 89    {
 290        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 91        {
 092            return;
 93        }
 294        if (!elementView)
 95        {
 096            return;
 97        }
 98
 299        PoolElementView(elementView);
 2100        userElementDictionary.Remove(userId);
 2101        OnModifyListCount();
 2102        CheckListEmptyState();
 2103    }
 104
 105    void IUsersAroundListHUDListView.SetUserRecording(string userId, bool isRecording)
 106    {
 0107        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 108        {
 0109            return;
 110        }
 0111        elementView.SetRecording(isRecording);
 0112    }
 113
 114    void IUsersAroundListHUDListView.SetUserMuted(string userId, bool isMuted)
 115    {
 3116        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 117        {
 0118            return;
 119        }
 3120        elementView.SetMuted(isMuted);
 3121    }
 122
 123    void IUsersAroundListHUDListView.SetUserBlocked(string userId, bool blocked)
 124    {
 3125        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 126        {
 0127            return;
 128        }
 3129        elementView.SetBlocked(blocked);
 3130    }
 131
 132    void IUsersAroundListHUDListView.SetVisibility(bool visible)
 133    {
 1134        if (visible)
 135        {
 1136            if (!gameObject.activeSelf)
 137            {
 1138                gameObject.SetActive(true);
 139            }
 140
 1141            showHideAnimator.Show();
 1142            CheckListEmptyState();
 1143            OnOpen?.Invoke();
 1144        }
 145        else
 146        {
 0147            showHideAnimator.Hide();
 0148            contextMenu.Hide();
 0149            confirmationDialog.Hide();
 150        }
 0151    }
 152
 153    void IUsersAroundListHUDListView.Dispose()
 154    {
 4155        userElementDictionary.Clear();
 4156        availableElements.Clear();
 157
 4158        if (!isGameObjectDestroyed)
 159        {
 4160            Destroy(gameObject);
 161        }
 4162    }
 163
 0164    void OnMuteUser(string userId, bool mute) { OnRequestMuteUser?.Invoke(userId, mute); }
 165
 0166    void OnMuteGlobal(bool mute) { OnRequestMuteGlobal?.Invoke(mute); }
 167
 168    void OnUserContextMenu(Vector3 position, string userId)
 169    {
 0170        contextMenu.transform.position = position;
 0171        contextMenu.Show(userId);
 0172    }
 173
 174    void PoolElementView(UsersAroundListHUDListElementView element)
 175    {
 2176        element.OnPoolRelease();
 2177        availableElements.Enqueue(element);
 2178    }
 179
 10180    void OnModifyListCount() { textPlayersTitle.text = string.Format(playersTextPattern, userElementDictionary.Count); }
 181
 182    void CheckListEmptyState()
 183    {
 6184        bool isEmpty = userElementDictionary.Count == 0;
 6185        emptyListGameObject.SetActive(isEmpty);
 6186    }
 187
 188    void OnVoiceChatSettingChanged(int index)
 189    {
 0190        var newSettings = Settings.i.generalSettings.Data;
 0191        newSettings.voiceChatAllow = (GeneralSettings.VoiceChatAllow)index;
 0192        Settings.i.generalSettings.Apply(newSettings);
 0193    }
 194
 4195    void OnSettingsChanged(GeneralSettings settings) { voiceChatSpinBox.SetValue((int)settings.voiceChatAllow, false); }
 196}