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