| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | namespace MainScripts.DCL.Controllers.HUD.ToSPopupHUD |
| | 7 | | { |
| | 8 | | public interface IToSPopupView : IDisposable |
| | 9 | | { |
| | 10 | | event Action OnAccept; |
| | 11 | | event Action OnCancel; |
| | 12 | | event Action OnTermsOfServiceLinkPressed; |
| | 13 | |
|
| | 14 | | void Show(); |
| | 15 | |
|
| | 16 | | void Hide(); |
| | 17 | | } |
| | 18 | |
|
| | 19 | | public class ToSPopupView : MonoBehaviour, IToSPopupView, IPointerClickHandler |
| | 20 | | { |
| | 21 | | public event Action OnAccept; |
| | 22 | | public event Action OnCancel; |
| | 23 | | public event Action OnTermsOfServiceLinkPressed; |
| | 24 | |
|
| | 25 | | private bool isDestroyed = false; |
| | 26 | |
|
| | 27 | | [SerializeField] internal ButtonComponentView agreeButton; |
| | 28 | | [SerializeField] internal ButtonComponentView cancelButton; |
| | 29 | | [SerializeField] internal TextMeshProUGUI tosText; |
| | 30 | |
|
| | 31 | | private void Awake() |
| | 32 | | { |
| 0 | 33 | | Initialize(); |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | internal void Initialize() |
| | 37 | | { |
| 0 | 38 | | agreeButton.onClick.AddListener(OnAcceptPressed); |
| 0 | 39 | | cancelButton.onClick.AddListener(OnCancelPressed); |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | private void OnAcceptPressed() |
| | 43 | | { |
| 0 | 44 | | OnAccept?.Invoke(); |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | private void OnCancelPressed() |
| | 48 | | { |
| 0 | 49 | | OnCancel?.Invoke(); |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | public void Show() |
| | 53 | | { |
| 0 | 54 | | gameObject.SetActive(true); |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | public void Hide() |
| | 58 | | { |
| 0 | 59 | | gameObject.SetActive(false); |
| 0 | 60 | | } |
| | 61 | |
|
| | 62 | | private void OnDestroy() |
| | 63 | | { |
| 0 | 64 | | isDestroyed = true; |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | public void Dispose() |
| | 68 | | { |
| 0 | 69 | | if (!isDestroyed) |
| 0 | 70 | | Destroy(gameObject); |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | public void OnPointerClick(PointerEventData eventData) |
| | 74 | | { |
| 0 | 75 | | if (eventData.button != PointerEventData.InputButton.Left) return; |
| 0 | 76 | | int linkIndex = TMP_TextUtilities.FindIntersectingLink(tosText, eventData.position, tosText.canvas.worldCame |
| 0 | 77 | | if (linkIndex == -1) |
| 0 | 78 | | return; |
| | 79 | |
|
| | 80 | | //There should be only one link, we dont even need to get it |
| 0 | 81 | | OnTermsOfServiceLinkPressed?.Invoke(); |
| 0 | 82 | | } |
| | 83 | | } |
| | 84 | | } |