| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.Backpack |
| | 7 | | { |
| | 8 | | public class VRMDetailsComponentView : BaseComponentView, IVRMDetailsComponentView |
| | 9 | | { |
| | 10 | | private const string VRM_EXPORT_DETAILS_POOL_ID = "VRMExportDetails"; |
| | 11 | | [SerializeField] private ButtonComponentView vrmExportButton; |
| | 12 | | [SerializeField] private GameObject exportWarningBar; |
| | 13 | | [SerializeField] private Button backButton; |
| | 14 | | [SerializeField] private VRMDetailItemComponentView vrmDetailPrefab; |
| | 15 | | [SerializeField] private Transform wearablesContainer; |
| | 16 | |
|
| | 17 | | private Pool wearableDetailPool; |
| 37 | 18 | | private readonly List<(PoolableObject, VRMDetailItemComponentView)> pooledItems = new (); |
| 37 | 19 | | private readonly List<string> equippedItemsURNs = new (); |
| | 20 | |
|
| | 21 | | public event Action OnBackButtonPressed; |
| | 22 | | public event Action OnVRMExportButtonPressed; |
| | 23 | | public event Action<VRMItemModel, UnequipWearableSource> OnWearableUnequipped; |
| | 24 | | public event Action<VRMItemModel, EquipWearableSource> OnWearableEquipped; |
| | 25 | |
|
| | 26 | | public override void Awake() |
| | 27 | | { |
| 0 | 28 | | base.Awake(); |
| 0 | 29 | | vrmExportButton.onClick.RemoveAllListeners(); |
| 0 | 30 | | vrmExportButton.onClick.AddListener(OnVRMExportButtonClick); |
| | 31 | |
|
| 0 | 32 | | backButton.onClick.RemoveAllListeners(); |
| 0 | 33 | | backButton.onClick.AddListener(() => OnBackButtonPressed?.Invoke()); |
| | 34 | |
|
| 0 | 35 | | wearableDetailPool = GetItemDetailPool(); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public override void Dispose() |
| | 39 | | { |
| 0 | 40 | | base.Dispose(); |
| 0 | 41 | | TearDown(); |
| 0 | 42 | | vrmExportButton.onClick.RemoveAllListeners(); |
| 0 | 43 | | backButton.onClick.RemoveAllListeners(); |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | public override void OnDisable() |
| | 47 | | { |
| 0 | 48 | | base.OnDisable(); |
| | 49 | |
|
| 0 | 50 | | TearDown(); |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | private void TearDown() |
| | 54 | | { |
| 0 | 55 | | foreach ((PoolableObject pooledItem, VRMDetailItemComponentView component) in pooledItems) |
| | 56 | | { |
| 0 | 57 | | component.ClearOnWearableUnequippedEvents(); |
| 0 | 58 | | pooledItem.Release(); |
| | 59 | | } |
| | 60 | |
|
| 0 | 61 | | pooledItems.Clear(); |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | private Pool GetItemDetailPool() |
| | 65 | | { |
| 0 | 66 | | var entryPool = PoolManager.i.GetPool(VRM_EXPORT_DETAILS_POOL_ID); |
| 0 | 67 | | if (entryPool != null) return entryPool; |
| | 68 | |
|
| 0 | 69 | | entryPool = PoolManager.i.AddPool( |
| | 70 | | VRM_EXPORT_DETAILS_POOL_ID, |
| | 71 | | Instantiate(vrmDetailPrefab).gameObject, |
| | 72 | | maxPrewarmCount: 5, |
| | 73 | | isPersistent: true); |
| | 74 | |
|
| 0 | 75 | | entryPool.ForcePrewarm(); |
| | 76 | |
|
| 0 | 77 | | return entryPool; |
| | 78 | | } |
| | 79 | |
|
| | 80 | | private void OnVRMExportButtonClick() |
| | 81 | | { |
| 0 | 82 | | OnVRMExportButtonPressed?.Invoke(); |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | private void EnableVRMExport(bool enable) |
| | 86 | | { |
| 0 | 87 | | vrmExportButton.SetInteractable(enable); |
| 0 | 88 | | exportWarningBar.SetActive(!enable); |
| 0 | 89 | | } |
| | 90 | |
|
| 0 | 91 | | public override void RefreshControl() { } |
| | 92 | |
|
| | 93 | | public void FillVRMBlockingWearablesList(List<NFTDataDTO> itemsToDisplay) |
| | 94 | | { |
| 0 | 95 | | EnableVRMExport(false); |
| 0 | 96 | | equippedItemsURNs.Clear(); |
| | 97 | |
|
| 0 | 98 | | foreach (var itemData in itemsToDisplay) |
| | 99 | | { |
| 0 | 100 | | equippedItemsURNs.Add(itemData.urn); |
| 0 | 101 | | var detailItem = wearableDetailPool.Get(); |
| 0 | 102 | | var detailComponentView = detailItem.gameObject.GetComponent<VRMDetailItemComponentView>(); |
| | 103 | |
|
| 0 | 104 | | detailComponentView.transform.SetParent(wearablesContainer, false); |
| 0 | 105 | | pooledItems.Add((detailItem, detailComponentView)); |
| | 106 | |
|
| 0 | 107 | | var vrmItemModel = new VRMItemModel |
| | 108 | | { |
| | 109 | | wearableUrn = itemData.urn, |
| | 110 | | wearableImageUrl = itemData.thumbnail, |
| | 111 | | wearableName = itemData.name, |
| | 112 | | wearableCategoryName = itemData.data.wearable.category, |
| | 113 | | wearableCreatorImageUrl = itemData.creatorImageUrl, |
| | 114 | | wearableCreatorName = itemData.creatorName, |
| | 115 | | wearableCanBeUnEquipped = itemData.canBeUnEquipped, |
| | 116 | | }; |
| | 117 | |
|
| 0 | 118 | | detailComponentView.SetModel(vrmItemModel); |
| 0 | 119 | | detailComponentView.ClearOnWearableUnequippedEvents(); |
| | 120 | |
|
| 0 | 121 | | detailComponentView.OnUnEquipWearable += () => |
| | 122 | | { |
| 0 | 123 | | equippedItemsURNs.Remove(itemData.urn); |
| | 124 | |
|
| 0 | 125 | | if (equippedItemsURNs.Count == 0) |
| 0 | 126 | | EnableVRMExport(true); |
| | 127 | |
|
| 0 | 128 | | OnWearableUnequipped?.Invoke(vrmItemModel, UnequipWearableSource.None); |
| 0 | 129 | | }; |
| | 130 | |
|
| 0 | 131 | | detailComponentView.OnEquipWearable += () => |
| | 132 | | { |
| 0 | 133 | | equippedItemsURNs.Add(itemData.urn); |
| | 134 | |
|
| 0 | 135 | | if (equippedItemsURNs.Count > 0) |
| 0 | 136 | | EnableVRMExport(false); |
| | 137 | |
|
| 0 | 138 | | OnWearableEquipped?.Invoke(vrmItemModel, EquipWearableSource.None); |
| 0 | 139 | | }; |
| | 140 | | } |
| 0 | 141 | | } |
| | 142 | | } |
| | 143 | | } |