| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | internal class SectionProjectView : MonoBehaviour, IDisposable |
| | 8 | | { |
| | 9 | | public event Action OnScrollRectValueChanged; |
| | 10 | | public event Action OnCreateProjectRequest; |
| | 11 | |
|
| | 12 | | [SerializeField] public GameObject contentContainer; |
| | 13 | | [SerializeField] public GameObject contentGameObject; |
| | 14 | | [SerializeField] public ScrollRect scrollRect; |
| | 15 | | [SerializeField] internal GameObject emptyContainer; |
| | 16 | | [SerializeField] internal GameObject loadingAnimationContainer; |
| | 17 | | [SerializeField] internal GameObject noSearchResultContainer; |
| | 18 | | [SerializeField] internal Button buttonNoProjectsCTA; |
| | 19 | |
|
| | 20 | | private bool isDestroyed = false; |
| | 21 | |
|
| | 22 | | public void SetParent(Transform parent) |
| | 23 | | { |
| 0 | 24 | | transform.SetParent(parent); |
| 0 | 25 | | transform.ResetLocalTRS(); |
| 0 | 26 | | } |
| | 27 | |
|
| 0 | 28 | | public void SetActive(bool active) { gameObject.SetActive(active); } |
| | 29 | |
|
| 8 | 30 | | public void ResetScrollRect() { scrollRect.verticalNormalizedPosition = 1; } |
| | 31 | |
|
| | 32 | | public void Dispose() |
| | 33 | | { |
| 1 | 34 | | if (!isDestroyed) |
| | 35 | | { |
| 1 | 36 | | Destroy(gameObject); |
| | 37 | | } |
| 1 | 38 | | } |
| | 39 | |
|
| | 40 | | private void Awake() |
| | 41 | | { |
| 1 | 42 | | buttonNoProjectsCTA.onClick.AddListener(() => OnCreateProjectRequest?.Invoke()); |
| 1 | 43 | | scrollRect.onValueChanged.AddListener(OnScrollValueChanged); |
| 1 | 44 | | } |
| | 45 | |
|
| | 46 | | private void OnDestroy() |
| | 47 | | { |
| 1 | 48 | | isDestroyed = true; |
| 1 | 49 | | buttonNoProjectsCTA.onClick.RemoveAllListeners(); |
| 1 | 50 | | scrollRect.onValueChanged.RemoveListener(OnScrollValueChanged); |
| 1 | 51 | | } |
| | 52 | |
|
| 0 | 53 | | private void OnScrollValueChanged(Vector2 value) { OnScrollRectValueChanged?.Invoke(); } |
| | 54 | |
|
| | 55 | | public void SetEmpty() |
| | 56 | | { |
| 0 | 57 | | contentGameObject.SetActive(false); |
| 0 | 58 | | emptyContainer.SetActive(true); |
| 0 | 59 | | noSearchResultContainer.SetActive(false); |
| 0 | 60 | | loadingAnimationContainer.SetActive(false); |
| 0 | 61 | | } |
| | 62 | |
|
| | 63 | | public void SetLoading() |
| | 64 | | { |
| 0 | 65 | | contentGameObject.SetActive(false); |
| 0 | 66 | | emptyContainer.SetActive(false); |
| 0 | 67 | | noSearchResultContainer.SetActive(false); |
| 0 | 68 | | loadingAnimationContainer.SetActive(true); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | public void SetNoSearchResult() |
| | 72 | | { |
| 0 | 73 | | contentGameObject.SetActive(false); |
| 0 | 74 | | emptyContainer.SetActive(false); |
| 0 | 75 | | noSearchResultContainer.SetActive(true); |
| 0 | 76 | | loadingAnimationContainer.SetActive(false); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | public void SetFilled() |
| | 80 | | { |
| 2 | 81 | | contentGameObject.SetActive(true); |
| 2 | 82 | | emptyContainer.SetActive(false); |
| 2 | 83 | | noSearchResultContainer.SetActive(false); |
| 2 | 84 | | loadingAnimationContainer.SetActive(false); |
| 2 | 85 | | ResetScrollRect(); |
| 2 | 86 | | } |
| | 87 | | } |