| | 1 | | using DCl.Social.Friends; |
| | 2 | | using System; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine; |
| | 5 | | using TMPro; |
| | 6 | | using SocialFeaturesAnalytics; |
| | 7 | | using DCL.Social.Friends; |
| | 8 | | using UIComponents.Scripts.Components; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | namespace DCL.Social.Passports |
| | 12 | | { |
| | 13 | | public class PassportPlayerInfoComponentView : BaseComponentView<PlayerPassportModel>, IPassportPlayerInfoComponentV |
| | 14 | | { |
| | 15 | | [SerializeField] private TextMeshProUGUI name; |
| | 16 | | [SerializeField] private TextMeshProUGUI nameInOptionsPanel; |
| | 17 | | [SerializeField] private Button walletCopyButton; |
| | 18 | | [SerializeField] private TextMeshProUGUI wallet; |
| | 19 | | [SerializeField] private ButtonComponentView optionsButton; |
| | 20 | | [SerializeField] private ButtonComponentView addFriendButton; |
| | 21 | | [SerializeField] private ButtonComponentView alreadyFriendsButton; |
| | 22 | | [SerializeField] private ButtonComponentView cancelFriendRequestButton; |
| | 23 | | [SerializeField] private ButtonComponentView acceptFriendButton; |
| | 24 | | [SerializeField] private ButtonComponentView blockedFriendButton; |
| | 25 | | [SerializeField] private Button whisperButton; |
| | 26 | | [SerializeField] private GameObject whisperNonFriendsPopup; |
| | 27 | | [SerializeField] private GameObject onlineStatus; |
| | 28 | | [SerializeField] private GameObject offlineStatus; |
| | 29 | | [SerializeField] private GameObject normalUserPanel; |
| | 30 | | [SerializeField] private GameObject friendsFlowContainer; |
| | 31 | | [SerializeField] private UserContextMenu userContextMenu; |
| | 32 | |
|
| | 33 | | [SerializeField] private GameObject alreadyFriendsVariation; |
| | 34 | | [SerializeField] private GameObject unfriendVariation; |
| | 35 | |
|
| | 36 | | [SerializeField] private GameObject alreadyBlockedVariation; |
| | 37 | | [SerializeField] private GameObject unblockVariation; |
| | 38 | |
|
| | 39 | | [SerializeField] private JumpInButton jumpInButton; |
| | 40 | |
|
| | 41 | | public event Action OnAddFriend; |
| | 42 | | public event Action OnRemoveFriend; |
| | 43 | | public event Action OnCancelFriendRequest; |
| | 44 | | public event Action OnAcceptFriendRequest; |
| | 45 | | public event Action OnBlockUser; |
| | 46 | | public event Action OnUnblockUser; |
| | 47 | | public event Action OnReportUser; |
| | 48 | | public event Action<string> OnWhisperUser; |
| | 49 | |
|
| | 50 | | private string fullWalletAddress; |
| | 51 | | private bool areFriends; |
| | 52 | | private bool isBlocked = false; |
| | 53 | |
|
| | 54 | | public override void Start() |
| | 55 | | { |
| 0 | 56 | | walletCopyButton.onClick.AddListener(CopyWalletToClipboard); |
| 0 | 57 | | addFriendButton.onClick.AddListener(()=>OnAddFriend?.Invoke()); |
| 0 | 58 | | alreadyFriendsButton.onClick.AddListener(()=>OnRemoveFriend?.Invoke()); |
| 0 | 59 | | cancelFriendRequestButton.onClick.AddListener(()=>OnCancelFriendRequest?.Invoke()); |
| 0 | 60 | | acceptFriendButton.onClick.AddListener(()=>OnAcceptFriendRequest?.Invoke()); |
| 0 | 61 | | userContextMenu.OnBlock += OnBlock; |
| 0 | 62 | | blockedFriendButton.onClick.AddListener(()=>OnUnblockUser?.Invoke()); |
| 0 | 63 | | userContextMenu.OnReport += OnReport; |
| 0 | 64 | | whisperButton.onClick.AddListener(WhisperActionFlow); |
| 0 | 65 | | optionsButton.onClick.AddListener(OpenOptions); |
| | 66 | |
|
| 0 | 67 | | alreadyFriendsButton.onFocused += RemoveFriendsFocused; |
| 0 | 68 | | blockedFriendButton.onFocused += BlockFriendFocused; |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | private void OnReport(string Obj) |
| | 72 | | { |
| 0 | 73 | | OnReportUser?.Invoke(); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | private void OnBlock(string Arg1, bool Arg2) |
| | 77 | | { |
| 0 | 78 | | OnBlockUser?.Invoke(); |
| 0 | 79 | | } |
| | 80 | |
|
| | 81 | | public override void RefreshControl() |
| | 82 | | { |
| 0 | 83 | | if (model == null) |
| 0 | 84 | | return; |
| | 85 | |
|
| 0 | 86 | | SetGuestUser(model.isGuest); |
| 0 | 87 | | SetName(model.name); |
| 0 | 88 | | userContextMenu.Hide(); |
| 0 | 89 | | SetWallet(model.userId); |
| 0 | 90 | | SetPresence(model.presenceStatus); |
| 0 | 91 | | SetIsBlocked(model.isBlocked); |
| 0 | 92 | | SetHasBlockedOwnUser(model.hasBlocked); |
| 0 | 93 | | SetFriendStatus(model.friendshipStatus); |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | public override void Dispose() |
| | 97 | | { |
| 0 | 98 | | base.Dispose(); |
| | 99 | |
|
| 0 | 100 | | walletCopyButton.onClick.RemoveAllListeners(); |
| 0 | 101 | | addFriendButton.onClick.RemoveAllListeners(); |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | public void InitializeJumpInButton(IFriendsController friendsController, string userId, ISocialAnalytics socialA |
| | 105 | | { |
| 0 | 106 | | jumpInButton.gameObject.SetActive(true); |
| 0 | 107 | | jumpInButton.Initialize(friendsController, userId, socialAnalytics); |
| 0 | 108 | | } |
| | 109 | |
|
| | 110 | | private void RemoveFriendsFocused(bool isFocused) |
| | 111 | | { |
| 0 | 112 | | alreadyFriendsVariation.SetActive(!isFocused); |
| 0 | 113 | | unfriendVariation.SetActive(isFocused); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | private void BlockFriendFocused(bool isFocused) |
| | 117 | | { |
| 0 | 118 | | alreadyBlockedVariation.SetActive(!isFocused); |
| 0 | 119 | | unblockVariation.SetActive(isFocused); |
| 0 | 120 | | } |
| | 121 | |
|
| | 122 | | private void SetName(string name) |
| | 123 | | { |
| 0 | 124 | | this.name.text = name; |
| 0 | 125 | | nameInOptionsPanel.text = name; |
| 0 | 126 | | } |
| | 127 | |
|
| | 128 | | private void SetWallet(string wallet) |
| | 129 | | { |
| 0 | 130 | | fullWalletAddress = wallet; |
| 0 | 131 | | this.wallet.text = $"{wallet.Substring(0,5)}...{wallet.Substring(wallet.Length - 5)}"; |
| 0 | 132 | | } |
| | 133 | |
|
| | 134 | | public void SetIsBlocked(bool isBlocked) |
| | 135 | | { |
| 0 | 136 | | this.isBlocked = isBlocked; |
| 0 | 137 | | DisableAllFriendFlowButtons(); |
| 0 | 138 | | blockedFriendButton.gameObject.SetActive(true); |
| 0 | 139 | | } |
| | 140 | |
|
| | 141 | | private void SetPresence(PresenceStatus status) |
| | 142 | | { |
| 0 | 143 | | if(status == PresenceStatus.ONLINE) |
| | 144 | | { |
| 0 | 145 | | onlineStatus.SetActive(true); |
| 0 | 146 | | offlineStatus.SetActive(false); |
| | 147 | | } |
| | 148 | | else |
| | 149 | | { |
| 0 | 150 | | onlineStatus.SetActive(false); |
| 0 | 151 | | offlineStatus.SetActive(true); |
| | 152 | | } |
| 0 | 153 | | } |
| | 154 | |
|
| | 155 | | private void SetGuestUser(bool isGuest) |
| | 156 | | { |
| 0 | 157 | | normalUserPanel.SetActive(!isGuest); |
| 0 | 158 | | } |
| | 159 | |
|
| | 160 | | private void SetHasBlockedOwnUser(bool hasBlocked) |
| | 161 | | { |
| 0 | 162 | | friendsFlowContainer.SetActive(!hasBlocked); |
| 0 | 163 | | } |
| | 164 | |
|
| | 165 | | private void SetFriendStatus(FriendshipStatus friendStatus) |
| | 166 | | { |
| 0 | 167 | | areFriends = friendStatus == FriendshipStatus.FRIEND; |
| | 168 | |
|
| 0 | 169 | | if(isBlocked) return; |
| | 170 | |
|
| | 171 | | switch (friendStatus) |
| | 172 | | { |
| | 173 | | case FriendshipStatus.NOT_FRIEND: |
| 0 | 174 | | DisableAllFriendFlowButtons(); |
| 0 | 175 | | addFriendButton.gameObject.SetActive(true); |
| 0 | 176 | | break; |
| | 177 | | case FriendshipStatus.FRIEND: |
| 0 | 178 | | DisableAllFriendFlowButtons(); |
| 0 | 179 | | alreadyFriendsButton.gameObject.SetActive(true); |
| 0 | 180 | | break; |
| | 181 | | case FriendshipStatus.REQUESTED_FROM: |
| 0 | 182 | | DisableAllFriendFlowButtons(); |
| 0 | 183 | | acceptFriendButton.gameObject.SetActive(true); |
| 0 | 184 | | break; |
| | 185 | | case FriendshipStatus.REQUESTED_TO: |
| 0 | 186 | | DisableAllFriendFlowButtons(); |
| 0 | 187 | | cancelFriendRequestButton.gameObject.SetActive(true); |
| | 188 | | break; |
| | 189 | | default: |
| | 190 | | break; |
| | 191 | | } |
| 0 | 192 | | whisperNonFriendsPopup.SetActive(false); |
| 0 | 193 | | } |
| | 194 | |
|
| | 195 | | private void DisableAllFriendFlowButtons() |
| | 196 | | { |
| 0 | 197 | | alreadyFriendsButton.gameObject.SetActive(false); |
| 0 | 198 | | addFriendButton.gameObject.SetActive(false); |
| 0 | 199 | | cancelFriendRequestButton.gameObject.SetActive(false); |
| 0 | 200 | | acceptFriendButton.gameObject.SetActive(false); |
| 0 | 201 | | blockedFriendButton.gameObject.SetActive(false); |
| 0 | 202 | | } |
| | 203 | |
|
| | 204 | | private void CopyWalletToClipboard() |
| | 205 | | { |
| 0 | 206 | | if(fullWalletAddress == null) |
| 0 | 207 | | return; |
| | 208 | |
|
| 0 | 209 | | GUIUtility.systemCopyBuffer = fullWalletAddress; |
| 0 | 210 | | } |
| | 211 | |
|
| | 212 | | private void WhisperActionFlow() |
| | 213 | | { |
| 0 | 214 | | if (areFriends) |
| | 215 | | { |
| 0 | 216 | | OnWhisperUser?.Invoke(model.userId); |
| | 217 | | } |
| | 218 | | else |
| | 219 | | { |
| 0 | 220 | | whisperNonFriendsPopup.SetActive(!areFriends); |
| 0 | 221 | | StartCoroutine(WaitAndClosePopup()); |
| | 222 | | } |
| 0 | 223 | | } |
| | 224 | |
|
| | 225 | | private void OpenOptions() |
| | 226 | | { |
| 0 | 227 | | userContextMenu.Show(model.userId); |
| 0 | 228 | | } |
| | 229 | |
|
| | 230 | | private IEnumerator WaitAndClosePopup() |
| | 231 | | { |
| 0 | 232 | | yield return new WaitForSeconds(3); |
| 0 | 233 | | whisperNonFriendsPopup.SetActive(false); |
| 0 | 234 | | } |
| | 235 | | } |
| | 236 | | } |