| | 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 | | internal static CharacterPreviewController characterPreviewController; |
| | 136 | | private AvatarEditorHUDController controller; |
| 49 | 137 | | internal readonly Dictionary<string, ItemSelector> selectorsByCategory = new Dictionary<string, ItemSelector>(); |
| 49 | 138 | | private readonly HashSet<WearableItem> wearablesWithLoadingSpinner = new HashSet<WearableItem>(); |
| 49 | 139 | | private Dictionary<string, ToggleComponentModel> loadedCollectionModels = new Dictionary<string, ToggleComponentMode |
| | 140 | |
|
| | 141 | | public event Action<AvatarModel> OnAvatarAppear; |
| | 142 | | public event Action<bool> OnSetVisibility; |
| | 143 | | public event Action OnRandomize; |
| | 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 | | if (characterPreviewController == null) |
| | 150 | | { |
| 48 | 151 | | characterPreviewController = Instantiate(characterPreviewPrefab).GetComponent<CharacterPreviewController>(); |
| 48 | 152 | | characterPreviewController.name = "_CharacterPreviewController"; |
| | 153 | | } |
| | 154 | |
|
| 48 | 155 | | isOpen = false; |
| 48 | 156 | | arePanelsInitialized = false; |
| 48 | 157 | | } |
| | 158 | |
|
| | 159 | | private void Initialize(AvatarEditorHUDController controller) |
| | 160 | | { |
| 48 | 161 | | this.controller = controller; |
| 48 | 162 | | gameObject.name = VIEW_OBJECT_NAME; |
| | 163 | |
|
| 48 | 164 | | randomizeButton.onClick.AddListener(OnRandomizeButton); |
| 48 | 165 | | doneButton.onClick.AddListener(OnDoneButton); |
| 48 | 166 | | InitializeWearableChangeEvents(); |
| | 167 | |
|
| 576 | 168 | | foreach (var button in goToMarketplaceButtons) |
| 240 | 169 | | button.onClick.RemoveAllListeners(); |
| 576 | 170 | | foreach (var button in goToMarketplaceButtons) |
| 240 | 171 | | button.onClick.AddListener(controller.GoToMarketplaceOrConnectWallet); |
| | 172 | |
|
| 48 | 173 | | characterPreviewController.camera.enabled = false; |
| | 174 | |
|
| 48 | 175 | | collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection; |
| 48 | 176 | | collectionsDropdown.OnOptionSelectionChanged += controller.ToggleThirdPartyCollection; |
| | 177 | |
|
| 48 | 178 | | clickBlocker.OnClicked += ClickBlockerClicked; |
| | 179 | |
|
| 48 | 180 | | ConfigureSectionSelector(); |
| 48 | 181 | | } |
| | 182 | |
|
| | 183 | | public void SetIsWeb3(bool isWeb3User) |
| | 184 | | { |
| 103 | 185 | | web3Container.SetActive(isWeb3User); |
| 103 | 186 | | noWeb3Container.SetActive(!isWeb3User); |
| 103 | 187 | | skinsWeb3Container.SetActive(isWeb3User); |
| 103 | 188 | | skinsMissingWeb3Container.SetActive(!isWeb3User); |
| 103 | 189 | | } |
| | 190 | |
|
| | 191 | | internal void InitializeNavigationEvents(bool isGuest) |
| | 192 | | { |
| 103 | 193 | | if (arePanelsInitialized) |
| 56 | 194 | | return; |
| | 195 | |
|
| 1880 | 196 | | for (int i = 0; i < navigationInfos.Length; i++) |
| | 197 | | { |
| 893 | 198 | | InitializeNavigationInfo(navigationInfos[i]); |
| | 199 | | } |
| 47 | 200 | | InitializeNavigationInfo(collectiblesNavigationInfo, !isGuest); |
| | 201 | |
|
| 47 | 202 | | characterPreviewRotation.OnHorizontalRotation += characterPreviewController.Rotate; |
| 47 | 203 | | arePanelsInitialized = true; |
| 47 | 204 | | } |
| | 205 | |
|
| | 206 | | private void InitializeNavigationInfo(AvatarEditorNavigationInfo current, bool isActive) |
| | 207 | | { |
| 940 | 208 | | current.Initialize(); |
| | 209 | |
|
| 940 | 210 | | current.toggle.isOn = isActive ? current.enabledByDefault : false; |
| 940 | 211 | | current.canvas.gameObject.SetActive(isActive ? current.enabledByDefault : false); |
| | 212 | |
|
| 940 | 213 | | current.toggle.onValueChanged.AddListener((on) => |
| | 214 | | { |
| 47 | 215 | | current.canvas.gameObject.SetActive(@on); |
| 47 | 216 | | characterPreviewController.SetFocus(current.focus); |
| 47 | 217 | | }); |
| 940 | 218 | | } |
| | 219 | |
|
| | 220 | | private void InitializeNavigationInfo(AvatarEditorNavigationInfo current) |
| | 221 | | { |
| 893 | 222 | | InitializeNavigationInfo(current, true); |
| 893 | 223 | | } |
| | 224 | |
|
| | 225 | | private void InitializeWearableChangeEvents() |
| | 226 | | { |
| 48 | 227 | | int nPairs = wearableGridPairs.Length; |
| 1728 | 228 | | for (int i = 0; i < nPairs; i++) |
| | 229 | | { |
| 816 | 230 | | wearableGridPairs[i].selector.OnItemClicked += controller.WearableClicked; |
| 816 | 231 | | wearableGridPairs[i].selector.OnSellClicked += controller.SellCollectible; |
| 816 | 232 | | selectorsByCategory.Add(wearableGridPairs[i].categoryFilter, wearableGridPairs[i].selector); |
| | 233 | | } |
| | 234 | |
|
| 48 | 235 | | collectiblesItemSelector.OnItemClicked += controller.WearableClicked; |
| 48 | 236 | | collectiblesItemSelector.OnSellClicked += controller.SellCollectible; |
| 48 | 237 | | collectiblesItemSelector.OnRetryClicked += controller.RetryLoadOwnedWearables; |
| | 238 | |
|
| 48 | 239 | | skinColorSelector.OnColorSelectorChange += controller.SkinColorClicked; |
| 48 | 240 | | eyeColorPickerComponent.OnColorChanged += controller.EyesColorClicked; |
| 48 | 241 | | hairColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 242 | | facialHairColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 243 | | eyeBrowsColorPickerComponent.OnColorChanged += controller.HairColorClicked; |
| 48 | 244 | | } |
| | 245 | |
|
| | 246 | | internal static AvatarEditorHUDView Create(AvatarEditorHUDController controller) |
| | 247 | | { |
| 48 | 248 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<AvatarEditorHUDView>(); |
| 48 | 249 | | view.Initialize(controller); |
| 48 | 250 | | return view; |
| | 251 | | } |
| | 252 | |
|
| | 253 | | public void UpdateSelectedBody(WearableItem bodyShape) |
| | 254 | | { |
| 1908 | 255 | | for (int i = 0; i < wearableGridPairs.Length; i++) |
| | 256 | | { |
| 901 | 257 | | if (wearableGridPairs[i].categoryFilter == WearableLiterals.Categories.BODY_SHAPE) |
| | 258 | | { |
| 53 | 259 | | wearableGridPairs[i].selector.UnselectAll(); |
| 53 | 260 | | wearableGridPairs[i].selector.Select(bodyShape.id); |
| 53 | 261 | | } |
| | 262 | | else |
| | 263 | | { |
| 848 | 264 | | wearableGridPairs[i].selector.SetBodyShape(bodyShape.id); |
| | 265 | | } |
| | 266 | | } |
| | 267 | |
|
| 53 | 268 | | collectiblesItemSelector.SetBodyShape(bodyShape.id); |
| 53 | 269 | | } |
| | 270 | |
|
| | 271 | | public void EquipWearable(WearableItem wearable) |
| | 272 | | { |
| 1027 | 273 | | selectorsByCategory[wearable.data.category].Select(wearable.id); |
| 1027 | 274 | | SetWearableLoadingSpinner(wearable, true); |
| 1027 | 275 | | collectiblesItemSelector.Select(wearable.id); |
| 1027 | 276 | | } |
| | 277 | |
|
| | 278 | | public void UnequipWearable(WearableItem wearable) |
| | 279 | | { |
| 464 | 280 | | selectorsByCategory[wearable.data.category].Unselect(wearable.id); |
| 464 | 281 | | SetWearableLoadingSpinner(wearable, false); |
| 464 | 282 | | collectiblesItemSelector.Unselect(wearable.id); |
| 464 | 283 | | } |
| | 284 | |
|
| | 285 | | internal void SetWearableLoadingSpinner(WearableItem wearable, bool isActive) |
| | 286 | | { |
| 1491 | 287 | | selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, isActive); |
| 1491 | 288 | | collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, isActive); |
| 1491 | 289 | | if (isActive) |
| 1027 | 290 | | wearablesWithLoadingSpinner.Add(wearable); |
| | 291 | | else |
| 464 | 292 | | wearablesWithLoadingSpinner.Remove(wearable); |
| 464 | 293 | | } |
| | 294 | |
|
| | 295 | | internal void ClearWearablesLoadingSpinner() |
| | 296 | | { |
| 668 | 297 | | foreach (WearableItem wearable in wearablesWithLoadingSpinner) |
| | 298 | | { |
| 292 | 299 | | selectorsByCategory[wearable.data.category].SetWearableLoadingSpinner(wearable.id, false); |
| 292 | 300 | | collectiblesItemSelector.SetWearableLoadingSpinner(wearable.id, false); |
| | 301 | | } |
| | 302 | |
|
| 42 | 303 | | wearablesWithLoadingSpinner.Clear(); |
| 42 | 304 | | } |
| | 305 | |
|
| | 306 | | public void SelectHairColor(Color hairColor) |
| | 307 | | { |
| 108 | 308 | | hairColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 309 | | hairColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 310 | | eyeBrowsColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 311 | | eyeBrowsColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 312 | | facialHairColorPickerComponent.SetColorSelector(hairColor); |
| 108 | 313 | | facialHairColorPickerComponent.UpdateSliderValues(hairColor); |
| 108 | 314 | | } |
| | 315 | |
|
| | 316 | | public Color GetRandomColor() |
| | 317 | | { |
| 2 | 318 | | return Color.HSVToRGB(UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range |
| | 319 | | } |
| | 320 | |
|
| | 321 | | public void SelectSkinColor(Color skinColor) |
| | 322 | | { |
| 107 | 323 | | skinColorSelector.Select(skinColor); |
| 107 | 324 | | } |
| | 325 | |
|
| | 326 | | public void SelectEyeColor(Color eyesColor) |
| | 327 | | { |
| 108 | 328 | | eyeColorPickerComponent.SetColorSelector(eyesColor); |
| 108 | 329 | | eyeColorPickerComponent.UpdateSliderValues(eyesColor); |
| 108 | 330 | | } |
| | 331 | |
|
| | 332 | | public void SetColors(List<Color> skinColors, List<Color> hairColors, List<Color> eyeColors) |
| | 333 | | { |
| 48 | 334 | | skinColorSelector.Populate(skinColors); |
| 48 | 335 | | eyeColorPickerComponent.SetColorList(eyeColors); |
| 48 | 336 | | hairColorPickerComponent.SetColorList(hairColors); |
| 48 | 337 | | eyeBrowsColorPickerComponent.SetColorList(hairColors); |
| 48 | 338 | | facialHairColorPickerComponent.SetColorList(hairColors); |
| 48 | 339 | | } |
| | 340 | |
|
| | 341 | | public void UnselectAllWearables() |
| | 342 | | { |
| 3744 | 343 | | for (int i = 0; i < wearableGridPairs.Length; i++) |
| | 344 | | { |
| 1768 | 345 | | if (wearableGridPairs[i].categoryFilter != WearableLiterals.Categories.BODY_SHAPE) |
| | 346 | | { |
| 1664 | 347 | | wearableGridPairs[i].selector.UnselectAll(); |
| | 348 | | } |
| | 349 | | } |
| | 350 | |
|
| 104 | 351 | | collectiblesItemSelector.UnselectAll(); |
| 104 | 352 | | } |
| | 353 | |
|
| | 354 | | public void UpdateAvatarPreview(AvatarModel avatarModel, bool skipAudio) |
| | 355 | | { |
| 125 | 356 | | if (avatarModel?.wearables == null) |
| 0 | 357 | | return; |
| | 358 | |
|
| 125 | 359 | | doneButton.interactable = false; |
| 125 | 360 | | loadingSpinnerGameObject.SetActive(true); |
| 125 | 361 | | characterPreviewController.UpdateModel(avatarModel, |
| | 362 | | () => |
| | 363 | | { |
| 42 | 364 | | if (doneButton != null) |
| 42 | 365 | | doneButton.interactable = true; |
| | 366 | |
|
| 42 | 367 | | loadingSpinnerGameObject?.SetActive(false); |
| | 368 | |
|
| 42 | 369 | | if(!skipAudio) |
| 0 | 370 | | OnAvatarAppear?.Invoke(avatarModel); |
| | 371 | |
|
| 42 | 372 | | ClearWearablesLoadingSpinner(); |
| 42 | 373 | | randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, false); |
| 42 | 374 | | }); |
| 125 | 375 | | } |
| | 376 | |
|
| | 377 | | public void AddWearable(WearableItem wearableItem, int amount, |
| | 378 | | Func<WearableItem, bool> hideOtherWearablesToastStrategy, |
| | 379 | | Func<WearableItem, bool> replaceOtherWearablesToastStrategy) |
| | 380 | | { |
| 4221 | 381 | | if (wearableItem == null) |
| 0 | 382 | | return; |
| | 383 | |
|
| 4221 | 384 | | if (!selectorsByCategory.ContainsKey(wearableItem.data.category)) |
| | 385 | | { |
| 0 | 386 | | Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} "); |
| 0 | 387 | | return; |
| | 388 | | } |
| | 389 | |
|
| 4221 | 390 | | string collectionName = GetWearableCollectionName(wearableItem); |
| | 391 | |
|
| 4221 | 392 | | selectorsByCategory[wearableItem.data.category].AddItemToggle( |
| | 393 | | wearableItem, |
| | 394 | | collectionName, |
| | 395 | | amount, |
| | 396 | | hideOtherWearablesToastStrategy, |
| | 397 | | replaceOtherWearablesToastStrategy); |
| | 398 | |
|
| 4221 | 399 | | if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection) |
| | 400 | | { |
| 21 | 401 | | collectiblesItemSelector.AddItemToggle( |
| | 402 | | wearableItem, |
| | 403 | | collectionName, |
| | 404 | | amount, |
| | 405 | | hideOtherWearablesToastStrategy, |
| | 406 | | replaceOtherWearablesToastStrategy); |
| | 407 | | } |
| 4221 | 408 | | } |
| | 409 | |
|
| | 410 | | public void RefreshSelectorsSize() |
| | 411 | | { |
| 151 | 412 | | using (var iterator = selectorsByCategory.GetEnumerator()) |
| | 413 | | { |
| 2718 | 414 | | while (iterator.MoveNext()) |
| | 415 | | { |
| 2567 | 416 | | iterator.Current.Value.UpdateSelectorLayout(); |
| | 417 | | } |
| 151 | 418 | | } |
| | 419 | |
|
| 151 | 420 | | collectiblesItemSelector.UpdateSelectorLayout(); |
| 151 | 421 | | } |
| | 422 | |
|
| | 423 | | private string GetWearableCollectionName(WearableItem wearableItem) |
| | 424 | | { |
| 4221 | 425 | | string collectionName = string.Empty; |
| | 426 | |
|
| 4221 | 427 | | if (wearableItem.IsFromThirdPartyCollection) |
| | 428 | | { |
| 0 | 429 | | loadedCollectionModels.TryGetValue(wearableItem.ThirdPartyCollectionId, out ToggleComponentModel collectionM |
| | 430 | |
|
| 0 | 431 | | if (collectionModel != null) |
| 0 | 432 | | collectionName = collectionModel.text; |
| | 433 | | } |
| | 434 | |
|
| 4221 | 435 | | return collectionName; |
| | 436 | | } |
| | 437 | |
|
| | 438 | | public void RemoveWearable(WearableItem wearableItem) |
| | 439 | | { |
| 0 | 440 | | if (wearableItem == null) |
| 0 | 441 | | return; |
| | 442 | |
|
| 0 | 443 | | if (!selectorsByCategory.ContainsKey(wearableItem.data.category)) |
| | 444 | | { |
| 0 | 445 | | Debug.LogError($"Category couldn't find selector for category: {wearableItem.data.category} "); |
| 0 | 446 | | return; |
| | 447 | | } |
| | 448 | |
|
| 0 | 449 | | selectorsByCategory[wearableItem.data.category].RemoveItemToggle(wearableItem.id); |
| 0 | 450 | | if (wearableItem.IsCollectible() || wearableItem.IsFromThirdPartyCollection) |
| 0 | 451 | | collectiblesItemSelector.RemoveItemToggle(wearableItem.id); |
| 0 | 452 | | } |
| | 453 | |
|
| | 454 | | public void RemoveAllWearables() |
| | 455 | | { |
| 151 | 456 | | using (var enumerator = selectorsByCategory.GetEnumerator()) |
| | 457 | | { |
| 2718 | 458 | | while (enumerator.MoveNext()) |
| | 459 | | { |
| 2567 | 460 | | enumerator.Current.Value.RemoveAllItemToggle(); |
| | 461 | | } |
| 151 | 462 | | } |
| | 463 | |
|
| 151 | 464 | | collectiblesItemSelector.RemoveAllItemToggle(); |
| 151 | 465 | | } |
| | 466 | |
|
| | 467 | | private void OnRandomizeButton() |
| | 468 | | { |
| 0 | 469 | | OnRandomize?.Invoke(); |
| 0 | 470 | | controller.RandomizeWearables(); |
| 0 | 471 | | randomizeAnimator?.SetBool(RANDOMIZE_ANIMATOR_LOADING_BOOL, true); |
| 0 | 472 | | } |
| | 473 | |
|
| | 474 | | private void OnDoneButton() |
| | 475 | | { |
| 0 | 476 | | doneButton.interactable = false; |
| 0 | 477 | | CoroutineStarter.Start(TakeSnapshotsAfterStopPreviewAnimation()); |
| 0 | 478 | | eyeColorPickerComponent.SetActive(false); |
| 0 | 479 | | hairColorPickerComponent.SetActive(false); |
| 0 | 480 | | facialHairColorPickerComponent.SetActive(false); |
| 0 | 481 | | eyeBrowsColorPickerComponent.SetActive(false); |
| 0 | 482 | | } |
| | 483 | |
|
| | 484 | | private IEnumerator TakeSnapshotsAfterStopPreviewAnimation() |
| | 485 | | { |
| | 486 | | // We need to stop the current preview animation in order to take a correct snapshot |
| 0 | 487 | | ResetPreviewEmote(); |
| 0 | 488 | | yield return new WaitForSeconds(TIME_TO_RESET_PREVIEW_ANIMATION); |
| 0 | 489 | | characterPreviewController.TakeSnapshots(OnSnapshotsReady, OnSnapshotsFailed); |
| 0 | 490 | | } |
| | 491 | |
|
| | 492 | | private void OnSnapshotsReady(Texture2D face256, Texture2D body) |
| | 493 | | { |
| 0 | 494 | | doneButton.interactable = true; |
| 0 | 495 | | controller.SaveAvatar(face256, body); |
| 0 | 496 | | } |
| | 497 | |
|
| 0 | 498 | | private void OnSnapshotsFailed() { doneButton.interactable = true; } |
| | 499 | |
|
| | 500 | | public void SetVisibility(bool visible) |
| | 501 | | { |
| 92 | 502 | | characterPreviewController.camera.enabled = visible; |
| 92 | 503 | | avatarEditorCanvas.enabled = visible; |
| 92 | 504 | | avatarEditorCanvasGroup.blocksRaycasts = visible; |
| | 505 | |
|
| 92 | 506 | | if (visible && !isOpen) |
| | 507 | | { |
| 43 | 508 | | OnSetVisibility?.Invoke(visible); |
| 0 | 509 | | } |
| 49 | 510 | | else if (!visible && isOpen) |
| | 511 | | { |
| 1 | 512 | | collectionsDropdown.Close(); |
| 1 | 513 | | noItemInCollectionWarning.Dismiss(true); |
| 1 | 514 | | OnSetVisibility?.Invoke(visible); |
| | 515 | | } |
| | 516 | |
|
| 92 | 517 | | isOpen = visible; |
| 92 | 518 | | } |
| | 519 | |
|
| | 520 | | public void CleanUp() |
| | 521 | | { |
| 48 | 522 | | loadingSpinnerGameObject = null; |
| 48 | 523 | | randomizeAnimator = null; |
| 48 | 524 | | if (wearableGridPairs != null) |
| | 525 | | { |
| 48 | 526 | | int nPairs = wearableGridPairs.Length; |
| 1728 | 527 | | for (int i = 0; i < nPairs; i++) |
| | 528 | | { |
| 816 | 529 | | var itemSelector = wearableGridPairs[i].selector; |
| 816 | 530 | | if (itemSelector != null) |
| | 531 | | { |
| 816 | 532 | | itemSelector.OnItemClicked -= controller.WearableClicked; |
| 816 | 533 | | itemSelector.OnSellClicked -= controller.SellCollectible; |
| | 534 | | } |
| | 535 | | } |
| | 536 | | } |
| | 537 | |
|
| 48 | 538 | | if (collectiblesItemSelector != null) |
| | 539 | | { |
| 48 | 540 | | collectiblesItemSelector.OnItemClicked -= controller.WearableClicked; |
| 48 | 541 | | collectiblesItemSelector.OnSellClicked -= controller.SellCollectible; |
| 48 | 542 | | collectiblesItemSelector.OnRetryClicked -= controller.RetryLoadOwnedWearables; |
| | 543 | | } |
| | 544 | |
|
| 48 | 545 | | if (skinColorSelector != null) |
| 48 | 546 | | skinColorSelector.OnColorSelectorChange -= controller.SkinColorClicked; |
| 48 | 547 | | if (eyeColorPickerComponent != null) |
| 48 | 548 | | eyeColorPickerComponent.OnColorChanged -= controller.EyesColorClicked; |
| 48 | 549 | | if (hairColorPickerComponent != null) |
| 48 | 550 | | hairColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| 48 | 551 | | if (facialHairColorPickerComponent != null) |
| 48 | 552 | | facialHairColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| 48 | 553 | | if (eyeBrowsColorPickerComponent != null) |
| 48 | 554 | | eyeBrowsColorPickerComponent.OnColorChanged -= controller.HairColorClicked; |
| | 555 | |
|
| 48 | 556 | | if (this != null) |
| 48 | 557 | | Destroy(gameObject); |
| | 558 | |
|
| 48 | 559 | | if (characterPreviewController != null) |
| | 560 | | { |
| 48 | 561 | | Destroy(characterPreviewController.gameObject); |
| 48 | 562 | | characterPreviewController = null; |
| | 563 | | } |
| | 564 | |
|
| 48 | 565 | | collectionsDropdown.OnOptionSelectionChanged -= controller.ToggleThirdPartyCollection; |
| 48 | 566 | | collectionsDropdown.Dispose(); |
| | 567 | |
|
| 48 | 568 | | sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| 48 | 569 | | sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| | 570 | |
|
| 48 | 571 | | clickBlocker.OnClicked -= ClickBlockerClicked; |
| 48 | 572 | | } |
| | 573 | |
|
| 2 | 574 | | public void ShowCollectiblesLoadingSpinner(bool isActive) { collectiblesItemSelector.ShowLoading(isActive); } |
| | 575 | |
|
| 2 | 576 | | public void ShowCollectiblesLoadingRetry(bool isActive) { collectiblesItemSelector.ShowRetryLoading(isActive); } |
| | 577 | |
|
| | 578 | | public void SetAsFullScreenMenuMode(Transform parentTransform) |
| | 579 | | { |
| 48 | 580 | | if (parentTransform == null) |
| 48 | 581 | | return; |
| | 582 | |
|
| 0 | 583 | | transform.SetParent(parentTransform); |
| 0 | 584 | | transform.localScale = Vector3.one; |
| | 585 | |
|
| 0 | 586 | | RectTransform rectTransform = transform as RectTransform; |
| 0 | 587 | | rectTransform.anchorMin = Vector2.zero; |
| 0 | 588 | | rectTransform.anchorMax = Vector2.one; |
| 0 | 589 | | rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 590 | | rectTransform.localPosition = Vector2.zero; |
| 0 | 591 | | rectTransform.offsetMax = Vector2.zero; |
| 0 | 592 | | rectTransform.offsetMin = Vector2.zero; |
| 0 | 593 | | } |
| | 594 | |
|
| | 595 | | public void OnPointerDown(PointerEventData eventData) |
| | 596 | | { |
| 0 | 597 | | if (eventData.pointerPressRaycast.gameObject != eyeColorPickerComponent.gameObject && |
| | 598 | | eventData.pointerPressRaycast.gameObject != hairColorPickerComponent.gameObject && |
| | 599 | | eventData.pointerPressRaycast.gameObject != eyeBrowsColorPickerComponent.gameObject && |
| | 600 | | eventData.pointerPressRaycast.gameObject != facialHairColorPickerComponent.gameObject) |
| | 601 | | { |
| 0 | 602 | | eyeColorPickerComponent.SetActive(false); |
| 0 | 603 | | hairColorPickerComponent.SetActive(false); |
| 0 | 604 | | eyeBrowsColorPickerComponent.SetActive(false); |
| 0 | 605 | | facialHairColorPickerComponent.SetActive(false); |
| | 606 | | } |
| 0 | 607 | | } |
| | 608 | |
|
| | 609 | | public void LoadCollectionsDropdown(Collection[] collections) |
| | 610 | | { |
| 0 | 611 | | List<ToggleComponentModel> collectionsToAdd = new List<ToggleComponentModel>(); |
| 0 | 612 | | foreach (var collection in collections) |
| | 613 | | { |
| 0 | 614 | | ToggleComponentModel newCollectionModel = new ToggleComponentModel |
| | 615 | | { |
| | 616 | | id = collection.urn, |
| | 617 | | text = collection.name, |
| | 618 | | isOn = false, |
| | 619 | | isTextActive = true |
| | 620 | | }; |
| | 621 | |
|
| 0 | 622 | | collectionsToAdd.Add(newCollectionModel); |
| 0 | 623 | | loadedCollectionModels.Add(collection.urn, newCollectionModel); |
| | 624 | | } |
| | 625 | |
|
| 0 | 626 | | collectionsDropdown.SetOptions(collectionsToAdd); |
| 0 | 627 | | } |
| | 628 | |
|
| | 629 | | public void BlockCollectionsDropdown(bool isBlocked) |
| | 630 | | { |
| 1 | 631 | | collectionsDropdown.SetLoadingActive(isBlocked); |
| 1 | 632 | | } |
| | 633 | |
|
| | 634 | | public void ShowSkinPopulatedList(bool show) |
| | 635 | | { |
| 0 | 636 | | skinsPopulatedListContainer.SetActive(show); |
| 0 | 637 | | skinsEmptyListContainer.SetActive(!show); |
| 0 | 638 | | skinsConnectWalletButtonContainer.SetActive(show); |
| 0 | 639 | | } |
| | 640 | |
|
| | 641 | | public void SetThirdPartyCollectionsVisibility(bool visible) => |
| 48 | 642 | | collectionsDropdown.gameObject.SetActive(visible); |
| | 643 | |
|
| | 644 | | internal void ConfigureSectionSelector() |
| | 645 | | { |
| 48 | 646 | | sectionTitle.text = AVATAR_SECTION_TITLE; |
| | 647 | |
|
| 48 | 648 | | sectionSelector.GetSection(AVATAR_SECTION_INDEX).onSelect.AddListener((isSelected) => |
| | 649 | | { |
| 0 | 650 | | avatarSection.SetActive(isSelected); |
| 0 | 651 | | randomizeButton.gameObject.SetActive(true); |
| | 652 | |
|
| 0 | 653 | | if (isSelected) |
| | 654 | | { |
| 0 | 655 | | sectionTitle.text = AVATAR_SECTION_TITLE; |
| 0 | 656 | | ResetPreviewEmote(); |
| | 657 | | } |
| | 658 | |
|
| 0 | 659 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(false, notifyEvent: false); |
| 0 | 660 | | }); |
| 48 | 661 | | sectionSelector.GetSection(EMOTES_SECTION_INDEX).onSelect.AddListener((isSelected) => |
| | 662 | | { |
| 0 | 663 | | emotesSection.SetActive(isSelected); |
| 0 | 664 | | randomizeButton.gameObject.SetActive(false); |
| | 665 | |
|
| 0 | 666 | | if (isSelected) |
| | 667 | | { |
| 0 | 668 | | sectionTitle.text = EMOTES_SECTION_TITLE; |
| 0 | 669 | | ResetPreviewEmote(); |
| | 670 | | } |
| | 671 | |
|
| 0 | 672 | | characterPreviewController.SetFocus(CharacterPreviewController.CameraFocus.DefaultEditing); |
| 0 | 673 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.Set(true, notifyEvent: false); |
| 0 | 674 | | }); |
| 48 | 675 | | } |
| | 676 | |
|
| | 677 | | internal void SetSectionActive(int sectionIndex, bool isActive) |
| | 678 | | { |
| 96 | 679 | | sectionSelector.GetSection(sectionIndex).SetActive(isActive); |
| 288 | 680 | | sectionSelector.gameObject.SetActive(sectionSelector.GetAllSections().Count(x => x.IsActive()) > 1); |
| 96 | 681 | | } |
| | 682 | |
|
| 2 | 683 | | public void PlayPreviewEmote(string emoteId) { characterPreviewController.PlayEmote(emoteId, (long)Time.realtimeSinc |
| | 684 | |
|
| 2 | 685 | | public void ResetPreviewEmote() { PlayPreviewEmote(RESET_PREVIEW_ANIMATION); } |
| | 686 | |
|
| | 687 | | public void ToggleThirdPartyCollection(string collectionId, bool isOn) |
| | 688 | | { |
| 0 | 689 | | List<IToggleComponentView> allCollectionOptions = collectionsDropdown.GetAllOptions(); |
| 0 | 690 | | foreach (IToggleComponentView collectionOption in allCollectionOptions) |
| | 691 | | { |
| 0 | 692 | | if (collectionOption.id == collectionId) |
| 0 | 693 | | collectionOption.isOn = isOn; |
| | 694 | | } |
| 0 | 695 | | } |
| | 696 | | public void ShowNoItemOfWearableCollectionWarning() |
| | 697 | | { |
| 0 | 698 | | noItemInCollectionWarning.Dismiss(true); |
| 0 | 699 | | noItemInCollectionWarning.Show(new DCL.NotificationModel.Model |
| | 700 | | { |
| | 701 | | timer = 5f, |
| | 702 | | }); |
| 0 | 703 | | } |
| | 704 | |
|
| | 705 | | private void ClickBlockerClicked() |
| | 706 | | { |
| 0 | 707 | | noItemInCollectionWarning.Dismiss(false); |
| 0 | 708 | | } |
| | 709 | |
|
| | 710 | | } |