< Summary

Class:DCL.Builder.NewProjectSecondStepView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/NewProject/NewProjectSecondStepView.cs
Covered lines:43
Uncovered lines:27
Coverable lines:70
Total lines:160
Line coverage:61.4% (43 of 70)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NewProjectSecondStepView()0%110100%
Start()0%110100%
RefreshControl()0%2100%
RowsInputLostFocus()0%6200%
ColumnsInputLostFocus()0%6200%
RowsChanged(...)0%6.744044.44%
ColumnsChanged(...)0%6.744044.44%
ValueChanged(...)0%2.082072.73%
ShowError()0%110100%
ShowGrid()0%110100%
NextPressed()0%3.143075%
BackPressed()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/NewProject/NewProjectSecondStepView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6
 7namespace DCL.Builder
 8{
 9    public class NewProjectSecondStepView : BaseComponentView
 10    {
 11        private const int MAX_PARCELS = 32;
 12
 13        private const string MAX_PARCELS_TEXT = " parcels";
 14
 15        public event Action OnBackPressed;
 16        public event Action<int, int> OnNextPressed;
 17
 18        [Header("Design variables")]
 19        [SerializeField] internal Color normalTextColor;
 20        [SerializeField] internal Color errorTextColor;
 21        [SerializeField] private GridContainerComponentModel gridModel;
 22        [SerializeField] private BaseComponentView parcelImagePrefab;
 23
 24        [Header("References")]
 25        [SerializeField] private LimitInputField rowsInputField;
 26        [SerializeField] private LimitInputField columsInputField;
 27        [SerializeField] internal TextMeshProUGUI parcelText;
 28        [SerializeField] internal GameObject errorGameObject;
 29        [SerializeField] internal GameObject gridGameObject;
 30        [SerializeField] private GridContainerComponentView gridView;
 31
 32        [SerializeField] internal ButtonComponentView nextButton;
 33        [SerializeField] private ButtonComponentView backButton;
 34
 1235        internal int rows = 2;
 1236        internal int colums = 2;
 37
 38        public override void Start()
 39        {
 440            base.Start();
 41
 442            rowsInputField.OnInputChange += RowsChanged;
 443            rowsInputField.OnInputLostFocus += RowsInputLostFocus;
 44
 445            columsInputField.OnInputChange += ColumnsChanged;
 446            columsInputField.OnInputLostFocus += ColumnsInputLostFocus;
 47
 448            backButton.onClick.AddListener(BackPressed);
 449            nextButton.onClick.AddListener(NextPressed);
 450            gridView.Configure(gridModel);
 451        }
 52
 053        public override void RefreshControl() {  }
 54
 55        internal void RowsInputLostFocus()
 56        {
 057            if (!string.IsNullOrEmpty(rowsInputField.GetValue()))
 058                return;
 59
 060            rows = 1;
 061            rowsInputField.SetText(rows.ToString());
 062            ValueChanged(rowsInputField);
 063        }
 64
 65        internal void ColumnsInputLostFocus()
 66        {
 067            if (!string.IsNullOrEmpty(columsInputField.GetValue()))
 068                return;
 69
 070            colums = 1;
 071            columsInputField.SetText(colums.ToString());
 072            ValueChanged(columsInputField);
 073        }
 74
 75        internal void RowsChanged(string value)
 76        {
 77            //We ensure that the minimum size of the row is 1
 178            if (string.IsNullOrEmpty(value) || value == "0")
 79            {
 080                if(rowsInputField.HasFocus())
 081                    return;
 082                rows = 1;
 083                rowsInputField.SetText(rows.ToString());
 084            }
 85            else
 86            {
 187                rows = Mathf.Abs(Int32.Parse(value));
 88            }
 189            ValueChanged(rowsInputField);
 190        }
 91
 92        internal void ColumnsChanged(string value)
 93        {
 94            //We ensure that the minimum size of the column is 1
 195            if (string.IsNullOrEmpty(value) || value == "0")
 96            {
 097                if(columsInputField.HasFocus())
 098                    return;
 099                colums = 1;
 0100                columsInputField.SetText(colums.ToString());
 0101            }
 102            else
 103            {
 1104                colums = Mathf.Abs(Int32.Parse(value));
 105            }
 1106            ValueChanged(columsInputField);
 1107        }
 108
 109        private void ValueChanged(LimitInputField origin)
 110        {
 2111            if (rows * colums > MAX_PARCELS)
 112            {
 0113                ShowError();
 0114                origin.SetError();
 0115            }
 116            else
 117            {
 2118                columsInputField.InputAvailable();
 2119                rowsInputField.InputAvailable();
 120
 2121                gridModel.constraintCount = rows;
 2122                gridView.SetItems(parcelImagePrefab, rows * colums);
 2123                gridView.Configure(gridModel);
 2124                ShowGrid();
 125            }
 2126        }
 127
 128        internal void ShowError()
 129        {
 1130            nextButton.SetInteractable(false);
 1131            errorGameObject.SetActive(true);
 1132            gridGameObject.SetActive(false);
 133
 1134            parcelText.color = errorTextColor;
 135
 1136            parcelText.text = (rows * colums) + MAX_PARCELS_TEXT;
 1137        }
 138
 139        internal void ShowGrid()
 140        {
 3141            nextButton.SetInteractable(true);
 3142            errorGameObject.SetActive(false);
 3143            gridGameObject.SetActive(true);
 144
 3145            parcelText.color = normalTextColor;
 146
 3147            parcelText.text = $"{(rows * colums)} parcels = {(rows * DCL.Configuration.ParcelSettings.PARCEL_SIZE)}x{col
 3148        }
 149
 150        internal void NextPressed()
 151        {
 1152            if (!nextButton.IsInteractable())
 0153                return;
 154
 1155            OnNextPressed?.Invoke(rows, colums);
 1156        }
 157
 2158        internal void BackPressed() { OnBackPressed?.Invoke(); }
 159    }
 160}