| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Interface; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.Rendering; |
| | 9 | | using UnityEngine.Rendering.Universal; |
| | 10 | | using Categories = WearableLiterals.Categories; |
| | 11 | |
|
| | 12 | | public class AvatarEditorHUDController : IHUD |
| | 13 | | { |
| | 14 | | private const int LOADING_OWNED_WEARABLES_RETRIES = 3; |
| | 15 | | private const string LOADING_OWNED_WEARABLES_ERROR_MESSAGE = "There was a problem loading your wearables"; |
| | 16 | | private const string URL_MARKET_PLACE = "https://market.decentraland.org/browse?section=wearables"; |
| | 17 | | private const string URL_GET_A_WALLET = "https://docs.decentraland.org/get-a-wallet"; |
| | 18 | | private const string URL_SELL_COLLECTIBLE_GENERIC = "https://market.decentraland.org/account"; |
| | 19 | | private const string URL_SELL_SPECIFIC_COLLECTIBLE = "https://market.decentraland.org/contracts/{collectionId}/token |
| | 20 | |
|
| 1 | 21 | | protected static readonly string[] categoriesThatMustHaveSelection = { Categories.BODY_SHAPE, Categories.UPPER_BODY, |
| 1 | 22 | | protected static readonly string[] categoriesToRandomize = { Categories.HAIR, Categories.EYES, Categories.EYEBROWS, |
| | 23 | |
|
| | 24 | | [NonSerialized] |
| | 25 | | public bool bypassUpdateAvatarPreview = false; |
| | 26 | |
|
| | 27 | | private UserProfile userProfile; |
| | 28 | | private BaseDictionary<string, WearableItem> catalog; |
| 87 | 29 | | bool renderingEnabled => CommonScriptableObjects.rendererState.Get(); |
| 0 | 30 | | bool isPlayerRendererLoaded => DataStore.i.isPlayerRendererLoaded.Get(); |
| 46 | 31 | | private readonly Dictionary<string, List<WearableItem>> wearablesByCategory = new Dictionary<string, List<WearableIt |
| 46 | 32 | | protected readonly AvatarEditorHUDModel model = new AvatarEditorHUDModel(); |
| | 33 | |
|
| | 34 | | private ColorList skinColorList; |
| | 35 | | private ColorList eyeColorList; |
| | 36 | | private ColorList hairColorList; |
| | 37 | | private bool prevMouseLockState = false; |
| 46 | 38 | | private int ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES; |
| | 39 | | private bool ownedWearablesAlreadyLoaded = false; |
| 46 | 40 | | private List<Nft> ownedNftCollectionsL1 = new List<Nft>(); |
| 46 | 41 | | private List<Nft> ownedNftCollectionsL2 = new List<Nft>(); |
| | 42 | |
|
| | 43 | | public AvatarEditorHUDView view; |
| | 44 | |
|
| | 45 | | public event Action OnOpen; |
| | 46 | | public event Action OnClose; |
| | 47 | |
|
| 92 | 48 | | public AvatarEditorHUDController() { } |
| | 49 | |
|
| | 50 | | public void Initialize(UserProfile userProfile, BaseDictionary<string, WearableItem> catalog, bool bypassUpdateAvata |
| | 51 | | { |
| 44 | 52 | | this.userProfile = userProfile; |
| 44 | 53 | | this.bypassUpdateAvatarPreview = bypassUpdateAvatarPreview; |
| | 54 | |
|
| 44 | 55 | | view = AvatarEditorHUDView.Create(this); |
| | 56 | |
|
| 44 | 57 | | view.OnToggleActionTriggered += ToggleVisibility; |
| 44 | 58 | | view.OnCloseActionTriggered += DiscardAndClose; |
| | 59 | |
|
| 44 | 60 | | skinColorList = Resources.Load<ColorList>("SkinTone"); |
| 44 | 61 | | hairColorList = Resources.Load<ColorList>("HairColor"); |
| 44 | 62 | | eyeColorList = Resources.Load<ColorList>("EyeColor"); |
| 44 | 63 | | view.SetColors(skinColorList.colors, hairColorList.colors, eyeColorList.colors); |
| | 64 | |
|
| 44 | 65 | | SetCatalog(catalog); |
| | 66 | |
|
| 44 | 67 | | LoadUserProfile(userProfile, true); |
| 44 | 68 | | this.userProfile.OnUpdate += LoadUserProfile; |
| 44 | 69 | | DataStore.i.isPlayerRendererLoaded.OnChange += PlayerRendererLoaded; |
| 44 | 70 | | } |
| | 71 | |
|
| | 72 | | public void SetCatalog(BaseDictionary<string, WearableItem> catalog) |
| | 73 | | { |
| 44 | 74 | | if (this.catalog != null) |
| | 75 | | { |
| 0 | 76 | | this.catalog.OnAdded -= AddWearable; |
| 0 | 77 | | this.catalog.OnRemoved -= RemoveWearable; |
| | 78 | | } |
| | 79 | |
|
| 44 | 80 | | this.catalog = catalog; |
| | 81 | |
|
| 44 | 82 | | ProcessCatalog(this.catalog); |
| 44 | 83 | | this.catalog.OnAdded += AddWearable; |
| 44 | 84 | | this.catalog.OnRemoved += RemoveWearable; |
| 44 | 85 | | } |
| | 86 | |
|
| | 87 | | private void LoadUserProfile(UserProfile userProfile) |
| | 88 | | { |
| 41 | 89 | | LoadUserProfile(userProfile, false); |
| 41 | 90 | | QueryNftCollections(userProfile.userId); |
| 41 | 91 | | } |
| | 92 | |
|
| | 93 | | private void LoadOwnedWereables(UserProfile userProfile) |
| | 94 | | { |
| 39 | 95 | | if (ownedWearablesAlreadyLoaded || ownedWearablesRemainingRequests <= 0 || string.IsNullOrEmpty(userProfile.user |
| 38 | 96 | | return; |
| | 97 | |
|
| 1 | 98 | | view.ShowCollectiblesLoadingSpinner(true); |
| 1 | 99 | | view.ShowCollectiblesLoadingRetry(false); |
| 1 | 100 | | CatalogController.RequestOwnedWearables(userProfile.userId) |
| | 101 | | .Then((ownedWearables) => |
| | 102 | | { |
| 0 | 103 | | ownedWearablesAlreadyLoaded = true; |
| 0 | 104 | | this.userProfile.SetInventory(ownedWearables.Select(x => x.id).ToArray()); |
| 0 | 105 | | LoadUserProfile(userProfile, true); |
| 0 | 106 | | view.ShowCollectiblesLoadingSpinner(false); |
| 0 | 107 | | }) |
| | 108 | | .Catch((error) => |
| | 109 | | { |
| 0 | 110 | | ownedWearablesRemainingRequests--; |
| 0 | 111 | | if (ownedWearablesRemainingRequests > 0) |
| | 112 | | { |
| 0 | 113 | | Debug.LogWarning("Retrying owned wereables loading..."); |
| 0 | 114 | | LoadOwnedWereables(userProfile); |
| 0 | 115 | | } |
| | 116 | | else |
| | 117 | | { |
| 0 | 118 | | NotificationsController.i.ShowNotification(new Notification.Model |
| | 119 | | { |
| | 120 | | message = LOADING_OWNED_WEARABLES_ERROR_MESSAGE, |
| | 121 | | type = NotificationFactory.Type.GENERIC, |
| | 122 | | timer = 10f, |
| | 123 | | destroyOnFinish = true |
| | 124 | | }); |
| | 125 | |
|
| 0 | 126 | | view.ShowCollectiblesLoadingSpinner(false); |
| 0 | 127 | | view.ShowCollectiblesLoadingRetry(true); |
| 0 | 128 | | Debug.LogError(error); |
| | 129 | | } |
| 0 | 130 | | }); |
| 1 | 131 | | } |
| | 132 | |
|
| | 133 | | private void QueryNftCollections(string userId) |
| | 134 | | { |
| 41 | 135 | | if (string.IsNullOrEmpty(userId)) |
| 41 | 136 | | return; |
| | 137 | |
|
| 0 | 138 | | DCL.Environment.i.platform.serviceProviders.theGraph.QueryNftCollections(userProfile.userId, NftCollectionsLayer |
| 0 | 139 | | .Then((nfts) => ownedNftCollectionsL1 = nfts) |
| 0 | 140 | | .Catch((error) => Debug.LogError(error)); |
| | 141 | |
|
| 0 | 142 | | DCL.Environment.i.platform.serviceProviders.theGraph.QueryNftCollections(userProfile.userId, NftCollectionsLayer |
| 0 | 143 | | .Then((nfts) => ownedNftCollectionsL2 = nfts) |
| 0 | 144 | | .Catch((error) => Debug.LogError(error)); |
| 0 | 145 | | } |
| | 146 | |
|
| | 147 | | public void RetryLoadOwnedWearables() |
| | 148 | | { |
| 0 | 149 | | ownedWearablesRemainingRequests = LOADING_OWNED_WEARABLES_RETRIES; |
| 0 | 150 | | LoadOwnedWereables(userProfile); |
| 0 | 151 | | } |
| | 152 | |
|
| | 153 | | private void PlayerRendererLoaded(bool current, bool previous) |
| | 154 | | { |
| 2 | 155 | | if (!current) |
| 0 | 156 | | return; |
| | 157 | |
|
| 2 | 158 | | if (!ownedWearablesAlreadyLoaded) |
| | 159 | | { |
| 2 | 160 | | List<string> equippedOwnedWearables = new List<string>(); |
| 4 | 161 | | for (int i = 0; i < userProfile.avatar.wearables.Count; i++) |
| | 162 | | { |
| 0 | 163 | | if (catalog.TryGetValue(userProfile.avatar.wearables[i], out WearableItem wearable) && |
| | 164 | | !wearable.data.tags.Contains("base-wearable")) |
| | 165 | | { |
| 0 | 166 | | equippedOwnedWearables.Add(userProfile.avatar.wearables[i]); |
| | 167 | | } |
| | 168 | | } |
| | 169 | |
|
| 2 | 170 | | userProfile.SetInventory(equippedOwnedWearables.ToArray()); |
| | 171 | | } |
| | 172 | |
|
| 2 | 173 | | LoadUserProfile(userProfile, true); |
| 2 | 174 | | DataStore.i.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| 2 | 175 | | } |
| | 176 | |
|
| | 177 | | public void LoadUserProfile(UserProfile userProfile, bool forceLoading) |
| | 178 | | { |
| 87 | 179 | | bool avatarEditorNotVisible = renderingEnabled && !view.isOpen; |
| 87 | 180 | | bool isPlaying = !Application.isBatchMode; |
| | 181 | |
|
| 87 | 182 | | if (!forceLoading) |
| | 183 | | { |
| 41 | 184 | | if (isPlaying && avatarEditorNotVisible) |
| 0 | 185 | | return; |
| | 186 | | } |
| | 187 | |
|
| 87 | 188 | | if (userProfile == null) |
| 0 | 189 | | return; |
| | 190 | |
|
| 87 | 191 | | if (userProfile.avatar == null || string.IsNullOrEmpty(userProfile.avatar.bodyShape)) |
| 3 | 192 | | return; |
| | 193 | |
|
| 84 | 194 | | CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.bodyShape, out var bodyShape); |
| | 195 | |
|
| 84 | 196 | | if (bodyShape == null) |
| | 197 | | { |
| 0 | 198 | | return; |
| | 199 | | } |
| | 200 | |
|
| 84 | 201 | | view.SetIsWeb3(userProfile.hasConnectedWeb3); |
| | 202 | |
|
| 84 | 203 | | ProcessCatalog(this.catalog); |
| 84 | 204 | | EquipBodyShape(bodyShape); |
| 84 | 205 | | EquipSkinColor(userProfile.avatar.skinColor); |
| 84 | 206 | | EquipHairColor(userProfile.avatar.hairColor); |
| 84 | 207 | | EquipEyesColor(userProfile.avatar.eyeColor); |
| | 208 | |
|
| 84 | 209 | | model.wearables.Clear(); |
| 84 | 210 | | view.UnselectAllWearables(); |
| | 211 | |
|
| 84 | 212 | | int wearablesCount = userProfile.avatar.wearables.Count; |
| | 213 | |
|
| 84 | 214 | | if (isPlayerRendererLoaded) |
| | 215 | | { |
| 184 | 216 | | for (var i = 0; i < wearablesCount; i++) |
| | 217 | | { |
| 53 | 218 | | CatalogController.wearableCatalog.TryGetValue(userProfile.avatar.wearables[i], out var wearable); |
| 53 | 219 | | if (wearable == null) |
| | 220 | | { |
| 0 | 221 | | Debug.LogError($"Couldn't find wearable with ID {userProfile.avatar.wearables[i]}"); |
| 0 | 222 | | continue; |
| | 223 | | } |
| | 224 | |
|
| 53 | 225 | | EquipWearable(wearable); |
| | 226 | | } |
| | 227 | | } |
| | 228 | |
|
| 84 | 229 | | EnsureWearablesCategoriesNotEmpty(); |
| | 230 | |
|
| 84 | 231 | | UpdateAvatarPreview(); |
| 84 | 232 | | } |
| | 233 | |
|
| | 234 | | private void EnsureWearablesCategoriesNotEmpty() |
| | 235 | | { |
| 137 | 236 | | var categoriesInUse = model.wearables.Select(x => x.data.category).ToArray(); |
| 1344 | 237 | | for (var i = 0; i < categoriesThatMustHaveSelection.Length; i++) |
| | 238 | | { |
| 588 | 239 | | var category = categoriesThatMustHaveSelection[i]; |
| 588 | 240 | | if (category != Categories.BODY_SHAPE && !(categoriesInUse.Contains(category))) |
| | 241 | | { |
| | 242 | | WearableItem wearable; |
| 462 | 243 | | var defaultItemId = WearableLiterals.DefaultWearables.GetDefaultWearable(model.bodyShape.id, category); |
| 462 | 244 | | if (defaultItemId != null) |
| | 245 | | { |
| 462 | 246 | | CatalogController.wearableCatalog.TryGetValue(defaultItemId, out wearable); |
| 462 | 247 | | } |
| | 248 | | else |
| | 249 | | { |
| 0 | 250 | | wearable = wearablesByCategory[category].FirstOrDefault(x => x.SupportsBodyShape(model.bodyShape.id) |
| | 251 | | } |
| | 252 | |
|
| 462 | 253 | | if (wearable != null) |
| | 254 | | { |
| 462 | 255 | | EquipWearable(wearable); |
| | 256 | | } |
| | 257 | | } |
| | 258 | | } |
| 84 | 259 | | } |
| | 260 | |
|
| | 261 | | public void WearableClicked(string wearableId) |
| | 262 | | { |
| 20 | 263 | | CatalogController.wearableCatalog.TryGetValue(wearableId, out var wearable); |
| 20 | 264 | | if (wearable == null) |
| 3 | 265 | | return; |
| | 266 | |
|
| 17 | 267 | | if (wearable.data.category == Categories.BODY_SHAPE) |
| | 268 | | { |
| 3 | 269 | | if (wearable.id == model.bodyShape.id) |
| 0 | 270 | | return; |
| 3 | 271 | | EquipBodyShape(wearable); |
| 3 | 272 | | } |
| | 273 | | else |
| | 274 | | { |
| 14 | 275 | | if (model.wearables.Contains(wearable)) |
| | 276 | | { |
| 2 | 277 | | if (!categoriesThatMustHaveSelection.Contains(wearable.data.category)) |
| | 278 | | { |
| 0 | 279 | | UnequipWearable(wearable); |
| 0 | 280 | | } |
| | 281 | | else |
| | 282 | | { |
| 2 | 283 | | return; |
| | 284 | | } |
| | 285 | | } |
| | 286 | | else |
| | 287 | | { |
| 91 | 288 | | var sameCategoryEquipped = model.wearables.FirstOrDefault(x => x.data.category == wearable.data.category |
| 12 | 289 | | if (sameCategoryEquipped != null) |
| | 290 | | { |
| 2 | 291 | | UnequipWearable(sameCategoryEquipped); |
| | 292 | | } |
| | 293 | |
|
| 12 | 294 | | EquipWearable(wearable); |
| | 295 | | } |
| | 296 | | } |
| | 297 | |
|
| 15 | 298 | | UpdateAvatarPreview(); |
| 15 | 299 | | } |
| | 300 | |
|
| | 301 | | public void HairColorClicked(Color color) |
| | 302 | | { |
| 2 | 303 | | EquipHairColor(color); |
| 2 | 304 | | view.SelectHairColor(model.hairColor); |
| 2 | 305 | | UpdateAvatarPreview(); |
| 2 | 306 | | } |
| | 307 | |
|
| | 308 | | public void SkinColorClicked(Color color) |
| | 309 | | { |
| 2 | 310 | | EquipSkinColor(color); |
| 2 | 311 | | view.SelectSkinColor(model.skinColor); |
| 2 | 312 | | UpdateAvatarPreview(); |
| 2 | 313 | | } |
| | 314 | |
|
| | 315 | | public void EyesColorClicked(Color color) |
| | 316 | | { |
| 2 | 317 | | EquipEyesColor(color); |
| 2 | 318 | | view.SelectEyeColor(model.eyesColor); |
| 2 | 319 | | UpdateAvatarPreview(); |
| 2 | 320 | | } |
| | 321 | |
|
| | 322 | | protected virtual void UpdateAvatarPreview() |
| | 323 | | { |
| 106 | 324 | | if (!bypassUpdateAvatarPreview) |
| 106 | 325 | | view.UpdateAvatarPreview(model.ToAvatarModel()); |
| 106 | 326 | | } |
| | 327 | |
|
| | 328 | | private void EquipHairColor(Color color) |
| | 329 | | { |
| 87 | 330 | | var colorToSet = color; |
| 880 | 331 | | if (!hairColorList.colors.Any(x => x.AproxComparison(colorToSet))) |
| | 332 | | { |
| 78 | 333 | | colorToSet = hairColorList.colors[hairColorList.defaultColor]; |
| | 334 | | } |
| | 335 | |
|
| 87 | 336 | | model.hairColor = colorToSet; |
| 87 | 337 | | view.SelectHairColor(model.hairColor); |
| 87 | 338 | | } |
| | 339 | |
|
| | 340 | | private void EquipEyesColor(Color color) |
| | 341 | | { |
| 87 | 342 | | var colorToSet = color; |
| 886 | 343 | | if (!eyeColorList.colors.Any(x => x.AproxComparison(color))) |
| | 344 | | { |
| 78 | 345 | | colorToSet = eyeColorList.colors[eyeColorList.defaultColor]; |
| | 346 | | } |
| | 347 | |
|
| 87 | 348 | | model.eyesColor = colorToSet; |
| 87 | 349 | | view.SelectEyeColor(model.eyesColor); |
| 87 | 350 | | } |
| | 351 | |
|
| | 352 | | private void EquipSkinColor(Color color) |
| | 353 | | { |
| 86 | 354 | | var colorToSet = color; |
| 877 | 355 | | if (!skinColorList.colors.Any(x => x.AproxComparison(colorToSet))) |
| | 356 | | { |
| 78 | 357 | | colorToSet = skinColorList.colors[skinColorList.defaultColor]; |
| | 358 | | } |
| | 359 | |
|
| 86 | 360 | | model.skinColor = colorToSet; |
| 86 | 361 | | view.SelectSkinColor(model.skinColor); |
| 86 | 362 | | } |
| | 363 | |
|
| | 364 | | private void EquipBodyShape(WearableItem bodyShape) |
| | 365 | | { |
| 87 | 366 | | if (bodyShape.data.category != Categories.BODY_SHAPE) |
| | 367 | | { |
| 0 | 368 | | Debug.LogError($"Item ({bodyShape.id} is not a body shape"); |
| 0 | 369 | | return; |
| | 370 | | } |
| | 371 | |
|
| 87 | 372 | | if (model.bodyShape == bodyShape) |
| 37 | 373 | | return; |
| | 374 | |
|
| 50 | 375 | | model.bodyShape = bodyShape; |
| 50 | 376 | | view.UpdateSelectedBody(bodyShape); |
| | 377 | |
|
| 50 | 378 | | int wearablesCount = model.wearables.Count; |
| 172 | 379 | | for (var i = wearablesCount - 1; i >= 0; i--) |
| | 380 | | { |
| 36 | 381 | | UnequipWearable(model.wearables[i]); |
| | 382 | | } |
| | 383 | |
|
| 50 | 384 | | var defaultWearables = WearableLiterals.DefaultWearables.GetDefaultWearables(bodyShape.id); |
| 812 | 385 | | for (var i = 0; i < defaultWearables.Length; i++) |
| | 386 | | { |
| 356 | 387 | | if (catalog.TryGetValue(defaultWearables[i], out var wearable)) |
| 356 | 388 | | EquipWearable(wearable); |
| | 389 | | } |
| 50 | 390 | | } |
| | 391 | |
|
| | 392 | | private void EquipWearable(WearableItem wearable) |
| | 393 | | { |
| 890 | 394 | | if (!wearablesByCategory.ContainsKey(wearable.data.category)) |
| 0 | 395 | | return; |
| | 396 | |
|
| 890 | 397 | | if (wearablesByCategory[wearable.data.category].Contains(wearable) && wearable.SupportsBodyShape(model.bodyShape |
| | 398 | | { |
| 890 | 399 | | var toReplace = GetWearablesReplacedBy(wearable); |
| 890 | 400 | | toReplace.ForEach(UnequipWearable); |
| 890 | 401 | | model.wearables.Add(wearable); |
| 890 | 402 | | view.EquipWearable(wearable); |
| | 403 | | } |
| 890 | 404 | | } |
| | 405 | |
|
| | 406 | | private void UnequipWearable(WearableItem wearable) |
| | 407 | | { |
| 40 | 408 | | if (model.wearables.Contains(wearable)) |
| | 409 | | { |
| 40 | 410 | | model.wearables.Remove(wearable); |
| 40 | 411 | | view.UnequipWearable(wearable); |
| | 412 | | } |
| 40 | 413 | | } |
| | 414 | |
|
| | 415 | | public void UnequipAllWearables() |
| | 416 | | { |
| 926 | 417 | | foreach (var wearable in model.wearables) |
| | 418 | | { |
| 395 | 419 | | view.UnequipWearable(wearable); |
| | 420 | | } |
| | 421 | |
|
| 68 | 422 | | model.wearables.Clear(); |
| 68 | 423 | | } |
| | 424 | |
|
| | 425 | | private void ProcessCatalog(BaseDictionary<string, WearableItem> catalog) |
| | 426 | | { |
| 128 | 427 | | wearablesByCategory.Clear(); |
| 128 | 428 | | view.RemoveAllWearables(); |
| 128 | 429 | | using (var iterator = catalog.Get().GetEnumerator()) |
| | 430 | | { |
| 4446 | 431 | | while (iterator.MoveNext()) |
| | 432 | | { |
| 4318 | 433 | | AddWearable(iterator.Current.Key, iterator.Current.Value); |
| | 434 | | } |
| 128 | 435 | | } |
| 128 | 436 | | } |
| | 437 | |
|
| | 438 | | private void AddWearable(string id, WearableItem wearable) |
| | 439 | | { |
| 4324 | 440 | | if (!wearable.data.tags.Contains("base-wearable") && userProfile.GetItemAmount(id) == 0) |
| | 441 | | { |
| 752 | 442 | | return; |
| | 443 | | } |
| | 444 | |
|
| 3572 | 445 | | if (!wearablesByCategory.ContainsKey(wearable.data.category)) |
| | 446 | | { |
| 1397 | 447 | | wearablesByCategory.Add(wearable.data.category, new List<WearableItem>()); |
| | 448 | | } |
| | 449 | |
|
| 3572 | 450 | | wearablesByCategory[wearable.data.category].Add(wearable); |
| 3572 | 451 | | view.AddWearable(wearable, userProfile.GetItemAmount(id)); |
| 3572 | 452 | | } |
| | 453 | |
|
| | 454 | | private void RemoveWearable(string id, WearableItem wearable) |
| | 455 | | { |
| 0 | 456 | | if (wearablesByCategory.ContainsKey(wearable.data.category)) |
| | 457 | | { |
| 0 | 458 | | if (wearablesByCategory[wearable.data.category].Remove(wearable)) |
| | 459 | | { |
| 0 | 460 | | if (wearablesByCategory[wearable.data.category].Count == 0) |
| | 461 | | { |
| 0 | 462 | | wearablesByCategory.Remove(wearable.data.category); |
| | 463 | | } |
| | 464 | | } |
| | 465 | | } |
| | 466 | |
|
| 0 | 467 | | view.RemoveWearable(wearable); |
| 0 | 468 | | } |
| | 469 | |
|
| | 470 | | public void RandomizeWearables() |
| | 471 | | { |
| 1 | 472 | | EquipHairColor(hairColorList.colors[UnityEngine.Random.Range(0, hairColorList.colors.Count)]); |
| 1 | 473 | | EquipEyesColor(eyeColorList.colors[UnityEngine.Random.Range(0, eyeColorList.colors.Count)]); |
| | 474 | |
|
| 1 | 475 | | model.wearables.Clear(); |
| 1 | 476 | | view.UnselectAllWearables(); |
| 1 | 477 | | using (var iterator = wearablesByCategory.GetEnumerator()) |
| | 478 | | { |
| 12 | 479 | | while (iterator.MoveNext()) |
| | 480 | | { |
| 11 | 481 | | string category = iterator.Current.Key; |
| 11 | 482 | | if (!categoriesToRandomize.Contains(category)) |
| | 483 | | { |
| | 484 | | continue; |
| | 485 | | } |
| | 486 | |
|
| 29 | 487 | | var supportedWearables = iterator.Current.Value.Where(x => x.SupportsBodyShape(model.bodyShape.id)).ToAr |
| 7 | 488 | | if (supportedWearables.Length == 0) |
| | 489 | | { |
| 0 | 490 | | Debug.LogError($"Couldn't get any wearable for category {category} and bodyshape {model.bodyShape.id |
| | 491 | | } |
| | 492 | |
|
| 7 | 493 | | var wearable = supportedWearables[UnityEngine.Random.Range(0, supportedWearables.Length - 1)]; |
| 7 | 494 | | EquipWearable(wearable); |
| | 495 | | } |
| 1 | 496 | | } |
| | 497 | |
|
| 1 | 498 | | UpdateAvatarPreview(); |
| 1 | 499 | | } |
| | 500 | |
|
| | 501 | | public List<WearableItem> GetWearablesReplacedBy(WearableItem wearableItem) |
| | 502 | | { |
| 890 | 503 | | List<WearableItem> wearablesToReplace = new List<WearableItem>(); |
| | 504 | |
|
| 890 | 505 | | HashSet<string> categoriesToReplace = new HashSet<string>(wearableItem.GetReplacesList(model.bodyShape.id) ?? ne |
| | 506 | |
|
| 890 | 507 | | int wearableCount = model.wearables.Count; |
| 6820 | 508 | | for (int i = 0; i < wearableCount; i++) |
| | 509 | | { |
| 2520 | 510 | | var wearable = model.wearables[i]; |
| 2520 | 511 | | if (wearable == null) |
| | 512 | | continue; |
| | 513 | |
|
| 2520 | 514 | | if (categoriesToReplace.Contains(wearable.data.category)) |
| | 515 | | { |
| 2 | 516 | | wearablesToReplace.Add(wearable); |
| 2 | 517 | | } |
| | 518 | | else |
| | 519 | | { |
| | 520 | | //For retrocompatibility's sake we check current wearables against new one (compatibility matrix is symm |
| 2518 | 521 | | HashSet<string> replacesList = new HashSet<string>(wearable.GetReplacesList(model.bodyShape.id) ?? new s |
| 2518 | 522 | | if (replacesList.Contains(wearableItem.data.category)) |
| | 523 | | { |
| 0 | 524 | | wearablesToReplace.Add(wearable); |
| | 525 | | } |
| | 526 | | } |
| | 527 | | } |
| | 528 | |
|
| 890 | 529 | | return wearablesToReplace; |
| | 530 | | } |
| | 531 | |
|
| 46 | 532 | | private float prevRenderScale = 1.0f; |
| | 533 | | private Camera mainCamera; |
| | 534 | |
|
| | 535 | | public void SetVisibility(bool visible) |
| | 536 | | { |
| 40 | 537 | | var currentRenderProfile = DCL.RenderProfileManifest.i.currentProfile; |
| | 538 | |
|
| 40 | 539 | | if (!visible && view.isOpen) |
| | 540 | | { |
| 1 | 541 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(1f); |
| 1 | 542 | | DCL.Environment.i.messaging.manager.paused = false; |
| 1 | 543 | | currentRenderProfile.avatarProfile.currentProfile = currentRenderProfile.avatarProfile.inWorld; |
| 1 | 544 | | currentRenderProfile.avatarProfile.Apply(); |
| 1 | 545 | | if (prevMouseLockState) |
| | 546 | | { |
| 0 | 547 | | Utils.LockCursor(); |
| | 548 | | } |
| | 549 | |
|
| | 550 | | // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0 |
| 1 | 551 | | var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| 1 | 552 | | asset.renderScale = prevRenderScale; |
| | 553 | |
|
| 1 | 554 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(false); |
| 1 | 555 | | OnClose?.Invoke(); |
| 0 | 556 | | } |
| 39 | 557 | | else if (visible && !view.isOpen) |
| | 558 | | { |
| 39 | 559 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(0f); |
| 39 | 560 | | LoadOwnedWereables(userProfile); |
| 39 | 561 | | DCL.Environment.i.messaging.manager.paused = DataStore.i.isSignUpFlow.Get(); |
| 39 | 562 | | currentRenderProfile.avatarProfile.currentProfile = currentRenderProfile.avatarProfile.avatarEditor; |
| 39 | 563 | | currentRenderProfile.avatarProfile.Apply(); |
| | 564 | |
|
| 39 | 565 | | prevMouseLockState = Utils.isCursorLocked; |
| 39 | 566 | | Utils.UnlockCursor(); |
| | 567 | |
|
| | 568 | | // NOTE(Brian): SSAO doesn't work correctly with the offseted avatar preview if the renderScale != 1.0 |
| 39 | 569 | | var asset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| 39 | 570 | | prevRenderScale = asset.renderScale; |
| 39 | 571 | | asset.renderScale = 1.0f; |
| | 572 | |
|
| 39 | 573 | | CommonScriptableObjects.isFullscreenHUDOpen.Set(true); |
| 39 | 574 | | OnOpen?.Invoke(); |
| | 575 | | } |
| | 576 | |
|
| 40 | 577 | | currentRenderProfile.avatarProfile.Apply(); |
| 40 | 578 | | view.SetVisibility(visible); |
| 40 | 579 | | } |
| | 580 | |
|
| | 581 | | public void Dispose() |
| | 582 | | { |
| 39 | 583 | | view.OnToggleActionTriggered -= ToggleVisibility; |
| 39 | 584 | | view.OnCloseActionTriggered -= DiscardAndClose; |
| | 585 | |
|
| 39 | 586 | | CleanUp(); |
| 39 | 587 | | } |
| | 588 | |
|
| | 589 | | public void CleanUp() |
| | 590 | | { |
| 44 | 591 | | UnequipAllWearables(); |
| | 592 | |
|
| 44 | 593 | | if (view != null) |
| 44 | 594 | | view.CleanUp(); |
| | 595 | |
|
| 44 | 596 | | this.userProfile.OnUpdate -= LoadUserProfile; |
| 44 | 597 | | this.catalog.OnAdded -= AddWearable; |
| 44 | 598 | | this.catalog.OnRemoved -= RemoveWearable; |
| 44 | 599 | | DataStore.i.isPlayerRendererLoaded.OnChange -= PlayerRendererLoaded; |
| 44 | 600 | | } |
| | 601 | |
|
| 0 | 602 | | public void SetConfiguration(HUDConfiguration configuration) { SetVisibility(configuration.active); } |
| | 603 | |
|
| | 604 | | public void SaveAvatar(Texture2D faceSnapshot, Texture2D face128Snapshot, Texture2D face256Snapshot, Texture2D bodyS |
| | 605 | | { |
| 1 | 606 | | var avatarModel = model.ToAvatarModel(); |
| | 607 | |
|
| 1 | 608 | | WebInterface.SendSaveAvatar(avatarModel, faceSnapshot, face128Snapshot, face256Snapshot, bodySnapshot, DataStore |
| 1 | 609 | | userProfile.OverrideAvatar(avatarModel, face256Snapshot); |
| 1 | 610 | | if (DataStore.i.isSignUpFlow.Get()) |
| 0 | 611 | | DataStore.i.HUDs.signupVisible.Set(true); |
| | 612 | |
|
| 1 | 613 | | SetVisibility(false); |
| 1 | 614 | | } |
| | 615 | |
|
| | 616 | | public void DiscardAndClose() |
| | 617 | | { |
| 0 | 618 | | if (!view.isOpen) |
| 0 | 619 | | return; |
| | 620 | |
|
| 0 | 621 | | if (!DataStore.i.isSignUpFlow.Get()) |
| 0 | 622 | | LoadUserProfile(userProfile); |
| | 623 | | else |
| 0 | 624 | | WebInterface.SendCloseUserAvatar(true); |
| | 625 | |
|
| 0 | 626 | | SetVisibility(false); |
| 0 | 627 | | } |
| | 628 | |
|
| | 629 | | public void GoToMarketplace() |
| | 630 | | { |
| 0 | 631 | | if (userProfile.hasConnectedWeb3) |
| 0 | 632 | | WebInterface.OpenURL(URL_MARKET_PLACE); |
| | 633 | | else |
| 0 | 634 | | WebInterface.OpenURL(URL_GET_A_WALLET); |
| 0 | 635 | | } |
| | 636 | |
|
| | 637 | | public void SellCollectible(string collectibleId) |
| | 638 | | { |
| 0 | 639 | | var ownedCollectible = ownedNftCollectionsL1.FirstOrDefault(nft => nft.urn == collectibleId); |
| 0 | 640 | | if (ownedCollectible == null) |
| 0 | 641 | | ownedCollectible = ownedNftCollectionsL2.FirstOrDefault(nft => nft.urn == collectibleId); |
| | 642 | |
|
| 0 | 643 | | if (ownedCollectible != null) |
| 0 | 644 | | WebInterface.OpenURL(URL_SELL_SPECIFIC_COLLECTIBLE.Replace("{collectionId}", ownedCollectible.collectionId). |
| | 645 | | else |
| 0 | 646 | | WebInterface.OpenURL(URL_SELL_COLLECTIBLE_GENERIC); |
| 0 | 647 | | } |
| | 648 | |
|
| 0 | 649 | | public void ToggleVisibility() { SetVisibility(!view.isOpen); } |
| | 650 | | } |