| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Collections; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Runtime.CompilerServices; |
| | 7 | | using TMPro; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.EventSystems; |
| | 10 | | using UnityEngine.UI; |
| | 11 | | using static WearableCollectionsAPIData; |
| | 12 | |
|
| | 13 | | [assembly: InternalsVisibleTo("AvatarEditorHUDTests")] |
| | 14 | |
|
| | 15 | | public class AvatarEditorHUDView : MonoBehaviour, IPointerDownHandler |
| | 16 | | { |
| 1 | 17 | | private static readonly int RANDOMIZE_ANIMATOR_LOADING_BOOL = Animator.StringToHash("Loading"); |
| | 18 | | private const string VIEW_PATH = "AvatarEditorHUD"; |
| | 19 | | private const string VIEW_OBJECT_NAME = "_AvatarEditorHUD"; |
| | 20 | | internal const int AVATAR_SECTION_INDEX = 0; |
| | 21 | | internal const string AVATAR_SECTION_TITLE = "Avatar"; |
| | 22 | | internal const int EMOTES_SECTION_INDEX = 1; |
| | 23 | | internal const string EMOTES_SECTION_TITLE = "Emotes"; |
| | 24 | | private const string RESET_PREVIEW_ANIMATION = "Idle"; |
| | 25 | | private const float TIME_TO_RESET_PREVIEW_ANIMATION = 0.2f; |
| | 26 | |
|
| 0 | 27 | | public bool isOpen { get; private set; } |
| 0 | 28 | | internal DataStore_EmotesCustomization emotesCustomizationDataStore => DataStore.i.emotesCustomization; |
| | 29 | |
|
| | 30 | | internal bool arePanelsInitialized = false; |
| | 31 | |
|
| | 32 | | [Serializable] |
| | 33 | | public class AvatarEditorNavigationInfo |
| | 34 | | { |
| | 35 | | public Toggle toggle; |
| | 36 | | public Canvas canvas; |
| | 37 | | public bool enabledByDefault; |
| | 38 | | public CharacterPreviewController.CameraFocus focus = CharacterPreviewController.CameraFocus.DefaultEditing; |
| | 39 | |
|
| | 40 | | //To remove when we refactor this to avoid ToggleGroup issues when quitting application |
| 1880 | 41 | | public void Initialize() { Application.quitting += () => toggle.onValueChanged.RemoveAllListeners(); } |
| | 42 | | } |
| | 43 | |
|
| | 44 | | [Serializable] |
| | 45 | | public class AvatarEditorWearableFilter |
| | 46 | | { |
| | 47 | | public string categoryFilter; |
| | 48 | | public ItemSelector selector; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | [SerializeField] |
| | 52 | | internal Canvas avatarEditorCanvas; |
| | 53 | |
|
| | 54 | | [SerializeField] |
| | 55 | | internal CanvasGroup avatarEditorCanvasGroup; |
| | 56 | |
|
| | 57 | | [SerializeField] |
| | 58 | | internal AvatarEditorNavigationInfo[] navigationInfos; |
| | 59 | |
|
| | 60 | | [SerializeField] |
| | 61 | | internal AvatarEditorWearableFilter[] wearableGridPairs; |
| | 62 | |
|
| | 63 | | [SerializeField] |
| | 64 | | internal AvatarEditorNavigationInfo collectiblesNavigationInfo; |
| | 65 | |
|
| | 66 | | [SerializeField] |
| | 67 | | internal ItemSelector collectiblesItemSelector; |
| | 68 | |
|
| | 69 | | [SerializeField] |
| | 70 | | internal ColorSelector skinColorSelector; |
| | 71 | |
|
| | 72 | | [SerializeField] |
| | 73 | | internal ColorPickerComponentView eyeColorPickerComponent; |
| | 74 | |
|
| | 75 | | [SerializeField] |
| | 76 | | internal ColorPickerComponentView hairColorPickerComponent; |
| | 77 | |
|
| | 78 | | [SerializeField] |
| | 79 | | internal ColorPickerComponentView facialHairColorPickerComponent; |
| | 80 | |
|
| | 81 | | [SerializeField] |
| | 82 | | internal ColorPickerComponentView eyeBrowsColorPickerComponent; |
| | 83 | |
|
| | 84 | | [SerializeField] |
| | 85 | | internal GameObject characterPreviewPrefab; |
| | 86 | |
|
| | 87 | | [SerializeField] |
| | 88 | | internal PreviewCameraRotation characterPreviewRotation; |
| | 89 | |
|
| | 90 | | [SerializeField] |
| | 91 | | internal Button randomizeButton; |
| | 92 | |
|
| | 93 | | [SerializeField] |
| | 94 | | internal Animator randomizeAnimator; |
| | 95 | |
|
| | 96 | | [SerializeField] |
| | 97 | | internal Button doneButton; |
| | 98 | |
|
| | 99 | | [SerializeField] internal Button[] goToMarketplaceButtons; |
| | 100 | |
|
| | 101 | | [SerializeField] internal GameObject loadingSpinnerGameObject; |
| | 102 | |
|
| | 103 | | [Header("Collectibles")] |
| | 104 | | [SerializeField] |
| | 105 | | internal GameObject web3Container; |
| | 106 | |
|
| | 107 | | [SerializeField] |
| | 108 | | internal GameObject noWeb3Container; |
| | 109 | |
|
| | 110 | | [Header("Skins")] |
| | 111 | |
|
| | 112 | | [SerializeField] internal GameObject skinsFeatureContainer; |
| | 113 | |
|
| | 114 | | [SerializeField] internal GameObject skinsWeb3Container; |
| | 115 | |
|
| | 116 | | [SerializeField] internal GameObject skinsMissingWeb3Container; |
| | 117 | |
|
| | 118 | | [SerializeField] internal GameObject skinsConnectWalletButtonContainer; |
| | 119 | |
|
| | 120 | | [SerializeField] private GameObject skinsPopulatedListContainer; |
| | 121 | | [SerializeField] private GameObject skinsEmptyListContainer; |
| | 122 | |
|
| | 123 | | [SerializeField] |
| | 124 | | internal DropdownComponentView collectionsDropdown; |
| | 125 | |
|
| | 126 | | [Header("Section Selector")] |
| | 127 | | [SerializeField] internal SectionSelectorComponentView sectionSelector; |
| | 128 | | [SerializeField] internal TMP_Text sectionTitle; |
| | 129 | | [SerializeField] internal GameObject avatarSection; |
| | 130 | | [SerializeField] internal GameObject emotesSection; |
| | 131 | |
|
| | 132 | | [SerializeField] internal UIHelper_ClickBlocker clickBlocker; |
| | 133 | | [SerializeField] internal Notification noItemInCollectionWarning; |
| | 134 | |
|
| | 135 | | private static CharacterPreviewController characterPreviewController; |
| | 136 | | private AvatarEditorHUDController controller; |
| 50 | 137 | | internal readonly Dictionary<string, ItemSelector> selectorsByCategory = new Dictionary<string, ItemSelector>(); |
| 50 | 138 | | private readonly HashSet<WearableItem> wearablesWithLoadingSpinner = new HashSet<WearableItem>(); |
| 50 | 139 | | private readonly Dictionary<string, ToggleComponentModel> loadedCollectionModels = new Dictionary<string, ToggleComp |
| | 140 | | private bool isAvatarDirty; |
| | 141 | | private AvatarModel avatarModelToUpdate; |
| | 142 | | private bool updateAvatarShouldSkipAudio; |
| | 143 | |
|
| | 144 | | public event Action<AvatarModel> OnAvatarAppear; |
| | 145 | | public event Action<bool> OnSetVisibility; |
| | 146 | | public event Action OnRandomize; |
| | 147 | |
|
| | 148 | | private void Awake() |
| | 149 | | { |
| 48 | 150 | | loadingSpinnerGameObject.SetActive(false); |
| 48 | 151 | | doneButton.interactable = false; //the default state of the button should be disable until a profile has been lo |
| 48 | 152 | | if (characterPreviewController == null) |
| | 153 | | { |
| 48 | 154 | | characterPreviewController = Instantiate(characterPreviewPrefab).GetComponent<CharacterPreviewController>(); |
| 48 | 155 | | characterPreviewController.name = "_CharacterPreviewController"; |
| | 156 | | } |
| | 157 | |
|
| 48 | 158 | | isOpen = false; |
| 48 | 159 | | arePanelsInitialized = false; |
| 48 | 160 | | } |
| | 161 | |
|
| | 162 | | private void Initialize(AvatarEditorHUDController controller) |
| | 163 | | { |
| 48 | 164 | | this.controller = controller; |
| 48 | 165 | | gameObject.name = VIEW_OBJECT_NAME; |
| | 166 | |
|
| 48 | 167 | | randomizeButton.onClick.AddListener(OnRandomizeButton); |
| 48 | 168 | | doneButton.onClick.AddListener(OnDoneButton); |
| 48 | 169 | | InitializeWearableChangeEvents(); |
| | 170 | |
|
| 576 | 171 | | foreach (var button in goToMarketplaceButtons) |
| 240 | 172 | | button.onClick.RemoveAllListeners(); |
| 576 | 173 | | foreach (var button in goToMarketplaceButtons) |
| 240 | 174 | | button.onClick.AddListener(controller.GoToMarketplaceOrConnectWallet); |
| | 175 | |
|
| 48 | 176 | | characterPreviewController.camera.enabled = false; |
| | 177 | |
|
| 48 | 178 | | collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection; |
| 48 | 179 | | collectionsDropdown.OnOptionSelectionChanged += controller.ToggleThirdPartyCollection; |
| | 180 | |
|
| 48 | 181 | | clickBlocker.OnClicked += ClickBlockerClicked; |
| | 182 | |
|
| 48 | 183 | | ConfigureSectionSelector(); |
| 48 | 184 | | } |
| | 185 | |
|
| | 186 | | private void Update() |
| | 187 | | { |
| 1 | 188 | | UpdateAvatarModelWhenNeeded(); |
| 1 | 189 | | } |
| | 190 | |
|
| | 191 | | public void SetIsWeb3(bool isWeb3User) |
| | 192 | | { |
| 103 | 193 | | web3Container.SetActive(isWeb3User); |
| 103 | 194 | | noWeb3Container.SetActive(!isWeb3User); |
| 103 | 195 | | skinsWeb3Container.SetActive(isWeb3User); |
| 103 | 196 | | skinsMissingWeb3Container.SetActive(!isWeb3User); |
| 103 | 197 | | } |
| | 198 | |
|
| | 199 | | internal void InitializeNavigationEvents(bool isGuest) |
| | 200 | | { |
| 103 | 201 | | if (arePanelsInitialized) |
| 56 | 202 | | return; |
| | 203 | |
|
| 1880 | 204 | | for (int i = 0; i < navigationInfos.Length; i++) |
| | 205 | | { |
| 893 | 206 | | InitializeNavigationInfo(navigationInfos[i]); |
| | 207 | | } |
| 47 | 208 | | InitializeNavigationInfo(collectiblesNavigationInfo, !isGuest); |
| | 209 | |
|
| 47 | 210 | | characterPreviewRotation.OnHorizontalRotation += characterPreviewController.Rotate; |
| 47 | 211 | | arePanelsInitialized = true; |
| 47 | 212 | | } |
| | 213 | |
|
| | 214 | | private void InitializeNavigationInfo(AvatarEditorNavigationInfo current, bool isActive) |
| | 215 | | { |
| 940 | 216 | | current.Initialize(); |
| | 217 | |
|
| 940 | 218 | | current.toggle.isOn = isActive ? current.enabledByDefault : false; |
| 940 | 219 | | current.canvas.gameObject.SetActive(isActive ? current.enabledByDefault : false); |
| | 220 | |
|
| 940 | 221 | | current.toggle.onValueChanged.AddListener((on) => |
| | 222 | | { |
| 47 | 223 | | current.canvas.gameObject.SetActive(@on); |
| 47 | 224 | | characterPreviewController.SetFocus(current.focus); |
| 47 | 225 | | }); |
| 940 | 226 | | } |
| | 227 | |
|
| | 228 | | private void InitializeNavigationInfo(AvatarEditorNavigationInfo current) |
| | 229 | | { |
| 893 | 230 | | InitializeNavigationInfo(current, true); |
| 893 | 231 | | } |
| | 232 | |
|
| | 233 | | private void InitializeWearableChangeEvents() |
| | 234 | | { |
| 48 | 235 | | int nPairs = wearableGridPairs.Length; |
| 1728 | 236 | | for (int i = 0; i < nPairs; i++) |
| | 237 | | { |
| 816 | 238 | | wearableGridPairs[i].selector.OnItemClicked += controller.WearableClicked; |
| 816 | 239 | | wearableGridPairs[i].selector.OnSellClicked += controller.SellCollectible; |
| 816 | 240 | | selectorsByCategory.Add(wearableGridPairs[i].categoryFilter, wearableGridPairs[i].selector); |
| | 241 | | } |
| | 242 | |
|
| 48 | 243 | | collectiblesItemSelector.OnItemClicked += controller.WearableClicked; |
| 48 | 244 | | collectiblesItemSelector.OnSellClicked += controller.SellCollectible; |
| 48 | 245 | | collectiblesItemSelector.OnRetryClicked += controller.RetryLoadOwnedWearables; |
| | 246 | |
|
| 48 | 247 | | skinColorSelector.OnColorSelectorChange += controller.SkinColorClicked; |
| 48 | 248 | | eyeColorPickerComponent.OnColorChanged += controller.EyesColorClicked; |
| 48 | 249 | | hairColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 250 | | facialHairColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 251 | | eyeBrowsColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 252 | | } |
| | 253 | |
|
| | 254 | | internal static AvatarEditorHUDView Create(AvatarEditorHUDController controller) |
| | 255 | | { |
| 48 | 256 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<AvatarEditorHUDView>(); |
| 48 | 257 | | view.Initialize(controller); |
| 48 | 258 | | return view; |
| | 259 | | } |
| | 260 | |
|
| | 261 | | public void UpdateSelectedBody(WearableItem bodyShape) |
| | 262 | | { |
| 1908 | 263 | | for (int i = 0; i < wearableGridPairs.Length; i++) |
| | 264 | | { |
| 901 | 265 | | if (wearableGridPairs[i].categoryFilter == WearableLiterals.Categories.BODY_SHAPE) |
| | 266 | | { |
| 53 | 267 | | wearableGridPairs[i].selector.UnselectAll(); |
| 53 | 268 | | wearableGridPairs[i].selector.Select(bodyShape.id); |
| 53 | 269 | | } |
| | 270 | | else |
| | 271 | | { |
| 848 | 272 | | wearableGridPairs[i].selector.SetBodyShape(bodyShape.id); |
| | 273 | | } |
| | 274 | | } |
| | 275 | |
|
| 53 | 276 | | collectiblesItemSelector.SetBodyShape(bodyShape.id); |
| 53 | 277 | | } |
| | 278 | |
|
| | 279 | | public void EquipWearable(WearableItem wearable) |
| | 280 | | { |
| 1027 | 281 | | selectorsByCategory[wearable.data.category].Select(wearable.id); |
| 1027 | 282 | | SetWearableLoadingSpinner(wearable, true); |
| 1027 | 283 | | collectiblesItemSelector.Select(wearable.id); |
| 1027 | 284 | | } |
| | 285 | |
|
| | 286 | | public void UnequipWearable(WearableItem wearable) |
| | 287 | | { |
| 464 | 288 | | selectorsByCategory[wearable.data.category].Unselect(wearable.id); |
| 464 | 289 | | SetWearableLoadingSpinner(wearable, false); |
| 464 | 290 | | collectiblesItemSelector.Unselect(wearable.id); |
| 464 | 291 | | } |
| | 292 | |
|
| | 293 | | internal void SetWearableLoadingSpinner(WearableItem wearable, bool isActive) |
| | 294 | | { |
| 1491 | 295 | | selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, isActive); |
| 1491 | 296 | | collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, isActive); |
| 1491 | 297 | | if (isActive) |
| 1027 | 298 | | wearablesWithLoadingSpinner.Add(wearable); |
| | 299 | | else |
| 464 | 300 | | wearablesWithLoadingSpinner.Remove(wearable); |
| 464 | 301 | | } |
| | 302 | |
|
| | 303 | | internal void ClearWearablesLoadingSpinner() |
| | 304 | | { |
| 0 | 305 | | foreach (WearableItem wearable in wearablesWithLoadingSpinner) |
| | 306 | | { |
| 0 | 307 | | selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, false); |
| 0 | 308 | | collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, false); |
| | 309 | | } |
| | 310 | |
|
| 0 | 311 | | wearablesWithLoadingSpinner.Clear(); |
| 0 | 312 | | } |
| | 313 | |
|
| | 314 | | public void SelectHairColor(Color hairColor) |
| | 315 | | { |
| 108 | 316 | | hairColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 317 | | hairColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 318 | | eyeBrowsColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 319 | | eyeBrowsColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 320 | | facialHairColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 321 | | facialHairColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 322 | | } |
| | 323 | |
|
| | 324 | | public Color GetRandomColor() |
| | 325 | | { |
| 2 | 326 | | return Color.HSVToRGB(UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range |
| | 327 | | } |
| | 328 | |
|
| | 329 | | public void SelectSkinColor(Color skinColor) |
| | 330 | | { |
| 107 | 331 | | skinColorSelector.Select(skinColor); |
| 107 | 332 | | } |
| | 333 | |
|
| | 334 | | public void SelectEyeColor(Color eyesColor) |
| | 335 | | { |
| 108 | 336 | | eyeColorPickerComponent.SetColorSelector(eyesColor); |
| 108 | 337 | | eyeColorPickerComponent.UpdateSliderValues(eyesColor); |
| 108 | 338 | | } |
| | 339 | |
|
| | 340 | | public void SetColors(List<Color> skinColors, List<Color> hairColors, List<Color> eyeColors) |
| | 341 | | { |
| 48 | 342 | | skinColorSelector.Populate(skinColors); |
| 48 | 343 | | eyeColorPickerComponent.SetColorList(eyeColors); |
| 48 | 344 | | hairColorPickerComponent.SetColorList(hairColors); |
| 48 | 345 | | eyeBrowsColorPickerComponent.SetColorList(hairColors); |
| 48 | 346 | | facialHairColorPickerComponent.SetColorList(hairColors); |
| 48 | 347 | | } |
| | 348 | |
|
| | 349 | | public void UnselectAllWearables() |
| | 350 | | { |
| 3744 | 351 | | for (int i = 0; i < wearableGridPairs.Length; i++) |
| | 352 | | { |
| 1768 | 353 | | if (wearableGridPairs[i].categoryFilter != WearableLiterals.Categories.BODY_SHAPE) |
| | 354 | | { |
| 1664 | 355 | | wearableGridPairs[i].selector.UnselectAll(); |
| | 356 | | } |
| | 357 | | } |
| | 358 | |
|
| 104 | 359 | | collectiblesItemSelector.UnselectAll(); |
| 104 | 360 | | } |
| | 361 | |
|
| | 362 | | public void UpdateAvatarPreview(AvatarModel avatarModel, bool skipAudio) |
| | 363 | | { |
| 125 | 364 | | if (avatarModel?.wearables == null) |
| 0 | 365 | | return; |
| | 366 | |
|
| | 367 | | // We delay the updating of the avatar 1 frame to disengage from the kernel message flow |
| | 368 | | // otherwise the cancellation of the updating task throws an exception that is catch by |
| | 369 | | // kernel setthrew method, which floods the analytics. |
| | 370 | | // Also it updates just once if its called many times in a row |
| 125 | 371 | | isAvatarDirty = true; |
| 125 | 372 | | avatarModelToUpdate = avatarModel; |
| 125 | 373 | | updateAvatarShouldSkipAudio = skipAudio; |
| | 374 | |
|
| 125 | 375 | | doneButton.interactable = false; |
| 125 | 376 | | loadingSpinnerGameObject.SetActive(true); |
| 125 | 377 | | } |
| | 378 | |
|
| | 379 | | public void AddWearable(WearableItem wearableItem, int amount, |
| | 380 | | Func<WearableItem, bool> hideOtherWearablesToastStrategy, |
| | 381 | | Func<WearableItem, bool> replaceOtherWearablesToastStrategy) |
| | 382 | | { |
| 4221 | 383 | | if (wearableItem == null) |
| 0 | 384 | | return; |
| | 385 | |
|
| 4221 | 386 | | if (!selectorsByCategory.ContainsKey(wearableItem.data.category)) |
| | 387 | | { |
| 0 | 388 | | Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} "); |
| 0 | 389 | | return; |
| | 390 | | } |
| | 391 | |
|
| 4221 | 392 | | string collectionName = GetWearableCollectionName(wearableItem); |
| | 393 | |
|
| 4221 | 394 | | selectorsByCategory[wearableItem.data.category].AddItemToggle( |
| | 395 | | wearableItem, |
| | 396 | | collectionName, |
| | 397 | | amount, |
| | 398 | | hideOtherWearablesToastStrategy, |
| | 399 | | replaceOtherWearablesToastStrategy); |
| | 400 | |
|
| 4221 | 401 | | if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection) |
| | 402 | | { |
| 21 | 403 | | collectiblesItemSelector.AddItemToggle( |
| | 404 | | wearableItem, |
| | 405 | | collectionName, |
| | 406 | | amount, |
| | 407 | | hideOtherWearablesToastStrategy, |
| | 408 | | replaceOtherWearablesToastStrategy); |
| | 409 | | } |
| 4221 | 410 | | } |
| | 411 | |
|
| | 412 | | public void RefreshSelectorsSize() |
| | 413 | | { |
| 151 | 414 | | using (var iterator = selectorsByCategory.GetEnumerator()) |
| | 415 | | { |
| 2718 | 416 | | while (iterator.MoveNext()) |
| | 417 | | { |
| 2567 | 418 | | iterator.Current.Value.UpdateSelectorLayout(); |
| | 419 | | } |
| 151 | 420 | | } |
| | 421 | |
|
| 151 | 422 | | collectiblesItemSelector.UpdateSelectorLayout(); |
| 151 | 423 | | } |
| | 424 | |
|
| | 425 | | private string GetWearableCollectionName(WearableItem wearableItem) |
| | 426 | | { |
| 4221 | 427 | | string collectionName = string.Empty; |
| | 428 | |
|
| 4221 | 429 | | if (wearableItem.IsFromThirdPartyCollection) |
| | 430 | | { |
| 0 | 431 | | loadedCollectionModels.TryGetValue(wearableItem.ThirdPartyCollectionId, out ToggleComponentModel collectionM |
| | 432 | |
|
| 0 | 433 | | if (collectionModel != null) |
| 0 | 434 | | collectionName = collectionModel.text; |
| | 435 | | } |
| | 436 | |
|
| 4221 | 437 | | return collectionName; |
| | 438 | | } |
| | 439 | |
|
| | 440 | | public void RemoveWearable(WearableItem wearableItem) |
| | 441 | | { |
| 0 | 442 | | if (wearableItem == null) |
| 0 | 443 | | return; |
| | 444 | |
|
| 0 | 445 | | if (!selectorsByCategory.ContainsKey(wearableItem.data.category)) |
| | 446 | | { |
| 0 | 447 | | Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} "); |
| 0 | 448 | | return; |
| | 449 | | } |
| | 450 | |
|
| 0 | 451 | | selectorsByCategory[wearableItem.data.category].RemoveItemToggle(wearableItem.id); |
| 0 | 452 | | if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection) |
| 0 | 453 | | collectiblesItemSelector.RemoveItemToggle(wearableItem.id); |
| 0 | 454 | | } |
| | 455 | |
|
| | 456 | | public void RemoveAllWearables() |
| | 457 | | { |
| 151 | 458 | | using (var enumerator = selectorsByCategory.GetEnumerator()) |
| | 459 | | { |
| 2718 | 460 | | while (enumerator.MoveNext()) |
| | 461 | | { |
| 2567 | 462 | | enumerator.Current.Value.RemoveAllItemToggle(); |
| | 463 | | } |
| 151 | 464 | | } |
| | 465 | |
|
| 151 | 466 | | collectiblesItemSelector.RemoveAllItemToggle(); |
| 151 | 467 | | } |
| | 468 | |
|
| | 469 | | private void OnRandomizeButton() |
| | 470 | | { |
| 0 | 471 | | OnRandomize?.Invoke(); |
| 0 | 472 | | controller.RandomizeWearables(); |
| 0 | 473 | | randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, true); |
| 0 | 474 | | } |
| | 475 | |
|
| | 476 | | private void OnDoneButton() |
| | 477 | | { |
| 0 | 478 | | doneButton.interactable = false; |
| 0 | 479 | | CoroutineStarter.Start(TakeSnapshotsAfterStopPreviewAnimation()); |
| 0 | 480 | | eyeColorPickerComponent.SetActive(false); |
| 0 | 481 | | hairColorPickerComponent.SetActive(false); |
| 0 | 482 | | facialHairColorPickerComponent.SetActive(false); |
| 0 | 483 | | eyeBrowsColorPickerComponent.SetActive(false); |
| 0 | 484 | | } |
| | 485 | |
|
| | 486 | | private IEnumerator TakeSnapshotsAfterStopPreviewAnimation() |
| | 487 | | { |
| | 488 | | // We need to stop the current preview animation in order to take a correct snapshot |
| 0 | 489 | | ResetPreviewEmote(); |
| 0 | 490 | | yield return new WaitForSeconds(TIME_TO_RESET_PREVIEW_ANIMATION); |
| 0 | 491 | | characterPreviewController.TakeSnapshots(OnSnapshotsReady, OnSnapshotsFailed); |
| 0 | 492 | | } |
| | 493 | |
|
| | 494 | | private void OnSnapshotsReady(Texture2D face256, Texture2D body) |
| | 495 | | { |
| 0 | 496 | | doneButton.interactable = true; |
| 0 | 497 | | controller.SaveAvatar(face256, body); |
| 0 | 498 | | } |
| | 499 | |
|
| 0 | 500 | | private void OnSnapshotsFailed() { doneButton.interactable = true; } |
| | 501 | |
|
| | 502 | | public void SetVisibility(bool visible) |
| | 503 | | { |
| 92 | 504 | | characterPreviewController.camera.enabled = visible; |
| 92 | 505 | | avatarEditorCanvas.enabled = visible; |
| 92 | 506 | | avatarEditorCanvasGroup.blocksRaycasts = visible; |
| | 507 | |
|
| 92 | 508 | | if (visible && !isOpen) |
| | 509 | | { |
| 43 | 510 | | OnSetVisibility?.Invoke(visible); |
| 0 | 511 | | } |
| 49 | 512 | | else if (!visible && isOpen) |
| | 513 | | { |
| 1 | 514 | | collectionsDropdown.Close(); |
| 1 | 515 | | noItemInCollectionWarning.Dismiss(true); |
| 1 | 516 | | OnSetVisibility?.Invoke(visible); |
| | 517 | | } |
| | 518 | |
|
| 92 | 519 | | isOpen = visible; |
| 92 | 520 | | } |
| | 521 | |
|
| | 522 | | public void CleanUp() |
| | 523 | | { |
| 48 | 524 | | loadingSpinnerGameObject = null; |
| 48 | 525 | | randomizeAnimator = null; |
| 48 | 526 | | if (wearableGridPairs != null) |
| | 527 | | { |
| 48 | 528 | | int nPairs = wearableGridPairs.Length; |
| 1728 | 529 | | for (int i = 0; i < nPairs; i++) |
| | 530 | | { |
| 816 | 531 | | var itemSelector = wearableGridPairs[i].selector; |
| 816 | 532 | | if (itemSelector != null) |
| | 533 | | { |
| 816 | 534 | | itemSelector.OnItemClicked -= controller.WearableClicked; |
| 816 | 535 | | itemSelector.OnSellClicked -= controller.SellCollectible; |
| | 536 | | } |
| | 537 | | } |
| | 538 | | } |
| | 539 | |
|
| 48 | 540 | | if (collectiblesItemSelector != null) |
| | 541 | | { |
| 48 | 542 | | collectiblesItemSelector.OnItemClicked -= controller.WearableClicked; |
| 48 | 543 | | collectiblesItemSelector.OnSellClicked -= controller.SellCollectible; |
| 48 | 544 | | collectiblesItemSelector.OnRetryClicked -= controller.RetryLoadOwnedWearables; |
| | 545 | | } |
| | 546 | |
|
| 48 | 547 | | if (skinColorSelector != null) |
| 48 | 548 | | skinColorSelector.OnColorSelectorChange -= controller.SkinColorClicked; |
| 48 | 549 | | if (eyeColorPickerComponent != null) |
| 48 | 550 | | eyeColorPickerComponent.OnColorChanged -= controller.EyesColorClicked; |
| 48 | 551 | | if (hairColorPickerComponent != null) |
| 48 | 552 | | hairColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| 48 | 553 | | if (facialHairColorPickerComponent != null) |
| 48 | 554 | | facialHairColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| 48 | 555 | | if (eyeBrowsColorPickerComponent != null) |
| 48 | 556 | | eyeBrowsColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| | 557 | |
|
| 48 | 558 | | if (this != null) |
| 48 | 559 | | Destroy(gameObject); |
| | 560 | |
|
| 48 | 561 | | if (characterPreviewController != null) |
| | 562 | | { |
| 48 | 563 | | Destroy(characterPreviewController.gameObject); |
| 48 | 564 | | characterPreviewController = null; |
| | 565 | | } |
| | 566 | |
|
| 48 | 567 | | collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection; |
| 48 | 568 | | collectionsDropdown.Dispose(); |
| | 569 | |
|
| 48 | 570 | | sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| 48 | 571 | | sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| | 572 | |
|
| 48 | 573 | | clickBlocker.OnClicked -= ClickBlockerClicked; |
| 48 | 574 | | } |
| | 575 | |
|
| 0 | 576 | | public void ShowCollectiblesLoadingSpinner(bool isActive) { collectiblesItemSelector.ShowLoading(isActive); } |
| | 577 | |
|
| 0 | 578 | | public void ShowCollectiblesLoadingRetry(bool isActive) { collectiblesItemSelector.ShowRetryLoading(isActive); } |
| | 579 | |
|
| | 580 | | public void SetAsFullScreenMenuMode(Transform parentTransform) |
| | 581 | | { |
| 48 | 582 | | if (parentTransform == null) |
| 48 | 583 | | return; |
| | 584 | |
|
| 0 | 585 | | transform.SetParent(parentTransform); |
| 0 | 586 | | transform.localScale = Vector3.one; |
| | 587 | |
|
| 0 | 588 | | RectTransform rectTransform = transform as RectTransform; |
| 0 | 589 | | rectTransform.anchorMin = Vector2.zero; |
| 0 | 590 | | rectTransform.anchorMax = Vector2.one; |
| 0 | 591 | | rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 592 | | rectTransform.localPosition = Vector2.zero; |
| 0 | 593 | | rectTransform.offsetMax = Vector2.zero; |
| 0 | 594 | | rectTransform.offsetMin = Vector2.zero; |
| 0 | 595 | | } |
| | 596 | |
|
| | 597 | | public void OnPointerDown(PointerEventData eventData) |
| | 598 | | { |
| 0 | 599 | | if (eventData.pointerPressRaycast.gameObject != eyeColorPickerComponent.gameObject && |
| | 600 | | eventData.pointerPressRaycast.gameObject != hairColorPickerComponent.gameObject && |
| | 601 | | eventData.pointerPressRaycast.gameObject != eyeBrowsColorPickerComponent.gameObject && |
| | 602 | | eventData.pointerPressRaycast.gameObject != facialHairColorPickerComponent.gameObject) |
| | 603 | | { |
| 0 | 604 | | eyeColorPickerComponent.SetActive(false); |
| 0 | 605 | | hairColorPickerComponent.SetActive(false); |
| 0 | 606 | | eyeBrowsColorPickerComponent.SetActive(false); |
| 0 | 607 | | facialHairColorPickerComponent.SetActive(false); |
| | 608 | | } |
| 0 | 609 | | } |
| | 610 | |
|
| | 611 | | public void LoadCollectionsDropdown(Collection[] collections) |
| | 612 | | { |
| 0 | 613 | | List<ToggleComponentModel> collectionsToAdd = new List<ToggleComponentModel>(); |
| 0 | 614 | | foreach (var collection in collections) |
| | 615 | | { |
| 0 | 616 | | ToggleComponentModel newCollectionModel = new ToggleComponentModel |
| | 617 | | { |
| | 618 | | id = collection.urn, |
| | 619 | | text = collection.name, |
| | 620 | | isOn = false, |
| | 621 | | isTextActive = true |
| | 622 | | }; |
| | 623 | |
|
| 0 | 624 | | collectionsToAdd.Add(newCollectionModel); |
| 0 | 625 | | loadedCollectionModels.Add(collection.urn, newCollectionModel); |
| | 626 | | } |
| | 627 | |
|
| 0 | 628 | | collectionsDropdown.SetOptions(collectionsToAdd); |
| 0 | 629 | | } |
| | 630 | |
|
| | 631 | | public void BlockCollectionsDropdown(bool isBlocked) |
| | 632 | | { |
| 1 | 633 | | collectionsDropdown.SetLoadingActive(isBlocked); |
| 1 | 634 | | } |
| | 635 | |
|
| | 636 | | public void ShowSkinPopulatedList(bool show) |
| | 637 | | { |
| 0 | 638 | | skinsPopulatedListContainer.SetActive(show); |
| 0 | 639 | | skinsEmptyListContainer.SetActive(!show); |
| 0 | 640 | | skinsConnectWalletButtonContainer.SetActive(show); |
| 0 | 641 | | } |
| | 642 | |
|
| | 643 | | public void SetThirdPartyCollectionsVisibility(bool visible) => |
| 48 | 644 | | collectionsDropdown.gameObject.SetActive(visible); |
| | 645 | |
|
| | 646 | | internal void ConfigureSectionSelector() |
| | 647 | | { |
| 48 | 648 | | sectionTitle.text = AVATAR_SECTION_TITLE; |
| | 649 | |
|
| 48 | 650 | | sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.AddListener((isSelected) => |
| | 651 | | { |
| 0 | 652 | | avatarSection.SetActive(isSelected); |
| 0 | 653 | | randomizeButton.gameObject.SetActive(true); |
| | 654 | |
|
| 0 | 655 | | if (isSelected) |
| | 656 | | { |
| 0 | 657 | | sectionTitle.text = AVATAR_SECTION_TITLE; |
| 0 | 658 | | ResetPreviewEmote(); |
| | 659 | | } |
| | 660 | |
|
| 0 | 661 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(false, notifyEvent: false); |
| 0 | 662 | | }); |
| 48 | 663 | | sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.AddListener((isSelected) => |
| | 664 | | { |
| 0 | 665 | | emotesSection.SetActive(isSelected); |
| 0 | 666 | | randomizeButton.gameObject.SetActive(false); |
| | 667 | |
|
| 0 | 668 | | if (isSelected) |
| | 669 | | { |
| 0 | 670 | | sectionTitle.text = EMOTES_SECTION_TITLE; |
| 0 | 671 | | ResetPreviewEmote(); |
| | 672 | | } |
| | 673 | |
|
| 0 | 674 | | characterPreviewController.SetFocus(CharacterPreviewController.CameraFocus.DefaultEditing); |
| 0 | 675 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(true, notifyEvent: false); |
| 0 | 676 | | }); |
| 48 | 677 | | } |
| | 678 | |
|
| | 679 | | internal void SetSectionActive(int sectionIndex, bool isActive) |
| | 680 | | { |
| 96 | 681 | | sectionSelector.GetSection(sectionIndex).SetActive(isActive); |
| 288 | 682 | | sectionSelector.gameObject.SetActive(sectionSelector.GetAllSections().Count(x => x.IsActive()) > 1); |
| 96 | 683 | | } |
| | 684 | |
|
| 2 | 685 | | public void PlayPreviewEmote(string emoteId) { characterPreviewController.PlayEmote(emoteId, (long)Time.realtimeSinc |
| | 686 | |
|
| 2 | 687 | | public void ResetPreviewEmote() { PlayPreviewEmote(RESET_PREVIEW_ANIMATION); } |
| | 688 | |
|
| | 689 | | public void ToggleThirdPartyCollection(string collectionId, bool isOn) |
| | 690 | | { |
| 0 | 691 | | List<IToggleComponentView> allCollectionOptions = collectionsDropdown.GetAllOptions(); |
| 0 | 692 | | foreach (IToggleComponentView collectionOption in allCollectionOptions) |
| | 693 | | { |
| 0 | 694 | | if (collectionOption.id == collectionId) |
| 0 | 695 | | collectionOption.isOn = isOn; |
| | 696 | | } |
| 0 | 697 | | } |
| | 698 | | public void ShowNoItemOfWearableCollectionWarning() |
| | 699 | | { |
| 0 | 700 | | noItemInCollectionWarning.Dismiss(true); |
| 0 | 701 | | noItemInCollectionWarning.Show(new DCL.NotificationModel.Model |
| | 702 | | { |
| | 703 | | timer = 5f, |
| | 704 | | }); |
| 0 | 705 | | } |
| | 706 | |
|
| | 707 | | private void ClickBlockerClicked() |
| | 708 | | { |
| 0 | 709 | | noItemInCollectionWarning.Dismiss(false); |
| 0 | 710 | | } |
| | 711 | |
|
| | 712 | | private void UpdateAvatarModelWhenNeeded() |
| | 713 | | { |
| 1 | 714 | | if (isAvatarDirty) |
| | 715 | | { |
| 0 | 716 | | characterPreviewController.UpdateModel(avatarModelToUpdate, |
| | 717 | | () => |
| | 718 | | { |
| 0 | 719 | | if (doneButton != null) |
| 0 | 720 | | doneButton.interactable = true; |
| | 721 | |
|
| 0 | 722 | | loadingSpinnerGameObject?.SetActive(false); |
| | 723 | |
|
| 0 | 724 | | if (!updateAvatarShouldSkipAudio) |
| 0 | 725 | | OnAvatarAppear?.Invoke(avatarModelToUpdate); |
| | 726 | |
|
| 0 | 727 | | ClearWearablesLoadingSpinner(); |
| 0 | 728 | | randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, false); |
| 0 | 729 | | }); |
| | 730 | |
|
| 0 | 731 | | isAvatarDirty = false; |
| | 732 | | } |
| 1 | 733 | | } |
| | 734 | | } |