| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | internal class UsersSearchPromptView : MonoBehaviour, IDisposable |
| | 5 | | { |
| | 6 | | public event Action<string> OnSearchText; |
| | 7 | | public event Action OnShouldHide; |
| | 8 | |
|
| | 9 | | [SerializeField] internal SearchInputField searchInputField; |
| | 10 | | [SerializeField] private GameObject emptyListGO; |
| | 11 | | [SerializeField] internal Transform friendListParent; |
| | 12 | | [SerializeField] private UserElementView userElementBase; |
| | 13 | | [SerializeField] private ShowHideAnimator showHideAnimator; |
| | 14 | |
|
| | 15 | | private bool isDestroyed = false; |
| | 16 | | private RectTransform rectTransform; |
| | 17 | |
|
| | 18 | | private void Awake() |
| | 19 | | { |
| 7 | 20 | | rectTransform = GetComponent<RectTransform>(); |
| 7 | 21 | | searchInputField.OnSearchText += OnSearch; |
| 7 | 22 | | SetFriendListEmpty(true); |
| 7 | 23 | | gameObject.SetActive(false); |
| 7 | 24 | | } |
| | 25 | |
|
| | 26 | | private void OnDestroy() |
| | 27 | | { |
| 7 | 28 | | searchInputField.OnSearchText -= OnSearch; |
| 7 | 29 | | isDestroyed = true; |
| 7 | 30 | | } |
| | 31 | |
|
| 0 | 32 | | private void Update() { HideIfClickedOutside(); } |
| | 33 | |
|
| | 34 | | public void Dispose() |
| | 35 | | { |
| 26 | 36 | | if (!isDestroyed) |
| | 37 | | { |
| 26 | 38 | | Destroy(gameObject); |
| | 39 | | } |
| 26 | 40 | | } |
| | 41 | |
|
| | 42 | | public void SetFriendListEmpty(bool isEmpty) |
| | 43 | | { |
| 19 | 44 | | emptyListGO.SetActive(isEmpty); |
| 19 | 45 | | friendListParent.gameObject.SetActive(!isEmpty); |
| 19 | 46 | | } |
| | 47 | |
|
| 12 | 48 | | public void ClearSearch() { searchInputField.ClearSearch(); } |
| | 49 | |
|
| 0 | 50 | | public UserElementView GetUsersBaseElement() { return userElementBase; } |
| | 51 | |
|
| 0 | 52 | | public Transform GetUserElementsParent() { return friendListParent; } |
| | 53 | |
|
| | 54 | | public void Show() |
| | 55 | | { |
| 6 | 56 | | this.enabled = true; |
| 6 | 57 | | if (!gameObject.activeSelf) |
| | 58 | | { |
| 6 | 59 | | gameObject.SetActive(true); |
| | 60 | | } |
| 6 | 61 | | showHideAnimator.Show(); |
| 6 | 62 | | } |
| | 63 | |
|
| 0 | 64 | | public void Hide() { showHideAnimator.Hide(); } |
| | 65 | |
|
| 0 | 66 | | public void SetIdleSearchTime(float idleSearchTime) { searchInputField.SetIdleSearchTime(idleSearchTime); } |
| | 67 | |
|
| 4 | 68 | | public void ShowSearchSpinner() { searchInputField.ShowSearchSpinner(); } |
| | 69 | |
|
| 2 | 70 | | public void ShowClearButton() { searchInputField.ShowSearchClearButton(); } |
| | 71 | |
|
| 16 | 72 | | private void OnSearch(string value) { OnSearchText?.Invoke(value); } |
| | 73 | |
|
| | 74 | | private void HideIfClickedOutside() |
| | 75 | | { |
| 0 | 76 | | if (Input.GetMouseButtonDown(0) && |
| | 77 | | !RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition)) |
| | 78 | | { |
| 0 | 79 | | OnShouldHide?.Invoke(); |
| 0 | 80 | | this.enabled = false; |
| | 81 | | } |
| 0 | 82 | | } |
| | 83 | | } |