| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Builder; |
| | 5 | | using UnityEngine; |
| | 6 | | using Object = UnityEngine.Object; |
| | 7 | |
|
| | 8 | | public interface INewProjectFlowController |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// When a new project is created |
| | 12 | | /// </summary> |
| | 13 | | event Action<ProjectData> OnNewProjectCrated; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// This will create a new project data and show the view to create it |
| | 17 | | /// </summary> |
| | 18 | | void NewProject(); |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Hide the view |
| | 22 | | /// </summary> |
| | 23 | | void Hide(); |
| | 24 | |
|
| | 25 | | void Dispose(); |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// This will return true if the new project windows is active |
| | 29 | | /// </summary> |
| | 30 | | /// <returns></returns> |
| | 31 | | bool IsActive(); |
| | 32 | | } |
| | 33 | |
|
| | 34 | | public class NewProjectFlowController : INewProjectFlowController |
| | 35 | | { |
| | 36 | | public const string VIEW_PATH = "NewProject/NewProjectFlowView"; |
| | 37 | |
|
| | 38 | | public event Action<ProjectData> OnNewProjectCrated; |
| | 39 | |
|
| | 40 | | internal ProjectData projectData; |
| | 41 | |
|
| | 42 | | internal INewProjectFlowView view; |
| | 43 | |
|
| 0 | 44 | | public NewProjectFlowController() |
| | 45 | | { |
| 0 | 46 | | var prefab = Resources.Load<NewProjectFlowView>(VIEW_PATH); |
| 0 | 47 | | var instantiateView = Object.Instantiate(prefab); |
| 0 | 48 | | Initilizate(instantiateView); |
| 0 | 49 | | } |
| | 50 | |
|
| 4 | 51 | | public NewProjectFlowController(INewProjectFlowView view) |
| | 52 | | { |
| 4 | 53 | | Initilizate(view); |
| 4 | 54 | | } |
| | 55 | |
|
| | 56 | | private void Initilizate(INewProjectFlowView view) |
| | 57 | | { |
| 4 | 58 | | this.view = view; |
| 4 | 59 | | view.OnTittleAndDescriptionSet += SetTitleAndDescription; |
| 4 | 60 | | view.OnSizeSet += SetRowsAndColumns; |
| 4 | 61 | | } |
| | 62 | |
|
| 0 | 63 | | public void Hide() { view.Hide(); } |
| | 64 | |
|
| | 65 | | public void Dispose() |
| | 66 | | { |
| 4 | 67 | | view.OnTittleAndDescriptionSet -= SetTitleAndDescription; |
| 4 | 68 | | view.OnSizeSet -= SetRowsAndColumns; |
| 4 | 69 | | view.Dispose(); |
| 4 | 70 | | } |
| | 71 | |
|
| | 72 | | public bool IsActive() |
| | 73 | | { |
| 0 | 74 | | return view.IsActive(); |
| | 75 | | } |
| | 76 | |
|
| | 77 | | public void NewProject() |
| | 78 | | { |
| 4 | 79 | | projectData = new ProjectData(); |
| 4 | 80 | | projectData.id = Guid.NewGuid().ToString(); |
| 4 | 81 | | projectData.eth_address = UserProfile.GetOwnUserProfile().ethAddress; |
| | 82 | |
|
| 4 | 83 | | view.ShowNewProjectTitleAndDescrition(); |
| 4 | 84 | | } |
| | 85 | |
|
| | 86 | | public void SetTitleAndDescription(string title, string description) |
| | 87 | | { |
| 1 | 88 | | projectData.title = title; |
| 1 | 89 | | projectData.description = description; |
| 1 | 90 | | } |
| | 91 | |
|
| | 92 | | public void SetRowsAndColumns(int rows, int columns) |
| | 93 | | { |
| 1 | 94 | | projectData.rows = rows; |
| 1 | 95 | | projectData.cols = columns; |
| | 96 | |
|
| 1 | 97 | | NewProjectCreated(); |
| 1 | 98 | | } |
| | 99 | |
|
| | 100 | | internal void NewProjectCreated() |
| | 101 | | { |
| 2 | 102 | | projectData.created_at = DateTime.UtcNow; |
| 2 | 103 | | projectData.updated_at = DateTime.UtcNow; |
| | 104 | |
|
| 2 | 105 | | view.Reset(); |
| 2 | 106 | | OnNewProjectCrated?.Invoke(projectData); |
| 2 | 107 | | view.Hide(); |
| 2 | 108 | | } |
| | 109 | | } |