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