| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Builder; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | public interface INewProjectFlowView |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// This will set the title and description of the new project. Order param: Title - Description |
| | 11 | | /// </summary> |
| | 12 | | event Action<string, string> OnTittleAndDescriptionSet; |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// Set the size of the new project. Order param: Rows - Columns |
| | 16 | | /// </summary> |
| | 17 | | event Action<int, int> OnSizeSet; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// This will show the first step of the new project flow |
| | 21 | | /// </summary> |
| | 22 | | void ShowNewProjectTitleAndDescrition(); |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// This will reset the view to the initial values |
| | 26 | | /// </summary> |
| | 27 | | void Reset(); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Hide the view |
| | 31 | | /// </summary> |
| | 32 | | void Hide(); |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// This will return true if the new project windows is active |
| | 36 | | /// </summary> |
| | 37 | | /// <returns></returns> |
| | 38 | | bool IsActive(); |
| | 39 | |
|
| | 40 | | void Dispose(); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public class NewProjectFlowView : MonoBehaviour, INewProjectFlowView |
| | 44 | | { |
| | 45 | | public event Action<string, string> OnTittleAndDescriptionSet; |
| | 46 | | public event Action<int, int> OnSizeSet; |
| | 47 | |
|
| | 48 | | [SerializeField] private NewProjectFirstStepView newProjectFirstStepView; |
| | 49 | | [SerializeField] private NewProjectSecondStepView newProjectSecondStepView; |
| | 50 | |
|
| | 51 | | [SerializeField] private ModalComponentView modal; |
| | 52 | | [SerializeField] private CarouselComponentView carrousel; |
| | 53 | |
|
| | 54 | | internal int currentStep = 0; |
| | 55 | |
|
| | 56 | | private void Awake() |
| | 57 | | { |
| 0 | 58 | | name = "_BuilderNewProjectFlowView"; |
| 0 | 59 | | newProjectFirstStepView.OnBackPressed += BackPressed; |
| 0 | 60 | | newProjectSecondStepView.OnBackPressed += BackPressed; |
| | 61 | |
|
| 0 | 62 | | newProjectFirstStepView.OnNextPressed += SetTittleAndDescription; |
| 0 | 63 | | newProjectSecondStepView.OnNextPressed += SetSize; |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | private void OnDestroy() |
| | 67 | | { |
| 0 | 68 | | Dispose(); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | public void ShowNewProjectTitleAndDescrition() |
| | 72 | | { |
| 0 | 73 | | gameObject.SetActive(true); |
| 0 | 74 | | modal.Show(); |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | public void Reset() |
| | 78 | | { |
| 0 | 79 | | currentStep = 0; |
| 0 | 80 | | carrousel.ResetCarousel(); |
| 0 | 81 | | } |
| | 82 | |
|
| | 83 | | public void Hide() |
| | 84 | | { |
| 0 | 85 | | modal.Hide(); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | public bool IsActive() |
| | 89 | | { |
| 0 | 90 | | return modal.isVisible; |
| | 91 | | } |
| | 92 | |
|
| | 93 | | public void Dispose() |
| | 94 | | { |
| 0 | 95 | | newProjectFirstStepView.OnBackPressed += BackPressed; |
| 0 | 96 | | newProjectSecondStepView.OnBackPressed += BackPressed; |
| | 97 | |
|
| 0 | 98 | | newProjectFirstStepView.OnNextPressed -= SetTittleAndDescription; |
| 0 | 99 | | newProjectSecondStepView.OnNextPressed -= SetSize; |
| 0 | 100 | | } |
| | 101 | |
|
| | 102 | | internal void SetSize(int rows, int colums) |
| | 103 | | { |
| 1 | 104 | | NextPressed(); |
| 1 | 105 | | OnSizeSet?.Invoke(rows, colums); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | internal void SetTittleAndDescription(string title, string description) |
| | 109 | | { |
| 1 | 110 | | NextPressed(); |
| 1 | 111 | | OnTittleAndDescriptionSet?.Invoke(title, description); |
| 1 | 112 | | } |
| | 113 | |
|
| | 114 | | internal void NextPressed() |
| | 115 | | { |
| 3 | 116 | | if (currentStep >= 2) |
| 0 | 117 | | return; |
| | 118 | |
|
| 3 | 119 | | currentStep++; |
| 3 | 120 | | carrousel.GoToNextItem(); |
| 3 | 121 | | } |
| | 122 | |
|
| | 123 | | internal void BackPressed() |
| | 124 | | { |
| 1 | 125 | | if (currentStep == 0) |
| 0 | 126 | | Hide(); |
| | 127 | | else |
| | 128 | | { |
| 1 | 129 | | currentStep--; |
| 1 | 130 | | carrousel.GoToPreviousItem(); |
| | 131 | | } |
| 1 | 132 | | } |
| | 133 | | } |