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