| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using UnityEngine; |
| | 5 | | using TMPro; |
| | 6 | |
|
| | 7 | | namespace DCL.Social.Passports |
| | 8 | | { |
| | 9 | | public class PassportNavigationComponentView : BaseComponentView, IPassportNavigationComponentView |
| | 10 | | { |
| | 11 | | private const string GUEST_TEXT = "is a guest"; |
| | 12 | | private const string TEMPLATE_DESCRIPTION_TEXT = "This person doesn't have an about description yet."; |
| | 13 | | private const int ABOUT_SUB_SECTION_INDEX = 0; |
| | 14 | | private const int COLLECTIBLES_SUB_SECTION_INDEX = 1; |
| | 15 | |
|
| | 16 | | [SerializeField] private GameObject aboutPanel; |
| | 17 | | [SerializeField] private GameObject wearablesPanel; |
| | 18 | | [SerializeField] private SectionSelectorComponentView subSectionSelector; |
| | 19 | | [SerializeField] private GameObject guestPanel; |
| | 20 | | [SerializeField] private GameObject normalPanel; |
| | 21 | | [SerializeField] private Transform equippedWearablesContainer; |
| | 22 | | [SerializeField] private TextMeshProUGUI usernameText; |
| | 23 | | [SerializeField] private TextMeshProUGUI descriptionText; |
| | 24 | | [SerializeField] private CarouselComponentView nftWearablesCarousel; |
| | 25 | | [SerializeField] private CarouselComponentView nftEmotesCarousel; |
| | 26 | | [SerializeField] private Transform nftWearablesCarouselContent; |
| | 27 | | [SerializeField] private Transform nftEmotesCarouselContent; |
| | 28 | | [SerializeField] private GameObject wearableUIReferenceObject; |
| | 29 | | [SerializeField] private GameObject nftPageUIReferenceObject; |
| | 30 | |
|
| | 31 | | public event Action<string> OnClickBuyNft; |
| | 32 | |
|
| | 33 | | private const string NFT_ICON_POOL_NAME_PREFIX = "NFTIconsEntriesPool_"; |
| | 34 | | private const string NFT_PAGES_POOL_NAME_PREFIX = "NFTPagesEntriesPool_"; |
| | 35 | | private const int MAX_NFT_ICON_ENTRIES = 20; |
| | 36 | | private const int MAX_NFT_PAGES_ENTRIES = 20; |
| 0 | 37 | | private static readonly Vector3 NFT_ICON_SCALE = new Vector3(0.7f, 0.7f, 0.7f); |
| | 38 | |
|
| 0 | 39 | | private List<PoolableObject> nftIconPoolableQueue = new List<PoolableObject>(); |
| 0 | 40 | | private List<PoolableObject> nftPagesPoolableQueue = new List<PoolableObject>(); |
| | 41 | | private Pool nftIconsEntryPool; |
| | 42 | | private Pool nftPagesEntryPool; |
| | 43 | |
|
| | 44 | | public override void Start() |
| | 45 | | { |
| 0 | 46 | | subSectionSelector.GetSection(ABOUT_SUB_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| 0 | 47 | | subSectionSelector.GetSection(COLLECTIBLES_SUB_SECTION_INDEX).onSelect.RemoveAllListeners(); |
| 0 | 48 | | subSectionSelector.GetSection(ABOUT_SUB_SECTION_INDEX).onSelect.AddListener((isActive) => aboutPanel.SetActi |
| 0 | 49 | | subSectionSelector.GetSection(COLLECTIBLES_SUB_SECTION_INDEX).onSelect.AddListener((isActive) => wearablesPa |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | public void InitializeView() |
| | 53 | | { |
| 0 | 54 | | nftPagesEntryPool = GetNftPagesEntryPool(); |
| 0 | 55 | | nftIconsEntryPool = GetNftIconEntryPool(); |
| 0 | 56 | | CleanWearables(); |
| 0 | 57 | | CleanEquippedWearables(); |
| 0 | 58 | | SetInitialTab(); |
| 0 | 59 | | } |
| | 60 | |
|
| | 61 | | public void SetGuestUser(bool isGuest) |
| | 62 | | { |
| 0 | 63 | | guestPanel.SetActive(isGuest); |
| 0 | 64 | | normalPanel.SetActive(!isGuest); |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | public void SetName(string username) |
| | 68 | | { |
| 0 | 69 | | usernameText.text = $"{username} {GUEST_TEXT}"; |
| 0 | 70 | | } |
| | 71 | |
|
| | 72 | | public void SetDescription(string description) |
| | 73 | | { |
| 0 | 74 | | descriptionText.text = string.IsNullOrEmpty(description) ? TEMPLATE_DESCRIPTION_TEXT : description; |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | public void SetEquippedWearables(WearableItem[] wearables, string bodyShapeId) |
| | 78 | | { |
| 0 | 79 | | HashSet<string> hidesList = WearableItem.ComposeHiddenCategories(bodyShapeId, wearables.ToList()); |
| | 80 | |
|
| 0 | 81 | | foreach (var wearable in wearables) |
| | 82 | | { |
| 0 | 83 | | if (!hidesList.Contains(wearable.data.category)) |
| | 84 | | { |
| 0 | 85 | | PoolableObject poolableObject = nftIconsEntryPool.Get(); |
| 0 | 86 | | nftIconPoolableQueue.Add(poolableObject); |
| 0 | 87 | | poolableObject.gameObject.transform.SetParent(equippedWearablesContainer, false); |
| 0 | 88 | | poolableObject.gameObject.transform.localScale = NFT_ICON_SCALE; |
| 0 | 89 | | NFTIconComponentView nftIconComponentView = poolableObject.gameObject.GetComponent<NFTIconComponentV |
| 0 | 90 | | nftIconComponentView.onMarketplaceButtonClick.RemoveAllListeners(); |
| 0 | 91 | | nftIconComponentView.onMarketplaceButtonClick.AddListener(() => ClickOnBuyWearable(wearable.id)); |
| | 92 | |
|
| 0 | 93 | | NFTIconComponentModel nftModel = new NFTIconComponentModel() |
| | 94 | | { |
| | 95 | | showMarketplaceButton = wearable.IsCollectible(), |
| | 96 | | showType = wearable.IsCollectible(), |
| | 97 | | type = wearable.data.category, |
| | 98 | | marketplaceURI = "", |
| | 99 | | name = wearable.GetName(), |
| | 100 | | rarity = wearable.rarity, |
| | 101 | | imageURI = wearable.ComposeThumbnailUrl() |
| | 102 | | }; |
| | 103 | |
|
| 0 | 104 | | nftIconComponentView.Configure(nftModel); |
| | 105 | | } |
| | 106 | | } |
| 0 | 107 | | } |
| | 108 | |
|
| | 109 | | public void SetCollectibleWearables(WearableItem[] wearables) |
| | 110 | | { |
| 0 | 111 | | nftWearablesCarousel.CleanInstantiatedItems(); |
| 0 | 112 | | for (int i = 0; i < wearables.Length; i += 4) |
| | 113 | | { |
| 0 | 114 | | PoolableObject nftPagePoolElement = nftPagesEntryPool.Get(); |
| 0 | 115 | | nftPagesPoolableQueue.Add(nftPagePoolElement); |
| 0 | 116 | | nftPagePoolElement.gameObject.transform.SetParent(nftWearablesCarouselContent, false); |
| 0 | 117 | | NftPageView nftPageView = nftPagePoolElement.gameObject.GetComponent<NftPageView>(); |
| 0 | 118 | | nftPageView.OnClickBuyNft -= ClickOnBuyWearable; |
| 0 | 119 | | NFTIconComponentModel[] pageElements = new NFTIconComponentModel[4]; |
| 0 | 120 | | string[] nftIds = new string[4]; |
| 0 | 121 | | for (int j = 0; j < 4; j++) |
| | 122 | | { |
| 0 | 123 | | if (wearables.Length > i + j && wearables[i + j] != null) |
| | 124 | | { |
| 0 | 125 | | pageElements[j] = new () |
| | 126 | | { |
| | 127 | | showMarketplaceButton = true, |
| | 128 | | showType = true, |
| | 129 | | type = wearables[i+j].data.category, |
| | 130 | | marketplaceURI = "", |
| | 131 | | name = wearables[i+j].GetName(), |
| | 132 | | rarity = wearables[i+j].rarity, |
| | 133 | | imageURI = wearables[i+j].ComposeThumbnailUrl() |
| | 134 | | }; |
| | 135 | |
|
| 0 | 136 | | nftIds[j] = wearables[i + j].id; |
| | 137 | | } |
| | 138 | | else |
| | 139 | | { |
| 0 | 140 | | pageElements[j] = null; |
| 0 | 141 | | nftIds[j] = ""; |
| | 142 | | } |
| | 143 | | } |
| 0 | 144 | | nftPageView.SetPageElementsContent(pageElements, nftIds); |
| 0 | 145 | | nftPageView.OnClickBuyNft += ClickOnBuyWearable; |
| 0 | 146 | | nftWearablesCarousel.AddItem(nftPageView); |
| | 147 | | } |
| 0 | 148 | | nftWearablesCarousel.GenerateDotsSelector(); |
| 0 | 149 | | nftWearablesCarousel.ResetManualCarousel(); |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | public void SetCollectibleEmotes(WearableItem[] wearables) |
| | 153 | | { |
| 0 | 154 | | nftEmotesCarousel.CleanInstantiatedItems(); |
| 0 | 155 | | for (int i = 0; i < wearables.Length; i += 4) |
| | 156 | | { |
| 0 | 157 | | PoolableObject nftPagePoolElement = nftPagesEntryPool.Get(); |
| 0 | 158 | | nftPagesPoolableQueue.Add(nftPagePoolElement); |
| 0 | 159 | | nftPagePoolElement.gameObject.transform.SetParent(nftEmotesCarouselContent, false); |
| 0 | 160 | | NftPageView nftPageView = nftPagePoolElement.gameObject.GetComponent<NftPageView>(); |
| 0 | 161 | | nftPageView.OnClickBuyNft -= ClickOnBuyWearable; |
| 0 | 162 | | NFTIconComponentModel[] pageElements = new NFTIconComponentModel[4]; |
| 0 | 163 | | string[] nftIds = new string[4]; |
| 0 | 164 | | for (int j = 0; j < 4; j++) |
| | 165 | | { |
| 0 | 166 | | if (wearables.Length > i + j && wearables[i + j] != null) |
| | 167 | | { |
| 0 | 168 | | pageElements[j] = new () |
| | 169 | | { |
| | 170 | | showMarketplaceButton = true, |
| | 171 | | showType = true, |
| | 172 | | type = "emote", |
| | 173 | | marketplaceURI = "", |
| | 174 | | name = wearables[i+j].GetName(), |
| | 175 | | rarity = wearables[i+j].rarity, |
| | 176 | | imageURI = wearables[i+j].ComposeThumbnailUrl() |
| | 177 | | }; |
| | 178 | |
|
| 0 | 179 | | nftIds[j] = wearables[i + j].id; |
| | 180 | | } |
| | 181 | | else |
| | 182 | | { |
| 0 | 183 | | pageElements[j] = null; |
| 0 | 184 | | nftIds[j] = ""; |
| | 185 | | } |
| | 186 | | } |
| 0 | 187 | | nftPageView.SetPageElementsContent(pageElements, nftIds); |
| 0 | 188 | | nftPageView.OnClickBuyNft += ClickOnBuyWearable; |
| 0 | 189 | | nftEmotesCarousel.AddItem(nftPageView); |
| | 190 | | } |
| 0 | 191 | | nftEmotesCarousel.GenerateDotsSelector(); |
| 0 | 192 | | nftEmotesCarousel.ResetManualCarousel(); |
| 0 | 193 | | } |
| | 194 | |
|
| | 195 | | public void SetInitialTab() |
| | 196 | | { |
| 0 | 197 | | subSectionSelector.GetSection(ABOUT_SUB_SECTION_INDEX).SelectToggle(); |
| 0 | 198 | | subSectionSelector.GetSection(COLLECTIBLES_SUB_SECTION_INDEX).SetUnselectedVisuals(); |
| 0 | 199 | | } |
| | 200 | |
|
| | 201 | | private void ClickOnBuyWearable(string wearableId) |
| | 202 | | { |
| 0 | 203 | | OnClickBuyNft?.Invoke(wearableId); |
| 0 | 204 | | } |
| | 205 | |
|
| | 206 | | private void CleanEquippedWearables() |
| | 207 | | { |
| 0 | 208 | | foreach (var poolObject in nftIconPoolableQueue) |
| | 209 | | { |
| 0 | 210 | | nftIconsEntryPool.Release(poolObject); |
| | 211 | | } |
| 0 | 212 | | nftIconPoolableQueue = new List<PoolableObject>(); |
| 0 | 213 | | } |
| | 214 | |
|
| | 215 | | private void CleanWearables() |
| | 216 | | { |
| 0 | 217 | | foreach (var poolObject in nftPagesPoolableQueue) |
| | 218 | | { |
| 0 | 219 | | nftPagesEntryPool.Release(poolObject); |
| | 220 | | } |
| 0 | 221 | | nftPagesPoolableQueue = new List<PoolableObject>(); |
| 0 | 222 | | } |
| | 223 | |
|
| | 224 | | private Pool GetNftIconEntryPool() |
| | 225 | | { |
| 0 | 226 | | var pool = PoolManager.i.GetPool(NFT_ICON_POOL_NAME_PREFIX + name + GetInstanceID()); |
| 0 | 227 | | if (pool != null) return pool; |
| | 228 | |
|
| 0 | 229 | | pool = PoolManager.i.AddPool( |
| | 230 | | NFT_ICON_POOL_NAME_PREFIX + name + GetInstanceID(), |
| | 231 | | Instantiate(wearableUIReferenceObject).gameObject, |
| | 232 | | maxPrewarmCount: MAX_NFT_ICON_ENTRIES, |
| | 233 | | isPersistent: true); |
| 0 | 234 | | pool.ForcePrewarm(); |
| | 235 | |
|
| 0 | 236 | | return pool; |
| | 237 | | } |
| | 238 | |
|
| | 239 | | private Pool GetNftPagesEntryPool() |
| | 240 | | { |
| 0 | 241 | | var pool = PoolManager.i.GetPool(NFT_PAGES_POOL_NAME_PREFIX + name + GetInstanceID()); |
| 0 | 242 | | if (pool != null) return pool; |
| | 243 | |
|
| 0 | 244 | | pool = PoolManager.i.AddPool( |
| | 245 | | NFT_PAGES_POOL_NAME_PREFIX + name + GetInstanceID(), |
| | 246 | | Instantiate(nftPageUIReferenceObject).gameObject, |
| | 247 | | maxPrewarmCount: MAX_NFT_PAGES_ENTRIES, |
| | 248 | | isPersistent: true); |
| 0 | 249 | | pool.ForcePrewarm(); |
| | 250 | |
|
| 0 | 251 | | return pool; |
| | 252 | | } |
| | 253 | |
|
| | 254 | | public override void RefreshControl() |
| | 255 | | { |
| 0 | 256 | | } |
| | 257 | |
|
| | 258 | | } |
| | 259 | | } |