| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | internal interface IOwnersPopupView |
| | 7 | | { |
| | 8 | | event Action OnClosePopup; |
| | 9 | | void Show(); |
| | 10 | | void Hide(bool instant); |
| | 11 | | void SetElements(List<IOwnerInfoElement> elements); |
| | 12 | | bool IsActive(); |
| | 13 | | } |
| | 14 | |
|
| | 15 | | internal class OwnersPopupView : MonoBehaviour, IOwnersPopupView |
| | 16 | | { |
| | 17 | | private const int ADDRESS_MAX_CHARS = 19; |
| | 18 | | private const float ELEMENT_FONT_SIZE = 17; |
| | 19 | | private const float ELEMENT_HORIZONTAL_SPACING = 17; |
| | 20 | |
|
| | 21 | | [SerializeField] internal Transform ownerElementsContainer; |
| | 22 | | [SerializeField] internal Button closeButton; |
| | 23 | | [SerializeField] internal Button backgroundCloseButton; |
| | 24 | | [SerializeField] private ShowHideAnimator showHideAnimator; |
| | 25 | | [SerializeField] private ScrollRect scrollRect; |
| | 26 | |
|
| | 27 | | public event Action OnClosePopup; |
| | 28 | |
|
| | 29 | | void IOwnersPopupView.Show() |
| | 30 | | { |
| 1 | 31 | | gameObject.SetActive(true); |
| 1 | 32 | | scrollRect.verticalNormalizedPosition = 1; |
| 1 | 33 | | showHideAnimator.Show(); |
| 1 | 34 | | } |
| | 35 | |
|
| | 36 | | void IOwnersPopupView.Hide(bool instant) |
| | 37 | | { |
| 2 | 38 | | showHideAnimator.Hide(); |
| 2 | 39 | | if (instant) |
| | 40 | | { |
| 2 | 41 | | gameObject.SetActive(false); |
| | 42 | | } |
| 2 | 43 | | } |
| | 44 | |
|
| | 45 | | void IOwnersPopupView.SetElements(List<IOwnerInfoElement> elements) |
| | 46 | | { |
| 0 | 47 | | for (int i = 0; i < elements.Count; i++) |
| | 48 | | { |
| 0 | 49 | | elements[i].SetParent(ownerElementsContainer); |
| 0 | 50 | | elements[i].SetAddressLength(ADDRESS_MAX_CHARS); |
| 0 | 51 | | elements[i].SetColorIndex(i); |
| 0 | 52 | | elements[i].SetConfig(ELEMENT_FONT_SIZE, ELEMENT_HORIZONTAL_SPACING); |
| 0 | 53 | | elements[i].SetActive(true); |
| | 54 | | } |
| 0 | 55 | | } |
| | 56 | |
|
| 2 | 57 | | bool IOwnersPopupView.IsActive() { return gameObject.activeSelf; } |
| | 58 | |
|
| | 59 | | private void Awake() |
| | 60 | | { |
| 7 | 61 | | closeButton.onClick.AddListener(() => OnClosePopup?.Invoke()); |
| 7 | 62 | | backgroundCloseButton.onClick.AddListener(() => OnClosePopup?.Invoke()); |
| 7 | 63 | | } |
| | 64 | | } |