| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Social.Friends; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.Events; |
| | 9 | | using UnityEngine.UI; |
| | 10 | |
|
| | 11 | | public class PlayerInfoCardHUDView : MonoBehaviour |
| | 12 | | { |
| | 13 | | private const string PREFAB_PATH = "PlayerInfoCardHUD"; |
| | 14 | |
|
| | 15 | | public enum Tabs |
| | 16 | | { |
| | 17 | | Passport, |
| | 18 | | Trade, |
| | 19 | | Block |
| | 20 | | } |
| | 21 | |
|
| | 22 | | [Serializable] |
| | 23 | | internal class TabsMapping |
| | 24 | | { |
| | 25 | | public GameObject container; |
| | 26 | | public Toggle toggle; |
| | 27 | | public Tabs tab; |
| | 28 | | } |
| | 29 | |
|
| | 30 | | [SerializeField] internal GenericFactory collectiblesFactory; |
| | 31 | | [SerializeField] internal Canvas cardCanvas; |
| | 32 | | [SerializeField] internal TabsMapping[] tabsMapping; |
| | 33 | | [SerializeField] internal Button hideCardButton; |
| | 34 | |
|
| | 35 | | [Space][SerializeField] internal RawImage avatarPicture; |
| | 36 | | [SerializeField] internal Image blockedAvatarOverlay; |
| | 37 | | [SerializeField] internal TextMeshProUGUI name; |
| | 38 | |
|
| | 39 | | [Header("Friends")][SerializeField] internal GameObject friendStatusContainer; |
| | 40 | | [SerializeField] internal Button requestSentButton; |
| | 41 | | [SerializeField] internal Button addFriendButton; |
| | 42 | | [SerializeField] internal GameObject alreadyFriendsContainer; |
| | 43 | | [SerializeField] internal GameObject requestReceivedContainer; |
| | 44 | | [SerializeField] internal Button acceptRequestButton; |
| | 45 | | [SerializeField] internal Button rejectRequestButton; |
| | 46 | |
|
| | 47 | | [Header("Passport")][SerializeField] internal TextMeshProUGUI description; |
| | 48 | |
|
| | 49 | | [Header("Trade")][SerializeField] private RectTransform wearablesContainer; |
| | 50 | | [SerializeField] private GameObject emptyCollectiblesImage; |
| | 51 | |
|
| | 52 | | [Header("Block")][SerializeField] internal Button reportPlayerButton; |
| | 53 | | [SerializeField] internal Button blockPlayerButton; |
| | 54 | | [SerializeField] internal Button unblockPlayerButton; |
| | 55 | |
|
| 27 | 56 | | internal readonly List<PlayerInfoCollectibleItem> playerInfoCollectibles = new List<PlayerInfoCollectibleItem>(10); |
| 166 | 57 | | private UnityAction<bool> toggleChangedDelegate => (x) => UpdateTabs(); |
| | 58 | |
|
| | 59 | | private MouseCatcher mouseCatcher; |
| | 60 | | private HUDCanvasCameraModeController hudCanvasCameraModeController; |
| | 61 | |
|
| 52 | 62 | | private void Awake() { hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), Dat |
| | 63 | |
|
| | 64 | | public static PlayerInfoCardHUDView CreateView() |
| | 65 | | { |
| 26 | 66 | | return Instantiate(Resources.Load<GameObject>(PREFAB_PATH)).GetComponent<PlayerInfoCardHUDView>(); |
| | 67 | | } |
| | 68 | |
|
| | 69 | | public void Initialize(UnityAction cardClosedCallback, |
| | 70 | | UnityAction reportPlayerCallback, |
| | 71 | | UnityAction blockPlayerCallback, |
| | 72 | | UnityAction unblockPlayerCallback, |
| | 73 | | UnityAction addFriendCallback, |
| | 74 | | UnityAction cancelInvitation, |
| | 75 | | UnityAction acceptFriendRequest, |
| | 76 | | UnityAction rejectFriendRequest) |
| | 77 | | { |
| 27 | 78 | | hideCardButton.onClick.RemoveAllListeners(); |
| 27 | 79 | | hideCardButton.onClick.AddListener(cardClosedCallback); |
| | 80 | |
|
| 27 | 81 | | reportPlayerButton.onClick.RemoveAllListeners(); |
| 27 | 82 | | reportPlayerButton.onClick.AddListener(reportPlayerCallback); |
| | 83 | |
|
| 27 | 84 | | blockPlayerButton.onClick.RemoveAllListeners(); |
| 27 | 85 | | blockPlayerButton.onClick.AddListener(blockPlayerCallback); |
| | 86 | |
|
| 27 | 87 | | unblockPlayerButton.onClick.RemoveAllListeners(); |
| 27 | 88 | | unblockPlayerButton.onClick.AddListener(unblockPlayerCallback); |
| | 89 | |
|
| 27 | 90 | | addFriendButton.onClick.RemoveAllListeners(); |
| 27 | 91 | | addFriendButton.onClick.AddListener(addFriendCallback); |
| | 92 | |
|
| 27 | 93 | | requestSentButton.onClick.RemoveAllListeners(); |
| 27 | 94 | | requestSentButton.onClick.AddListener(cancelInvitation); |
| | 95 | |
|
| 27 | 96 | | acceptRequestButton.onClick.RemoveAllListeners(); |
| 27 | 97 | | acceptRequestButton.onClick.AddListener(acceptFriendRequest); |
| | 98 | |
|
| 27 | 99 | | rejectRequestButton.onClick.RemoveAllListeners(); |
| 27 | 100 | | rejectRequestButton.onClick.AddListener(rejectFriendRequest); |
| | 101 | |
|
| 216 | 102 | | for (int index = 0; index < tabsMapping.Length; index++) |
| | 103 | | { |
| 81 | 104 | | var tab = tabsMapping[index]; |
| 81 | 105 | | tab.toggle.onValueChanged.RemoveListener(toggleChangedDelegate); |
| 81 | 106 | | tab.toggle.onValueChanged.AddListener(toggleChangedDelegate); |
| | 107 | | } |
| | 108 | |
|
| 54 | 109 | | for (int index = 0; index < tabsMapping.Length; index++) |
| | 110 | | { |
| 27 | 111 | | if (tabsMapping[index].tab == Tabs.Passport) |
| | 112 | | { |
| 27 | 113 | | tabsMapping[index].toggle.isOn = true; |
| 27 | 114 | | break; |
| | 115 | | } |
| | 116 | | } |
| | 117 | |
|
| 27 | 118 | | if (SceneReferences.i != null) |
| | 119 | | { |
| 27 | 120 | | var mouseCatcher = SceneReferences.i.mouseCatcher; |
| | 121 | |
|
| 27 | 122 | | if (mouseCatcher != null) |
| | 123 | | { |
| 0 | 124 | | this.mouseCatcher = mouseCatcher; |
| 0 | 125 | | mouseCatcher.OnMouseDown += OnPointerDown; |
| | 126 | | } |
| | 127 | | } |
| 27 | 128 | | } |
| | 129 | |
|
| | 130 | | public void SetCardActive(bool active) |
| | 131 | | { |
| 46 | 132 | | if (active && mouseCatcher != null) |
| | 133 | | { |
| 0 | 134 | | mouseCatcher.UnlockCursor(); |
| | 135 | | } |
| | 136 | |
|
| 46 | 137 | | cardCanvas.enabled = active; |
| 46 | 138 | | } |
| | 139 | |
|
| | 140 | | private void UpdateTabs() |
| | 141 | | { |
| 32 | 142 | | for (int index = 0; index < tabsMapping.Length; index++) |
| | 143 | | { |
| 12 | 144 | | tabsMapping[index].container.SetActive(tabsMapping[index].toggle.isOn); |
| | 145 | | } |
| 4 | 146 | | } |
| | 147 | |
|
| | 148 | | public void SetFaceSnapshot(Texture2D texture) |
| | 149 | | { |
| 0 | 150 | | avatarPicture.texture = texture; |
| 0 | 151 | | } |
| | 152 | |
|
| 31 | 153 | | public void SetName(string name) => this.name.text = name; |
| | 154 | |
|
| | 155 | | public void SetDescription(string description) |
| | 156 | | { |
| 31 | 157 | | if (description != null) |
| 29 | 158 | | this.description.text = description; |
| 31 | 159 | | } |
| | 160 | |
|
| | 161 | | public void HideFriendshipInteraction() |
| | 162 | | { |
| 0 | 163 | | requestReceivedContainer.SetActive(false); |
| 0 | 164 | | addFriendButton.gameObject.SetActive(false); |
| 0 | 165 | | alreadyFriendsContainer.SetActive(false); |
| 0 | 166 | | requestSentButton.gameObject.SetActive(false); |
| 0 | 167 | | } |
| | 168 | |
|
| | 169 | | public void UpdateFriendshipInteraction(bool canUseFriendButton, |
| | 170 | | UserStatus status) |
| | 171 | | { |
| 31 | 172 | | if (status == null) |
| | 173 | | { |
| 27 | 174 | | requestReceivedContainer.SetActive(false); |
| 27 | 175 | | addFriendButton.gameObject.SetActive(false); |
| 27 | 176 | | alreadyFriendsContainer.SetActive(false); |
| 27 | 177 | | requestSentButton.gameObject.SetActive(false); |
| 27 | 178 | | return; |
| | 179 | | } |
| | 180 | |
|
| 4 | 181 | | friendStatusContainer.SetActive(canUseFriendButton); |
| | 182 | |
|
| 4 | 183 | | if (!canUseFriendButton) |
| | 184 | | { |
| 0 | 185 | | addFriendButton.gameObject.SetActive(false); |
| 0 | 186 | | alreadyFriendsContainer.SetActive(false); |
| 0 | 187 | | requestSentButton.gameObject.SetActive(false); |
| 0 | 188 | | return; |
| | 189 | | } |
| | 190 | |
|
| 4 | 191 | | addFriendButton.gameObject.SetActive(false); |
| 4 | 192 | | alreadyFriendsContainer.SetActive(false); |
| 4 | 193 | | requestReceivedContainer.SetActive(false); |
| 4 | 194 | | requestSentButton.gameObject.SetActive(false); |
| | 195 | |
|
| 4 | 196 | | switch (status.friendshipStatus) |
| | 197 | | { |
| | 198 | | case FriendshipStatus.NOT_FRIEND: |
| 1 | 199 | | addFriendButton.gameObject.SetActive(true); |
| 1 | 200 | | break; |
| | 201 | | case FriendshipStatus.FRIEND: |
| 1 | 202 | | alreadyFriendsContainer.SetActive(true); |
| 1 | 203 | | break; |
| | 204 | | case FriendshipStatus.REQUESTED_FROM: |
| 1 | 205 | | requestReceivedContainer.SetActive(true); |
| 1 | 206 | | break; |
| | 207 | | case FriendshipStatus.REQUESTED_TO: |
| 1 | 208 | | requestSentButton.gameObject.SetActive(true); |
| | 209 | | break; |
| | 210 | | } |
| 1 | 211 | | } |
| | 212 | |
|
| | 213 | | public void SetIsBlocked(bool isBlocked) |
| | 214 | | { |
| 31 | 215 | | unblockPlayerButton.gameObject.SetActive(isBlocked); |
| 31 | 216 | | blockedAvatarOverlay.gameObject.SetActive(isBlocked); |
| 31 | 217 | | } |
| | 218 | |
|
| | 219 | | public void SetVisibility(bool visible) |
| | 220 | | { |
| 0 | 221 | | if (gameObject.activeSelf != visible) |
| | 222 | | { |
| 0 | 223 | | if (visible) |
| | 224 | | { |
| 0 | 225 | | AudioScriptableObjects.dialogOpen.Play(true); |
| | 226 | | } |
| | 227 | | else |
| | 228 | | { |
| 0 | 229 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 230 | | } |
| | 231 | | } |
| | 232 | |
|
| 0 | 233 | | gameObject.SetActive(visible); |
| 0 | 234 | | } |
| | 235 | |
|
| | 236 | | public void ClearCollectibles() |
| | 237 | | { |
| 218 | 238 | | for (var i = playerInfoCollectibles.Count - 1; i >= 0; i--) |
| | 239 | | { |
| 78 | 240 | | var playerInfoCollectible = playerInfoCollectibles[i]; |
| 78 | 241 | | playerInfoCollectibles.RemoveAt(i); |
| 78 | 242 | | Destroy(playerInfoCollectible.gameObject); |
| | 243 | | } |
| 31 | 244 | | } |
| | 245 | |
|
| | 246 | | public void SetWearables(IEnumerable<WearableItem> wearables) |
| | 247 | | { |
| 31 | 248 | | var emptyWearables = true; |
| | 249 | |
|
| 434 | 250 | | foreach (var wearable in wearables) |
| | 251 | | { |
| 186 | 252 | | emptyWearables = false; |
| 186 | 253 | | var playerInfoCollectible = |
| | 254 | | collectiblesFactory.Instantiate<PlayerInfoCollectibleItem>(wearable.rarity, |
| | 255 | | wearablesContainer.transform); |
| 186 | 256 | | if (playerInfoCollectible == null) continue; |
| 186 | 257 | | playerInfoCollectibles.Add(playerInfoCollectible); |
| 186 | 258 | | playerInfoCollectible.Initialize(wearable); |
| | 259 | | } |
| | 260 | |
|
| 31 | 261 | | emptyCollectiblesImage.SetActive(emptyWearables); |
| 31 | 262 | | } |
| | 263 | |
|
| | 264 | | private void OnPointerDown() |
| | 265 | | { |
| 0 | 266 | | hideCardButton.onClick.Invoke(); |
| 0 | 267 | | } |
| | 268 | |
|
| | 269 | | private void OnDestroy() |
| | 270 | | { |
| 26 | 271 | | hudCanvasCameraModeController?.Dispose(); |
| 26 | 272 | | if (mouseCatcher != null) |
| 0 | 273 | | mouseCatcher.OnMouseDown -= OnPointerDown; |
| 26 | 274 | | } |
| | 275 | | } |