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