| | 1 | | using DCL; |
| | 2 | | using DCLServices.CameraReelService; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCLFeatures.CameraReel.ScreenshotViewer |
| | 9 | | { |
| | 10 | | public class ScreenshotVisiblePersonView : MonoBehaviour |
| | 11 | | { |
| 0 | 12 | | public static readonly BaseHashSet<ScreenshotVisiblePersonView> Instances = new (); |
| | 13 | |
|
| | 14 | | [Header("PROFILE")] |
| | 15 | | [SerializeField] private ProfileCardComponentView profileCard; |
| | 16 | | [SerializeField] private GameObject isGuestImage; |
| | 17 | | [SerializeField] private Button wearablesListButton; |
| | 18 | | [SerializeField] private Button userNameButton; |
| | 19 | | [SerializeField] private Image dropdownArrow; |
| | 20 | | [SerializeField] private Sprite arrowUp; |
| | 21 | |
|
| | 22 | | [Header("WEARABLES")] |
| | 23 | | [SerializeField] private NFTIconComponentView wearableTemplate; |
| | 24 | | [SerializeField] private Transform wearablesListContainer; |
| | 25 | | [SerializeField] private GameObject emptyWearablesListMessage; |
| | 26 | |
|
| 0 | 27 | | private readonly Dictionary<NFTIconComponentView, PoolableObject> wearables = new (); |
| | 28 | |
|
| | 29 | | private Sprite arrowDown; |
| | 30 | | private bool isShowingWearablesList; |
| | 31 | | private bool hasWearables; |
| | 32 | |
|
| | 33 | | public event Action<VisiblePerson> OnConfigureRequested; |
| | 34 | | public event Action<NFTIconComponentModel> OnOpenWearableMarketplaceRequested; |
| | 35 | | public event Action OnOpenProfileRequested; |
| | 36 | |
|
| | 37 | | private void Awake() |
| | 38 | | { |
| 0 | 39 | | wearablesListButton.onClick.AddListener(ShowHideList); |
| 0 | 40 | | userNameButton.onClick.AddListener(() => OnOpenProfileRequested?.Invoke()); |
| 0 | 41 | | arrowDown = dropdownArrow.sprite; |
| | 42 | |
|
| 0 | 43 | | if (!Instances.Contains(this)) |
| 0 | 44 | | Instances.Add(this); |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | private void OnDestroy() |
| | 48 | | { |
| 0 | 49 | | Instances.Remove(this); |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | public void Configure(VisiblePerson visiblePerson) |
| | 53 | | { |
| 0 | 54 | | if (!Instances.Contains(this)) |
| 0 | 55 | | Instances.Add(this); |
| | 56 | |
|
| 0 | 57 | | wearablesListContainer.gameObject.SetActive(false); |
| 0 | 58 | | OnConfigureRequested?.Invoke(visiblePerson); |
| 0 | 59 | | } |
| | 60 | |
|
| | 61 | | public void ClearWearables() |
| | 62 | | { |
| 0 | 63 | | foreach ((NFTIconComponentView _, PoolableObject poolObj) in wearables) |
| 0 | 64 | | poolObj.Release(); |
| | 65 | |
|
| 0 | 66 | | wearables.Clear(); |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public void AddWearable(NFTIconComponentModel nftModel) |
| | 70 | | { |
| 0 | 71 | | wearablesListContainer.gameObject.SetActive(false); |
| 0 | 72 | | hasWearables = true; |
| | 73 | |
|
| 0 | 74 | | Pool wearablePool = GetWearableEntryPool(); |
| 0 | 75 | | PoolableObject poolObj = wearablePool.Get(); |
| 0 | 76 | | NFTIconComponentView wearableEntry = poolObj.gameObject.GetComponent<NFTIconComponentView>(); |
| 0 | 77 | | wearableEntry.transform.SetParent(wearablesListContainer, false); |
| 0 | 78 | | wearableEntry.Configure(nftModel); |
| 0 | 79 | | Button equipButton = wearableEntry.GetComponent<Button>(); |
| 0 | 80 | | equipButton.onClick.RemoveAllListeners(); |
| 0 | 81 | | equipButton.onClick.AddListener(() => OnOpenWearableMarketplaceRequested?.Invoke(nftModel)); |
| 0 | 82 | | wearableEntry.gameObject.SetActive(true); |
| 0 | 83 | | wearables[wearableEntry] = poolObj; |
| 0 | 84 | | } |
| | 85 | |
|
| | 86 | | public void SetProfileName(string userName) |
| | 87 | | { |
| 0 | 88 | | profileCard.SetProfileName(userName); |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | public void SetProfileAddress(string address) |
| | 92 | | { |
| 0 | 93 | | profileCard.SetProfileAddress(address); |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | public void SetProfilePicture(string url) |
| | 97 | | { |
| 0 | 98 | | profileCard.SetProfilePicture(url); |
| 0 | 99 | | } |
| | 100 | |
|
| | 101 | | public void SetGuestMode(bool isGuest) |
| | 102 | | { |
| 0 | 103 | | isGuestImage.SetActive(isGuest); |
| 0 | 104 | | wearablesListButton.interactable = !isGuest; |
| 0 | 105 | | } |
| | 106 | |
|
| | 107 | | private void ShowHideList() |
| | 108 | | { |
| 0 | 109 | | isShowingWearablesList = !isShowingWearablesList; |
| 0 | 110 | | dropdownArrow.sprite = isShowingWearablesList ? arrowUp : arrowDown; |
| | 111 | |
|
| 0 | 112 | | if (hasWearables) |
| 0 | 113 | | wearablesListContainer.gameObject.SetActive(isShowingWearablesList); |
| | 114 | | else |
| 0 | 115 | | emptyWearablesListMessage.SetActive(isShowingWearablesList); |
| | 116 | |
|
| 0 | 117 | | LayoutRebuilder.ForceRebuildLayoutImmediate(transform as RectTransform); |
| 0 | 118 | | } |
| | 119 | |
|
| | 120 | | private Pool GetWearableEntryPool() |
| | 121 | | { |
| | 122 | | const string POOL_ID = "CameraReelPictureDetailProfileWearables"; |
| 0 | 123 | | var entryPool = PoolManager.i.GetPool(POOL_ID); |
| 0 | 124 | | if (entryPool != null) return entryPool; |
| | 125 | |
|
| 0 | 126 | | entryPool = PoolManager.i.AddPool( |
| | 127 | | POOL_ID, |
| | 128 | | Instantiate(wearableTemplate).gameObject, |
| | 129 | | maxPrewarmCount: 10, |
| | 130 | | isPersistent: true); |
| | 131 | |
|
| 0 | 132 | | return entryPool; |
| | 133 | | } |
| | 134 | | } |
| | 135 | | } |