< Summary

Class:EntityListAdapter
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Scripts/GodMode/Inspector/EntityListAdapter.cs
Covered lines:44
Uncovered lines:55
Coverable lines:99
Total lines:206
Line coverage:44.4% (44 of 99)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%4.123050%
OnDestroy()0%5.673033.33%
SetContent(...)0%2.042078.57%
SelectOrDeselect()0%12300%
ShowOrHide()0%6200%
LockOrUnlock()0%6200%
DeleteEntity()0%6200%
SetInfo(...)0%5.685070%
GetThumbnail(...)0%8.213016.67%
SetThumbnail(...)0%6200%
Rename(...)0%12300%
AllowNameEdition(...)0%110100%
DeleteAdapter(...)0%12300%
SetEntityError(...)0%2.062075%
SetTextboxActive(...)0%2.52050%
CheckEntityNameColor(...)0%4.074083.33%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Scripts/GodMode/Inspector/EntityListAdapter.cs

#LineLine coverage
 1using DCL;
 2using DCL.Models;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.EventSystems;
 6using UnityEngine.UI;
 7
 8public class EntityListAdapter : MonoBehaviour
 9{
 10    public Color entitySelectedColor;
 11    public Color entityUnselectedColor;
 12    public Color entityWithoutErrorsColor;
 13    public Color entityErrorColor;
 14    public Color iconsSelectedColor;
 15    public Color iconsUnselectedColor;
 16    public TMP_InputField nameInputField;
 17    public TextMeshProUGUI nameInputField_Text;
 18    public Image selectedImg;
 19    public RawImage entityThumbnailImg;
 20    public Button unlockButton;
 21    public Button lockButton;
 22    public Image showImg;
 23    public Image textBoxImage;
 24    public System.Action<EntityAction, BIWEntity, EntityListAdapter> OnActionInvoked;
 25    public System.Action<BIWEntity, string> OnEntityRename;
 26    BIWEntity currentEntity;
 27    internal AssetPromise_Texture loadedThumbnailPromise;
 28
 29    private void Start()
 30    {
 131        if (nameInputField != null)
 32        {
 033            nameInputField.onSelect.AddListener((currentText) => SetTextboxActive(true));
 34
 035            nameInputField.onEndEdit.AddListener((newText) =>
 36            {
 037                Rename(newText);
 038                SetTextboxActive(false);
 39
 040                if (EventSystem.current != null && !EventSystem.current.alreadySelecting)
 041                    EventSystem.current.SetSelectedGameObject(null);
 042            });
 43
 044            nameInputField.onSubmit.AddListener((newText) => EventSystem.current?.SetSelectedGameObject(null));
 45        }
 46
 147        SetTextboxActive(false);
 148    }
 49
 50    private void OnDestroy()
 51    {
 152        if (nameInputField != null)
 53        {
 054            nameInputField.onSelect.RemoveAllListeners();
 055            nameInputField.onEndEdit.RemoveAllListeners();
 056            nameInputField.onSubmit.RemoveAllListeners();
 57        }
 58
 159        if (currentEntity != null)
 60        {
 061            currentEntity.OnStatusUpdate -= SetInfo;
 062            currentEntity.OnDelete -= DeleteAdapter;
 063            currentEntity.OnErrorStatusChange -= SetEntityError;
 64        }
 165    }
 66
 67    public void SetContent(BIWEntity decentrelandEntity)
 68    {
 1469        if (currentEntity != null)
 70        {
 071            currentEntity.OnStatusUpdate -= SetInfo;
 072            currentEntity.OnDelete -= DeleteAdapter;
 073            currentEntity.OnErrorStatusChange -= SetEntityError;
 74        }
 75
 1476        currentEntity = decentrelandEntity;
 1477        currentEntity.OnStatusUpdate += SetInfo;
 1478        currentEntity.OnDelete += DeleteAdapter;
 1479        currentEntity.OnErrorStatusChange += SetEntityError;
 80
 1481        AllowNameEdition(false);
 1482        SetInfo(decentrelandEntity);
 83
 1484        entityThumbnailImg.enabled = false;
 1485        CatalogItem entitySceneObject = decentrelandEntity.GetCatalogItemAssociated();
 1486        GetThumbnail(entitySceneObject);
 1487    }
 88
 89    public void SelectOrDeselect()
 90    {
 091        if (currentEntity.isVisible)
 092            OnActionInvoked?.Invoke(EntityAction.SELECT, currentEntity, this);
 093    }
 94
 095    public void ShowOrHide() { OnActionInvoked?.Invoke(EntityAction.SHOW, currentEntity, this); }
 96
 097    public void LockOrUnlock() { OnActionInvoked?.Invoke(EntityAction.LOCK, currentEntity, this); }
 98
 099    public void DeleteEntity() { OnActionInvoked?.Invoke(EntityAction.DELETE, currentEntity, this); }
 100
 101    void SetInfo(BIWEntity entityToEdit)
 102    {
 14103        if (this == null)
 0104            return;
 105
 14106        if (string.IsNullOrEmpty(entityToEdit.GetDescriptiveName()))
 14107            nameInputField.text = entityToEdit.rootEntity.entityId;
 108        else
 0109            nameInputField.text = entityToEdit.GetDescriptiveName();
 110
 111        //NOTE (Adrian): this is done to force the text component to update, otherwise it won't show the text, seems lik
 14112        nameInputField.textComponent.enabled = true;
 113
 114
 14115        if (entityToEdit.isVisible)
 14116            showImg.color = iconsSelectedColor;
 117        else
 0118            showImg.color = iconsUnselectedColor;
 119
 14120        CheckEntityNameColor(entityToEdit);
 121
 14122        unlockButton.gameObject.SetActive(!entityToEdit.isLocked);
 14123        lockButton.gameObject.SetActive(entityToEdit.isLocked);
 124
 14125        if (entityToEdit.isSelected)
 126        {
 0127            AllowNameEdition(true);
 0128            selectedImg.color = entitySelectedColor;
 0129        }
 130        else
 131        {
 14132            AllowNameEdition(false);
 14133            selectedImg.color = entityUnselectedColor;
 134        }
 135
 14136        SetEntityError(entityToEdit);
 14137    }
 138
 139    internal void GetThumbnail(CatalogItem catalogItem)
 140    {
 14141        if (catalogItem == null)
 14142            return;
 143
 0144        var url = catalogItem.thumbnailURL;
 145
 0146        if (string.IsNullOrEmpty(url))
 0147            return;
 148
 0149        var newLoadedThumbnailPromise = new AssetPromise_Texture(url);
 0150        newLoadedThumbnailPromise.OnSuccessEvent += SetThumbnail;
 0151        newLoadedThumbnailPromise.OnFailEvent += x => { Debug.Log($"Error downloading: {url}"); };
 0152        AssetPromiseKeeper_Texture.i.Keep(newLoadedThumbnailPromise);
 0153        AssetPromiseKeeper_Texture.i.Forget(loadedThumbnailPromise);
 0154        loadedThumbnailPromise = newLoadedThumbnailPromise;
 0155    }
 156
 157    internal void SetThumbnail(Asset_Texture texture)
 158    {
 0159        if (entityThumbnailImg == null)
 0160            return;
 0161        entityThumbnailImg.enabled = true;
 0162        entityThumbnailImg.texture = texture.texture;
 0163    }
 164
 165    public void Rename(string newName)
 166    {
 0167        if (!string.IsNullOrEmpty(newName))
 0168            OnEntityRename?.Invoke(currentEntity, newName);
 169        else
 0170            nameInputField.text = currentEntity.GetDescriptiveName();
 0171    }
 172
 56173    public void AllowNameEdition(bool isAllowed) { nameInputField.enabled = isAllowed; }
 174
 175    void DeleteAdapter(BIWEntity entityToEdit)
 176    {
 0177        if (this != null && entityToEdit.entityUniqueId == currentEntity.entityUniqueId)
 0178            Destroy(gameObject);
 0179    }
 180
 181    private void SetEntityError(BIWEntity entity)
 182    {
 28183        if (entity != currentEntity)
 0184            return;
 185
 28186        CheckEntityNameColor(entity);
 28187    }
 188
 189    private void SetTextboxActive(bool isActive)
 190    {
 1191        if (textBoxImage == null)
 1192            return;
 193
 0194        textBoxImage.enabled = isActive;
 0195    }
 196
 197    private void CheckEntityNameColor(BIWEntity entity)
 198    {
 42199        if (entity.hasError)
 14200            nameInputField_Text.color = entityErrorColor;
 28201        else if (!entity.isVisible || entity.isLocked)
 0202            nameInputField_Text.color = iconsUnselectedColor;
 203        else
 28204            nameInputField_Text.color = entityWithoutErrorsColor;
 28205    }
 206}