| | 1 | | using System; |
| | 2 | | using DCL.Builder; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public interface ILandPublisherController |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// When the publish button has been pressed |
| | 9 | | /// </summary> |
| | 10 | | event Action<IBuilderScene> OnPublishPressed; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// When the publish action is canceled |
| | 14 | | /// </summary> |
| | 15 | | event Action OnPublishCancel; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Init the controller with the default view |
| | 19 | | /// </summary> |
| | 20 | | void Initialize(); |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Init the view with an specific view |
| | 24 | | /// </summary> |
| | 25 | | /// <param name="landPublisherView"></param> |
| | 26 | | void Initialize(ILandPublisherView landPublisherView); |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Set the view active |
| | 30 | | /// </summary> |
| | 31 | | /// <param name="isActive"></param> |
| | 32 | | void SetActive(bool isActive); |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// This will start the flow of the publishing |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="scene"></param> |
| | 38 | | void StartPublishFlow(IBuilderScene scene); |
| | 39 | | void Dispose(); |
| | 40 | | } |
| | 41 | |
|
| | 42 | | public class LandPublisherController : ILandPublisherController |
| | 43 | | { |
| | 44 | | public event Action OnPublishCancel; |
| | 45 | | public event Action<IBuilderScene> OnPublishPressed; |
| | 46 | |
|
| | 47 | | internal const string PREFAB_PATH = "Land/LandPublisherView"; |
| | 48 | | internal const string DEFAULT_SCENE_NAME = "My new place"; |
| | 49 | | internal const string DEFAULT_SCENE_DESC = ""; |
| | 50 | |
|
| | 51 | | internal ILandPublisherView landPublisherView; |
| | 52 | | internal IBuilderScene sceneToPublish; |
| | 53 | |
|
| | 54 | | public void Initialize() |
| | 55 | | { |
| 0 | 56 | | var template = Resources.Load<LandPublisherView>(PREFAB_PATH); |
| 0 | 57 | | Initialize(GameObject.Instantiate(template)); |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | public void Initialize(ILandPublisherView landPublisherView) |
| | 61 | | { |
| 3 | 62 | | this.landPublisherView = landPublisherView; |
| | 63 | |
|
| 3 | 64 | | landPublisherView.OnCancel += Cancel; |
| 3 | 65 | | landPublisherView.OnPublish += Publish; |
| | 66 | |
|
| 3 | 67 | | SetDefaultPublicationInfo(); |
| 3 | 68 | | } |
| | 69 | |
|
| | 70 | | public void Dispose() |
| | 71 | | { |
| 3 | 72 | | landPublisherView.OnCancel -= Cancel; |
| 3 | 73 | | landPublisherView.OnPublish -= Publish; |
| 3 | 74 | | } |
| | 75 | |
|
| 6 | 76 | | public void SetActive(bool isActive) { landPublisherView.SetActive(isActive); } |
| | 77 | |
|
| | 78 | | public void Cancel() |
| | 79 | | { |
| 1 | 80 | | SetActive(false); |
| 1 | 81 | | OnPublishCancel?.Invoke(); |
| 1 | 82 | | } |
| | 83 | |
|
| | 84 | | public void StartPublishFlow(IBuilderScene scene) |
| | 85 | | { |
| 0 | 86 | | sceneToPublish = scene; |
| 0 | 87 | | SetCustomPublicationInfo(scene); |
| 0 | 88 | | SetActive(true); |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | public void Publish() |
| | 92 | | { |
| 0 | 93 | | sceneToPublish.manifest.project.title = landPublisherView.GetSceneName(); |
| 0 | 94 | | sceneToPublish.manifest.project.description = landPublisherView.GetSceneDescription(); |
| | 95 | |
|
| 0 | 96 | | SetActive(false); |
| 0 | 97 | | OnPublishPressed?.Invoke(sceneToPublish); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | public void SetDefaultPublicationInfo() |
| | 101 | | { |
| 3 | 102 | | landPublisherView.SetSceneName(DEFAULT_SCENE_NAME); |
| 3 | 103 | | landPublisherView.SetSceneDescription(DEFAULT_SCENE_DESC); |
| 3 | 104 | | } |
| | 105 | |
|
| | 106 | | public void SetCustomPublicationInfo(IBuilderScene scene) |
| | 107 | | { |
| 0 | 108 | | landPublisherView.SetSceneName(scene.manifest.project.title); |
| 0 | 109 | | landPublisherView.SetSceneDescription(scene.manifest.project.description); |
| 0 | 110 | | SetPublicationScreenshot(scene.sceneScreenshotTexture); |
| 0 | 111 | | } |
| | 112 | |
|
| 0 | 113 | | public void SetPublicationScreenshot(Texture2D sceneScreenshot) { landPublisherView.SetPublicationScreenshot(sceneSc |
| | 114 | | } |