| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.Builder |
| | 7 | | { |
| | 8 | | public class GenericPopUpView : BaseComponentView, IGenericPopUp |
| | 9 | | { |
| | 10 | | public event Action OnOkPressed; |
| | 11 | | public event Action OnCancelPressed; |
| | 12 | |
|
| | 13 | | [SerializeField] internal Button cancelButton; |
| | 14 | | [SerializeField] internal Button okButton; |
| | 15 | |
|
| | 16 | | [SerializeField] internal TextMeshProUGUI subtitleText; |
| | 17 | |
|
| | 18 | | [SerializeField] internal TextMeshProUGUI okButtonText; |
| | 19 | | [SerializeField] internal TextMeshProUGUI cancelButtonText; |
| | 20 | |
|
| | 21 | | [SerializeField] internal ModalComponentView modalView; |
| | 22 | | [SerializeField] internal ShowHideAnimator showHideAnimator; |
| | 23 | |
|
| | 24 | | public override void Awake() |
| | 25 | | { |
| 0 | 26 | | base.Awake(); |
| 0 | 27 | | cancelButton.onClick.AddListener( () => |
| | 28 | | { |
| 0 | 29 | | Hide(); |
| 0 | 30 | | OnCancelPressed?.Invoke(); |
| 0 | 31 | | }); |
| 0 | 32 | | okButton.onClick.AddListener( () => |
| | 33 | | { |
| 0 | 34 | | Hide(); |
| 0 | 35 | | OnOkPressed?.Invoke(); |
| 0 | 36 | | }); |
| | 37 | |
|
| 0 | 38 | | showHideAnimator.OnWillFinishHide += (x) => |
| | 39 | | { |
| 0 | 40 | | gameObject.SetActive(false); |
| 0 | 41 | | }; |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public void ShowPopUpWithoutTitle(string subtitle, string okButtonText, string cancelButtonText, Action OnOk, Ac |
| | 45 | | { |
| 0 | 46 | | RemoveAllListener(); |
| 0 | 47 | | SetSubtitleText(subtitle); |
| 0 | 48 | | SetOkButtonText(okButtonText); |
| 0 | 49 | | SetCancelButtonText(cancelButtonText); |
| 0 | 50 | | Show(); |
| | 51 | |
|
| 0 | 52 | | OnOkPressed += () => OnOk?.Invoke(); |
| | 53 | |
|
| 0 | 54 | | OnCancelPressed += () => OnCancel?.Invoke(); |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | public override void Dispose() |
| | 58 | | { |
| 0 | 59 | | base.Dispose(); |
| 0 | 60 | | cancelButton.onClick.RemoveAllListeners(); |
| 0 | 61 | | okButton.onClick.RemoveAllListeners(); |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | public void RemoveAllListener() |
| | 65 | | { |
| 0 | 66 | | OnOkPressed = null; |
| 0 | 67 | | OnCancelPressed = null; |
| 0 | 68 | | } |
| | 69 | |
|
| | 70 | | public override void Show(bool instant = false) |
| | 71 | | { |
| 0 | 72 | | gameObject.SetActive(true); |
| 0 | 73 | | base.Show(instant); |
| 0 | 74 | | modalView.Show(instant); |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | public override void Hide(bool instant = false) |
| | 78 | | { |
| 0 | 79 | | base.Hide(instant); |
| 0 | 80 | | modalView.Hide(instant); |
| 0 | 81 | | } |
| | 82 | |
|
| 0 | 83 | | public void SetSubtitleText(string text) { subtitleText.text = text; } |
| | 84 | |
|
| 0 | 85 | | public void SetOkButtonText(string text) { okButtonText.text = text; } |
| | 86 | |
|
| 0 | 87 | | public void SetCancelButtonText(string text) { cancelButtonText.text = text; } |
| | 88 | |
|
| 0 | 89 | | public override void RefreshControl() { } |
| | 90 | | } |
| | 91 | | } |