| | 1 | | using DCL; |
| | 2 | | using DCL.EmotesCustomization; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Interface; |
| | 5 | | using DCL.NotificationModel; |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Linq; |
| | 9 | | using System.Threading; |
| | 10 | | using Cysharp.Threading.Tasks; |
| | 11 | | using DCL.Emotes; |
| | 12 | | using UnityEngine; |
| | 13 | | using UnityEngine.Rendering; |
| | 14 | | using UnityEngine.Rendering.Universal; |
| | 15 | | using Categories = WearableLiterals.Categories; |
| | 16 | | using Environment = DCL.Environment; |
| | 17 | | using Random = UnityEngine.Random; |
| | 18 | | using Type = DCL.NotificationModel.Type; |
| | 19 | |
|
| | 20 | | public class AvatarEditorHUDController : IHUD |
| | 21 | | { |
| | 22 | | private const int LOADING_OWNED_WEARABLES_RETRIES = 3; |
| | 23 | | private const string LOADING_OWNED_WEARABLES_ERROR_MESSAGE = "There was a problem loading your wearables"; |
| | 24 | | private const string URL_MARKET_PLACE = "https://market.decentraland.org/browse?section=wearables"; |
| | 25 | | private const string URL_GET_A_WALLET = "https://docs.decentraland.org/get-a-wallet"; |
| | 26 | | private const string URL_SELL_COLLECTIBLE_GENERIC = "https://market.decentraland.org/account"; |
| | 27 | | private const string URL_SELL_SPECIFIC_COLLECTIBLE = "https://market.decentraland.org/contracts/{collectionId}/token |
| | 28 | | private const string THIRD_PARTY_COLLECTIONS_FEATURE_FLAG = "third_party_collections"; |
| | 29 | | internal const string EQUIP_WEARABLE_METRIC = "equip_wearable"; |
| 1 | 30 | | protected static readonly string[] categoriesThatMustHaveSelection = { Categories.BODY_SHAPE, Categories.UPPER_BODY, |
| 1 | 31 | | protected static readonly string[] categoriesToRandomize = { Categories.HAIR, Categories.EYES, Categories.EYEBROWS, |
| | 32 | |
|
| | 33 | | [NonSerialized] |
| | 34 | | public bool bypassUpdateAvatarPreview = false; |
| | 35 | |
|
| | 36 | | internal UserProfile userProfile; |
| | 37 | | internal readonly IAnalytics analytics; |
| | 38 | | internal readonly INewUserExperienceAnalytics newUserExperienceAnalytics; |
| | 39 | | private BaseDictionary<string, WearableItem> catalog; |
| 106 | 40 | | bool renderingEnabled => CommonScriptableObjects.rendererState.Get(); |
| 103 | 41 | | bool isPlayerRendererLoaded => DataStore.i.common.isPlayerRendererLoaded.Get(); |
| 183 | 42 | | BaseVariable<bool> avatarEditorVisible => DataStore.i.HUDs.avatarEditorVisible; |
| 139 | 43 | | BaseVariable<Transform> configureBackpackInFullscreenMenu => DataStore.i.exploreV2.configureBackpackInFullscreenMenu |
| 91 | 44 | | BaseVariable<bool> exploreV2IsOpen => DataStore.i.exploreV2.isOpen; |
| 363 | 45 | | DataStore_EmotesCustomization emotesCustomizationDataStore => DataStore.i.emotesCustomization; |
| 0 | 46 | | DataStore_FeatureFlag featureFlagsDataStore => DataStore.i.featureFlags; |
| | 47 | |
|
| | 48 | | private readonly DataStore_FeatureFlag featureFlags; |
| | 49 | |
|
| 48 | 50 | | private readonly Dictionary<string, List<WearableItem>> wearablesByCategory = new Dictionary<string, List<WearableIt |
| 48 | 51 | | protected readonly AvatarEditorHUDModel model = new AvatarEditorHUDModel(); |
| | 52 | |
|
| | 53 | | private ColorList skinColorList; |
| | 54 | | private ColorList eyeColorList; |
| | 55 | | private ColorList hairColorList; |
| | 56 | | private bool prevMouseLockState = false; |
| 48 | 57 | | private int ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES; |
| | 58 | | private bool ownedWearablesAlreadyLoaded = false; |
| 48 | 59 | | private List<Nft> ownedNftCollectionsL1 = new List<Nft>(); |
| 48 | 60 | | private List<Nft> ownedNftCollectionsL2 = new List<Nft>(); |
| | 61 | | private bool avatarIsDirty = false; |
| | 62 | | private float lastTimeOwnedWearablesChecked = 0; |
| 48 | 63 | | private float lastTimeOwnedEmotesChecked = float.MinValue; |
| | 64 | | internal bool collectionsAlreadyLoaded = false; |
| 48 | 65 | | private float prevRenderScale = 1.0f; |
| | 66 | | private bool isAvatarPreviewReady; |
| 48 | 67 | | private List<string> thirdPartyWearablesLoaded = new List<string>(); |
| 48 | 68 | | private CancellationTokenSource loadEmotesCTS = new CancellationTokenSource(); |
| | 69 | |
|
| | 70 | | internal IEmotesCustomizationComponentController emotesCustomizationComponentController; |
| | 71 | |
|
| 91 | 72 | | private bool isThirdPartyCollectionsEnabled => featureFlags.flags.Get().IsFeatureEnabled(THIRD_PARTY_COLLECTIONS_FEA |
| | 73 | |
|
| | 74 | | public AvatarEditorHUDView view; |
| | 75 | |
|
| | 76 | | private bool loadingWearables; |
| | 77 | | private WearableItem[] emotesLoadedAsWearables; |
| | 78 | |
|
| | 79 | | public event Action OnOpen; |
| | 80 | | public event Action OnClose; |
| | 81 | |
|
| 48 | 82 | | public AvatarEditorHUDController(DataStore_FeatureFlag featureFlags, IAnalytics analytics) |
| | 83 | | { |
| 48 | 84 | | this.featureFlags = featureFlags; |
| 48 | 85 | | this.analytics = analytics; |
| 48 | 86 | | this.newUserExperienceAnalytics = new NewUserExperienceAnalytics(analytics); |
| 48 | 87 | | } |
| | 88 | |
|
| | 89 | | public void Initialize(UserProfile userProfile, |
| | 90 | | BaseDictionary<string, WearableItem> catalog, |
| | 91 | | bool bypassUpdateAvatarPreview = false) |
| | 92 | | { |
| 48 | 93 | | this.userProfile = userProfile; |
| 48 | 94 | | this.bypassUpdateAvatarPreview = bypassUpdateAvatarPreview; |
| | 95 | |
|
| 48 | 96 | | view = AvatarEditorHUDView.Create(this); |
| | 97 | |
|
| 48 | 98 | | view.skinsFeatureContainer.SetActive(true); |
| 48 | 99 | | avatarEditorVisible.OnChange += OnAvatarEditorVisibleChanged; |
| 48 | 100 | | OnAvatarEditorVisibleChanged(avatarEditorVisible.Get(), false); |
| | 101 | |
|
| 48 | 102 | | configureBackpackInFullscreenMenu.OnChange += ConfigureBackpackInFullscreenMenuChanged; |
| 48 | 103 | | ConfigureBackpackInFullscreenMenuChanged(configureBackpackInFullscreenMenu.Get(), null); |
| | 104 | |
|
| 48 | 105 | | exploreV2IsOpen.OnChange += ExploreV2IsOpenChanged; |
| | 106 | |
|
| 48 | 107 | | skinColorList = Resources.Load<ColorList>("SkinTone"); |
| 48 | 108 | | hairColorList = Resources.Load<ColorList>("HairColor"); |
| 48 | 109 | | eyeColorList = Resources.Load<ColorList>("EyeColor"); |
| 48 | 110 | | view.SetColors(skinColorList.colors, hairColorList.colors, eyeColorList.colors); |
| | 111 | |
|
| 48 | 112 | | SetCatalog(catalog); |
| | 113 | |
|
| 48 | 114 | | this.userProfile.OnUpdate += LoadUserProfile; |
| | 115 | |
|
| 48 | 116 | | view.SetSectionActive(AvatarEditorHUDView.EMOTES_SECTION_INDEX, false); |
| | 117 | |
|
| 48 | 118 | | emotesCustomizationComponentController = CreateEmotesController(); |
| 48 | 119 | | IEmotesCustomizationComponentView emotesSectionView = emotesCustomizationComponentController.Initialize( |
| | 120 | | DataStore.i.emotesCustomization, |
| | 121 | | DataStore.i.emotes, |
| | 122 | | DataStore.i.exploreV2, |
| | 123 | | DataStore.i.HUDs); |
| | 124 | | //Initialize with embedded emotes |
| 48 | 125 | | emotesCustomizationComponentController.SetEmotes(EmbeddedEmotesSO.Provide().emotes.ToArray()); |
| 48 | 126 | | emotesSectionView.viewTransform.SetParent(view.emotesSection.transform, false); |
| 48 | 127 | | view.SetSectionActive(AvatarEditorHUDView.EMOTES_SECTION_INDEX, true); |
| | 128 | |
|
| 48 | 129 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.OnChange += HandleEmotesCostumizationSelection; |
| 48 | 130 | | emotesCustomizationDataStore.currentLoadedEmotes.OnAdded += OnNewEmoteAdded; |
| | 131 | |
|
| 48 | 132 | | emotesCustomizationComponentController.onEmotePreviewed += OnPreviewEmote; |
| 48 | 133 | | emotesCustomizationComponentController.onEmoteEquipped += OnEmoteEquipped; |
| 48 | 134 | | emotesCustomizationComponentController.onEmoteUnequipped += OnEmoteUnequipped; |
| 48 | 135 | | emotesCustomizationComponentController.onEmoteSell += OnRedirectToEmoteSelling; |
| | 136 | |
|
| 48 | 137 | | LoadUserProfile(userProfile, true); |
| | 138 | |
|
| 48 | 139 | | DataStore.i.HUDs.isAvatarEditorInitialized.Set(true); |
| | 140 | |
|
| 48 | 141 | | view.SetThirdPartyCollectionsVisibility(isThirdPartyCollectionsEnabled); |
| 48 | 142 | | } |
| | 143 | |
|
| | 144 | | public void SetCatalog(BaseDictionary<string, WearableItem> catalog) |
| | 145 | | { |
| 48 | 146 | | if (this.catalog != null) |
| | 147 | | { |
| 0 | 148 | | this.catalog.OnAdded -= OnAdditionalWearableAdded; |
| 0 | 149 | | this.catalog.OnRemoved -= OnAdditionalWearableRemoved; |
| | 150 | | } |
| | 151 | |
|
| 48 | 152 | | this.catalog = catalog; |
| | 153 | |
|
| 48 | 154 | | ProcessCatalog(this.catalog); |
| 48 | 155 | | this.catalog.OnAdded += OnAdditionalWearableAdded; |
| 48 | 156 | | this.catalog.OnRemoved += OnAdditionalWearableRemoved; |
| 48 | 157 | | } |
| | 158 | |
|
| | 159 | | private void OnAdditionalWearableRemoved(string s, WearableItem item) |
| | 160 | | { |
| 0 | 161 | | RemoveWearable(s, item); |
| 0 | 162 | | view.RefreshSelectorsSize(); |
| 0 | 163 | | } |
| | 164 | |
|
| | 165 | | private void OnAdditionalWearableAdded(string id, WearableItem item) |
| | 166 | | { |
| 11 | 167 | | AddWearable(id, item); |
| 11 | 168 | | view.RefreshSelectorsSize(); |
| 11 | 169 | | } |
| | 170 | |
|
| | 171 | | private void LoadUserProfile(UserProfile userProfile) |
| | 172 | | { |
| 43 | 173 | | LoadUserProfile(userProfile, false); |
| 43 | 174 | | QueryNftCollections(userProfile.userId); |
| 43 | 175 | | } |
| | 176 | |
|
| | 177 | | private void LoadOwnedWereables(UserProfile userProfile) |
| | 178 | | { |
| | 179 | | // If there is more than 1 minute that we have checked the owned wearables, we try it again |
| | 180 | | // This is done in order to retrieved the wearables after you has claimed them |
| 43 | 181 | | if ((Time.realtimeSinceStartup < lastTimeOwnedWearablesChecked + 60 && |
| | 182 | | (ownedWearablesAlreadyLoaded || |
| | 183 | | ownedWearablesRemainingRequests <= 0)) || |
| | 184 | | string.IsNullOrEmpty(userProfile.userId)) |
| 43 | 185 | | return; |
| | 186 | |
|
| 0 | 187 | | lastTimeOwnedWearablesChecked = Time.realtimeSinceStartup; |
| | 188 | |
|
| 0 | 189 | | loadingWearables = true; |
| 0 | 190 | | CatalogController.RequestOwnedWearables(userProfile.userId) |
| | 191 | | .Then((ownedWearables) => |
| | 192 | | { |
| 0 | 193 | | ownedWearablesAlreadyLoaded = true; |
| | 194 | | //Prior profile V1 emotes must be retrieved along the wearables, onwards they will be reque |
| 0 | 195 | | this.userProfile.SetInventory(ownedWearables.Select(x => x.id).Concat(thirdPartyWearablesLo |
| 0 | 196 | | LoadUserProfile(userProfile, true); |
| 0 | 197 | | if (userProfile != null && userProfile.avatar != null) |
| | 198 | | { |
| 0 | 199 | | emotesLoadedAsWearables = ownedWearables.Where(x => x.IsEmote()).ToArray(); |
| | 200 | | } |
| 0 | 201 | | view.ShowSkinPopulatedList(ownedWearables.Any(item => item.IsSkin())); |
| 0 | 202 | | loadingWearables = false; |
| 0 | 203 | | }) |
| | 204 | | .Catch((error) => |
| | 205 | | { |
| 0 | 206 | | ownedWearablesRemainingRequests--; |
| 0 | 207 | | if (ownedWearablesRemainingRequests > 0) |
| | 208 | | { |
| 0 | 209 | | Debug.LogWarning("Retrying owned wereables loading..."); |
| 0 | 210 | | LoadOwnedWereables(userProfile); |
| 0 | 211 | | } |
| | 212 | | else |
| | 213 | | { |
| 0 | 214 | | NotificationsController.i.ShowNotification(new Model |
| | 215 | | { |
| | 216 | | message = LOADING_OWNED_WEARABLES_ERROR_MESSAGE, |
| | 217 | | type = Type.GENERIC, |
| | 218 | | timer = 10f, |
| | 219 | | destroyOnFinish = true |
| | 220 | | }); |
| | 221 | |
|
| 0 | 222 | | Debug.LogError(error); |
| 0 | 223 | | loadingWearables = false; |
| | 224 | | } |
| 0 | 225 | | }); |
| 0 | 226 | | } |
| | 227 | |
|
| | 228 | | private void LoadOwnedEmotes() |
| | 229 | | { |
| | 230 | | //Only check emotes once every 60 seconds |
| 43 | 231 | | if (Time.realtimeSinceStartup < lastTimeOwnedEmotesChecked + 60) |
| 0 | 232 | | return; |
| | 233 | |
|
| 43 | 234 | | lastTimeOwnedEmotesChecked = Time.realtimeSinceStartup; |
| | 235 | | //TODO only request OwnedEmotes once every minute |
| 43 | 236 | | loadEmotesCTS?.Cancel(); |
| 43 | 237 | | loadEmotesCTS?.Dispose(); |
| 43 | 238 | | loadEmotesCTS = null; |
| | 239 | | // we only follow this flow with new profiles |
| 43 | 240 | | if (userProfile?.avatar != null) |
| | 241 | | { |
| 43 | 242 | | loadEmotesCTS = new CancellationTokenSource(); |
| 43 | 243 | | LoadOwnedEmotesTask(loadEmotesCTS.Token); |
| | 244 | | } |
| 43 | 245 | | } |
| | 246 | |
|
| | 247 | | private async UniTaskVoid LoadOwnedEmotesTask(CancellationToken ct = default, int retries = LOADING_OWNED_WEARABLES_ |
| | 248 | | { |
| 43 | 249 | | var emotesCatalog = Environment.i.serviceLocator.Get<IEmotesCatalogService>(); |
| | 250 | | try |
| | 251 | | { |
| 43 | 252 | | var embeddedEmotes = Resources.Load<EmbeddedEmotesSO>("EmbeddedEmotes").emotes; |
| 43 | 253 | | var emotes = await emotesCatalog.RequestOwnedEmotesAsync(userProfile.userId, ct); |
| 43 | 254 | | var emotesList = emotes == null ? embeddedEmotes.Cast<WearableItem>().ToList() : emotes.Concat(embeddedEmote |
| 43 | 255 | | var emotesFilter = new HashSet<string>(); |
| 1720 | 256 | | foreach (var e in emotesList) |
| 817 | 257 | | emotesFilter.Add(e.id); |
| | 258 | |
|
| 43 | 259 | | if(loadingWearables) |
| 0 | 260 | | await UniTask.WaitWhile(() => loadingWearables, cancellationToken: ct); |
| | 261 | |
|
| 43 | 262 | | if (emotesLoadedAsWearables != null) |
| | 263 | | { |
| 0 | 264 | | foreach (var emoteAsWearable in emotesLoadedAsWearables) |
| | 265 | | { |
| 0 | 266 | | if (emotesFilter.Contains(emoteAsWearable.id)) |
| | 267 | | continue; |
| | 268 | |
|
| 0 | 269 | | emotesList.Add(emoteAsWearable); |
| | 270 | | } |
| | 271 | |
|
| 0 | 272 | | emotesLoadedAsWearables = null; |
| | 273 | | } |
| | 274 | |
|
| 43 | 275 | | emotesCustomizationDataStore.UnequipMissingEmotes(emotesList); |
| 43 | 276 | | emotesCustomizationComponentController.SetEmotes(emotesList.ToArray()); |
| | 277 | |
|
| 43 | 278 | | } |
| 0 | 279 | | catch (Exception e) |
| | 280 | | { |
| 0 | 281 | | OperationCanceledException opCanceled = e as OperationCanceledException; |
| | 282 | | // If the cancellation was requested upwards, dont retry |
| 0 | 283 | | if (opCanceled != null && ct.IsCancellationRequested) |
| 0 | 284 | | return; |
| | 285 | |
|
| 0 | 286 | | if (retries > 0) |
| | 287 | | { |
| 0 | 288 | | LoadOwnedEmotesTask(ct, retries - 1); |
| 0 | 289 | | } |
| | 290 | | else |
| | 291 | | { |
| 0 | 292 | | if (opCanceled == null) // Ignore operation canceled exceptions when logging |
| 0 | 293 | | Debug.LogWarning(e.ToString()); |
| | 294 | | const string ERROR = "There was a problem loading your emotes"; |
| 0 | 295 | | NotificationsController.i.ShowNotification(new Model |
| | 296 | | { |
| | 297 | | message = ERROR, |
| | 298 | | type = Type.GENERIC, |
| | 299 | | timer = 10f, |
| | 300 | | destroyOnFinish = true |
| | 301 | | }); |
| | 302 | | } |
| 0 | 303 | | } |
| 43 | 304 | | } |
| | 305 | |
|
| | 306 | | private void QueryNftCollections(string userId) |
| | 307 | | { |
| 43 | 308 | | if (string.IsNullOrEmpty(userId)) |
| 43 | 309 | | return; |
| | 310 | |
|
| 0 | 311 | | Environment.i.platform.serviceProviders.theGraph.QueryNftCollections(userProfile.userId, NftCollectionsLayer.ETH |
| 0 | 312 | | .Then((nfts) => ownedNftCollectionsL1 = nfts) |
| 0 | 313 | | .Catch((error) => Debug.LogError(error)); |
| | 314 | |
|
| 0 | 315 | | Environment.i.platform.serviceProviders.theGraph.QueryNftCollections(userProfile.userId, NftCollectionsLayer.MAT |
| 0 | 316 | | .Then((nfts) => ownedNftCollectionsL2 = nfts) |
| 0 | 317 | | .Catch((error) => Debug.LogError(error)); |
| 0 | 318 | | } |
| | 319 | |
|
| | 320 | | public void RetryLoadOwnedWearables() |
| | 321 | | { |
| 0 | 322 | | ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES; |
| 0 | 323 | | LoadOwnedWereables(userProfile); |
| 0 | 324 | | LoadOwnedEmotes(); |
| 0 | 325 | | } |
| | 326 | |
|
| | 327 | | private void PlayerRendererLoaded(bool current, bool previous) |
| | 328 | | { |
| 15 | 329 | | if (!current) |
| 0 | 330 | | return; |
| | 331 | |
|
| 15 | 332 | | if (!ownedWearablesAlreadyLoaded) |
| | 333 | | { |
| 15 | 334 | | List<string> equippedOwnedWearables = new List<string>(); |
| 78 | 335 | | for (int i = 0; i < userProfile.avatar.wearables.Count; i++) |
| | 336 | | { |
| 24 | 337 | | if (catalog.TryGetValue(userProfile.avatar.wearables[i], out WearableItem wearable) && |
| | 338 | | !wearable.data.tags.Contains(WearableLiterals.Tags.BASE_WEARABLE)) |
| | 339 | | { |
| 0 | 340 | | equippedOwnedWearables.Add(userProfile.avatar.wearables[i]); |
| | 341 | | } |
| | 342 | | } |
| | 343 | |
|
| 15 | 344 | | userProfile.SetInventory(equippedOwnedWearables.ToArray()); |
| | 345 | | } |
| | 346 | |
|
| 15 | 347 | | LoadUserProfile(userProfile, true); |
| 15 | 348 | | DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| 15 | 349 | | } |
| | 350 | |
|
| | 351 | | public void LoadUserProfile(UserProfile userProfile, bool forceLoading) |
| | 352 | | { |
| 106 | 353 | | bool avatarEditorNotVisible = renderingEnabled && !view.isOpen; |
| 106 | 354 | | bool isPlaying = !Application.isBatchMode; |
| | 355 | |
|
| 106 | 356 | | if (!forceLoading) |
| | 357 | | { |
| 43 | 358 | | if (isPlaying && avatarEditorNotVisible) |
| 0 | 359 | | return; |
| | 360 | | } |
| | 361 | |
|
| 106 | 362 | | if (userProfile == null) |
| 0 | 363 | | return; |
| | 364 | |
|
| 106 | 365 | | if (userProfile.avatar == null || string.IsNullOrEmpty(userProfile.avatar.bodyShape)) |
| 3 | 366 | | return; |
| | 367 | |
|
| 103 | 368 | | view.InitializeNavigationEvents(!userProfile.hasConnectedWeb3); |
| | 369 | |
|
| 103 | 370 | | CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.bodyShape, out var bodyShape); |
| | 371 | |
|
| 103 | 372 | | if (bodyShape == null) |
| | 373 | | { |
| 0 | 374 | | return; |
| | 375 | | } |
| | 376 | |
|
| 103 | 377 | | view.SetIsWeb3(userProfile.hasConnectedWeb3); |
| | 378 | |
|
| 103 | 379 | | ProcessCatalog(this.catalog); |
| 103 | 380 | | EquipBodyShape(bodyShape); |
| 103 | 381 | | EquipSkinColor(userProfile.avatar.skinColor); |
| 103 | 382 | | EquipHairColor(userProfile.avatar.hairColor); |
| 103 | 383 | | EquipEyesColor(userProfile.avatar.eyeColor); |
| | 384 | |
|
| 103 | 385 | | model.wearables.Clear(); |
| 103 | 386 | | view.UnselectAllWearables(); |
| | 387 | |
|
| 103 | 388 | | int wearablesCount = userProfile.avatar.wearables.Count; |
| | 389 | |
|
| 103 | 390 | | if (isPlayerRendererLoaded) |
| | 391 | | { |
| 180 | 392 | | for (var i = 0; i < wearablesCount; i++) |
| | 393 | | { |
| 55 | 394 | | CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.wearables[i], out var wearable); |
| 55 | 395 | | if (wearable == null) |
| | 396 | | { |
| 0 | 397 | | Debug.LogError($"Couldn't find wearable with ID {userProfile.avatar.wearables[i]}"); |
| 0 | 398 | | continue; |
| | 399 | | } |
| | 400 | |
|
| 55 | 401 | | if (wearable.IsEmote()) |
| 0 | 402 | | EquipEmote(wearable); |
| | 403 | | else |
| 55 | 404 | | EquipWearable(wearable); |
| | 405 | | } |
| | 406 | | } |
| | 407 | |
|
| 103 | 408 | | EnsureWearablesCategoriesNotEmpty(); |
| | 409 | |
|
| 103 | 410 | | UpdateAvatarPreview(true); |
| 103 | 411 | | isAvatarPreviewReady = true; |
| 103 | 412 | | } |
| | 413 | |
|
| | 414 | | private void EnsureWearablesCategoriesNotEmpty() |
| | 415 | | { |
| 103 | 416 | | var categoriesInUse = model.wearables |
| 55 | 417 | | .Where(x => !x.IsEmote()) |
| 55 | 418 | | .Select(x => x.data.category).ToArray(); |
| | 419 | |
|
| 1648 | 420 | | for (var i = 0; i < categoriesThatMustHaveSelection.Length; i++) |
| | 421 | | { |
| 721 | 422 | | var category = categoriesThatMustHaveSelection[i]; |
| 721 | 423 | | if (category != Categories.BODY_SHAPE && !(categoriesInUse.Contains(category))) |
| | 424 | | { |
| | 425 | | WearableItem wearable; |
| 576 | 426 | | var defaultItemId = WearableLiterals.DefaultWearables.GetDefaultWearable(model.bodyShape.id, category); |
| 576 | 427 | | if (defaultItemId != null) |
| | 428 | | { |
| 576 | 429 | | CatalogController.wearableCatalog.TryGetValue(defaultItemId, out wearable); |
| 576 | 430 | | } |
| | 431 | | else |
| | 432 | | { |
| 0 | 433 | | wearable = wearablesByCategory[category].FirstOrDefault(x => x.SupportsBodyShape(model.bodyShape.id) |
| | 434 | | } |
| | 435 | |
|
| 576 | 436 | | if (wearable != null) |
| | 437 | | { |
| 576 | 438 | | EquipWearable(wearable); |
| | 439 | | } |
| | 440 | | } |
| | 441 | | } |
| 103 | 442 | | } |
| | 443 | |
|
| | 444 | | public void WearableClicked(string wearableId) |
| | 445 | | { |
| 20 | 446 | | CatalogController.wearableCatalog.TryGetValue(wearableId, out var wearable); |
| 23 | 447 | | if (wearable == null) return; |
| | 448 | |
|
| 17 | 449 | | if (wearable.data.category == Categories.BODY_SHAPE) |
| | 450 | | { |
| 3 | 451 | | if (wearable.id == model.bodyShape.id) |
| 0 | 452 | | return; |
| 3 | 453 | | EquipBodyShape(wearable); |
| 3 | 454 | | } |
| | 455 | | else |
| | 456 | | { |
| 14 | 457 | | if (model.wearables.Contains(wearable)) |
| | 458 | | { |
| 2 | 459 | | if (!categoriesThatMustHaveSelection.Contains(wearable.data.category)) |
| | 460 | | { |
| 0 | 461 | | UnequipWearable(wearable); |
| 0 | 462 | | } |
| | 463 | | else |
| | 464 | | { |
| 2 | 465 | | return; |
| | 466 | | } |
| | 467 | | } |
| | 468 | | else |
| | 469 | | { |
| 12 | 470 | | if (IsTryingToReplaceSkin(wearable)) |
| 0 | 471 | | UnequipWearable(model.GetWearable(Categories.SKIN)); |
| | 472 | |
|
| 12 | 473 | | var sameCategoryEquipped = model.GetWearable(wearable.data.category); |
| 12 | 474 | | if (sameCategoryEquipped != null) |
| 2 | 475 | | UnequipWearable(sameCategoryEquipped); |
| | 476 | |
|
| 12 | 477 | | EquipWearable(wearable); |
| | 478 | | } |
| | 479 | | } |
| | 480 | |
|
| 15 | 481 | | UpdateAvatarPreview(false); |
| 15 | 482 | | } |
| | 483 | |
|
| | 484 | | public void HairColorClicked(Color color) |
| | 485 | | { |
| 2 | 486 | | EquipHairColor(color); |
| 2 | 487 | | view.SelectHairColor(model.hairColor); |
| 2 | 488 | | UpdateAvatarPreview(true); |
| 2 | 489 | | } |
| | 490 | |
|
| | 491 | | public void SkinColorClicked(Color color) |
| | 492 | | { |
| 2 | 493 | | EquipSkinColor(color); |
| 2 | 494 | | view.SelectSkinColor(model.skinColor); |
| 2 | 495 | | UpdateAvatarPreview(true); |
| 2 | 496 | | } |
| | 497 | |
|
| | 498 | | public void EyesColorClicked(Color color) |
| | 499 | | { |
| 2 | 500 | | EquipEyesColor(color); |
| 2 | 501 | | view.SelectEyeColor(model.eyesColor); |
| 2 | 502 | | UpdateAvatarPreview(true); |
| 2 | 503 | | } |
| | 504 | |
|
| | 505 | | protected virtual void UpdateAvatarPreview(bool skipAudio) |
| | 506 | | { |
| 125 | 507 | | if (bypassUpdateAvatarPreview) |
| 0 | 508 | | return; |
| | 509 | |
|
| 125 | 510 | | AvatarModel modelToUpdate = model.ToAvatarModel(); |
| | 511 | |
|
| | 512 | | // We always keep the loaded emotes into the Avatar Preview |
| 5000 | 513 | | foreach (string emoteId in emotesCustomizationDataStore.currentLoadedEmotes.Get()) |
| | 514 | | { |
| 2375 | 515 | | modelToUpdate.emotes.Add(new AvatarModel.AvatarEmoteEntry() { urn = emoteId }); |
| | 516 | | } |
| | 517 | |
|
| 125 | 518 | | view.UpdateAvatarPreview(modelToUpdate, skipAudio); |
| 125 | 519 | | } |
| | 520 | |
|
| | 521 | | private void EquipHairColor(Color color) |
| | 522 | | { |
| 106 | 523 | | model.hairColor = color; |
| 106 | 524 | | view.SelectHairColor(model.hairColor); |
| 106 | 525 | | } |
| | 526 | |
|
| | 527 | | private void EquipEyesColor(Color color) |
| | 528 | | { |
| 106 | 529 | | model.eyesColor = color; |
| 106 | 530 | | view.SelectEyeColor(model.eyesColor); |
| 106 | 531 | | } |
| | 532 | |
|
| | 533 | | private void EquipSkinColor(Color color) |
| | 534 | | { |
| 105 | 535 | | model.skinColor = color; |
| 105 | 536 | | view.SelectSkinColor(model.skinColor); |
| 105 | 537 | | } |
| | 538 | |
|
| | 539 | | private void EquipBodyShape(WearableItem bodyShape) |
| | 540 | | { |
| 106 | 541 | | if (bodyShape.data.category != Categories.BODY_SHAPE) |
| | 542 | | { |
| 0 | 543 | | Debug.LogError($"Item ({bodyShape.id} is not a body shape"); |
| 0 | 544 | | return; |
| | 545 | | } |
| | 546 | |
|
| 106 | 547 | | if (model.bodyShape == bodyShape) |
| 44 | 548 | | return; |
| | 549 | |
|
| 62 | 550 | | model.bodyShape = bodyShape; |
| 62 | 551 | | emotesCustomizationComponentController.SetEquippedBodyShape(bodyShape.id); |
| 62 | 552 | | view.UpdateSelectedBody(bodyShape); |
| | 553 | |
|
| 62 | 554 | | int wearablesCount = model.wearables.Count; |
| 182 | 555 | | for (var i = wearablesCount - 1; i >= 0; i--) |
| | 556 | | { |
| 29 | 557 | | UnequipWearable(model.wearables[i]); |
| | 558 | | } |
| | 559 | |
|
| 62 | 560 | | var defaultWearables = WearableLiterals.DefaultWearables.GetDefaultWearables(bodyShape.id); |
| 1022 | 561 | | for (var i = 0; i < defaultWearables.Length; i++) |
| | 562 | | { |
| 449 | 563 | | if (catalog.TryGetValue(defaultWearables[i], out var wearable)) |
| 449 | 564 | | EquipWearable(wearable); |
| | 565 | | } |
| 62 | 566 | | } |
| | 567 | |
|
| | 568 | | private void EquipWearable(WearableItem wearable) |
| | 569 | | { |
| 1099 | 570 | | if (wearable.IsEmote()) |
| 0 | 571 | | return; |
| | 572 | |
|
| 1099 | 573 | | if (!wearablesByCategory.ContainsKey(wearable.data.category)) |
| 0 | 574 | | return; |
| | 575 | |
|
| 1099 | 576 | | if (wearablesByCategory[wearable.data.category].Contains(wearable) && wearable.SupportsBodyShape(model.bodyShape |
| | 577 | | { |
| 1099 | 578 | | var toReplace = GetWearablesReplacedBy(wearable); |
| 1099 | 579 | | toReplace.ForEach(UnequipWearable); |
| 1099 | 580 | | model.wearables.Add(wearable); |
| 1099 | 581 | | view.EquipWearable(wearable); |
| 1099 | 582 | | avatarIsDirty = true; |
| | 583 | | } |
| 1099 | 584 | | } |
| | 585 | |
|
| | 586 | | private void UnequipWearable(WearableItem wearable) |
| | 587 | | { |
| 33 | 588 | | if (wearable.IsEmote()) |
| 0 | 589 | | return; |
| | 590 | |
|
| 33 | 591 | | if (model.wearables.Contains(wearable)) |
| | 592 | | { |
| 33 | 593 | | model.wearables.Remove(wearable); |
| 33 | 594 | | view.UnequipWearable(wearable); |
| 33 | 595 | | avatarIsDirty = true; |
| | 596 | | } |
| 33 | 597 | | } |
| | 598 | |
|
| | 599 | | private void EquipEmote(WearableItem emote) |
| | 600 | | { |
| 0 | 601 | | if (!emote.IsEmote()) |
| 0 | 602 | | return; |
| 0 | 603 | | avatarIsDirty = true; |
| 0 | 604 | | } |
| | 605 | |
|
| | 606 | | private void UnequipEmote(WearableItem emote) |
| | 607 | | { |
| 0 | 608 | | if (!emote.IsEmote()) |
| 0 | 609 | | return; |
| | 610 | |
|
| 0 | 611 | | avatarIsDirty = true; |
| 0 | 612 | | } |
| | 613 | |
|
| | 614 | | public void UnequipAllWearables() |
| | 615 | | { |
| 1012 | 616 | | foreach (var wearable in model.wearables) |
| | 617 | | { |
| 431 | 618 | | if (!wearable.IsEmote()) |
| 431 | 619 | | view.UnequipWearable(wearable); |
| | 620 | | } |
| | 621 | |
|
| 75 | 622 | | model.wearables.Clear(); |
| 75 | 623 | | } |
| | 624 | |
|
| | 625 | | private void ProcessCatalog(BaseDictionary<string, WearableItem> catalog) |
| | 626 | | { |
| 151 | 627 | | wearablesByCategory.Clear(); |
| 151 | 628 | | view.RemoveAllWearables(); |
| 151 | 629 | | using (var iterator = catalog.Get().GetEnumerator()) |
| | 630 | | { |
| 5551 | 631 | | while (iterator.MoveNext()) |
| | 632 | | { |
| 5400 | 633 | | if (iterator.Current.Value.IsEmote()) |
| | 634 | | continue; |
| | 635 | |
|
| 5400 | 636 | | AddWearable(iterator.Current.Key, iterator.Current.Value); |
| | 637 | | } |
| 151 | 638 | | } |
| | 639 | |
|
| 151 | 640 | | view.RefreshSelectorsSize(); |
| 151 | 641 | | } |
| | 642 | |
|
| | 643 | | private void AddWearable(string id, WearableItem wearable) |
| | 644 | | { |
| 5411 | 645 | | if (!wearable.data.tags.Contains(WearableLiterals.Tags.BASE_WEARABLE) && userProfile.GetItemAmount(id) == 0) |
| 1190 | 646 | | return; |
| | 647 | |
|
| 4221 | 648 | | if (!wearablesByCategory.ContainsKey(wearable.data.category)) |
| 1650 | 649 | | wearablesByCategory.Add(wearable.data.category, new List<WearableItem>()); |
| | 650 | |
|
| 4221 | 651 | | wearablesByCategory[wearable.data.category].Add(wearable); |
| 4221 | 652 | | view.AddWearable(wearable, userProfile.GetItemAmount(id), |
| | 653 | | ShouldShowHideOtherWearablesToast, |
| | 654 | | ShouldShowReplaceOtherWearablesToast); |
| 4221 | 655 | | } |
| | 656 | |
|
| | 657 | | private void RemoveWearable(string id, WearableItem wearable) |
| | 658 | | { |
| 0 | 659 | | if (wearablesByCategory.ContainsKey(wearable.data.category)) |
| | 660 | | { |
| 0 | 661 | | if (wearablesByCategory[wearable.data.category].Remove(wearable)) |
| | 662 | | { |
| 0 | 663 | | if (wearablesByCategory[wearable.data.category].Count == 0) |
| | 664 | | { |
| 0 | 665 | | wearablesByCategory.Remove(wearable.data.category); |
| | 666 | | } |
| | 667 | | } |
| | 668 | | } |
| | 669 | |
|
| 0 | 670 | | view.RemoveWearable(wearable); |
| 0 | 671 | | } |
| | 672 | |
|
| | 673 | | public void RandomizeWearables() |
| | 674 | | { |
| 1 | 675 | | EquipHairColor(view.GetRandomColor()); |
| 1 | 676 | | EquipEyesColor(view.GetRandomColor()); |
| | 677 | |
|
| 7 | 678 | | List<WearableItem> wearablesToRemove = model.wearables.Where(x => !x.IsEmote()).ToList(); |
| 14 | 679 | | foreach (var wearable in wearablesToRemove) |
| | 680 | | { |
| 6 | 681 | | model.wearables.Remove(wearable); |
| | 682 | | } |
| | 683 | |
|
| 1 | 684 | | view.UnselectAllWearables(); |
| 1 | 685 | | using (var iterator = wearablesByCategory.GetEnumerator()) |
| | 686 | | { |
| 12 | 687 | | while (iterator.MoveNext()) |
| | 688 | | { |
| 11 | 689 | | string category = iterator.Current.Key; |
| 11 | 690 | | if (!categoriesToRandomize.Contains(category)) |
| | 691 | | { |
| | 692 | | continue; |
| | 693 | | } |
| | 694 | |
|
| 29 | 695 | | var supportedWearables = iterator.Current.Value.Where(x => x.SupportsBodyShape(model.bodyShape.id)).ToAr |
| 7 | 696 | | if (supportedWearables.Length == 0) |
| | 697 | | { |
| 0 | 698 | | Debug.LogError($"Couldn't get any wearable for category {category} and bodyshape {model.bodyShape.id |
| | 699 | | } |
| | 700 | |
|
| 7 | 701 | | var wearable = supportedWearables[Random.Range(0, supportedWearables.Length - 1)]; |
| 7 | 702 | | EquipWearable(wearable); |
| | 703 | | } |
| 1 | 704 | | } |
| | 705 | |
|
| 1 | 706 | | UpdateAvatarPreview(false); |
| 1 | 707 | | } |
| | 708 | |
|
| | 709 | | private List<WearableItem> GetWearablesReplacedBy(WearableItem wearableItem) |
| | 710 | | { |
| 1099 | 711 | | var wearablesToReplace = new List<WearableItem>(); |
| 1099 | 712 | | var categoriesToReplace = new HashSet<string>(wearableItem.GetReplacesList(model.bodyShape.id) ?? new string[0]) |
| | 713 | |
|
| 1099 | 714 | | int wearableCount = model.wearables.Count; |
| 8468 | 715 | | for (int i = 0; i < wearableCount; i++) |
| | 716 | | { |
| 3135 | 717 | | var wearable = model.wearables[i]; |
| 3135 | 718 | | if (wearable == null) continue; |
| | 719 | |
|
| 3135 | 720 | | if (categoriesToReplace.Contains(wearable.data.category)) |
| | 721 | | { |
| 2 | 722 | | wearablesToReplace.Add(wearable); |
| 2 | 723 | | } |
| | 724 | | else |
| | 725 | | { |
| | 726 | | //For retrocompatibility's sake we check current wearables against new one (compatibility matrix is symm |
| 3133 | 727 | | HashSet<string> replacesList = new HashSet<string>(wearable.GetReplacesList(model.bodyShape.id) ?? new s |
| 3133 | 728 | | if (replacesList.Contains(wearableItem.data.category)) |
| | 729 | | { |
| 0 | 730 | | wearablesToReplace.Add(wearable); |
| | 731 | | } |
| | 732 | | } |
| | 733 | | } |
| | 734 | |
|
| 1099 | 735 | | return wearablesToReplace; |
| | 736 | | } |
| | 737 | |
|
| 88 | 738 | | public void SetVisibility(bool visible) { avatarEditorVisible.Set(visible); } |
| | 739 | |
|
| 184 | 740 | | private void OnAvatarEditorVisibleChanged(bool current, bool previous) { SetVisibility_Internal(current); } |
| | 741 | |
|
| | 742 | | private void SetVisibility_Internal(bool visible) |
| | 743 | | { |
| 92 | 744 | | bool isSignUpFlow = DataStore.i.common.isSignUpFlow.Get(); |
| 92 | 745 | | if (!visible && view.isOpen) |
| | 746 | | { |
| 1 | 747 | | view.ResetPreviewEmote(); |
| | 748 | |
|
| 1 | 749 | | if (isSignUpFlow) |
| 0 | 750 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(1f); |
| | 751 | |
|
| 1 | 752 | | Environment.i.messaging.manager.paused = false; |
| 1 | 753 | | DataStore.i.skyboxConfig.avatarMatProfile.Set(AvatarMaterialProfile.InWorld); |
| 1 | 754 | | if (prevMouseLockState && isSignUpFlow) |
| | 755 | | { |
| 0 | 756 | | Utils.LockCursor(); |
| | 757 | | } |
| | 758 | |
|
| | 759 | | // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0 |
| 1 | 760 | | var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| 1 | 761 | | asset.renderScale = prevRenderScale; |
| | 762 | |
|
| 1 | 763 | | if (isSignUpFlow) |
| 0 | 764 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(false); |
| | 765 | |
|
| 1 | 766 | | DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| | 767 | |
|
| 1 | 768 | | OnClose?.Invoke(); |
| 0 | 769 | | } |
| 91 | 770 | | else if (visible && !view.isOpen) |
| | 771 | | { |
| 43 | 772 | | if (isSignUpFlow) |
| | 773 | | { |
| 0 | 774 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(0f); |
| 0 | 775 | | view.sectionSelector.Hide(true); |
| 0 | 776 | | } |
| | 777 | | else |
| | 778 | | { |
| 43 | 779 | | view.sectionSelector.Show(true); |
| | 780 | | } |
| | 781 | |
|
| 43 | 782 | | LoadOwnedWereables(userProfile); |
| 43 | 783 | | if (!isSignUpFlow) |
| 43 | 784 | | LoadOwnedEmotes(); |
| | 785 | |
|
| 43 | 786 | | LoadCollections(); |
| 43 | 787 | | Environment.i.messaging.manager.paused = isSignUpFlow; |
| 43 | 788 | | DataStore.i.skyboxConfig.avatarMatProfile.Set(AvatarMaterialProfile.InEditor); |
| | 789 | |
|
| 43 | 790 | | prevMouseLockState = Utils.IsCursorLocked; |
| | 791 | |
|
| 43 | 792 | | if (isSignUpFlow || !DataStore.i.exploreV2.isInitialized.Get()) |
| 43 | 793 | | Utils.UnlockCursor(); |
| | 794 | |
|
| | 795 | | // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0 |
| 43 | 796 | | var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| 43 | 797 | | prevRenderScale = asset.renderScale; |
| 43 | 798 | | asset.renderScale = 1.0f; |
| | 799 | |
|
| 43 | 800 | | if (isSignUpFlow) |
| 0 | 801 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(true); |
| | 802 | |
|
| 43 | 803 | | DataStore.i.common.isPlayerRendererLoaded.OnChange += PlayerRendererLoaded; |
| | 804 | |
|
| 43 | 805 | | OnOpen?.Invoke(); |
| | 806 | | } |
| | 807 | |
|
| 92 | 808 | | view.SetVisibility(visible); |
| 92 | 809 | | } |
| | 810 | |
|
| | 811 | | public void Dispose() |
| | 812 | | { |
| 43 | 813 | | loadEmotesCTS?.Cancel(); |
| 43 | 814 | | loadEmotesCTS?.Dispose(); |
| 43 | 815 | | loadEmotesCTS = null; |
| | 816 | |
|
| 43 | 817 | | avatarEditorVisible.OnChange -= OnAvatarEditorVisibleChanged; |
| 43 | 818 | | configureBackpackInFullscreenMenu.OnChange -= ConfigureBackpackInFullscreenMenuChanged; |
| 43 | 819 | | DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| 43 | 820 | | exploreV2IsOpen.OnChange -= ExploreV2IsOpenChanged; |
| 43 | 821 | | emotesCustomizationDataStore.isEmotesCustomizationSelected.OnChange -= HandleEmotesCostumizationSelection; |
| 43 | 822 | | emotesCustomizationDataStore.currentLoadedEmotes.OnAdded -= OnNewEmoteAdded; |
| | 823 | |
|
| 43 | 824 | | emotesCustomizationComponentController.onEmotePreviewed -= OnPreviewEmote; |
| 43 | 825 | | emotesCustomizationComponentController.onEmoteEquipped -= OnEmoteEquipped; |
| 43 | 826 | | emotesCustomizationComponentController.onEmoteUnequipped -= OnEmoteUnequipped; |
| 43 | 827 | | emotesCustomizationComponentController.onEmoteSell -= OnRedirectToEmoteSelling; |
| | 828 | |
|
| 43 | 829 | | CleanUp(); |
| 43 | 830 | | } |
| | 831 | |
|
| | 832 | | public void CleanUp() |
| | 833 | | { |
| 48 | 834 | | UnequipAllWearables(); |
| | 835 | |
|
| 48 | 836 | | if (view != null) |
| 48 | 837 | | view.CleanUp(); |
| | 838 | |
|
| 48 | 839 | | this.userProfile.OnUpdate -= LoadUserProfile; |
| 48 | 840 | | this.catalog.OnAdded -= AddWearable; |
| 48 | 841 | | this.catalog.OnRemoved -= RemoveWearable; |
| 48 | 842 | | DataStore.i.common.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| 48 | 843 | | } |
| | 844 | |
|
| 0 | 845 | | public void SetConfiguration(HUDConfiguration configuration) { SetVisibility(configuration.active); } |
| | 846 | |
|
| | 847 | | public void SaveAvatar(Texture2D face256Snapshot, Texture2D bodySnapshot) |
| | 848 | | { |
| 1 | 849 | | var avatarModel = model.ToAvatarModel(); |
| | 850 | |
|
| | 851 | | // Add the equipped emotes to the avatar model |
| 1 | 852 | | List<AvatarModel.AvatarEmoteEntry> emoteEntries = new List<AvatarModel.AvatarEmoteEntry>(); |
| 1 | 853 | | int equippedEmotesCount = emotesCustomizationDataStore.unsavedEquippedEmotes.Count(); |
| 22 | 854 | | for (int i = 0; i < equippedEmotesCount; i++) |
| | 855 | | { |
| 10 | 856 | | var equippedEmote = emotesCustomizationDataStore.unsavedEquippedEmotes[i]; |
| 10 | 857 | | if (equippedEmote == null) |
| | 858 | | continue; |
| 0 | 859 | | emoteEntries.Add(new AvatarModel.AvatarEmoteEntry { slot = i, urn = equippedEmote.id }); |
| | 860 | | } |
| | 861 | |
|
| 1 | 862 | | avatarModel.emotes = emoteEntries; |
| | 863 | |
|
| 1 | 864 | | SendNewEquippedWearablesAnalytics(userProfile.avatar.wearables, avatarModel.wearables); |
| 1 | 865 | | emotesCustomizationDataStore.equippedEmotes.Set(emotesCustomizationDataStore.unsavedEquippedEmotes.Get()); |
| | 866 | |
|
| | 867 | |
|
| 1 | 868 | | WebInterface.SendSaveAvatar(avatarModel, face256Snapshot, bodySnapshot, DataStore.i.common.isSignUpFlow.Get()); |
| 1 | 869 | | userProfile.OverrideAvatar(avatarModel, face256Snapshot); |
| | 870 | |
|
| 1 | 871 | | if (DataStore.i.common.isSignUpFlow.Get()) |
| | 872 | | { |
| 0 | 873 | | DataStore.i.HUDs.signupVisible.Set(true); |
| 0 | 874 | | newUserExperienceAnalytics.AvatarEditSuccessNux(); |
| | 875 | | } |
| | 876 | |
|
| | 877 | |
|
| 1 | 878 | | avatarIsDirty = false; |
| 1 | 879 | | SetVisibility(false); |
| 1 | 880 | | } |
| | 881 | |
|
| | 882 | | public void GoToMarketplaceOrConnectWallet() |
| | 883 | | { |
| 0 | 884 | | if (userProfile.hasConnectedWeb3) |
| 0 | 885 | | WebInterface.OpenURL(URL_MARKET_PLACE); |
| | 886 | | else |
| 0 | 887 | | WebInterface.OpenURL(URL_GET_A_WALLET); |
| 0 | 888 | | } |
| | 889 | |
|
| | 890 | | public void SellCollectible(string collectibleId) |
| | 891 | | { |
| 0 | 892 | | var ownedCollectible = ownedNftCollectionsL1.FirstOrDefault(nft => nft.urn == collectibleId); |
| 0 | 893 | | if (ownedCollectible == null) |
| 0 | 894 | | ownedCollectible = ownedNftCollectionsL2.FirstOrDefault(nft => nft.urn == collectibleId); |
| | 895 | |
|
| 0 | 896 | | if (ownedCollectible != null) |
| 0 | 897 | | WebInterface.OpenURL(URL_SELL_SPECIFIC_COLLECTIBLE.Replace("{collectionId}", ownedCollectible.collectionId). |
| | 898 | | else |
| 0 | 899 | | WebInterface.OpenURL(URL_SELL_COLLECTIBLE_GENERIC); |
| 0 | 900 | | } |
| | 901 | |
|
| 0 | 902 | | public void ToggleVisibility() { SetVisibility(!view.isOpen); } |
| | 903 | |
|
| 96 | 904 | | private void ConfigureBackpackInFullscreenMenuChanged(Transform currentParentTransform, Transform previousParentTran |
| | 905 | |
|
| | 906 | | private void ExploreV2IsOpenChanged(bool current, bool previous) |
| | 907 | | { |
| 0 | 908 | | if (!current && avatarIsDirty) |
| | 909 | | { |
| 0 | 910 | | LoadUserProfile(userProfile, true); |
| | 911 | |
|
| 0 | 912 | | emotesCustomizationComponentController.RestoreEmoteSlots(); |
| | 913 | |
|
| 0 | 914 | | avatarIsDirty = false; |
| | 915 | | } |
| 0 | 916 | | } |
| | 917 | |
|
| | 918 | | private void LoadCollections() |
| | 919 | | { |
| 43 | 920 | | if (!isThirdPartyCollectionsEnabled || collectionsAlreadyLoaded) |
| 43 | 921 | | return; |
| | 922 | |
|
| 0 | 923 | | WearablesFetchingHelper.GetThirdPartyCollections() |
| | 924 | | .Then((collections) => |
| | 925 | | { |
| 0 | 926 | | view.LoadCollectionsDropdown(collections); |
| 0 | 927 | | collectionsAlreadyLoaded = true; |
| 0 | 928 | | LoadUserThirdPartyWearables(); |
| 0 | 929 | | }) |
| 0 | 930 | | .Catch((error) => Debug.LogError(error)); |
| 0 | 931 | | } |
| | 932 | |
|
| | 933 | | private void LoadUserThirdPartyWearables() |
| | 934 | | { |
| 0 | 935 | | List<string> collectionIdsToLoad = new List<string>(); |
| 0 | 936 | | foreach (string wearableId in userProfile.avatar.wearables) |
| | 937 | | { |
| 0 | 938 | | CatalogController.wearableCatalog.TryGetValue(wearableId, out var wearable); |
| | 939 | |
|
| 0 | 940 | | if (wearable != null && wearable.IsFromThirdPartyCollection) |
| | 941 | | { |
| 0 | 942 | | if (!collectionIdsToLoad.Contains(wearable.ThirdPartyCollectionId)) |
| 0 | 943 | | collectionIdsToLoad.Add(wearable.ThirdPartyCollectionId); |
| | 944 | | } |
| | 945 | | } |
| | 946 | |
|
| 0 | 947 | | foreach (string collectionId in collectionIdsToLoad) |
| | 948 | | { |
| 0 | 949 | | view.ToggleThirdPartyCollection(collectionId, true); |
| | 950 | | } |
| 0 | 951 | | } |
| | 952 | |
|
| | 953 | | public void ToggleThirdPartyCollection(bool isOn, string collectionId, string collectionName) |
| | 954 | | { |
| 1 | 955 | | if (isOn) |
| 1 | 956 | | FetchAndShowThirdPartyCollection(collectionId, collectionName); |
| | 957 | | else |
| 0 | 958 | | RemoveThirdPartyCollection(collectionId); |
| 0 | 959 | | } |
| | 960 | |
|
| | 961 | | private void FetchAndShowThirdPartyCollection(string collectionId, string collectionName) |
| | 962 | | { |
| 1 | 963 | | view.BlockCollectionsDropdown(true); |
| 1 | 964 | | CatalogController.RequestThirdPartyWearablesByCollection(userProfile.userId, collectionId) |
| | 965 | | .Then(wearables => |
| | 966 | | { |
| 0 | 967 | | if (wearables.Count().Equals(0)) view.ShowNoItemOfWearableCollectionWarning(); |
| | 968 | |
|
| 0 | 969 | | foreach (var wearable in wearables) |
| | 970 | | { |
| 0 | 971 | | if (!userProfile.ContainsInInventory(wearable.id)) |
| | 972 | | { |
| 0 | 973 | | userProfile.AddToInventory(wearable.id); |
| | 974 | |
|
| 0 | 975 | | if (!thirdPartyWearablesLoaded.Contains(wearable.id)) |
| 0 | 976 | | thirdPartyWearablesLoaded.Add(wearable.id); |
| | 977 | | } |
| | 978 | | } |
| | 979 | |
|
| 0 | 980 | | view.BlockCollectionsDropdown(false); |
| 0 | 981 | | LoadUserProfile(userProfile, true); |
| 0 | 982 | | }) |
| | 983 | | .Catch((error) => |
| | 984 | | { |
| 0 | 985 | | view.BlockCollectionsDropdown(false); |
| 0 | 986 | | Debug.LogError(error); |
| 0 | 987 | | }); |
| 1 | 988 | | } |
| | 989 | |
|
| | 990 | | private void RemoveThirdPartyCollection(string collectionId) |
| | 991 | | { |
| 0 | 992 | | var wearablesToRemove = CatalogController.i.Wearables.GetValues() |
| 0 | 993 | | .Where(wearable => !userProfile.HasEquipped(wearable.id) |
| | 994 | | && wearable.ThirdPartyCollectionId == collectionId) |
| 0 | 995 | | .Select(item => item.id) |
| | 996 | | .ToList(); |
| 0 | 997 | | CatalogController.i.Remove(wearablesToRemove); |
| | 998 | |
|
| 0 | 999 | | foreach (string wearableId in wearablesToRemove) |
| | 1000 | | { |
| 0 | 1001 | | userProfile.RemoveFromInventory(wearableId); |
| 0 | 1002 | | thirdPartyWearablesLoaded.Remove(wearableId); |
| | 1003 | | } |
| | 1004 | |
|
| 0 | 1005 | | LoadUserProfile(userProfile, true); |
| 0 | 1006 | | } |
| | 1007 | |
|
| | 1008 | | private bool ShouldShowHideOtherWearablesToast(WearableItem wearable) |
| | 1009 | | { |
| 0 | 1010 | | var isWearingSkinAlready = model.wearables.Any(item => item.IsSkin()); |
| 0 | 1011 | | return wearable.IsSkin() && !isWearingSkinAlready; |
| | 1012 | | } |
| | 1013 | |
|
| | 1014 | | private bool IsTryingToReplaceSkin(WearableItem wearable) |
| | 1015 | | { |
| 12 | 1016 | | return model.wearables.Any(skin => |
| | 1017 | | { |
| 80 | 1018 | | return skin.IsSkin() |
| | 1019 | | && skin.DoesHide(wearable.data.category, model.bodyShape.id); |
| | 1020 | | }); |
| | 1021 | | } |
| | 1022 | |
|
| | 1023 | | private bool ShouldShowReplaceOtherWearablesToast(WearableItem wearable) |
| | 1024 | | { |
| 0 | 1025 | | if (IsTryingToReplaceSkin(wearable)) return true; |
| 0 | 1026 | | var toReplace = GetWearablesReplacedBy(wearable); |
| 0 | 1027 | | if (wearable == null || toReplace.Count == 0) return false; |
| 0 | 1028 | | if (model.wearables.Contains(wearable)) return false; |
| | 1029 | |
|
| | 1030 | | // NOTE: why just 1? |
| 0 | 1031 | | if (toReplace.Count == 1) |
| | 1032 | | { |
| 0 | 1033 | | var w = toReplace[0]; |
| 0 | 1034 | | if (w.data.category == wearable.data.category) |
| 0 | 1035 | | return false; |
| | 1036 | | } |
| 0 | 1037 | | return true; |
| | 1038 | | } |
| | 1039 | |
|
| | 1040 | |
|
| | 1041 | | private void HandleEmotesCostumizationSelection(bool current, bool previous) |
| | 1042 | | { |
| 0 | 1043 | | if (!current) |
| 0 | 1044 | | return; |
| | 1045 | |
|
| 0 | 1046 | | view.sectionSelector.GetSection(AvatarEditorHUDView.EMOTES_SECTION_INDEX).SelectToggle(); |
| 0 | 1047 | | } |
| | 1048 | |
|
| | 1049 | | private void OnNewEmoteAdded(string emoteId) |
| | 1050 | | { |
| 0 | 1051 | | if (!isAvatarPreviewReady) |
| 0 | 1052 | | return; |
| | 1053 | |
|
| 0 | 1054 | | UpdateAvatarPreview(true); |
| 0 | 1055 | | } |
| | 1056 | |
|
| 0 | 1057 | | private void OnPreviewEmote(string emoteId) { view.PlayPreviewEmote(emoteId); } |
| | 1058 | |
|
| | 1059 | | private void OnEmoteEquipped(string emoteId) |
| | 1060 | | { |
| 0 | 1061 | | catalog.TryGetValue(emoteId, out WearableItem equippedEmote); |
| | 1062 | |
|
| 0 | 1063 | | if (equippedEmote != null) |
| 0 | 1064 | | EquipEmote(equippedEmote); |
| 0 | 1065 | | } |
| | 1066 | |
|
| | 1067 | | private void OnEmoteUnequipped(string emoteId) |
| | 1068 | | { |
| 0 | 1069 | | catalog.TryGetValue(emoteId, out WearableItem unequippedEmote); |
| | 1070 | |
|
| 0 | 1071 | | if (unequippedEmote != null) |
| 0 | 1072 | | UnequipEmote(unequippedEmote); |
| 0 | 1073 | | } |
| | 1074 | |
|
| 0 | 1075 | | private void OnRedirectToEmoteSelling(string emoteId) { SellCollectible(emoteId); } |
| | 1076 | |
|
| | 1077 | | internal void SendNewEquippedWearablesAnalytics(List<string> oldWearables, List<string> newWearables) |
| | 1078 | | { |
| 28 | 1079 | | for (int i = 0; i < newWearables.Count; i++) |
| | 1080 | | { |
| 12 | 1081 | | if (oldWearables.Contains(newWearables[i])) |
| | 1082 | | continue; |
| | 1083 | |
|
| 9 | 1084 | | catalog.TryGetValue(newWearables[i], out WearableItem newEquippedEmote); |
| 9 | 1085 | | if (newEquippedEmote != null && !newEquippedEmote.IsEmote()) |
| 9 | 1086 | | SendEquipWearableAnalytic(newEquippedEmote); |
| | 1087 | | } |
| 2 | 1088 | | } |
| | 1089 | |
|
| | 1090 | | private void SendEquipWearableAnalytic(WearableItem equippedWearable) |
| | 1091 | | { |
| 9 | 1092 | | Dictionary<string, string> data = new Dictionary<string, string>(); |
| 9 | 1093 | | data.Add("name", equippedWearable.GetName()); |
| 9 | 1094 | | data.Add("rarity", equippedWearable.rarity); |
| 9 | 1095 | | data.Add("category", equippedWearable.data.category); |
| 9 | 1096 | | data.Add("linked_wearable", equippedWearable.IsFromThirdPartyCollection.ToString()); |
| 9 | 1097 | | data.Add("third_party_collection_id", equippedWearable.ThirdPartyCollectionId); |
| 9 | 1098 | | data.Add("is_in_l2", equippedWearable.IsInL2().ToString()); |
| 9 | 1099 | | data.Add("smart_item", equippedWearable.IsSmart().ToString()); |
| | 1100 | |
|
| 9 | 1101 | | analytics.SendAnalytic(EQUIP_WEARABLE_METRIC, data); |
| 9 | 1102 | | } |
| | 1103 | |
|
| 48 | 1104 | | internal virtual IEmotesCustomizationComponentController CreateEmotesController() => new EmotesCustomizationComponen |
| | 1105 | | } |