| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public interface IPublicationDetailsController |
| | 5 | | { |
| | 6 | | event Action OnCancel; |
| | 7 | | event Action OnConfirm; |
| | 8 | |
|
| | 9 | | void Initialize(IPublicationDetailsView publicationDetailsView); |
| | 10 | | void Dispose(); |
| | 11 | | void SetActive(bool isActive); |
| | 12 | | void Cancel(); |
| | 13 | | void Publish(string sceneName, string sceneDescription); |
| | 14 | | void ValidatePublicationInfo(string sceneName); |
| | 15 | | void SetDefaultPublicationInfo(); |
| | 16 | | void SetCustomPublicationInfo(string sceneName, string sceneDescription); |
| | 17 | | void SetPublicationScreenshot(Texture2D sceneScreenshot); |
| | 18 | | string GetSceneName(); |
| | 19 | | string GetSceneDescription(); |
| | 20 | | Texture2D GetSceneScreenshotTexture(); |
| | 21 | | } |
| | 22 | |
|
| | 23 | | public class PublicationDetailsController : IPublicationDetailsController |
| | 24 | | { |
| | 25 | | public event Action OnCancel; |
| | 26 | | public event Action OnConfirm; |
| | 27 | |
|
| | 28 | | internal const string DEFAULT_SCENE_NAME = "My new place"; |
| | 29 | | internal const string DEFAULT_SCENE_DESC = ""; |
| | 30 | |
|
| | 31 | | internal IPublicationDetailsView publicationDetailsView; |
| | 32 | | internal bool isValidated = false; |
| | 33 | |
|
| | 34 | | public void Initialize(IPublicationDetailsView publicationDetailsView) |
| | 35 | | { |
| 12 | 36 | | this.publicationDetailsView = publicationDetailsView; |
| | 37 | |
|
| 12 | 38 | | publicationDetailsView.OnCancel += Cancel; |
| 12 | 39 | | publicationDetailsView.OnPublish += Publish; |
| 12 | 40 | | publicationDetailsView.OnSceneNameChange += ValidatePublicationInfo; |
| | 41 | |
|
| 12 | 42 | | SetDefaultPublicationInfo(); |
| 12 | 43 | | ValidatePublicationInfo(publicationDetailsView.currentSceneName); |
| 12 | 44 | | } |
| | 45 | |
|
| | 46 | | public void Dispose() |
| | 47 | | { |
| 12 | 48 | | publicationDetailsView.OnCancel -= Cancel; |
| 12 | 49 | | publicationDetailsView.OnPublish -= Publish; |
| 12 | 50 | | publicationDetailsView.OnSceneNameChange -= ValidatePublicationInfo; |
| 12 | 51 | | } |
| | 52 | |
|
| 8 | 53 | | public void SetActive(bool isActive) { publicationDetailsView.SetActive(isActive); } |
| | 54 | |
|
| | 55 | | public void Cancel() |
| | 56 | | { |
| 1 | 57 | | SetActive(false); |
| 1 | 58 | | OnCancel?.Invoke(); |
| 1 | 59 | | } |
| | 60 | |
|
| | 61 | | public void Publish(string sceneName, string sceneDescription) |
| | 62 | | { |
| 2 | 63 | | if (!isValidated) |
| 1 | 64 | | return; |
| | 65 | |
|
| 1 | 66 | | SetActive(false); |
| 1 | 67 | | OnConfirm?.Invoke(); |
| 1 | 68 | | } |
| | 69 | |
|
| | 70 | | public void ValidatePublicationInfo(string sceneName) |
| | 71 | | { |
| 14 | 72 | | isValidated = sceneName.Length > 0; |
| 14 | 73 | | publicationDetailsView.SetSceneNameValidationActive(!isValidated); |
| 14 | 74 | | publicationDetailsView.SetPublishButtonActive(isValidated); |
| 14 | 75 | | } |
| | 76 | |
|
| | 77 | | public void SetDefaultPublicationInfo() |
| | 78 | | { |
| 13 | 79 | | publicationDetailsView.SetSceneName(DEFAULT_SCENE_NAME); |
| 13 | 80 | | publicationDetailsView.SetSceneDescription(DEFAULT_SCENE_DESC); |
| 13 | 81 | | } |
| | 82 | |
|
| | 83 | | public void SetCustomPublicationInfo(string sceneName, string sceneDescription) |
| | 84 | | { |
| 1 | 85 | | publicationDetailsView.SetSceneName(sceneName); |
| 1 | 86 | | publicationDetailsView.SetSceneDescription(sceneDescription); |
| 1 | 87 | | } |
| | 88 | |
|
| 0 | 89 | | public void SetPublicationScreenshot(Texture2D sceneScreenshot) { publicationDetailsView.SetPublicationScreenshot(sc |
| | 90 | |
|
| 1 | 91 | | public string GetSceneName() { return publicationDetailsView.GetSceneName(); } |
| | 92 | |
|
| 1 | 93 | | public string GetSceneDescription() { return publicationDetailsView.GetSceneDescription(); } |
| | 94 | |
|
| 1 | 95 | | public Texture2D GetSceneScreenshotTexture() { return publicationDetailsView.GetSceneScreenshotTexture(); } |
| | 96 | | } |