| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public interface IPublicationDetailsView |
| | 7 | | { |
| | 8 | | event Action OnCancel; |
| | 9 | | event Action<string, string> 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 SetSceneNameValidationActive(bool isActive); |
| | 18 | | void SetSceneName(string newtext); |
| | 19 | | void SetSceneDescription(string newtext); |
| | 20 | | void SetPublishButtonActive(bool isActive); |
| | 21 | | void SetPublicationScreenshot(Texture2D screenshotTexture); |
| | 22 | | string GetSceneName(); |
| | 23 | | string GetSceneDescription(); |
| | 24 | | Texture2D GetSceneScreenshotTexture(); |
| | 25 | | void UpdateSceneNameCharCounter(); |
| | 26 | | void UpdateSceneDescriptionCharCounter(); |
| | 27 | | } |
| | 28 | |
|
| | 29 | | public class PublicationDetailsView : MonoBehaviour, IPublicationDetailsView |
| | 30 | | { |
| | 31 | | public event Action OnCancel; |
| | 32 | | public event Action<string, string> OnPublish; |
| | 33 | | public event Action<string> OnSceneNameChange; |
| | 34 | |
|
| | 35 | | [SerializeField] internal Button cancelButton; |
| | 36 | | [SerializeField] internal Button publishButton; |
| | 37 | | [SerializeField] internal TMP_Text publishButtonText; |
| | 38 | | [SerializeField] internal TMP_InputField sceneNameInput; |
| | 39 | | [SerializeField] internal TMP_Text sceneNameValidationText; |
| | 40 | | [SerializeField] internal TMP_InputField sceneDescriptionInput; |
| | 41 | | [SerializeField] internal Image sceneScreenshot; |
| | 42 | | [SerializeField] internal TMP_Text sceneNameCharCounterText; |
| 56 | 43 | | [SerializeField] internal int sceneNameCharLimit = 30; |
| | 44 | | [SerializeField] internal TMP_Text sceneDescriptionCharCounterText; |
| 56 | 45 | | [SerializeField] internal int sceneDescriptionCharLimit = 140; |
| | 46 | |
|
| | 47 | | private const string VIEW_PATH = "Common/PublicationDetailsView"; |
| | 48 | |
|
| 0 | 49 | | public string currentSceneName => sceneNameInput.text; |
| | 50 | |
|
| | 51 | | internal static PublicationDetailsView Create() |
| | 52 | | { |
| 15 | 53 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<PublicationDetailsView>(); |
| 15 | 54 | | view.gameObject.name = "_PublicationDetailsView"; |
| | 55 | |
|
| 15 | 56 | | return view; |
| | 57 | | } |
| | 58 | |
|
| | 59 | | private void Awake() |
| | 60 | | { |
| 15 | 61 | | cancelButton.onClick.AddListener(Cancel); |
| 15 | 62 | | publishButton.onClick.AddListener(Publish); |
| | 63 | |
|
| 15 | 64 | | sceneNameInput.onValueChanged.AddListener((newText) => |
| | 65 | | { |
| 4 | 66 | | UpdateSceneNameCharCounter(); |
| 4 | 67 | | OnSceneNameChange?.Invoke(newText); |
| 0 | 68 | | }); |
| | 69 | |
|
| 15 | 70 | | sceneDescriptionInput.onValueChanged.AddListener((newText) => |
| | 71 | | { |
| 4 | 72 | | UpdateSceneDescriptionCharCounter(); |
| 4 | 73 | | }); |
| | 74 | |
|
| 15 | 75 | | sceneNameInput.characterLimit = sceneNameCharLimit; |
| 15 | 76 | | sceneDescriptionInput.characterLimit = sceneDescriptionCharLimit; |
| 15 | 77 | | } |
| | 78 | |
|
| | 79 | | private void OnDestroy() |
| | 80 | | { |
| 15 | 81 | | cancelButton.onClick.RemoveListener(Cancel); |
| 15 | 82 | | publishButton.onClick.RemoveListener(Publish); |
| | 83 | |
|
| 15 | 84 | | sceneNameInput.onValueChanged.RemoveAllListeners(); |
| 15 | 85 | | sceneDescriptionInput.onValueChanged.RemoveAllListeners(); |
| 15 | 86 | | } |
| | 87 | |
|
| 4 | 88 | | public void SetActive(bool isActive) { gameObject.SetActive(isActive); } |
| | 89 | |
|
| 2 | 90 | | public void Cancel() { OnCancel?.Invoke(); } |
| | 91 | |
|
| 2 | 92 | | public void Publish() { OnPublish?.Invoke(sceneNameInput.text, sceneDescriptionInput.text); } |
| | 93 | |
|
| 4 | 94 | | public void SetSceneNameValidationActive(bool isActive) { sceneNameValidationText.enabled = isActive; } |
| | 95 | |
|
| | 96 | | public void SetSceneName(string newtext) |
| | 97 | | { |
| 1 | 98 | | sceneNameInput.text = newtext; |
| 1 | 99 | | UpdateSceneNameCharCounter(); |
| 1 | 100 | | } |
| | 101 | |
|
| | 102 | | public void SetSceneDescription(string newtext) |
| | 103 | | { |
| 1 | 104 | | sceneDescriptionInput.text = newtext; |
| 1 | 105 | | UpdateSceneDescriptionCharCounter(); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | public void SetPublishButtonActive(bool isActive) |
| | 109 | | { |
| 2 | 110 | | publishButton.interactable = isActive; |
| 2 | 111 | | publishButtonText.color = new Color(publishButtonText.color.r, publishButtonText.color.g, publishButtonText.colo |
| 2 | 112 | | } |
| | 113 | |
|
| 0 | 114 | | public void SetPublicationScreenshot(Texture2D screenshotTexture) { sceneScreenshot.sprite = Sprite.Create(screensho |
| | 115 | |
|
| 0 | 116 | | public string GetSceneName() { return sceneNameInput.text; } |
| | 117 | |
|
| 0 | 118 | | public string GetSceneDescription() { return sceneDescriptionInput.text; } |
| | 119 | |
|
| 1 | 120 | | public Texture2D GetSceneScreenshotTexture() { return sceneScreenshot.sprite.texture; } |
| | 121 | |
|
| 12 | 122 | | public void UpdateSceneNameCharCounter() { sceneNameCharCounterText.text = $"{sceneNameInput.text.Length}/{sceneName |
| | 123 | |
|
| 12 | 124 | | public void UpdateSceneDescriptionCharCounter() { sceneDescriptionCharCounterText.text = $"{sceneDescriptionInput.te |
| | 125 | | } |