| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using SocialBar.UserThumbnail; |
| | 4 | | using SocialFeaturesAnalytics; |
| | 5 | | using TMPro; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.EventSystems; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | | public class PrivateChatWindowComponentView : BaseComponentView, IPrivateChatComponentView, IPointerDownHandler |
| | 11 | | { |
| | 12 | | private const float REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD = 0.995f; |
| | 13 | |
|
| | 14 | | [SerializeField] internal Button backButton; |
| | 15 | | [SerializeField] internal Button closeButton; |
| | 16 | | [SerializeField] internal UserThumbnailComponentView userThumbnail; |
| | 17 | | [SerializeField] internal TMP_Text userNameLabel; |
| | 18 | | [SerializeField] internal PrivateChatHUDView chatView; |
| | 19 | | [SerializeField] internal GameObject jumpInButtonContainer; |
| | 20 | | [SerializeField] internal JumpInButton jumpInButton; |
| | 21 | | [SerializeField] internal UserContextMenu userContextMenu; |
| | 22 | | [SerializeField] internal RectTransform userContextMenuReferencePoint; |
| | 23 | | [SerializeField] internal Button optionsButton; |
| | 24 | | [SerializeField] internal GameObject messagesLoading; |
| | 25 | | [SerializeField] internal ScrollRect scroll; |
| | 26 | | [SerializeField] internal GameObject oldMessagesLoadingContainer; |
| | 27 | | [SerializeField] private Model model; |
| | 28 | |
|
| | 29 | | private IFriendsController friendsController; |
| | 30 | | private ISocialAnalytics socialAnalytics; |
| | 31 | | private Coroutine alphaRoutine; |
| | 32 | | private Vector2 originalSize; |
| | 33 | |
|
| | 34 | | public event Action OnPressBack; |
| | 35 | | public event Action OnMinimize; |
| | 36 | | public event Action OnClose; |
| | 37 | | public event Action<string> OnUnfriend |
| | 38 | | { |
| 1 | 39 | | add => userContextMenu.OnUnfriend += value; |
| 1 | 40 | | remove => userContextMenu.OnUnfriend -= value; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public event Action OnRequireMoreMessages; |
| | 44 | | public event Action<bool> OnFocused |
| | 45 | | { |
| 2 | 46 | | add => onFocused += value; |
| 1 | 47 | | remove => onFocused -= value; |
| | 48 | | } |
| | 49 | | public event Action OnClickOverWindow; |
| | 50 | |
|
| 1 | 51 | | public IChatHUDComponentView ChatHUD => chatView; |
| 2 | 52 | | public bool IsActive => gameObject.activeInHierarchy; |
| 0 | 53 | | public RectTransform Transform => (RectTransform) transform; |
| 0 | 54 | | public bool IsFocused => isFocused; |
| | 55 | |
|
| | 56 | | public static PrivateChatWindowComponentView Create() |
| | 57 | | { |
| 14 | 58 | | return Instantiate(Resources.Load<PrivateChatWindowComponentView>("SocialBarV1/PrivateChatHUD")); |
| | 59 | | } |
| | 60 | |
|
| | 61 | | public override void Awake() |
| | 62 | | { |
| 14 | 63 | | base.Awake(); |
| 14 | 64 | | originalSize = ((RectTransform) transform).sizeDelta; |
| 15 | 65 | | backButton.onClick.AddListener(() => OnPressBack?.Invoke()); |
| 15 | 66 | | closeButton.onClick.AddListener(() => OnClose?.Invoke()); |
| 14 | 67 | | optionsButton.onClick.AddListener(ShowOptions); |
| 14 | 68 | | userContextMenu.OnBlock += HandleBlockFromContextMenu; |
| 14 | 69 | | scroll.onValueChanged.AddListener((scrollPos) => |
| | 70 | | { |
| 0 | 71 | | if (scrollPos.y > REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD) |
| 0 | 72 | | OnRequireMoreMessages?.Invoke(); |
| 0 | 73 | | }); |
| 14 | 74 | | } |
| | 75 | |
|
| | 76 | | public void Initialize(IFriendsController friendsController, ISocialAnalytics socialAnalytics) |
| | 77 | | { |
| 1 | 78 | | this.friendsController = friendsController; |
| 1 | 79 | | this.socialAnalytics = socialAnalytics; |
| 1 | 80 | | } |
| | 81 | |
|
| | 82 | | public override void Dispose() |
| | 83 | | { |
| 28 | 84 | | if (!this) return; |
| 28 | 85 | | if (!gameObject) return; |
| | 86 | |
|
| 28 | 87 | | if (userContextMenu != null) |
| | 88 | | { |
| 28 | 89 | | userContextMenu.OnBlock -= HandleBlockFromContextMenu; |
| | 90 | | } |
| | 91 | |
|
| 28 | 92 | | base.Dispose(); |
| 28 | 93 | | } |
| | 94 | |
|
| | 95 | | public void SetLoadingMessagesActive(bool isActive) |
| | 96 | | { |
| 3 | 97 | | if (messagesLoading == null) |
| 0 | 98 | | return; |
| | 99 | |
|
| 3 | 100 | | messagesLoading.SetActive(isActive); |
| 3 | 101 | | } |
| | 102 | |
|
| | 103 | | public void SetOldMessagesLoadingActive(bool isActive) |
| | 104 | | { |
| 3 | 105 | | if (oldMessagesLoadingContainer == null) |
| 0 | 106 | | return; |
| | 107 | |
|
| 3 | 108 | | oldMessagesLoadingContainer.SetActive(isActive); |
| 3 | 109 | | oldMessagesLoadingContainer.transform.SetAsFirstSibling(); |
| 3 | 110 | | } |
| | 111 | |
|
| | 112 | | public override void RefreshControl() |
| | 113 | | { |
| 2 | 114 | | userThumbnail.Configure(new UserThumbnailComponentModel |
| | 115 | | { |
| | 116 | | faceUrl = model.faceSnapshotUrl, |
| | 117 | | isBlocked = model.isUserBlocked, |
| | 118 | | isOnline = model.isUserOnline |
| | 119 | | }); |
| 2 | 120 | | userNameLabel.SetText(model.userName); |
| 2 | 121 | | jumpInButtonContainer.SetActive(model.isUserOnline); |
| 2 | 122 | | } |
| | 123 | |
|
| | 124 | | public void Setup(UserProfile profile, bool isOnline, bool isBlocked) |
| | 125 | | { |
| 2 | 126 | | model = new Model |
| | 127 | | { |
| | 128 | | userId = profile.userId, |
| | 129 | | faceSnapshotUrl = profile.face256SnapshotURL, |
| | 130 | | userName = profile.userName, |
| | 131 | | isUserOnline = isOnline, |
| | 132 | | isUserBlocked = isBlocked |
| | 133 | | }; |
| 2 | 134 | | RefreshControl(); |
| | 135 | |
|
| 2 | 136 | | jumpInButton.Initialize(friendsController, profile.userId, socialAnalytics); |
| 2 | 137 | | } |
| | 138 | |
|
| 2 | 139 | | public void Show() => gameObject.SetActive(true); |
| | 140 | |
|
| 2 | 141 | | public void Hide() => gameObject.SetActive(false); |
| | 142 | |
|
| 1 | 143 | | public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke(); |
| | 144 | |
|
| | 145 | | private void ShowOptions() |
| | 146 | | { |
| 0 | 147 | | var contextMenuTransform = (RectTransform) userContextMenu.transform; |
| 0 | 148 | | contextMenuTransform.pivot = userContextMenuReferencePoint.pivot; |
| 0 | 149 | | contextMenuTransform.position = userContextMenuReferencePoint.position; |
| 0 | 150 | | userContextMenu.Show(model.userId); |
| 0 | 151 | | } |
| | 152 | |
|
| | 153 | | private void HandleBlockFromContextMenu(string userId, bool isBlocked) |
| | 154 | | { |
| 0 | 155 | | if (userId != model.userId) return; |
| 0 | 156 | | model.isUserBlocked = isBlocked; |
| 0 | 157 | | RefreshControl(); |
| 0 | 158 | | } |
| | 159 | |
|
| | 160 | | [Serializable] |
| | 161 | | private struct Model |
| | 162 | | { |
| | 163 | | public string userId; |
| | 164 | | public string userName; |
| | 165 | | public string faceSnapshotUrl; |
| | 166 | | public bool isUserBlocked; |
| | 167 | | public bool isUserOnline; |
| | 168 | | } |
| | 169 | | } |