| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Builder |
| | 8 | | { |
| | 9 | | public interface IPublishProjectController |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// The publish has been confirmed |
| | 13 | | /// </summary> |
| | 14 | | event Action<IBuilderScene, PublishInfo> OnPublishPressed; |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// When the publish action is canceled |
| | 18 | | /// </summary> |
| | 19 | | event Action OnPublishCancel; |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Start the publish flow for a project |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="builderScene"></param> |
| | 25 | | void StartPublishFlow(IBuilderScene builderScene); |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Set the view active |
| | 29 | | /// </summary> |
| | 30 | | /// <param name="isActive"></param> |
| | 31 | | void SetActive(bool isActive); |
| | 32 | |
|
| | 33 | | void Initialize(); |
| | 34 | | void Dispose(); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | public class PublishProjectController : IPublishProjectController |
| | 38 | | { |
| | 39 | | public event Action<IBuilderScene, PublishInfo> OnPublishPressed; |
| | 40 | | public event Action OnPublishCancel; |
| | 41 | |
|
| | 42 | | private const string DETAIL_PREFAB_PATH = "Project/PublishPopupView"; |
| | 43 | |
|
| | 44 | | internal IPublishProjectDetailView detailView; |
| | 45 | |
|
| | 46 | | internal IBuilderScene sceneToPublish; |
| | 47 | |
|
| | 48 | | private PublishInfo.ProjectRotation projectRotation = PublishInfo.ProjectRotation.NORTH; |
| | 49 | |
|
| 0 | 50 | | public PublishProjectController() { detailView = GameObject.Instantiate(Resources.Load<PublishProjectDetailView> |
| | 51 | |
|
| | 52 | | public void Initialize() |
| | 53 | | { |
| 0 | 54 | | detailView.OnCancel += ViewClosed; |
| 0 | 55 | | detailView.OnPublishButtonPressed += PublishButtonPressedButtonPressed; |
| 0 | 56 | | detailView.OnProjectRotateChange += RotationChange; |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | public void Dispose() |
| | 60 | | { |
| 0 | 61 | | detailView.OnCancel -= ViewClosed; |
| 0 | 62 | | detailView.OnPublishButtonPressed -= PublishButtonPressedButtonPressed; |
| 0 | 63 | | detailView.OnProjectRotateChange -= RotationChange; |
| | 64 | |
|
| 0 | 65 | | detailView.Dispose(); |
| 0 | 66 | | } |
| | 67 | |
|
| 0 | 68 | | internal void RotationChange(PublishInfo.ProjectRotation newRotation) { projectRotation = newRotation; } |
| | 69 | |
|
| | 70 | | public void StartPublishFlow(IBuilderScene builderScene) |
| | 71 | | { |
| 0 | 72 | | sceneToPublish = builderScene; |
| | 73 | |
|
| 0 | 74 | | detailView.SetProjectToPublish(sceneToPublish); |
| 0 | 75 | | detailView.Show(); |
| 0 | 76 | | detailView.ResetView(); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | public void SetActive(bool isActive) |
| | 80 | | { |
| 0 | 81 | | if (isActive) |
| 0 | 82 | | detailView.Show(); |
| | 83 | | else |
| 0 | 84 | | ViewClosed(); |
| 0 | 85 | | } |
| | 86 | |
|
| | 87 | | private void ViewClosed() |
| | 88 | | { |
| 0 | 89 | | detailView.Hide(); |
| 0 | 90 | | OnPublishCancel?.Invoke(); |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | private void PublishButtonPressedButtonPressed(PublishInfo info) |
| | 94 | | { |
| 0 | 95 | | info.rotation = projectRotation; |
| 0 | 96 | | OnPublishPressed?.Invoke(sceneToPublish, info); |
| 0 | 97 | | } |
| | 98 | | } |
| | 99 | | } |