< Summary

Class:EntityInformationView
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/EntityInformationView.cs
Covered lines:59
Uncovered lines:25
Coverable lines:84
Total lines:228
Line coverage:70.2% (59 of 84)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Create()0%110100%
Awake()0%220100%
OnDestroy()0%110100%
LateUpdate()0%20400%
SetCurrentEntity(...)0%2100%
ToggleDetailsInfo()0%330100%
ToggleBasicInfo()0%330100%
StartChangingName()0%220100%
EndChangingName()0%220100%
ChangeEntityName(...)0%4.123050%
Disable()0%220100%
SetEntityThumbnailEnable(...)0%2.062075%
SetEntityThumbnailTexture(...)0%2.062075%
SeEntityLimitsText(...)0%110100%
SetSmartItemListViewActive(...)0%110100%
SetNameIFText(...)0%110100%
SetActive(...)0%110100%
SetPositionAttribute(...)0%2100%
SetRotationAttribute(...)0%2100%
SetScaleAttribute(...)0%2100%
UpdateEntitiesSelection(...)0%220100%
SetTransparencyMode(...)0%110100%
SetNameIFTextboxActive(...)0%2.062075%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/EntityInformationView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5using UnityEngine.UI;
 6
 7public interface IEntityInformationView
 8{
 9    BIWEntity currentEntity { get; set; }
 10    AttributeXYZ position { get; }
 11    AttributeXYZ rotation { get; }
 12    AttributeXYZ scale { get; }
 13    SmartItemListView smartItemList { get; }
 14
 15    event Action OnDisable;
 16    event Action OnEndChangingName;
 17    event Action<BIWEntity, string> OnNameChange;
 18    event Action OnStartChangingName;
 19    event Action<BIWEntity> OnUpdateInfo;
 20
 21    void ChangeEntityName(string newName);
 22    void Disable();
 23    void EndChangingName();
 24    void SeEntityLimitsText(string tris, string mats, string textures);
 25    void SetActive(bool isActive);
 26    void SetCurrentEntity(BIWEntity entity);
 27    void SetEntityThumbnailEnable(bool isEnable);
 28    void SetEntityThumbnailTexture(Texture2D texture);
 29    void SetNameIFText(string text);
 30    void SetPositionAttribute(Vector3 newPos);
 31    void SetRotationAttribute(Vector3 newRotation);
 32    void SetScaleAttribute(Vector3 newScale);
 33    void SetSmartItemListViewActive(bool isActive);
 34    void StartChangingName();
 35    void ToggleBasicInfo();
 36    void ToggleDetailsInfo();
 37    void UpdateEntitiesSelection(int numberOfSelectedEntities);
 38    void SetTransparencyMode(float alphaValue, bool interactable = true);
 39}
 40
 41public class EntityInformationView : MonoBehaviour, IEntityInformationView
 42{
 43    [Header("Sprites")]
 44    [SerializeField] internal Sprite openMenuSprite;
 45
 46    [SerializeField] internal Sprite closeMenuSprite;
 47
 48    [Header("Prefab references")]
 49    [SerializeField] internal CanvasGroup canvasGroup;
 50
 51    [SerializeField] internal GameObject individualEntityPanel;
 52    [SerializeField] internal GameObject multipleEntitiesPanel;
 53    [SerializeField] internal TextMeshProUGUI multipleEntitiesText;
 54    [SerializeField] internal TextMeshProUGUI entityLimitsTrisTxt;
 55    [SerializeField] internal TextMeshProUGUI entityLimitsMaterialsTxt;
 56    [SerializeField] internal TextMeshProUGUI entityLimitsTextureTxt;
 57    [SerializeField] internal TMP_InputField nameIF;
 58    [SerializeField] internal Image nameIFTextBoxImage;
 59    [SerializeField] internal RawImage entitytTumbailImg;
 60    [SerializeField] internal AttributeXYZ positionAttribute;
 61    [SerializeField] internal AttributeXYZ rotationAttribute;
 62    [SerializeField] internal AttributeXYZ scaleAttribute;
 63    [SerializeField] internal GameObject detailsGO;
 64    [SerializeField] internal GameObject basicsGO;
 65    [SerializeField] internal Image detailsToggleBtn;
 66    [SerializeField] internal Image basicToggleBtn;
 67    [SerializeField] internal SmartItemListView smartItemListView;
 68    [SerializeField] internal Button backButton;
 69    [SerializeField] internal Button detailsToggleButton;
 70    [SerializeField] internal Button basicInfoTogglekButton;
 71
 072    public BIWEntity currentEntity { get; set; }
 073    public AttributeXYZ position => positionAttribute;
 074    public AttributeXYZ rotation => rotationAttribute;
 075    public AttributeXYZ scale => scaleAttribute;
 076    public SmartItemListView smartItemList => smartItemListView;
 77
 78    public event Action<BIWEntity, string> OnNameChange;
 79    public event Action<BIWEntity> OnUpdateInfo;
 80    public event Action OnStartChangingName;
 81    public event Action OnEndChangingName;
 82    public event Action OnDisable;
 83
 84    internal const int FRAMES_BETWEEN_UPDATES = 5;
 85    private const string VIEW_PATH = "Common/EntityInformationView";
 86
 87    internal static EntityInformationView Create()
 88    {
 2289        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<EntityInformationView>();
 2290        view.gameObject.name = "_EntityInformationView";
 91
 2292        return view;
 93    }
 94
 95    private void Awake()
 96    {
 2297        backButton.onClick.AddListener(Disable);
 2298        detailsToggleButton.onClick.AddListener(ToggleDetailsInfo);
 2299        basicInfoTogglekButton.onClick.AddListener(ToggleBasicInfo);
 22100        nameIF.onEndEdit.AddListener((newName) =>
 101        {
 0102            ChangeEntityName(newName);
 0103            SetNameIFTextboxActive(false);
 0104        });
 22105        nameIF.onSelect.AddListener((newName) =>
 106        {
 0107            SetNameIFTextboxActive(true);
 0108            StartChangingName();
 0109        });
 22110        nameIF.onSubmit.AddListener((newText) => EventSystem.current?.SetSelectedGameObject(null));
 22111        nameIF.onDeselect.AddListener((newName) => EndChangingName());
 112
 22113        SetNameIFTextboxActive(false);
 22114    }
 115
 116    private void OnDestroy()
 117    {
 22118        backButton.onClick.RemoveListener(Disable);
 22119        detailsToggleButton.onClick.RemoveListener(ToggleDetailsInfo);
 22120        basicInfoTogglekButton.onClick.RemoveListener(ToggleBasicInfo);
 22121        nameIF.onEndEdit.RemoveAllListeners();
 22122        nameIF.onSelect.RemoveAllListeners();
 22123        nameIF.onSubmit.RemoveAllListeners();
 22124        nameIF.onDeselect.RemoveAllListeners();
 22125    }
 126
 127    private void LateUpdate()
 128    {
 0129        if (currentEntity == null)
 0130            return;
 131
 0132        if (Time.frameCount % FRAMES_BETWEEN_UPDATES == 0)
 0133            OnUpdateInfo?.Invoke(currentEntity);
 0134    }
 135
 0136    public void SetCurrentEntity(BIWEntity entity) { currentEntity = entity; }
 137
 138    public void ToggleDetailsInfo()
 139    {
 2140        detailsGO.SetActive(!detailsGO.activeSelf);
 2141        detailsToggleBtn.sprite = detailsGO.activeSelf ? openMenuSprite : closeMenuSprite;
 2142    }
 143
 144    public void ToggleBasicInfo()
 145    {
 2146        basicsGO.SetActive(!basicsGO.activeSelf);
 2147        basicToggleBtn.sprite = basicsGO.activeSelf ? openMenuSprite : closeMenuSprite;
 2148    }
 149
 2150    public void StartChangingName() { OnStartChangingName?.Invoke(); }
 151
 2152    public void EndChangingName() { OnEndChangingName?.Invoke(); }
 153
 154    public void ChangeEntityName(string newName)
 155    {
 1156        if (!string.IsNullOrEmpty(newName))
 1157            OnNameChange?.Invoke(currentEntity, newName);
 158        else
 0159            SetNameIFText(currentEntity.GetDescriptiveName());
 0160    }
 161
 2162    public void Disable() { OnDisable?.Invoke(); }
 163
 164    public void SetEntityThumbnailEnable(bool isEnable)
 165    {
 2166        if (entitytTumbailImg == null)
 0167            return;
 168
 2169        entitytTumbailImg.enabled = isEnable;
 2170    }
 171
 172    public void SetEntityThumbnailTexture(Texture2D texture)
 173    {
 1174        if (entitytTumbailImg == null)
 0175            return;
 176
 1177        entitytTumbailImg.texture = texture;
 1178    }
 179
 180    public void SeEntityLimitsText(string tris, string mats, string textures)
 181    {
 1182        entityLimitsTrisTxt.text = tris;
 1183        entityLimitsMaterialsTxt.text = mats;
 1184        entityLimitsTextureTxt.text = textures;
 1185    }
 186
 4187    public void SetSmartItemListViewActive(bool isActive) { smartItemListView.gameObject.SetActive(isActive); }
 188
 2189    public void SetNameIFText(string text) { nameIF.SetTextWithoutNotify(text); }
 190
 4191    public void SetActive(bool isActive) { gameObject.SetActive(isActive); }
 192
 0193    public void SetPositionAttribute(Vector3 newPos) { positionAttribute.SetValues(newPos); }
 194
 0195    public void SetRotationAttribute(Vector3 newRotation) { rotationAttribute.SetValues(newRotation); }
 196
 0197    public void SetScaleAttribute(Vector3 newScale) { scaleAttribute.SetValues(newScale); }
 198
 199    public void UpdateEntitiesSelection(int numberOfSelectedEntities)
 200    {
 2201        if (numberOfSelectedEntities > 1)
 202        {
 1203            individualEntityPanel.SetActive(false);
 1204            multipleEntitiesPanel.SetActive(true);
 1205            multipleEntitiesText.text = $"{numberOfSelectedEntities} entities selected";
 1206        }
 207        else
 208        {
 1209            individualEntityPanel.SetActive(true);
 1210            multipleEntitiesPanel.SetActive(false);
 211        }
 1212    }
 213
 214    public void SetTransparencyMode(float alphaValue, bool interactable = true)
 215    {
 2216        canvasGroup.alpha = alphaValue;
 2217        canvasGroup.blocksRaycasts = interactable;
 2218        canvasGroup.interactable = interactable;
 2219    }
 220
 221    private void SetNameIFTextboxActive(bool isActive)
 222    {
 22223        if (nameIFTextBoxImage == null)
 0224            return;
 225
 22226        nameIFTextBoxImage.enabled = isActive;
 22227    }
 228}