< Summary

Class:DCL.Builder.PublishProjectDetailView
Assembly:BuilderPublisher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Publisher/ProjectPublishHUD/Scripts/PublishProjectDetailView.cs
Covered lines:0
Uncovered lines:43
Coverable lines:43
Total lines:164
Line coverage:0% (0 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PublishProjectDetailView()0%2100%
RefreshControl()0%6200%
Awake()0%2100%
Dispose()0%2100%
SetProjectToPublish(...)0%2100%
GetScreenshotText(...)0%2100%
FillLandDropDown()0%6200%
Show()0%2100%
Hide()0%2100%
PublishButtonPressed()0%6200%
CancelPublish()0%6200%
CancelButtonPressed()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Publisher/ProjectPublishHUD/Scripts/PublishProjectDetailView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCL.Builder
 9{
 10    public interface IPublishProjectDetailView
 11    {
 12        /// <summary>
 13        /// If the publish is canceled this action will be called
 14        /// </summary>
 15        public event Action OnCancel;
 16
 17        /// <summary>
 18        /// If the publish button is pressed this action will be called
 19        /// </summary>
 20        public event Action OnPublishButtonPressed;
 21
 22        /// <summary>
 23        /// Set the project to publish
 24        /// </summary>
 25        /// <param name="scene"></param>
 26        void SetProjectToPublish(BuilderScene scene);
 27
 28        /// <summary>
 29        /// This will show the detail modal
 30        /// </summary>
 31        void Show();
 32
 33        /// <summary>
 34        /// This will hide the detail modal
 35        /// </summary>
 36        void Hide();
 37
 38        /// <summary>
 39        /// Dispose the view
 40        /// </summary>
 41        void Dispose();
 42    }
 43
 44    public class PublishProjectDetailView : BaseComponentView, IPublishProjectDetailView
 45    {
 46        private const string SCREENSHOT_TEXT =  @"{0} parcel = {1}x{2}m";
 47
 48        //TODO: This will be implemented in the future
 49        public event Action OnProjectRotate;
 50        public event Action OnCancel;
 51        public event Action OnPublishButtonPressed;
 52
 53        [SerializeField] internal Button cancelButton;
 54        [SerializeField] internal Button publishButton;
 55
 56        //TODO: This functionality will be implemented in the future
 57        [SerializeField] internal Button rotateLeftButton;
 58        [SerializeField] internal Button rotateRightButton;
 59
 60        [SerializeField] internal Button zoomInButton;
 61        [SerializeField] internal Button zoomOutButton;
 62        [SerializeField] internal Button resetToLandButton;
 63        [SerializeField] internal Image mapImage;
 64
 65        [SerializeField] internal RawImage sceneScreenshotImage;
 66
 67        [SerializeField] internal ModalComponentView modal;
 68
 69        [SerializeField] internal TMP_Text sceneScreenshotParcelText;
 70        [SerializeField] internal LimitInputField nameInputField;
 71        [SerializeField] internal LimitInputField descriptionInputField;
 72
 73        [SerializeField] internal TMP_Dropdown landsDropDown;
 74
 75        internal BuilderScene scene;
 76
 077        internal Dictionary<string, LandWithAccess> landsDropdownDictionary = new Dictionary<string, LandWithAccess>();
 78
 79        public override void RefreshControl()
 80        {
 081            if (scene == null)
 082                return;
 83
 084            SetProjectToPublish(scene);
 085        }
 86
 87        public override void Awake()
 88        {
 089            base.Awake();
 090            modal.OnCloseAction += CancelPublish;
 91
 092            cancelButton.onClick.AddListener(CancelButtonPressed);
 093            publishButton.onClick.AddListener(PublishButtonPressed);
 094        }
 95
 96        public override void Dispose()
 97        {
 098            base.Dispose();
 99
 0100            modal.OnCloseAction -= CancelPublish;
 101
 0102            cancelButton.onClick.RemoveAllListeners();
 0103            publishButton.onClick.RemoveAllListeners();
 0104        }
 105
 106        public void SetProjectToPublish(BuilderScene scene)
 107        {
 0108            this.scene = scene;
 109
 110            //We set the screenshot
 0111            sceneScreenshotImage.texture = scene.sceneScreenshotTexture;
 112
 113            //We set the scene info
 0114            nameInputField.SetText(scene.manifest.project.title);
 0115            descriptionInputField.SetText(scene.manifest.project.description);
 0116            sceneScreenshotParcelText.text = GetScreenshotText(scene.scene.sceneData.parcels);
 117
 118            //We fill the land drop down
 0119            FillLandDropDown();
 0120        }
 121
 122        private string GetScreenshotText(Vector2Int[] parcels)
 123        {
 0124            Vector2Int sceneSize = BIWUtils.GetSceneSize(parcels);
 0125            return string.Format(SCREENSHOT_TEXT, parcels.Length, sceneSize.x * DCL.Configuration.ParcelSettings.PARCEL_
 126        }
 127
 128        private void FillLandDropDown()
 129        {
 0130            landsDropdownDictionary.Clear();
 131
 0132            List<TMP_Dropdown.OptionData> landsOption =  new List<TMP_Dropdown.OptionData>();
 0133            foreach (var land in DataStore.i.builderInWorld.landsWithAccess.Get())
 134            {
 0135                TMP_Dropdown.OptionData landData = new TMP_Dropdown.OptionData();
 0136                string text = land.name + " " + land.baseCoords.x + "," + land.baseCoords.y;
 0137                landData.text = text;
 0138                landsOption.Add(landData);
 0139                landsDropdownDictionary.Add(text, land);
 140            }
 141
 0142            landsDropDown.options = landsOption;
 0143        }
 144
 0145        public void Show() { modal.Show(); }
 146
 0147        public void Hide() { modal.Hide(); }
 148
 149        private void PublishButtonPressed()
 150        {
 0151            modal.Hide();
 0152            OnPublishButtonPressed?.Invoke();
 0153        }
 154
 0155        private void CancelPublish() { OnCancel?.Invoke(); }
 156
 157        private void CancelButtonPressed()
 158        {
 0159            modal.Hide();
 0160            CancelPublish();
 0161        }
 162
 163    }
 164}