| | 1 | | using DCL.Helpers; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UIComponents.CollapsableSortedList; |
| | 6 | | using UIComponents.Scripts.Components; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.EventSystems; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | namespace DCL.MyAccount |
| | 12 | | { |
| | 13 | | public class MyProfileComponentView : BaseComponentView<MyProfileModel>, IMyProfileComponentView, IPointerClickHandl |
| | 14 | | { |
| | 15 | | private const float DISABLED_SECTION_ALPHA = 0.7f; |
| | 16 | | private const string ABOUT_READ_ONLY_CONTAINER_NAME = "AboutReadOnlyContainer"; |
| | 17 | |
|
| | 18 | | [Header("General")] |
| | 19 | | [SerializeField] internal GameObject mainContainer; |
| | 20 | | [SerializeField] internal GameObject loadingContainer; |
| | 21 | | [SerializeField] internal RectTransform contentTransform; |
| | 22 | | [SerializeField] internal GameObject scrollBar; |
| | 23 | |
|
| | 24 | | [Header("Header")] |
| | 25 | | [SerializeField] internal RectTransform headerContainerTransform; |
| | 26 | | [SerializeField] internal CollapsableListToggleButton disclaimerButton; |
| | 27 | |
|
| | 28 | | [Header("Names")] |
| | 29 | | [SerializeField] internal RectTransform namesContainerTransform; |
| | 30 | | [SerializeField] internal GameObject nameTypeSelectorContainer; |
| | 31 | | [SerializeField] internal GameObject nonClaimedNameModeContainer; |
| | 32 | | [SerializeField] internal TMP_InputField nonClaimedNameInputField; |
| | 33 | | [SerializeField] internal GameObject nonClaimedNameEditionLogo; |
| | 34 | | [SerializeField] internal TMP_Text nonClaimedNameAddressHashtag; |
| | 35 | | [SerializeField] internal GameObject claimNameBanner; |
| | 36 | | [SerializeField] internal Button claimNameButton; |
| | 37 | | [SerializeField] internal GameObject claimedNameModeContainer; |
| | 38 | | [SerializeField] internal DropdownComponentView claimedNameDropdown; |
| | 39 | | [SerializeField] internal Button claimedNameGoToNonClaimedNameButton; |
| | 40 | | [SerializeField] internal TMP_Text claimedNameGoToNonClaimedNameButtonText; |
| | 41 | | [SerializeField] internal GameObject claimedNameGoToNonClaimedNameSelectionMark; |
| | 42 | | [SerializeField] internal GameObject claimedNameInputContainer; |
| | 43 | | [SerializeField] internal TMP_InputField claimedNameInputField; |
| | 44 | | [SerializeField] internal GameObject claimedNameEditionLogo; |
| | 45 | | [SerializeField] internal TMP_Text claimedNameAddressHashtag; |
| | 46 | | [SerializeField] internal Button claimedNameBackToClaimedNamesListButton; |
| | 47 | | [SerializeField] internal TMP_Text claimedNameBackToClaimedNamesListButtonText; |
| | 48 | | [SerializeField] internal GameObject claimedNameBackToClaimedNamesListSelectionMark; |
| | 49 | | [SerializeField] internal Button claimedNameUniqueNameButton; |
| | 50 | | [SerializeField] internal GameObject nameValidationsContainer; |
| | 51 | | [SerializeField] internal TMP_Text nameCharCounter; |
| | 52 | | [SerializeField] internal GameObject nonValidNameWarning; |
| | 53 | |
|
| | 54 | | [Header("About")] |
| | 55 | | [SerializeField] internal TMP_InputField aboutInputText; |
| | 56 | | [SerializeField] internal TMP_Text aboutCharCounter; |
| | 57 | | [SerializeField] internal CanvasGroup aboutCanvasGroup; |
| | 58 | | [SerializeField] internal GameObject editableAboutContainer; |
| | 59 | | [SerializeField] internal GameObject readOnlyAboutContainer; |
| | 60 | | [SerializeField] internal TMP_Text readOnlyAboutInputText; |
| | 61 | |
|
| | 62 | | [Header("Links")] |
| | 63 | | [SerializeField] internal RectTransform linksContainerTransform; |
| | 64 | | [SerializeField] internal MyProfileLinkListComponentView linkListView; |
| | 65 | | [SerializeField] internal CanvasGroup linksCanvasGroup; |
| | 66 | |
|
| | 67 | | [Header("Additional Info")] |
| | 68 | | [SerializeField] internal RectTransform additionalInfoContainerTransform; |
| | 69 | | [SerializeField] internal MyProfileAdditionalInfoListComponentView additionalInfoList; |
| | 70 | | [SerializeField] internal CanvasGroup additionalInfoCanvasGroup; |
| | 71 | |
|
| | 72 | | public event Action<string> OnCurrentNameEdited; |
| | 73 | | public event Action<string, bool> OnCurrentNameSubmitted; |
| | 74 | | public event Action OnGoFromClaimedToNonClaimNameClicked; |
| | 75 | | public event Action OnClaimNameClicked; |
| | 76 | | public event Action<string> OnAboutDescriptionSubmitted; |
| | 77 | | public event Action<(string title, string url)> OnLinkAdded; |
| | 78 | | public event Action<(string title, string url)> OnLinkRemoved; |
| | 79 | |
|
| | 80 | | public override void Awake() |
| | 81 | | { |
| 0 | 82 | | base.Awake(); |
| | 83 | |
|
| 0 | 84 | | UpdateNameCharLimit(0, nonClaimedNameInputField.characterLimit); |
| 0 | 85 | | UpdateAboutCharLimit(0, aboutInputText.characterLimit); |
| | 86 | |
|
| 0 | 87 | | nonClaimedNameInputField.onValueChanged.AddListener(newName => |
| | 88 | | { |
| 0 | 89 | | UpdateNameCharLimit(newName.Length, nonClaimedNameInputField.characterLimit); |
| 0 | 90 | | OnCurrentNameEdited?.Invoke(newName); |
| 0 | 91 | | }); |
| 0 | 92 | | nonClaimedNameInputField.onSelect.AddListener(_ => |
| | 93 | | { |
| 0 | 94 | | nonClaimedNameEditionLogo.SetActive(false); |
| 0 | 95 | | nonClaimedNameAddressHashtag.gameObject.SetActive(true); |
| 0 | 96 | | }); |
| 0 | 97 | | nonClaimedNameInputField.onDeselect.AddListener(newName => |
| | 98 | | { |
| 0 | 99 | | nonClaimedNameEditionLogo.SetActive(true); |
| 0 | 100 | | nonClaimedNameAddressHashtag.gameObject.SetActive(false); |
| 0 | 101 | | OnCurrentNameSubmitted?.Invoke(newName, false); |
| 0 | 102 | | }); |
| 0 | 103 | | nonClaimedNameInputField.onSubmit.AddListener(newName => OnCurrentNameSubmitted?.Invoke(newName, false)); |
| 0 | 104 | | claimedNameInputField.onValueChanged.AddListener(newName => |
| | 105 | | { |
| 0 | 106 | | UpdateNameCharLimit(newName.Length, claimedNameInputField.characterLimit); |
| 0 | 107 | | OnCurrentNameEdited?.Invoke(newName); |
| 0 | 108 | | }); |
| 0 | 109 | | claimedNameInputField.onSelect.AddListener(_ => |
| | 110 | | { |
| 0 | 111 | | claimedNameEditionLogo.SetActive(false); |
| 0 | 112 | | claimedNameAddressHashtag.gameObject.SetActive(true); |
| 0 | 113 | | }); |
| 0 | 114 | | claimedNameInputField.onDeselect.AddListener(newName => |
| | 115 | | { |
| 0 | 116 | | claimedNameEditionLogo.SetActive(true); |
| 0 | 117 | | claimedNameAddressHashtag.gameObject.SetActive(false); |
| 0 | 118 | | OnCurrentNameSubmitted?.Invoke(newName, false); |
| 0 | 119 | | }); |
| 0 | 120 | | claimedNameInputField.onSubmit.AddListener(newName => OnCurrentNameSubmitted?.Invoke(newName, false)); |
| 0 | 121 | | claimedNameDropdown.OnOptionSelectionChanged += (isOn, optionId, _) => |
| | 122 | | { |
| 0 | 123 | | if (!isOn) return; |
| 0 | 124 | | OnCurrentNameSubmitted?.Invoke(optionId, true); |
| 0 | 125 | | }; |
| 0 | 126 | | claimNameButton.onClick.AddListener(() => OnClaimNameClicked?.Invoke()); |
| 0 | 127 | | claimedNameGoToNonClaimedNameButton.onClick.AddListener(() => |
| | 128 | | { |
| 0 | 129 | | Utils.ForceRebuildLayoutImmediate(namesContainerTransform); |
| 0 | 130 | | OnGoFromClaimedToNonClaimNameClicked?.Invoke(); |
| 0 | 131 | | }); |
| 0 | 132 | | claimedNameBackToClaimedNamesListButton.onClick.AddListener(() => |
| | 133 | | { |
| 0 | 134 | | Utils.ForceRebuildLayoutImmediate(namesContainerTransform); |
| 0 | 135 | | SetClaimedNameModeAsInput(false); |
| 0 | 136 | | }); |
| 0 | 137 | | claimedNameUniqueNameButton.onClick.AddListener(() => OnClaimNameClicked?.Invoke()); |
| | 138 | |
|
| 0 | 139 | | aboutInputText.onValueChanged.AddListener(newDesc => UpdateAboutCharLimit(newDesc.Length, aboutInputText.cha |
| 0 | 140 | | aboutInputText.onDeselect.AddListener(newDesc => |
| | 141 | | { |
| 0 | 142 | | readOnlyAboutInputText.text = newDesc; |
| 0 | 143 | | readOnlyAboutContainer.SetActive(true); |
| 0 | 144 | | editableAboutContainer.SetActive(false); |
| 0 | 145 | | OnAboutDescriptionSubmitted?.Invoke(newDesc); |
| 0 | 146 | | }); |
| 0 | 147 | | aboutInputText.onSubmit.AddListener(newDesc => OnAboutDescriptionSubmitted?.Invoke(newDesc)); |
| | 148 | |
|
| 0 | 149 | | linkListView.OnAddedNew += tuple => |
| | 150 | | { |
| 0 | 151 | | OnLinkAdded?.Invoke((tuple.title, tuple.url)); |
| 0 | 152 | | Utils.ForceRebuildLayoutImmediate(linksContainerTransform); |
| 0 | 153 | | }; |
| 0 | 154 | | linkListView.OnRemoved += tuple => |
| | 155 | | { |
| 0 | 156 | | OnLinkRemoved?.Invoke((tuple.title, tuple.url)); |
| 0 | 157 | | Utils.ForceRebuildLayoutImmediate(linksContainerTransform); |
| 0 | 158 | | }; |
| | 159 | |
|
| 0 | 160 | | disclaimerButton.OnToggled += _ => Utils.ForceRebuildLayoutImmediate(headerContainerTransform); |
| 0 | 161 | | additionalInfoList.OnAdditionalFieldAdded += () => Utils.ForceRebuildLayoutImmediate(additionalInfoContainer |
| 0 | 162 | | additionalInfoList.OnAdditionalFieldRemoved += () => Utils.ForceRebuildLayoutImmediate(additionalInfoContain |
| 0 | 163 | | } |
| | 164 | |
|
| | 165 | | public override void Show(bool instant = false) |
| | 166 | | { |
| 0 | 167 | | gameObject.SetActive(true); |
| | 168 | |
|
| 0 | 169 | | if (scrollBar != null) |
| 0 | 170 | | scrollBar.SetActive(true); |
| 0 | 171 | | } |
| | 172 | |
|
| | 173 | | public override void Hide(bool instant = false) |
| | 174 | | { |
| 0 | 175 | | gameObject.SetActive(false); |
| | 176 | |
|
| 0 | 177 | | if (scrollBar != null) |
| 0 | 178 | | scrollBar.SetActive(false); |
| 0 | 179 | | } |
| | 180 | |
|
| | 181 | | public void OnPointerClick(PointerEventData eventData) |
| | 182 | | { |
| 0 | 183 | | if (eventData.pointerCurrentRaycast.gameObject.name != ABOUT_READ_ONLY_CONTAINER_NAME) |
| 0 | 184 | | return; |
| | 185 | |
|
| 0 | 186 | | readOnlyAboutContainer.SetActive(false); |
| 0 | 187 | | editableAboutContainer.SetActive(true); |
| 0 | 188 | | aboutInputText.Select(); |
| 0 | 189 | | } |
| | 190 | |
|
| | 191 | | public override void Dispose() |
| | 192 | | { |
| 0 | 193 | | nonClaimedNameInputField.onValueChanged.RemoveAllListeners(); |
| 0 | 194 | | nonClaimedNameInputField.onSelect.RemoveAllListeners(); |
| 0 | 195 | | nonClaimedNameInputField.onDeselect.RemoveAllListeners(); |
| 0 | 196 | | nonClaimedNameInputField.onSubmit.RemoveAllListeners(); |
| 0 | 197 | | claimedNameInputField.onSelect.RemoveAllListeners(); |
| 0 | 198 | | claimedNameInputField.onDeselect.RemoveAllListeners(); |
| 0 | 199 | | claimedNameInputField.onSubmit.RemoveAllListeners(); |
| 0 | 200 | | claimNameButton.onClick.RemoveAllListeners(); |
| 0 | 201 | | claimedNameGoToNonClaimedNameButton.onClick.RemoveAllListeners(); |
| 0 | 202 | | claimedNameBackToClaimedNamesListButton.onClick.RemoveAllListeners(); |
| 0 | 203 | | claimedNameUniqueNameButton.onClick.RemoveAllListeners(); |
| | 204 | |
|
| 0 | 205 | | base.Dispose(); |
| 0 | 206 | | } |
| | 207 | |
|
| | 208 | | public override void RefreshControl() |
| | 209 | | { |
| 0 | 210 | | SetClaimedNameMode(model.IsClaimedMode); |
| 0 | 211 | | SetCurrentName(model.MainName, model.NonClaimedHashtag); |
| 0 | 212 | | SetClaimNameBannerActive(model.ShowClaimBanner); |
| 0 | 213 | | SetClaimedNameModeAsInput(model.ShowInputForClaimedMode); |
| 0 | 214 | | SetClaimedNameDropdownOptions(model.loadedClaimedNames); |
| 0 | 215 | | SetAboutDescription(model.AboutDescription); |
| 0 | 216 | | } |
| | 217 | |
|
| | 218 | | public void SetClaimedNameMode(bool isClaimed) |
| | 219 | | { |
| 0 | 220 | | model.IsClaimedMode = isClaimed; |
| 0 | 221 | | nameTypeSelectorContainer.SetActive(isClaimed); |
| 0 | 222 | | nonClaimedNameModeContainer.SetActive(!isClaimed); |
| 0 | 223 | | claimedNameModeContainer.SetActive(isClaimed); |
| 0 | 224 | | nameValidationsContainer.SetActive(!isClaimed || model.ShowInputForClaimedMode); |
| 0 | 225 | | } |
| | 226 | |
|
| | 227 | | public void SetCurrentName(string newName, string nonClaimedHashtag) |
| | 228 | | { |
| 0 | 229 | | model.MainName = newName; |
| 0 | 230 | | model.NonClaimedHashtag = nonClaimedHashtag; |
| | 231 | |
|
| 0 | 232 | | if (model.IsClaimedMode) |
| | 233 | | { |
| 0 | 234 | | claimedNameDropdown.SelectOption(newName, false); |
| 0 | 235 | | claimedNameDropdown.SetTitle(newName); |
| | 236 | | } |
| | 237 | |
|
| 0 | 238 | | claimedNameInputField.text = newName; |
| 0 | 239 | | claimedNameAddressHashtag.text = $"#{nonClaimedHashtag}"; |
| 0 | 240 | | nonClaimedNameInputField.text = newName; |
| 0 | 241 | | nonClaimedNameAddressHashtag.text = $"#{nonClaimedHashtag}"; |
| 0 | 242 | | } |
| | 243 | |
|
| | 244 | | public void SetClaimNameBannerActive(bool isActive) |
| | 245 | | { |
| 0 | 246 | | model.ShowClaimBanner = isActive; |
| 0 | 247 | | claimNameBanner.SetActive(!model.IsClaimedMode && isActive); |
| 0 | 248 | | } |
| | 249 | |
|
| | 250 | | public void SetClaimedNameModeAsInput(bool isInput, bool cleanInputField = false) |
| | 251 | | { |
| 0 | 252 | | model.ShowInputForClaimedMode = isInput; |
| 0 | 253 | | claimedNameInputContainer.SetActive(isInput); |
| 0 | 254 | | claimedNameDropdown.gameObject.SetActive(!isInput); |
| 0 | 255 | | nameValidationsContainer.SetActive(isInput); |
| 0 | 256 | | nameValidationsContainer.SetActive(!model.IsClaimedMode || isInput); |
| | 257 | |
|
| 0 | 258 | | claimedNameGoToNonClaimedNameSelectionMark.SetActive(isInput); |
| 0 | 259 | | claimedNameBackToClaimedNamesListSelectionMark.SetActive(!isInput); |
| 0 | 260 | | claimedNameGoToNonClaimedNameButtonText.fontStyle = isInput ? FontStyles.Bold : FontStyles.Normal; |
| 0 | 261 | | claimedNameBackToClaimedNamesListButtonText.fontStyle = isInput ? FontStyles.Normal : FontStyles.Bold; |
| | 262 | |
|
| 0 | 263 | | if (cleanInputField) |
| 0 | 264 | | claimedNameInputField.text = string.Empty; |
| | 265 | |
|
| 0 | 266 | | if (isInput) |
| | 267 | | { |
| 0 | 268 | | if (cleanInputField) |
| 0 | 269 | | claimedNameInputField.Select(); |
| | 270 | |
|
| 0 | 271 | | return; |
| | 272 | | } |
| | 273 | |
|
| 0 | 274 | | if (model.loadedClaimedNames.Contains(model.MainName)) |
| | 275 | | { |
| 0 | 276 | | claimedNameDropdown.SelectOption(model.MainName, false); |
| 0 | 277 | | claimedNameDropdown.SetTitle(model.MainName); |
| | 278 | | } |
| | 279 | | else |
| | 280 | | { |
| 0 | 281 | | claimedNameDropdown.SelectOption( |
| | 282 | | model.loadedClaimedNames.Count == 0 ? string.Empty : model.loadedClaimedNames[0], |
| | 283 | | model.loadedClaimedNames.Count != 0); |
| 0 | 284 | | claimedNameDropdown.SetTitle(model.loadedClaimedNames.Count == 0 ? string.Empty : model.loadedClaimedNam |
| | 285 | | } |
| 0 | 286 | | } |
| | 287 | |
|
| | 288 | | public void SetClaimedNameDropdownOptions(List<string> claimedNamesList) |
| | 289 | | { |
| 0 | 290 | | model.loadedClaimedNames.Clear(); |
| 0 | 291 | | model.loadedClaimedNames.AddRange(claimedNamesList); |
| | 292 | |
|
| 0 | 293 | | List<ToggleComponentModel> collectionsToAdd = new (); |
| | 294 | |
|
| 0 | 295 | | foreach (string claimedName in claimedNamesList) |
| | 296 | | { |
| 0 | 297 | | ToggleComponentModel newCollectionModel = new ToggleComponentModel |
| | 298 | | { |
| | 299 | | id = claimedName, |
| | 300 | | text = claimedName, |
| | 301 | | isOn = false, |
| | 302 | | isTextActive = true, |
| | 303 | | changeTextColorOnSelect = true, |
| | 304 | | }; |
| | 305 | |
|
| 0 | 306 | | collectionsToAdd.Add(newCollectionModel); |
| | 307 | | } |
| | 308 | |
|
| 0 | 309 | | if (collectionsToAdd.Count > 0) |
| 0 | 310 | | claimedNameDropdown.SetTitle(collectionsToAdd[0].text); |
| | 311 | |
|
| 0 | 312 | | claimedNameDropdown.SetOptions(collectionsToAdd); |
| 0 | 313 | | } |
| | 314 | |
|
| | 315 | | public void SetAboutDescription(string newDesc) |
| | 316 | | { |
| 0 | 317 | | model.AboutDescription = newDesc; |
| 0 | 318 | | aboutInputText.text = newDesc; |
| 0 | 319 | | readOnlyAboutInputText.text = newDesc; |
| 0 | 320 | | } |
| | 321 | |
|
| | 322 | | public void SetAboutEnabled(bool isEnabled) |
| | 323 | | { |
| 0 | 324 | | aboutCanvasGroup.alpha = isEnabled ? 1f : DISABLED_SECTION_ALPHA; |
| 0 | 325 | | aboutCanvasGroup.interactable = isEnabled; |
| 0 | 326 | | aboutCanvasGroup.blocksRaycasts = isEnabled; |
| 0 | 327 | | } |
| | 328 | |
|
| | 329 | | public void SetLoadingActive(bool isActive) |
| | 330 | | { |
| 0 | 331 | | loadingContainer.SetActive(isActive); |
| 0 | 332 | | mainContainer.SetActive(!isActive); |
| 0 | 333 | | } |
| | 334 | |
|
| | 335 | | public void SetNonValidNameWarningActive(bool isActive) => |
| 0 | 336 | | nonValidNameWarning.SetActive(isActive); |
| | 337 | |
|
| | 338 | | public void SetLinks(List<UserProfileModel.Link> links) |
| | 339 | | { |
| 0 | 340 | | linkListView.Clear(); |
| | 341 | |
|
| 0 | 342 | | foreach (UserProfileModel.Link link in links) |
| 0 | 343 | | linkListView.Add(link.title, link.url); |
| 0 | 344 | | } |
| | 345 | |
|
| | 346 | | public void ClearLinkInput() => |
| 0 | 347 | | linkListView.ClearInput(); |
| | 348 | |
|
| | 349 | | public void EnableOrDisableAddLinksOption(bool isEnabled) => |
| 0 | 350 | | linkListView.EnableOrDisableAddNewLinkOption(isEnabled); |
| | 351 | |
|
| | 352 | | public void SetLinksEnabled(bool isEnabled) |
| | 353 | | { |
| 0 | 354 | | linksCanvasGroup.alpha = isEnabled ? 1f : DISABLED_SECTION_ALPHA; |
| 0 | 355 | | linksCanvasGroup.interactable = isEnabled; |
| 0 | 356 | | linksCanvasGroup.blocksRaycasts = isEnabled; |
| 0 | 357 | | } |
| | 358 | |
|
| | 359 | | public void SetAdditionalInfoOptions(AdditionalInfoOptionsModel additionalInfoOptionsModel) |
| | 360 | | { |
| 0 | 361 | | additionalInfoList.SetOptions(additionalInfoOptionsModel); |
| 0 | 362 | | } |
| | 363 | |
|
| | 364 | | public void SetAdditionalInfoValues(Dictionary<string, (string title, string value)> values) |
| | 365 | | { |
| 0 | 366 | | additionalInfoList.SetValues(values); |
| 0 | 367 | | } |
| | 368 | |
|
| | 369 | | public void SetAdditionalInfoEnabled(bool isEnabled) |
| | 370 | | { |
| 0 | 371 | | additionalInfoCanvasGroup.alpha = isEnabled ? 1f : DISABLED_SECTION_ALPHA; |
| 0 | 372 | | additionalInfoCanvasGroup.interactable = isEnabled; |
| 0 | 373 | | additionalInfoCanvasGroup.blocksRaycasts = isEnabled; |
| 0 | 374 | | } |
| | 375 | |
|
| | 376 | | public void RefreshContentLayout() => |
| 0 | 377 | | Utils.ForceRebuildLayoutImmediate(contentTransform); |
| | 378 | |
|
| | 379 | | private void UpdateNameCharLimit(int currentLenght, int maxLength) => |
| 0 | 380 | | nameCharCounter.text = $"{currentLenght}/{maxLength}"; |
| | 381 | |
|
| | 382 | | private void UpdateAboutCharLimit(int currentLenght, int maxLength) => |
| 0 | 383 | | aboutCharCounter.text = $"{currentLenght}/{maxLength}"; |
| | 384 | | } |
| | 385 | | } |