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