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