| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Tasks; |
| | 3 | | using System; |
| | 4 | | using System.Threading; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.EventSystems; |
| | 7 | | using UnityEngine.UI; |
| | 8 | |
|
| | 9 | | namespace DCL.MyAccount |
| | 10 | | { |
| | 11 | | public class MyAccountSectionHUDComponentView : BaseComponentView, IMyAccountSectionHUDComponentView |
| | 12 | | { |
| | 13 | | private const float COPY_TOAST_VISIBLE_TIME = 3; |
| | 14 | |
|
| | 15 | | [SerializeField] internal GameObject sectionsMenu; |
| | 16 | | [SerializeField] internal MyProfileComponentView myProfileComponentView; |
| | 17 | | [SerializeField] internal EmailNotificationsComponentView emailNotificationsComponentView; |
| | 18 | | [SerializeField] internal BlockedListComponentView blockedListComponentView; |
| | 19 | | [SerializeField] internal ShowHideAnimator accountSettingsUpdatedToast; |
| | 20 | |
|
| | 21 | | [Header("Sections Menu Configuration")] |
| | 22 | | [SerializeField] internal Button myProfileButton; |
| | 23 | | [SerializeField] internal GameObject myProfileButtonDeselected; |
| | 24 | | [SerializeField] internal Image myProfileButtonDeselectedImage; |
| | 25 | | [SerializeField] internal GameObject myProfileButtonSelected; |
| | 26 | | [SerializeField] internal Image myProfileButtonSelectedImage; |
| | 27 | | [SerializeField] internal Button emailNotificationsButton; |
| | 28 | | [SerializeField] internal GameObject emailNotificationsButtonDeselected; |
| | 29 | | [SerializeField] internal Image emailNotificationsButtonDeselectedImage; |
| | 30 | | [SerializeField] internal GameObject emailNotificationsButtonSelected; |
| | 31 | | [SerializeField] internal Image emailNotificationsButtonSelectedImage; |
| | 32 | |
|
| | 33 | | [SerializeField] internal Button blockedListButton; |
| | 34 | | [SerializeField] internal GameObject blockedListButtonDeselected; |
| | 35 | | [SerializeField] internal Image blockedListButtonDeselectedImage; |
| | 36 | | [SerializeField] internal GameObject blockedListButtonSelected; |
| | 37 | | [SerializeField] internal Image blockedListButtonSelectedImage; |
| | 38 | |
|
| 0 | 39 | | public IMyProfileComponentView CurrentMyProfileView => myProfileComponentView; |
| 0 | 40 | | public IEmailNotificationsComponentView CurrentEmailNotificationsView => emailNotificationsComponentView; |
| 0 | 41 | | public IBlockedListComponentView CurrentBlockedListComponentView => blockedListComponentView; |
| | 42 | |
|
| | 43 | | private Transform thisTransform; |
| 0 | 44 | | private CancellationTokenSource showAccountSettingsCancellationToken = new (); |
| | 45 | |
|
| | 46 | | public override void Awake() |
| | 47 | | { |
| 0 | 48 | | base.Awake(); |
| | 49 | |
|
| 0 | 50 | | thisTransform = transform; |
| | 51 | |
|
| 0 | 52 | | myProfileButton.onClick.AddListener(() => OpenSection(MyAccountSection.MyProfile)); |
| 0 | 53 | | emailNotificationsButton.onClick.AddListener(() => OpenSection(MyAccountSection.EmailNotifications)); |
| 0 | 54 | | blockedListButton.onClick.AddListener(() => OpenSection(MyAccountSection.BlockedList)); |
| | 55 | |
|
| 0 | 56 | | OpenSection(MyAccountSection.MyProfile); |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | public override void Dispose() |
| | 60 | | { |
| 0 | 61 | | base.Dispose(); |
| | 62 | |
|
| 0 | 63 | | showAccountSettingsCancellationToken.SafeCancelAndDispose(); |
| 0 | 64 | | myProfileButton.onClick.RemoveAllListeners(); |
| 0 | 65 | | emailNotificationsButton.onClick.RemoveAllListeners(); |
| 0 | 66 | | } |
| | 67 | |
|
| 0 | 68 | | public override void RefreshControl() { } |
| | 69 | |
|
| | 70 | | public void SetAsFullScreenMenuMode(Transform parentTransform) |
| | 71 | | { |
| 0 | 72 | | if (parentTransform == null) |
| 0 | 73 | | return; |
| | 74 | |
|
| 0 | 75 | | thisTransform.SetParent(parentTransform); |
| 0 | 76 | | thisTransform.localScale = Vector3.one; |
| | 77 | |
|
| 0 | 78 | | RectTransform rectTransform = thisTransform as RectTransform; |
| 0 | 79 | | if (rectTransform == null) return; |
| 0 | 80 | | rectTransform.anchorMin = Vector2.zero; |
| 0 | 81 | | rectTransform.anchorMax = Vector2.one; |
| 0 | 82 | | rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 83 | | rectTransform.localPosition = Vector2.zero; |
| 0 | 84 | | rectTransform.offsetMax = Vector2.zero; |
| 0 | 85 | | rectTransform.offsetMin = Vector2.zero; |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | public void ShowAccountSettingsUpdatedToast() |
| | 89 | | { |
| | 90 | | async UniTaskVoid ShowAccountSettingsUpdatedToastAsync(CancellationToken cancellationToken) |
| | 91 | | { |
| 0 | 92 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 93 | |
|
| 0 | 94 | | if (!accountSettingsUpdatedToast.gameObject.activeSelf) |
| 0 | 95 | | accountSettingsUpdatedToast.gameObject.SetActive(true); |
| | 96 | |
|
| 0 | 97 | | accountSettingsUpdatedToast.Show(); |
| 0 | 98 | | await UniTask.Delay(TimeSpan.FromSeconds(COPY_TOAST_VISIBLE_TIME), cancellationToken: cancellationToken) |
| 0 | 99 | | accountSettingsUpdatedToast.Hide(); |
| 0 | 100 | | } |
| | 101 | |
|
| 0 | 102 | | showAccountSettingsCancellationToken = showAccountSettingsCancellationToken.SafeRestart(); |
| 0 | 103 | | ShowAccountSettingsUpdatedToastAsync(showAccountSettingsCancellationToken.Token).Forget(); |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | public void SetSectionsMenuActive(bool isActive) => |
| 0 | 107 | | sectionsMenu.SetActive(isActive); |
| | 108 | |
|
| | 109 | | private void OpenSection(MyAccountSection section) |
| | 110 | | { |
| 0 | 111 | | DeselectButtons(); |
| | 112 | |
|
| | 113 | | switch (section) |
| | 114 | | { |
| | 115 | | default: |
| | 116 | | case MyAccountSection.MyProfile: |
| 0 | 117 | | SetMyProfileButtonStatus(true); |
| 0 | 118 | | SetEmailNotificationsButtonStatus(false); |
| 0 | 119 | | SetBlockedListButtonStatus(false); |
| 0 | 120 | | myProfileComponentView.Show(); |
| 0 | 121 | | emailNotificationsComponentView.Hide(); |
| 0 | 122 | | blockedListComponentView.Hide(); |
| 0 | 123 | | break; |
| | 124 | | case MyAccountSection.EmailNotifications: |
| 0 | 125 | | SetMyProfileButtonStatus(false); |
| 0 | 126 | | SetEmailNotificationsButtonStatus(true); |
| 0 | 127 | | SetBlockedListButtonStatus(false); |
| 0 | 128 | | myProfileComponentView.Hide(); |
| 0 | 129 | | emailNotificationsComponentView.Show(); |
| 0 | 130 | | blockedListComponentView.Hide(); |
| 0 | 131 | | break; |
| | 132 | | case MyAccountSection.BlockedList: |
| 0 | 133 | | SetMyProfileButtonStatus(false); |
| 0 | 134 | | SetEmailNotificationsButtonStatus(false); |
| 0 | 135 | | SetBlockedListButtonStatus(true); |
| 0 | 136 | | myProfileComponentView.Hide(); |
| 0 | 137 | | emailNotificationsComponentView.Hide(); |
| 0 | 138 | | blockedListComponentView.Show(); |
| | 139 | | break; |
| | 140 | | } |
| | 141 | |
|
| 0 | 142 | | DataStore.i.myAccount.openSection.Set(section.ToString()); |
| 0 | 143 | | } |
| | 144 | |
|
| | 145 | | private void SetMyProfileButtonStatus(bool isSelected) |
| | 146 | | { |
| 0 | 147 | | myProfileButton.targetGraphic = isSelected ? myProfileButtonSelectedImage : myProfileButtonDeselectedImage; |
| 0 | 148 | | myProfileButtonDeselected.SetActive(!isSelected); |
| 0 | 149 | | myProfileButtonSelected.SetActive(isSelected); |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | private void SetEmailNotificationsButtonStatus(bool isSelected) |
| | 153 | | { |
| 0 | 154 | | emailNotificationsButton.targetGraphic = isSelected ? emailNotificationsButtonSelectedImage : emailNotificat |
| 0 | 155 | | emailNotificationsButtonDeselected.SetActive(!isSelected); |
| 0 | 156 | | emailNotificationsButtonSelected.SetActive(isSelected); |
| 0 | 157 | | } |
| | 158 | |
|
| | 159 | | private void SetBlockedListButtonStatus(bool isSelected) |
| | 160 | | { |
| 0 | 161 | | blockedListButton.targetGraphic = isSelected ? blockedListButtonSelectedImage : blockedListButtonDeselectedI |
| 0 | 162 | | blockedListButtonDeselected.SetActive(!isSelected); |
| 0 | 163 | | blockedListButtonSelected.SetActive(isSelected); |
| 0 | 164 | | } |
| | 165 | |
|
| | 166 | | private static void DeselectButtons() |
| | 167 | | { |
| 0 | 168 | | if (EventSystem.current == null) |
| 0 | 169 | | return; |
| | 170 | |
|
| 0 | 171 | | EventSystem.current.SetSelectedGameObject(null); |
| 0 | 172 | | } |
| | 173 | | } |
| | 174 | | } |