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