| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public interface ILandPublisherView |
| | 7 | | { |
| | 8 | | event Action OnCancel; |
| | 9 | | event Action OnPublish; |
| | 10 | | event Action<string> OnSceneNameChange; |
| | 11 | |
|
| | 12 | | string currentSceneName { get; } |
| | 13 | |
|
| | 14 | | void SetActive(bool isActive); |
| | 15 | | void Cancel(); |
| | 16 | | void Publish(); |
| | 17 | | void SetPublishButtonActive(bool isActive); |
| | 18 | | void SetPublicationScreenshot(Texture2D screenshotTexture); |
| | 19 | | string GetSceneName(); |
| | 20 | | string GetSceneDescription(); |
| | 21 | | Texture2D GetSceneScreenshotTexture(); |
| | 22 | | void SetSceneName(string name); |
| | 23 | | void SetSceneDescription(string desc); |
| | 24 | | } |
| | 25 | |
|
| | 26 | | public class LandPublisherView : MonoBehaviour, ILandPublisherView |
| | 27 | | { |
| | 28 | | public event Action OnCancel; |
| | 29 | | public event Action OnPublish; |
| | 30 | | public event Action<string> OnSceneNameChange; |
| | 31 | |
|
| | 32 | | [SerializeField] internal Button cancelButton; |
| | 33 | | [SerializeField] internal Button publishButton; |
| | 34 | | [SerializeField] internal TMP_Text publishButtonText; |
| | 35 | | [SerializeField] internal LimitInputField nameInputField; |
| | 36 | | [SerializeField] internal LimitInputField descriptionInputField; |
| | 37 | | [SerializeField] internal Image sceneScreenshot; |
| | 38 | |
|
| | 39 | | private const string VIEW_PATH = "Land/LandPublisherView"; |
| | 40 | |
|
| 0 | 41 | | public string currentSceneName => nameInputField.GetValue(); |
| | 42 | |
|
| | 43 | | internal static LandPublisherView Create() |
| | 44 | | { |
| 9 | 45 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<LandPublisherView>(); |
| 9 | 46 | | view.gameObject.name = "_PublicationDetailsView"; |
| | 47 | |
|
| 9 | 48 | | return view; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | private void Awake() |
| | 52 | | { |
| 9 | 53 | | cancelButton.onClick.AddListener(Cancel); |
| 9 | 54 | | publishButton.onClick.AddListener(Publish); |
| | 55 | |
|
| 9 | 56 | | nameInputField.OnEmptyValue += DisableNextButton; |
| 9 | 57 | | nameInputField.OnLimitReached += DisableNextButton; |
| 9 | 58 | | nameInputField.OnInputAvailable += EnableNextButton; |
| | 59 | |
|
| 9 | 60 | | descriptionInputField.OnLimitReached += DisableNextButton; |
| 9 | 61 | | descriptionInputField.OnInputAvailable += EnableNextButton; |
| | 62 | |
|
| 9 | 63 | | gameObject.SetActive(false); |
| 9 | 64 | | } |
| | 65 | |
|
| | 66 | | private void OnDestroy() |
| | 67 | | { |
| 9 | 68 | | cancelButton.onClick.RemoveListener(Cancel); |
| 9 | 69 | | publishButton.onClick.RemoveListener(Publish); |
| | 70 | |
|
| 9 | 71 | | nameInputField.OnLimitReached -= DisableNextButton; |
| 9 | 72 | | nameInputField.OnInputAvailable -= EnableNextButton; |
| 9 | 73 | | nameInputField.OnEmptyValue -= DisableNextButton; |
| | 74 | |
|
| 9 | 75 | | descriptionInputField.OnLimitReached -= DisableNextButton; |
| 9 | 76 | | descriptionInputField.OnInputAvailable -= EnableNextButton; |
| 9 | 77 | | } |
| | 78 | |
|
| | 79 | | internal void EnableNextButton() |
| | 80 | | { |
| 0 | 81 | | if(nameInputField.IsInputAvailable() && descriptionInputField.IsInputAvailable()) |
| 0 | 82 | | publishButton.interactable = true; |
| 0 | 83 | | } |
| | 84 | |
|
| 0 | 85 | | internal void DisableNextButton() { publishButton.interactable = false; } |
| | 86 | |
|
| 4 | 87 | | public void SetActive(bool isActive) { gameObject.SetActive(isActive); } |
| | 88 | |
|
| 2 | 89 | | public void Cancel() { OnCancel?.Invoke(); } |
| | 90 | |
|
| 2 | 91 | | public void Publish() { OnPublish?.Invoke(); } |
| | 92 | |
|
| | 93 | | public void SetPublishButtonActive(bool isActive) |
| | 94 | | { |
| 2 | 95 | | publishButton.interactable = isActive; |
| 2 | 96 | | publishButtonText.color = new Color(publishButtonText.color.r, publishButtonText.color.g, publishButtonText.colo |
| 2 | 97 | | } |
| | 98 | |
|
| 0 | 99 | | public void SetPublicationScreenshot(Texture2D screenshotTexture) { sceneScreenshot.sprite = Sprite.Create(screensho |
| | 100 | |
|
| 0 | 101 | | public string GetSceneName() { return nameInputField.GetValue(); } |
| | 102 | |
|
| 0 | 103 | | public string GetSceneDescription() { return descriptionInputField.GetValue(); } |
| | 104 | |
|
| 1 | 105 | | public Texture2D GetSceneScreenshotTexture() { return sceneScreenshot.sprite.texture; } |
| | 106 | |
|
| 0 | 107 | | public void SetSceneName(string name) { nameInputField.SetText(name); } |
| | 108 | |
|
| 0 | 109 | | public void SetSceneDescription(string desc) { descriptionInputField.SetText(desc); } |
| | 110 | | } |