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