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