| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.Builder |
| | 9 | | { |
| | 10 | | public interface INewProjectDetailView |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Create project button pressed |
| | 14 | | /// </summary> |
| | 15 | | event Action<string, string> OnCreatePressed; |
| | 16 | |
|
| | 17 | | event Action<string> OnSceneNameChange; |
| | 18 | |
|
| | 19 | | void SetActive(bool isActive); |
| | 20 | |
|
| | 21 | | void SetSceneNameValidationActive(bool isActive); |
| | 22 | |
|
| | 23 | | void SetCreateProjectButtonActive(bool isActive); |
| | 24 | | } |
| | 25 | |
|
| | 26 | | public class NewLandProjectDetailView : MonoBehaviour, INewProjectDetailView |
| | 27 | | { |
| | 28 | | [SerializeField] internal Button cancelButton; |
| | 29 | | [SerializeField] internal Button createProjectButton; |
| | 30 | | [SerializeField] internal TMP_Text createProjectButtonText; |
| | 31 | |
|
| | 32 | | [Header("Project name")] |
| | 33 | | [SerializeField] internal TMP_InputField sceneNameInput; |
| | 34 | | [SerializeField] internal TMP_Text sceneNameValidationText; |
| | 35 | | [SerializeField] internal TMP_Text sceneNameCharCounterText; |
| 20 | 36 | | [SerializeField] internal int sceneNameCharLimit = 30; |
| | 37 | |
|
| | 38 | | [Header("Project description")] |
| | 39 | | [SerializeField] internal TMP_InputField sceneDescriptionInput; |
| | 40 | | [SerializeField] internal TMP_Text sceneDescriptionCharCounterText; |
| 20 | 41 | | [SerializeField] internal int sceneDescriptionCharLimit = 140; |
| | 42 | |
|
| | 43 | | public event Action<string, string> OnCreatePressed; |
| | 44 | | public event Action<string> OnSceneNameChange; |
| | 45 | |
|
| | 46 | | private void Awake() |
| | 47 | | { |
| 0 | 48 | | cancelButton.onClick.AddListener(Cancel); |
| 0 | 49 | | createProjectButton.onClick.AddListener(CreateProject); |
| | 50 | |
|
| 0 | 51 | | sceneNameInput.onValueChanged.AddListener((newText) => |
| | 52 | | { |
| 0 | 53 | | UpdateSceneNameCharCounter(); |
| 0 | 54 | | OnSceneNameChange?.Invoke(newText); |
| 0 | 55 | | }); |
| | 56 | |
|
| 0 | 57 | | sceneDescriptionInput.onValueChanged.AddListener((newText) => |
| | 58 | | { |
| 0 | 59 | | UpdateSceneDescriptionCharCounter(); |
| 0 | 60 | | }); |
| | 61 | |
|
| 0 | 62 | | sceneNameInput.characterLimit = sceneNameCharLimit; |
| 0 | 63 | | sceneDescriptionInput.characterLimit = sceneDescriptionCharLimit; |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | private void OnDestroy() |
| | 67 | | { |
| 0 | 68 | | createProjectButton.onClick.RemoveListener(CreateProject); |
| | 69 | |
|
| 0 | 70 | | sceneNameInput.onValueChanged.RemoveAllListeners(); |
| 0 | 71 | | sceneDescriptionInput.onValueChanged.RemoveAllListeners(); |
| 0 | 72 | | } |
| | 73 | |
|
| 0 | 74 | | public void SetSceneNameValidationActive(bool isActive) { sceneNameValidationText.enabled = isActive; } |
| | 75 | |
|
| 0 | 76 | | public void SetActive(bool isActive) { gameObject.SetActive(isActive); } |
| | 77 | |
|
| | 78 | | public void SetCreateProjectButtonActive(bool isActive) |
| | 79 | | { |
| 0 | 80 | | createProjectButton.interactable = isActive; |
| 0 | 81 | | createProjectButtonText.color = new Color(createProjectButtonText.color.r, createProjectButtonText.color.g, |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | internal void CreateProject() |
| | 85 | | { |
| 0 | 86 | | OnCreatePressed?.Invoke(sceneNameInput.text, sceneDescriptionInput.text); |
| 0 | 87 | | SetActive(false); |
| 0 | 88 | | } |
| | 89 | |
|
| 0 | 90 | | internal void UpdateSceneNameCharCounter() { sceneNameCharCounterText.text = $"{sceneNameInput.text.Length}/{sce |
| | 91 | |
|
| 0 | 92 | | internal void UpdateSceneDescriptionCharCounter() { sceneDescriptionCharCounterText.text = $"{sceneDescriptionIn |
| | 93 | |
|
| 0 | 94 | | internal void Cancel() { SetActive(false); } |
| | 95 | | } |
| | 96 | | } |