< Summary

Class:UsersAroundListHUDListView
Assembly:UsersAroundListHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListView.cs
Covered lines:64
Uncovered lines:24
Coverable lines:88
Total lines:197
Line coverage:72.7% (64 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%2100%

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;
 4using DCL.SettingsData;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8internal class UsersAroundListHUDListView : MonoBehaviour, IUsersAroundListHUDListView
 9{
 10    public event Action<string, bool> OnRequestMuteUser;
 11    public event Action<bool> OnRequestMuteGlobal;
 12    public event Action OnGoToCrowdPressed;
 13    public event Action OnOpen;
 14
 15    [SerializeField] private UsersAroundListHUDListElementView listElementView;
 16    [SerializeField] private ShowHideAnimator showHideAnimator;
 17    [SerializeField] internal TMPro.TextMeshProUGUI textPlayersTitle;
 18    [SerializeField] internal Transform contentPlayers;
 19    [SerializeField] internal Toggle muteAllToggle;
 20    [SerializeField] internal UserContextMenu contextMenu;
 21    [SerializeField] internal UserContextConfirmationDialog confirmationDialog;
 22    [SerializeField] internal GameObject emptyListGameObject;
 23    [SerializeField] internal Button gotoCrowdButton;
 24    [SerializeField] internal SpinBoxPresetted voiceChatSpinBox;
 25
 26    internal Queue<UsersAroundListHUDListElementView> availableElements;
 27    internal Dictionary<string, UsersAroundListHUDListElementView> userElementDictionary;
 28
 29    private string playersTextPattern;
 30    private bool isGameObjectDestroyed = false;
 31
 32    private void Awake()
 33    {
 434        availableElements = new Queue<UsersAroundListHUDListElementView>();
 435        userElementDictionary = new Dictionary<string, UsersAroundListHUDListElementView>();
 36
 437        playersTextPattern = textPlayersTitle.text;
 438        textPlayersTitle.text = string.Format(playersTextPattern, userElementDictionary?.Count ?? 0);
 39
 440        muteAllToggle.onValueChanged.AddListener(OnMuteGlobal);
 441        gotoCrowdButton.onClick.AddListener(() => OnGoToCrowdPressed?.Invoke());
 442        voiceChatSpinBox.onValueChanged.AddListener(OnVoiceChatSettingChanged);
 43
 444        listElementView.OnMuteUser += OnMuteUser;
 445        listElementView.OnShowUserContexMenu += OnUserContextMenu;
 446        listElementView.OnPoolRelease();
 447        availableElements.Enqueue(listElementView);
 48
 449        Settings.i.OnGeneralSettingsChanged += OnSettingsChanged;
 450    }
 51
 52    void OnDestroy()
 53    {
 454        isGameObjectDestroyed = true;
 455        Settings.i.OnGeneralSettingsChanged -= OnSettingsChanged;
 456    }
 57
 58    void IUsersAroundListHUDListView.AddOrUpdatePlayer(Player player)
 59    {
 360        if (userElementDictionary.ContainsKey(player.id))
 61        {
 062            return;
 63        }
 64
 365        var profile = UserProfileController.userProfilesCatalog.Get(player.id);
 66
 367        if (profile == null)
 068            return;
 69
 370        UsersAroundListHUDListElementView view = null;
 371        if (availableElements.Count > 0)
 72        {
 273            view = availableElements.Dequeue();
 274        }
 75        else
 76        {
 177            view = Instantiate(listElementView, contentPlayers);
 178            view.OnMuteUser += OnMuteUser;
 179            view.OnShowUserContexMenu += OnUserContextMenu;
 80        }
 81
 382        view.OnPoolGet();
 383        view.SetUserProfile(profile);
 384        userElementDictionary.Add(player.id, view);
 385        OnModifyListCount();
 386        CheckListEmptyState();
 387    }
 88
 89    void IUsersAroundListHUDListView.RemoveUser(string userId)
 90    {
 291        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 92        {
 093            return;
 94        }
 295        if (!elementView)
 96        {
 097            return;
 98        }
 99
 2100        PoolElementView(elementView);
 2101        userElementDictionary.Remove(userId);
 2102        OnModifyListCount();
 2103        CheckListEmptyState();
 2104    }
 105
 106    void IUsersAroundListHUDListView.SetUserRecording(string userId, bool isRecording)
 107    {
 0108        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 109        {
 0110            return;
 111        }
 0112        elementView.SetRecording(isRecording);
 0113    }
 114
 115    void IUsersAroundListHUDListView.SetUserMuted(string userId, bool isMuted)
 116    {
 3117        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 118        {
 0119            return;
 120        }
 3121        elementView.SetMuted(isMuted);
 3122    }
 123
 124    void IUsersAroundListHUDListView.SetUserBlocked(string userId, bool blocked)
 125    {
 3126        if (!userElementDictionary.TryGetValue(userId, out UsersAroundListHUDListElementView elementView))
 127        {
 0128            return;
 129        }
 3130        elementView.SetBlocked(blocked);
 3131    }
 132
 133    void IUsersAroundListHUDListView.SetVisibility(bool visible)
 134    {
 1135        if (visible)
 136        {
 1137            if (!gameObject.activeSelf)
 138            {
 1139                gameObject.SetActive(true);
 140            }
 141
 1142            showHideAnimator.Show();
 1143            CheckListEmptyState();
 1144            OnOpen?.Invoke();
 1145        }
 146        else
 147        {
 0148            showHideAnimator.Hide();
 0149            contextMenu.Hide();
 0150            confirmationDialog.Hide();
 151        }
 0152    }
 153
 154    void IUsersAroundListHUDListView.Dispose()
 155    {
 4156        userElementDictionary.Clear();
 4157        availableElements.Clear();
 158
 4159        if (!isGameObjectDestroyed)
 160        {
 4161            Destroy(gameObject);
 162        }
 4163    }
 164
 0165    void OnMuteUser(string userId, bool mute) { OnRequestMuteUser?.Invoke(userId, mute); }
 166
 0167    void OnMuteGlobal(bool mute) { OnRequestMuteGlobal?.Invoke(mute); }
 168
 169    void OnUserContextMenu(Vector3 position, string userId)
 170    {
 0171        contextMenu.transform.position = position;
 0172        contextMenu.Show(userId);
 0173    }
 174
 175    void PoolElementView(UsersAroundListHUDListElementView element)
 176    {
 2177        element.OnPoolRelease();
 2178        availableElements.Enqueue(element);
 2179    }
 180
 10181    void OnModifyListCount() { textPlayersTitle.text = string.Format(playersTextPattern, userElementDictionary.Count); }
 182
 183    void CheckListEmptyState()
 184    {
 6185        bool isEmpty = userElementDictionary.Count == 0;
 6186        emptyListGameObject.SetActive(isEmpty);
 6187    }
 188
 189    void OnVoiceChatSettingChanged(int index)
 190    {
 0191        var newSettings = Settings.i.generalSettings;
 0192        newSettings.voiceChatAllow = (GeneralSettings.VoiceChatAllow)index;
 0193        Settings.i.ApplyGeneralSettings(newSettings);
 0194    }
 195
 0196    void OnSettingsChanged(GeneralSettings settings) { voiceChatSpinBox.SetValue((int)settings.voiceChatAllow, false); }
 197}