| | 1 | | using DCL.Helpers; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using TMPro; |
| | 6 | | using UIComponents.Scripts.Components; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | | namespace DCL.PortableExperiences.Confirmation |
| | 11 | | { |
| | 12 | | public class ExperiencesConfirmationPopupComponentView : BaseComponentView<ExperiencesConfirmationViewModel>, |
| | 13 | | IExperiencesConfirmationPopupView |
| | 14 | | { |
| | 15 | | [Serializable] |
| | 16 | | private struct PermissionContainer |
| | 17 | | { |
| | 18 | | public string permission; |
| | 19 | | public GameObject container; |
| | 20 | | } |
| | 21 | |
|
| | 22 | | [SerializeField] private Button acceptButton; |
| | 23 | | [SerializeField] private Button rejectButton; |
| | 24 | | [SerializeField] private Button[] cancelButtons; |
| | 25 | | [SerializeField] private InputAction_Trigger cancelTrigger; |
| | 26 | | [SerializeField] private GameObject permissionsContainer; |
| | 27 | | [SerializeField] private GameObject descriptionContainer; |
| | 28 | | [SerializeField] private TMP_Text nameLabel; |
| | 29 | | [SerializeField] private TMP_Text descriptionLabel; |
| | 30 | | [SerializeField] private TMP_Text allowButtonLabel; |
| | 31 | | [SerializeField] private TMP_Text rejectButtonLabel; |
| | 32 | | [SerializeField] private Toggle dontAskMeAgainToggle; |
| | 33 | | [SerializeField] private ImageComponentView iconImage; |
| | 34 | | [SerializeField] private Texture2D defaultIconSprite; |
| | 35 | | [SerializeField] private RectTransform root; |
| | 36 | | [SerializeField] private GameObject smartWearableTitle; |
| | 37 | | [SerializeField] private GameObject scenePxTitle; |
| | 38 | | [SerializeField] private List<PermissionContainer> permissionsConfig; |
| | 39 | | [SerializeField] private Button useWeb3ApiInfoButton; |
| | 40 | | [SerializeField] private ShowHideAnimator useWeb3ApiInfoToast; |
| | 41 | |
|
| | 42 | | private Dictionary<string, GameObject> permissionContainers; |
| | 43 | |
|
| | 44 | | public event Action OnAccepted; |
| | 45 | | public event Action OnRejected; |
| | 46 | | public event Action OnCancelled; |
| | 47 | | public event Action OnDontShowAnymore; |
| | 48 | | public event Action OnKeepShowing; |
| | 49 | |
|
| | 50 | | public override void Awake() |
| | 51 | | { |
| 0 | 52 | | base.Awake(); |
| | 53 | |
|
| 0 | 54 | | permissionContainers = permissionsConfig.ToDictionary(container => container.permission, container => contai |
| | 55 | |
|
| 0 | 56 | | acceptButton.onClick.AddListener(() => OnAccepted?.Invoke()); |
| 0 | 57 | | rejectButton.onClick.AddListener(() => OnRejected?.Invoke()); |
| | 58 | |
|
| 0 | 59 | | foreach (Button cancelButton in cancelButtons) |
| 0 | 60 | | cancelButton.onClick.AddListener(() => OnCancelled?.Invoke()); |
| | 61 | |
|
| 0 | 62 | | dontAskMeAgainToggle.onValueChanged.AddListener(arg0 => |
| | 63 | | { |
| 0 | 64 | | if (arg0) |
| 0 | 65 | | OnDontShowAnymore?.Invoke(); |
| | 66 | | else |
| 0 | 67 | | OnKeepShowing?.Invoke(); |
| 0 | 68 | | }); |
| | 69 | |
|
| 0 | 70 | | useWeb3ApiInfoButton.onClick.AddListener(() => |
| | 71 | | { |
| 0 | 72 | | if (useWeb3ApiInfoToast.gameObject.activeSelf) |
| 0 | 73 | | useWeb3ApiInfoToast.Hide(); |
| | 74 | | else |
| | 75 | | { |
| 0 | 76 | | useWeb3ApiInfoToast.gameObject.SetActive(true); |
| 0 | 77 | | useWeb3ApiInfoToast.ShowDelayHide(10f); |
| | 78 | | } |
| 0 | 79 | | }); |
| 0 | 80 | | } |
| | 81 | |
|
| | 82 | | public override void OnEnable() |
| | 83 | | { |
| 0 | 84 | | base.OnEnable(); |
| | 85 | |
|
| 0 | 86 | | cancelTrigger.OnTriggered += OnCancelTriggered; |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | public override void OnDisable() |
| | 90 | | { |
| 0 | 91 | | base.OnDisable(); |
| | 92 | |
|
| 0 | 93 | | cancelTrigger.OnTriggered -= OnCancelTriggered; |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | public override void RefreshControl() |
| | 97 | | { |
| 0 | 98 | | bool isPermissionsEnabled = model.Permissions.Count > 0; |
| 0 | 99 | | bool isDescriptionEnabled = !string.IsNullOrEmpty(model.Description); |
| | 100 | |
|
| 0 | 101 | | permissionsContainer.SetActive(isPermissionsEnabled); |
| 0 | 102 | | descriptionContainer.SetActive(isDescriptionEnabled); |
| | 103 | |
|
| 0 | 104 | | foreach ((string _, GameObject container) in permissionContainers) |
| 0 | 105 | | container.SetActive(false); |
| | 106 | |
|
| 0 | 107 | | foreach (string permission in model.Permissions) |
| 0 | 108 | | permissionContainers[permission].SetActive(true); |
| | 109 | |
|
| 0 | 110 | | descriptionLabel.text = model.Description; |
| 0 | 111 | | nameLabel.text = model.Name; |
| | 112 | |
|
| 0 | 113 | | if (string.IsNullOrEmpty(model.IconUrl)) |
| | 114 | | { |
| 0 | 115 | | iconImage.UseLoadingIndicator = false; |
| 0 | 116 | | iconImage.SetImage(defaultIconSprite); |
| 0 | 117 | | iconImage.ImageComponent.color = new Color(0.08627451f, 0.08235294f, 0.09411765f, 1f); |
| | 118 | | } |
| | 119 | | else |
| | 120 | | { |
| 0 | 121 | | iconImage.UseLoadingIndicator = true; |
| 0 | 122 | | iconImage.SetImage(model.IconUrl); |
| 0 | 123 | | iconImage.ImageComponent.color = Color.white; |
| | 124 | | } |
| | 125 | |
|
| 0 | 126 | | smartWearableTitle.SetActive(model.IsSmartWearable); |
| 0 | 127 | | scenePxTitle.SetActive(!model.IsSmartWearable); |
| | 128 | |
|
| 0 | 129 | | if (model.IsSmartWearable) |
| | 130 | | { |
| 0 | 131 | | allowButtonLabel.text = "ALLOW AND EQUIP"; |
| 0 | 132 | | rejectButtonLabel.text = "DON'T ALLOW\nAND EQUIP"; |
| | 133 | | } |
| | 134 | | else |
| | 135 | | { |
| 0 | 136 | | allowButtonLabel.text = "OK"; |
| 0 | 137 | | rejectButtonLabel.text = "DON'T ALLOW"; |
| | 138 | | } |
| | 139 | |
|
| 0 | 140 | | root.ForceUpdateLayout(); |
| 0 | 141 | | } |
| | 142 | |
|
| | 143 | | public override void Show(bool instant = false) |
| | 144 | | { |
| 0 | 145 | | gameObject.SetActive(true); |
| 0 | 146 | | base.Show(instant); |
| | 147 | |
|
| | 148 | | // let the subscribers know that the default option is 'keep showing' |
| 0 | 149 | | if (dontAskMeAgainToggle.isOn) |
| 0 | 150 | | dontAskMeAgainToggle.isOn = false; |
| | 151 | | else |
| 0 | 152 | | OnKeepShowing?.Invoke(); |
| 0 | 153 | | } |
| | 154 | |
|
| | 155 | | public override void Hide(bool instant = false) |
| | 156 | | { |
| 0 | 157 | | base.Hide(instant); |
| | 158 | |
|
| 0 | 159 | | if (instant) |
| 0 | 160 | | gameObject.SetActive(false); |
| 0 | 161 | | } |
| | 162 | |
|
| | 163 | | private void OnCancelTriggered(DCLAction_Trigger action) => |
| 0 | 164 | | OnCancelled?.Invoke(); |
| | 165 | | } |
| | 166 | | } |