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