| | 1 | | using DCL; |
| | 2 | | using DCLServices.CameraReelService; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Globalization; |
| | 6 | | using System.Linq; |
| | 7 | | using TMPro; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | namespace DCLFeatures.CameraReel.ScreenshotViewer |
| | 12 | | { |
| | 13 | | public class ScreenshotViewerInfoSidePanelView : MonoBehaviour, IScreenshotViewerInfoSidePanelView |
| | 14 | | { |
| 0 | 15 | | private readonly Dictionary<ScreenshotVisiblePersonView, PoolableObject> profiles = new (); |
| | 16 | |
|
| | 17 | | [Header("INFORMATION PANEL")] |
| | 18 | | [SerializeField] private Button infoPanelTextButton; |
| | 19 | | [SerializeField] private TMP_Text dataTime; |
| | 20 | | [SerializeField] private TMP_Text sceneInfo; |
| | 21 | | [SerializeField] private Button sceneInfoButton; |
| | 22 | | [SerializeField] private TMP_Text photoOwnerNameLabel; |
| | 23 | | [SerializeField] private ImageComponentView photoOwnerAvatarPicture; |
| | 24 | | [SerializeField] private Button pictureOwnerProfileButton; |
| | 25 | |
|
| | 26 | | [Header("VISIBLE PEOPLE PANEL")] |
| | 27 | | [SerializeField] private ScreenshotVisiblePersonView profileEntryTemplate; |
| | 28 | | [SerializeField] private Transform profileGridContainer; |
| | 29 | |
|
| | 30 | | private MetadataSidePanelAnimator metadataSidePanelAnimator; |
| | 31 | |
|
| | 32 | | public event Action SceneButtonClicked; |
| | 33 | | public event Action SidePanelButtonClicked; |
| | 34 | | public event Action OnOpenPictureOwnerProfile; |
| | 35 | |
|
| | 36 | | private void Awake() |
| | 37 | | { |
| 0 | 38 | | profileEntryTemplate.gameObject.SetActive(false); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | private void OnEnable() |
| | 42 | | { |
| 0 | 43 | | infoPanelTextButton.onClick.AddListener(() => SidePanelButtonClicked?.Invoke()); |
| 0 | 44 | | sceneInfoButton.onClick.AddListener(() => SceneButtonClicked?.Invoke()); |
| 0 | 45 | | pictureOwnerProfileButton.onClick.AddListener(() => OnOpenPictureOwnerProfile?.Invoke()); |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | private void OnDisable() |
| | 49 | | { |
| 0 | 50 | | infoPanelTextButton.onClick.RemoveAllListeners(); |
| 0 | 51 | | sceneInfoButton.onClick.RemoveAllListeners(); |
| 0 | 52 | | pictureOwnerProfileButton.onClick.RemoveAllListeners(); |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | public void SetSceneInfoText(Scene scene) => |
| 0 | 56 | | sceneInfo.text = $"{scene.name}, {scene.location.x}, {scene.location.y}"; |
| | 57 | |
|
| | 58 | | public void SetDateText(DateTime dateTime) => |
| 0 | 59 | | dataTime.text = dateTime.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture); |
| | 60 | |
|
| | 61 | | public void ShowVisiblePersons(VisiblePerson[] visiblePeople) |
| | 62 | | { |
| 0 | 63 | | ClearCurrentProfiles(); |
| | 64 | |
|
| 0 | 65 | | Pool profilePool = GetProfileEntryPool(); |
| | 66 | |
|
| 0 | 67 | | foreach (VisiblePerson visiblePerson in visiblePeople.OrderBy(person => person.isGuest) |
| 0 | 68 | | .ThenByDescending(person => person.wearables.Length)) |
| | 69 | | { |
| 0 | 70 | | PoolableObject poolObj = profilePool.Get(); |
| 0 | 71 | | ScreenshotVisiblePersonView profileEntry = poolObj.gameObject.GetComponent<ScreenshotVisiblePersonView>( |
| 0 | 72 | | profileEntry.transform.SetParent(profileGridContainer, false); |
| 0 | 73 | | profiles[profileEntry] = poolObj; |
| 0 | 74 | | profileEntry.Configure(visiblePerson); |
| 0 | 75 | | profileEntry.gameObject.SetActive(true); |
| | 76 | | } |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | public void SetPictureOwner(string userName, string avatarPictureUrl) |
| | 80 | | { |
| 0 | 81 | | photoOwnerNameLabel.text = userName; |
| 0 | 82 | | photoOwnerAvatarPicture.SetImage(avatarPictureUrl); |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | private void ClearCurrentProfiles() |
| | 86 | | { |
| 0 | 87 | | foreach ((_, PoolableObject poolObj) in profiles) |
| 0 | 88 | | poolObj.Release(); |
| | 89 | |
|
| 0 | 90 | | profiles.Clear(); |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | private Pool GetProfileEntryPool() |
| | 94 | | { |
| | 95 | | const string POOL_ID = "PictureDetailProfile"; |
| 0 | 96 | | var entryPool = PoolManager.i.GetPool(POOL_ID); |
| 0 | 97 | | if (entryPool != null) return entryPool; |
| | 98 | |
|
| 0 | 99 | | entryPool = PoolManager.i.AddPool( |
| | 100 | | POOL_ID, |
| | 101 | | Instantiate(profileEntryTemplate).gameObject, |
| | 102 | | maxPrewarmCount: 10, |
| | 103 | | isPersistent: true); |
| | 104 | |
|
| 0 | 105 | | return entryPool; |
| | 106 | | } |
| | 107 | | } |
| | 108 | | } |